@vercel/nft 0.26.3 → 0.26.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/analyze.js CHANGED
@@ -26,7 +26,7 @@ const acorn = acorn_1.Parser.extend(
26
26
  //require("acorn-class-fields"),
27
27
  //require("acorn-static-class-features"),
28
28
  //require("acorn-private-class-elements")
29
- require("acorn-import-attributes").importAttributes);
29
+ require('acorn-import-attributes').importAttributes);
30
30
  const os_1 = __importDefault(require("os"));
31
31
  const wrappers_1 = require("./utils/wrappers");
32
32
  const resolve_from_1 = __importDefault(require("resolve-from"));
@@ -36,9 +36,9 @@ const staticProcess = {
36
36
  },
37
37
  env: {
38
38
  NODE_ENV: static_eval_1.UNKNOWN,
39
- [static_eval_1.UNKNOWN]: true
39
+ [static_eval_1.UNKNOWN]: true,
40
40
  },
41
- [static_eval_1.UNKNOWN]: true
41
+ [static_eval_1.UNKNOWN]: true,
42
42
  };
43
43
  // unique symbol value to identify express instance in static analysis
44
44
  const EXPRESS_SET = Symbol();
@@ -66,7 +66,7 @@ const fsSymbols = {
66
66
  readFile: FS_FN,
67
67
  readFileSync: FS_FN,
68
68
  stat: FS_FN,
69
- statSync: FS_FN
69
+ statSync: FS_FN,
70
70
  };
71
71
  const fsExtraSymbols = {
72
72
  ...fsSymbols,
@@ -79,69 +79,72 @@ const fsExtraSymbols = {
79
79
  };
80
80
  const staticModules = Object.assign(Object.create(null), {
81
81
  bindings: {
82
- default: BINDINGS
82
+ default: BINDINGS,
83
83
  },
84
84
  express: {
85
85
  default: function () {
86
86
  return {
87
87
  [static_eval_1.UNKNOWN]: true,
88
88
  set: EXPRESS_SET,
89
- engine: EXPRESS_ENGINE
89
+ engine: EXPRESS_ENGINE,
90
90
  };
91
- }
91
+ },
92
92
  },
93
93
  fs: {
94
94
  default: fsSymbols,
95
- ...fsSymbols
95
+ ...fsSymbols,
96
96
  },
97
97
  'fs-extra': {
98
98
  default: fsExtraSymbols,
99
- ...fsExtraSymbols
99
+ ...fsExtraSymbols,
100
100
  },
101
101
  'graceful-fs': {
102
102
  default: fsSymbols,
103
- ...fsSymbols
103
+ ...fsSymbols,
104
104
  },
105
105
  process: {
106
106
  default: staticProcess,
107
- ...staticProcess
107
+ ...staticProcess,
108
108
  },
109
109
  // populated below
110
110
  path: {
111
- default: {}
111
+ default: {},
112
112
  },
113
113
  os: {
114
114
  default: os_1.default,
115
- ...os_1.default
115
+ ...os_1.default,
116
116
  },
117
117
  '@mapbox/node-pre-gyp': {
118
118
  default: node_pre_gyp_1.default,
119
- ...node_pre_gyp_1.default
119
+ ...node_pre_gyp_1.default,
120
120
  },
121
121
  'node-pre-gyp': binary_locators_1.pregyp,
122
122
  'node-pre-gyp/lib/pre-binding': binary_locators_1.pregyp,
123
123
  'node-pre-gyp/lib/pre-binding.js': binary_locators_1.pregyp,
124
124
  'node-gyp-build': {
125
- default: NODE_GYP_BUILD
125
+ default: NODE_GYP_BUILD,
126
+ },
127
+ '@aminya/node-gyp-build': {
128
+ default: NODE_GYP_BUILD,
126
129
  },
127
- 'nbind': {
130
+ nbind: {
128
131
  init: NBIND_INIT,
129
132
  default: {
130
- init: NBIND_INIT
131
- }
133
+ init: NBIND_INIT,
134
+ },
132
135
  },
133
136
  'resolve-from': {
134
- default: resolve_from_1.default
137
+ default: resolve_from_1.default,
135
138
  },
136
139
  'strong-globalize': {
137
140
  default: {
138
- SetRootDir: SET_ROOT_DIR
141
+ SetRootDir: SET_ROOT_DIR,
139
142
  },
140
- SetRootDir: SET_ROOT_DIR
143
+ SetRootDir: SET_ROOT_DIR,
144
+ },
145
+ pkginfo: {
146
+ default: PKG_INFO,
141
147
  },
142
- 'pkginfo': {
143
- default: PKG_INFO
144
- }
145
148
  });
146
149
  const globalBindings = {
147
150
  // Support for require calls generated from `import` statements by babel
@@ -153,15 +156,18 @@ const globalBindings = {
153
156
  MONGOOSE_DRIVER_PATH: undefined,
154
157
  URL: url_1.URL,
155
158
  Object: {
156
- assign: Object.assign
157
- }
159
+ assign: Object.assign,
160
+ },
158
161
  };
159
- globalBindings.global = globalBindings.GLOBAL = globalBindings.globalThis = globalBindings;
162
+ globalBindings.global =
163
+ globalBindings.GLOBAL =
164
+ globalBindings.globalThis =
165
+ globalBindings;
160
166
  // call expression triggers
161
167
  const TRIGGER = Symbol();
162
168
  binary_locators_1.pregyp.find[TRIGGER] = true;
163
169
  const staticPath = staticModules.path;
164
- Object.keys(path_1.default).forEach(name => {
170
+ Object.keys(path_1.default).forEach((name) => {
165
171
  const pathFn = path_1.default[name];
166
172
  if (typeof pathFn === 'function') {
167
173
  const fn = function mockPath() {
@@ -180,7 +186,12 @@ staticPath.resolve = staticPath.default.resolve = function (...args) {
180
186
  };
181
187
  staticPath.resolve[TRIGGER] = true;
182
188
  const excludeAssetExtensions = new Set(['.h', '.cmake', '.c', '.cpp']);
183
- const excludeAssetFiles = new Set(['CHANGELOG.md', 'README.md', 'readme.md', 'changelog.md']);
189
+ const excludeAssetFiles = new Set([
190
+ 'CHANGELOG.md',
191
+ 'README.md',
192
+ 'readme.md',
193
+ 'changelog.md',
194
+ ]);
184
195
  let cwd;
185
196
  const absoluteRegEx = /^\/[^\/]+|^[a-z]:[\\/][^\\/]+/i;
186
197
  function isAbsolutePathOrUrl(str) {
@@ -202,7 +213,6 @@ function isAbsolutePathOrUrl(str) {
202
213
  }
203
214
  const BOUND_REQUIRE = Symbol();
204
215
  const repeatGlobRegEx = /([\/\\]\*\*[\/\\]\*)+/g;
205
- ;
206
216
  async function analyze(id, code, job) {
207
217
  const assets = new Set();
208
218
  const deps = new Set();
@@ -216,23 +226,31 @@ async function analyze(id, code, job) {
216
226
  if (!job.analysis.emitGlobs)
217
227
  return;
218
228
  const wildcardIndex = wildcardPath.indexOf(static_eval_1.WILDCARD);
219
- const dirIndex = wildcardIndex === -1 ? wildcardPath.length : wildcardPath.lastIndexOf(path_1.default.sep, wildcardIndex);
229
+ const dirIndex = wildcardIndex === -1
230
+ ? wildcardPath.length
231
+ : wildcardPath.lastIndexOf(path_1.default.sep, wildcardIndex);
220
232
  const assetDirPath = wildcardPath.substring(0, dirIndex);
221
233
  const patternPath = wildcardPath.slice(dirIndex);
222
- const wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => {
234
+ const wildcardPattern = patternPath
235
+ .replace(static_eval_1.wildcardRegEx, (_match, index) => {
223
236
  return patternPath[index - 1] === path_1.default.sep ? '**/*' : '*';
224
- }).replace(repeatGlobRegEx, '/**/*') || '/**/*';
237
+ })
238
+ .replace(repeatGlobRegEx, '/**/*') || '/**/*';
225
239
  if (job.ignoreFn(path_1.default.relative(job.base, assetDirPath + wildcardPattern)))
226
240
  return;
227
241
  assetEmissionPromises = assetEmissionPromises.then(async () => {
228
242
  if (job.log)
229
243
  console.log('Globbing ' + assetDirPath + wildcardPattern);
230
- const files = (await new Promise((resolve, reject) => (0, glob_1.default)(assetDirPath + wildcardPattern, { mark: true, ignore: assetDirPath + '/**/node_modules/**/*', dot: true }, (err, files) => err ? reject(err) : resolve(files))));
244
+ const files = await new Promise((resolve, reject) => (0, glob_1.default)(assetDirPath + wildcardPattern, {
245
+ mark: true,
246
+ ignore: assetDirPath + '/**/node_modules/**/*',
247
+ dot: true,
248
+ }, (err, files) => (err ? reject(err) : resolve(files))));
231
249
  files
232
- .filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
250
+ .filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
233
251
  !excludeAssetFiles.has(path_1.default.basename(name)) &&
234
252
  !name.endsWith('/'))
235
- .forEach(file => assets.add(file));
253
+ .forEach((file) => assets.add(file));
236
254
  });
237
255
  };
238
256
  let assetEmissionPromises = Promise.resolve();
@@ -241,7 +259,10 @@ async function analyze(id, code, job) {
241
259
  let ast;
242
260
  let isESM = false;
243
261
  try {
244
- ast = acorn.parse(code, { ecmaVersion: 'latest', allowReturnOutsideFunction: true });
262
+ ast = acorn.parse(code, {
263
+ ecmaVersion: 'latest',
264
+ allowReturnOutsideFunction: true,
265
+ });
245
266
  isESM = false;
246
267
  }
247
268
  catch (e) {
@@ -253,7 +274,11 @@ async function analyze(id, code, job) {
253
274
  //@ts-ignore
254
275
  if (!ast) {
255
276
  try {
256
- ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', allowAwaitOutsideFunction: true });
277
+ ast = acorn.parse(code, {
278
+ ecmaVersion: 'latest',
279
+ sourceType: 'module',
280
+ allowAwaitOutsideFunction: true,
281
+ });
257
282
  isESM = true;
258
283
  }
259
284
  catch (e) {
@@ -266,16 +291,16 @@ async function analyze(id, code, job) {
266
291
  const knownBindings = Object.assign(Object.create(null), {
267
292
  __dirname: {
268
293
  shadowDepth: 0,
269
- value: { value: path_1.default.resolve(id, '..') }
294
+ value: { value: path_1.default.resolve(id, '..') },
270
295
  },
271
296
  __filename: {
272
297
  shadowDepth: 0,
273
- value: { value: id }
298
+ value: { value: id },
274
299
  },
275
300
  process: {
276
301
  shadowDepth: 0,
277
- value: { value: staticProcess }
278
- }
302
+ value: { value: staticProcess },
303
+ },
279
304
  });
280
305
  if (!isESM || job.mixedModules) {
281
306
  knownBindings.require = {
@@ -289,9 +314,9 @@ async function analyze(id, code, job) {
289
314
  },
290
315
  resolve(specifier) {
291
316
  return (0, resolve_dependency_js_1.default)(specifier, id, job);
292
- }
293
- }
294
- }
317
+ },
318
+ },
319
+ },
295
320
  };
296
321
  knownBindings.require.value.value.resolve[TRIGGER] = true;
297
322
  }
@@ -302,7 +327,7 @@ async function analyze(id, code, job) {
302
327
  return;
303
328
  knownBindings[name] = {
304
329
  shadowDepth: 0,
305
- value: value
330
+ value: value,
306
331
  };
307
332
  }
308
333
  function getKnownBinding(name) {
@@ -328,14 +353,19 @@ async function analyze(id, code, job) {
328
353
  for (const impt of decl.specifiers) {
329
354
  if (impt.type === 'ImportNamespaceSpecifier')
330
355
  setKnownBinding(impt.local.name, { value: staticModule });
331
- else if (impt.type === 'ImportDefaultSpecifier' && 'default' in staticModule)
356
+ else if (impt.type === 'ImportDefaultSpecifier' &&
357
+ 'default' in staticModule)
332
358
  setKnownBinding(impt.local.name, { value: staticModule.default });
333
- else if (impt.type === 'ImportSpecifier' && impt.imported.name in staticModule)
334
- setKnownBinding(impt.local.name, { value: staticModule[impt.imported.name] });
359
+ else if (impt.type === 'ImportSpecifier' &&
360
+ impt.imported.name in staticModule)
361
+ setKnownBinding(impt.local.name, {
362
+ value: staticModule[impt.imported.name],
363
+ });
335
364
  }
336
365
  }
337
366
  }
338
- else if (decl.type === 'ExportNamedDeclaration' || decl.type === 'ExportAllDeclaration') {
367
+ else if (decl.type === 'ExportNamedDeclaration' ||
368
+ decl.type === 'ExportAllDeclaration') {
339
369
  if (decl.source)
340
370
  deps.add(String(decl.source.value));
341
371
  }
@@ -343,10 +373,10 @@ async function analyze(id, code, job) {
343
373
  }
344
374
  async function computePureStaticValue(expr, computeBranches = true) {
345
375
  const vars = Object.create(null);
346
- Object.keys(globalBindings).forEach(name => {
376
+ Object.keys(globalBindings).forEach((name) => {
347
377
  vars[name] = { value: globalBindings[name] };
348
378
  });
349
- Object.keys(knownBindings).forEach(name => {
379
+ Object.keys(knownBindings).forEach((name) => {
350
380
  vars[name] = getKnownBinding(name);
351
381
  });
352
382
  vars['import.meta'] = { url: importMetaUrl };
@@ -361,29 +391,33 @@ async function analyze(id, code, job) {
361
391
  // Express engine opt-out
362
392
  let definedExpressEngines = false;
363
393
  function emitWildcardRequire(wildcardRequire) {
364
- if (!job.analysis.emitGlobs || !wildcardRequire.startsWith('./') && !wildcardRequire.startsWith('../'))
394
+ if (!job.analysis.emitGlobs ||
395
+ (!wildcardRequire.startsWith('./') && !wildcardRequire.startsWith('../')))
365
396
  return;
366
397
  wildcardRequire = path_1.default.resolve(dir, wildcardRequire);
367
398
  const wildcardIndex = wildcardRequire.indexOf(static_eval_1.WILDCARD);
368
- const dirIndex = wildcardIndex === -1 ? wildcardRequire.length : wildcardRequire.lastIndexOf(path_1.default.sep, wildcardIndex);
399
+ const dirIndex = wildcardIndex === -1
400
+ ? wildcardRequire.length
401
+ : wildcardRequire.lastIndexOf(path_1.default.sep, wildcardIndex);
369
402
  const wildcardDirPath = wildcardRequire.substring(0, dirIndex);
370
403
  const patternPath = wildcardRequire.slice(dirIndex);
371
404
  let wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => {
372
405
  return patternPath[index - 1] === path_1.default.sep ? '**/*' : '*';
373
406
  }) || '/**/*';
374
407
  if (!wildcardPattern.endsWith('*'))
375
- wildcardPattern += '?(' + (job.ts ? '.ts|.tsx|' : '') + '.js|.json|.node)';
408
+ wildcardPattern +=
409
+ '?(' + (job.ts ? '.ts|.tsx|' : '') + '.js|.json|.node)';
376
410
  if (job.ignoreFn(path_1.default.relative(job.base, wildcardDirPath + wildcardPattern)))
377
411
  return;
378
412
  assetEmissionPromises = assetEmissionPromises.then(async () => {
379
413
  if (job.log)
380
414
  console.log('Globbing ' + wildcardDirPath + wildcardPattern);
381
- const files = (await new Promise((resolve, reject) => (0, glob_1.default)(wildcardDirPath + wildcardPattern, { mark: true, ignore: wildcardDirPath + '/**/node_modules/**/*' }, (err, files) => err ? reject(err) : resolve(files))));
415
+ const files = await new Promise((resolve, reject) => (0, glob_1.default)(wildcardDirPath + wildcardPattern, { mark: true, ignore: wildcardDirPath + '/**/node_modules/**/*' }, (err, files) => (err ? reject(err) : resolve(files))));
382
416
  files
383
- .filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
417
+ .filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
384
418
  !excludeAssetFiles.has(path_1.default.basename(name)) &&
385
419
  !name.endsWith('/'))
386
- .forEach(file => deps.add(file));
420
+ .forEach((file) => deps.add(file));
387
421
  });
388
422
  }
389
423
  async function processRequireArg(expression, isImport = false) {
@@ -416,7 +450,14 @@ async function analyze(id, code, job) {
416
450
  let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
417
451
  if (isAst(ast)) {
418
452
  (0, wrappers_1.handleWrappers)(ast);
419
- await (0, special_cases_1.default)({ id, ast, emitDependency: path => deps.add(path), emitAsset: path => assets.add(path), emitAssetDirectory, job });
453
+ await (0, special_cases_1.default)({
454
+ id,
455
+ ast,
456
+ emitDependency: (path) => deps.add(path),
457
+ emitAsset: (path) => assets.add(path),
458
+ emitAssetDirectory,
459
+ job,
460
+ });
420
461
  }
421
462
  async function backtrack(parent, context) {
422
463
  // computing a static expression outward
@@ -426,8 +467,11 @@ async function analyze(id, code, job) {
426
467
  throw new Error('Internal error: No staticChildNode for backtrack.');
427
468
  const curStaticValue = await computePureStaticValue(parent, true);
428
469
  if (curStaticValue) {
429
- if ('value' in curStaticValue && typeof curStaticValue.value !== 'symbol' ||
430
- 'then' in curStaticValue && typeof curStaticValue.then !== 'symbol' && typeof curStaticValue.else !== 'symbol') {
470
+ if (('value' in curStaticValue &&
471
+ typeof curStaticValue.value !== 'symbol') ||
472
+ ('then' in curStaticValue &&
473
+ typeof curStaticValue.then !== 'symbol' &&
474
+ typeof curStaticValue.else !== 'symbol')) {
431
475
  staticChildValue = curStaticValue;
432
476
  staticChildNode = parent;
433
477
  if (context)
@@ -455,19 +499,31 @@ async function analyze(id, code, job) {
455
499
  if (!parent)
456
500
  return;
457
501
  if (node.type === 'Identifier') {
458
- if ((0, ast_helpers_1.isIdentifierRead)(node, parent) && job.analysis.computeFileReferences) {
502
+ if ((0, ast_helpers_1.isIdentifierRead)(node, parent) &&
503
+ job.analysis.computeFileReferences) {
459
504
  let binding;
460
505
  // detect asset leaf expression triggers (if not already)
461
506
  // __dirname, __filename
462
- if (typeof (binding = getKnownBinding(node.name)?.value) === 'string' && binding.match(absoluteRegEx) ||
463
- binding && (typeof binding === 'function' || typeof binding === 'object') && binding[TRIGGER]) {
464
- staticChildValue = { value: typeof binding === 'string' ? binding : undefined };
507
+ if ((typeof (binding = getKnownBinding(node.name)?.value) === 'string' &&
508
+ binding.match(absoluteRegEx)) ||
509
+ (binding &&
510
+ (typeof binding === 'function' || typeof binding === 'object') &&
511
+ binding[TRIGGER])) {
512
+ staticChildValue = {
513
+ value: typeof binding === 'string' ? binding : undefined,
514
+ };
465
515
  staticChildNode = node;
466
516
  await backtrack(parent, this);
467
517
  }
468
518
  }
469
519
  }
470
- else if (job.analysis.computeFileReferences && node.type === 'MemberExpression' && node.object.type === 'MetaProperty' && node.object.meta.name === 'import' && node.object.property.name === 'meta' && (node.property.computed ? node.property.value : node.property.name) === 'url') {
520
+ else if (job.analysis.computeFileReferences &&
521
+ node.type === 'MemberExpression' &&
522
+ node.object.type === 'MetaProperty' &&
523
+ node.object.meta.name === 'import' &&
524
+ node.object.property.name === 'meta' &&
525
+ (node.property.computed ? node.property.value : node.property.name) ===
526
+ 'url') {
471
527
  // import.meta.url leaf trigger
472
528
  staticChildValue = { value: importMetaUrl };
473
529
  staticChildNode = node;
@@ -484,8 +540,11 @@ async function analyze(id, code, job) {
484
540
  // - nodegyp()
485
541
  // - etc.
486
542
  else if (node.type === 'CallExpression') {
487
- if ((!isESM || job.mixedModules) && node.callee.type === 'Identifier' && node.arguments.length) {
488
- if (node.callee.name === 'require' && knownBindings.require.shadowDepth === 0) {
543
+ if ((!isESM || job.mixedModules) &&
544
+ node.callee.type === 'Identifier' &&
545
+ node.arguments.length) {
546
+ if (node.callee.name === 'require' &&
547
+ knownBindings.require.shadowDepth === 0) {
489
548
  await processRequireArg(node.arguments[0]);
490
549
  return;
491
550
  }
@@ -514,10 +573,15 @@ async function analyze(id, code, job) {
514
573
  await processRequireArg(node.arguments[0]);
515
574
  return;
516
575
  }
517
- const calleeValue = job.analysis.evaluatePureExpressions && await computePureStaticValue(node.callee, false);
576
+ const calleeValue = job.analysis.evaluatePureExpressions &&
577
+ (await computePureStaticValue(node.callee, false));
518
578
  // if we have a direct pure static function,
519
579
  // and that function has a [TRIGGER] symbol -> trigger asset emission from it
520
- if (calleeValue && 'value' in calleeValue && typeof calleeValue.value === 'function' && calleeValue.value[TRIGGER] && job.analysis.computeFileReferences) {
580
+ if (calleeValue &&
581
+ 'value' in calleeValue &&
582
+ typeof calleeValue.value === 'function' &&
583
+ calleeValue.value[TRIGGER] &&
584
+ job.analysis.computeFileReferences) {
521
585
  staticChildValue = await computePureStaticValue(node, true);
522
586
  // if it computes, then we start backtracking
523
587
  if (staticChildValue && parent) {
@@ -526,7 +590,9 @@ async function analyze(id, code, job) {
526
590
  }
527
591
  }
528
592
  // handle well-known function symbol cases
529
- else if (calleeValue && 'value' in calleeValue && typeof calleeValue.value === 'symbol') {
593
+ else if (calleeValue &&
594
+ 'value' in calleeValue &&
595
+ typeof calleeValue.value === 'symbol') {
530
596
  switch (calleeValue.value) {
531
597
  // customRequireWrapper('...')
532
598
  case BOUND_REQUIRE:
@@ -565,18 +631,35 @@ async function analyze(id, code, job) {
565
631
  }
566
632
  break;
567
633
  case NODE_GYP_BUILD:
568
- if (node.arguments.length === 1 && node.arguments[0].type === 'Identifier' &&
569
- node.arguments[0].name === '__dirname' && knownBindings.__dirname.shadowDepth === 0) {
634
+ // handle case: require('node-gyp-build')(__dirname)
635
+ const withDirname = node.arguments.length === 1 &&
636
+ node.arguments[0].type === 'Identifier' &&
637
+ node.arguments[0].name === '__dirname';
638
+ // handle case: require('node-gyp-build')(path.join(__dirname, '..'))
639
+ const withPathJoinDirname = node.arguments.length === 1 &&
640
+ node.arguments[0].callee?.object?.name === 'path' &&
641
+ node.arguments[0].callee?.property?.name === 'join' &&
642
+ node.arguments[0].arguments.length === 2 &&
643
+ node.arguments[0].arguments[0].type === 'Identifier' &&
644
+ node.arguments[0].arguments[0].name === '__dirname' &&
645
+ node.arguments[0].arguments[1].type === 'Literal';
646
+ if (knownBindings.__dirname.shadowDepth === 0 &&
647
+ (withDirname || withPathJoinDirname)) {
648
+ const pathJoinedDir = withPathJoinDirname
649
+ ? path_1.default.join(dir, node.arguments[0].arguments[1].value)
650
+ : dir;
570
651
  let resolved;
571
652
  try {
653
+ // the pkg could be 'node-gyp-build' or '@aminya/node-gyp-build'
654
+ const pkgName = node.callee.arguments[0].value;
572
655
  // use installed version of node-gyp-build since resolving
573
656
  // binaries can differ among versions
574
- const nodeGypBuildPath = (0, resolve_from_1.default)(dir, 'node-gyp-build');
575
- resolved = require(nodeGypBuildPath).path(dir);
657
+ const nodeGypBuildPath = (0, resolve_from_1.default)(pathJoinedDir, pkgName);
658
+ resolved = require(nodeGypBuildPath).path(pathJoinedDir);
576
659
  }
577
660
  catch (e) {
578
661
  try {
579
- resolved = node_gyp_build_1.default.path(dir);
662
+ resolved = node_gyp_build_1.default.path(pathJoinedDir);
580
663
  }
581
664
  catch (e) { }
582
665
  }
@@ -591,7 +674,10 @@ async function analyze(id, code, job) {
591
674
  case NBIND_INIT:
592
675
  if (node.arguments.length) {
593
676
  const arg = await computePureStaticValue(node.arguments[0], false);
594
- if (arg && 'value' in arg && (typeof arg.value === 'string' || typeof arg.value === 'undefined')) {
677
+ if (arg &&
678
+ 'value' in arg &&
679
+ (typeof arg.value === 'string' ||
680
+ typeof arg.value === 'undefined')) {
595
681
  const bindingInfo = (0, binary_locators_1.nbind)(arg.value);
596
682
  if (bindingInfo && bindingInfo.path) {
597
683
  deps.add(path_1.default.relative(dir, bindingInfo.path).replace(/\\/g, '/'));
@@ -622,7 +708,9 @@ async function analyze(id, code, job) {
622
708
  // if it computes, then we start backtracking
623
709
  if (staticChildValue) {
624
710
  staticChildNode = node.arguments[0];
625
- if (calleeValue.value === FS_DIR_FN && node.arguments[0].type === 'Identifier' && node.arguments[0].name === '__dirname') {
711
+ if (calleeValue.value === FS_DIR_FN &&
712
+ node.arguments[0].type === 'Identifier' &&
713
+ node.arguments[0].name === '__dirname') {
626
714
  // Special case `fs.readdirSync(__dirname)` to emit right away
627
715
  emitAssetDirectory(dir);
628
716
  }
@@ -646,7 +734,8 @@ async function analyze(id, code, job) {
646
734
  case PKG_INFO:
647
735
  let pjsonPath = path_1.default.resolve(id, '../package.json');
648
736
  const rootPjson = path_1.default.resolve('/package.json');
649
- while (pjsonPath !== rootPjson && (await job.stat(pjsonPath) === null))
737
+ while (pjsonPath !== rootPjson &&
738
+ (await job.stat(pjsonPath)) === null)
650
739
  pjsonPath = path_1.default.resolve(pjsonPath, '../../package.json');
651
740
  if (pjsonPath !== rootPjson)
652
741
  assets.add(pjsonPath);
@@ -654,7 +743,10 @@ async function analyze(id, code, job) {
654
743
  }
655
744
  }
656
745
  }
657
- else if (node.type === 'VariableDeclaration' && parent && !(0, ast_helpers_1.isVarLoop)(parent) && job.analysis.evaluatePureExpressions) {
746
+ else if (node.type === 'VariableDeclaration' &&
747
+ parent &&
748
+ !(0, ast_helpers_1.isVarLoop)(parent) &&
749
+ job.analysis.evaluatePureExpressions) {
658
750
  for (const decl of node.declarations) {
659
751
  if (!decl.init)
660
752
  continue;
@@ -674,10 +766,14 @@ async function analyze(id, code, job) {
674
766
  computed.value === null ||
675
767
  !(prop.key.name in computed.value))
676
768
  continue;
677
- setKnownBinding(prop.value.name, { value: computed.value[prop.key.name] });
769
+ setKnownBinding(prop.value.name, {
770
+ value: computed.value[prop.key.name],
771
+ });
678
772
  }
679
773
  }
680
- if (!('value' in computed) && isAbsolutePathOrUrl(computed.then) && isAbsolutePathOrUrl(computed.else)) {
774
+ if (!('value' in computed) &&
775
+ isAbsolutePathOrUrl(computed.then) &&
776
+ isAbsolutePathOrUrl(computed.else)) {
681
777
  staticChildValue = computed;
682
778
  staticChildNode = decl.init;
683
779
  await emitStaticChildAsset();
@@ -685,7 +781,10 @@ async function analyze(id, code, job) {
685
781
  }
686
782
  }
687
783
  }
688
- else if (node.type === 'AssignmentExpression' && parent && !(0, ast_helpers_1.isLoop)(parent) && job.analysis.evaluatePureExpressions) {
784
+ else if (node.type === 'AssignmentExpression' &&
785
+ parent &&
786
+ !(0, ast_helpers_1.isLoop)(parent) &&
787
+ job.analysis.evaluatePureExpressions) {
689
788
  if (!hasKnownBindingValue(node.left.name)) {
690
789
  const computed = await computePureStaticValue(node.right, false);
691
790
  if (computed && 'value' in computed) {
@@ -703,7 +802,9 @@ async function analyze(id, code, job) {
703
802
  computed.value === null ||
704
803
  !(prop.key.name in computed.value))
705
804
  continue;
706
- setKnownBinding(prop.value.name, { value: computed.value[prop.key.name] });
805
+ setKnownBinding(prop.value.name, {
806
+ value: computed.value[prop.key.name],
807
+ });
707
808
  }
708
809
  }
709
810
  if (isAbsolutePathOrUrl(computed.value)) {
@@ -716,11 +817,15 @@ async function analyze(id, code, job) {
716
817
  }
717
818
  // Support require wrappers like function p (x) { ...; var y = require(x); ...; return y; }
718
819
  else if ((!isESM || job.mixedModules) &&
719
- (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&
720
- (node.arguments || node.params)[0] && (node.arguments || node.params)[0].type === 'Identifier') {
820
+ (node.type === 'FunctionDeclaration' ||
821
+ node.type === 'FunctionExpression' ||
822
+ node.type === 'ArrowFunctionExpression') &&
823
+ (node.arguments || node.params)[0] &&
824
+ (node.arguments || node.params)[0].type === 'Identifier') {
721
825
  let fnName;
722
826
  let args;
723
- if ((node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') &&
827
+ if ((node.type === 'ArrowFunctionExpression' ||
828
+ node.type === 'FunctionExpression') &&
724
829
  parent &&
725
830
  parent.type === 'VariableDeclarator' &&
726
831
  parent.id.type === 'Identifier') {
@@ -734,7 +839,8 @@ async function analyze(id, code, job) {
734
839
  if (fnName && node.body.body) {
735
840
  let requireDecl, returned = false;
736
841
  for (let i = 0; i < node.body.body.length; i++) {
737
- if (node.body.body[i].type === 'VariableDeclaration' && !requireDecl) {
842
+ if (node.body.body[i].type === 'VariableDeclaration' &&
843
+ !requireDecl) {
738
844
  requireDecl = node.body.body[i].declarations.find((decl) => decl &&
739
845
  decl.id &&
740
846
  decl.id.type === 'Identifier' &&
@@ -779,14 +885,16 @@ async function analyze(id, code, job) {
779
885
  }
780
886
  if (staticChildNode && parent)
781
887
  await backtrack(parent, this);
782
- }
888
+ },
783
889
  });
784
890
  await assetEmissionPromises;
785
891
  return { assets, deps, imports, isESM };
786
892
  async function emitAssetPath(assetPath) {
787
893
  // verify the asset file / directory exists
788
894
  const wildcardIndex = assetPath.indexOf(static_eval_1.WILDCARD);
789
- const dirIndex = wildcardIndex === -1 ? assetPath.length : assetPath.lastIndexOf(path_1.default.sep, wildcardIndex);
895
+ const dirIndex = wildcardIndex === -1
896
+ ? assetPath.length
897
+ : assetPath.lastIndexOf(path_1.default.sep, wildcardIndex);
790
898
  const basePath = assetPath.substring(0, dirIndex);
791
899
  try {
792
900
  var stats = await job.stat(basePath);
@@ -829,30 +937,46 @@ async function analyze(id, code, job) {
829
937
  return false;
830
938
  // do not emit asset directories higher than the node_modules base if a package
831
939
  if (pkgBase) {
832
- const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) + path_1.default.sep + 'node_modules' + path_1.default.sep;
940
+ const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) +
941
+ path_1.default.sep +
942
+ 'node_modules' +
943
+ path_1.default.sep;
833
944
  if (!assetPath.startsWith(nodeModulesBase)) {
834
945
  if (job.log)
835
- console.log('Skipping asset emission of ' + assetPath.replace(static_eval_1.wildcardRegEx, '*') + ' for ' + id + ' as it is outside the package base ' + pkgBase);
946
+ console.log('Skipping asset emission of ' +
947
+ assetPath.replace(static_eval_1.wildcardRegEx, '*') +
948
+ ' for ' +
949
+ id +
950
+ ' as it is outside the package base ' +
951
+ pkgBase);
836
952
  return false;
837
953
  }
838
954
  }
839
955
  return true;
840
956
  }
841
957
  function resolveAbsolutePathOrUrl(value) {
842
- return value instanceof url_1.URL ? (0, url_1.fileURLToPath)(value) : value.startsWith('file:') ? (0, url_1.fileURLToPath)(new url_1.URL(value)) : path_1.default.resolve(value);
958
+ return value instanceof url_1.URL
959
+ ? (0, url_1.fileURLToPath)(value)
960
+ : value.startsWith('file:')
961
+ ? (0, url_1.fileURLToPath)(new url_1.URL(value))
962
+ : path_1.default.resolve(value);
843
963
  }
844
964
  async function emitStaticChildAsset() {
845
965
  if (!staticChildValue) {
846
966
  return;
847
967
  }
848
- if ('value' in staticChildValue && isAbsolutePathOrUrl(staticChildValue.value)) {
968
+ if ('value' in staticChildValue &&
969
+ isAbsolutePathOrUrl(staticChildValue.value)) {
849
970
  try {
850
971
  const resolved = resolveAbsolutePathOrUrl(staticChildValue.value);
851
972
  await emitAssetPath(resolved);
852
973
  }
853
974
  catch (e) { }
854
975
  }
855
- else if ('then' in staticChildValue && 'else' in staticChildValue && isAbsolutePathOrUrl(staticChildValue.then) && isAbsolutePathOrUrl(staticChildValue.else)) {
976
+ else if ('then' in staticChildValue &&
977
+ 'else' in staticChildValue &&
978
+ isAbsolutePathOrUrl(staticChildValue.then) &&
979
+ isAbsolutePathOrUrl(staticChildValue.else)) {
856
980
  let resolvedThen;
857
981
  try {
858
982
  resolvedThen = resolveAbsolutePathOrUrl(staticChildValue.then);
@@ -868,7 +992,10 @@ async function analyze(id, code, job) {
868
992
  if (resolvedElse)
869
993
  await emitAssetPath(resolvedElse);
870
994
  }
871
- else if (staticChildNode && staticChildNode.type === 'ArrayExpression' && 'value' in staticChildValue && staticChildValue.value instanceof Array) {
995
+ else if (staticChildNode &&
996
+ staticChildNode.type === 'ArrayExpression' &&
997
+ 'value' in staticChildValue &&
998
+ staticChildValue.value instanceof Array) {
872
999
  for (const value of staticChildValue.value) {
873
1000
  try {
874
1001
  const resolved = resolveAbsolutePathOrUrl(value);
@@ -881,7 +1008,6 @@ async function analyze(id, code, job) {
881
1008
  }
882
1009
  }
883
1010
  exports.default = analyze;
884
- ;
885
1011
  function isAst(ast) {
886
1012
  return 'body' in ast;
887
1013
  }