app-builder-lib 26.16.1 → 26.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/out/node-module-collector/index.js +48 -15
  2. package/out/node-module-collector/index.js.map +1 -1
  3. package/out/node-module-collector/moduleManager.d.ts +7 -1
  4. package/out/node-module-collector/moduleManager.js +2 -2
  5. package/out/node-module-collector/moduleManager.js.map +1 -1
  6. package/out/node-module-collector/nodeModulesCollector.d.ts +7 -3
  7. package/out/node-module-collector/nodeModulesCollector.js +14 -5
  8. package/out/node-module-collector/nodeModulesCollector.js.map +1 -1
  9. package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +42 -0
  10. package/out/node-module-collector/pnpmNodeModulesCollector.js +146 -0
  11. package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
  12. package/out/targets/FlatpakTarget.js +6 -1
  13. package/out/targets/FlatpakTarget.js.map +1 -1
  14. package/out/targets/archive.d.ts +12 -0
  15. package/out/targets/archive.js +45 -1
  16. package/out/targets/archive.js.map +1 -1
  17. package/out/targets/nsis/NsisTarget.js +4 -0
  18. package/out/targets/nsis/NsisTarget.js.map +1 -1
  19. package/out/targets/nsis/nsisOptions.d.ts +15 -2
  20. package/out/targets/nsis/nsisOptions.js.map +1 -1
  21. package/out/targets/pkg.d.ts +16 -0
  22. package/out/targets/pkg.js +27 -0
  23. package/out/targets/pkg.js.map +1 -1
  24. package/out/util/appFileCopier.d.ts +5 -0
  25. package/out/util/appFileCopier.js +19 -1
  26. package/out/util/appFileCopier.js.map +1 -1
  27. package/out/version.d.ts +1 -1
  28. package/out/version.js +1 -1
  29. package/out/version.js.map +1 -1
  30. package/package.json +7 -7
  31. package/scheme.json +16 -4
@@ -1,3 +1,4 @@
1
+ import { Lazy } from "lazy-val";
1
2
  import { NodeModulesCollector } from "./nodeModulesCollector";
2
3
  import { PM } from "./packageManager";
3
4
  import { PnpmDependency } from "./types";
@@ -9,6 +10,30 @@ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmD
9
10
  private _allWorkspacePackages;
10
11
  private _pnpmMajorVersion;
11
12
  private readonly pnpmVersion;
13
+ /**
14
+ * Detect pnpm's installed layout from the on-disk structure rather than `pnpm config list`.
15
+ * pnpm 11 no longer echoes `node-linker` (from `.npmrc`) in `config list`, so the base-class
16
+ * config-parsing detection silently reports "not hoisted" for a hoisted install, which would
17
+ * disable the downward search needed to find version-conflicted nested deps.
18
+ *
19
+ * In the default isolated store every regular top-level package resolves — through a symlink
20
+ * on POSIX, a junction on Windows — into `node_modules/.pnpm/<name>@<ver>/node_modules/<name>`.
21
+ * In a hoisted layout the same package is a real directory directly under `node_modules`.
22
+ * `realpath` transparently follows both symlinks and junctions, so a layout is isolated iff
23
+ * *any* top-level package's real path routes through `.pnpm`. We scan rather than sample the
24
+ * first entry because `link:` packages resolve to their source (never under `.pnpm`) and could
25
+ * otherwise mask an isolated store.
26
+ */
27
+ protected isHoisted: Lazy<boolean>;
28
+ /**
29
+ * The pnpm workspace root containing `rootDir` (nearest ancestor with `pnpm-workspace.yaml`, as pnpm
30
+ * itself resolves it), or null outside a workspace or when `rootDir` is the workspace root.
31
+ */
32
+ private readonly workspaceRoot;
33
+ /** `rootDir`, then the workspace root when `rootDir` is a workspace package. */
34
+ private readonly layoutRoots;
35
+ /** Returns true if `nmDir` is an isolated (`.pnpm`) store, false if hoisted, null if it holds no packages. */
36
+ private scanNodeModulesLayout;
12
37
  /**
13
38
  * Memo for `locateFromDepOrRoot`, keyed by `name@version`. pnpm's content-addressed virtual
14
39
  * store guarantees that any given `name@version` resolves to a single location on disk, so
@@ -22,6 +47,9 @@ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmD
22
47
  * every shared subtree of the pnpm list output, exploding work in deep workspaces.
23
48
  */
24
49
  private readonly collectedDeps;
50
+ /** Reverse index of `allDependencies` keyed by package name (without version). Built once on
51
+ * first access inside `extractProductionDependencyGraph`, after `allDependencies` is settled. */
52
+ private _allDepsByName;
25
53
  /**
26
54
  * Returns the workspace packages to iterate over, gated by detected pnpm version:
27
55
  * - pnpm v11+: multi-entry workspace output → return the full parsed array
@@ -29,6 +57,7 @@ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmD
29
57
  */
30
58
  private get allWorkspacePackages();
31
59
  protected getArgs(): string[];
60
+ private getAllDepsByName;
32
61
  /**
33
62
  * Locate a package version, preferring the dep's own reported path before falling back to rootDir.
34
63
  * This is critical for pnpm non-hoisted (virtual store) setups where each package has its own
@@ -37,6 +66,19 @@ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmD
37
66
  */
38
67
  private locateFromDepOrRoot;
39
68
  protected extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string): Promise<void>;
69
+ /**
70
+ * Resolve a dependency that `pnpm list` left out of a package's tree to its `allDependencies` entry.
71
+ * The lookup goes through the copy node itself would load from `parentPath` (the package's real store
72
+ * directory), filtered by the declared range, and falls back to a name-only match only when nothing on
73
+ * disk resolves to a collected entry (a `link:` dep, whose entry is keyed by its `link:` version).
74
+ *
75
+ * A name-only lookup returns whichever version was collected first, which is wrong as soon as two
76
+ * versions of the package are installed: with the app pinning es5-ext@0.10.53 while its transitive
77
+ * d@1.0.2 needs es5-ext ^0.10.64, `d` was wired to 0.10.53 and the nested 0.10.64 copy (with its own
78
+ * esniff / event-emitter / next-tick@1.1.0 closure) vanished from the asar (#8493). pnpm 10.29.3+
79
+ * made this common, because its deduped output routes every repeated package through this recovery.
80
+ */
81
+ private resolveOmittedDependency;
40
82
  protected collectAllDependencies(_tree: PnpmDependency, _appPackageName: string): Promise<void>;
41
83
  private collectDepsRecursively;
42
84
  protected getTreeFromWorkspaces(tree: PnpmDependency, packageName: string): PnpmDependency;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PnpmNodeModulesCollector = void 0;
4
+ const fs = require("fs-extra");
4
5
  const lazy_val_1 = require("lazy-val");
6
+ const path = require("path");
5
7
  const moduleManager_1 = require("./moduleManager");
6
8
  const nodeModulesCollector_1 = require("./nodeModulesCollector");
7
9
  const packageManager_1 = require("./packageManager");
10
+ const builder_util_1 = require("builder-util");
8
11
  class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
9
12
  constructor() {
10
13
  super(...arguments);
@@ -23,6 +26,58 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
23
26
  const major = parseInt(((_a = result.stdout) !== null && _a !== void 0 ? _a : "0").split(".")[0], 10);
24
27
  return isNaN(major) ? 0 : major;
25
28
  });
29
+ /**
30
+ * Detect pnpm's installed layout from the on-disk structure rather than `pnpm config list`.
31
+ * pnpm 11 no longer echoes `node-linker` (from `.npmrc`) in `config list`, so the base-class
32
+ * config-parsing detection silently reports "not hoisted" for a hoisted install, which would
33
+ * disable the downward search needed to find version-conflicted nested deps.
34
+ *
35
+ * In the default isolated store every regular top-level package resolves — through a symlink
36
+ * on POSIX, a junction on Windows — into `node_modules/.pnpm/<name>@<ver>/node_modules/<name>`.
37
+ * In a hoisted layout the same package is a real directory directly under `node_modules`.
38
+ * `realpath` transparently follows both symlinks and junctions, so a layout is isolated iff
39
+ * *any* top-level package's real path routes through `.pnpm`. We scan rather than sample the
40
+ * first entry because `link:` packages resolve to their source (never under `.pnpm`) and could
41
+ * otherwise mask an isolated store.
42
+ */
43
+ this.isHoisted = new lazy_val_1.Lazy(async () => {
44
+ // A workspace package's own `node_modules` is often absent (or holds only its version
45
+ // conflicts) in a hoisted workspace, so fall back to the workspace root's `node_modules`.
46
+ let sawPackage = false;
47
+ for (const dir of await this.layoutRoots.value) {
48
+ const isolated = await this.scanNodeModulesLayout(path.join(dir, "node_modules"));
49
+ if (isolated != null) {
50
+ if (isolated) {
51
+ return false;
52
+ }
53
+ sawPackage = true;
54
+ }
55
+ }
56
+ // Packages exist and none route through `.pnpm` → hoisted. No packages → flat default.
57
+ return sawPackage;
58
+ });
59
+ /**
60
+ * The pnpm workspace root containing `rootDir` (nearest ancestor with `pnpm-workspace.yaml`, as pnpm
61
+ * itself resolves it), or null outside a workspace or when `rootDir` is the workspace root.
62
+ */
63
+ this.workspaceRoot = new lazy_val_1.Lazy(async () => {
64
+ let current = path.resolve(this.rootDir);
65
+ while (true) {
66
+ if (await (0, builder_util_1.exists)(path.join(current, "pnpm-workspace.yaml"))) {
67
+ return current === path.resolve(this.rootDir) ? null : current;
68
+ }
69
+ const parent = path.dirname(current);
70
+ if (parent === current) {
71
+ return null;
72
+ }
73
+ current = parent;
74
+ }
75
+ });
76
+ /** `rootDir`, then the workspace root when `rootDir` is a workspace package. */
77
+ this.layoutRoots = new lazy_val_1.Lazy(async () => {
78
+ const workspaceRoot = await this.workspaceRoot.value;
79
+ return workspaceRoot == null ? [this.rootDir] : [this.rootDir, workspaceRoot];
80
+ });
26
81
  /**
27
82
  * Memo for `locateFromDepOrRoot`, keyed by `name@version`. pnpm's content-addressed virtual
28
83
  * store guarantees that any given `name@version` resolves to a single location on disk, so
@@ -36,6 +91,33 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
36
91
  * every shared subtree of the pnpm list output, exploding work in deep workspaces.
37
92
  */
38
93
  this.collectedDeps = new Set();
94
+ /** Reverse index of `allDependencies` keyed by package name (without version). Built once on
95
+ * first access inside `extractProductionDependencyGraph`, after `allDependencies` is settled. */
96
+ this._allDepsByName = null;
97
+ }
98
+ /** Returns true if `nmDir` is an isolated (`.pnpm`) store, false if hoisted, null if it holds no packages. */
99
+ async scanNodeModulesLayout(nmDir) {
100
+ const entries = await fs.readdir(nmDir).catch(() => []);
101
+ let sawPackage = false;
102
+ for (const name of entries) {
103
+ if (name.startsWith(".")) {
104
+ continue; // .pnpm, .bin, .modules.yaml
105
+ }
106
+ const entryPath = path.join(nmDir, name);
107
+ // A scoped dir (@scope) is not a package itself; descend to its packages.
108
+ const candidates = name.startsWith("@") ? (await fs.readdir(entryPath).catch(() => [])).map(s => path.join(entryPath, s)) : [entryPath];
109
+ for (const candidate of candidates) {
110
+ const real = await fs.realpath(candidate).catch(() => null);
111
+ if (real == null) {
112
+ continue;
113
+ }
114
+ sawPackage = true;
115
+ if (real.split(path.sep).includes(".pnpm")) {
116
+ return true; // isolated store: a package routes through the virtual store
117
+ }
118
+ }
119
+ }
120
+ return sawPackage ? false : null;
39
121
  }
40
122
  /**
41
123
  * Returns the workspace packages to iterate over, gated by detected pnpm version:
@@ -51,6 +133,18 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
51
133
  getArgs() {
52
134
  return ["list", "--prod", "--json", "--depth", "Infinity", "--silent", "--loglevel=error"];
53
135
  }
136
+ getAllDepsByName() {
137
+ if (!this._allDepsByName) {
138
+ this._allDepsByName = new Map();
139
+ for (const [id, dep] of this.allDependencies.entries()) {
140
+ const { name } = this.parseNameVersion(id);
141
+ if (!this._allDepsByName.has(name)) {
142
+ this._allDepsByName.set(name, dep);
143
+ }
144
+ }
145
+ }
146
+ return this._allDepsByName;
147
+ }
54
148
  /**
55
149
  * Locate a package version, preferring the dep's own reported path before falling back to rootDir.
56
150
  * This is critical for pnpm non-hoisted (virtual store) setups where each package has its own
@@ -76,6 +170,27 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
76
170
  // land at `<root>/node_modules/A/node_modules/B` — downward BFS is needed to find them.
77
171
  const skipDownwardSearch = !(await this.isHoisted.value);
78
172
  const promise = (async () => {
173
+ // Phase 1: find a version that SATISFIES requiredRange, trying the dep's own location
174
+ // first, then the workspace root. Crucially, neither pass accepts an out-of-range override
175
+ // here — so a wrong-version copy reachable via upward search from `parentPath` (e.g. a
176
+ // hoisted top-level dep) can't shadow the correct nested copy under root. With
177
+ // `nodeLinker: hoisted`, pnpm still reports virtual-store `path`s that don't exist on disk;
178
+ // an upward walk from one meets the root copy, which previously got accepted as an
179
+ // "override" before the root search (whose downward BFS finds the nested copy) ever ran.
180
+ //
181
+ // When `rootDir` is a workspace package, a hoisted install keeps the tree — including the
182
+ // nested `<workspaceRoot>/node_modules/A/node_modules/B` copies — under the workspace root,
183
+ // which the downward BFS from `rootDir` never reaches (its `node_modules` is often absent),
184
+ // so search the workspace root last.
185
+ let satisfying = parentPath ? await this.cache.locatePackageVersion({ pkgName, parentDir: parentPath, requiredRange, skipDownwardSearch, skipOverrideFallback: true }) : null;
186
+ for (const dir of await this.layoutRoots.value) {
187
+ satisfying !== null && satisfying !== void 0 ? satisfying : (satisfying = await this.cache.locatePackageVersion({ pkgName, parentDir: dir, requiredRange, skipDownwardSearch, skipOverrideFallback: true }));
188
+ }
189
+ if (satisfying) {
190
+ return satisfying;
191
+ }
192
+ // Phase 2: no version satisfies requiredRange (package-manager override, or no range
193
+ // given). Fall back to the original dep-then-root order, now allowing override versions.
79
194
  const fromDep = parentPath ? await this.cache.locatePackageVersion({ pkgName, parentDir: parentPath, requiredRange, skipDownwardSearch }) : null;
80
195
  if (fromDep) {
81
196
  return fromDep;
@@ -113,6 +228,19 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
113
228
  const all = packageJson ? { ...packageJson.dependencies, ...packageJson.optionalDependencies } : { ...tree.dependencies, ...tree.optionalDependencies };
114
229
  const optional = packageJson ? { ...packageJson.optionalDependencies } : {};
115
230
  const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
231
+ // pnpm --prod omits sub-deps for link: packages (and synthetic entries derived from them), and pnpm
232
+ // 10.29.3+ prints a repeated subtree only once, so every later occurrence is a childless `deduped`
233
+ // stub (which is what `tree` is when the stub was the first occurrence collected). For any dep
234
+ // declared in the package.json (all) that pnpm left out of the tree, recover the resolved entry
235
+ // from allDependencies so it lands in the production graph.
236
+ for (const [depName, declaredRange] of Object.entries(all)) {
237
+ if (!deps[depName]) {
238
+ const dep = await this.resolveOmittedDependency(depName, declaredRange, tree.path);
239
+ if (dep && (0, builder_util_1.isValidKey)(depName)) {
240
+ deps[depName] = dep;
241
+ }
242
+ }
243
+ }
116
244
  this.productionGraph[dependencyId] = { dependencies: [] };
117
245
  const depPromises = Object.entries(deps).map(async ([packageName, dependency]) => {
118
246
  // First check if it's in production dependencies
@@ -142,6 +270,24 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
142
270
  }
143
271
  this.productionGraph[dependencyId] = { dependencies: collectedDependencies };
144
272
  }
273
+ /**
274
+ * Resolve a dependency that `pnpm list` left out of a package's tree to its `allDependencies` entry.
275
+ * The lookup goes through the copy node itself would load from `parentPath` (the package's real store
276
+ * directory), filtered by the declared range, and falls back to a name-only match only when nothing on
277
+ * disk resolves to a collected entry (a `link:` dep, whose entry is keyed by its `link:` version).
278
+ *
279
+ * A name-only lookup returns whichever version was collected first, which is wrong as soon as two
280
+ * versions of the package are installed: with the app pinning es5-ext@0.10.53 while its transitive
281
+ * d@1.0.2 needs es5-ext ^0.10.64, `d` was wired to 0.10.53 and the nested 0.10.64 copy (with its own
282
+ * esniff / event-emitter / next-tick@1.1.0 closure) vanished from the asar (#8493). pnpm 10.29.3+
283
+ * made this common, because its deduped output routes every repeated package through this recovery.
284
+ */
285
+ async resolveOmittedDependency(depName, declaredRange, parentPath) {
286
+ const range = typeof declaredRange === "string" ? declaredRange : undefined;
287
+ const located = await this.locateFromDepOrRoot(depName, parentPath, range);
288
+ const exact = located ? this.allDependencies.get(`${depName}@${located.packageJson.version}`) : undefined;
289
+ return exact !== null && exact !== void 0 ? exact : this.getAllDepsByName().get(depName);
290
+ }
145
291
  async collectAllDependencies(_tree, _appPackageName) {
146
292
  for (const root of this.allWorkspacePackages) {
147
293
  await this.collectDepsRecursively(root);
@@ -1 +1 @@
1
- {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,uCAA+B;AAC/B,mDAA+D;AAC/D,iEAA6D;AAC7D,qDAA+D;AAG/D,MAAa,wBAAyB,SA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F,IAAI,CAAC,qBAAqB,GAAG,cAAc,CAAA;QAC3C,IAAI,CAAC,iBAAiB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAA;QACrD,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF;AApMD,4DAoMC","sourcesContent":["import { Lazy } from \"lazy-val\"\nimport { LogMessageByKey, type Package } from \"./moduleManager\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { getPackageManagerCommand, PM } from \"./packageManager\"\nimport { PnpmDependency } from \"./types\"\n\nexport class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {\n public readonly installOptions = {\n manager: PM.PNPM,\n lockfile: \"pnpm-lock.yaml\",\n }\n\n // Raw backing field — all entries from `pnpm list --json`\n private _allWorkspacePackages: PnpmDependency[] = []\n // Cached after parseDependenciesTree resolves the Lazy; 0 = safe default (treated as < v11)\n private _pnpmMajorVersion = 0\n // Runs `pnpm --version` once and caches the major version number\n private readonly pnpmVersion = new Lazy<number>(async () => {\n const result = await this.asyncExec(getPackageManagerCommand(PM.PNPM), [\"--version\"])\n const major = parseInt((result.stdout ?? \"0\").split(\".\")[0], 10)\n return isNaN(major) ? 0 : major\n })\n\n /**\n * Memo for `locateFromDepOrRoot`, keyed by `name@version`. pnpm's content-addressed virtual\n * store guarantees that any given `name@version` resolves to a single location on disk, so\n * once we've resolved a package we can short-circuit every subsequent lookup. This is the\n * dominant speedup for large workspaces where the `pnpm list --json` tree contains the same\n * `name@version` thousands of times (one entry per dependent).\n */\n private readonly locateMemo: Map<string, Promise<Package | null>> = new Map()\n\n /**\n * Visited set for `collectDepsRecursively`, keyed by `name@version`. Without this we re-walk\n * every shared subtree of the pnpm list output, exploding work in deep workspaces.\n */\n private readonly collectedDeps: Set<string> = new Set()\n\n /**\n * Returns the workspace packages to iterate over, gated by detected pnpm version:\n * - pnpm v11+: multi-entry workspace output → return the full parsed array\n * - pnpm < v11 / non-workspace / detection failure: single-tree behavior → return only [0]\n */\n private get allWorkspacePackages(): PnpmDependency[] {\n if (this._pnpmMajorVersion >= 11) {\n return this._allWorkspacePackages\n }\n return this._allWorkspacePackages.slice(0, 1)\n }\n\n protected getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\", \"--silent\", \"--loglevel=error\"]\n }\n\n /**\n * Locate a package version, preferring the dep's own reported path before falling back to rootDir.\n * This is critical for pnpm non-hoisted (virtual store) setups where each package has its own\n * nested node_modules. Searching only from rootDir can resolve the wrong version when multiple\n * versions of a dep exist in the workspace.\n */\n private async locateFromDepOrRoot(pkgName: string, parentPath: string | undefined, requiredRange?: string) {\n // pnpm's virtual store is content-addressed: every `name@version` lookup is deterministic,\n // so memoize on the exact version. `requiredRange` is normally an exact version coming from\n // the pnpm list output (e.g. `value.version`), which makes this cache hit on duplicates.\n // Only memoize when we have a concrete version — semver ranges could resolve differently\n // depending on what's installed at `parentPath` vs root, so skip the cache for those.\n const memoKey = requiredRange && /^\\d/.test(requiredRange) ? `${pkgName}@${requiredRange}` : null\n if (memoKey != null) {\n const cached = this.locateMemo.get(memoKey)\n if (cached != null) {\n return cached\n }\n }\n\n // pnpm's default `.pnpm` virtual store is flat, so `downwardSearch` would burn thousands\n // of `readdir`/`lstat` calls finding nothing. With `nodeLinker: hoisted`, however, the\n // layout is a traditional nested `node_modules` tree where version-conflicted packages\n // land at `<root>/node_modules/A/node_modules/B` — downward BFS is needed to find them.\n const skipDownwardSearch = !(await this.isHoisted.value)\n const promise = (async (): Promise<Package | null> => {\n const fromDep = parentPath ? await this.cache.locatePackageVersion({ pkgName, parentDir: parentPath, requiredRange, skipDownwardSearch }) : null\n if (fromDep) {\n return fromDep\n }\n return this.cache.locatePackageVersion({ pkgName, parentDir: this.rootDir, requiredRange, skipDownwardSearch })\n })()\n\n if (memoKey != null) {\n this.locateMemo.set(memoKey, promise)\n }\n return promise\n }\n\n // pnpm 10+ does not automatically preserve transitive optional platform-specific\n // packages (e.g. sass-embedded-linux-x64) across lock file regeneration. Users\n // must list them as direct optionalDependencies. Missing ones are emitted as\n // PKG_OPTIONAL_PLATFORM_NOT_INSTALLED warnings in the log summary.\n protected async extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string) {\n if (this.productionGraph[dependencyId]) {\n return\n }\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n if ((tree.dedupedDependenciesCount ?? 0) > 0) {\n const realDep = this.allDependencies.get(dependencyId)\n if (realDep) {\n this.cache.logSummary[LogMessageByKey.PKG_DUPLICATE_REF].push(dependencyId)\n tree = realDep\n } else {\n this.cache.logSummary[LogMessageByKey.PKG_DUPLICATE_REF_UNRESOLVED].push(dependencyId)\n return\n }\n }\n\n const packageName = tree.name || tree.from\n const { packageJson } = (await this.locateFromDepOrRoot(packageName, tree.path, tree.version)) || {}\n\n const all = packageJson ? { ...packageJson.dependencies, ...packageJson.optionalDependencies } : { ...tree.dependencies, ...tree.optionalDependencies }\n const optional = packageJson ? { ...packageJson.optionalDependencies } : {}\n\n const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) }\n this.productionGraph[dependencyId] = { dependencies: [] }\n const depPromises = Object.entries(deps).map(async ([packageName, dependency]) => {\n // First check if it's in production dependencies\n if (!all[packageName]) {\n return undefined\n }\n\n // Then check if optional dependency path exists (using actual resolved path)\n if (optional[packageName]) {\n const pkg = await this.locateFromDepOrRoot(packageName, tree.path, dependency.version)\n if (!pkg) {\n // Declared in `optionalDependencies`, so a miss is an expected condition (e.g. fsevents\n // on Linux/Windows) — classify it as a missing optional dependency, not PKG_NOT_ON_DISK.\n this.logMissingDependency(`${packageName}@${dependency.version}`, true)\n return undefined\n }\n }\n const { id: childDependencyId, pkgOverride } = this.normalizePackageVersion(packageName, dependency)\n await this.extractProductionDependencyGraph(pkgOverride, childDependencyId)\n return childDependencyId\n })\n\n const collectedDependencies: string[] = []\n for (const dep of depPromises) {\n const result = await dep\n if (result !== undefined) {\n collectedDependencies.push(result)\n }\n }\n this.productionGraph[dependencyId] = { dependencies: collectedDependencies }\n }\n\n protected async collectAllDependencies(_tree: PnpmDependency, _appPackageName: string): Promise<void> {\n for (const root of this.allWorkspacePackages) {\n await this.collectDepsRecursively(root)\n }\n }\n\n private async collectDepsRecursively(tree: PnpmDependency): Promise<void> {\n const visit = async (key: string, value: PnpmDependency) => {\n if ((value?.dedupedDependenciesCount ?? 0) > 0) {\n return\n }\n const id = `${key}@${value.version}`\n // The pnpm list output can include the same `name@version` thousands of times across a\n // deep workspace; without this guard we re-resolve and re-recurse each occurrence.\n if (this.collectedDeps.has(id)) {\n return\n }\n this.collectedDeps.add(id)\n const pkg = await this.locateFromDepOrRoot(key, value.path, value.version)\n this.allDependencies.set(id, { ...value, path: pkg?.packageDir ?? value.path })\n await this.collectDepsRecursively(value)\n }\n\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n await visit(key, value)\n }\n for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {\n await visit(key, value)\n }\n }\n\n protected override getTreeFromWorkspaces(tree: PnpmDependency, packageName: string): PnpmDependency {\n // pnpm v10 workspace: app is nested as a dependency of root — handled by base class\n const result = super.getTreeFromWorkspaces(tree, packageName)\n if (result !== tree) {\n return result\n }\n // pnpm v11 workspace: each workspace package is a separate top-level array entry;\n // non-workspace (single-tree): find returns the one entry or undefined → falls back to tree\n const match = this.allWorkspacePackages.find(pkg => pkg.name === packageName || pkg.from === packageName)\n return match ?? tree\n }\n\n protected async parseDependenciesTree(jsonBlob: string): Promise<PnpmDependency> {\n const dependencyTree = this.extractJsonFromPollutedOutput<PnpmDependency[]>(jsonBlob)\n this._allWorkspacePackages = dependencyTree\n this._pnpmMajorVersion = await this.pnpmVersion.value\n return dependencyTree[0]\n }\n}\n"]}
1
+ {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,uCAA+B;AAC/B,6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,CAAC,CAAA;QAC7D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,MAAM,CAAA;QACf,CAAC;QACD,kFAAkF;QAClF,4FAA4F;QAC5F,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;QACzG,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,CAAA;IACtB,CAAC;IAES,KAAK,CAAC,qBAAqB,CAAC,QAAgB;QACpD,MAAM,cAAc,GAAG,IAAI,CAAC,6BAA6B,CAAmB,QAAQ,CAAC,CAAA;QACrF,IAAI,CAAC,qBAAqB,GAAG,cAAc,CAAA;QAC3C,IAAI,CAAC,iBAAiB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAA;QACrD,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF;AA5VD,4DA4VC","sourcesContent":["import * as fs from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { LogMessageByKey, type Package } from \"./moduleManager\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { getPackageManagerCommand, PM } from \"./packageManager\"\nimport { PnpmDependency } from \"./types\"\nimport { exists, isValidKey } from \"builder-util\"\n\nexport class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {\n public readonly installOptions = {\n manager: PM.PNPM,\n lockfile: \"pnpm-lock.yaml\",\n }\n\n // Raw backing field — all entries from `pnpm list --json`\n private _allWorkspacePackages: PnpmDependency[] = []\n // Cached after parseDependenciesTree resolves the Lazy; 0 = safe default (treated as < v11)\n private _pnpmMajorVersion = 0\n // Runs `pnpm --version` once and caches the major version number\n private readonly pnpmVersion = new Lazy<number>(async () => {\n const result = await this.asyncExec(getPackageManagerCommand(PM.PNPM), [\"--version\"])\n const major = parseInt((result.stdout ?? \"0\").split(\".\")[0], 10)\n return isNaN(major) ? 0 : major\n })\n\n /**\n * Detect pnpm's installed layout from the on-disk structure rather than `pnpm config list`.\n * pnpm 11 no longer echoes `node-linker` (from `.npmrc`) in `config list`, so the base-class\n * config-parsing detection silently reports \"not hoisted\" for a hoisted install, which would\n * disable the downward search needed to find version-conflicted nested deps.\n *\n * In the default isolated store every regular top-level package resolves — through a symlink\n * on POSIX, a junction on Windows — into `node_modules/.pnpm/<name>@<ver>/node_modules/<name>`.\n * In a hoisted layout the same package is a real directory directly under `node_modules`.\n * `realpath` transparently follows both symlinks and junctions, so a layout is isolated iff\n * *any* top-level package's real path routes through `.pnpm`. We scan rather than sample the\n * first entry because `link:` packages resolve to their source (never under `.pnpm`) and could\n * otherwise mask an isolated store.\n */\n protected override isHoisted = new Lazy<boolean>(async () => {\n // A workspace package's own `node_modules` is often absent (or holds only its version\n // conflicts) in a hoisted workspace, so fall back to the workspace root's `node_modules`.\n let sawPackage = false\n for (const dir of await this.layoutRoots.value) {\n const isolated = await this.scanNodeModulesLayout(path.join(dir, \"node_modules\"))\n if (isolated != null) {\n if (isolated) {\n return false\n }\n sawPackage = true\n }\n }\n // Packages exist and none route through `.pnpm` → hoisted. No packages → flat default.\n return sawPackage\n })\n\n /**\n * The pnpm workspace root containing `rootDir` (nearest ancestor with `pnpm-workspace.yaml`, as pnpm\n * itself resolves it), or null outside a workspace or when `rootDir` is the workspace root.\n */\n private readonly workspaceRoot = new Lazy<string | null>(async () => {\n let current = path.resolve(this.rootDir)\n while (true) {\n if (await exists(path.join(current, \"pnpm-workspace.yaml\"))) {\n return current === path.resolve(this.rootDir) ? null : current\n }\n const parent = path.dirname(current)\n if (parent === current) {\n return null\n }\n current = parent\n }\n })\n\n /** `rootDir`, then the workspace root when `rootDir` is a workspace package. */\n private readonly layoutRoots = new Lazy<string[]>(async () => {\n const workspaceRoot = await this.workspaceRoot.value\n return workspaceRoot == null ? [this.rootDir] : [this.rootDir, workspaceRoot]\n })\n\n /** Returns true if `nmDir` is an isolated (`.pnpm`) store, false if hoisted, null if it holds no packages. */\n private async scanNodeModulesLayout(nmDir: string): Promise<boolean | null> {\n const entries = await fs.readdir(nmDir).catch(() => [] as string[])\n let sawPackage = false\n for (const name of entries) {\n if (name.startsWith(\".\")) {\n continue // .pnpm, .bin, .modules.yaml\n }\n const entryPath = path.join(nmDir, name)\n // A scoped dir (@scope) is not a package itself; descend to its packages.\n const candidates = name.startsWith(\"@\") ? (await fs.readdir(entryPath).catch(() => [] as string[])).map(s => path.join(entryPath, s)) : [entryPath]\n for (const candidate of candidates) {\n const real = await fs.realpath(candidate).catch(() => null)\n if (real == null) {\n continue\n }\n sawPackage = true\n if (real.split(path.sep).includes(\".pnpm\")) {\n return true // isolated store: a package routes through the virtual store\n }\n }\n }\n return sawPackage ? false : null\n }\n\n /**\n * Memo for `locateFromDepOrRoot`, keyed by `name@version`. pnpm's content-addressed virtual\n * store guarantees that any given `name@version` resolves to a single location on disk, so\n * once we've resolved a package we can short-circuit every subsequent lookup. This is the\n * dominant speedup for large workspaces where the `pnpm list --json` tree contains the same\n * `name@version` thousands of times (one entry per dependent).\n */\n private readonly locateMemo: Map<string, Promise<Package | null>> = new Map()\n\n /**\n * Visited set for `collectDepsRecursively`, keyed by `name@version`. Without this we re-walk\n * every shared subtree of the pnpm list output, exploding work in deep workspaces.\n */\n private readonly collectedDeps: Set<string> = new Set()\n\n /** Reverse index of `allDependencies` keyed by package name (without version). Built once on\n * first access inside `extractProductionDependencyGraph`, after `allDependencies` is settled. */\n private _allDepsByName: Map<string, PnpmDependency> | null = null\n\n /**\n * Returns the workspace packages to iterate over, gated by detected pnpm version:\n * - pnpm v11+: multi-entry workspace output → return the full parsed array\n * - pnpm < v11 / non-workspace / detection failure: single-tree behavior → return only [0]\n */\n private get allWorkspacePackages(): PnpmDependency[] {\n if (this._pnpmMajorVersion >= 11) {\n return this._allWorkspacePackages\n }\n return this._allWorkspacePackages.slice(0, 1)\n }\n\n protected getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\", \"--silent\", \"--loglevel=error\"]\n }\n\n private getAllDepsByName(): Map<string, PnpmDependency> {\n if (!this._allDepsByName) {\n this._allDepsByName = new Map()\n for (const [id, dep] of this.allDependencies.entries()) {\n const { name } = this.parseNameVersion(id)\n if (!this._allDepsByName.has(name)) {\n this._allDepsByName.set(name, dep)\n }\n }\n }\n return this._allDepsByName\n }\n\n /**\n * Locate a package version, preferring the dep's own reported path before falling back to rootDir.\n * This is critical for pnpm non-hoisted (virtual store) setups where each package has its own\n * nested node_modules. Searching only from rootDir can resolve the wrong version when multiple\n * versions of a dep exist in the workspace.\n */\n private async locateFromDepOrRoot(pkgName: string, parentPath: string | undefined, requiredRange?: string) {\n // pnpm's virtual store is content-addressed: every `name@version` lookup is deterministic,\n // so memoize on the exact version. `requiredRange` is normally an exact version coming from\n // the pnpm list output (e.g. `value.version`), which makes this cache hit on duplicates.\n // Only memoize when we have a concrete version — semver ranges could resolve differently\n // depending on what's installed at `parentPath` vs root, so skip the cache for those.\n const memoKey = requiredRange && /^\\d/.test(requiredRange) ? `${pkgName}@${requiredRange}` : null\n if (memoKey != null) {\n const cached = this.locateMemo.get(memoKey)\n if (cached != null) {\n return cached\n }\n }\n\n // pnpm's default `.pnpm` virtual store is flat, so `downwardSearch` would burn thousands\n // of `readdir`/`lstat` calls finding nothing. With `nodeLinker: hoisted`, however, the\n // layout is a traditional nested `node_modules` tree where version-conflicted packages\n // land at `<root>/node_modules/A/node_modules/B` — downward BFS is needed to find them.\n const skipDownwardSearch = !(await this.isHoisted.value)\n const promise = (async (): Promise<Package | null> => {\n // Phase 1: find a version that SATISFIES requiredRange, trying the dep's own location\n // first, then the workspace root. Crucially, neither pass accepts an out-of-range override\n // here — so a wrong-version copy reachable via upward search from `parentPath` (e.g. a\n // hoisted top-level dep) can't shadow the correct nested copy under root. With\n // `nodeLinker: hoisted`, pnpm still reports virtual-store `path`s that don't exist on disk;\n // an upward walk from one meets the root copy, which previously got accepted as an\n // \"override\" before the root search (whose downward BFS finds the nested copy) ever ran.\n //\n // When `rootDir` is a workspace package, a hoisted install keeps the tree — including the\n // nested `<workspaceRoot>/node_modules/A/node_modules/B` copies — under the workspace root,\n // which the downward BFS from `rootDir` never reaches (its `node_modules` is often absent),\n // so search the workspace root last.\n let satisfying = parentPath ? await this.cache.locatePackageVersion({ pkgName, parentDir: parentPath, requiredRange, skipDownwardSearch, skipOverrideFallback: true }) : null\n for (const dir of await this.layoutRoots.value) {\n satisfying ??= await this.cache.locatePackageVersion({ pkgName, parentDir: dir, requiredRange, skipDownwardSearch, skipOverrideFallback: true })\n }\n if (satisfying) {\n return satisfying\n }\n // Phase 2: no version satisfies requiredRange (package-manager override, or no range\n // given). Fall back to the original dep-then-root order, now allowing override versions.\n const fromDep = parentPath ? await this.cache.locatePackageVersion({ pkgName, parentDir: parentPath, requiredRange, skipDownwardSearch }) : null\n if (fromDep) {\n return fromDep\n }\n return this.cache.locatePackageVersion({ pkgName, parentDir: this.rootDir, requiredRange, skipDownwardSearch })\n })()\n\n if (memoKey != null) {\n this.locateMemo.set(memoKey, promise)\n }\n return promise\n }\n\n // pnpm 10+ does not automatically preserve transitive optional platform-specific\n // packages (e.g. sass-embedded-linux-x64) across lock file regeneration. Users\n // must list them as direct optionalDependencies. Missing ones are emitted as\n // PKG_OPTIONAL_PLATFORM_NOT_INSTALLED warnings in the log summary.\n protected async extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string) {\n if (this.productionGraph[dependencyId]) {\n return\n }\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n if ((tree.dedupedDependenciesCount ?? 0) > 0) {\n const realDep = this.allDependencies.get(dependencyId)\n if (realDep) {\n this.cache.logSummary[LogMessageByKey.PKG_DUPLICATE_REF].push(dependencyId)\n tree = realDep\n } else {\n this.cache.logSummary[LogMessageByKey.PKG_DUPLICATE_REF_UNRESOLVED].push(dependencyId)\n return\n }\n }\n\n const packageName = tree.name || tree.from\n const { packageJson } = (await this.locateFromDepOrRoot(packageName, tree.path, tree.version)) || {}\n\n const all = packageJson ? { ...packageJson.dependencies, ...packageJson.optionalDependencies } : { ...tree.dependencies, ...tree.optionalDependencies }\n const optional = packageJson ? { ...packageJson.optionalDependencies } : {}\n\n const deps: Record<string, PnpmDependency> = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) }\n\n // pnpm --prod omits sub-deps for link: packages (and synthetic entries derived from them), and pnpm\n // 10.29.3+ prints a repeated subtree only once, so every later occurrence is a childless `deduped`\n // stub (which is what `tree` is when the stub was the first occurrence collected). For any dep\n // declared in the package.json (all) that pnpm left out of the tree, recover the resolved entry\n // from allDependencies so it lands in the production graph.\n for (const [depName, declaredRange] of Object.entries(all)) {\n if (!deps[depName]) {\n const dep = await this.resolveOmittedDependency(depName, declaredRange, tree.path)\n if (dep && isValidKey(depName)) {\n deps[depName] = dep\n }\n }\n }\n\n this.productionGraph[dependencyId] = { dependencies: [] }\n const depPromises = Object.entries(deps).map(async ([packageName, dependency]) => {\n // First check if it's in production dependencies\n if (!all[packageName]) {\n return undefined\n }\n\n // Then check if optional dependency path exists (using actual resolved path)\n if (optional[packageName]) {\n const pkg = await this.locateFromDepOrRoot(packageName, tree.path, dependency.version)\n if (!pkg) {\n // Declared in `optionalDependencies`, so a miss is an expected condition (e.g. fsevents\n // on Linux/Windows) — classify it as a missing optional dependency, not PKG_NOT_ON_DISK.\n this.logMissingDependency(`${packageName}@${dependency.version}`, true)\n return undefined\n }\n }\n const { id: childDependencyId, pkgOverride } = this.normalizePackageVersion(packageName, dependency)\n await this.extractProductionDependencyGraph(pkgOverride, childDependencyId)\n return childDependencyId\n })\n\n const collectedDependencies: string[] = []\n for (const dep of depPromises) {\n const result = await dep\n if (result !== undefined) {\n collectedDependencies.push(result)\n }\n }\n this.productionGraph[dependencyId] = { dependencies: collectedDependencies }\n }\n\n /**\n * Resolve a dependency that `pnpm list` left out of a package's tree to its `allDependencies` entry.\n * The lookup goes through the copy node itself would load from `parentPath` (the package's real store\n * directory), filtered by the declared range, and falls back to a name-only match only when nothing on\n * disk resolves to a collected entry (a `link:` dep, whose entry is keyed by its `link:` version).\n *\n * A name-only lookup returns whichever version was collected first, which is wrong as soon as two\n * versions of the package are installed: with the app pinning es5-ext@0.10.53 while its transitive\n * d@1.0.2 needs es5-ext ^0.10.64, `d` was wired to 0.10.53 and the nested 0.10.64 copy (with its own\n * esniff / event-emitter / next-tick@1.1.0 closure) vanished from the asar (#8493). pnpm 10.29.3+\n * made this common, because its deduped output routes every repeated package through this recovery.\n */\n private async resolveOmittedDependency(depName: string, declaredRange: unknown, parentPath: string | undefined): Promise<PnpmDependency | undefined> {\n const range = typeof declaredRange === \"string\" ? declaredRange : undefined\n const located = await this.locateFromDepOrRoot(depName, parentPath, range)\n const exact = located ? this.allDependencies.get(`${depName}@${located.packageJson.version}`) : undefined\n return exact ?? this.getAllDepsByName().get(depName)\n }\n\n protected async collectAllDependencies(_tree: PnpmDependency, _appPackageName: string): Promise<void> {\n for (const root of this.allWorkspacePackages) {\n await this.collectDepsRecursively(root)\n }\n }\n\n private async collectDepsRecursively(tree: PnpmDependency): Promise<void> {\n const visit = async (key: string, value: PnpmDependency) => {\n if ((value?.dedupedDependenciesCount ?? 0) > 0) {\n return\n }\n const id = `${key}@${value.version}`\n // The pnpm list output can include the same `name@version` thousands of times across a\n // deep workspace; without this guard we re-resolve and re-recurse each occurrence.\n if (this.collectedDeps.has(id)) {\n return\n }\n this.collectedDeps.add(id)\n const pkg = await this.locateFromDepOrRoot(key, value.path, value.version)\n this.allDependencies.set(id, { ...value, path: pkg?.packageDir ?? value.path })\n await this.collectDepsRecursively(value)\n }\n\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n await visit(key, value)\n }\n for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {\n await visit(key, value)\n }\n }\n\n protected override getTreeFromWorkspaces(tree: PnpmDependency, packageName: string): PnpmDependency {\n // pnpm v10 workspace: app is nested as a dependency of root — handled by base class\n const result = super.getTreeFromWorkspaces(tree, packageName)\n if (result !== tree) {\n return result\n }\n // pnpm v11 workspace: each workspace package is a separate top-level array entry;\n // non-workspace (single-tree): find returns the one entry or undefined → falls back to tree\n const match = this.allWorkspacePackages.find(pkg => pkg.name === packageName || pkg.from === packageName)\n return match ?? tree\n }\n\n protected async parseDependenciesTree(jsonBlob: string): Promise<PnpmDependency> {\n const dependencyTree = this.extractJsonFromPollutedOutput<PnpmDependency[]>(jsonBlob)\n this._allWorkspacePackages = dependencyTree\n this._pnpmMajorVersion = await this.pnpmVersion.value\n return dependencyTree[0]\n }\n}\n"]}
@@ -79,6 +79,7 @@ class FlatpakTarget extends core_1.Target {
79
79
  await Promise.all(copyIcons);
80
80
  }
81
81
  getFlatpakBuilderOptions(appOutDir, stageDir, artifactName, arch) {
82
+ var _a, _b;
82
83
  const appIdentifier = this.appId;
83
84
  const { executableName } = this.packager;
84
85
  const flatpakArch = (0, builder_util_1.toLinuxArchString)(arch, "flatpak");
@@ -94,13 +95,17 @@ class FlatpakTarget extends core_1.Target {
94
95
  branch: this.options.branch,
95
96
  modules: this.options.modules,
96
97
  };
98
+ // `this.options` is `linux` deep-merged with `flatpak`, and deepAssign concatenates arrays, so the
99
+ // shared `linux.files` globs (string | FileSet | array of either) would leak into this [src, dest] tuple
100
+ // list. Read the flatpak-specific list from the raw config instead of the merged options.
101
+ const extraFiles = (_b = (_a = this.packager.config.flatpak) === null || _a === void 0 ? void 0 : _a.files) !== null && _b !== void 0 ? _b : [];
97
102
  const buildOptions = {
98
103
  baseFlatpakref: `app/${manifest.base}/${flatpakArch}/${manifest.baseVersion}`,
99
104
  runtimeFlatpakref: `runtime/${manifest.runtime}/${flatpakArch}/${manifest.runtimeVersion}`,
100
105
  sdkFlatpakref: `runtime/${manifest.sdk}/${flatpakArch}/${manifest.runtimeVersion}`,
101
106
  arch: flatpakArch,
102
107
  bundlePath: path.join(this.outDir, artifactName),
103
- files: [[stageDir, "/"], [appOutDir, path.join("/lib", appIdentifier)], ...(this.options.files || [])],
108
+ files: [[stageDir, "/"], [appOutDir, path.join("/lib", appIdentifier)], ...extraFiles],
104
109
  symlinks: [[path.join("/lib", appIdentifier, executableName), path.join("/bin", executableName)], ...(this.options.symlinks || [])],
105
110
  };
106
111
  return { manifest, buildOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"FlatpakTarget.js","sourceRoot":"","sources":["../../src/targets/FlatpakTarget.ts"],"names":[],"mappings":";;AAAA,6DAA8G;AAC9G,+CAAgE;AAChE,uCAA4C;AAC5C,6BAA4B;AAC5B,kCAAgC;AAGhC,6CAA4D;AAE5D,6CAAuD;AACvD,+DAA0D;AAE1D,MAAqB,aAAc,SAAQ,aAAM;IAG/C,YACE,IAAY,EACK,QAAuB,EAChC,MAAyB,EACxB,MAAc;QAEvB,KAAK,CAAC,IAAI,CAAC,CAAA;QAJM,aAAQ,GAAR,QAAQ,CAAe;QAChC,WAAM,GAAN,MAAM,CAAmB;QACxB,WAAM,GAAN,MAAM,CAAQ;QANhB,YAAO,GAAmB,IAAA,iCAAU,EAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAG,IAAI,CAAC,QAAQ,CAAC,MAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IASvI,CAAC;IAED,IAAI,KAAK;QACP,OAAO,0BAA0B,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,IAAU;QACvC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QAClC,MAAM,YAAY,GAAG,QAAQ,CAAC,yBAAyB,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;QACnG,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,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Manifest } from \"@malept/flatpak-bundler\"\nimport { Arch, copyFile, toLinuxArchString } from \"builder-util\"\nimport { chmod, outputFile } from \"fs-extra\"\nimport * as path from \"path\"\nimport { Target } from \"../core\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport { FlatpakOptions } from \"../options/linuxOptions\"\nimport { getNotLocalizedLicenseFile } from \"../util/license\"\nimport { LinuxTargetHelper } from \"./LinuxTargetHelper\"\nimport { createStageDir, StageDir } from \"./targetUtil\"\nimport { deepAssign, Nullish } from \"builder-util-runtime\"\n\nexport default class FlatpakTarget extends Target {\n readonly options: FlatpakOptions = deepAssign({}, this.packager.platformSpecificBuildOptions, (this.packager.config as any)[this.name])\n\n constructor(\n name: string,\n private readonly packager: LinuxPackager,\n private helper: LinuxTargetHelper,\n readonly outDir: string\n ) {\n super(name)\n }\n\n get appId(): string {\n return filterFlatpakAppIdentifier(this.packager.appInfo.id)\n }\n\n async build(appOutDir: string, arch: Arch): Promise<any> {\n const { packager, options } = this\n const artifactName = packager.expandArtifactNamePattern(options, \"flatpak\", arch, undefined, false)\n const artifactPath = path.join(this.outDir, artifactName)\n await packager.info.emitArtifactBuildStarted({\n targetPresentableName: \"flatpak\",\n file: artifactPath,\n arch,\n })\n\n const stageDir = await this.prepareStageDir(arch)\n\n const { manifest, buildOptions } = this.getFlatpakBuilderOptions(appOutDir, stageDir.dir, artifactName, arch)\n await bundleFlatpak(manifest, buildOptions)\n\n await stageDir.cleanup()\n\n await packager.info.emitArtifactBuildCompleted({\n file: artifactPath,\n safeArtifactName: packager.computeSafeArtifactName(artifactName, \"flatpak\", arch, false),\n target: this,\n arch,\n packager,\n isWriteUpdateInfo: false,\n })\n }\n\n private async prepareStageDir(arch: Arch): Promise<StageDir> {\n const stageDir = await createStageDir(this, this.packager, arch)\n\n await Promise.all([this.createSandboxBinWrapper(stageDir), this.createDesktopFile(stageDir), this.copyLicenseFile(stageDir), this.copyIcons(stageDir)])\n\n return stageDir\n }\n\n private async createSandboxBinWrapper(stageDir: StageDir) {\n const useWaylandFlags = !!this.options.useWaylandFlags\n const electronWrapperPath = stageDir.getTempFile(path.join(\"bin\", \"electron-wrapper\"))\n await outputFile(electronWrapperPath, getElectronWrapperScript(this.packager.executableName, this.options.executableArgs, useWaylandFlags))\n await chmod(electronWrapperPath, 0o755)\n }\n\n private async createDesktopFile(stageDir: StageDir) {\n const appIdentifier = this.appId\n const desktopFile = stageDir.getTempFile(path.join(\"share\", \"applications\", `${appIdentifier}.desktop`))\n await this.helper.writeDesktopEntry(this.options, \"electron-wrapper %U\", desktopFile, { Icon: appIdentifier })\n }\n\n private async copyLicenseFile(stageDir: StageDir) {\n const licenseSrc = await getNotLocalizedLicenseFile(this.options.license, this.packager, [\"txt\", \"html\"])\n if (licenseSrc) {\n const licenseDst = stageDir.getTempFile(path.join(\"share\", \"doc\", this.appId, \"copyright\"))\n await copyFile(licenseSrc, licenseDst)\n }\n }\n\n private async copyIcons(stageDir: StageDir) {\n const icons = await this.helper.icons\n const copyIcons = icons.map(async icon => {\n if (icon.size > 512) {\n // Flatpak does not allow icons larger than 512 pixels\n return Promise.resolve()\n }\n const extWithDot = path.extname(icon.file)\n const sizeName = extWithDot === \".svg\" ? \"scalable\" : `${icon.size}x${icon.size}`\n const iconDst = stageDir.getTempFile(path.join(\"share\", \"icons\", \"hicolor\", sizeName, \"apps\", `${this.appId}${extWithDot}`))\n\n return copyFile(icon.file, iconDst)\n })\n\n await Promise.all(copyIcons)\n }\n\n private getFlatpakBuilderOptions(appOutDir: string, stageDir: string, artifactName: string, arch: Arch): { manifest: FlatpakManifest; buildOptions: FlatpakBundlerBuildOptions } {\n const appIdentifier = this.appId\n const { executableName } = this.packager\n const flatpakArch = toLinuxArchString(arch, \"flatpak\")\n\n const manifest: FlatpakManifest = {\n id: appIdentifier,\n command: \"electron-wrapper\",\n runtime: this.options.runtime || flatpakBuilderDefaults.runtime,\n runtimeVersion: this.options.runtimeVersion || flatpakBuilderDefaults.runtimeVersion,\n sdk: this.options.sdk || flatpakBuilderDefaults.sdk,\n base: this.options.base || flatpakBuilderDefaults.base,\n baseVersion: this.options.baseVersion || flatpakBuilderDefaults.baseVersion,\n finishArgs: this.options.finishArgs || flatpakBuilderDefaults.finishArgs,\n branch: this.options.branch,\n modules: this.options.modules,\n }\n\n const buildOptions: FlatpakBundlerBuildOptions = {\n baseFlatpakref: `app/${manifest.base}/${flatpakArch}/${manifest.baseVersion}`,\n runtimeFlatpakref: `runtime/${manifest.runtime}/${flatpakArch}/${manifest.runtimeVersion}`,\n sdkFlatpakref: `runtime/${manifest.sdk}/${flatpakArch}/${manifest.runtimeVersion}`,\n arch: flatpakArch as any,\n bundlePath: path.join(this.outDir, artifactName),\n files: [[stageDir, \"/\"], [appOutDir, path.join(\"/lib\", appIdentifier)], ...(this.options.files || [])],\n symlinks: [[path.join(\"/lib\", appIdentifier, executableName), path.join(\"/bin\", executableName)], ...(this.options.symlinks || [])],\n }\n\n return { manifest, buildOptions }\n }\n}\n\nconst flatpakBuilderDefaults: Omit<FlatpakManifest, \"id\" | \"command\"> = {\n runtime: \"org.freedesktop.Platform\",\n runtimeVersion: \"20.08\",\n sdk: \"org.freedesktop.Sdk\",\n base: \"org.electronjs.Electron2.BaseApp\",\n baseVersion: \"20.08\",\n finishArgs: [\n // Wayland/X11 Rendering\n \"--socket=wayland\",\n \"--socket=x11\",\n \"--share=ipc\",\n // Open GL\n \"--device=dri\",\n // Audio output\n \"--socket=pulseaudio\",\n // Read/write home directory access\n \"--filesystem=home\",\n // Allow communication with network\n \"--share=network\",\n // System notifications with libnotify\n \"--talk-name=org.freedesktop.Notifications\",\n ],\n}\n\nfunction getElectronWrapperScript(executableName: string, executableArgs: string[] | Nullish, useWaylandFlags: boolean): string {\n const stringifiedExecutableArgs = executableArgs?.join(\" \") || \"\"\n if (useWaylandFlags) {\n return `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nif [ \"\\${XDG_SESSION_TYPE}\" == \"wayland\" ]; then\n zypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} --enable-features=UseOzonePlatform --ozone-platform=wayland \"$@\"\nelse\n zypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} \"$@\"\nfi\n`\n }\n return `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nzypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} \"$@\"\n`\n}\n\nfunction filterFlatpakAppIdentifier(identifier: string) {\n // Remove special characters and allow only alphanumeric (A-Z,a-z,0-9), underscore (_), and period (.)\n // Flatpak documentation: https://docs.flatpak.org/en/latest/conventions.html#application-ids\n return identifier.replace(/-/g, \"_\").replace(/[^a-zA-Z0-9._]/g, \"\")\n}\n"]}
1
+ {"version":3,"file":"FlatpakTarget.js","sourceRoot":"","sources":["../../src/targets/FlatpakTarget.ts"],"names":[],"mappings":";;AAAA,6DAA8G;AAC9G,+CAAgE;AAChE,uCAA4C;AAC5C,6BAA4B;AAC5B,kCAAgC;AAGhC,6CAA4D;AAE5D,6CAAuD;AACvD,+DAA0D;AAE1D,MAAqB,aAAc,SAAQ,aAAM;IAG/C,YACE,IAAY,EACK,QAAuB,EAChC,MAAyB,EACxB,MAAc;QAEvB,KAAK,CAAC,IAAI,CAAC,CAAA;QAJM,aAAQ,GAAR,QAAQ,CAAe;QAChC,WAAM,GAAN,MAAM,CAAmB;QACxB,WAAM,GAAN,MAAM,CAAQ;QANhB,YAAO,GAAmB,IAAA,iCAAU,EAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAG,IAAI,CAAC,QAAQ,CAAC,MAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IASvI,CAAC;IAED,IAAI,KAAK;QACP,OAAO,0BAA0B,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAiB,E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5C,cAAc,KAAK,yBAAyB;;CAEhE,CAAA;IACC,CAAC;IACD,OAAO;;;;iBAIQ,cAAc,KAAK,yBAAyB;CAC5D,CAAA;AACD,CAAC;AAED,SAAS,0BAA0B,CAAC,UAAkB;IACpD,sGAAsG;IACtG,6FAA6F;IAC7F,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAA;AACrE,CAAC","sourcesContent":["import { bundle as bundleFlatpak, FlatpakBundlerBuildOptions, FlatpakManifest } from \"@malept/flatpak-bundler\"\nimport { Arch, copyFile, toLinuxArchString } from \"builder-util\"\nimport { chmod, outputFile } from \"fs-extra\"\nimport * as path from \"path\"\nimport { Target } from \"../core\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport { FlatpakOptions } from \"../options/linuxOptions\"\nimport { getNotLocalizedLicenseFile } from \"../util/license\"\nimport { LinuxTargetHelper } from \"./LinuxTargetHelper\"\nimport { createStageDir, StageDir } from \"./targetUtil\"\nimport { deepAssign, Nullish } from \"builder-util-runtime\"\n\nexport default class FlatpakTarget extends Target {\n readonly options: FlatpakOptions = deepAssign({}, this.packager.platformSpecificBuildOptions, (this.packager.config as any)[this.name])\n\n constructor(\n name: string,\n private readonly packager: LinuxPackager,\n private helper: LinuxTargetHelper,\n readonly outDir: string\n ) {\n super(name)\n }\n\n get appId(): string {\n return filterFlatpakAppIdentifier(this.packager.appInfo.id)\n }\n\n async build(appOutDir: string, arch: Arch): Promise<any> {\n const { packager, options } = this\n const artifactName = packager.expandArtifactNamePattern(options, \"flatpak\", arch, undefined, false)\n const artifactPath = path.join(this.outDir, artifactName)\n await packager.info.emitArtifactBuildStarted({\n targetPresentableName: \"flatpak\",\n file: artifactPath,\n arch,\n })\n\n const stageDir = await this.prepareStageDir(arch)\n\n const { manifest, buildOptions } = this.getFlatpakBuilderOptions(appOutDir, stageDir.dir, artifactName, arch)\n await bundleFlatpak(manifest, buildOptions)\n\n await stageDir.cleanup()\n\n await packager.info.emitArtifactBuildCompleted({\n file: artifactPath,\n safeArtifactName: packager.computeSafeArtifactName(artifactName, \"flatpak\", arch, false),\n target: this,\n arch,\n packager,\n isWriteUpdateInfo: false,\n })\n }\n\n private async prepareStageDir(arch: Arch): Promise<StageDir> {\n const stageDir = await createStageDir(this, this.packager, arch)\n\n await Promise.all([this.createSandboxBinWrapper(stageDir), this.createDesktopFile(stageDir), this.copyLicenseFile(stageDir), this.copyIcons(stageDir)])\n\n return stageDir\n }\n\n private async createSandboxBinWrapper(stageDir: StageDir) {\n const useWaylandFlags = !!this.options.useWaylandFlags\n const electronWrapperPath = stageDir.getTempFile(path.join(\"bin\", \"electron-wrapper\"))\n await outputFile(electronWrapperPath, getElectronWrapperScript(this.packager.executableName, this.options.executableArgs, useWaylandFlags))\n await chmod(electronWrapperPath, 0o755)\n }\n\n private async createDesktopFile(stageDir: StageDir) {\n const appIdentifier = this.appId\n const desktopFile = stageDir.getTempFile(path.join(\"share\", \"applications\", `${appIdentifier}.desktop`))\n await this.helper.writeDesktopEntry(this.options, \"electron-wrapper %U\", desktopFile, { Icon: appIdentifier })\n }\n\n private async copyLicenseFile(stageDir: StageDir) {\n const licenseSrc = await getNotLocalizedLicenseFile(this.options.license, this.packager, [\"txt\", \"html\"])\n if (licenseSrc) {\n const licenseDst = stageDir.getTempFile(path.join(\"share\", \"doc\", this.appId, \"copyright\"))\n await copyFile(licenseSrc, licenseDst)\n }\n }\n\n private async copyIcons(stageDir: StageDir) {\n const icons = await this.helper.icons\n const copyIcons = icons.map(async icon => {\n if (icon.size > 512) {\n // Flatpak does not allow icons larger than 512 pixels\n return Promise.resolve()\n }\n const extWithDot = path.extname(icon.file)\n const sizeName = extWithDot === \".svg\" ? \"scalable\" : `${icon.size}x${icon.size}`\n const iconDst = stageDir.getTempFile(path.join(\"share\", \"icons\", \"hicolor\", sizeName, \"apps\", `${this.appId}${extWithDot}`))\n\n return copyFile(icon.file, iconDst)\n })\n\n await Promise.all(copyIcons)\n }\n\n private getFlatpakBuilderOptions(appOutDir: string, stageDir: string, artifactName: string, arch: Arch): { manifest: FlatpakManifest; buildOptions: FlatpakBundlerBuildOptions } {\n const appIdentifier = this.appId\n const { executableName } = this.packager\n const flatpakArch = toLinuxArchString(arch, \"flatpak\")\n\n const manifest: FlatpakManifest = {\n id: appIdentifier,\n command: \"electron-wrapper\",\n runtime: this.options.runtime || flatpakBuilderDefaults.runtime,\n runtimeVersion: this.options.runtimeVersion || flatpakBuilderDefaults.runtimeVersion,\n sdk: this.options.sdk || flatpakBuilderDefaults.sdk,\n base: this.options.base || flatpakBuilderDefaults.base,\n baseVersion: this.options.baseVersion || flatpakBuilderDefaults.baseVersion,\n finishArgs: this.options.finishArgs || flatpakBuilderDefaults.finishArgs,\n branch: this.options.branch,\n modules: this.options.modules,\n }\n\n // `this.options` is `linux` deep-merged with `flatpak`, and deepAssign concatenates arrays, so the\n // shared `linux.files` globs (string | FileSet | array of either) would leak into this [src, dest] tuple\n // list. Read the flatpak-specific list from the raw config instead of the merged options.\n const extraFiles = this.packager.config.flatpak?.files ?? []\n\n const buildOptions: FlatpakBundlerBuildOptions = {\n baseFlatpakref: `app/${manifest.base}/${flatpakArch}/${manifest.baseVersion}`,\n runtimeFlatpakref: `runtime/${manifest.runtime}/${flatpakArch}/${manifest.runtimeVersion}`,\n sdkFlatpakref: `runtime/${manifest.sdk}/${flatpakArch}/${manifest.runtimeVersion}`,\n arch: flatpakArch as any,\n bundlePath: path.join(this.outDir, artifactName),\n files: [[stageDir, \"/\"], [appOutDir, path.join(\"/lib\", appIdentifier)], ...extraFiles],\n symlinks: [[path.join(\"/lib\", appIdentifier, executableName), path.join(\"/bin\", executableName)], ...(this.options.symlinks || [])],\n }\n\n return { manifest, buildOptions }\n }\n}\n\nconst flatpakBuilderDefaults: Omit<FlatpakManifest, \"id\" | \"command\"> = {\n runtime: \"org.freedesktop.Platform\",\n runtimeVersion: \"20.08\",\n sdk: \"org.freedesktop.Sdk\",\n base: \"org.electronjs.Electron2.BaseApp\",\n baseVersion: \"20.08\",\n finishArgs: [\n // Wayland/X11 Rendering\n \"--socket=wayland\",\n \"--socket=x11\",\n \"--share=ipc\",\n // Open GL\n \"--device=dri\",\n // Audio output\n \"--socket=pulseaudio\",\n // Read/write home directory access\n \"--filesystem=home\",\n // Allow communication with network\n \"--share=network\",\n // System notifications with libnotify\n \"--talk-name=org.freedesktop.Notifications\",\n ],\n}\n\nfunction getElectronWrapperScript(executableName: string, executableArgs: string[] | Nullish, useWaylandFlags: boolean): string {\n const stringifiedExecutableArgs = executableArgs?.join(\" \") || \"\"\n if (useWaylandFlags) {\n return `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nif [ \"\\${XDG_SESSION_TYPE}\" == \"wayland\" ]; then\n zypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} --enable-features=UseOzonePlatform --ozone-platform=wayland \"$@\"\nelse\n zypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} \"$@\"\nfi\n`\n }\n return `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nzypak-wrapper \"${executableName}\" ${stringifiedExecutableArgs} \"$@\"\n`\n}\n\nfunction filterFlatpakAppIdentifier(identifier: string) {\n // Remove special characters and allow only alphanumeric (A-Z,a-z,0-9), underscore (_), and period (.)\n // Flatpak documentation: https://docs.flatpak.org/en/latest/conventions.html#application-ids\n return identifier.replace(/-/g, \"_\").replace(/[^a-zA-Z0-9._]/g, \"\")\n}\n"]}
@@ -23,6 +23,18 @@ export interface ArchiveOptions {
23
23
  * @default false
24
24
  */
25
25
  preserveSymlinks?: boolean;
26
+ /**
27
+ * Paths, relative to the archived directory, to append as uncompressed (`Copy`) members instead of
28
+ * compressing them with the rest of the archive. Differential updates diff the *compressed* archive
29
+ * with a content-defined blockmap, and a large compressed member (an asar) diverges wholesale from
30
+ * its previous version on any change — storing it keeps unchanged regions byte-identical between
31
+ * builds, so the delta stays proportional to what actually changed. The stored members are excluded
32
+ * from the main (compressed) pass and appended in a second 7za invocation with `-mx=0`; the
33
+ * `ELECTRON_BUILDER_COMPRESSION_LEVEL` override deliberately does not apply to them (byte-stability
34
+ * is the point), while `preserveSymlinks` and `isArchiveHeaderCompressed` are mirrored into the
35
+ * append pass. Paths that do not exist are skipped. Not supported by the native-zip NFD fallback.
36
+ */
37
+ storedPaths?: Array<string> | null;
26
38
  /**
27
39
  * Restrict the 7z filter to one the install-time extractor (the self-vendored Nsis7z plugin) can
28
40
  * decode. Modern 7za (24.09) auto-applies a CPU branch converter to executable content at
@@ -150,6 +150,7 @@ function compute7zCompressArgs(format, options = {}) {
150
150
  // 7z is very fast, so, use ultra compression
151
151
  /** @internal */
152
152
  async function archive(format, outFile, dirToArchive, options = {}) {
153
+ var _a;
153
154
  const outFileStat = await (0, builder_util_1.statOrNull)(outFile);
154
155
  const dirStat = await (0, builder_util_1.statOrNull)(dirToArchive);
155
156
  if (outFileStat && dirStat && outFileStat.mtime > dirStat.mtime) {
@@ -163,6 +164,21 @@ async function archive(format, outFile, dirToArchive, options = {}) {
163
164
  builder_util_1.log.warn({ reason: "7z doesn't support NFD-normalized filenames" }, `using zip`);
164
165
  use7z = false;
165
166
  }
167
+ // Resolve storedPaths before the main pass so they can be excluded from it. Member names are
168
+ // native-separator, relative to the 7za cwd (which differs with withoutDir), so the same string
169
+ // works as both the exact `-x!` exclude mask and the append argument.
170
+ const storedMembers = [];
171
+ for (const storedPath of (_a = options.storedPaths) !== null && _a !== void 0 ? _a : []) {
172
+ if (storedPath.includes("..")) {
173
+ throw new Error(`Stored archive path contains path traversal sequence: "${storedPath}"`);
174
+ }
175
+ if (await (0, builder_util_1.exists)(path.join(dirToArchive, storedPath))) {
176
+ storedMembers.push(path.normalize(options.withoutDir ? storedPath : path.join(path.basename(dirToArchive), storedPath)));
177
+ }
178
+ }
179
+ if (storedMembers.length > 0 && !use7z) {
180
+ throw new Error("storedPaths is not supported with the native zip fallback");
181
+ }
166
182
  if (use7z) {
167
183
  const args = compute7zCompressArgs(format, options);
168
184
  // Modern 7-Zip (24.09) dereferences symlinks by default; the 7-Zip 16.02 bundled before
@@ -175,8 +191,11 @@ async function archive(format, outFile, dirToArchive, options = {}) {
175
191
  await (0, builder_util_1.unlinkIfExists)(outFile);
176
192
  args.push(outFile, options.withoutDir ? "." : path.basename(dirToArchive));
177
193
  args.push(...buildExcludeArgs(options.excluded, "-xr!"));
194
+ // `-x!` (exact, non-recursive) so only the member itself is skipped, never a same-named sibling
195
+ args.push(...storedMembers.map(member => `-x!${member}`));
196
+ const cwd = options.withoutDir ? dirToArchive : path.dirname(dirToArchive);
178
197
  try {
179
- await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), args, { cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive) }, builder_util_1.debug7z.enabled);
198
+ await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), args, { cwd }, builder_util_1.debug7z.enabled);
180
199
  }
181
200
  catch (e) {
182
201
  if (e.code === "ENOENT" && !(await (0, builder_util_1.exists)(dirToArchive))) {
@@ -186,6 +205,31 @@ async function archive(format, outFile, dirToArchive, options = {}) {
186
205
  throw e;
187
206
  }
188
207
  }
208
+ if (storedMembers.length > 0) {
209
+ // Second pass: append the stored members with no compression. -mx=0 unconditionally — the
210
+ // compression-level env override must not reach these members (see storedPaths docs). The
211
+ // main pass's symlink, timestamp, and header-compression flags are mirrored so the option
212
+ // stays generic: the append rewrites the archive header and may itself store a symlink.
213
+ const appendArgs = debug7zArgs("a");
214
+ appendArgs.push("-mx=0");
215
+ if (options.preserveSymlinks) {
216
+ appendArgs.push("-snl");
217
+ }
218
+ if (!options.isRegularFile) {
219
+ appendArgs.push("-mtc=off");
220
+ }
221
+ if (format === "7z" || format.endsWith(".7z")) {
222
+ if (options.isArchiveHeaderCompressed === false) {
223
+ appendArgs.push("-mhc=off");
224
+ }
225
+ appendArgs.push("-mtm=off", "-mta=off");
226
+ }
227
+ else if (format === "zip") {
228
+ appendArgs.push("-mm=Copy", "-mcu");
229
+ }
230
+ appendArgs.push(outFile, ...storedMembers);
231
+ await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), appendArgs, { cwd }, builder_util_1.debug7z.enabled);
232
+ }
189
233
  }
190
234
  else {
191
235
  // macOS native zip (NFD fallback): -y preserves symlinks