-
Notifications
You must be signed in to change notification settings - Fork 128
node: Add support for pnpm #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nukeop
wants to merge
1
commit into
flatpak:master
Choose a base branch
from
nukeop:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,530
−1,082
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import base64 | ||
| import hashlib | ||
| import json | ||
| import os | ||
| import re | ||
| import sys | ||
| import tarfile | ||
| import time | ||
|
|
||
| _SANITIZE_RE = re.compile(r'[\\/:*?"<>|]') | ||
|
|
||
|
|
||
| def populate_store(manifest_path: str, tarball_dir: str, store_dir: str) -> None: | ||
| with open(manifest_path, encoding='utf-8') as f: | ||
| manifest = json.load(f) | ||
|
|
||
| store_version = manifest['store_version'] | ||
| packages = manifest['packages'] | ||
|
|
||
| store = os.path.join(store_dir, store_version) | ||
| os.makedirs(os.path.join(store, 'files'), exist_ok=True) | ||
| os.makedirs(os.path.join(store, 'index'), exist_ok=True) | ||
|
|
||
| now = int(time.time() * 1000) | ||
|
|
||
| for tarball_name, info in packages.items(): | ||
| tarball_path = os.path.join(tarball_dir, tarball_name) | ||
| if not os.path.isfile(tarball_path): | ||
| raise FileNotFoundError(tarball_path) | ||
|
|
||
| _process_tarball( | ||
| tarball_path=tarball_path, | ||
| pkg_name=info['name'], | ||
| pkg_version=info['version'], | ||
| integrity_hex=info['integrity_hex'], | ||
| store=store, | ||
| now=now, | ||
| ) | ||
|
|
||
|
|
||
| def _process_tarball( | ||
| *, | ||
| tarball_path: str, | ||
| pkg_name: str, | ||
| pkg_version: str, | ||
| integrity_hex: str, | ||
| store: str, | ||
| now: int, | ||
| ) -> None: | ||
| index_files: dict[str, dict[str, object]] = {} | ||
|
|
||
| with tarfile.open(tarball_path, 'r:gz') as tf: | ||
| for member in tf.getmembers(): | ||
| if not member.isfile(): | ||
| continue | ||
| fobj = tf.extractfile(member) | ||
| if fobj is None: | ||
| continue | ||
| data = fobj.read() | ||
|
|
||
| digest = hashlib.sha512(data).digest() | ||
| file_hex = digest.hex() | ||
| is_exec = bool(member.mode & 0o111) | ||
|
|
||
| cas_dir = os.path.join(store, 'files', file_hex[:2]) | ||
| cas_name = file_hex[2:] + ('-exec' if is_exec else '') | ||
| cas_path = os.path.join(cas_dir, cas_name) | ||
| if not os.path.exists(cas_path): | ||
| os.makedirs(cas_dir, exist_ok=True) | ||
| with open(cas_path, 'wb') as out: | ||
| out.write(data) | ||
| if is_exec: | ||
| os.chmod(cas_path, 0o755) | ||
|
|
||
| rel_name = member.name | ||
| if '/' in rel_name: | ||
| rel_name = rel_name.split('/', 1)[1] | ||
|
|
||
| b64 = base64.b64encode(digest).decode() | ||
| index_files[rel_name] = { | ||
| 'checkedAt': now, | ||
| 'integrity': f'sha512-{b64}', | ||
| 'mode': member.mode, | ||
| 'size': len(data), | ||
| } | ||
|
|
||
| idx_prefix = integrity_hex[:2] | ||
| idx_rest = integrity_hex[2:64] | ||
| pkg_id = _SANITIZE_RE.sub('+', f'{pkg_name}@{pkg_version}') | ||
| idx_dir = os.path.join(store, 'index', idx_prefix) | ||
| os.makedirs(idx_dir, exist_ok=True) | ||
| idx_path = os.path.join(idx_dir, f'{idx_rest}-{pkg_id}.json') | ||
| index_data = { | ||
| 'name': pkg_name, | ||
| 'version': pkg_version, | ||
| 'files': index_files, | ||
| } | ||
| with open(idx_path, 'w', encoding='utf-8') as out: | ||
| json.dump(index_data, out) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| if len(sys.argv) != 4: | ||
| print( | ||
| f'Usage: {sys.argv[0]} <manifest.json> <tarball-dir> <store-dir>', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
| populate_store(sys.argv[1], sys.argv[2], sys.argv[3]) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs
os.chmod(cas_path, member.mode)or something to preserve executable files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this: