app-builder-lib 26.0.6 → 26.0.8

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 (59) 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 +1 -1
  6. package/out/macPackager.js.map +1 -1
  7. package/out/node-module-collector/nodeModulesCollector.d.ts +14 -11
  8. package/out/node-module-collector/nodeModulesCollector.js +113 -83
  9. package/out/node-module-collector/nodeModulesCollector.js.map +1 -1
  10. package/out/node-module-collector/npmNodeModulesCollector.d.ts +5 -3
  11. package/out/node-module-collector/npmNodeModulesCollector.js +45 -12
  12. package/out/node-module-collector/npmNodeModulesCollector.js.map +1 -1
  13. package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +5 -3
  14. package/out/node-module-collector/pnpmNodeModulesCollector.js +35 -12
  15. package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
  16. package/out/node-module-collector/types.d.ts +20 -22
  17. package/out/node-module-collector/types.js.map +1 -1
  18. package/out/node-module-collector/yarnNodeModulesCollector.d.ts +2 -6
  19. package/out/node-module-collector/yarnNodeModulesCollector.js +2 -23
  20. package/out/node-module-collector/yarnNodeModulesCollector.js.map +1 -1
  21. package/out/packager.d.ts +32 -12
  22. package/out/packager.js +51 -55
  23. package/out/packager.js.map +1 -1
  24. package/out/platformPackager.js +23 -33
  25. package/out/platformPackager.js.map +1 -1
  26. package/out/publish/PublishManager.d.ts +2 -2
  27. package/out/publish/PublishManager.js +23 -23
  28. package/out/publish/PublishManager.js.map +1 -1
  29. package/out/publish/updateInfoBuilder.js +2 -2
  30. package/out/publish/updateInfoBuilder.js.map +1 -1
  31. package/out/targets/AppImageTarget.js +2 -2
  32. package/out/targets/AppImageTarget.js.map +1 -1
  33. package/out/targets/AppxTarget.js +3 -3
  34. package/out/targets/AppxTarget.js.map +1 -1
  35. package/out/targets/ArchiveTarget.js +2 -2
  36. package/out/targets/ArchiveTarget.js.map +1 -1
  37. package/out/targets/FlatpakTarget.js +2 -2
  38. package/out/targets/FlatpakTarget.js.map +1 -1
  39. package/out/targets/FpmTarget.js +2 -2
  40. package/out/targets/FpmTarget.js.map +1 -1
  41. package/out/targets/MsiTarget.js +3 -3
  42. package/out/targets/MsiTarget.js.map +1 -1
  43. package/out/targets/differentialUpdateInfoBuilder.js +1 -1
  44. package/out/targets/differentialUpdateInfoBuilder.js.map +1 -1
  45. package/out/targets/nsis/NsisTarget.js +2 -2
  46. package/out/targets/nsis/NsisTarget.js.map +1 -1
  47. package/out/targets/pkg.js +1 -1
  48. package/out/targets/pkg.js.map +1 -1
  49. package/out/targets/snap.js +2 -2
  50. package/out/targets/snap.js.map +1 -1
  51. package/out/util/asyncEventEmitter.d.ts +33 -0
  52. package/out/util/asyncEventEmitter.js +66 -0
  53. package/out/util/asyncEventEmitter.js.map +1 -0
  54. package/out/util/resolve.js +1 -0
  55. package/out/util/resolve.js.map +1 -1
  56. package/out/version.d.ts +1 -1
  57. package/out/version.js +1 -1
  58. package/out/version.js.map +1 -1
  59. package/package.json +7 -7
@@ -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 = this.getCommand();
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,56 +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
- 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;
66
81
  }
67
- };
68
- flatten(tree);
69
- 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
+ }, {});
70
111
  }
71
- getAllDependencies(tree) {
72
- const dependencies = tree.dependencies || {};
73
- for (const [key, value] of Object.entries(dependencies)) {
74
- 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) {
75
116
  this.allDependencies.set(`${key}@${value.version}`, value);
76
- this.getAllDependencies(value);
117
+ this.collectAllDependencies(value);
77
118
  }
78
119
  }
79
120
  }
80
- async getDependenciesTree() {
81
- const command = this.getCommand();
82
- const args = this.getArgs();
83
- const dependencies = await (0, builder_util_1.exec)(command, args, {
84
- cwd: this.rootDir,
85
- shell: true,
86
- });
87
- const dependencyTree = JSON.parse(dependencies);
88
- // pnpm returns an array of dependency trees
89
- if (Array.isArray(dependencyTree)) {
90
- const tree = dependencyTree[0];
91
- if (tree.optionalDependencies) {
92
- 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
+ }
93
127
  }
94
- return tree;
95
128
  }
96
- // yarn and npm return a single dependency tree
97
- return dependencyTree;
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));
145
+ }
146
+ }
147
+ return node;
98
148
  }
99
149
  _getNodeModules(dependencies, result) {
100
150
  if (dependencies.size === 0) {
@@ -114,32 +164,12 @@ class NodeModulesCollector {
114
164
  };
115
165
  result.push(node);
116
166
  if (d.dependencies.size > 0) {
117
- node["dependencies"] = [];
118
- this._getNodeModules(d.dependencies, node["dependencies"]);
167
+ node.dependencies = [];
168
+ this._getNodeModules(d.dependencies, node.dependencies);
119
169
  }
120
170
  }
121
171
  result.sort((a, b) => a.name.localeCompare(b.name));
122
172
  }
123
- getTreeFromWorkspaces(tree) {
124
- if (tree.workspaces && tree.dependencies) {
125
- for (const [key, value] of Object.entries(tree.dependencies)) {
126
- if (this.rootDir.endsWith(path.normalize(key))) {
127
- return value;
128
- }
129
- }
130
- }
131
- return tree;
132
- }
133
- async getNodeModules() {
134
- const tree = await this.getDependenciesTree();
135
- const realTree = this.getTreeFromWorkspaces(tree);
136
- this.getAllDependencies(realTree);
137
- this.removeNonProductionDependencie(realTree);
138
- const dependencyGraph = this.convertToDependencyGraph(realTree);
139
- const hoisterResult = (0, hoist_1.hoist)(this.transToHoisterTree(dependencyGraph), { check: true });
140
- this._getNodeModules(hoisterResult.dependencies, this.nodeModules);
141
- return this.nodeModules;
142
- }
143
173
  }
144
174
  exports.NodeModulesCollector = NodeModulesCollector;
145
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,GAAG,EAAE,QAAkC,IAAI,GAAG,EAAE;QAC7G,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACzB,MAAM,IAAI,GAAG,GA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AI,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;AAzJD,oDAyJC","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 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"],"names":[],"mappings":";;;AAAA,mCAAqE;AACrE,6BAA4B;AAC5B,yBAAwB;AAExB,+CAAwC;AAExC,MAAsB,oBAAoB;IAKxC,YAA6B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAJpC,gBAAW,GAAqB,EAAE,CAAA;QAChC,sBAAiB,GAAwB,IAAI,GAAG,EAAE,CAAA;QAClD,o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C,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;AA/LD,oDA+LC","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\"\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 protected abstract getCommand(): 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 = this.getCommand()\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,10 @@
1
1
  import { NodeModulesCollector } from "./nodeModulesCollector";
2
- import { DependencyTree } from "./types";
3
- export declare class NpmNodeModulesCollector extends NodeModulesCollector {
2
+ import { DependencyTree, NpmDependency } from "./types";
3
+ export declare class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency, string> {
4
4
  constructor(rootDir: string);
5
5
  getCommand(): string;
6
6
  getArgs(): string[];
7
- removeNonProductionDependencie(tree: DependencyTree): void;
7
+ protected extractRelevantData(npmTree: NpmDependency): NpmDependency;
8
+ protected extractProductionDependencyTree(tree: NpmDependency): DependencyTree;
9
+ protected parseDependenciesTree(jsonBlob: string): NpmDependency;
8
10
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NpmNodeModulesCollector = void 0;
4
4
  const nodeModulesCollector_1 = require("./nodeModulesCollector");
5
+ const builder_util_1 = require("builder-util");
5
6
  class NpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
6
7
  constructor(rootDir) {
7
8
  super(rootDir);
@@ -12,20 +13,52 @@ class NpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollecto
12
13
  getArgs() {
13
14
  return ["list", "-a", "--include", "prod", "--include", "optional", "--omit", "dev", "--json", "--long", "--silent"];
14
15
  }
15
- removeNonProductionDependencie(tree) {
16
- var _a;
17
- const dependencies = tree.dependencies || {};
18
- const _dependencies = tree._dependencies || {};
19
- if (dependencies && Object.keys(dependencies).length === 0) {
20
- tree.dependencies = ((_a = this.allDependencies.get(`${tree.name}@${tree.version}`)) === null || _a === void 0 ? void 0 : _a.dependencies) || {};
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;
21
30
  }
22
- for (const [key, value] of Object.entries(dependencies)) {
23
- if (!_dependencies[key] || Object.keys(value).length === 0) {
24
- delete dependencies[key];
25
- 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;
26
35
  }
27
- this.removeNonProductionDependencie(value);
28
- }
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);
29
62
  }
30
63
  }
31
64
  exports.NpmNodeModulesCollector = NpmNodeModulesCollector;
@@ -1 +1 @@
1
- {"version":3,"file":"npmNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/npmNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,MAAa,uBAAwB,SAAQ,2CAAoB;IAC/D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,UAAU;QACR,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAA;IACzD,CAAC;IAED,OAAO;QACL,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;IACtH,CAAC;IAED,8BAA8B,CAAC,IAAoB;;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,EAAE,CAAA;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAA;QAC9C,IAAI,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3D,IAAI,CAAC,YAAY,GAAG,CAAA,MAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,0CAAE,YAAY,KAAI,EAAE,CAAA;QAClG,CAAC;QAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3D,OAAO,YAAY,CAAC,GAAG,CAAC,CAAA;gBACxB,SAAQ;YACV,CAAC;YACD,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;CACF;AA5BD,0DA4BC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { DependencyTree } from \"./types\"\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 (dependencies && Object.keys(dependencies).length === 0) {\n tree.dependencies = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies || {}\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,iEAA6D;AAE7D,+CAAkC;AAElC,MAAa,uBAAwB,SAAQ,2CAA2C;IACtF,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,UAAU;QACR,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,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C,GAAG,EAAE,IAAI,EAAE,EAAE;YAC7F,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAA;YACtC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAChE,OAAO,GAAG,CAAA;YACZ,CAAC;YACD,IAAI,4BAA4B,EAAE,CAAC;gBACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,UAAU,CAAA;gBACtD,MAAM,cAAc,GAAyB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;gBAChF,OAAO;oBACL,GAAG,GAAG;oBACN,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,cAAc,EAAE,4BAA4B,EAAE;iBACnE,CAAA;YACH,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;SAC7B,CAAA;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,qBAAqB,CAAC,QAAgB;QAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC;CACF;AAjED,0DAiEC","sourcesContent":["import { 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 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 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,10 @@
1
1
  import { NodeModulesCollector } from "./nodeModulesCollector";
2
- import { DependencyTree } from "./types";
3
- export declare class PnpmNodeModulesCollector extends NodeModulesCollector {
2
+ import { DependencyTree, PnpmDependency } from "./types";
3
+ export declare class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {
4
4
  constructor(rootDir: string);
5
5
  getCommand(): string;
6
6
  getArgs(): string[];
7
- removeNonProductionDependencie(tree: DependencyTree): void;
7
+ protected extractRelevantData(npmTree: PnpmDependency): PnpmDependency;
8
+ extractProductionDependencyTree(tree: PnpmDependency): DependencyTree;
9
+ protected parseDependenciesTree(jsonBlob: string): PnpmDependency;
8
10
  }
@@ -13,20 +13,43 @@ class PnpmNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollect
13
13
  getArgs() {
14
14
  return ["list", "--prod", "--json", "--depth", "Infinity"];
15
15
  }
16
- removeNonProductionDependencie(tree) {
17
- const dependencies = tree.dependencies || {};
16
+ extractRelevantData(npmTree) {
17
+ const tree = super.extractRelevantData(npmTree);
18
+ return {
19
+ ...tree,
20
+ optionalDependencies: this.extractInternal(npmTree.optionalDependencies),
21
+ };
22
+ }
23
+ extractProductionDependencyTree(tree) {
18
24
  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;
25
+ const packageJson = require(path.join(p, "package.json"));
26
+ const prodDependencies = { ...(packageJson.dependencies || {}), ...(packageJson.optionalDependencies || {}) };
27
+ const deps = { ...(tree.dependencies || {}), ...(tree.optionalDependencies || {}) };
28
+ const dependencies = Object.entries(deps).reduce((acc, curr) => {
29
+ const [packageName, dependency] = curr;
30
+ if (!prodDependencies[packageName]) {
31
+ return acc;
27
32
  }
28
- this.removeNonProductionDependencie(value);
29
- }
33
+ return {
34
+ ...acc,
35
+ [packageName]: this.extractProductionDependencyTree(dependency),
36
+ };
37
+ }, {});
38
+ const { name, version, path: packagePath, workspaces } = tree;
39
+ const depTree = {
40
+ name,
41
+ version,
42
+ path: packagePath,
43
+ workspaces,
44
+ dependencies,
45
+ implicitDependenciesInjected: false,
46
+ };
47
+ return depTree;
48
+ }
49
+ parseDependenciesTree(jsonBlob) {
50
+ const dependencyTree = JSON.parse(jsonBlob);
51
+ // pnpm returns an array of dependency trees
52
+ return dependencyTree[0];
30
53
  }
31
54
  }
32
55
  exports.PnpmNodeModulesCollector = PnpmNodeModulesCollector;
@@ -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,iEAA6D;AAE7D,6BAA4B;AAE5B,MAAa,wBAAyB,SAAQ,2CAAoD;IAChG,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,UA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,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;CACF;AAvDD,4DAuDC","sourcesContent":["import { NodeModulesCollector } from \"./nodeModulesCollector\"\nimport { Dependency, DependencyTree, PnpmDependency } from \"./types\"\nimport * as path from \"path\"\n\nexport class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependency, PnpmDependency> {\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 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 {
8
- readonly version?: string;
9
- readonly name?: string;
10
- readonly from?: string;
11
- readonly workspaces?: string[];
7
+ export type ParsedDependencyTree = {
8
+ readonly name: string;
9
+ readonly version: string;
12
10
  readonly path: string;
13
- dependencies?: {
14
- [packageName: string]: DependencyTree;
15
- };
16
- _dependencies?: {
11
+ readonly workspaces?: string[];
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 version?: string\n readonly name?: string\n readonly from?: string\n readonly workspaces?: string[]\n readonly path: string\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"]}
@@ -1,8 +1,4 @@
1
- import { NodeModulesCollector } from "./nodeModulesCollector";
2
- import { DependencyTree } from "./types";
3
- export declare class YarnNodeModulesCollector extends NodeModulesCollector {
1
+ import { NpmNodeModulesCollector } from "./npmNodeModulesCollector";
2
+ export declare class YarnNodeModulesCollector extends NpmNodeModulesCollector {
4
3
  constructor(rootDir: string);
5
- getCommand(): string;
6
- getArgs(): string[];
7
- removeNonProductionDependencie(tree: DependencyTree): void;
8
4
  }
@@ -1,32 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.YarnNodeModulesCollector = void 0;
4
- const nodeModulesCollector_1 = require("./nodeModulesCollector");
5
- class YarnNodeModulesCollector extends nodeModulesCollector_1.NodeModulesCollector {
4
+ const npmNodeModulesCollector_1 = require("./npmNodeModulesCollector");
5
+ class YarnNodeModulesCollector extends npmNodeModulesCollector_1.NpmNodeModulesCollector {
6
6
  constructor(rootDir) {
7
7
  super(rootDir);
8
8
  }
9
- getCommand() {
10
- return process.platform === "win32" ? "npm.cmd" : "npm";
11
- }
12
- getArgs() {
13
- return ["list", "-a", "--include", "prod", "--include", "optional", "--omit", "dev", "--json", "--long", "--silent"];
14
- }
15
- removeNonProductionDependencie(tree) {
16
- var _a;
17
- const dependencies = tree.dependencies || {};
18
- const _dependencies = tree._dependencies || {};
19
- if (dependencies && Object.keys(dependencies).length === 0) {
20
- tree.dependencies = ((_a = this.allDependencies.get(`${tree.name}@${tree.version}`)) === null || _a === void 0 ? void 0 : _a.dependencies) || {};
21
- }
22
- for (const [key, value] of Object.entries(dependencies)) {
23
- if (!_dependencies[key] || Object.keys(value).length === 0) {
24
- delete dependencies[key];
25
- continue;
26
- }
27
- this.removeNonProductionDependencie(value);
28
- }
29
- }
30
9
  }
31
10
  exports.YarnNodeModulesCollector = YarnNodeModulesCollector;
32
11
  //# sourceMappingURL=yarnNodeModulesCollector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"yarnNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/yarnNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,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,SAAS,CAAC,CAAC,CAAC,KAAK,CAAA;IACzD,CAAC;IAED,OAAO;QACL,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;IACtH,CAAC;IAED,8BAA8B,CAAC,IAAoB;;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,EAAE,CAAA;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAA;QAC9C,IAAI,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3D,IAAI,CAAC,YAAY,GAAG,CAAA,MAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,0CAAE,YAAY,KAAI,EAAE,CAAA;QAClG,CAAC;QAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3D,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 } from \"./types\"\n\nexport class YarnNodeModulesCollector 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 (dependencies && Object.keys(dependencies).length === 0) {\n tree.dependencies = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies || {}\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":"yarnNodeModulesCollector.js","sourceRoot":"","sources":["../../src/node-module-collector/yarnNodeModulesCollector.ts"],"names":[],"mappings":";;;AAAA,uEAAmE;AAEnE,MAAa,wBAAyB,SAAQ,iDAAuB;IACnE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;CACF;AAJD,4DAIC","sourcesContent":["import { NpmNodeModulesCollector } from \"./npmNodeModulesCollector\"\n\nexport class YarnNodeModulesCollector extends NpmNodeModulesCollector {\n constructor(rootDir: string) {\n super(rootDir)\n }\n}\n"]}