app-builder-lib 26.4.1 → 26.6.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 (34) hide show
  1. package/out/binDownload.d.ts +17 -0
  2. package/out/binDownload.js +153 -0
  3. package/out/binDownload.js.map +1 -1
  4. package/out/macPackager.js +2 -1
  5. package/out/macPackager.js.map +1 -1
  6. package/out/node-module-collector/hoist.js +7 -4
  7. package/out/node-module-collector/hoist.js.map +1 -1
  8. package/out/node-module-collector/nodeModulesCollector.d.ts +90 -2
  9. package/out/node-module-collector/nodeModulesCollector.js +143 -4
  10. package/out/node-module-collector/nodeModulesCollector.js.map +1 -1
  11. package/out/node-module-collector/npmNodeModulesCollector.d.ts +0 -1
  12. package/out/node-module-collector/npmNodeModulesCollector.js +1 -6
  13. package/out/node-module-collector/npmNodeModulesCollector.js.map +1 -1
  14. package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +1 -2
  15. package/out/node-module-collector/pnpmNodeModulesCollector.js +31 -36
  16. package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
  17. package/out/node-module-collector/traversalNodeModulesCollector.d.ts +0 -1
  18. package/out/node-module-collector/traversalNodeModulesCollector.js +0 -3
  19. package/out/node-module-collector/traversalNodeModulesCollector.js.map +1 -1
  20. package/out/options/macOptions.d.ts +4 -0
  21. package/out/options/macOptions.js.map +1 -1
  22. package/out/platformPackager.d.ts +1 -1
  23. package/out/platformPackager.js.map +1 -1
  24. package/out/targets/FlatpakTarget.js +11 -9
  25. package/out/targets/FlatpakTarget.js.map +1 -1
  26. package/out/targets/archive.js.map +1 -1
  27. package/out/util/packageDependencies.js +2 -1
  28. package/out/util/packageDependencies.js.map +1 -1
  29. package/out/version.d.ts +1 -1
  30. package/out/version.js +1 -1
  31. package/out/version.js.map +1 -1
  32. package/package.json +12 -10
  33. package/scheme.json +7 -0
  34. package/templates/nsis/uninstaller.nsh +2 -0
@@ -34,6 +34,21 @@ class NodeModulesCollector {
34
34
  return false;
35
35
  });
36
36
  }
37
+ /**
38
+ * Retrieves and collects all Node.js modules for a given package.
39
+ *
40
+ * This method orchestrates the entire module collection process by:
41
+ * 1. Fetching the dependency tree from the package manager
42
+ * 2. Collecting all dependencies recursively
43
+ * 3. Extracting workspace references if applicable
44
+ * 4. Building a production dependency graph
45
+ * 5. Hoisting the dependencies to their final locations
46
+ * 6. Resolving and returning module information
47
+ *
48
+ * @param options - Configuration object
49
+ * @param options.packageName - The name of the package to collect modules for
50
+ * @returns Promise resolving to an array of NodeModuleInfo objects representing all collected modules
51
+ */
37
52
  async getNodeModules({ packageName }) {
38
53
  const tree = await this.getDependenciesTree(this.installOptions.manager);
39
54
  await this.collectAllDependencies(tree, packageName);
@@ -46,6 +61,17 @@ class NodeModulesCollector {
46
61
  builder_util_1.log.debug({ packageName, depCount: this.nodeModules.length }, "node modules collection complete");
47
62
  return this.nodeModules;
48
63
  }
64
+ /**
65
+ * Retrieves the dependency tree from the package manager.
66
+ *
67
+ * Executes the appropriate package manager command to fetch the dependency tree and writes
68
+ * the output to a temporary file. Includes retry logic to handle transient failures such as
69
+ * incomplete JSON output or missing files. Will retry up to 1 time with exponential backoff.
70
+ *
71
+ * @param pm - The package manager to use (npm, yarn, pnpm, etc.)
72
+ * @returns Promise resolving to the parsed dependency tree
73
+ * @throws {Error} If the dependency tree cannot be retrieved after retries
74
+ */
49
75
  async getDependenciesTree(pm) {
50
76
  const command = (0, packageManager_1.getPackageManagerCommand)(pm);
51
77
  const args = this.getArgs();
@@ -56,7 +82,8 @@ class NodeModulesCollector {
56
82
  return (0, builder_util_1.retry)(async () => {
57
83
  await this.streamCollectorCommandToFile(command, args, this.rootDir, tempOutputFile);
58
84
  const shellOutput = await fs.readFile(tempOutputFile, { encoding: "utf8" });
59
- return await this.parseDependenciesTree(shellOutput.trim());
85
+ const result = await Promise.resolve(this.parseDependenciesTree(shellOutput));
86
+ return result;
60
87
  }, {
61
88
  retries: 1,
62
89
  interval: 2000,
@@ -64,7 +91,7 @@ class NodeModulesCollector {
64
91
  shouldRetry: async (error) => {
65
92
  var _a;
66
93
  const logFields = { error: error.message, tempOutputFile, cwd: this.rootDir };
67
- if (!(await this.cache.exists[tempOutputFile])) {
94
+ if (!(await (0, builder_util_1.exists)(tempOutputFile))) {
68
95
  builder_util_1.log.debug(logFields, "dependency tree output file missing, retrying");
69
96
  return true;
70
97
  }
@@ -83,6 +110,77 @@ class NodeModulesCollector {
83
110
  },
84
111
  });
85
112
  }
113
+ /**
114
+ * Parses the dependencies tree from shell command output.
115
+ *
116
+ **/
117
+ parseDependenciesTree(shellOutput) {
118
+ return this.extractJsonFromPollutedOutput(shellOutput);
119
+ }
120
+ /**
121
+ *
122
+ * This method attempts to extract and parse JSON data from shell output that may contain
123
+ * additional non-JSON content (like warnings or informational messages). It first tries
124
+ * to parse the entire output as JSON, and if that fails, it intelligently searches for
125
+ * JSON content within the output by:
126
+ * 1. Finding the first line that starts with `{` or `[`
127
+ * 2. Tracking bracket depth to find the matching closing bracket
128
+ * 3. Extracting only the valid JSON portion
129
+ *
130
+ * @param shellOutput - The raw output from a shell command, potentially containing JSON
131
+ * @returns The parsed dependencies tree object
132
+ * @throws {Error} If no JSON content is found in the output
133
+ * @throws {Error} If no matching closing bracket is found in the output
134
+ * @throws {SyntaxError} If the extracted content is not valid JSON
135
+ */
136
+ extractJsonFromPollutedOutput(shellOutput) {
137
+ const consoleOutput = shellOutput.trim();
138
+ try {
139
+ return JSON.parse(consoleOutput);
140
+ }
141
+ catch {
142
+ // Continue
143
+ }
144
+ const lines = consoleOutput.split("\n");
145
+ // Find the first line that starts with { or [
146
+ const jsonStartIdx = lines.findIndex(line => {
147
+ const trimmed = line.trim();
148
+ return trimmed.startsWith("{") || trimmed.startsWith("[");
149
+ });
150
+ if (jsonStartIdx === -1) {
151
+ throw new Error("No JSON content found in output");
152
+ }
153
+ // Find matching closing bracket using bracket counting
154
+ let depth = 0;
155
+ let jsonEndIdx = -1;
156
+ for (let i = jsonStartIdx; i < lines.length; i++) {
157
+ const line = lines[i];
158
+ for (const char of line) {
159
+ if (char === "{" || char === "[") {
160
+ depth++;
161
+ }
162
+ else if (char === "}" || char === "]") {
163
+ depth--;
164
+ if (depth === 0) {
165
+ jsonEndIdx = i;
166
+ break;
167
+ }
168
+ }
169
+ }
170
+ if (jsonEndIdx !== -1) {
171
+ break;
172
+ }
173
+ }
174
+ if (jsonEndIdx === -1) {
175
+ throw new Error("No matching closing bracket found in output");
176
+ }
177
+ // Parse the matched JSON section
178
+ const candidate = lines
179
+ .slice(jsonStartIdx, jsonEndIdx + 1)
180
+ .join("\n")
181
+ .trim();
182
+ return JSON.parse(candidate);
183
+ }
86
184
  cacheKey(pkg) {
87
185
  const rel = path.relative(this.rootDir, pkg.path);
88
186
  return `${pkg.name}::${pkg.version}::${rel !== null && rel !== void 0 ? rel : "."}`;
@@ -90,6 +188,16 @@ class NodeModulesCollector {
90
188
  packageVersionString(pkg) {
91
189
  return `${pkg.name}@${pkg.version}`;
92
190
  }
191
+ /**
192
+ * Determines if a given dependency is a production dependency of a package.
193
+ *
194
+ * Checks both the dependencies and optionalDependencies of a package to see if
195
+ * the specified dependency name is listed.
196
+ *
197
+ * @param depName - The name of the dependency to check
198
+ * @param pkg - The package to search for the dependency in
199
+ * @returns True if the dependency is found in either dependencies or optionalDependencies, false otherwise
200
+ */
93
201
  isProdDependency(depName, pkg) {
94
202
  const prodDeps = { ...pkg.dependencies, ...pkg.optionalDependencies };
95
203
  return prodDeps[depName] != null;
@@ -103,7 +211,11 @@ class NodeModulesCollector {
103
211
  return result;
104
212
  }
105
213
  /**
106
- * Parse a dependency identifier like "@scope/pkg@1.2.3" or "pkg@1.2.3"
214
+ * Parses a dependency identifier string into name and version components.
215
+ *
216
+ * Handles both scoped packages (e.g., "@scope/pkg@1.2.3") and regular packages (e.g., "pkg@1.2.3").
217
+ * If the identifier is malformed or cannot be parsed, defaults to treating the entire string as
218
+ * the package name with an "unknown" version.
107
219
  */
108
220
  parseNameVersion(identifier) {
109
221
  const lastAt = identifier.lastIndexOf("@");
@@ -115,6 +227,17 @@ class NodeModulesCollector {
115
227
  const version = identifier.slice(lastAt + 1);
116
228
  return { name, version };
117
229
  }
230
+ /**
231
+ * Retrieves the dependency tree and handles workspace package self-references.
232
+ *
233
+ * If the project is a workspace project, this method removes the root package's self-reference
234
+ * from the dependency tree to avoid circular dependencies. It promotes the root package's
235
+ * direct dependencies to the top level of the tree.
236
+ *
237
+ * @param tree - The original dependency tree
238
+ * @param packageName - The name of the package to check for and remove from the tree
239
+ * @returns Promise resolving to the pruned dependency tree
240
+ */
118
241
  async getTreeFromWorkspaces(tree, packageName) {
119
242
  var _a;
120
243
  if (!(tree.workspaces && tree.dependencies)) {
@@ -194,6 +317,22 @@ class NodeModulesCollector {
194
317
  return { stdout: undefined, stderr: error.message };
195
318
  }
196
319
  }
320
+ /**
321
+ * Executes a command and streams its output to a file.
322
+ *
323
+ * Spawns a child process to execute the specified command with arguments, capturing stdout
324
+ * to a file. Handles Windows-specific quirks by wrapping .cmd files in a temporary .bat file
325
+ * when necessary. Enables corepack strict mode by default but allows process.env overrides.
326
+ *
327
+ * Special handling for `npm list` exit code 1, which is expected in certain scenarios.
328
+ *
329
+ * @param command - The command to execute
330
+ * @param args - Array of command-line arguments
331
+ * @param cwd - The working directory to execute the command in
332
+ * @param tempOutputFile - The path to the temporary file where stdout will be written
333
+ * @returns Promise that resolves when the command completes successfully or rejects if it fails
334
+ * @throws {Error} If the child process spawn fails or exits with a non-zero code
335
+ */
197
336
  async streamCollectorCommandToFile(command, args, cwd, tempOutputFile) {
198
337
  const execName = path.basename(command, path.extname(command));
199
338
  const isWindowsScriptFile = process.platform === "win32" && path.extname(command).toLowerCase() === ".cmd";
@@ -216,7 +355,7 @@ class NodeModulesCollector {
216
355
  const child = childProcess.spawn(command, args, {
217
356
  cwd,
218
357
  env: { COREPACK_ENABLE_STRICT: "0", ...process.env }, // allow `process.env` overrides
219
- shell: false, // required to prevent console logs polution from shell profile loading when `true`
358
+ shell: true, // `true`` is now required: https://github.com/electron-userland/electron-builder/issues/9488
220
359
  });
221
360
  let stderr = "";
222
361
  child.stdout.pipe(outStream);
@@ -1 +1 @@
1
- {"version":3,"file":"nodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/nodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,8CAA6C;AAC7C,+BAA8B;AAC9B,uCAA4C;AAC5C,uCAA+B;AAC/B,6BAA4B;AAC5B,mCAAqE;AACrE,mDAA+C;AAC/C,qDAA+D;AAG/D,MAAsB,oBAAoB;IAsBxC,YACqB,OAAe,EACjB,cAAsB;QADpB,YAAO,GAAP,OAAO,CAAQ;QACjB,mBAAc,GAAd,cAAc,CAAQ;QAvBxB,gBAAW,GAAqB,EAAE,CAAA;QAChC,oBAAe,GAA6B,IAAI,GAAG,EAAE,CAAA;QACrD,oBAAe,GAAoB,EAAE,CAAA;QACrC,UAAK,GAAkB,IAAI,6BAAa,EAAE,CAAA;QAEnD,cAAS,GAAG,IAAI,eAAI,CAAU,KAAK,IAAI,EAAE;YACjD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,cAAc,CAAA;YACvC,MAAM,OAAO,GAAG,IAAA,yCAAwB,EAAC,OAAO,CAAC,CAAA;YACjD,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;YACzE,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,kBAAG,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,iGAAiG,CAAC,CAAA;gBACzH,OAAO,KAAK,CAAA;YACd,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAA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OAAO,EAAE,GAAG,CAAC,EAAE;gBACtB,MAAM,CAAC,IAAI,KAAK,CAAC,uCAAuC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;YACzE,CAAC,CAAC,CAAA;YAEF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE;gBACvB,SAAS,CAAC,KAAK,EAAE,CAAA;gBACjB,0CAA0C;gBAC1C,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,QAAQ,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;gBAC5F,IAAI,YAAY,EAAE,CAAC;oBACjB,kBAAG,CAAC,KAAK,CAAC,IAAI,EAAE,uIAAuI,CAAC,CAAA;gBAC1J,CAAC;gBACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtB,kBAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,wDAAwD,CAAC,CAAA;gBACjF,CAAC;gBACD,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,IAAI,YAAY,CAAA;gBAChD,OAAO,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kDAAkD,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC,CAAA;YAC5H,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AApRD,oDAoRC","sourcesContent":["import { log, retry, TmpDir } from \"builder-util\"\nimport * as childProcess from \"child_process\"\nimport * as fs from \"fs-extra\"\nimport { createWriteStream } from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { hoist, type HoisterResult, type HoisterTree } from \"./hoist\"\nimport { ModuleManager } from \"./moduleManager\"\nimport { getPackageManagerCommand, PM } from \"./packageManager\"\nimport type { Dependency, DependencyGraph, NodeModuleInfo, PackageJson } from \"./types\"\n\nexport abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDepType, OptionalDepType>, OptionalDepType> {\n private readonly nodeModules: NodeModuleInfo[] = []\n protected readonly allDependencies: Map<string, ProdDepType> = new Map()\n protected readonly productionGraph: DependencyGraph = {}\n protected readonly cache: ModuleManager = new ModuleManager()\n\n protected isHoisted = new Lazy<boolean>(async () => {\n const { manager } = this.installOptions\n const command = getPackageManagerCommand(manager)\n const config = (await this.asyncExec(command, [\"config\", \"list\"])).stdout\n if (config == null) {\n log.debug({ manager }, \"unable to determine if node_modules are hoisted: no config output. falling back to hoisted mode\")\n return false\n }\n const lines = Object.fromEntries(config.split(\"\\n\").map(line => line.split(\"=\").map(s => s.trim())))\n if (lines[\"node-linker\"] === \"hoisted\") {\n log.debug({ manager }, \"node_modules are hoisted\")\n return true\n }\n return false\n })\n\n constructor(\n protected readonly rootDir: string,\n private readonly tempDirManager: TmpDir\n ) {}\n\n public async getNodeModules({ packageName }: { packageName: string }): Promise<NodeModuleInfo[]> {\n const tree: ProdDepType = await this.getDependenciesTree(this.installOptions.manager)\n\n await this.collectAllDependencies(tree, packageName)\n const realTree: ProdDepType = await this.getTreeFromWorkspaces(tree, packageName)\n await this.extractProductionDependencyGraph(realTree, packageName)\n\n const hoisterResult: HoisterResult = hoist(this.transformToHoisterTree(this.productionGraph, packageName), {\n check: log.isDebugEnabled,\n })\n\n await this._getNodeModules(hoisterResult.dependencies, this.nodeModules)\n log.debug({ packageName, depCount: this.nodeModules.length }, \"node modules collection complete\")\n\n return this.nodeModules\n }\n\n public abstract readonly installOptions: {\n manager: PM\n lockfile: string\n }\n\n protected abstract getArgs(): string[]\n protected abstract parseDependenciesTree(jsonBlob: string): Promise<ProdDepType>\n protected abstract extractProductionDependencyGraph(tree: Dependency<ProdDepType, OptionalDepType>, dependencyId: string): Promise<void>\n protected abstract collectAllDependencies(tree: Dependency<ProdDepType, OptionalDepType>, appPackageName: string): Promise<void>\n\n protected async getDependenciesTree(pm: PM): Promise<ProdDepType> {\n const command = getPackageManagerCommand(pm)\n const args = this.getArgs()\n\n const tempOutputFile = await this.tempDirManager.getTempFile({\n prefix: path.basename(command, path.extname(command)),\n suffix: \"output.json\",\n })\n\n return retry(\n async () => {\n await this.streamCollectorCommandToFile(command, args, this.rootDir, tempOutputFile)\n const shellOutput = await fs.readFile(tempOutputFile, { encoding: \"utf8\" })\n return await this.parseDependenciesTree(shellOutput.trim())\n },\n {\n retries: 1,\n interval: 2000,\n backoff: 2000,\n shouldRetry: async (error: any) => {\n const logFields = { error: error.message, tempOutputFile, cwd: this.rootDir }\n\n if (!(await this.cache.exists[tempOutputFile])) {\n log.debug(logFields, \"dependency tree output file missing, retrying\")\n return true\n }\n\n const fileContent = await fs.readFile(tempOutputFile, { encoding: \"utf8\" })\n const fields = { ...logFields, fileContent }\n\n if (fileContent.trim().length === 0) {\n log.debug(fields, \"dependency tree output file empty, retrying\")\n return true\n }\n\n if (error.message?.includes(\"Unexpected end of JSON input\")) {\n log.debug(fields, \"JSON parse error in dependency tree, retrying\")\n return true\n }\n\n log.error(fields, \"error parsing dependencies tree\")\n return false\n },\n }\n )\n }\n\n protected cacheKey(pkg: Pick<ProdDepType, \"name\" | \"version\" | \"path\">): string {\n const rel = path.relative(this.rootDir, pkg.path)\n return `${pkg.name}::${pkg.version}::${rel ?? \".\"}`\n }\n\n protected packageVersionString(pkg: Pick<ProdDepType, \"name\" | \"version\">): string {\n return `${pkg.name}@${pkg.version}`\n }\n\n protected isProdDependency(depName: string, pkg: ProdDepType): boolean {\n const prodDeps = { ...pkg.dependencies, ...pkg.optionalDependencies }\n return prodDeps[depName] != null\n }\n\n protected async locatePackageWithVersion(depTree: Pick<ProdDepType, \"name\" | \"version\" | \"path\">): Promise<{ packageDir: string; packageJson: PackageJson } | null> {\n const result = await this.cache.locatePackageVersion({\n parentDir: depTree.path,\n pkgName: depTree.name,\n requiredRange: depTree.version,\n })\n return result\n }\n /**\n * Parse a dependency identifier like \"@scope/pkg@1.2.3\" or \"pkg@1.2.3\"\n */\n protected parseNameVersion(identifier: string): { name: string; version: string } {\n const lastAt = identifier.lastIndexOf(\"@\")\n if (lastAt <= 0) {\n // fallback for scoped packages or malformed strings\n return { name: identifier, version: \"unknown\" }\n }\n const name = identifier.slice(0, lastAt)\n const version = identifier.slice(lastAt + 1)\n return { name, version }\n }\n\n protected async getTreeFromWorkspaces(tree: ProdDepType, packageName: string): Promise<ProdDepType> {\n if (!(tree.workspaces && tree.dependencies)) {\n return tree\n }\n\n if (tree.dependencies?.[packageName]) {\n const { name, path, dependencies } = tree.dependencies[packageName]\n log.debug({ name, path, dependencies: JSON.stringify(dependencies) }, \"pruning root app/self reference from workspace tree\")\n for (const [name, pkg] of Object.entries(dependencies ?? {})) {\n tree.dependencies[name] = pkg\n this.allDependencies.set(this.packageVersionString(pkg), pkg)\n }\n delete tree.dependencies[packageName]\n }\n return Promise.resolve(tree)\n }\n\n private transformToHoisterTree(obj: DependencyGraph, key: string, nodes: Map<string, HoisterTree> = new Map()): HoisterTree {\n let node = nodes.get(key)\n const { name, version } = this.parseNameVersion(key)\n\n if (!node) {\n node = {\n name,\n identName: name,\n reference: version,\n dependencies: new Set<HoisterTree>(),\n peerNames: new Set<string>(),\n }\n\n nodes.set(key, node)\n\n const deps = (obj[key] || {}).dependencies || []\n for (const dep of deps) {\n const child = this.transformToHoisterTree(obj, dep, nodes)\n node.dependencies.add(child)\n }\n }\n\n return node\n }\n\n private async _getNodeModules(dependencies: Set<HoisterResult>, result: NodeModuleInfo[]) {\n if (dependencies.size === 0) {\n return\n }\n\n for (const d of dependencies.values()) {\n const reference = [...d.references][0]\n const p = this.allDependencies.get(`${d.name}@${reference}`)?.path\n if (p === undefined) {\n log.warn({ name: d.name, reference }, \"cannot find path for dependency\")\n continue\n }\n\n // fix npm list issue\n // https://github.com/npm/cli/issues/8535\n if (!(await this.cache.exists[p])) {\n log.debug({ name: d.name, reference, p }, \"dependency path does not exist\")\n continue\n }\n\n const node: NodeModuleInfo = {\n name: d.name,\n version: reference,\n dir: await this.cache.realPath[p],\n }\n result.push(node)\n if (d.dependencies.size > 0) {\n node.dependencies = []\n await this._getNodeModules(d.dependencies, node.dependencies)\n }\n }\n result.sort((a, b) => a.name.localeCompare(b.name))\n }\n\n async asyncExec(command: string, args: string[], cwd: string = this.rootDir): Promise<{ stdout: string | undefined; stderr: string | undefined }> {\n const file = await this.tempDirManager.getTempFile({ prefix: \"exec-\", suffix: \".txt\" })\n try {\n await this.streamCollectorCommandToFile(command, args, cwd, file)\n const result = await fs.readFile(file, { encoding: \"utf8\" })\n return { stdout: result?.trim(), stderr: undefined }\n } catch (error: any) {\n log.debug({ error: error.message }, \"failed to execute command\")\n return { stdout: undefined, stderr: error.message }\n }\n }\n\n async streamCollectorCommandToFile(command: string, args: string[], cwd: string, tempOutputFile: string) {\n const execName = path.basename(command, path.extname(command))\n const isWindowsScriptFile = process.platform === \"win32\" && path.extname(command).toLowerCase() === \".cmd\"\n if (isWindowsScriptFile) {\n // If the command is a Windows script file (.cmd), we need to wrap it in a .bat file to ensure it runs correctly with cmd.exe\n // This is necessary because .cmd files are not directly executable in the same way as .bat files.\n // We create a temporary .bat file that calls the .cmd file with the provided arguments. The .bat file will be executed by cmd.exe.\n // Note: This is a workaround for Windows command execution quirks for specifically when `shell: false`\n const tempBatFile = await this.tempDirManager.getTempFile({\n prefix: execName,\n suffix: \".bat\",\n })\n const batScript = `@echo off\\r\\n\"${command}\" %*\\r\\n` // <-- CRLF required for .bat\n await fs.writeFile(tempBatFile, batScript, { encoding: \"utf8\" })\n command = \"cmd.exe\"\n args = [\"/c\", tempBatFile, ...args]\n }\n\n await new Promise<void>((resolve, reject) => {\n const outStream = createWriteStream(tempOutputFile)\n\n const child = childProcess.spawn(command, args, {\n cwd,\n env: { COREPACK_ENABLE_STRICT: \"0\", ...process.env }, // allow `process.env` overrides\n shell: false, // required to prevent console logs polution from shell profile loading when `true`\n })\n\n let stderr = \"\"\n child.stdout.pipe(outStream)\n child.stderr.on(\"data\", chunk => {\n stderr += chunk.toString()\n })\n child.on(\"error\", err => {\n reject(new Error(`Node module collector spawn failed: ${err.message}`))\n })\n\n child.on(\"close\", code => {\n outStream.close()\n // https://github.com/npm/npm/issues/17624\n const shouldIgnore = code === 1 && \"npm\" === execName.toLowerCase() && args.includes(\"list\")\n if (shouldIgnore) {\n log.debug(null, \"`npm list` returned non-zero exit code, but it MIGHT be expected (https://github.com/npm/npm/issues/17624). Check stderr for details.\")\n }\n if (stderr.length > 0) {\n log.debug({ stderr }, \"note: there was node module collector output on stderr\")\n }\n const shouldResolve = code === 0 || shouldIgnore\n return shouldResolve ? resolve() : reject(new Error(`Node module collector process exited with code ${code}:\\n${stderr}`))\n })\n })\n }\n}\n"]}
1
+ {"version":3,"file":"nodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/nodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+CAAyD;AACzD,8CAA6C;AAC7C,+BAA8B;AAC9B,uCAA4C;AAC5C,uCAA+B;AAC/B,6BAA4B;AAC5B,mCAAqE;AACrE,mDAA+C;AAC/C,qDAA+D;AAG/D,MAAsB,oBAAoB;IAsBxC,YACqB,OAAe,EACjB,cAAsB;QADpB,YAAO,GAAP,OAAO,CAAQ;QACjB,mBAAc,GAAd,cAAc,CAAQ;QAvBxB,gBAAW,GAAqB,EAAE,CAAA;QAChC,oBAAe,GAA6B,IAAI,GAAG,EAAE,CAAA;QACrD,oBAAe,GAAoB,EAAE,CAAA;QACrC,UAAK,GAAkB,IAAI,6BAAa,EAAE,CAAA;QAEnD,cAAS,GAAG,IAAI,eAAI,CAAU,KAAK,IAAI,EAAE;YACjD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,cAAc,CAAA;YACvC,MAAM,OAAO,GAAG,IAAA,yCAAwB,EAAC,OAAO,CAAC,CAAA;YACjD,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,QAAQ,EA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,IAAI,CAAC,EAAE;gBACvB,SAAS,CAAC,KAAK,EAAE,CAAA;gBACjB,0CAA0C;gBAC1C,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,QAAQ,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;gBAC5F,IAAI,YAAY,EAAE,CAAC;oBACjB,kBAAG,CAAC,KAAK,CAAC,IAAI,EAAE,uIAAuI,CAAC,CAAA;gBAC1J,CAAC;gBACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtB,kBAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,wDAAwD,CAAC,CAAA;gBACjF,CAAC;gBACD,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,IAAI,YAAY,CAAA;gBAChD,OAAO,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kDAAkD,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC,CAAA;YAC5H,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAraD,oDAqaC","sourcesContent":["import { exists, log, retry, TmpDir } from \"builder-util\"\nimport * as childProcess from \"child_process\"\nimport * as fs from \"fs-extra\"\nimport { createWriteStream } from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { hoist, type HoisterResult, type HoisterTree } from \"./hoist\"\nimport { ModuleManager } from \"./moduleManager\"\nimport { getPackageManagerCommand, PM } from \"./packageManager\"\nimport type { Dependency, DependencyGraph, NodeModuleInfo, PackageJson } from \"./types\"\n\nexport abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDepType, OptionalDepType>, OptionalDepType> {\n private readonly nodeModules: NodeModuleInfo[] = []\n protected readonly allDependencies: Map<string, ProdDepType> = new Map()\n protected readonly productionGraph: DependencyGraph = {}\n protected readonly cache: ModuleManager = new ModuleManager()\n\n protected isHoisted = new Lazy<boolean>(async () => {\n const { manager } = this.installOptions\n const command = getPackageManagerCommand(manager)\n const config = (await this.asyncExec(command, [\"config\", \"list\"])).stdout\n if (config == null) {\n log.debug({ manager }, \"unable to determine if node_modules are hoisted: no config output. falling back to hoisted mode\")\n return false\n }\n const lines = Object.fromEntries(config.split(\"\\n\").map(line => line.split(\"=\").map(s => s.trim())))\n if (lines[\"node-linker\"] === \"hoisted\") {\n log.debug({ manager }, \"node_modules are hoisted\")\n return true\n }\n return false\n })\n\n constructor(\n protected readonly rootDir: string,\n private readonly tempDirManager: TmpDir\n ) {}\n\n /**\n * Retrieves and collects all Node.js modules for a given package.\n *\n * This method orchestrates the entire module collection process by:\n * 1. Fetching the dependency tree from the package manager\n * 2. Collecting all dependencies recursively\n * 3. Extracting workspace references if applicable\n * 4. Building a production dependency graph\n * 5. Hoisting the dependencies to their final locations\n * 6. Resolving and returning module information\n *\n * @param options - Configuration object\n * @param options.packageName - The name of the package to collect modules for\n * @returns Promise resolving to an array of NodeModuleInfo objects representing all collected modules\n */\n public async getNodeModules({ packageName }: { packageName: string }): Promise<NodeModuleInfo[]> {\n const tree: ProdDepType = await this.getDependenciesTree(this.installOptions.manager)\n\n await this.collectAllDependencies(tree, packageName)\n const realTree: ProdDepType = await this.getTreeFromWorkspaces(tree, packageName)\n await this.extractProductionDependencyGraph(realTree, packageName)\n\n const hoisterResult: HoisterResult = hoist(this.transformToHoisterTree(this.productionGraph, packageName), {\n check: log.isDebugEnabled,\n })\n\n await this._getNodeModules(hoisterResult.dependencies, this.nodeModules)\n log.debug({ packageName, depCount: this.nodeModules.length }, \"node modules collection complete\")\n\n return this.nodeModules\n }\n\n public abstract readonly installOptions: {\n manager: PM\n lockfile: string\n }\n\n protected abstract getArgs(): string[]\n protected abstract extractProductionDependencyGraph(tree: Dependency<ProdDepType, OptionalDepType>, dependencyId: string): Promise<void>\n protected abstract collectAllDependencies(tree: Dependency<ProdDepType, OptionalDepType>, appPackageName: string): Promise<void>\n\n /**\n * Retrieves the dependency tree from the package manager.\n *\n * Executes the appropriate package manager command to fetch the dependency tree and writes\n * the output to a temporary file. Includes retry logic to handle transient failures such as\n * incomplete JSON output or missing files. Will retry up to 1 time with exponential backoff.\n *\n * @param pm - The package manager to use (npm, yarn, pnpm, etc.)\n * @returns Promise resolving to the parsed dependency tree\n * @throws {Error} If the dependency tree cannot be retrieved after retries\n */\n protected async getDependenciesTree(pm: PM): Promise<ProdDepType> {\n const command = getPackageManagerCommand(pm)\n const args = this.getArgs()\n\n const tempOutputFile = await this.tempDirManager.getTempFile({\n prefix: path.basename(command, path.extname(command)),\n suffix: \"output.json\",\n })\n\n return retry(\n async () => {\n await this.streamCollectorCommandToFile(command, args, this.rootDir, tempOutputFile)\n const shellOutput = await fs.readFile(tempOutputFile, { encoding: \"utf8\" })\n const result = await Promise.resolve(this.parseDependenciesTree(shellOutput))\n return result\n },\n {\n retries: 1,\n interval: 2000,\n backoff: 2000,\n shouldRetry: async (error: any) => {\n const logFields = { error: error.message, tempOutputFile, cwd: this.rootDir }\n\n if (!(await exists(tempOutputFile))) {\n log.debug(logFields, \"dependency tree output file missing, retrying\")\n return true\n }\n\n const fileContent = await fs.readFile(tempOutputFile, { encoding: \"utf8\" })\n const fields = { ...logFields, fileContent }\n\n if (fileContent.trim().length === 0) {\n log.debug(fields, \"dependency tree output file empty, retrying\")\n return true\n }\n\n if (error.message?.includes(\"Unexpected end of JSON input\")) {\n log.debug(fields, \"JSON parse error in dependency tree, retrying\")\n return true\n }\n\n log.error(fields, \"error parsing dependencies tree\")\n return false\n },\n }\n )\n }\n\n /**\n * Parses the dependencies tree from shell command output.\n *\n **/\n protected parseDependenciesTree(shellOutput: string): ProdDepType | Promise<ProdDepType> {\n return this.extractJsonFromPollutedOutput<ProdDepType>(shellOutput)\n }\n /**\n *\n * This method attempts to extract and parse JSON data from shell output that may contain\n * additional non-JSON content (like warnings or informational messages). It first tries\n * to parse the entire output as JSON, and if that fails, it intelligently searches for\n * JSON content within the output by:\n * 1. Finding the first line that starts with `{` or `[`\n * 2. Tracking bracket depth to find the matching closing bracket\n * 3. Extracting only the valid JSON portion\n *\n * @param shellOutput - The raw output from a shell command, potentially containing JSON\n * @returns The parsed dependencies tree object\n * @throws {Error} If no JSON content is found in the output\n * @throws {Error} If no matching closing bracket is found in the output\n * @throws {SyntaxError} If the extracted content is not valid JSON\n */\n protected extractJsonFromPollutedOutput<T>(shellOutput: string): T {\n const consoleOutput = shellOutput.trim()\n try {\n return JSON.parse(consoleOutput)\n } catch {\n // Continue\n }\n\n const lines = consoleOutput.split(\"\\n\")\n\n // Find the first line that starts with { or [\n const jsonStartIdx = lines.findIndex(line => {\n const trimmed = line.trim()\n return trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")\n })\n\n if (jsonStartIdx === -1) {\n throw new Error(\"No JSON content found in output\")\n }\n\n // Find matching closing bracket using bracket counting\n let depth = 0\n let jsonEndIdx = -1\n\n for (let i = jsonStartIdx; i < lines.length; i++) {\n const line = lines[i]\n for (const char of line) {\n if (char === \"{\" || char === \"[\") {\n depth++\n } else if (char === \"}\" || char === \"]\") {\n depth--\n if (depth === 0) {\n jsonEndIdx = i\n break\n }\n }\n }\n if (jsonEndIdx !== -1) {\n break\n }\n }\n\n if (jsonEndIdx === -1) {\n throw new Error(\"No matching closing bracket found in output\")\n }\n\n // Parse the matched JSON section\n const candidate = lines\n .slice(jsonStartIdx, jsonEndIdx + 1)\n .join(\"\\n\")\n .trim()\n\n return JSON.parse(candidate)\n }\n\n protected cacheKey(pkg: Pick<ProdDepType, \"name\" | \"version\" | \"path\">): string {\n const rel = path.relative(this.rootDir, pkg.path)\n return `${pkg.name}::${pkg.version}::${rel ?? \".\"}`\n }\n\n protected packageVersionString(pkg: Pick<ProdDepType, \"name\" | \"version\">): string {\n return `${pkg.name}@${pkg.version}`\n }\n\n /**\n * Determines if a given dependency is a production dependency of a package.\n *\n * Checks both the dependencies and optionalDependencies of a package to see if\n * the specified dependency name is listed.\n *\n * @param depName - The name of the dependency to check\n * @param pkg - The package to search for the dependency in\n * @returns True if the dependency is found in either dependencies or optionalDependencies, false otherwise\n */\n protected isProdDependency(depName: string, pkg: ProdDepType): boolean {\n const prodDeps = { ...pkg.dependencies, ...pkg.optionalDependencies }\n return prodDeps[depName] != null\n }\n\n protected async locatePackageWithVersion(depTree: Pick<ProdDepType, \"name\" | \"version\" | \"path\">): Promise<{ packageDir: string; packageJson: PackageJson } | null> {\n const result = await this.cache.locatePackageVersion({\n parentDir: depTree.path,\n pkgName: depTree.name,\n requiredRange: depTree.version,\n })\n return result\n }\n /**\n * Parses a dependency identifier string into name and version components.\n *\n * Handles both scoped packages (e.g., \"@scope/pkg@1.2.3\") and regular packages (e.g., \"pkg@1.2.3\").\n * If the identifier is malformed or cannot be parsed, defaults to treating the entire string as\n * the package name with an \"unknown\" version.\n */\n protected parseNameVersion(identifier: string): { name: string; version: string } {\n const lastAt = identifier.lastIndexOf(\"@\")\n if (lastAt <= 0) {\n // fallback for scoped packages or malformed strings\n return { name: identifier, version: \"unknown\" }\n }\n const name = identifier.slice(0, lastAt)\n const version = identifier.slice(lastAt + 1)\n return { name, version }\n }\n\n /**\n * Retrieves the dependency tree and handles workspace package self-references.\n *\n * If the project is a workspace project, this method removes the root package's self-reference\n * from the dependency tree to avoid circular dependencies. It promotes the root package's\n * direct dependencies to the top level of the tree.\n *\n * @param tree - The original dependency tree\n * @param packageName - The name of the package to check for and remove from the tree\n * @returns Promise resolving to the pruned dependency tree\n */\n protected async getTreeFromWorkspaces(tree: ProdDepType, packageName: string): Promise<ProdDepType> {\n if (!(tree.workspaces && tree.dependencies)) {\n return tree\n }\n\n if (tree.dependencies?.[packageName]) {\n const { name, path, dependencies } = tree.dependencies[packageName]\n log.debug({ name, path, dependencies: JSON.stringify(dependencies) }, \"pruning root app/self reference from workspace tree\")\n for (const [name, pkg] of Object.entries(dependencies ?? {})) {\n tree.dependencies[name] = pkg\n this.allDependencies.set(this.packageVersionString(pkg), pkg)\n }\n delete tree.dependencies[packageName]\n }\n return Promise.resolve(tree)\n }\n\n private transformToHoisterTree(obj: DependencyGraph, key: string, nodes: Map<string, HoisterTree> = new Map()): HoisterTree {\n let node = nodes.get(key)\n const { name, version } = this.parseNameVersion(key)\n\n if (!node) {\n node = {\n name,\n identName: name,\n reference: version,\n dependencies: new Set<HoisterTree>(),\n peerNames: new Set<string>(),\n }\n\n nodes.set(key, node)\n\n const deps = (obj[key] || {}).dependencies || []\n for (const dep of deps) {\n const child = this.transformToHoisterTree(obj, dep, nodes)\n node.dependencies.add(child)\n }\n }\n\n return node\n }\n\n private async _getNodeModules(dependencies: Set<HoisterResult>, result: NodeModuleInfo[]) {\n if (dependencies.size === 0) {\n return\n }\n\n for (const d of dependencies.values()) {\n const reference = [...d.references][0]\n const p = this.allDependencies.get(`${d.name}@${reference}`)?.path\n if (p === undefined) {\n log.warn({ name: d.name, reference }, \"cannot find path for dependency\")\n continue\n }\n\n // fix npm list issue\n // https://github.com/npm/cli/issues/8535\n if (!(await this.cache.exists[p])) {\n log.debug({ name: d.name, reference, p }, \"dependency path does not exist\")\n continue\n }\n\n const node: NodeModuleInfo = {\n name: d.name,\n version: reference,\n dir: await this.cache.realPath[p],\n }\n result.push(node)\n if (d.dependencies.size > 0) {\n node.dependencies = []\n await this._getNodeModules(d.dependencies, node.dependencies)\n }\n }\n result.sort((a, b) => a.name.localeCompare(b.name))\n }\n\n async asyncExec(command: string, args: string[], cwd: string = this.rootDir): Promise<{ stdout: string | undefined; stderr: string | undefined }> {\n const file = await this.tempDirManager.getTempFile({ prefix: \"exec-\", suffix: \".txt\" })\n try {\n await this.streamCollectorCommandToFile(command, args, cwd, file)\n const result = await fs.readFile(file, { encoding: \"utf8\" })\n return { stdout: result?.trim(), stderr: undefined }\n } catch (error: any) {\n log.debug({ error: error.message }, \"failed to execute command\")\n return { stdout: undefined, stderr: error.message }\n }\n }\n\n /**\n * Executes a command and streams its output to a file.\n *\n * Spawns a child process to execute the specified command with arguments, capturing stdout\n * to a file. Handles Windows-specific quirks by wrapping .cmd files in a temporary .bat file\n * when necessary. Enables corepack strict mode by default but allows process.env overrides.\n *\n * Special handling for `npm list` exit code 1, which is expected in certain scenarios.\n *\n * @param command - The command to execute\n * @param args - Array of command-line arguments\n * @param cwd - The working directory to execute the command in\n * @param tempOutputFile - The path to the temporary file where stdout will be written\n * @returns Promise that resolves when the command completes successfully or rejects if it fails\n * @throws {Error} If the child process spawn fails or exits with a non-zero code\n */\n async streamCollectorCommandToFile(command: string, args: string[], cwd: string, tempOutputFile: string) {\n const execName = path.basename(command, path.extname(command))\n const isWindowsScriptFile = process.platform === \"win32\" && path.extname(command).toLowerCase() === \".cmd\"\n if (isWindowsScriptFile) {\n // If the command is a Windows script file (.cmd), we need to wrap it in a .bat file to ensure it runs correctly with cmd.exe\n // This is necessary because .cmd files are not directly executable in the same way as .bat files.\n // We create a temporary .bat file that calls the .cmd file with the provided arguments. The .bat file will be executed by cmd.exe.\n // Note: This is a workaround for Windows command execution quirks for specifically when `shell: false`\n const tempBatFile = await this.tempDirManager.getTempFile({\n prefix: execName,\n suffix: \".bat\",\n })\n const batScript = `@echo off\\r\\n\"${command}\" %*\\r\\n` // <-- CRLF required for .bat\n await fs.writeFile(tempBatFile, batScript, { encoding: \"utf8\" })\n command = \"cmd.exe\"\n args = [\"/c\", tempBatFile, ...args]\n }\n\n await new Promise<void>((resolve, reject) => {\n const outStream = createWriteStream(tempOutputFile)\n\n const child = childProcess.spawn(command, args, {\n cwd,\n env: { COREPACK_ENABLE_STRICT: \"0\", ...process.env }, // allow `process.env` overrides\n shell: true, // `true`` is now required: https://github.com/electron-userland/electron-builder/issues/9488\n })\n\n let stderr = \"\"\n child.stdout.pipe(outStream)\n child.stderr.on(\"data\", chunk => {\n stderr += chunk.toString()\n })\n child.on(\"error\", err => {\n reject(new Error(`Node module collector spawn failed: ${err.message}`))\n })\n\n child.on(\"close\", code => {\n outStream.close()\n // https://github.com/npm/npm/issues/17624\n const shouldIgnore = code === 1 && \"npm\" === execName.toLowerCase() && args.includes(\"list\")\n if (shouldIgnore) {\n log.debug(null, \"`npm list` returned non-zero exit code, but it MIGHT be expected (https://github.com/npm/npm/issues/17624). Check stderr for details.\")\n }\n if (stderr.length > 0) {\n log.debug({ stderr }, \"note: there was node module collector output on stderr\")\n }\n const shouldResolve = code === 0 || shouldIgnore\n return shouldResolve ? resolve() : reject(new Error(`Node module collector process exited with code ${code}:\\n${stderr}`))\n })\n })\n }\n}\n"]}
@@ -11,5 +11,4 @@ export declare class NpmNodeModulesCollector extends NodeModulesCollector<NpmDep
11
11
  protected extractProductionDependencyGraph(tree: NpmDependency, dependencyId: string): Promise<void>;
12
12
  private isDuplicatedNpmDependency;
13
13
  protected isProdDependency(packageName: string, tree: NpmDependency): boolean;
14
- protected parseDependenciesTree(jsonBlob: string): Promise<NpmDependency>;
15
14
  }
@@ -45,9 +45,7 @@ class NpmNodeModulesCollector extends nodeModulesCollector_js_1.NodeModulesColle
45
45
  continue;
46
46
  }
47
47
  const dependency = resolvedDeps[packageName];
48
- // Use the key (alias name) for aliased packages to match how they're stored in allDependencies
49
- const normalizedName = packageName !== dependency.name ? packageName : dependency.name;
50
- const childDependencyId = `${normalizedName}@${dependency.version}`;
48
+ const childDependencyId = this.packageVersionString({ name: packageName, version: dependency.version });
51
49
  await this.extractProductionDependencyGraph(dependency, childDependencyId);
52
50
  collectedDependencies.push(childDependencyId);
53
51
  }
@@ -66,9 +64,6 @@ class NpmNodeModulesCollector extends nodeModulesCollector_js_1.NodeModulesColle
66
64
  var _a;
67
65
  return ((_a = tree._dependencies) === null || _a === void 0 ? void 0 : _a[packageName]) != null;
68
66
  }
69
- async parseDependenciesTree(jsonBlob) {
70
- return Promise.resolve(JSON.parse(jsonBlob));
71
- }
72
67
  }
73
68
  exports.NpmNodeModulesCollector = NpmNodeModulesCollector;
74
69
  //# sourceMappingURL=npmNodeModulesCollector.js.map
@@ -1 +1 @@
1
- {"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MAAM,EAAE,aAAa,GAAG,EAAE,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;QACtD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,CAAA;QACtG,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,6DAA6D;IACnD,gBAAgB,CAAC,WAAmB,EAAE,IAAmB;;QACjE,OAAO,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAG,WAAW,CAAC,KAAI,IAAI,CAAA;IAClD,CAAC;IAES,KAAK,CAAC,qBAAqB,CAAC,QAAgB;QACpD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC9C,CAAC;CACF;AArED,0DAqEC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector.js\"\nimport { PM } from \"./packageManager.js\"\nimport { NpmDependency } from \"./types.js\"\n\nexport class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency, string> {\n public readonly installOptions = {\n manager: PM.NPM,\n lockfile: \"package-lock.json\",\n }\n\n protected getArgs(): string[] {\n return [\"list\", \"-a\", \"--include\", \"prod\", \"--include\", \"optional\", \"--omit\", \"dev\", \"--json\", \"--long\", \"--silent\"]\n }\n\n protected async collectAllDependencies(tree: NpmDependency) {\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n if (this.isDuplicatedNpmDependency(value)) {\n continue\n }\n // Use the key (alias name) instead of value.name for npm aliased packages\n // e.g., { \"foo\": { name: \"@scope/bar\", ... } } should be stored as \"foo@version\"\n // This ensures aliased packages are copied to the correct location in node_modules\n const normalizedDep: NpmDependency = key !== value.name ? { ...value, name: key } : value\n this.allDependencies.set(this.packageVersionString(normalizedDep), normalizedDep)\n await this.collectAllDependencies(value)\n }\n }\n\n protected async extractProductionDependencyGraph(tree: NpmDependency, dependencyId: string): Promise<void> {\n if (this.productionGraph[dependencyId]) {\n return\n }\n\n const isDuplicateDep = this.isDuplicatedNpmDependency(tree)\n const resolvedDeps = isDuplicateDep ? this.allDependencies.get(dependencyId)?.dependencies : tree.dependencies\n // Initialize with empty dependencies array first to mark this dependency as \"in progress\"\n // After initialization, if there are libraries with the same name+version later, they will not be searched recursively again\n // This will prevents infinite loops when circular dependencies are encountered.\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n const collectedDependencies: string[] = []\n if (resolvedDeps && Object.keys(resolvedDeps).length > 0) {\n for (const packageName in resolvedDeps) {\n if (!this.isProdDependency(packageName, tree)) {\n continue\n }\n const dependency = resolvedDeps[packageName]\n // Use the key (alias name) for aliased packages to match how they're stored in allDependencies\n const normalizedName = packageName !== dependency.name ? packageName : dependency.name\n const childDependencyId = `${normalizedName}@${dependency.version}`\n await this.extractProductionDependencyGraph(dependency, childDependencyId)\n collectedDependencies.push(childDependencyId)\n }\n }\n this.productionGraph[dependencyId] = { dependencies: collectedDependencies }\n }\n\n // Check: is package already included as a prod dependency due to another package?\n // We need to check this to prevent infinite loops in case of duplicated dependencies\n private isDuplicatedNpmDependency(tree: NpmDependency): boolean {\n const { _dependencies = {}, dependencies = {} } = tree\n const isDuplicateDep = Object.keys(_dependencies).length > 0 && Object.keys(dependencies).length === 0\n return isDuplicateDep\n }\n\n // `npm list` provides explicit list of deps in _dependencies\n protected isProdDependency(packageName: string, tree: NpmDependency) {\n return tree._dependencies?.[packageName] != null\n }\n\n protected async parseDependenciesTree(jsonBlob: string): Promise<NpmDependency> {\n return Promise.resolve(JSON.parse(jsonBlob))\n }\n}\n"]}
1
+ {"version":3,"file":"npmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/npmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAChE,2DAAwC;AAGxC,MAAa,uBAAwB,SAAQ,8CAA2C;IAAxF;;QACkB,mBAAc,GAAG;YAC/B,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ED,6DAA6D;IACnD,gBAAgB,CAAC,WAAmB,EAAE,IAAmB;;QACjE,OAAO,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAG,WAAW,CAAC,KAAI,IAAI,CAAA;IAClD,CAAC;CACF;AA/DD,0DA+DC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector.js\"\nimport { PM } from \"./packageManager.js\"\nimport { NpmDependency } from \"./types.js\"\n\nexport class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency, string> {\n public readonly installOptions = {\n manager: PM.NPM,\n lockfile: \"package-lock.json\",\n }\n\n protected getArgs(): string[] {\n return [\"list\", \"-a\", \"--include\", \"prod\", \"--include\", \"optional\", \"--omit\", \"dev\", \"--json\", \"--long\", \"--silent\"]\n }\n\n protected async collectAllDependencies(tree: NpmDependency) {\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n if (this.isDuplicatedNpmDependency(value)) {\n continue\n }\n // Use the key (alias name) instead of value.name for npm aliased packages\n // e.g., { \"foo\": { name: \"@scope/bar\", ... } } should be stored as \"foo@version\"\n // This ensures aliased packages are copied to the correct location in node_modules\n const normalizedDep: NpmDependency = key !== value.name ? { ...value, name: key } : value\n this.allDependencies.set(this.packageVersionString(normalizedDep), normalizedDep)\n await this.collectAllDependencies(value)\n }\n }\n\n protected async extractProductionDependencyGraph(tree: NpmDependency, dependencyId: string): Promise<void> {\n if (this.productionGraph[dependencyId]) {\n return\n }\n\n const isDuplicateDep = this.isDuplicatedNpmDependency(tree)\n const resolvedDeps = isDuplicateDep ? this.allDependencies.get(dependencyId)?.dependencies : tree.dependencies\n // Initialize with empty dependencies array first to mark this dependency as \"in progress\"\n // After initialization, if there are libraries with the same name+version later, they will not be searched recursively again\n // This will prevents infinite loops when circular dependencies are encountered.\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n const collectedDependencies: string[] = []\n if (resolvedDeps && Object.keys(resolvedDeps).length > 0) {\n for (const packageName in resolvedDeps) {\n if (!this.isProdDependency(packageName, tree)) {\n continue\n }\n const dependency = resolvedDeps[packageName]\n const childDependencyId = this.packageVersionString({ name: packageName, version: dependency.version })\n await this.extractProductionDependencyGraph(dependency, childDependencyId)\n collectedDependencies.push(childDependencyId)\n }\n }\n this.productionGraph[dependencyId] = { dependencies: collectedDependencies }\n }\n\n // Check: is package already included as a prod dependency due to another package?\n // We need to check this to prevent infinite loops in case of duplicated dependencies\n private isDuplicatedNpmDependency(tree: NpmDependency): boolean {\n const { _dependencies = {}, dependencies = {} } = tree\n const isDuplicateDep = Object.keys(_dependencies).length > 0 && Object.keys(dependencies).length === 0\n return isDuplicateDep\n }\n\n // `npm list` provides explicit list of deps in _dependencies\n protected isProdDependency(packageName: string, tree: NpmDependency) {\n return tree._dependencies?.[packageName] != null\n }\n}\n"]}
@@ -7,9 +7,8 @@ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmD
7
7
  lockfile: string;
8
8
  };
9
9
  protected getArgs(): string[];
10
- private getProductionDependencies;
11
10
  protected extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string): Promise<void>;
12
11
  protected collectAllDependencies(tree: PnpmDependency): Promise<void>;
13
12
  protected packageVersionString(pkg: PnpmDependency): string;
14
- protected parseDependenciesTree(jsonBlob: string): Promise<PnpmDependency>;
13
+ protected parseDependenciesTree(jsonBlob: string): PnpmDependency;
15
14
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PnpmNodeModulesCollector = void 0;
4
4
  const builder_util_1 = require("builder-util");
5
- const path = require("path");
6
5
  const nodeModulesCollector_1 = require("./nodeModulesCollector");
7
6
  const packageManager_1 = require("./packageManager");
8
7
  class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
@@ -16,59 +15,55 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
16
15
  getArgs() {
17
16
  return ["list", "--prod", "--json", "--depth", "Infinity"];
18
17
  }
19
- async getProductionDependencies(depTree) {
20
- const packageName = depTree.name || depTree.from;
21
- if ((0, builder_util_1.isEmptyOrSpaces)(packageName)) {
22
- builder_util_1.log.error(depTree, `Cannot determine production dependencies for package with empty name`);
23
- throw new Error(`Cannot compute production dependencies for package with empty name: ${packageName}`);
24
- }
25
- const result = await this.cache.locatePackageVersion({ parentDir: depTree.path, pkgName: packageName, requiredRange: depTree.version });
26
- if (result == null) {
27
- return { path: path.resolve(depTree.path), dependencies: {}, optionalDependencies: {} };
28
- }
29
- const { dependencies, optionalDependencies } = result.packageJson;
30
- return { path: result.packageDir, dependencies: { ...dependencies }, optionalDependencies: { ...optionalDependencies } };
31
- }
32
18
  async extractProductionDependencyGraph(tree, dependencyId) {
33
- var _a, _b, _c, _d;
34
19
  if (this.productionGraph[dependencyId]) {
35
20
  return;
36
21
  }
37
22
  this.productionGraph[dependencyId] = { dependencies: [] };
38
23
  const packageName = tree.name || tree.from;
39
- const treeDep = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
40
- const json = packageName === dependencyId ? null : await this.getProductionDependencies(tree);
41
- const prodDependencies = json ? { ...json.dependencies, ...json.optionalDependencies } : treeDep;
42
- const collectedDependencies = [];
43
- for (const packageName in treeDep) {
44
- if (!prodDependencies[packageName]) {
45
- continue;
24
+ const { packageJson } = (await this.cache.locatePackageVersion({ pkgName: packageName, parentDir: this.rootDir, requiredRange: tree.version })) || {};
25
+ const all = packageJson ? { ...packageJson.dependencies, ...packageJson.optionalDependencies } : { ...tree.dependencies, ...tree.optionalDependencies };
26
+ const optional = packageJson ? { ...packageJson.optionalDependencies } : {};
27
+ const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
28
+ this.productionGraph[dependencyId] = { dependencies: [] };
29
+ const depPromises = Object.entries(deps).map(async ([packageName, dependency]) => {
30
+ // First check if it's in production dependencies
31
+ if (!all[packageName]) {
32
+ return undefined;
46
33
  }
47
34
  // Then check if optional dependency path exists (using actual resolved path)
48
- const version = ((_a = json === null || json === void 0 ? void 0 : json.optionalDependencies) === null || _a === void 0 ? void 0 : _a[packageName]) || ((_c = (_b = tree.optionalDependencies) === null || _b === void 0 ? void 0 : _b[packageName]) === null || _c === void 0 ? void 0 : _c.version) || "";
49
- const result = await this.locatePackageWithVersion({ name: packageName, version, path: (_d = json === null || json === void 0 ? void 0 : json.path) !== null && _d !== void 0 ? _d : tree.path });
50
- if (result == null || !(await this.cache.exists[result.packageDir])) {
51
- builder_util_1.log.debug({ packageName, version: version, searchPath: result === null || result === void 0 ? void 0 : result.packageDir }, `optional dependency not installed, skipping`);
52
- continue;
35
+ if (optional[packageName]) {
36
+ const pkg = await this.cache.locatePackageVersion({ pkgName: packageName, parentDir: this.rootDir, requiredRange: dependency.version });
37
+ if (!pkg) {
38
+ builder_util_1.log.debug({ name: packageName, version: dependency.version, path: dependency.path }, `optional dependency doesn't exist, skipping - likely not installed`);
39
+ return undefined;
40
+ }
53
41
  }
54
- const dependency = treeDep[packageName];
55
42
  const childDependencyId = this.packageVersionString(dependency);
56
43
  await this.extractProductionDependencyGraph(dependency, childDependencyId);
57
- collectedDependencies.push(childDependencyId);
44
+ return childDependencyId;
45
+ });
46
+ const collectedDependencies = [];
47
+ for (const dep of depPromises) {
48
+ const result = await dep;
49
+ if (result !== undefined) {
50
+ collectedDependencies.push(result);
51
+ }
58
52
  }
59
53
  this.productionGraph[dependencyId] = { dependencies: collectedDependencies };
60
54
  }
61
55
  async collectAllDependencies(tree) {
56
+ var _a, _b;
62
57
  // Collect regular dependencies
63
58
  for (const [key, value] of Object.entries(tree.dependencies || {})) {
64
- const json = await this.getProductionDependencies({ ...value, name: key });
65
- this.allDependencies.set(`${key}@${value.version}`, { ...value, path: json.path });
59
+ const pkg = await this.cache.locatePackageVersion({ pkgName: key, parentDir: this.rootDir, requiredRange: value.version });
60
+ this.allDependencies.set(`${key}@${value.version}`, { ...value, path: (_a = pkg === null || pkg === void 0 ? void 0 : pkg.packageDir) !== null && _a !== void 0 ? _a : value.path });
66
61
  await this.collectAllDependencies(value);
67
62
  }
68
63
  // Collect optional dependencies if they exist
69
64
  for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {
70
- const json = await this.getProductionDependencies(value);
71
- this.allDependencies.set(`${key}@${value.version}`, { ...value, path: json.path });
65
+ const pkg = await this.cache.locatePackageVersion({ pkgName: key, parentDir: this.rootDir, requiredRange: value.version });
66
+ this.allDependencies.set(`${key}@${value.version}`, { ...value, path: (_b = pkg === null || pkg === void 0 ? void 0 : pkg.packageDir) !== null && _b !== void 0 ? _b : value.path });
72
67
  await this.collectAllDependencies(value);
73
68
  }
74
69
  }
@@ -76,10 +71,10 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
76
71
  // we use 'from' field because 'name' may be different in case of aliases
77
72
  return `${pkg.from}@${pkg.version}`;
78
73
  }
79
- async parseDependenciesTree(jsonBlob) {
80
- const dependencyTree = JSON.parse(jsonBlob);
74
+ parseDependenciesTree(jsonBlob) {
81
75
  // pnpm returns an array of dependency trees
82
- return Promise.resolve(dependencyTree[0]);
76
+ const dependencyTree = this.extractJsonFromPollutedOutput(jsonBlob);
77
+ return dependencyTree[0];
83
78
  }
84
79
  }
85
80
  exports.PnpmNodeModulesCollector = PnpmNodeModulesCollector;
@@ -1 +1 @@
1
- {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+CAAmD;AACnD,6BAA4B;AAC5B,iEAA6D;AAC7D,qDAAqC;AAGrC,MAAa,wBAAyB,SAAQ,2CAAoD;IAAlG;;QACkB,mBAAc,GAAG;YAC/B,OAAO,EAAE,mBAAE,CAAC,IAAI;YAChB,QAAQ,EAAE,gBAAgB;SAC3B,CAAA;IAiFH,CAAC;IA/EW,OAAO;QACf,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC;IAEO,KAAK,CAAC,yBAA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AG,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;YAClF,MAAM,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,GAAmB;QAChD,yEAAyE;QACzE,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAA;IACrC,CAAC;IAES,KAAK,CAAC,qBAAqB,CAAC,QAAgB;QACpD,MAAM,cAAc,GAAqB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7D,4CAA4C;QAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;CACF;AArFD,4DAqFC","sourcesContent":["import { isEmptyOrSpaces, log } from \"builder-util\"\nimport * as path from \"path\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { 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 protected getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\"]\n }\n\n private async getProductionDependencies(depTree: PnpmDependency): Promise<{ path: string; dependencies: Record<string, string>; optionalDependencies: Record<string, string> }> {\n const packageName = depTree.name || depTree.from\n if (isEmptyOrSpaces(packageName)) {\n log.error(depTree, `Cannot determine production dependencies for package with empty name`)\n throw new Error(`Cannot compute production dependencies for package with empty name: ${packageName}`)\n }\n\n const result = await this.cache.locatePackageVersion({ parentDir: depTree.path, pkgName: packageName, requiredRange: depTree.version })\n if (result == null) {\n return { path: path.resolve(depTree.path), dependencies: {}, optionalDependencies: {} }\n }\n\n const { dependencies, optionalDependencies } = result.packageJson\n return { path: result.packageDir, dependencies: { ...dependencies }, optionalDependencies: { ...optionalDependencies } }\n }\n\n protected async extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string) {\n if (this.productionGraph[dependencyId]) {\n return\n }\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n const packageName = tree.name || tree.from\n\n const treeDep = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) }\n const json = packageName === dependencyId ? null : await this.getProductionDependencies(tree)\n const prodDependencies = json ? { ...json.dependencies, ...json.optionalDependencies } : treeDep\n\n const collectedDependencies: string[] = []\n for (const packageName in treeDep) {\n if (!prodDependencies[packageName]) {\n continue\n }\n\n // Then check if optional dependency path exists (using actual resolved path)\n const version = json?.optionalDependencies?.[packageName] || tree.optionalDependencies?.[packageName]?.version || \"\"\n const result = await this.locatePackageWithVersion({ name: packageName, version, path: json?.path ?? tree.path })\n if (result == null || !(await this.cache.exists[result.packageDir])) {\n log.debug({ packageName, version: version, searchPath: result?.packageDir }, `optional dependency not installed, skipping`)\n continue\n }\n const dependency = treeDep[packageName]\n const childDependencyId = this.packageVersionString(dependency)\n await this.extractProductionDependencyGraph(dependency, childDependencyId)\n collectedDependencies.push(childDependencyId)\n }\n this.productionGraph[dependencyId] = { dependencies: collectedDependencies }\n }\n\n protected async collectAllDependencies(tree: PnpmDependency) {\n // Collect regular dependencies\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n const json = await this.getProductionDependencies({ ...value, name: key })\n this.allDependencies.set(`${key}@${value.version}`, { ...value, path: json.path })\n await this.collectAllDependencies(value)\n }\n\n // Collect optional dependencies if they exist\n for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {\n const json = await this.getProductionDependencies(value)\n this.allDependencies.set(`${key}@${value.version}`, { ...value, path: json.path })\n await this.collectAllDependencies(value)\n }\n }\n\n protected packageVersionString(pkg: PnpmDependency): string {\n // we use 'from' field because 'name' may be different in case of aliases\n return `${pkg.from}@${pkg.version}`\n }\n\n protected async parseDependenciesTree(jsonBlob: string): Promise<PnpmDependency> {\n const dependencyTree: PnpmDependency[] = JSON.parse(jsonBlob)\n // pnpm returns an array of dependency trees\n return Promise.resolve(dependencyTree[0])\n }\n}\n"]}
1
+ {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,+CAAkC;AAClC,iEAA6D;AAC7D,qDAAqC;AAGrC,MAAa,wBAAyB,SAAQ,2CAAoD;IAAlG;;QACkB,mBAAc,GAAG;YAC/B,OAAO,EAAE,mBAAE,CAAC,IAAI;YAChB,QAAQ,EAAE,gBAAgB;SAC3B,CAAA;IA2EH,CAAC;IAzEW,OAAO;QACf,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC;IAES,KAAK,CAAC,gCAAgC,CAAC,IAAoB,EAAE,YAAoB;QACzF,IAAI,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YACvC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA;QAEzD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;QAErJ,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,YAAY,EAAE,GAAG,WAAW,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,GAA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C3E,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC1H,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,mCAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YACtG,MAAM,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IAES,oBAAoB,CAAC,GAAmB;QAChD,yEAAyE;QACzE,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAA;IACrC,CAAC;IAES,qBAAqB,CAAC,QAAgB;QAC9C,4CAA4C;QAC5C,MAAM,cAAc,GAAqB,IAAI,CAAC,6BAA6B,CAAmB,QAAQ,CAAC,CAAA;QACvG,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF;AA/ED,4DA+EC","sourcesContent":["import { log } from \"builder-util\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { 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 protected getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\"]\n }\n\n protected async extractProductionDependencyGraph(tree: PnpmDependency, dependencyId: string) {\n if (this.productionGraph[dependencyId]) {\n return\n }\n this.productionGraph[dependencyId] = { dependencies: [] }\n\n const packageName = tree.name || tree.from\n const { packageJson } = (await this.cache.locatePackageVersion({ pkgName: packageName, parentDir: this.rootDir, requiredRange: 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.cache.locatePackageVersion({ pkgName: packageName, parentDir: this.rootDir, requiredRange: dependency.version })\n if (!pkg) {\n log.debug({ name: packageName, version: dependency.version, path: dependency.path }, `optional dependency doesn't exist, skipping - likely not installed`)\n return undefined\n }\n }\n const childDependencyId = this.packageVersionString(dependency)\n await this.extractProductionDependencyGraph(dependency, 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) {\n // Collect regular dependencies\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n const pkg = await this.cache.locatePackageVersion({ pkgName: key, parentDir: this.rootDir, requiredRange: value.version })\n this.allDependencies.set(`${key}@${value.version}`, { ...value, path: pkg?.packageDir ?? value.path })\n await this.collectAllDependencies(value)\n }\n\n // Collect optional dependencies if they exist\n for (const [key, value] of Object.entries(tree.optionalDependencies || {})) {\n const pkg = await this.cache.locatePackageVersion({ pkgName: key, parentDir: this.rootDir, requiredRange: value.version })\n this.allDependencies.set(`${key}@${value.version}`, { ...value, path: pkg?.packageDir ?? value.path })\n await this.collectAllDependencies(value)\n }\n }\n\n protected packageVersionString(pkg: PnpmDependency): string {\n // we use 'from' field because 'name' may be different in case of aliases\n return `${pkg.from}@${pkg.version}`\n }\n\n protected parseDependenciesTree(jsonBlob: string): PnpmDependency {\n // pnpm returns an array of dependency trees\n const dependencyTree: PnpmDependency[] = this.extractJsonFromPollutedOutput<PnpmDependency[]>(jsonBlob)\n return dependencyTree[0]\n }\n}\n"]}
@@ -10,7 +10,6 @@ export declare class TraversalNodeModulesCollector extends NodeModulesCollector<
10
10
  protected getDependenciesTree(_pm: PM): Promise<TraversedDependency>;
11
11
  protected collectAllDependencies(tree: TraversedDependency, appPackageName: string): Promise<void>;
12
12
  protected extractProductionDependencyGraph(tree: TraversedDependency, dependencyId: string): Promise<void>;
13
- protected parseDependenciesTree(jsonBlob: string): Promise<TraversedDependency>;
14
13
  /**
15
14
  * Builds a dependency tree using only package.json dependencies and optionalDependencies.
16
15
  * This skips devDependencies and uses Node.js module resolution (require.resolve).
@@ -43,9 +43,6 @@ class TraversalNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCo
43
43
  }
44
44
  this.productionGraph[dependencyId] = { dependencies: collectedDependencies };
45
45
  }
46
- async parseDependenciesTree(jsonBlob) {
47
- return Promise.resolve(JSON.parse(jsonBlob));
48
- }
49
46
  /**
50
47
  * Builds a dependency tree using only package.json dependencies and optionalDependencies.
51
48
  * This skips devDependencies and uses Node.js module resolution (require.resolve).