app-builder-lib 26.17.0 → 26.18.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.
- package/out/asar/asarUtil.js +7 -2
- package/out/asar/asarUtil.js.map +1 -1
- package/out/forge-maker.d.ts +64 -0
- package/out/forge-maker.js +108 -2
- package/out/forge-maker.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +37 -0
- package/out/node-module-collector/pnpmNodeModulesCollector.js +102 -24
- package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
- package/out/targets/blockmap/blockmap.d.ts +43 -3
- package/out/targets/blockmap/blockmap.js +143 -16
- package/out/targets/blockmap/blockmap.js.map +1 -1
- package/out/targets/blockmap/verbatimRange.d.ts +43 -0
- package/out/targets/blockmap/verbatimRange.js +122 -0
- package/out/targets/blockmap/verbatimRange.js.map +1 -0
- package/out/targets/differentialUpdateInfoBuilder.d.ts +27 -2
- package/out/targets/differentialUpdateInfoBuilder.js +77 -5
- package/out/targets/differentialUpdateInfoBuilder.js.map +1 -1
- package/out/targets/nsis/NsisTarget.d.ts +35 -2
- package/out/targets/nsis/NsisTarget.js +121 -29
- package/out/targets/nsis/NsisTarget.js.map +1 -1
- package/out/targets/nsis/nsisOptions.d.ts +8 -3
- package/out/targets/nsis/nsisOptions.js.map +1 -1
- package/out/targets/nsis/nsisUtil.d.ts +7 -0
- package/out/targets/nsis/nsisUtil.js +14 -3
- package/out/targets/nsis/nsisUtil.js.map +1 -1
- package/out/targets/snap/core24.d.ts +2 -0
- package/out/targets/snap/core24.js +30 -7
- package/out/targets/snap/core24.js.map +1 -1
- package/out/targets/snap/coreLegacy.js +1 -2
- package/out/targets/snap/coreLegacy.js.map +1 -1
- package/out/util/appFileCopier.js +1 -1
- package/out/util/appFileCopier.js.map +1 -1
- package/out/version.d.ts +1 -1
- package/out/version.js +1 -1
- package/out/version.js.map +1 -1
- package/package.json +10 -8
- package/scheme.json +5 -5
|
@@ -94,6 +94,8 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
|
|
|
94
94
|
/** Reverse index of `allDependencies` keyed by package name (without version). Built once on
|
|
95
95
|
* first access inside `extractProductionDependencyGraph`, after `allDependencies` is settled. */
|
|
96
96
|
this._allDepsByName = null;
|
|
97
|
+
/** The app's own node of the `pnpm list` output (the root of the production graph), set by `getTreeFromWorkspaces`. */
|
|
98
|
+
this.rootTree = null;
|
|
97
99
|
}
|
|
98
100
|
/** Returns true if `nmDir` is an isolated (`.pnpm`) store, false if hoisted, null if it holds no packages. */
|
|
99
101
|
async scanNodeModulesLayout(nmDir) {
|
|
@@ -196,12 +198,34 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
|
|
|
196
198
|
return fromDep;
|
|
197
199
|
}
|
|
198
200
|
return this.cache.locatePackageVersion({ pkgName, parentDir: this.rootDir, requiredRange, skipDownwardSearch });
|
|
199
|
-
})();
|
|
201
|
+
})().then(pkg => this.toRealPackage(pkg));
|
|
200
202
|
if (memoKey != null) {
|
|
201
203
|
this.locateMemo.set(memoKey, promise);
|
|
202
204
|
}
|
|
203
205
|
return promise;
|
|
204
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Resolve a located package to its real directory (the symlink target), leaving a non-symlinked
|
|
209
|
+
* hit untouched.
|
|
210
|
+
*
|
|
211
|
+
* `locatePackageVersion` returns the path it *walked*, which in pnpm's isolated store is the
|
|
212
|
+
* `node_modules/<name>` symlink rather than `.pnpm/<name>@<ver>/node_modules/<name>`. That
|
|
213
|
+
* distinction matters because the store keeps a package's dependencies as SIBLINGS inside
|
|
214
|
+
* `.pnpm/<name>@<ver>/node_modules/`, reachable only from the real path: searching upward from
|
|
215
|
+
* the symlink walks the dependent's directory instead, and finds the dependency only by accident
|
|
216
|
+
* (through pnpm's hidden `.pnpm/node_modules` hoist, possibly at the wrong version). `visitDep`
|
|
217
|
+
* resolves the deps of every package pnpm printed without children (deduped stubs) from disk
|
|
218
|
+
* through here.
|
|
219
|
+
*
|
|
220
|
+
* Resolving the link is what Node itself does (`--preserve-symlinks` is off by default).
|
|
221
|
+
*/
|
|
222
|
+
async toRealPackage(pkg) {
|
|
223
|
+
if (pkg == null) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const packageDir = await this.cache.realPath[pkg.packageDir];
|
|
227
|
+
return packageDir === pkg.packageDir ? pkg : { ...pkg, packageDir };
|
|
228
|
+
}
|
|
205
229
|
// pnpm 10+ does not automatically preserve transitive optional platform-specific
|
|
206
230
|
// packages (e.g. sass-embedded-linux-x64) across lock file regeneration. Users
|
|
207
231
|
// must list them as direct optionalDependencies. Missing ones are emitted as
|
|
@@ -224,7 +248,13 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
|
|
|
224
248
|
}
|
|
225
249
|
}
|
|
226
250
|
const packageName = tree.name || tree.from;
|
|
227
|
-
|
|
251
|
+
// The app root is never installed inside a node_modules directory, so it is read from its own
|
|
252
|
+
// directory instead of being located by name. A by-name lookup finds a same-named dependency
|
|
253
|
+
// whenever the app shares its name with one (an app called `debug` depending on `debug`), and
|
|
254
|
+
// that dependency's package.json would then decide which of the app's dependencies are kept.
|
|
255
|
+
const isRoot = tree === this.rootTree;
|
|
256
|
+
const rootPackageJson = isRoot && tree.path ? await fs.readJson(path.join(tree.path, "package.json")).catch(() => null) : null;
|
|
257
|
+
const { packageJson } = (isRoot ? { packageJson: rootPackageJson } : await this.locateFromDepOrRoot(packageName, tree.path, tree.version)) || {};
|
|
228
258
|
const all = packageJson ? { ...packageJson.dependencies, ...packageJson.optionalDependencies } : { ...tree.dependencies, ...tree.optionalDependencies };
|
|
229
259
|
const optional = packageJson ? { ...packageJson.optionalDependencies } : {};
|
|
230
260
|
const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
|
|
@@ -293,40 +323,88 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
|
|
|
293
323
|
await this.collectDepsRecursively(root);
|
|
294
324
|
}
|
|
295
325
|
}
|
|
296
|
-
async
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
326
|
+
async readPackageJsonAt(dir) {
|
|
327
|
+
const packageJson = await fs.readJson(path.join(dir, "package.json")).catch(() => null);
|
|
328
|
+
return packageJson ? { packageDir: dir, packageJson } : null;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Visit a single dependency node, adding it and its transitive deps to allDependencies.
|
|
332
|
+
*
|
|
333
|
+
* pnpm 10.29.3+ prints a repeated subtree only once; every later occurrence is a childless
|
|
334
|
+
* `deduped` stub. Stubs must still be registered here: the one full print can sit under a node
|
|
335
|
+
* this walk skips, e.g. a second peer variant of a package with the same `name@version` (the
|
|
336
|
+
* guard below), so a package seen only as stubs was dropped from the asar together with its whole
|
|
337
|
+
* closure (#10253). For a stub (and every dependency discovered beneath one, `fromDisk`), we fall
|
|
338
|
+
* back to the on-disk package.json to discover transitive deps, resolving each one from the
|
|
339
|
+
* package's own store directory first (where pnpm placed them).
|
|
340
|
+
*
|
|
341
|
+
* Other childless entries keep the tree walk. A `link:` package is also printed without children,
|
|
342
|
+
* but its declared deps resolve from the link target's own `node_modules` (e.g. a linked
|
|
343
|
+
* electron-updater checkout's monorepo store), outside the app. Walking them would register those
|
|
344
|
+
* foreign copies under `name@version`, so the guard below then skips the app's own copy of the same
|
|
345
|
+
* `name@version` together with its subtree (`jsonfile` vanished from under `fs-extra`).
|
|
346
|
+
*/
|
|
347
|
+
async visitDep(key, value, fromDisk = false) {
|
|
348
|
+
var _a, _b, _c, _d;
|
|
349
|
+
const id = `${key}@${value.version}`;
|
|
350
|
+
// The pnpm list output can include the same `name@version` thousands of times across a
|
|
351
|
+
// deep workspace; without this guard we re-resolve and re-recurse each occurrence.
|
|
352
|
+
if (this.collectedDeps.has(id)) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this.collectedDeps.add(id);
|
|
356
|
+
const located = await this.locateFromDepOrRoot(key, value.path, value.version);
|
|
357
|
+
const resolvedPath = (_a = located === null || located === void 0 ? void 0 : located.packageDir) !== null && _a !== void 0 ? _a : value.path;
|
|
358
|
+
this.allDependencies.set(id, { ...value, path: resolvedPath });
|
|
359
|
+
// Fall back to reading package.json straight from the resolved directory when the by-name lookup
|
|
360
|
+
// came up empty, e.g. a workspace package, which nothing above it exposes under `node_modules/`.
|
|
361
|
+
const pkg = located !== null && located !== void 0 ? located : (resolvedPath != null ? await this.readPackageJsonAt(resolvedPath) : null);
|
|
362
|
+
const hasTreeDeps = Object.keys((_b = value.dependencies) !== null && _b !== void 0 ? _b : {}).length > 0 || Object.keys((_c = value.optionalDependencies) !== null && _c !== void 0 ? _c : {}).length > 0;
|
|
363
|
+
const isDedupedStub = ((_d = value.dedupedDependenciesCount) !== null && _d !== void 0 ? _d : 0) > 0;
|
|
364
|
+
if ((isDedupedStub || fromDisk) && !hasTreeDeps && (pkg === null || pkg === void 0 ? void 0 : pkg.packageJson)) {
|
|
365
|
+
// Pass the declared version range so that resolution skips wrong-version hoisted packages and
|
|
366
|
+
// finds the correct nested copy.
|
|
367
|
+
const pkgOptionalDecl = pkg.packageJson.optionalDependencies || {};
|
|
368
|
+
const pkgDepsDecl = { ...(pkg.packageJson.dependencies || {}), ...pkgOptionalDecl };
|
|
369
|
+
for (const [depName, depRange] of Object.entries(pkgDepsDecl)) {
|
|
370
|
+
const resolved = await this.locateFromDepOrRoot(depName, pkg.packageDir, typeof depRange === "string" ? depRange : undefined);
|
|
371
|
+
if (!resolved) {
|
|
372
|
+
// A miss here silently ships a broken app (the dependency is simply absent from the
|
|
373
|
+
// asar and only fails at runtime with MODULE_NOT_FOUND), so surface it in the log
|
|
374
|
+
// summary. Optional deps are an expected miss and get the quieter bucket.
|
|
375
|
+
this.logMissingDependency(`${depName}@${depRange}`, pkgOptionalDecl[depName] != null);
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
await this.visitDep(depName, {
|
|
379
|
+
from: depName,
|
|
380
|
+
name: depName,
|
|
381
|
+
version: resolved.packageJson.version,
|
|
382
|
+
path: resolved.packageDir,
|
|
383
|
+
dependencies: {},
|
|
384
|
+
optionalDependencies: {},
|
|
385
|
+
}, true);
|
|
307
386
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this.allDependencies.set(id, { ...value, path: (_b = pkg === null || pkg === void 0 ? void 0 : pkg.packageDir) !== null && _b !== void 0 ? _b : value.path });
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
311
389
|
await this.collectDepsRecursively(value);
|
|
312
|
-
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async collectDepsRecursively(tree) {
|
|
313
393
|
for (const [key, value] of Object.entries(tree.dependencies || {})) {
|
|
314
|
-
await
|
|
394
|
+
await this.visitDep(key, value);
|
|
315
395
|
}
|
|
316
396
|
for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {
|
|
317
|
-
await
|
|
397
|
+
await this.visitDep(key, value);
|
|
318
398
|
}
|
|
319
399
|
}
|
|
320
400
|
getTreeFromWorkspaces(tree, packageName) {
|
|
401
|
+
var _a;
|
|
321
402
|
// pnpm v10 workspace: app is nested as a dependency of root — handled by base class
|
|
322
403
|
const result = super.getTreeFromWorkspaces(tree, packageName);
|
|
323
|
-
if (result !== tree) {
|
|
324
|
-
return result;
|
|
325
|
-
}
|
|
326
404
|
// pnpm v11 workspace: each workspace package is a separate top-level array entry;
|
|
327
405
|
// non-workspace (single-tree): find returns the one entry or undefined → falls back to tree
|
|
328
|
-
|
|
329
|
-
return
|
|
406
|
+
this.rootTree = result !== tree ? result : ((_a = this.allWorkspacePackages.find(pkg => pkg.name === packageName || pkg.from === packageName)) !== null && _a !== void 0 ? _a : tree);
|
|
407
|
+
return this.rootTree;
|
|
330
408
|
}
|
|
331
409
|
async parseDependenciesTree(jsonBlob) {
|
|
332
410
|
const dependencyTree = this.extractJsonFromPollutedOutput(jsonBlob);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,uCAA+B;AAC/B,6BAA4B;AAC5B,mDAA+D;AAC/D,iEAA6D;AAC7D,qDAA+D;AAE/D,+CAAiD;AAEjD,MAAa,wBAAyB,SAAQ,2CAAoD;IAAlG;;QACkB,mBAAc,GAAG;YAC/B,OAAO,EAAE,mBAAE,CAAC,IAAI;YAChB,QAAQ,EAAE,gBAAgB;SAC3B,CAAA;QAED,0DAA0D;QAClD,0BAAqB,GAAqB,EAAE,CAAA;QACpD,4FAA4F;QACpF,sBAAiB,GAAG,CAAC,CAAA;QAC7B,iEAAiE;QAChD,gBAAW,GAAG,IAAI,eAAI,CAAS,KAAK,IAAI,EAAE;;YACzD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAA,yCAAwB,EAAC,mBAAE,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;YACrF,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,MAAA,MAAM,CAAC,MAAM,mCAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YAChE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QACjC,CAAC,CAAC,CAAA;QAEF;;;;;;;;;;;;;WAaG;QACgB,cAAS,GAAG,IAAI,eAAI,CAAU,KAAK,IAAI,EAAE;YAC1D,sFAAsF;YACtF,0FAA0F;YAC1F,IAAI,UAAU,GAAG,KAAK,CAAA;YAC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AK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC;YAC3E,MAAM,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAEkB,qBAAqB,CAAC,IAAoB,EAAE,WAAmB;QAChF,oFAAoF;QACpF,MAAM,MAAM,GAAG,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,WAAW,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"]}
|
|
1
|
+
{"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,uCAA+B;AAC/B,6BAA4B;AAC5B,mDAA+D;AAC/D,iEAA6D;AAC7D,qDAA+D;AAE/D,+CAAiD;AAEjD,MAAa,wBAAyB,SAAQ,2CAAoD;IAAlG;;QACkB,mBAAc,GAAG;YAC/B,OAAO,EAAE,mBAAE,CAAC,IAAI;YAChB,QAAQ,EAAE,gBAAgB;SAC3B,CAAA;QAED,0DAA0D;QAClD,0BAAqB,GAAqB,EAAE,CAAA;QACpD,4FAA4F;QACpF,sBAAiB,GAAG,CAAC,CAAA;QAC7B,iEAAiE;QAChD,gBAAW,GAAG,IAAI,eAAI,CAAS,KAAK,IAAI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,qBAAqB,CAAC,IAAoB,EAAE,WAAmB;;QAChF,oFAAoF;QACpF,MAAM,MAAM,GAAG,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC7D,kFAAkF;QAClF,4FAA4F;QAC5F,IAAI,CAAC,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,mCAAI,IAAI,CAAC,CAAA;QAChJ,OAAO,IAAI,CAAC,QAAQ,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;AAjbD,4DAibC","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 { PackageJson, 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 /** The app's own node of the `pnpm list` output (the root of the production graph), set by `getTreeFromWorkspaces`. */\n private rootTree: 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 })().then(pkg => this.toRealPackage(pkg))\n\n if (memoKey != null) {\n this.locateMemo.set(memoKey, promise)\n }\n return promise\n }\n\n /**\n * Resolve a located package to its real directory (the symlink target), leaving a non-symlinked\n * hit untouched.\n *\n * `locatePackageVersion` returns the path it *walked*, which in pnpm's isolated store is the\n * `node_modules/<name>` symlink rather than `.pnpm/<name>@<ver>/node_modules/<name>`. That\n * distinction matters because the store keeps a package's dependencies as SIBLINGS inside\n * `.pnpm/<name>@<ver>/node_modules/`, reachable only from the real path: searching upward from\n * the symlink walks the dependent's directory instead, and finds the dependency only by accident\n * (through pnpm's hidden `.pnpm/node_modules` hoist, possibly at the wrong version). `visitDep`\n * resolves the deps of every package pnpm printed without children (deduped stubs) from disk\n * through here.\n *\n * Resolving the link is what Node itself does (`--preserve-symlinks` is off by default).\n */\n private async toRealPackage(pkg: Package | null): Promise<Package | null> {\n if (pkg == null) {\n return null\n }\n const packageDir = await this.cache.realPath[pkg.packageDir]\n return packageDir === pkg.packageDir ? pkg : { ...pkg, packageDir }\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 // The app root is never installed inside a node_modules directory, so it is read from its own\n // directory instead of being located by name. A by-name lookup finds a same-named dependency\n // whenever the app shares its name with one (an app called `debug` depending on `debug`), and\n // that dependency's package.json would then decide which of the app's dependencies are kept.\n const isRoot = tree === this.rootTree\n const rootPackageJson: PackageJson | null = isRoot && tree.path ? await fs.readJson(path.join(tree.path, \"package.json\")).catch(() => null) : null\n const { packageJson } = (isRoot ? { packageJson: rootPackageJson } : 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 readPackageJsonAt(dir: string): Promise<Package | null> {\n const packageJson: PackageJson | null = await fs.readJson(path.join(dir, \"package.json\")).catch(() => null)\n return packageJson ? { packageDir: dir, packageJson } : null\n }\n\n /**\n * Visit a single dependency node, adding it and its transitive deps to allDependencies.\n *\n * pnpm 10.29.3+ prints a repeated subtree only once; every later occurrence is a childless\n * `deduped` stub. Stubs must still be registered here: the one full print can sit under a node\n * this walk skips, e.g. a second peer variant of a package with the same `name@version` (the\n * guard below), so a package seen only as stubs was dropped from the asar together with its whole\n * closure (#10253). For a stub (and every dependency discovered beneath one, `fromDisk`), we fall\n * back to the on-disk package.json to discover transitive deps, resolving each one from the\n * package's own store directory first (where pnpm placed them).\n *\n * Other childless entries keep the tree walk. A `link:` package is also printed without children,\n * but its declared deps resolve from the link target's own `node_modules` (e.g. a linked\n * electron-updater checkout's monorepo store), outside the app. Walking them would register those\n * foreign copies under `name@version`, so the guard below then skips the app's own copy of the same\n * `name@version` together with its subtree (`jsonfile` vanished from under `fs-extra`).\n */\n private async visitDep(key: string, value: PnpmDependency, fromDisk = false): Promise<void> {\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\n const located = await this.locateFromDepOrRoot(key, value.path, value.version)\n const resolvedPath = located?.packageDir ?? value.path\n this.allDependencies.set(id, { ...value, path: resolvedPath })\n\n // Fall back to reading package.json straight from the resolved directory when the by-name lookup\n // came up empty, e.g. a workspace package, which nothing above it exposes under `node_modules/`.\n const pkg = located ?? (resolvedPath != null ? await this.readPackageJsonAt(resolvedPath) : null)\n const hasTreeDeps = Object.keys(value.dependencies ?? {}).length > 0 || Object.keys(value.optionalDependencies ?? {}).length > 0\n const isDedupedStub = (value.dedupedDependenciesCount ?? 0) > 0\n if ((isDedupedStub || fromDisk) && !hasTreeDeps && pkg?.packageJson) {\n // Pass the declared version range so that resolution skips wrong-version hoisted packages and\n // finds the correct nested copy.\n const pkgOptionalDecl = pkg.packageJson.optionalDependencies || {}\n const pkgDepsDecl = { ...(pkg.packageJson.dependencies || {}), ...pkgOptionalDecl }\n for (const [depName, depRange] of Object.entries(pkgDepsDecl)) {\n const resolved = await this.locateFromDepOrRoot(depName, pkg.packageDir, typeof depRange === \"string\" ? depRange : undefined)\n if (!resolved) {\n // A miss here silently ships a broken app (the dependency is simply absent from the\n // asar and only fails at runtime with MODULE_NOT_FOUND), so surface it in the log\n // summary. Optional deps are an expected miss and get the quieter bucket.\n this.logMissingDependency(`${depName}@${depRange}`, pkgOptionalDecl[depName] != null)\n continue\n }\n await this.visitDep(\n depName,\n {\n from: depName,\n name: depName,\n version: resolved.packageJson.version,\n path: resolved.packageDir,\n dependencies: {},\n optionalDependencies: {},\n } as unknown as PnpmDependency,\n true\n )\n }\n } else {\n await this.collectDepsRecursively(value)\n }\n }\n\n private async collectDepsRecursively(tree: PnpmDependency): Promise<void> {\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n await this.visitDep(key, value)\n }\n for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {\n await this.visitDep(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 // 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 this.rootTree = result !== tree ? result : (this.allWorkspacePackages.find(pkg => pkg.name === packageName || pkg.from === packageName) ?? tree)\n return this.rootTree\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,16 +1,56 @@
|
|
|
1
1
|
import { BlockMapDataHolder } from "builder-util-runtime";
|
|
2
2
|
export type CompressionFormat = "deflate" | "gzip";
|
|
3
|
+
/** Rabin content-defined chunker parameters. `avg` must be a power of two; `min` < `avg` <= `max`. */
|
|
4
|
+
export interface ChunkerParams {
|
|
5
|
+
min: number;
|
|
6
|
+
avg: number;
|
|
7
|
+
max: number;
|
|
8
|
+
}
|
|
9
|
+
/** Default chunker (go-rabin defaults): 8 KB min / 16 KB avg / 32 KB max. */
|
|
10
|
+
export declare const DEFAULT_CHUNKER: ChunkerParams;
|
|
11
|
+
/**
|
|
12
|
+
* A byte range of the input that should be chunked with its own parameters — e.g. a stored
|
|
13
|
+
* (uncompressed) archive member that is expected to change in small, localized ways between
|
|
14
|
+
* releases, where finer blocks make a differential download proportional to the change.
|
|
15
|
+
* Chunk boundaries are forced at both edges of every region, so the blocks inside a region
|
|
16
|
+
* depend only on the region's own bytes.
|
|
17
|
+
*/
|
|
18
|
+
export interface BlockMapRegion {
|
|
19
|
+
offset: number;
|
|
20
|
+
size: number;
|
|
21
|
+
chunker: ChunkerParams;
|
|
22
|
+
}
|
|
23
|
+
export interface BuildBlockMapOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Byte ranges of the input that are chunked with their own `ChunkerParams`; bytes outside every
|
|
26
|
+
* region use `DEFAULT_CHUNKER`. Regions must be ascending, non-overlapping and lie entirely
|
|
27
|
+
* within the input file (an empty list or `null` is equivalent to "no regions").
|
|
28
|
+
*
|
|
29
|
+
* A chunk boundary is forced at the start and at the end of every region: any pending chunk is
|
|
30
|
+
* emitted when the region begins and the last chunk of the region is emitted when it ends. Because
|
|
31
|
+
* the chunker state is reset at every boundary, the sequence of (checksum, size) blocks produced
|
|
32
|
+
* for a region depends only on the region's own bytes — it is identical for the same bytes placed
|
|
33
|
+
* at a different offset or surrounded by different data.
|
|
34
|
+
*/
|
|
35
|
+
regions?: Array<BlockMapRegion> | null;
|
|
36
|
+
}
|
|
3
37
|
/**
|
|
4
38
|
* Build a content-defined block map for `inFile` using Rabin fingerprinting.
|
|
5
39
|
*
|
|
6
|
-
* Files are processed via streaming (peak memory ≈
|
|
7
|
-
* not the full file size), making this safe for large installers.
|
|
40
|
+
* Files are processed via streaming (peak memory ≈ the largest chunker `max` — 32 KB by default —
|
|
41
|
+
* per chunk, not the full file size), making this safe for large installers.
|
|
8
42
|
*
|
|
9
43
|
* - If `outFile` is omitted: compressed blockmap is appended to `inFile`
|
|
10
44
|
* (used for NSIS web installer / AppImage embed); `blockMapSize` is returned.
|
|
11
45
|
* - If `outFile` is provided: compressed blockmap is written to that file;
|
|
12
46
|
* `blockMapSize` is not included in the result.
|
|
13
47
|
*
|
|
48
|
+
* `options.regions` lets byte ranges of the input be chunked with their own parameters (see
|
|
49
|
+
* `BuildBlockMapOptions`). Chunk boundaries are forced at both edges of every region and the chunker
|
|
50
|
+
* state is reset there, so the blocks of a region depend only on the region's own bytes. Without
|
|
51
|
+
* regions the output is exactly what the default chunker produces. Regions never affect the returned
|
|
52
|
+
* `size` or `sha512`.
|
|
53
|
+
*
|
|
14
54
|
* Returned `sha512` is SHA-512 of the full file as it exists after the call.
|
|
15
55
|
*/
|
|
16
|
-
export declare function buildBlockMap(inFile: string, compressionFormat: CompressionFormat, outFile?: string): Promise<BlockMapDataHolder>;
|
|
56
|
+
export declare function buildBlockMap(inFile: string, compressionFormat: CompressionFormat, outFile?: string, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CHUNKER = void 0;
|
|
3
4
|
exports.buildBlockMap = buildBlockMap;
|
|
4
5
|
const crypto_1 = require("crypto");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const promises_1 = require("fs/promises");
|
|
7
8
|
const zlib = require("zlib");
|
|
8
|
-
const
|
|
9
|
+
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
9
10
|
// Rabin fingerprinting constants from github.com/aclements/go-rabin:
|
|
10
11
|
// Poly64 = 0xbfe6b8a5bf378d83 (degree-63 irreducible polynomial over GF(2))
|
|
11
12
|
// Window = 64 bytes, Avg = 16 KB, Min = 8 KB, Max = 32 KB
|
|
@@ -30,36 +31,121 @@ const RABIN_MAX = 32768;
|
|
|
30
31
|
const RABIN_WINDOW = 64;
|
|
31
32
|
// Boundary: all mask bits (14 bits) set in lo word. RABIN_AVG is a power of 2.
|
|
32
33
|
const RABIN_HASH_MASK = RABIN_AVG - 1; // 0x3FFF
|
|
34
|
+
/** Default chunker (go-rabin defaults): 8 KB min / 16 KB avg / 32 KB max. */
|
|
35
|
+
exports.DEFAULT_CHUNKER = { min: RABIN_MIN, avg: RABIN_AVG, max: RABIN_MAX };
|
|
33
36
|
function compress(data, format) {
|
|
34
37
|
return format === "deflate" ? zlib.deflateRawSync(data, { level: 9 }) : zlib.gzipSync(data, { level: 9 });
|
|
35
38
|
}
|
|
39
|
+
// The boundary test is `(lo & (avg - 1)) === avg - 1` on the low 32-bit word of the hash, so `avg`
|
|
40
|
+
// must fit in a 32-bit mask. 2^31 keeps the mask a non-negative int32.
|
|
41
|
+
const MAX_CHUNKER_AVG = 0x80000000;
|
|
42
|
+
function validateChunkerParams(where, chunker) {
|
|
43
|
+
if (chunker == null || typeof chunker !== "object") {
|
|
44
|
+
throw new Error(`${where}: chunker is required`);
|
|
45
|
+
}
|
|
46
|
+
const { min, avg, max } = chunker;
|
|
47
|
+
for (const [name, value] of [
|
|
48
|
+
["min", min],
|
|
49
|
+
["avg", avg],
|
|
50
|
+
["max", max],
|
|
51
|
+
]) {
|
|
52
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
53
|
+
throw new Error(`${where}: chunker.${name} must be a positive integer, got ${String(value)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (avg > MAX_CHUNKER_AVG || (avg & (avg - 1)) !== 0) {
|
|
57
|
+
throw new Error(`${where}: chunker.avg must be a power of two not greater than ${MAX_CHUNKER_AVG}, got ${avg}`);
|
|
58
|
+
}
|
|
59
|
+
if (!(min < avg && avg <= max)) {
|
|
60
|
+
throw new Error(`${where}: chunker must satisfy min < avg <= max, got min=${min} avg=${avg} max=${max}`);
|
|
61
|
+
}
|
|
62
|
+
if (min <= RABIN_WINDOW) {
|
|
63
|
+
throw new Error(`${where}: chunker.min must be greater than the Rabin window (${RABIN_WINDOW}), got ${min}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate `regions` (ascending, non-overlapping, sane chunker parameters, within `fileSize`) and
|
|
68
|
+
* return a normalized copy.
|
|
69
|
+
*/
|
|
70
|
+
function normalizeRegions(regions, fileSize) {
|
|
71
|
+
const result = [];
|
|
72
|
+
let previousEnd = 0;
|
|
73
|
+
for (let i = 0; i < regions.length; i++) {
|
|
74
|
+
const region = regions[i];
|
|
75
|
+
const where = `blockmap region #${i}`;
|
|
76
|
+
if (region == null || typeof region !== "object") {
|
|
77
|
+
throw new Error(`${where}: must be an object with offset, size and chunker`);
|
|
78
|
+
}
|
|
79
|
+
const { offset, size } = region;
|
|
80
|
+
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
81
|
+
throw new Error(`${where}: offset must be a non-negative integer, got ${String(offset)}`);
|
|
82
|
+
}
|
|
83
|
+
if (!Number.isSafeInteger(size) || size <= 0) {
|
|
84
|
+
throw new Error(`${where}: size must be a positive integer, got ${String(size)}`);
|
|
85
|
+
}
|
|
86
|
+
validateChunkerParams(where, region.chunker);
|
|
87
|
+
if (offset < previousEnd) {
|
|
88
|
+
throw new Error(`${where}: regions must be ascending and non-overlapping (offset ${offset} < previous region end ${previousEnd})`);
|
|
89
|
+
}
|
|
90
|
+
const end = offset + size;
|
|
91
|
+
if (end > fileSize) {
|
|
92
|
+
throw new Error(`${where}: [${offset}, ${end}) extends past the end of the input (${fileSize} bytes)`);
|
|
93
|
+
}
|
|
94
|
+
previousEnd = end;
|
|
95
|
+
result.push({ offset, size, chunker: { min: region.chunker.min, avg: region.chunker.avg, max: region.chunker.max } });
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
36
99
|
/**
|
|
37
100
|
* Build a content-defined block map for `inFile` using Rabin fingerprinting.
|
|
38
101
|
*
|
|
39
|
-
* Files are processed via streaming (peak memory ≈
|
|
40
|
-
* not the full file size), making this safe for large installers.
|
|
102
|
+
* Files are processed via streaming (peak memory ≈ the largest chunker `max` — 32 KB by default —
|
|
103
|
+
* per chunk, not the full file size), making this safe for large installers.
|
|
41
104
|
*
|
|
42
105
|
* - If `outFile` is omitted: compressed blockmap is appended to `inFile`
|
|
43
106
|
* (used for NSIS web installer / AppImage embed); `blockMapSize` is returned.
|
|
44
107
|
* - If `outFile` is provided: compressed blockmap is written to that file;
|
|
45
108
|
* `blockMapSize` is not included in the result.
|
|
46
109
|
*
|
|
110
|
+
* `options.regions` lets byte ranges of the input be chunked with their own parameters (see
|
|
111
|
+
* `BuildBlockMapOptions`). Chunk boundaries are forced at both edges of every region and the chunker
|
|
112
|
+
* state is reset there, so the blocks of a region depend only on the region's own bytes. Without
|
|
113
|
+
* regions the output is exactly what the default chunker produces. Regions never affect the returned
|
|
114
|
+
* `size` or `sha512`.
|
|
115
|
+
*
|
|
47
116
|
* Returned `sha512` is SHA-512 of the full file as it exists after the call.
|
|
48
117
|
*/
|
|
49
|
-
async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
118
|
+
async function buildBlockMap(inFile, compressionFormat, outFile, options) {
|
|
119
|
+
const requestedRegions = options === null || options === void 0 ? void 0 : options.regions;
|
|
120
|
+
// The input is pre-stat'ed only when regions are given, so a region past the end of the file fails before any work is done.
|
|
121
|
+
const regions = requestedRegions == null || requestedRegions.length === 0 ? [] : normalizeRegions(requestedRegions, (await (0, promises_1.stat)(inFile)).size);
|
|
50
122
|
const fileHash = (0, crypto_1.createHash)("sha512");
|
|
51
123
|
const checksums = [];
|
|
52
124
|
const sizes = [];
|
|
53
125
|
let totalSize = 0;
|
|
54
|
-
//
|
|
55
|
-
|
|
126
|
+
// Chunker parameters of the current segment. A segment is either a region (its own parameters) or
|
|
127
|
+
// the span between regions (DEFAULT_CHUNKER). They only change when `filePos` crosses `segmentEnd`,
|
|
128
|
+
// so the per-byte loop never looks anything up.
|
|
129
|
+
let curMin = RABIN_MIN;
|
|
130
|
+
let curMax = RABIN_MAX;
|
|
131
|
+
let curMask = RABIN_HASH_MASK;
|
|
132
|
+
let curSkip = RABIN_MIN - RABIN_WINDOW;
|
|
133
|
+
let segmentEnd = Infinity; // absolute offset (exclusive) at which the current segment ends
|
|
134
|
+
let nextRegion = 0; // index into `regions` of the next region not yet entered
|
|
135
|
+
let filePos = 0; // absolute offset of the next byte fed to the chunker
|
|
136
|
+
// Per-chunk Rabin state. Peak memory ≈ largest `max` (RABIN_MAX = 32 KB by default) — not file size.
|
|
137
|
+
let maxChunkSize = RABIN_MAX;
|
|
138
|
+
for (const region of regions) {
|
|
139
|
+
maxChunkSize = Math.max(maxChunkSize, region.chunker.max);
|
|
140
|
+
}
|
|
141
|
+
const chunkBuf = Buffer.allocUnsafe(maxChunkSize);
|
|
56
142
|
let chunkN = 0; // bytes accumulated for current chunk
|
|
57
143
|
let hi = 0;
|
|
58
144
|
let lo = 0;
|
|
59
145
|
const win = new Uint8Array(RABIN_WINDOW); // rolling window ring buffer
|
|
60
146
|
let wpos = 0;
|
|
61
147
|
function emitChunk() {
|
|
62
|
-
checksums.push(Buffer.from((0,
|
|
148
|
+
checksums.push(Buffer.from((0, blake2_js_1.blake2b)(chunkBuf.subarray(0, chunkN), { dkLen: 18 })).toString("base64"));
|
|
63
149
|
sizes.push(chunkN);
|
|
64
150
|
chunkN = 0;
|
|
65
151
|
hi = 0;
|
|
@@ -67,15 +153,37 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
67
153
|
win.fill(0);
|
|
68
154
|
wpos = 0;
|
|
69
155
|
}
|
|
156
|
+
// Enter the segment that starts at absolute offset `pos` (always a forced chunk boundary, so the
|
|
157
|
+
// Rabin state is already reset here). Either the next region starts exactly at `pos`, or a
|
|
158
|
+
// default-chunker span runs from `pos` up to the next region (or to the end of the file).
|
|
159
|
+
function enterSegmentAt(pos) {
|
|
160
|
+
const region = nextRegion < regions.length ? regions[nextRegion] : null;
|
|
161
|
+
if (region != null && region.offset === pos) {
|
|
162
|
+
curMin = region.chunker.min;
|
|
163
|
+
curMax = region.chunker.max;
|
|
164
|
+
curMask = region.chunker.avg - 1;
|
|
165
|
+
curSkip = curMin - RABIN_WINDOW;
|
|
166
|
+
segmentEnd = region.offset + region.size;
|
|
167
|
+
nextRegion++;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
curMin = RABIN_MIN;
|
|
171
|
+
curMax = RABIN_MAX;
|
|
172
|
+
curMask = RABIN_HASH_MASK;
|
|
173
|
+
curSkip = RABIN_MIN - RABIN_WINDOW;
|
|
174
|
+
segmentEnd = region == null ? Infinity : region.offset;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
enterSegmentAt(0);
|
|
70
178
|
// Called once per byte; inlines the three-phase Rabin state machine:
|
|
71
179
|
// skip (< MIN-WINDOW bytes) → prime (next WINDOW bytes) → scan (≥ MIN bytes)
|
|
72
180
|
function processByte(b) {
|
|
73
181
|
chunkBuf[chunkN++] = b;
|
|
74
|
-
if (chunkN <=
|
|
182
|
+
if (chunkN <= curSkip) {
|
|
75
183
|
// Skip phase: not close enough to MIN to start priming yet
|
|
76
184
|
return;
|
|
77
185
|
}
|
|
78
|
-
if (chunkN <=
|
|
186
|
+
if (chunkN <= curMin) {
|
|
79
187
|
// Prime phase: non-windowed hash update, filling the ring buffer
|
|
80
188
|
win[wpos] = b;
|
|
81
189
|
wpos = (wpos + 1) % RABIN_WINDOW;
|
|
@@ -85,7 +193,7 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
85
193
|
hi = (nhi ^ PUSH_HI[top]) | 0;
|
|
86
194
|
lo = (nlo ^ PUSH_LO[top]) | 0;
|
|
87
195
|
// At exactly MIN: check whether the primed hash is already a boundary
|
|
88
|
-
if (chunkN ===
|
|
196
|
+
if (chunkN === curMin && (lo & curMask) === curMask) {
|
|
89
197
|
emitChunk();
|
|
90
198
|
}
|
|
91
199
|
return;
|
|
@@ -101,7 +209,7 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
101
209
|
const nlo = ((lo << 8) | b) & 0xffffffff;
|
|
102
210
|
hi = (nhi ^ PUSH_HI[top]) | 0;
|
|
103
211
|
lo = (nlo ^ PUSH_LO[top]) | 0;
|
|
104
|
-
if ((lo &
|
|
212
|
+
if ((lo & curMask) === curMask || chunkN >= curMax) {
|
|
105
213
|
emitChunk();
|
|
106
214
|
}
|
|
107
215
|
}
|
|
@@ -110,17 +218,36 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
110
218
|
const rs = (0, fs_1.createReadStream)(inFile, { highWaterMark: 256 * 1024 });
|
|
111
219
|
rs.on("data", (chunk) => {
|
|
112
220
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
221
|
+
fileHash.update(buf);
|
|
222
|
+
totalSize += buf.length;
|
|
223
|
+
let i = 0;
|
|
224
|
+
while (i < buf.length) {
|
|
225
|
+
// Feed bytes up to the end of the buffer or of the current segment, whichever comes first;
|
|
226
|
+
// `segmentEnd` is Infinity once the last region is behind us.
|
|
227
|
+
const n = Math.min(buf.length - i, segmentEnd - filePos);
|
|
228
|
+
const stop = i + n;
|
|
229
|
+
for (; i < stop; i++) {
|
|
230
|
+
processByte(buf[i]);
|
|
231
|
+
}
|
|
232
|
+
filePos += n;
|
|
233
|
+
if (filePos === segmentEnd) {
|
|
234
|
+
// Forced boundary at a region edge: flush whatever is pending and switch parameters.
|
|
235
|
+
if (chunkN > 0) {
|
|
236
|
+
emitChunk();
|
|
237
|
+
}
|
|
238
|
+
enterSegmentAt(filePos);
|
|
239
|
+
}
|
|
118
240
|
}
|
|
119
241
|
});
|
|
120
242
|
rs.on("end", () => {
|
|
121
243
|
if (chunkN > 0) {
|
|
122
244
|
emitChunk();
|
|
123
245
|
}
|
|
246
|
+
if (nextRegion < regions.length || segmentEnd !== Infinity) {
|
|
247
|
+
// Only reachable if the file shrank between the pre-stat and the read.
|
|
248
|
+
reject(new Error(`blockmap region extends past the end of the input (${totalSize} bytes)`));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
124
251
|
resolve();
|
|
125
252
|
});
|
|
126
253
|
rs.on("error", reject);
|