From f981c737c4cd4958a4f96454c1fa3d80bb6e5546 Mon Sep 17 00:00:00 2001 From: Creeperkatze Date: Mon, 5 Oct 2026 18:10:29 +0200 Subject: [PATCH 1/2] node: Fix missing bins with pnpm v12 --- node/README.md | 3 + .../populate_pnpm_store.py | 22 +++++- node/tests/test_populate_pnpm_store.py | 67 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/node/README.md b/node/README.md index f9c4d41b..6dbba606 100644 --- a/node/README.md +++ b/node/README.md @@ -109,6 +109,9 @@ containing all the sources needed for the given package manager. If you're on npm or pnpm and you don't want to include devel dependencies, pass `--no-devel`. For npm, also pass `--production` to `npm install` itself. +For pnpm v12, pass `--pnpm-store-version v11` and run `pnpm install --offline --frozen-lockfile --trust-lockfile`. +Without `--trust-lockfile`, pnpm checks the lockfile against the registry and fails offline. + If you're using npm, you must run this script when the `node_modules` directory is **NOT** present. If you generate the `generated-sources.json` in CI, you can do this by passing `--package-lock-only` to `npm install`. diff --git a/node/flatpak_node_generator/populate_pnpm_store.py b/node/flatpak_node_generator/populate_pnpm_store.py index 5d5dad45..26997cc5 100644 --- a/node/flatpak_node_generator/populate_pnpm_store.py +++ b/node/flatpak_node_generator/populate_pnpm_store.py @@ -15,6 +15,21 @@ _SANITIZE_RE = re.compile(r'[\\/:*?"<>|]') _MAX_LENGTH_WITHOUT_HASH = 120 +_MANIFEST_FIELDS = ( + 'bin', + 'bundleDependencies', + 'bundledDependencies', + 'cpu', + 'dependencies', + 'devDependencies', + 'directories', + 'engines', + 'libc', + 'optionalDependencies', + 'os', + 'peerDependencies', + 'peerDependenciesMeta', +) def _msgpack_pack(obj: object) -> bytes: @@ -120,7 +135,7 @@ def _requires_prepare( def _pack_v11_store_entry( files: dict[str, dict[str, object]], - manifest: dict[str, str] | None = None, + manifest: Mapping[str, object] | None = None, requires_prepare: bool | None = None, ) -> bytes: """Encode a store v11 entry using msgpackr-compatible record extensions. @@ -250,6 +265,7 @@ def _process_tarball( real_pkg_version = pkg_version pkg_scripts: Mapping[str, object] | None = None pkg_main: str | None = None + pkg_manifest: dict[str, object] = {} rel_names: set[str] = set() with tarfile.open(tarball_path, 'r:gz') as tf: @@ -275,6 +291,9 @@ def _process_tarball( pkg_scripts = pkg_data['scripts'] if isinstance(pkg_data.get('main'), str): pkg_main = pkg_data['main'] + pkg_manifest = { + k: pkg_data[k] for k in _MANIFEST_FIELDS if k in pkg_data + } digest = hashlib.sha512(data).digest() file_hex = digest.hex() @@ -326,6 +345,7 @@ def _process_tarball( manifest = None if real_pkg_name or real_pkg_version: manifest = { + **pkg_manifest, 'name': real_pkg_name, 'version': real_pkg_version, } diff --git a/node/tests/test_populate_pnpm_store.py b/node/tests/test_populate_pnpm_store.py index 3431d27f..615ec5ca 100644 --- a/node/tests/test_populate_pnpm_store.py +++ b/node/tests/test_populate_pnpm_store.py @@ -513,6 +513,73 @@ def test_process_tarball_v11(tmp_path: Path) -> None: db.close() +def test_process_tarball_v11_manifest_fields(tmp_path: Path) -> None: + tar_path = tmp_path / 'pkg.tgz' + store_dir = tmp_path / 'store' / 'v11' + pkg_json = json.dumps( + { + 'name': 'real-pkg', + 'version': '1.2.3', + 'bin': {'real-pkg': 'bin/cli.js'}, + 'dependencies': {'dep': '^1.0.0'}, + 'engines': {'node': '>=18'}, + 'description': 'not kept', + 'scripts': {'test': 'not kept'}, + } + ) + + _create_tarball( + tar_path, + {'package/package.json': pkg_json, 'package/bin/cli.js': "console.log('hi');"}, + ) + + store_dir.mkdir(parents=True, exist_ok=True) + db = sqlite3.connect(str(store_dir / 'index.db')) + db.execute( + 'CREATE TABLE IF NOT EXISTS package_index (' + ' key TEXT PRIMARY KEY,' + ' data BLOB NOT NULL' + ') WITHOUT ROWID' + ) + + integrity = Integrity( + 'sha256', 'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2' + ) + + try: + _process_tarball( + tarball_path=str(tar_path), + pkg_name='real-pkg', + pkg_version='1.2.3', + integrity=integrity.to_base64(), + integrity_digest=integrity.digest, + integrity_algo=integrity.algorithm, + store=str(store_dir), + now=1234567890, + store_version='v11', + index_db=db, + ) + db.commit() + + expected_key = f'{integrity.algorithm}-{integrity.to_base64()}\treal-pkg@1.2.3' + row = db.execute( + 'SELECT data FROM package_index WHERE key = ?', (expected_key,) + ).fetchone() + assert row is not None + + # pnpm v12 links bins from the manifest in the store index + data = _decode_v11(row[0]) + assert data['manifest'] == { + 'name': 'real-pkg', + 'version': '1.2.3', + 'bin': {'real-pkg': 'bin/cli.js'}, + 'dependencies': {'dep': '^1.0.0'}, + 'engines': {'node': '>=18'}, + } + finally: + db.close() + + def test_process_tarball_v11_no_package_json(tmp_path: Path) -> None: tar_path = tmp_path / 'pkg.tgz' store_dir = tmp_path / 'store' / 'v11' From 85d88fdb5f28dfa39e23b886db41d151020462aa Mon Sep 17 00:00:00 2001 From: Creeperkatze Date: Sun, 11 Oct 2026 10:32:44 +0200 Subject: [PATCH 2/2] node: Match pnpm's store index manifest fields, add comment --- .../populate_pnpm_store.py | 17 +++++++++++++++-- node/tests/test_populate_pnpm_store.py | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/node/flatpak_node_generator/populate_pnpm_store.py b/node/flatpak_node_generator/populate_pnpm_store.py index 26997cc5..df408d2f 100644 --- a/node/flatpak_node_generator/populate_pnpm_store.py +++ b/node/flatpak_node_generator/populate_pnpm_store.py @@ -15,21 +15,24 @@ _SANITIZE_RE = re.compile(r'[\\/:*?"<>|]') _MAX_LENGTH_WITHOUT_HASH = 120 +# These are package.json fields pnpm keeps in its store index (normalizeBundledManifest.ts) _MANIFEST_FIELDS = ( 'bin', - 'bundleDependencies', 'bundledDependencies', + 'bundleDependencies', 'cpu', 'dependencies', 'devDependencies', 'directories', 'engines', + 'gypfile', 'libc', 'optionalDependencies', 'os', 'peerDependencies', 'peerDependenciesMeta', ) +_MANIFEST_LIFECYCLE_SCRIPTS = ('preinstall', 'install', 'postinstall') def _msgpack_pack(obj: object) -> bytes: @@ -292,8 +295,18 @@ def _process_tarball( if isinstance(pkg_data.get('main'), str): pkg_main = pkg_data['main'] pkg_manifest = { - k: pkg_data[k] for k in _MANIFEST_FIELDS if k in pkg_data + k: pkg_data[k] + for k in _MANIFEST_FIELDS + if pkg_data.get(k) is not None } + if pkg_scripts is not None: + lifecycle_scripts = { + k: pkg_scripts[k] + for k in _MANIFEST_LIFECYCLE_SCRIPTS + if pkg_scripts.get(k) + } + if lifecycle_scripts: + pkg_manifest['scripts'] = lifecycle_scripts digest = hashlib.sha512(data).digest() file_hex = digest.hex() diff --git a/node/tests/test_populate_pnpm_store.py b/node/tests/test_populate_pnpm_store.py index 615ec5ca..b1a08a2f 100644 --- a/node/tests/test_populate_pnpm_store.py +++ b/node/tests/test_populate_pnpm_store.py @@ -523,8 +523,10 @@ def test_process_tarball_v11_manifest_fields(tmp_path: Path) -> None: 'bin': {'real-pkg': 'bin/cli.js'}, 'dependencies': {'dep': '^1.0.0'}, 'engines': {'node': '>=18'}, + 'gypfile': True, + 'os': None, 'description': 'not kept', - 'scripts': {'test': 'not kept'}, + 'scripts': {'postinstall': 'node install.js', 'test': 'not kept'}, } ) @@ -575,6 +577,8 @@ def test_process_tarball_v11_manifest_fields(tmp_path: Path) -> None: 'bin': {'real-pkg': 'bin/cli.js'}, 'dependencies': {'dep': '^1.0.0'}, 'engines': {'node': '>=18'}, + 'gypfile': True, + 'scripts': {'postinstall': 'node install.js'}, } finally: db.close()