app-builder-lib 26.0.7 → 26.0.9

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 (62) hide show
  1. package/out/configuration.d.ts +8 -8
  2. package/out/configuration.js.map +1 -1
  3. package/out/index.js +5 -2
  4. package/out/index.js.map +1 -1
  5. package/out/macPackager.js +2 -2
  6. package/out/macPackager.js.map +1 -1
  7. package/out/node-module-collector/index.d.ts +3 -0
  8. package/out/node-module-collector/index.js +13 -2
  9. package/out/node-module-collector/index.js.map +1 -1
  10. package/out/node-module-collector/nodeModulesCollector.d.ts +20 -11
  11. package/out/node-module-collector/nodeModulesCollector.js +113 -86
  12. package/out/node-module-collector/nodeModulesCollector.js.map +1 -1
  13. package/out/node-module-collector/npmNodeModulesCollector.d.ts +13 -5
  14. package/out/node-module-collector/npmNodeModulesCollector.js +47 -18
  15. package/out/node-module-collector/npmNodeModulesCollector.js.map +1 -1
  16. package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +14 -5
  17. package/out/node-module-collector/pnpmNodeModulesCollector.js +53 -15
  18. package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
  19. package/out/node-module-collector/types.d.ts +17 -19
  20. package/out/node-module-collector/types.js.map +1 -1
  21. package/out/node-module-collector/yarnNodeModulesCollector.d.ts +5 -0
  22. package/out/node-module-collector/yarnNodeModulesCollector.js +5 -0
  23. package/out/node-module-collector/yarnNodeModulesCollector.js.map +1 -1
  24. package/out/packager.d.ts +32 -12
  25. package/out/packager.js +51 -55
  26. package/out/packager.js.map +1 -1
  27. package/out/platformPackager.js +23 -33
  28. package/out/platformPackager.js.map +1 -1
  29. package/out/publish/PublishManager.d.ts +2 -2
  30. package/out/publish/PublishManager.js +23 -23
  31. package/out/publish/PublishManager.js.map +1 -1
  32. package/out/publish/updateInfoBuilder.js +2 -2
  33. package/out/publish/updateInfoBuilder.js.map +1 -1
  34. package/out/targets/AppImageTarget.js +2 -2
  35. package/out/targets/AppImageTarget.js.map +1 -1
  36. package/out/targets/AppxTarget.js +3 -3
  37. package/out/targets/AppxTarget.js.map +1 -1
  38. package/out/targets/ArchiveTarget.js +2 -2
  39. package/out/targets/ArchiveTarget.js.map +1 -1
  40. package/out/targets/FlatpakTarget.js +2 -2
  41. package/out/targets/FlatpakTarget.js.map +1 -1
  42. package/out/targets/FpmTarget.js +2 -2
  43. package/out/targets/FpmTarget.js.map +1 -1
  44. package/out/targets/MsiTarget.js +3 -3
  45. package/out/targets/MsiTarget.js.map +1 -1
  46. package/out/targets/differentialUpdateInfoBuilder.js +1 -1
  47. package/out/targets/differentialUpdateInfoBuilder.js.map +1 -1
  48. package/out/targets/nsis/NsisTarget.js +2 -2
  49. package/out/targets/nsis/NsisTarget.js.map +1 -1
  50. package/out/targets/pkg.js +1 -1
  51. package/out/targets/pkg.js.map +1 -1
  52. package/out/targets/snap.js +7 -9
  53. package/out/targets/snap.js.map +1 -1
  54. package/out/util/asyncEventEmitter.d.ts +33 -0
  55. package/out/util/asyncEventEmitter.js +63 -0
  56. package/out/util/asyncEventEmitter.js.map +1 -0
  57. package/out/util/resolve.js +1 -0
  58. package/out/util/resolve.js.map +1 -1
  59. package/out/version.d.ts +1 -1
  60. package/out/version.js +1 -1
  61. package/out/version.js.map +1 -1
  62. package/package.json +5 -5
@@ -8,27 +8,54 @@ const builder_util_1 = require("builder-util");
8
8
  class NodeModulesCollector {
9
9
  constructor(rootDir) {
10
10
  this.rootDir = rootDir;
11
- this.allDependencies = new Map();
12
- this.dependencyPathMap = new Map();
13
11
  this.nodeModules = [];
12
+ this.dependencyPathMap = new Map();
13
+ this.allDependencies = new Map();
14
14
  }
15
- transToHoisterTree(obj, key = `.`, nodes = new Map()) {
16
- let node = nodes.get(key);
17
- const name = key.match(/@?[^@]+/)[0];
18
- if (!node) {
19
- node = {
20
- name,
21
- identName: name,
22
- reference: key.match(/@?[^@]+@?(.+)?/)[1] || ``,
23
- dependencies: new Set(),
24
- peerNames: new Set([]),
25
- };
26
- nodes.set(key, node);
27
- for (const dep of (obj[key] || {}).dependencies || []) {
28
- node.dependencies.add(this.transToHoisterTree(obj, dep, nodes));
29
- }
30
- }
31
- return node;
15
+ async getNodeModules() {
16
+ const tree = await this.getDependenciesTree();
17
+ const realTree = this.getTreeFromWorkspaces(tree);
18
+ const parsedTree = this.extractRelevantData(realTree);
19
+ this.collectAllDependencies(parsedTree);
20
+ const productionTree = this.extractProductionDependencyTree(parsedTree);
21
+ const dependencyGraph = this.convertToDependencyGraph(productionTree);
22
+ const hoisterResult = (0, hoist_1.hoist)(this.transToHoisterTree(dependencyGraph), { check: true });
23
+ this._getNodeModules(hoisterResult.dependencies, this.nodeModules);
24
+ return this.nodeModules;
25
+ }
26
+ async getDependenciesTree() {
27
+ const command = await this.pmCommand.value;
28
+ const args = this.getArgs();
29
+ const dependencies = await (0, builder_util_1.exec)(command, args, {
30
+ cwd: this.rootDir,
31
+ shell: true,
32
+ });
33
+ return this.parseDependenciesTree(dependencies);
34
+ }
35
+ extractRelevantData(npmTree) {
36
+ // Do not use `...npmTree` as we are explicitly extracting the data we need
37
+ const { name, version, path, workspaces, dependencies } = npmTree;
38
+ const tree = {
39
+ name,
40
+ version,
41
+ path,
42
+ workspaces,
43
+ // DFS extract subtree
44
+ dependencies: this.extractInternal(dependencies),
45
+ };
46
+ return tree;
47
+ }
48
+ extractInternal(deps) {
49
+ return deps && Object.keys(deps).length > 0
50
+ ? Object.entries(deps).reduce((accum, [packageName, depObjectOrVersionString]) => {
51
+ return {
52
+ ...accum,
53
+ [packageName]: typeof depObjectOrVersionString === "object" && Object.keys(depObjectOrVersionString).length > 0
54
+ ? this.extractRelevantData(depObjectOrVersionString)
55
+ : depObjectOrVersionString,
56
+ };
57
+ }, {})
58
+ : undefined;
32
59
  }
33
60
  resolvePath(filePath) {
34
61
  try {
@@ -45,59 +72,79 @@ class NodeModulesCollector {
45
72
  return filePath;
46
73
  }
47
74
  }
48
- convertToDependencyGraph(tree) {
49
- const result = { ".": {} };
50
- const flatten = (node, parentKey = ".") => {
51
- var _a;
52
- const dependencies = node.dependencies || {};
53
- for (const [key, value] of Object.entries(dependencies)) {
54
- // Skip empty dependencies(like some optionalDependencies)
55
- if (Object.keys(value).length === 0) {
56
- continue;
57
- }
58
- const version = value.version || "";
59
- const newKey = `${key}@${version}`;
60
- this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(value.path)));
61
- if (!((_a = result[parentKey]) === null || _a === void 0 ? void 0 : _a.dependencies)) {
62
- result[parentKey] = { dependencies: [] };
63
- }
64
- result[parentKey].dependencies.push(newKey);
65
- if (node.__circularDependencyDetected) {
66
- continue;
67
- }
68
- flatten(value, newKey);
75
+ convertToDependencyGraph(tree, parentKey = ".") {
76
+ return Object.entries(tree.dependencies || {}).reduce((acc, curr) => {
77
+ const [packageName, dependencies] = curr;
78
+ // Skip empty dependencies (like some optionalDependencies)
79
+ if (Object.keys(dependencies).length === 0) {
80
+ return acc;
69
81
  }
70
- };
71
- flatten(tree);
72
- return result;
82
+ const version = dependencies.version || "";
83
+ const newKey = `${packageName}@${version}`;
84
+ if (!dependencies.path) {
85
+ builder_util_1.log.error({
86
+ packageName,
87
+ data: dependencies,
88
+ parentModule: tree.name,
89
+ parentVersion: tree.version,
90
+ }, "dependency path is undefined");
91
+ throw new Error("unable to parse `path` during `tree.dependencies` reduce");
92
+ }
93
+ // Map dependency details: name, version and path to the dependency tree
94
+ this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(dependencies.path)));
95
+ if (!acc[parentKey]) {
96
+ acc[parentKey] = { dependencies: [] };
97
+ }
98
+ acc[parentKey].dependencies.push(newKey);
99
+ if (tree.implicitDependenciesInjected) {
100
+ builder_util_1.log.debug({
101
+ dependency: packageName,
102
+ version,
103
+ path: dependencies.path,
104
+ parentModule: tree.name,
105
+ parentVersion: tree.version,
106
+ }, "converted implicit dependency");
107
+ return acc;
108
+ }
109
+ return { ...acc, ...this.convertToDependencyGraph(dependencies, newKey) };
110
+ }, {});
73
111
  }
74
- getAllDependencies(tree) {
75
- const dependencies = tree.dependencies || {};
76
- for (const [key, value] of Object.entries(dependencies)) {
77
- if (value.dependencies && Object.keys(value.dependencies).length > 0) {
112
+ collectAllDependencies(tree) {
113
+ var _a;
114
+ for (const [key, value] of Object.entries(tree.dependencies || {})) {
115
+ if (Object.keys((_a = value.dependencies) !== null && _a !== void 0 ? _a : {}).length > 0) {
78
116
  this.allDependencies.set(`${key}@${value.version}`, value);
79
- this.getAllDependencies(value);
117
+ this.collectAllDependencies(value);
80
118
  }
81
119
  }
82
120
  }
83
- async getDependenciesTree() {
84
- const command = this.getCommand();
85
- const args = this.getArgs();
86
- const dependencies = await (0, builder_util_1.exec)(command, args, {
87
- cwd: this.rootDir,
88
- shell: true,
89
- });
90
- const dependencyTree = JSON.parse(dependencies);
91
- // pnpm returns an array of dependency trees
92
- if (Array.isArray(dependencyTree)) {
93
- const tree = dependencyTree[0];
94
- if (tree.optionalDependencies) {
95
- tree.dependencies = { ...tree.dependencies, ...tree.optionalDependencies };
121
+ getTreeFromWorkspaces(tree) {
122
+ if (tree.workspaces && tree.dependencies) {
123
+ for (const [key, value] of Object.entries(tree.dependencies)) {
124
+ if (this.rootDir.endsWith(path.normalize(key))) {
125
+ return value;
126
+ }
127
+ }
128
+ }
129
+ return tree;
130
+ }
131
+ transToHoisterTree(obj, key = `.`, nodes = new Map()) {
132
+ let node = nodes.get(key);
133
+ const name = key.match(/@?[^@]+/)[0];
134
+ if (!node) {
135
+ node = {
136
+ name,
137
+ identName: name,
138
+ reference: key.match(/@?[^@]+@?(.+)?/)[1] || ``,
139
+ dependencies: new Set(),
140
+ peerNames: new Set([]),
141
+ };
142
+ nodes.set(key, node);
143
+ for (const dep of (obj[key] || {}).dependencies || []) {
144
+ node.dependencies.add(this.transToHoisterTree(obj, dep, nodes));
96
145
  }
97
- return tree;
98
146
  }
99
- // yarn and npm return a single dependency tree
100
- return dependencyTree;
147
+ return node;
101
148
  }
102
149
  _getNodeModules(dependencies, result) {
103
150
  if (dependencies.size === 0) {
@@ -117,32 +164,12 @@ class NodeModulesCollector {
117
164
  };
118
165
  result.push(node);
119
166
  if (d.dependencies.size > 0) {
120
- node["dependencies"] = [];
121
- this._getNodeModules(d.dependencies, node["dependencies"]);
167
+ node.dependencies = [];
168
+ this._getNodeModules(d.dependencies, node.dependencies);
122
169
  }
123
170
  }
124
171
  result.sort((a, b) => a.name.localeCompare(b.name));
125
172
  }
126
- getTreeFromWorkspaces(tree) {
127
- if (tree.workspaces && tree.dependencies) {
128
- for (const [key, value] of Object.entries(tree.dependencies)) {
129
- if (this.rootDir.endsWith(path.normalize(key))) {
130
- return value;
131
- }
132
- }
133
- }
134
- return tree;
135
- }
136
- async getNodeModules() {
137
- const tree = await this.getDependenciesTree();
138
- const realTree = this.getTreeFromWorkspaces(tree);
139
- this.getAllDependencies(realTree);
140
- this.removeNonProductionDependencie(realTree);
141
- const dependencyGraph = this.convertToDependencyGraph(realTree);
142
- const hoisterResult = (0, hoist_1.hoist)(this.transToHoisterTree(dependencyGraph), { check: true });
143
- this._getNodeModules(hoisterResult.dependencies, this.nodeModules);
144
- return this.nodeModules;
145
- }
146
173
  }
147
174
  exports.NodeModulesCollector = NodeModulesCollector;
148
175
  //# sourceMappingURL=nodeModulesCollector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/nodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,mCAAqE;AACrE,6BAA4B;AAC5B,yBAAwB;AAExB,+CAAwC;AAExC,MAAsB,oBAAoB;IAKxC,YAA6B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAFlC,oBAAe,GAAgC,IAAI,GAAG,EAAE,CAAA;QAGhE,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAA;QAClC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;IACvB,CAAC;IAEO,kBAAkB,CAAC,GAAoB,EAAE,MAAc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AAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC7D,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBAC/C,OAAO,KAAK,CAAA;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,KAAK,CAAC,cAAc;QACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAA;QAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QACjC,IAAI,CAAC,8BAA8B,CAAC,QAAQ,CAAC,CAAA;QAC7C,MAAM,eAAe,GAAG,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAA;QAC/D,MAAM,aAAa,GAAG,IAAA,aAAK,EAAC,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACtF,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAClE,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;CACF;AA7JD,oDA6JC","sourcesContent":["import { hoist, type HoisterTree, type HoisterResult } from \"./hoist\"\nimport * as path from \"path\"\nimport * as fs from \"fs\"\nimport { NodeModuleInfo, DependencyTree, DependencyGraph } from \"./types\"\nimport { exec, log } from \"builder-util\"\n\nexport abstract class NodeModulesCollector {\n private nodeModules: NodeModuleInfo[]\n protected dependencyPathMap: Map<string, string>\n protected allDependencies: Map<string, DependencyTree> = new Map()\n\n constructor(private readonly rootDir: string) {\n this.dependencyPathMap = new Map()\n this.nodeModules = []\n }\n\n private transToHoisterTree(obj: DependencyGraph, key: string = `.`, nodes: Map<string, HoisterTree> = new Map()): HoisterTree {\n let node = nodes.get(key)\n const name = key.match(/@?[^@]+/)![0]\n if (!node) {\n node = {\n name,\n identName: name,\n reference: key.match(/@?[^@]+@?(.+)?/)![1] || ``,\n dependencies: new Set<HoisterTree>(),\n peerNames: new Set<string>([]),\n }\n nodes.set(key, node)\n\n for (const dep of (obj[key] || {}).dependencies || []) {\n node.dependencies.add(this.transToHoisterTree(obj, dep, nodes))\n }\n }\n return node\n }\n\n protected resolvePath(filePath: string) {\n try {\n const stats = fs.lstatSync(filePath)\n if (stats.isSymbolicLink()) {\n return fs.realpathSync(filePath)\n } else {\n return filePath\n }\n } catch (error: any) {\n log.debug({ message: error.message || error.stack }, \"error resolving path\")\n return filePath\n }\n }\n\n private convertToDependencyGraph(tree: DependencyTree): DependencyGraph {\n const result: DependencyGraph = { \".\": {} }\n\n const flatten = (node: DependencyTree, parentKey = \".\") => {\n const dependencies = node.dependencies || {}\n\n for (const [key, value] of Object.entries(dependencies)) {\n // Skip empty dependencies(like some optionalDependencies)\n if (Object.keys(value).length === 0) {\n continue\n }\n const version = value.version || \"\"\n const newKey = `${key}@${version}`\n this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(value.path)))\n if (!result[parentKey]?.dependencies) {\n result[parentKey] = { dependencies: [] }\n }\n result[parentKey].dependencies!.push(newKey)\n\n if (node.__circularDependencyDetected) {\n continue\n }\n flatten(value, newKey)\n }\n }\n\n flatten(tree)\n return result\n }\n\n getAllDependencies(tree: DependencyTree) {\n const dependencies = tree.dependencies || {}\n for (const [key, value] of Object.entries(dependencies)) {\n if (value.dependencies && Object.keys(value.dependencies).length > 0) {\n this.allDependencies.set(`${key}@${value.version}`, value)\n this.getAllDependencies(value)\n }\n }\n }\n\n abstract getCommand(): string\n abstract getArgs(): string[]\n abstract removeNonProductionDependencie(tree: DependencyTree): void\n\n protected async getDependenciesTree(): Promise<DependencyTree> {\n const command = this.getCommand()\n const args = this.getArgs()\n const dependencies = await exec(command, args, {\n cwd: this.rootDir,\n shell: true,\n })\n const dependencyTree: DependencyTree | DependencyTree[] = JSON.parse(dependencies)\n\n // pnpm returns an array of dependency trees\n if (Array.isArray(dependencyTree)) {\n const tree = dependencyTree[0]\n if (tree.optionalDependencies) {\n tree.dependencies = { ...tree.dependencies, ...tree.optionalDependencies }\n }\n return tree\n }\n\n // yarn and npm return a single dependency tree\n return dependencyTree\n }\n\n private _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.dependencyPathMap.get(`${d.name}@${reference}`)\n if (p === undefined) {\n log.debug({ name: d.name, reference }, \"cannot find path for dependency\")\n continue\n }\n const node: NodeModuleInfo = {\n name: d.name,\n version: reference,\n dir: p,\n }\n result.push(node)\n if (d.dependencies.size > 0) {\n node[\"dependencies\"] = []\n this._getNodeModules(d.dependencies, node[\"dependencies\"])\n }\n }\n result.sort((a, b) => a.name.localeCompare(b.name))\n }\n\n private getTreeFromWorkspaces(tree: DependencyTree): DependencyTree {\n if (tree.workspaces && tree.dependencies) {\n for (const [key, value] of Object.entries(tree.dependencies)) {\n if (this.rootDir.endsWith(path.normalize(key))) {\n return value\n }\n }\n }\n return tree\n }\n\n public async getNodeModules(): Promise<NodeModuleInfo[]> {\n const tree = await this.getDependenciesTree()\n const realTree = this.getTreeFromWorkspaces(tree)\n this.getAllDependencies(realTree)\n this.removeNonProductionDependencie(realTree)\n const dependencyGraph = this.convertToDependencyGraph(realTree)\n const hoisterResult = hoist(this.transToHoisterTree(dependencyGraph), { check: true })\n this._getNodeModules(hoisterResult.dependencies, this.nodeModules)\n return this.nodeModules\n }\n}\n"]}
1
+ {"version":3,"file":"nodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/nodeModulesCollector.ts"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AC5B,OAAM;QACR,CAAC;QAED,KAAK,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;YACtC,MAAM,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAA;YAC9D,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;gBACpB,kBAAG,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,iCAAiC,CAAC,CAAA;gBACzE,SAAQ;YACV,CAAC;YACD,MAAM,IAAI,GAAmB;gBAC3B,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,SAAS;gBAClB,GAAG,EAAE,CAAC;aACP,CAAA;YACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjB,IAAI,CAAC,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,YAAY,GAAG,EAAE,CAAA;gBACtB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;YACzD,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IACrD,CAAC;CACF;AApMD,oDAoMC","sourcesContent":["import { hoist, type HoisterTree, type HoisterResult } from \"./hoist\"\nimport * as path from \"path\"\nimport * as fs from \"fs\"\nimport type { NodeModuleInfo, DependencyTree, DependencyGraph, Dependency } from \"./types\"\nimport { exec, log } from \"builder-util\"\nimport { Lazy } from \"lazy-val\"\n\nexport abstract class NodeModulesCollector<T extends Dependency<T, OptionalsType>, OptionalsType> {\n private nodeModules: NodeModuleInfo[] = []\n protected dependencyPathMap: Map<string, string> = new Map()\n protected allDependencies: Map<string, T> = new Map()\n\n constructor(private readonly rootDir: string) {}\n\n public async getNodeModules(): Promise<NodeModuleInfo[]> {\n const tree: T = await this.getDependenciesTree()\n const realTree: T = this.getTreeFromWorkspaces(tree)\n const parsedTree: Dependency<T, OptionalsType> = this.extractRelevantData(realTree)\n\n this.collectAllDependencies(parsedTree)\n\n const productionTree: DependencyTree = this.extractProductionDependencyTree(parsedTree)\n const dependencyGraph: DependencyGraph = this.convertToDependencyGraph(productionTree)\n\n const hoisterResult: HoisterResult = hoist(this.transToHoisterTree(dependencyGraph), { check: true })\n this._getNodeModules(hoisterResult.dependencies, this.nodeModules)\n\n return this.nodeModules\n }\n\n public abstract readonly installOptions: Promise<{\n cmd: string\n args: string[]\n lockfile: string\n }>\n protected abstract readonly pmCommand: Lazy<string>\n protected abstract getArgs(): string[]\n protected abstract parseDependenciesTree(jsonBlob: string): T\n protected abstract extractProductionDependencyTree(tree: Dependency<T, OptionalsType>): DependencyTree\n\n protected async getDependenciesTree(): Promise<T> {\n const command = await this.pmCommand.value\n const args = this.getArgs()\n const dependencies = await exec(command, args, {\n cwd: this.rootDir,\n shell: true,\n })\n return this.parseDependenciesTree(dependencies)\n }\n\n protected extractRelevantData(npmTree: T): Dependency<T, OptionalsType> {\n // Do not use `...npmTree` as we are explicitly extracting the data we need\n const { name, version, path, workspaces, dependencies } = npmTree\n const tree: Dependency<T, OptionalsType> = {\n name,\n version,\n path,\n workspaces,\n // DFS extract subtree\n dependencies: this.extractInternal(dependencies),\n }\n\n return tree\n }\n\n protected extractInternal(deps: T[\"dependencies\"]): T[\"dependencies\"] {\n return deps && Object.keys(deps).length > 0\n ? Object.entries(deps).reduce((accum, [packageName, depObjectOrVersionString]) => {\n return {\n ...accum,\n [packageName]:\n typeof depObjectOrVersionString === \"object\" && Object.keys(depObjectOrVersionString).length > 0\n ? this.extractRelevantData(depObjectOrVersionString)\n : depObjectOrVersionString,\n }\n }, {})\n : undefined\n }\n\n protected resolvePath(filePath: string): string {\n try {\n const stats = fs.lstatSync(filePath)\n if (stats.isSymbolicLink()) {\n return fs.realpathSync(filePath)\n } else {\n return filePath\n }\n } catch (error: any) {\n log.debug({ message: error.message || error.stack }, \"error resolving path\")\n return filePath\n }\n }\n\n private convertToDependencyGraph(tree: DependencyTree, parentKey = \".\"): DependencyGraph {\n return Object.entries(tree.dependencies || {}).reduce<DependencyGraph>((acc, curr) => {\n const [packageName, dependencies] = curr\n // Skip empty dependencies (like some optionalDependencies)\n if (Object.keys(dependencies).length === 0) {\n return acc\n }\n const version = dependencies.version || \"\"\n const newKey = `${packageName}@${version}`\n if (!dependencies.path) {\n log.error(\n {\n packageName,\n data: dependencies,\n parentModule: tree.name,\n parentVersion: tree.version,\n },\n \"dependency path is undefined\"\n )\n throw new Error(\"unable to parse `path` during `tree.dependencies` reduce\")\n }\n // Map dependency details: name, version and path to the dependency tree\n this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(dependencies.path)))\n if (!acc[parentKey]) {\n acc[parentKey] = { dependencies: [] }\n }\n acc[parentKey].dependencies.push(newKey)\n if (tree.implicitDependenciesInjected) {\n log.debug(\n {\n dependency: packageName,\n version,\n path: dependencies.path,\n parentModule: tree.name,\n parentVersion: tree.version,\n },\n \"converted implicit dependency\"\n )\n return acc\n }\n\n return { ...acc, ...this.convertToDependencyGraph(dependencies, newKey) }\n }, {})\n }\n\n private collectAllDependencies(tree: Dependency<T, OptionalsType>) {\n for (const [key, value] of Object.entries(tree.dependencies || {})) {\n if (Object.keys(value.dependencies ?? {}).length > 0) {\n this.allDependencies.set(`${key}@${value.version}`, value)\n this.collectAllDependencies(value)\n }\n }\n }\n\n private getTreeFromWorkspaces(tree: T): T {\n if (tree.workspaces && tree.dependencies) {\n for (const [key, value] of Object.entries(tree.dependencies)) {\n if (this.rootDir.endsWith(path.normalize(key))) {\n return value\n }\n }\n }\n return tree\n }\n\n private transToHoisterTree(obj: DependencyGraph, key: string = `.`, nodes: Map<string, HoisterTree> = new Map()): HoisterTree {\n let node = nodes.get(key)\n const name = key.match(/@?[^@]+/)![0]\n if (!node) {\n node = {\n name,\n identName: name,\n reference: key.match(/@?[^@]+@?(.+)?/)![1] || ``,\n dependencies: new Set<HoisterTree>(),\n peerNames: new Set<string>([]),\n }\n nodes.set(key, node)\n\n for (const dep of (obj[key] || {}).dependencies || []) {\n node.dependencies.add(this.transToHoisterTree(obj, dep, nodes))\n }\n }\n return node\n }\n\n private _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.dependencyPathMap.get(`${d.name}@${reference}`)\n if (p === undefined) {\n log.debug({ name: d.name, reference }, \"cannot find path for dependency\")\n continue\n }\n const node: NodeModuleInfo = {\n name: d.name,\n version: reference,\n dir: p,\n }\n result.push(node)\n if (d.dependencies.size > 0) {\n node.dependencies = []\n this._getNodeModules(d.dependencies, node.dependencies)\n }\n }\n result.sort((a, b) => a.name.localeCompare(b.name))\n }\n}\n"]}
@@ -1,8 +1,16 @@
1
+ import { Lazy } from "lazy-val";
1
2
  import { NodeModulesCollector } from "./nodeModulesCollector";
2
- import { DependencyTree } from "./types";
3
- export declare class NpmNodeModulesCollector extends NodeModulesCollector {
3
+ import { DependencyTree, NpmDependency } from "./types";
4
+ export declare class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency, string> {
4
5
  constructor(rootDir: string);
5
- getCommand(): string;
6
- getArgs(): string[];
7
- removeNonProductionDependencie(tree: DependencyTree): void;
6
+ readonly pmCommand: Lazy<string>;
7
+ readonly installOptions: Promise<{
8
+ cmd: string;
9
+ args: string[];
10
+ lockfile: string;
11
+ }>;
12
+ protected getArgs(): string[];
13
+ protected extractRelevantData(npmTree: NpmDependency): NpmDependency;
14
+ protected extractProductionDependencyTree(tree: NpmDependency): DependencyTree;
15
+ protected parseDependenciesTree(jsonBlob: string): NpmDependency;
8
16
  }
@@ -1,35 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NpmNodeModulesCollector = void 0;
4
+ const lazy_val_1 = require("lazy-val");
4
5
  const nodeModulesCollector_1 = require("./nodeModulesCollector");
5
6
  const builder_util_1 = require("builder-util");
6
7
  class NpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
7
8
  constructor(rootDir) {
8
9
  super(rootDir);
9
- }
10
- getCommand() {
11
- return process.platform === "win32" ? "npm.cmd" : "npm";
10
+ this.pmCommand = new lazy_val_1.Lazy(() => Promise.resolve(process.platform === "win32" ? "npm.cmd" : "npm"));
11
+ this.installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: ["ci"], lockfile: "package-lock.json" }));
12
12
  }
13
13
  getArgs() {
14
14
  return ["list", "-a", "--include", "prod", "--include", "optional", "--omit", "dev", "--json", "--long", "--silent"];
15
15
  }
16
- removeNonProductionDependencie(tree) {
17
- var _a;
18
- const dependencies = tree.dependencies || {};
19
- const _dependencies = tree._dependencies || {};
20
- if (Object.keys(_dependencies).length > 0 && Object.keys(dependencies).length === 0) {
21
- tree.dependencies = ((_a = this.allDependencies.get(`${tree.name}@${tree.version}`)) === null || _a === void 0 ? void 0 : _a.dependencies) || {};
22
- tree.__circularDependencyDetected = true;
23
- builder_util_1.log.debug({ name: tree.name, version: tree.version }, "circular dependency detected");
24
- return;
16
+ extractRelevantData(npmTree) {
17
+ const tree = super.extractRelevantData(npmTree);
18
+ const { optionalDependencies, _dependencies } = npmTree;
19
+ return { ...tree, optionalDependencies, _dependencies };
20
+ }
21
+ extractProductionDependencyTree(tree) {
22
+ var _a, _b, _c, _d;
23
+ const _deps = (_a = tree._dependencies) !== null && _a !== void 0 ? _a : {};
24
+ let deps = (_b = tree.dependencies) !== null && _b !== void 0 ? _b : {};
25
+ let implicitDependenciesInjected = false;
26
+ if (Object.keys(_deps).length > 0 && Object.keys(deps).length === 0) {
27
+ builder_util_1.log.debug({ name: tree.name, version: tree.version }, "injecting implicit _dependencies");
28
+ deps = (_d = (_c = this.allDependencies.get(`${tree.name}@${tree.version}`)) === null || _c === void 0 ? void 0 : _c.dependencies) !== null && _d !== void 0 ? _d : {};
29
+ implicitDependenciesInjected = true;
25
30
  }
26
- for (const [key, value] of Object.entries(dependencies)) {
27
- if (!_dependencies[key] || Object.keys(value).length === 0) {
28
- delete dependencies[key];
29
- continue;
31
+ const dependencies = Object.entries(deps).reduce((acc, curr) => {
32
+ const [packageName, dependency] = curr;
33
+ if (!_deps[packageName] || Object.keys(dependency).length === 0) {
34
+ return acc;
30
35
  }
31
- this.removeNonProductionDependencie(value);
32
- }
36
+ if (implicitDependenciesInjected) {
37
+ const { name, version, path, workspaces } = dependency;
38
+ const simplifiedTree = { name, version, path, workspaces };
39
+ return {
40
+ ...acc,
41
+ [packageName]: { ...simplifiedTree, implicitDependenciesInjected },
42
+ };
43
+ }
44
+ return {
45
+ ...acc,
46
+ [packageName]: this.extractProductionDependencyTree(dependency),
47
+ };
48
+ }, {});
49
+ const { name, version, path: packagePath, workspaces } = tree;
50
+ const depTree = {
51
+ name,
52
+ version,
53
+ path: packagePath,
54
+ workspaces,
55
+ dependencies,
56
+ implicitDependenciesInjected,
57
+ };
58
+ return depTree;
59
+ }
60
+ parseDependenciesTree(jsonBlob) {
61
+ return JSON.parse(jsonBlob);
33
62
  }
34
63
  }
35
64
  exports.NpmNodeModulesCollector = NpmNodeModulesCollector;
@@ -1 +1 @@
1
- {"version":3,"file":"npmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/npmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAE7D,+CAAkC;AAElC,MAAa,uBAAwB,SAAQ,2CAAoB;IAC/D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,UAAU;QACR,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SAAQ;YACV,CAAC;YACD,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;CACF;AA/BD,0DA+BC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { DependencyTree } from \"./types\"\nimport { log } from \"builder-util\"\n\nexport class NpmNodeModulesCollector extends NodeModulesCollector {\n constructor(rootDir: string) {\n super(rootDir)\n }\n\n getCommand(): string {\n return process.platform === \"win32\" ? \"npm.cmd\" : \"npm\"\n }\n\n getArgs(): string[] {\n return [\"list\", \"-a\", \"--include\", \"prod\", \"--include\", \"optional\", \"--omit\", \"dev\", \"--json\", \"--long\", \"--silent\"]\n }\n\n removeNonProductionDependencie(tree: DependencyTree) {\n const dependencies = tree.dependencies || {}\n const _dependencies = tree._dependencies || {}\n if (Object.keys(_dependencies).length > 0 && Object.keys(dependencies).length === 0) {\n tree.dependencies = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies || {}\n tree.__circularDependencyDetected = true\n log.debug({ name: tree.name, version: tree.version }, \"circular dependency detected\")\n return\n }\n\n for (const [key, value] of Object.entries(dependencies)) {\n if (!_dependencies[key] || Object.keys(value).length === 0) {\n delete dependencies[key]\n continue\n }\n this.removeNonProductionDependencie(value)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"npmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/npmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,uCAA+B;AAC/B,iEAA6D;AAE7D,+CAAkC;AAElC,MAAa,uBAAwB,SAAQ,2CAA2C;IACtF,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAGA,cAAS,GAAG,IAAI,eAAI,CAAS,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;QACrG,mBAAc,GAAG,I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ACF;AAhED,0DAgEC","sourcesContent":["import { Lazy } from \"lazy-val\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { DependencyTree, NpmDependency, ParsedDependencyTree } from \"./types\"\nimport { log } from \"builder-util\"\n\nexport class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency, string> {\n constructor(rootDir: string) {\n super(rootDir)\n }\n\n public readonly pmCommand = new Lazy<string>(() => Promise.resolve(process.platform === \"win32\" ? \"npm.cmd\" : \"npm\"))\n public readonly installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: [\"ci\"], lockfile: \"package-lock.json\" }))\n\n protected getArgs(): string[] {\n return [\"list\", \"-a\", \"--include\", \"prod\", \"--include\", \"optional\", \"--omit\", \"dev\", \"--json\", \"--long\", \"--silent\"]\n }\n\n protected extractRelevantData(npmTree: NpmDependency): NpmDependency {\n const tree = super.extractRelevantData(npmTree)\n const { optionalDependencies, _dependencies } = npmTree\n return { ...tree, optionalDependencies, _dependencies }\n }\n\n protected extractProductionDependencyTree(tree: NpmDependency): DependencyTree {\n const _deps = tree._dependencies ?? {}\n\n let deps = tree.dependencies ?? {}\n let implicitDependenciesInjected = false\n\n if (Object.keys(_deps).length > 0 && Object.keys(deps).length === 0) {\n log.debug({ name: tree.name, version: tree.version }, \"injecting implicit _dependencies\")\n deps = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies ?? {}\n implicitDependenciesInjected = true\n }\n\n const dependencies = Object.entries(deps).reduce<DependencyTree[\"dependencies\"]>((acc, curr) => {\n const [packageName, dependency] = curr\n if (!_deps[packageName] || Object.keys(dependency).length === 0) {\n return acc\n }\n if (implicitDependenciesInjected) {\n const { name, version, path, workspaces } = dependency\n const simplifiedTree: ParsedDependencyTree = { name, version, path, workspaces }\n return {\n ...acc,\n [packageName]: { ...simplifiedTree, implicitDependenciesInjected },\n }\n }\n return {\n ...acc,\n [packageName]: this.extractProductionDependencyTree(dependency),\n }\n }, {})\n\n const { name, version, path: packagePath, workspaces } = tree\n const depTree: DependencyTree = {\n name,\n version,\n path: packagePath,\n workspaces,\n dependencies,\n implicitDependenciesInjected,\n }\n return depTree\n }\n\n protected parseDependenciesTree(jsonBlob: string): NpmDependency {\n return JSON.parse(jsonBlob)\n }\n}\n"]}
@@ -1,8 +1,17 @@
1
+ import { Lazy } from "lazy-val";
1
2
  import { NodeModulesCollector } from "./nodeModulesCollector";
2
- import { DependencyTree } from "./types";
3
- export declare class PnpmNodeModulesCollector extends NodeModulesCollector {
3
+ import { DependencyTree, PnpmDependency } from "./types";
4
+ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {
4
5
  constructor(rootDir: string);
5
- getCommand(): string;
6
- getArgs(): string[];
7
- removeNonProductionDependencie(tree: DependencyTree): void;
6
+ static readonly pmCommand: Lazy<string>;
7
+ protected readonly pmCommand: Lazy<string>;
8
+ readonly installOptions: Promise<{
9
+ cmd: string;
10
+ args: string[];
11
+ lockfile: string;
12
+ }>;
13
+ protected getArgs(): string[];
14
+ protected extractRelevantData(npmTree: PnpmDependency): PnpmDependency;
15
+ extractProductionDependencyTree(tree: PnpmDependency): DependencyTree;
16
+ protected parseDependenciesTree(jsonBlob: string): PnpmDependency;
8
17
  }
@@ -1,33 +1,71 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.PnpmNodeModulesCollector = void 0;
5
+ const lazy_val_1 = require("lazy-val");
4
6
  const nodeModulesCollector_1 = require("./nodeModulesCollector");
5
7
  const path = require("path");
8
+ const builder_util_1 = require("builder-util");
6
9
  class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
7
10
  constructor(rootDir) {
8
11
  super(rootDir);
9
- }
10
- getCommand() {
11
- return process.platform === "win32" ? "pnpm.cmd" : "pnpm";
12
+ this.pmCommand = _a.pmCommand;
13
+ this.installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: ["install", "--frozen-lockfile"], lockfile: "pnpm-lock.yaml" }));
12
14
  }
13
15
  getArgs() {
14
16
  return ["list", "--prod", "--json", "--depth", "Infinity"];
15
17
  }
16
- removeNonProductionDependencie(tree) {
17
- const dependencies = tree.dependencies || {};
18
+ extractRelevantData(npmTree) {
19
+ const tree = super.extractRelevantData(npmTree);
20
+ return {
21
+ ...tree,
22
+ optionalDependencies: this.extractInternal(npmTree.optionalDependencies),
23
+ };
24
+ }
25
+ extractProductionDependencyTree(tree) {
18
26
  const p = path.normalize(this.resolvePath(tree.path));
19
- const pJson = require(path.join(p, "package.json"));
20
- const _dependencies = pJson.dependencies || {};
21
- const _optionalDependencies = pJson.optionalDependencies || {};
22
- const prodDependencies = { ..._dependencies, ..._optionalDependencies };
23
- for (const [key, value] of Object.entries(dependencies)) {
24
- if (!prodDependencies[key]) {
25
- delete dependencies[key];
26
- continue;
27
+ const packageJson = require(path.join(p, "package.json"));
28
+ const prodDependencies = { ...(packageJson.dependencies || {}), ...(packageJson.optionalDependencies || {}) };
29
+ const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
30
+ const dependencies = Object.entries(deps).reduce((acc, curr) => {
31
+ const [packageName, dependency] = curr;
32
+ if (!prodDependencies[packageName]) {
33
+ return acc;
27
34
  }
28
- this.removeNonProductionDependencie(value);
29
- }
35
+ return {
36
+ ...acc,
37
+ [packageName]: this.extractProductionDependencyTree(dependency),
38
+ };
39
+ }, {});
40
+ const { name, version, path: packagePath, workspaces } = tree;
41
+ const depTree = {
42
+ name,
43
+ version,
44
+ path: packagePath,
45
+ workspaces,
46
+ dependencies,
47
+ implicitDependenciesInjected: false,
48
+ };
49
+ return depTree;
50
+ }
51
+ parseDependenciesTree(jsonBlob) {
52
+ const dependencyTree = JSON.parse(jsonBlob);
53
+ // pnpm returns an array of dependency trees
54
+ return dependencyTree[0];
30
55
  }
31
56
  }
32
57
  exports.PnpmNodeModulesCollector = PnpmNodeModulesCollector;
58
+ _a = PnpmNodeModulesCollector;
59
+ PnpmNodeModulesCollector.pmCommand = new lazy_val_1.Lazy(async () => {
60
+ if (process.platform === "win32") {
61
+ try {
62
+ await (0, builder_util_1.exec)("pnpm", ["--version"]);
63
+ }
64
+ catch (_error) {
65
+ builder_util_1.log.debug(null, "pnpm not detected, falling back to pnpm.cmd");
66
+ return "pnpm.cmd";
67
+ }
68
+ }
69
+ return "pnpm";
70
+ });
33
71
  //# sourceMappingURL=pnpmNodeModulesCollector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAE7D,6BAA4B;AAE5B,MAAa,wBAAyB,SAAQ,2CAAoB;IAChE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,UAAU;QACR,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAA;IAC3D,CAAC;IAED,OAAO;QACL,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC;IAED,8BAA8B,CAAC,IAAoB;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,EAAE,CAAA;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrD,MAAM,KAAK,GAAe,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAA;QAC/D,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,IAAI,EAAE,CAAA;QAC9C,MAAM,qBAAqB,GAAG,KAAK,CAAC,oBAAoB,IAAI,EAAE,CAAA;QAC9D,MAAM,gBAAgB,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,qBAAqB,EAAE,CAAA;QACvE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3B,OAAO,YAAY,CAAC,GAAG,CAAC,CAAA;gBACxB,SAAQ;YACV,CAAC;YACD,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;CACF;AA5BD,4DA4BC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { DependencyTree, Dependency } from \"./types\"\nimport * as path from \"path\"\n\nexport class PnpmNodeModulesCollector extends NodeModulesCollector {\n constructor(rootDir: string) {\n super(rootDir)\n }\n\n getCommand(): string {\n return process.platform === \"win32\" ? \"pnpm.cmd\" : \"pnpm\"\n }\n\n getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\"]\n }\n\n removeNonProductionDependencie(tree: DependencyTree) {\n const dependencies = tree.dependencies || {}\n const p = path.normalize(this.resolvePath(tree.path))\n const pJson: Dependency = require(path.join(p, \"package.json\"))\n const _dependencies = pJson.dependencies || {}\n const _optionalDependencies = pJson.optionalDependencies || {}\n const prodDependencies = { ..._dependencies, ..._optionalDependencies }\n for (const [key, value] of Object.entries(dependencies)) {\n if (!prodDependencies[key]) {\n delete dependencies[key]\n continue\n }\n this.removeNonProductionDependencie(value)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"pnpmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/pnpmNodeModulesCollector.ts"],"names":[],"mappings":";;;;AAAA,uCAA+B;AAC/B,iEAA6D;AAE7D,6BAA4B;AAC5B,+CAAwC;AAExC,MAAa,wBAAyB,SAAQ,2CAAoD;IAChG,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAeG,cAAS,GAAiB,EAAwB,CAAC,SAAS,CAAA;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,UAAU,CAAC,GAAG,IAAI,CAAA;YACtC,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;gBACnC,OAAO,GAAG,CAAA;YACZ,CAAC;YACD,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,+BAA+B,CAAC,UAAU,CAAC;aAChE,CAAA;QACH,CAAC,EAAE,EAAE,CAAC,CAAA;QAEN,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;QAC7D,MAAM,OAAO,GAAmB;YAC9B,IAAI;YACJ,OAAO;YACP,IAAI,EAAE,WAAW;YACjB,UAAU;YACV,YAAY;YACZ,4BAA4B,EAAE,KAAK;SACpC,CAAA;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,qBAAqB,CAAC,QAAgB;QAC9C,MAAM,cAAc,GAAqB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7D,4CAA4C;QAC5C,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;;AAjEH,4DAkEC;;AA7DiB,kCAAS,GAAG,IAAI,eAAI,CAAS,KAAK,IAAI,EAAE;IACtD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,IAAA,mBAAI,EAAC,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QACnC,CAAC;QAAC,OAAO,MAAW,EAAE,CAAC;YACrB,kBAAG,CAAC,KAAK,CAAC,IAAI,EAAE,6CAA6C,CAAC,CAAA;YAC9D,OAAO,UAAU,CAAA;QACnB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAC,AAVuB,CAUvB","sourcesContent":["import { Lazy } from \"lazy-val\"\nimport { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { Dependency, DependencyTree, PnpmDependency } from \"./types\"\nimport * as path from \"path\"\nimport { exec, log } from \"builder-util\"\n\nexport class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {\n constructor(rootDir: string) {\n super(rootDir)\n }\n\n static readonly pmCommand = new Lazy<string>(async () => {\n if (process.platform === \"win32\") {\n try {\n await exec(\"pnpm\", [\"--version\"])\n } catch (_error: any) {\n log.debug(null, \"pnpm not detected, falling back to pnpm.cmd\")\n return \"pnpm.cmd\"\n }\n }\n return \"pnpm\"\n })\n\n protected readonly pmCommand: Lazy<string> = PnpmNodeModulesCollector.pmCommand\n public readonly installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: [\"install\", \"--frozen-lockfile\"], lockfile: \"pnpm-lock.yaml\" }))\n\n protected getArgs(): string[] {\n return [\"list\", \"--prod\", \"--json\", \"--depth\", \"Infinity\"]\n }\n\n protected extractRelevantData(npmTree: PnpmDependency): PnpmDependency {\n const tree = super.extractRelevantData(npmTree)\n return {\n ...tree,\n optionalDependencies: this.extractInternal(npmTree.optionalDependencies),\n }\n }\n\n extractProductionDependencyTree(tree: PnpmDependency): DependencyTree {\n const p = path.normalize(this.resolvePath(tree.path))\n const packageJson: Dependency<string, string> = require(path.join(p, \"package.json\"))\n const prodDependencies = { ...(packageJson.dependencies || {}), ...(packageJson.optionalDependencies || {}) }\n\n const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) }\n const dependencies = Object.entries(deps).reduce<DependencyTree[\"dependencies\"]>((acc, curr) => {\n const [packageName, dependency] = curr\n if (!prodDependencies[packageName]) {\n return acc\n }\n return {\n ...acc,\n [packageName]: this.extractProductionDependencyTree(dependency),\n }\n }, {})\n\n const { name, version, path: packagePath, workspaces } = tree\n const depTree: DependencyTree = {\n name,\n version,\n path: packagePath,\n workspaces,\n dependencies,\n implicitDependenciesInjected: false,\n }\n return depTree\n }\n\n protected parseDependenciesTree(jsonBlob: string): PnpmDependency {\n const dependencyTree: PnpmDependency[] = JSON.parse(jsonBlob)\n // pnpm returns an array of dependency trees\n return dependencyTree[0]\n }\n}\n"]}
@@ -4,37 +4,35 @@ export interface NodeModuleInfo {
4
4
  dir: string;
5
5
  dependencies?: Array<NodeModuleInfo>;
6
6
  }
7
- export interface DependencyTree {
7
+ export type ParsedDependencyTree = {
8
8
  readonly name: string;
9
9
  readonly version: string;
10
10
  readonly path: string;
11
11
  readonly workspaces?: string[];
12
- __circularDependencyDetected?: boolean;
13
- dependencies?: {
14
- [packageName: string]: DependencyTree;
15
- };
16
- _dependencies?: {
12
+ };
13
+ export interface DependencyTree extends Omit<Dependency<DependencyTree, DependencyTree>, "optionalDependencies"> {
14
+ readonly implicitDependenciesInjected: boolean;
15
+ }
16
+ export interface PnpmDependency extends Dependency<PnpmDependency, PnpmDependency> {
17
+ }
18
+ export interface NpmDependency extends Dependency<NpmDependency, string> {
19
+ readonly _dependencies?: {
17
20
  [packageName: string]: string;
18
21
  };
19
- optionalDependencies?: {
20
- [packageName: string]: DependencyTree;
21
- };
22
- peerDependencies?: {
23
- [packageName: string]: DependencyTree;
24
- };
25
22
  }
26
- export interface Dependency {
27
- dependencies?: {
28
- [packageName: string]: string;
23
+ export type Dependency<T, V> = Dependencies<T, V> & ParsedDependencyTree;
24
+ export type Dependencies<T, V> = {
25
+ readonly dependencies?: {
26
+ [packageName: string]: T;
29
27
  };
30
- optionalDependencies?: {
31
- [packageName: string]: string;
28
+ readonly optionalDependencies?: {
29
+ [packageName: string]: V;
32
30
  };
33
- }
31
+ };
34
32
  export interface DependencyGraph {
35
33
  [packageNameAndVersion: string]: PackageDependencies;
36
34
  }
37
35
  interface PackageDependencies {
38
- dependencies?: string[];
36
+ readonly dependencies: string[];
39
37
  }
40
38
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/node-module-collector/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface NodeModuleInfo {\n name: string\n version: string\n dir: string\n dependencies?: Array<NodeModuleInfo>\n}\n\nexport interface DependencyTree {\n readonly name: string\n readonly version: string\n readonly path: string\n readonly workspaces?: string[]\n __circularDependencyDetected?: boolean\n dependencies?: {\n [packageName: string]: DependencyTree\n }\n // for npm list --json\n _dependencies?: {\n [packageName: string]: string\n }\n optionalDependencies?: {\n [packageName: string]: DependencyTree\n }\n peerDependencies?: {\n [packageName: string]: DependencyTree\n }\n}\n\nexport interface Dependency {\n dependencies?: {\n [packageName: string]: string\n }\n optionalDependencies?: {\n [packageName: string]: string\n }\n}\n\nexport interface DependencyGraph {\n [packageNameAndVersion: string]: PackageDependencies\n}\n\ninterface PackageDependencies {\n dependencies?: string[]\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/node-module-collector/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface NodeModuleInfo {\n name: string\n version: string\n dir: string\n dependencies?: Array<NodeModuleInfo>\n}\n\nexport type ParsedDependencyTree = {\n readonly name: string\n readonly version: string\n readonly path: string\n readonly workspaces?: string[] // we only use this at root level\n}\n\nexport interface DependencyTree extends Omit<Dependency<DependencyTree, DependencyTree>, \"optionalDependencies\"> {\n readonly implicitDependenciesInjected: boolean\n}\n\n// Note: `PnpmDependency` and `NpmDependency` include the output of `JSON.parse(...)` of `pnpm list` and `npm list` respectively\n// This object has a TON of info - a majority, if not all, of each dependency's package.json\n// We extract only what we need when constructing DependencyTree in `extractProductionDependencyTree`\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface PnpmDependency extends Dependency<PnpmDependency, PnpmDependency> {}\nexport interface NpmDependency extends Dependency<NpmDependency, string> {\n // implicit dependencies\n readonly _dependencies?: {\n [packageName: string]: string\n }\n}\n\nexport type Dependency<T, V> = Dependencies<T, V> & ParsedDependencyTree\n\nexport type Dependencies<T, V> = {\n readonly dependencies?: {\n [packageName: string]: T\n }\n readonly optionalDependencies?: {\n [packageName: string]: V\n }\n}\n\nexport interface DependencyGraph {\n [packageNameAndVersion: string]: PackageDependencies\n}\n\ninterface PackageDependencies {\n readonly dependencies: string[]\n}\n"]}