dependency-cruiser 17.2.0 → 17.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "17.2.0",
3
+ "version": "17.3.1",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -18,50 +18,51 @@
18
18
  ],
19
19
  "author": "Sander Verweij (https://sverweij.github.io)",
20
20
  "contributors": [
21
- "Hirotaka Miyagi (https://mh4gf.dev)",
22
- "TruongSinh Tran-Nguyen (https://truongsinh.pro)",
23
- "Bastian Hess (https://github.com/bashess)",
21
+ "0xflotus (https://github.com/0xflotus)",
24
22
  "Álvaro Cuesta (https://github.com/alvaro-cuesta)",
25
23
  "anna (https://github.com/annamooseity)",
26
- "Radosław Kłos (https://klos.dev)",
27
- "Joshua T (https://github.com/radiantly)",
28
- "Ivan (https://github.com/Winner95)",
29
- "Millicent Billette (https://github.com/1000i100)",
30
- "Frieder Bluemle (https://github.com/friederbluemle)",
31
- "davidparkagoda (https://github.com/davidparkagoda)",
32
- "Matt Button (https://github.com/BRMatt)",
33
- "Jon Lauridsen (https://jonlauridsen.com)",
34
- "Klaus Meinhardt (https://github.com/ajafff)",
35
- "cunzaizhuyi (https://github.com/cunzaizhuyi)",
36
- "Greg Lockwood (https://github.com/greglockwood)",
37
- "Jeremy Magland (https://github.com/magland)",
38
- "Sebastian Landwehr (https://sebastianlandwehr.com)",
39
- "Brody McKee (https://github.com/mrmckeb)",
24
+ "Bastian Hess (https://github.com/bashess)",
40
25
  "Bin (https://github.com/soulhat)",
41
- "정건우 (https://www.zigae.com/)",
42
- "Roy Swinkels (https://github.com/donroyco)",
43
- "Martin Slota (https://github.com/martinslota)",
44
- "Luke Page (https://github.com/lukeapage)",
45
- "Emily Marigold Klassen (https://forivall.com)",
26
+ "Brody McKee (https://github.com/mrmckeb)",
46
27
  "Christian Vuerings (https://github.com/christianvuerings)",
47
- "Yuanhai He (https://bestmike007.com)",
48
- "Quentin de Metz (https://github.com/quentindemetz)",
49
- "Lars Artmann (https://larsartmann.com)",
50
- "Jessica Kerr (https://jessitron.com)",
51
28
  "Creative Ataraxia (https://github.com/Creative-Ataraxia)",
52
- "0xflotus (https://github.com/0xflotus)",
53
- "KenjiroKubota (https://github.com/kubotak-is)",
29
+ "cunzaizhuyi (https://github.com/cunzaizhuyi)",
54
30
  "Daniel Edholm Ignat (https://github.com/dignite)",
55
31
  "Daniel Rodríguez Rivero (https://danielorodriguez.com)",
32
+ "davidparkagoda (https://github.com/davidparkagoda)",
33
+ "electrovir (https://github.com/electrovir)",
34
+ "Emily Marigold Klassen (https://forivall.com)",
35
+ "Frederik Schubert (https://github.com/ferdynator)",
36
+ "Frieder Bluemle (https://github.com/friederbluemle)",
37
+ "fusheng (https://github.com/lin-hun)",
38
+ "Greg Lockwood (https://github.com/greglockwood)",
39
+ "Hirotaka Miyagi (https://mh4gf.dev)",
40
+ "Ivan (https://github.com/Winner95)",
41
+ "Jeremy Magland (https://github.com/magland)",
42
+ "Jessica Kerr (https://jessitron.com)",
43
+ "Jon Lauridsen (https://jonlauridsen.com)",
44
+ "Joshua T (https://github.com/radiantly)",
45
+ "KenjiroKubota (https://github.com/kubotak-is)",
46
+ "Kentaro Suzuki (https://github.com/sushichan044)",
47
+ "Klaus Meinhardt (https://github.com/ajafff)",
48
+ "Lars Artmann (https://larsartmann.com)",
49
+ "Luke Page (https://github.com/lukeapage)",
50
+ "Martin Slota (https://github.com/martinslota)",
51
+ "Matt Button (https://github.com/BRMatt)",
52
+ "Millicent Billette (https://github.com/1000i100)",
56
53
  "Nick Ribal (https://github.com/elektronik2k5)",
54
+ "Quentin de Metz (https://github.com/quentindemetz)",
55
+ "Radosław Kłos (https://klos.dev)",
57
56
  "Richard Musiol (https://github.com/neelance)",
57
+ "Roy Swinkels (https://github.com/donroyco)",
58
+ "Sebastian Landwehr (https://sebastianlandwehr.com)",
58
59
  "Sharang Pai (https://sharangpai.me)",
59
60
  "Stefan Gojan (https://stefan-gojan.de)",
60
- "Valentin Semirulnik (https://github.com/7rulnik)",
61
61
  "Tharun Rajendran (https://github.com/tharun208)",
62
- "electrovir (https://github.com/electrovir)",
63
- "fusheng (https://github.com/lin-hun)",
64
- "Frederik Schubert (https://github.com/ferdynator)"
62
+ "TruongSinh Tran-Nguyen (https://truongsinh.pro)",
63
+ "Valentin Semirulnik (https://github.com/7rulnik)",
64
+ "Yuanhai He (https://bestmike007.com)",
65
+ "정건우 (https://www.zigae.com/)"
65
66
  ],
66
67
  "type": "module",
67
68
  "license": "MIT",
@@ -141,26 +142,26 @@
141
142
  "README.md"
142
143
  ],
143
144
  "dependencies": {
144
- "acorn": "^8.15.0",
145
- "acorn-jsx": "^5.3.2",
146
- "acorn-jsx-walk": "^2.0.0",
147
- "acorn-loose": "^8.5.2",
148
- "acorn-walk": "^8.3.4",
149
- "ajv": "^8.17.1",
150
- "commander": "^14.0.2",
151
- "enhanced-resolve": "^5.18.3",
152
- "ignore": "^7.0.5",
153
- "interpret": "^3.1.1",
154
- "is-installed-globally": "^1.0.0",
155
- "json5": "^2.2.3",
156
- "memoize": "^10.2.0",
157
- "picomatch": "^4.0.3",
158
- "prompts": "^2.4.2",
159
- "rechoir": "^0.8.0",
160
- "safe-regex": "^2.1.1",
161
- "semver": "^7.7.3",
162
- "tsconfig-paths-webpack-plugin": "^4.2.0",
163
- "watskeburt": "^4.2.3"
145
+ "acorn": "8.15.0",
146
+ "acorn-jsx": "5.3.2",
147
+ "acorn-jsx-walk": "2.0.0",
148
+ "acorn-loose": "8.5.2",
149
+ "acorn-walk": "8.3.4",
150
+ "ajv": "8.17.1",
151
+ "commander": "14.0.2",
152
+ "enhanced-resolve": "5.18.3",
153
+ "ignore": "7.0.5",
154
+ "interpret": "3.1.1",
155
+ "is-installed-globally": "1.0.0",
156
+ "json5": "2.2.3",
157
+ "memoize": "10.2.0",
158
+ "picomatch": "4.0.3",
159
+ "prompts": "2.4.2",
160
+ "rechoir": "0.8.0",
161
+ "safe-regex": "2.1.1",
162
+ "semver": "7.7.3",
163
+ "tsconfig-paths-webpack-plugin": "4.2.0",
164
+ "watskeburt": "5.0.0"
164
165
  },
165
166
  "overrides": {
166
167
  "cross-spawn": ">=6.0.6",
@@ -106,6 +106,8 @@ export function optionsAreCompatible(pOldOptions, pNewOptions) {
106
106
  pOldOptions.combinedDependencies === pNewOptions.combinedDependencies &&
107
107
  pOldOptions.experimentalStats === pNewOptions.experimentalStats &&
108
108
  pOldOptions.detectJSDocImports === pNewOptions.detectJSDocImports &&
109
+ pOldOptions.detectProcessBuiltinModuleCalls ===
110
+ pNewOptions.detectProcessBuiltinModuleCalls &&
109
111
  pOldOptions.skipAnalysisNotInRules === pNewOptions.skipAnalysisNotInRules &&
110
112
  metricsIsCompatible(pOldOptions.metrics, pNewOptions.metrics) &&
111
113
  // includeOnly suffers from a backwards compatibility disease
@@ -73,6 +73,17 @@ function buildDetectJSDocumentImportsAttribute(pInitOptions) {
73
73
  : "// detectJSDocImports: true,";
74
74
  }
75
75
 
76
+ /**
77
+ *
78
+ * @param {IInitConfig} pInitOptions
79
+ * @returns {string}
80
+ */
81
+ function buildDetectProcessBuiltinModuleCalls(pInitOptions) {
82
+ return pInitOptions.detectProcessBuiltinModuleCalls
83
+ ? "detectProcessBuiltinModuleCalls: true,"
84
+ : "// detectProcessBuiltinModuleCalls: true,";
85
+ }
86
+
76
87
  /**
77
88
  * @param {IInitConfig} pInitOptions
78
89
  * @returns {string}
@@ -213,6 +224,10 @@ export default function buildConfig(pInitOptions) {
213
224
  "{{detectJSDocImportsAttribute}}",
214
225
  buildDetectJSDocumentImportsAttribute(pInitOptions),
215
226
  )
227
+ .replace(
228
+ "{{detectProcessBuiltinModuleCalls}}",
229
+ buildDetectProcessBuiltinModuleCalls(pInitOptions),
230
+ )
216
231
  .replace(
217
232
  "{{tsPreCompilationDepsAttribute}}",
218
233
  buildTsPreCompilationDepsAttribute(pInitOptions),
@@ -239,6 +239,13 @@ module.exports = {
239
239
  */
240
240
  {{detectJSDocImportsAttribute}}
241
241
 
242
+ /*
243
+ false: don't look at process.getBuiltinModule calls (the default)
244
+ true: dependency-cruiser will detect calls to process.getBuiltinModule/
245
+ globalThis.process.getBuiltinModule as imports.
246
+ */
247
+ {{detectProcessBuiltinModuleCalls}}
248
+
242
249
  /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/main/'
243
250
  to open it on your online repo or \`vscode://file/$\{process.cwd()}/\` to
244
251
  open it in visual studio code),
@@ -113,9 +113,16 @@ const QUESTIONS = [
113
113
  {
114
114
  name: "detectJSDocImports",
115
115
  type: () => (tscIsAvailable() ? "confirm" : false),
116
- message: "Do you want to detect JSDoc imports as well (slower)?",
116
+ message: "Do you want to detect JSDoc imports (slightly slower)?",
117
117
  initial: false,
118
118
  },
119
+ {
120
+ name: "detectProcessBuiltinModuleCalls",
121
+ type: "confirm",
122
+ message:
123
+ "Do you want to detect process.getBuiltinModule imports (slightly slower)?",
124
+ initial: true,
125
+ },
119
126
  {
120
127
  name: "tsPreCompilationDeps",
121
128
  type: (_, pAnswers) => (pAnswers.useTsConfig ? "confirm" : false),
@@ -45,6 +45,7 @@ function getOneShotConfig(pOneShotConfigId) {
45
45
  useTsConfig: hasTSConfigCandidates(),
46
46
  tsConfig: getTSConfigCandidates().shift(),
47
47
  detectJSDocImports: false,
48
+ detectProcessBuiltinModuleCalls: true,
48
49
  tsPreCompilationDeps: hasTSConfigCandidates(),
49
50
  useWebpackConfig: hasWebpackConfigCandidates(),
50
51
  webpackConfig: getWebpackConfigCandidates().shift(),
@@ -13,12 +13,12 @@ import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
13
13
  import { uniq } from "#utl/array-util.mjs";
14
14
 
15
15
  function upsertCouplings(pAllDependents, pNewDependents) {
16
- pNewDependents.forEach((pNewDependent) => {
17
- pAllDependents[pNewDependent] = pAllDependents[pNewDependent] || {
16
+ for (const lNewDependent of pNewDependents) {
17
+ pAllDependents[lNewDependent] = pAllDependents[lNewDependent] || {
18
18
  count: 0,
19
19
  };
20
- pAllDependents[pNewDependent].count += 1;
21
- });
20
+ pAllDependents[lNewDependent].count += 1;
21
+ }
22
22
  }
23
23
 
24
24
  /**
@@ -64,9 +64,9 @@ function upsertFolderAttributes(pAllMetrics, pModule, pDirname) {
64
64
  }
65
65
 
66
66
  function aggregateToFolder(pAllFolders, pModule) {
67
- getParentFolders(dirname(pModule.source)).forEach((pParentDirectory) =>
68
- upsertFolderAttributes(pAllFolders, pModule, pParentDirectory),
69
- );
67
+ for (const lParentDirectory of getParentFolders(dirname(pModule.source))) {
68
+ upsertFolderAttributes(pAllFolders, pModule, lParentDirectory);
69
+ }
70
70
  return pAllFolders;
71
71
  }
72
72
 
@@ -5,6 +5,7 @@ const SHAREABLE_OPTIONS = [
5
5
  "collapse",
6
6
  "combinedDependencies",
7
7
  "detectJSDocImports",
8
+ "detectProcessBuiltinModuleCalls",
8
9
  "doNotFollow",
9
10
  "enhancedResolveOptions",
10
11
  "exclude",
@@ -1,14 +1,15 @@
1
- function isStringLiteral(pArgument) {
1
+ /* eslint-disable no-inline-comments */
2
+ export function isStringLiteral(pArgument) {
2
3
  return pArgument.type === "Literal" && typeof pArgument.value === "string";
3
4
  }
4
5
 
5
- function firstArgumentIsAString(pArgumentsNode) {
6
+ export function firstArgumentIsAString(pArgumentsNode) {
6
7
  return (
7
8
  pArgumentsNode && pArgumentsNode[0] && isStringLiteral(pArgumentsNode[0])
8
9
  );
9
10
  }
10
11
 
11
- function isPlaceholderLessTemplateLiteral(pArgument) {
12
+ export function isPlaceholderLessTemplateLiteral(pArgument) {
12
13
  return (
13
14
  pArgument.type === "TemplateLiteral" &&
14
15
  pArgument.quasis.length === 1 &&
@@ -16,7 +17,7 @@ function isPlaceholderLessTemplateLiteral(pArgument) {
16
17
  );
17
18
  }
18
19
 
19
- function firstArgumentIsATemplateLiteral(pArgumentsNode) {
20
+ export function firstArgumentIsATemplateLiteral(pArgumentsNode) {
20
21
  return (
21
22
  pArgumentsNode &&
22
23
  pArgumentsNode[0] &&
@@ -35,19 +36,52 @@ function isMemberCallExpression(pNode, pObjectName, pPropertyName) {
35
36
  );
36
37
  }
37
38
 
39
+ function isNestedMemberCallExpression(
40
+ pNode,
41
+ pObjectName,
42
+ pSecondObjectName,
43
+ pPropertyName,
44
+ ) {
45
+ return (
46
+ pNode.type === "CallExpression" &&
47
+ pNode.callee.type === "MemberExpression" &&
48
+ pNode.callee.object.type === "MemberExpression" &&
49
+ pNode.callee.object.object.type === "Identifier" &&
50
+ pNode.callee.object.object.name === pObjectName && // i.e. globalThis
51
+ pNode.callee.object.property.type === "Identifier" &&
52
+ pNode.callee.object.property.name === pSecondObjectName && // i.e. process
53
+ pNode.callee.property.type === "Identifier" &&
54
+ pNode.callee.property.name === pPropertyName // i.e. getBuiltinModule
55
+ );
56
+ }
57
+
38
58
  function isCalleeIdentifier(pNode, pName) {
39
59
  return "Identifier" === pNode?.callee?.type && pName === pNode?.callee?.name;
40
60
  }
41
61
 
42
- function isRequireOfSomeSort(pNode, pName) {
62
+ export function isRequireOfSomeSort(pNode, pName) {
63
+ // prevent doing the pName.split for the common case
64
+ if (pName === "require") {
65
+ return isCalleeIdentifier(pNode, pName);
66
+ }
67
+
43
68
  const lRequireStringElements = pName.split(".");
44
69
 
45
- return lRequireStringElements.length > 1
46
- ? isMemberCallExpression(pNode, ...lRequireStringElements)
47
- : isCalleeIdentifier(pNode, pName);
70
+ switch (lRequireStringElements.length) {
71
+ case 1:
72
+ return isCalleeIdentifier(pNode, pName);
73
+ // eslint-disable-next-line no-magic-numbers
74
+ case 2:
75
+ return isMemberCallExpression(pNode, ...lRequireStringElements);
76
+ // eslint-disable-next-line no-magic-numbers
77
+ case 3:
78
+ return isNestedMemberCallExpression(pNode, ...lRequireStringElements);
79
+ default:
80
+ return false;
81
+ }
48
82
  }
49
83
 
50
- function isLikelyAMDDefineOrRequire(pNode) {
84
+ export function isLikelyAMDDefineOrRequire(pNode) {
51
85
  return (
52
86
  pNode.expression.type === "CallExpression" &&
53
87
  pNode.expression.callee.type === "Identifier" &&
@@ -56,22 +90,10 @@ function isLikelyAMDDefineOrRequire(pNode) {
56
90
  );
57
91
  }
58
92
 
59
- function isLikelyAMDDefine(pNode) {
93
+ export function isLikelyAMDDefine(pNode) {
60
94
  return (
61
95
  pNode.expression.type === "CallExpression" &&
62
96
  pNode.expression.callee.type === "Identifier" &&
63
97
  pNode.expression.callee.name === "define"
64
98
  );
65
99
  }
66
-
67
- export default {
68
- firstArgumentIsAString,
69
- firstArgumentIsATemplateLiteral,
70
- isStringLiteral,
71
- isPlaceholderlessTemplateLiteral: isPlaceholderLessTemplateLiteral,
72
- isMemberCallExpression,
73
- isCalleeIdentifier,
74
- isRequireOfSomeSort,
75
- isLikelyAMDDefineOrRequire,
76
- isLikelyAMDDefine,
77
- };
@@ -1,29 +1,35 @@
1
1
  import { simple as walk_simple, base as walk_base } from "acorn-walk";
2
2
  import extractCommonJSDependencies from "./extract-cjs-deps.mjs";
3
- import estreeHelpers from "./estree-helpers.mjs";
3
+ import {
4
+ isLikelyAMDDefineOrRequire,
5
+ isLikelyAMDDefine,
6
+ } from "./estree-helpers.mjs";
4
7
 
5
8
  function extractRegularAMDDependencies(pNode, pDependencies) {
6
- if (estreeHelpers.isLikelyAMDDefineOrRequire(pNode)) {
7
- pNode.expression.arguments
8
- .filter((pArgument) => pArgument.type === "ArrayExpression")
9
- .forEach((pArgument) =>
10
- pArgument.elements.forEach((pElement) => {
11
- if (pElement.value && typeof pElement.value === "string") {
12
- pDependencies.push({
13
- module: pElement.value,
14
- moduleSystem: "amd",
15
- dynamic: false,
16
- exoticallyRequired: false,
17
- dependencyTypes: ["amd-define"],
18
- });
19
- }
20
- }),
21
- );
9
+ if (isLikelyAMDDefineOrRequire(pNode)) {
10
+ const lArrayExpressionArguments = pNode.expression.arguments.filter(
11
+ (pArgument) => pArgument.type === "ArrayExpression",
12
+ );
13
+
14
+ for (const lArgument of lArrayExpressionArguments) {
15
+ for (const lElement of lArgument.elements) {
16
+ // eslint-disable-next-line max-depth
17
+ if (lElement.value && typeof lElement.value === "string") {
18
+ pDependencies.push({
19
+ module: lElement.value,
20
+ moduleSystem: "amd",
21
+ dynamic: false,
22
+ exoticallyRequired: false,
23
+ dependencyTypes: ["amd-define"],
24
+ });
25
+ }
26
+ }
27
+ }
22
28
  }
23
29
  }
24
30
 
25
31
  function extractCommonJSWrappers(pNode, pDependencies, pExoticRequireStrings) {
26
- if (estreeHelpers.isLikelyAMDDefine(pNode)) {
32
+ if (isLikelyAMDDefine(pNode)) {
27
33
  pNode.expression.arguments
28
34
  .filter(
29
35
  (pArgument) =>
@@ -1,12 +1,16 @@
1
1
  import { simple as walk_simple, base as walk_base } from "acorn-walk";
2
- import estreeHelpers from "./estree-helpers.mjs";
2
+ import {
3
+ firstArgumentIsAString,
4
+ firstArgumentIsATemplateLiteral,
5
+ isRequireOfSomeSort,
6
+ } from "./estree-helpers.mjs";
3
7
 
4
8
  function pryStringsFromArguments(pArguments) {
5
9
  let lReturnValue = null;
6
10
 
7
- if (estreeHelpers.firstArgumentIsAString(pArguments)) {
11
+ if (firstArgumentIsAString(pArguments)) {
8
12
  lReturnValue = pArguments[0].value;
9
- } else if (estreeHelpers.firstArgumentIsATemplateLiteral(pArguments)) {
13
+ } else if (firstArgumentIsATemplateLiteral(pArguments)) {
10
14
  lReturnValue = pArguments[0].quasis[0].value.cooked;
11
15
  }
12
16
 
@@ -20,6 +24,28 @@ function getExoticRequireTypes(pModuleSystem) {
20
24
  return pModuleSystem === "amd" ? ["amd-exotic-require"] : ["exotic-require"];
21
25
  }
22
26
 
27
+ function getDependencyTypeAttributes(pName, pModuleSystem) {
28
+ switch (pName) {
29
+ case "require":
30
+ return {
31
+ exoticallyRequired: false,
32
+ dependencyTypes: getRequireTypes(pModuleSystem),
33
+ };
34
+ case "process.getBuiltinModule":
35
+ case "globalThis.process.getBuiltinModule":
36
+ return {
37
+ exoticallyRequired: false,
38
+ dependencyTypes: ["process-get-builtin-module"],
39
+ };
40
+ default:
41
+ return {
42
+ exoticallyRequired: true,
43
+ exoticRequire: pName,
44
+ dependencyTypes: getExoticRequireTypes(pModuleSystem),
45
+ };
46
+ }
47
+ }
48
+
23
49
  function pushRequireCallsToDependencies(
24
50
  pDependencies,
25
51
  pModuleSystem,
@@ -27,23 +53,14 @@ function pushRequireCallsToDependencies(
27
53
  ) {
28
54
  return (pNode) => {
29
55
  for (let lName of pRequireStrings) {
30
- if (estreeHelpers.isRequireOfSomeSort(pNode, lName)) {
56
+ if (isRequireOfSomeSort(pNode, lName)) {
31
57
  const lModuleName = pryStringsFromArguments(pNode.arguments);
32
58
  if (lModuleName) {
33
59
  pDependencies.push({
34
60
  module: lModuleName,
35
61
  moduleSystem: pModuleSystem,
36
62
  dynamic: false,
37
- ...(lName === "require"
38
- ? {
39
- exoticallyRequired: false,
40
- dependencyTypes: getRequireTypes(pModuleSystem),
41
- }
42
- : {
43
- exoticallyRequired: true,
44
- exoticRequire: lName,
45
- dependencyTypes: getExoticRequireTypes(pModuleSystem),
46
- }),
63
+ ...getDependencyTypeAttributes(lName, pModuleSystem),
47
64
  });
48
65
  }
49
66
  }
@@ -51,20 +68,31 @@ function pushRequireCallsToDependencies(
51
68
  };
52
69
  }
53
70
 
71
+ // eslint-disable-next-line max-params
54
72
  export default function extractCommonJSDependencies(
55
73
  pAST,
56
74
  pDependencies,
57
75
  pModuleSystem,
58
76
  pExoticRequireStrings,
77
+ pDetectProcessBuiltinModuleCalls,
59
78
  ) {
60
79
  // var/const lalala = require('./lalala');
61
80
  // require('./lalala');
62
81
  // require('./lalala').doFunkyStuff();
63
82
  // require('zoinks!./wappie')
64
83
  // require(`./withatemplateliteral`)
84
+ // when feature switched as such it will also detect
85
+ // process.getBuiltinModule('fs')
86
+ // globalThis.process.getBuiltinModule('path')
65
87
  // as well as renamed requires/ require wrappers
66
88
  // as passed in pExoticRequireStrings ("need", "window.require")
67
- const lRequireStrings = ["require"].concat(pExoticRequireStrings);
89
+ const lRequireStrings = ["require"]
90
+ .concat(
91
+ pDetectProcessBuiltinModuleCalls
92
+ ? ["process.getBuiltinModule", "globalThis.process.getBuiltinModule"]
93
+ : [],
94
+ )
95
+ .concat(pExoticRequireStrings);
68
96
 
69
97
  walk_simple(
70
98
  pAST,
@@ -1,12 +1,15 @@
1
1
  import { simple as walk_simple, base as walk_base } from "acorn-walk";
2
2
  import { extend } from "acorn-jsx-walk";
3
- import estreeHelpers from "./estree-helpers.mjs";
3
+ import {
4
+ isStringLiteral,
5
+ isPlaceholderLessTemplateLiteral,
6
+ } from "./estree-helpers.mjs";
4
7
 
5
8
  extend(walk_base);
6
9
 
7
10
  function pushImportNodeValue(pDependencies) {
8
11
  return (pNode) => {
9
- if (estreeHelpers.isStringLiteral(pNode.source)) {
12
+ if (isStringLiteral(pNode.source)) {
10
13
  pDependencies.push({
11
14
  module: pNode.source.value,
12
15
  moduleSystem: "es6",
@@ -14,7 +17,7 @@ function pushImportNodeValue(pDependencies) {
14
17
  exoticallyRequired: false,
15
18
  dependencyTypes: ["dynamic-import"],
16
19
  });
17
- } else if (estreeHelpers.isPlaceholderlessTemplateLiteral(pNode.source)) {
20
+ } else if (isPlaceholderLessTemplateLiteral(pNode.source)) {
18
21
  pDependencies.push({
19
22
  module: pNode.source.quasis[0].value.cooked,
20
23
  moduleSystem: "es6",
@@ -6,7 +6,12 @@ import { getASTCached } from "./parse.mjs";
6
6
  import extractStats from "./extract-stats.mjs";
7
7
 
8
8
  export function extract(
9
- { baseDir, moduleSystems, exoticRequireStrings },
9
+ {
10
+ baseDir,
11
+ moduleSystems,
12
+ exoticRequireStrings,
13
+ detectProcessBuiltinModuleCalls,
14
+ },
10
15
  pFileName,
11
16
  pTranspileOptions,
12
17
  ) {
@@ -14,7 +19,13 @@ export function extract(
14
19
  const lAST = getASTCached(join(baseDir, pFileName), pTranspileOptions);
15
20
 
16
21
  if (moduleSystems.includes("cjs")) {
17
- extractCommonJSDeps(lAST, lDependencies, "cjs", exoticRequireStrings);
22
+ extractCommonJSDeps(
23
+ lAST,
24
+ lDependencies,
25
+ "cjs",
26
+ exoticRequireStrings,
27
+ detectProcessBuiltinModuleCalls,
28
+ );
18
29
  }
19
30
  if (moduleSystems.includes("es6")) {
20
31
  extractES6Deps(lAST, lDependencies);