@vercel/nft 0.17.5 → 0.18.2

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
@@ -190,8 +190,8 @@ async function analyze(id, code, job) {
190
190
  return;
191
191
  const wildcardIndex = wildcardPath.indexOf(static_eval_1.WILDCARD);
192
192
  const dirIndex = wildcardIndex === -1 ? wildcardPath.length : wildcardPath.lastIndexOf(path_1.default.sep, wildcardIndex);
193
- const assetDirPath = wildcardPath.substr(0, dirIndex);
194
- const patternPath = wildcardPath.substr(dirIndex);
193
+ const assetDirPath = wildcardPath.substring(0, dirIndex);
194
+ const patternPath = wildcardPath.slice(dirIndex);
195
195
  const wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => {
196
196
  return patternPath[index - 1] === path_1.default.sep ? '**/*' : '*';
197
197
  }).replace(repeatGlobRegEx, '/**/*') || '/**/*';
@@ -339,8 +339,8 @@ async function analyze(id, code, job) {
339
339
  wildcardRequire = path_1.default.resolve(dir, wildcardRequire);
340
340
  const wildcardIndex = wildcardRequire.indexOf(static_eval_1.WILDCARD);
341
341
  const dirIndex = wildcardIndex === -1 ? wildcardRequire.length : wildcardRequire.lastIndexOf(path_1.default.sep, wildcardIndex);
342
- const wildcardDirPath = wildcardRequire.substr(0, dirIndex);
343
- const patternPath = wildcardRequire.substr(dirIndex);
342
+ const wildcardDirPath = wildcardRequire.substring(0, dirIndex);
343
+ const patternPath = wildcardRequire.slice(dirIndex);
344
344
  let wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => {
345
345
  return patternPath[index - 1] === path_1.default.sep ? '**/*' : '*';
346
346
  }) || '/**/*';
@@ -741,7 +741,7 @@ async function analyze(id, code, job) {
741
741
  // verify the asset file / directory exists
742
742
  const wildcardIndex = assetPath.indexOf(static_eval_1.WILDCARD);
743
743
  const dirIndex = wildcardIndex === -1 ? assetPath.length : assetPath.lastIndexOf(path_1.default.sep, wildcardIndex);
744
- const basePath = assetPath.substr(0, dirIndex);
744
+ const basePath = assetPath.substring(0, dirIndex);
745
745
  try {
746
746
  var stats = await job.stat(basePath);
747
747
  if (stats === null) {
@@ -779,11 +779,11 @@ async function analyze(id, code, job) {
779
779
  if (assetPath.endsWith(path_1.default.sep + 'node_modules' + wildcardSuffix))
780
780
  return false;
781
781
  // do not emit directories above __dirname
782
- if (dir.startsWith(assetPath.substr(0, assetPath.length - wildcardSuffix.length) + path_1.default.sep))
782
+ if (dir.startsWith(assetPath.slice(0, assetPath.length - wildcardSuffix.length) + path_1.default.sep))
783
783
  return false;
784
784
  // do not emit asset directories higher than the node_modules base if a package
785
785
  if (pkgBase) {
786
- const nodeModulesBase = id.substr(0, id.indexOf(path_1.default.sep + 'node_modules')) + path_1.default.sep + 'node_modules' + path_1.default.sep;
786
+ const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) + path_1.default.sep + 'node_modules' + path_1.default.sep;
787
787
  if (!assetPath.startsWith(nodeModulesBase)) {
788
788
  if (job.log)
789
789
  console.log('Skipping asset emission of ' + assetPath.replace(static_eval_1.wildcardRegEx, '*') + ' for ' + id + ' as it is outside the package base ' + pkgBase);
package/out/cli.js CHANGED
@@ -6,13 +6,26 @@ const graceful_fs_1 = require("graceful-fs");
6
6
  const { copyFile, mkdir } = graceful_fs_1.promises;
7
7
  const rimraf = require('rimraf');
8
8
  const node_file_trace_1 = require("./node-file-trace");
9
- async function cli(action = process.argv[2], files = process.argv.slice(3), outputDir = 'dist', cwd = process.cwd()) {
9
+ function printStack(file, reasons, stdout, cwd) {
10
+ stdout.push(file);
11
+ const reason = reasons.get(file);
12
+ if (!reason ||
13
+ !reason.parents ||
14
+ (reason.type.length === 1 && reason.type.includes('initial') && reason.parents.size === 0)) {
15
+ return;
16
+ }
17
+ for (let parent of reason.parents) {
18
+ printStack(parent, reasons, stdout, cwd);
19
+ }
20
+ }
21
+ async function cli(action = process.argv[2], entrypoint = process.argv[3], exitpoint = process.argv[4], outputDir = 'dist', cwd = process.cwd()) {
10
22
  const opts = {
11
23
  ts: true,
24
+ base: cwd,
12
25
  mixedModules: true,
13
- log: action !== 'size'
26
+ log: action == 'print' || action == 'build',
14
27
  };
15
- const { fileList, esmFileList, warnings } = await node_file_trace_1.nodeFileTrace(files, opts);
28
+ const { fileList, esmFileList, warnings, reasons } = await node_file_trace_1.nodeFileTrace([entrypoint], opts);
16
29
  const allFiles = [...fileList].concat([...esmFileList]).sort();
17
30
  const stdout = [];
18
31
  if (action === 'print') {
@@ -21,7 +34,9 @@ async function cli(action = process.argv[2], files = process.argv.slice(3), outp
21
34
  stdout.push('\n');
22
35
  if (warnings.size > 0) {
23
36
  stdout.push('WARNINGS:');
24
- stdout.push(...warnings);
37
+ for (var warning of warnings) {
38
+ stdout.push(warning.toString());
39
+ }
25
40
  }
26
41
  }
27
42
  else if (action === 'build') {
@@ -49,6 +64,15 @@ async function cli(action = process.argv[2], files = process.argv.slice(3), outp
49
64
  }
50
65
  stdout.push(`${bytes} bytes total`);
51
66
  }
67
+ else if (action === 'why') {
68
+ if (!exitpoint) {
69
+ throw new Error('Expected additional argument for "why" action');
70
+ }
71
+ const normalizedExitPoint = (path_1.isAbsolute(exitpoint)
72
+ ? path_1.relative(cwd, exitpoint)
73
+ : exitpoint).replace(/[/\\]/g, path_1.sep);
74
+ printStack(normalizedExitPoint, reasons, stdout, cwd);
75
+ }
52
76
  else {
53
77
  stdout.push(`△ nft ${require('../package.json').version}`);
54
78
  stdout.push('');
@@ -58,9 +82,10 @@ async function cli(action = process.argv[2], files = process.argv.slice(3), outp
58
82
  stdout.push('');
59
83
  stdout.push('Commands:');
60
84
  stdout.push('');
61
- stdout.push(' build trace and copy to the dist directory');
62
- stdout.push(' print trace and print to stdout');
63
- stdout.push(' size trace and print size in bytes');
85
+ stdout.push(' build [entrypoint] trace and copy to the dist directory');
86
+ stdout.push(' print [entrypoint] trace and print to stdout');
87
+ stdout.push(' size [entrypoint] trace and print size in bytes');
88
+ stdout.push(' why [entrypoint] [file] trace and print stack why file was included');
64
89
  }
65
90
  return stdout.join('\n');
66
91
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { NodeFileTraceOptions, NodeFileTraceResult, NodeFileTraceReasons, Stats } from './types';
2
+ import { NodeFileTraceOptions, NodeFileTraceResult, NodeFileTraceReasons, Stats, NodeFileTraceReasonType } from './types';
3
3
  export declare function nodeFileTrace(files: string[], opts?: NodeFileTraceOptions): Promise<NodeFileTraceResult>;
4
4
  export declare class Job {
5
5
  ts: boolean;
@@ -33,7 +33,7 @@ export declare class Job {
33
33
  resolve(id: string, parent: string, job: Job, cjsResolve: boolean): Promise<string | string[]>;
34
34
  readFile(path: string): Promise<string | Buffer | null>;
35
35
  realpath(path: string, parent?: string, seen?: Set<unknown>): Promise<string>;
36
- emitFile(path: string, reason: string, parent?: string, isRealpath?: boolean): Promise<boolean>;
36
+ emitFile(path: string, reasonType: NodeFileTraceReasonType, parent?: string, isRealpath?: boolean): Promise<boolean>;
37
37
  getPjsonBoundary(path: string): Promise<string | undefined>;
38
38
  emitDependency(path: string, parent?: string): Promise<void>;
39
39
  }
@@ -208,7 +208,7 @@ class Job {
208
208
  return path;
209
209
  return path_2.join(await this.realpath(path_1.dirname(path), parent, seen), path_1.basename(path));
210
210
  }
211
- async emitFile(path, reason, parent, isRealpath = false) {
211
+ async emitFile(path, reasonType, parent, isRealpath = false) {
212
212
  if (!isRealpath) {
213
213
  path = await this.realpath(path, parent);
214
214
  }
@@ -219,12 +219,15 @@ class Job {
219
219
  let reasonEntry = this.reasons.get(path);
220
220
  if (!reasonEntry) {
221
221
  reasonEntry = {
222
- type: reason,
222
+ type: [reasonType],
223
223
  ignored: false,
224
224
  parents: new Set()
225
225
  };
226
226
  this.reasons.set(path, reasonEntry);
227
227
  }
228
+ else if (!reasonEntry.type.includes(reasonType)) {
229
+ reasonEntry.type.push(reasonType);
230
+ }
228
231
  if (parent && this.ignoreFn(path, parent)) {
229
232
  if (!this.fileList.has(path) && reasonEntry) {
230
233
  reasonEntry.ignored = true;
@@ -241,7 +244,7 @@ class Job {
241
244
  const rootSeparatorIndex = path.indexOf(path_1.sep);
242
245
  let separatorIndex;
243
246
  while ((separatorIndex = path.lastIndexOf(path_1.sep)) > rootSeparatorIndex) {
244
- path = path.substr(0, separatorIndex);
247
+ path = path.slice(0, separatorIndex);
245
248
  if (await this.isFile(path + path_1.sep + 'package.json'))
246
249
  return path;
247
250
  }
@@ -288,7 +291,7 @@ class Job {
288
291
  ...[...assets].map(async (asset) => {
289
292
  const ext = path_1.extname(asset);
290
293
  if (ext === '.js' || ext === '.mjs' || ext === '.node' || ext === '' ||
291
- this.ts && (ext === '.ts' || ext === '.tsx') && asset.startsWith(this.base) && asset.substr(this.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1)
294
+ this.ts && (ext === '.ts' || ext === '.tsx') && asset.startsWith(this.base) && asset.slice(this.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1)
292
295
  await this.emitDependency(asset, path);
293
296
  else
294
297
  await this.emitFile(asset, 'asset', path);
@@ -41,9 +41,9 @@ async function resolveFile(path, parent, job) {
41
41
  path = await job.realpath(path, parent);
42
42
  if (await job.isFile(path))
43
43
  return path;
44
- if (job.ts && path.startsWith(job.base) && path.substr(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.ts'))
44
+ if (job.ts && path.startsWith(job.base) && path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.ts'))
45
45
  return path + '.ts';
46
- if (job.ts && path.startsWith(job.base) && path.substr(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.tsx'))
46
+ if (job.ts && path.startsWith(job.base) && path.slice(job.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1 && await job.isFile(path + '.tsx'))
47
47
  return path + '.tsx';
48
48
  if (await job.isFile(path + '.js'))
49
49
  return path + '.js';
@@ -205,7 +205,7 @@ async function resolvePackage(name, parent, job, cjsResolve) {
205
205
  let separatorIndex;
206
206
  const rootSeparatorIndex = packageParent.indexOf(path_1.sep);
207
207
  while ((separatorIndex = packageParent.lastIndexOf(path_1.sep)) > rootSeparatorIndex) {
208
- packageParent = packageParent.substr(0, separatorIndex);
208
+ packageParent = packageParent.slice(0, separatorIndex);
209
209
  const nodeModulesDir = packageParent + path_1.sep + 'node_modules';
210
210
  const stat = await job.stat(nodeModulesDir);
211
211
  if (!stat || !stat.isDirectory())
package/out/types.d.ts CHANGED
@@ -49,8 +49,9 @@ export interface NodeFileTraceOptions {
49
49
  readlink?: (path: string) => Promise<string | null>;
50
50
  resolve?: (id: string, parent: string, job: Job, cjsResolve: boolean) => Promise<string | string[]>;
51
51
  }
52
+ export declare type NodeFileTraceReasonType = 'initial' | 'resolve' | 'dependency' | 'asset' | 'sharedlib';
52
53
  export interface NodeFileTraceReasons extends Map<string, {
53
- type: string;
54
+ type: NodeFileTraceReasonType[];
54
55
  ignored: boolean;
55
56
  parents: Set<string>;
56
57
  }> {
@@ -9,9 +9,9 @@ function getPackageBase(id) {
9
9
  if (pkgIndex !== -1 &&
10
10
  (id[pkgIndex - 1] === '/' || id[pkgIndex - 1] === '\\') &&
11
11
  (id[pkgIndex + 12] === '/' || id[pkgIndex + 12] === '\\')) {
12
- const pkgNameMatch = id.substr(pkgIndex + 13).match(pkgNameRegEx);
12
+ const pkgNameMatch = id.slice(pkgIndex + 13).match(pkgNameRegEx);
13
13
  if (pkgNameMatch)
14
- return id.substr(0, pkgIndex + 13 + pkgNameMatch[0].length);
14
+ return id.slice(0, pkgIndex + 13 + pkgNameMatch[0].length);
15
15
  }
16
16
  return undefined;
17
17
  }
@@ -21,7 +21,7 @@ function getPackageName(id) {
21
21
  if (pkgIndex !== -1 &&
22
22
  (id[pkgIndex - 1] === '/' || id[pkgIndex - 1] === '\\') &&
23
23
  (id[pkgIndex + 12] === '/' || id[pkgIndex + 12] === '\\')) {
24
- const pkgNameMatch = id.substr(pkgIndex + 13).match(pkgNameRegEx);
24
+ const pkgNameMatch = id.slice(pkgIndex + 13).match(pkgNameRegEx);
25
25
  if (pkgNameMatch && pkgNameMatch.length > 0) {
26
26
  return pkgNameMatch[0].replace(/\\/g, '/');
27
27
  }
@@ -229,6 +229,11 @@ const specialCases = {
229
229
  emitAsset(path_1.resolve(path_1.dirname(id), '../data/geo.dat'));
230
230
  }
231
231
  },
232
+ 'pixelmatch'({ id, emitAsset }) {
233
+ if (id.endsWith('pixelmatch/index.js')) {
234
+ emitAsset(path_1.resolve(path_1.dirname(id), 'bin/pixelmatch'));
235
+ }
236
+ }
232
237
  };
233
238
  async function handleSpecialCases({ id, ast, emitAsset, emitAssetDirectory, job }) {
234
239
  const pkgName = get_package_base_1.getPackageName(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/nft",
3
- "version": "0.17.5",
3
+ "version": "0.18.2",
4
4
  "repository": "vercel/nft",
5
5
  "license": "MIT",
6
6
  "main": "./out/index.js",
@@ -55,6 +55,7 @@
55
55
  "bcrypt": "^5.0.1",
56
56
  "browserify-middleware": "^8.1.1",
57
57
  "bull": "^3.10.0",
58
+ "bullmq": "^1.74.2",
58
59
  "camaro": "^6.1.0",
59
60
  "canvas": "^2.9.0",
60
61
  "chromeless": "^1.5.2",
@@ -100,15 +101,17 @@
100
101
  "pdfkit": "^0.10.0",
101
102
  "pg": "^7.11.0",
102
103
  "phantomjs-prebuilt": "^2.1.16",
104
+ "pixelmatch": "^5.2.1",
103
105
  "playwright-core": "^1.17.1",
104
106
  "polyfill-library": "3.93.0",
105
- "prismjs": "^1.25.0",
107
+ "prismjs": "^1.27.0",
106
108
  "pug": "^3.0.1",
107
109
  "react": "^16.14.0",
108
110
  "react-dom": "^16.14.0",
109
111
  "redis": "^3.1.1",
110
112
  "remark-parse": "^10.0.0",
111
113
  "remark-prism": "^1.3.6",
114
+ "rimraf": "^3.0.2",
112
115
  "rxjs": "^6.5.2",
113
116
  "saslprep": "^1.0.3",
114
117
  "semver": "^7.1.1",
@@ -123,7 +126,7 @@
123
126
  "typescript": "^3.9.6",
124
127
  "uglify-js": "^3.6.0",
125
128
  "unified": "^10.1.0",
126
- "vm2": "^3.9.4",
129
+ "vm2": "^3.9.6",
127
130
  "vue": "^2.6.10",
128
131
  "vue-server-renderer": "^2.6.10",
129
132
  "when": "^3.7.8"