@vercel/nft 0.12.1 → 0.14.0

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
@@ -23,7 +23,7 @@ const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
23
23
  const node_pre_gyp_1 = __importDefault(require("@mapbox/node-pre-gyp"));
24
24
  const url_1 = require("url");
25
25
  // Note: these should be deprecated over time as they ship in Acorn core
26
- const acorn = acorn_1.Parser.extend(require("acorn-class-fields"), require("acorn-static-class-features"));
26
+ const acorn = acorn_1.Parser.extend(require("acorn-class-fields"), require("acorn-static-class-features"), require("acorn-private-class-elements"));
27
27
  const os_1 = __importDefault(require("os"));
28
28
  const wrappers_1 = require("./utils/wrappers");
29
29
  const resolve_from_1 = __importDefault(require("resolve-from"));
@@ -206,7 +206,7 @@ async function analyze(id, code, job) {
206
206
  let ast;
207
207
  let isESM = false;
208
208
  try {
209
- ast = acorn.parse(code, { ecmaVersion: 2020, allowReturnOutsideFunction: true });
209
+ ast = acorn.parse(code, { ecmaVersion: 'latest', allowReturnOutsideFunction: true });
210
210
  isESM = false;
211
211
  }
212
212
  catch (e) {
@@ -218,7 +218,7 @@ async function analyze(id, code, job) {
218
218
  //@ts-ignore
219
219
  if (!ast) {
220
220
  try {
221
- ast = acorn.parse(code, { ecmaVersion: 2020, sourceType: 'module', allowAwaitOutsideFunction: true });
221
+ ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', allowAwaitOutsideFunction: true });
222
222
  isESM = true;
223
223
  }
224
224
  catch (e) {
@@ -283,10 +283,10 @@ async function analyze(id, code, job) {
283
283
  const binding = knownBindings[name];
284
284
  return binding && binding.shadowDepth === 0;
285
285
  }
286
- if (isESM || job.mixedModules) {
286
+ if ((isESM || job.mixedModules) && isAst(ast)) {
287
287
  for (const decl of ast.body) {
288
288
  if (decl.type === 'ImportDeclaration') {
289
- const source = decl.source.value;
289
+ const source = String(decl.source.value);
290
290
  deps.add(source);
291
291
  const staticModule = staticModules[source];
292
292
  if (staticModule) {
@@ -302,7 +302,7 @@ async function analyze(id, code, job) {
302
302
  }
303
303
  else if (decl.type === 'ExportNamedDeclaration' || decl.type === 'ExportAllDeclaration') {
304
304
  if (decl.source)
305
- deps.add(decl.source.value);
305
+ deps.add(String(decl.source.value));
306
306
  }
307
307
  }
308
308
  }
@@ -379,8 +379,10 @@ async function analyze(id, code, job) {
379
379
  }
380
380
  }
381
381
  let scope = rollup_pluginutils_1.attachScopes(ast, 'scope');
382
- wrappers_1.handleWrappers(ast);
383
- special_cases_1.default({ id, ast, emitAsset: path => assets.add(path), emitAssetDirectory, job });
382
+ if (isAst(ast)) {
383
+ wrappers_1.handleWrappers(ast);
384
+ special_cases_1.default({ id, ast, emitAsset: path => assets.add(path), emitAssetDirectory, job });
385
+ }
384
386
  function backtrack(parent, context) {
385
387
  // computing a static expression outward
386
388
  // -> compute and backtrack
@@ -812,3 +814,6 @@ async function analyze(id, code, job) {
812
814
  }
813
815
  exports.default = analyze;
814
816
  ;
817
+ function isAst(ast) {
818
+ return 'body' in ast;
819
+ }
package/out/cli.js CHANGED
@@ -10,7 +10,7 @@ async function cli(action = process.argv[2], files = process.argv.slice(3), outp
10
10
  const opts = {
11
11
  ts: true,
12
12
  mixedModules: true,
13
- log: true
13
+ log: action !== 'size'
14
14
  };
15
15
  const { fileList, esmFileList, warnings } = await node_file_trace_1.nodeFileTrace(files, opts);
16
16
  const allFiles = fileList.concat(esmFileList);
@@ -34,8 +34,33 @@ async function cli(action = process.argv[2], files = process.argv.slice(3), outp
34
34
  await copyFile(src, dest);
35
35
  }
36
36
  }
37
+ else if (action === 'size') {
38
+ const isSymbolicLink = (m) => (m & 61440) === 40960;
39
+ let bytes = 0;
40
+ for (const f of allFiles) {
41
+ const lstat = fs_1.lstatSync(f);
42
+ if (isSymbolicLink(lstat.mode)) {
43
+ bytes += lstat.size;
44
+ }
45
+ else {
46
+ const stat = fs_1.statSync(f);
47
+ bytes += stat.size;
48
+ }
49
+ }
50
+ stdout.push(`${bytes} bytes total`);
51
+ }
37
52
  else {
38
- stdout.push('△ nft - provide an action such as `nft build` or `nft print`.');
53
+ stdout.push(`△ nft ${require('../package.json').version}`);
54
+ stdout.push('');
55
+ stdout.push('Usage:');
56
+ stdout.push('');
57
+ stdout.push(` $ nft [command] <file>`);
58
+ stdout.push('');
59
+ stdout.push('Commands:');
60
+ 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');
39
64
  }
40
65
  return stdout.join('\n');
41
66
  }
package/out/types.d.ts CHANGED
@@ -62,13 +62,3 @@ export interface NodeFileTraceResult {
62
62
  reasons: NodeFileTraceReasons;
63
63
  warnings: Error[];
64
64
  }
65
- export interface StaticValue {
66
- value: any;
67
- wildcards?: string[];
68
- }
69
- export interface ConditionalValue {
70
- test: string;
71
- then: any;
72
- else: any;
73
- }
74
- export declare type EvaluatedValue = StaticValue | ConditionalValue | undefined;
@@ -48,7 +48,9 @@ const specialCases = {
48
48
  if (id.endsWith('oracledb/lib/oracledb.js')) {
49
49
  for (const statement of ast.body) {
50
50
  if (statement.type === 'ForStatement' &&
51
+ 'body' in statement.body &&
51
52
  statement.body.body &&
53
+ Array.isArray(statement.body.body) &&
52
54
  statement.body.body[0] &&
53
55
  statement.body.body[0].type === 'TryStatement' &&
54
56
  statement.body.body[0].block.body[0] &&
@@ -81,6 +83,18 @@ const specialCases = {
81
83
  emitAssetDirectory(path_1.resolve(path_1.dirname(id), '..', 'bin'));
82
84
  }
83
85
  },
86
+ 'remark-prism'({ id, emitAssetDirectory }) {
87
+ const file = 'remark-prism/src/highlight.js';
88
+ if (id.endsWith(file)) {
89
+ try {
90
+ const node_modules = id.slice(0, -file.length);
91
+ emitAssetDirectory(path_1.resolve(node_modules, 'prismjs', 'components'));
92
+ }
93
+ catch (e) {
94
+ // fail silently
95
+ }
96
+ }
97
+ },
84
98
  'semver'({ id, emitAsset }) {
85
99
  if (id.endsWith('semver/index.js')) {
86
100
  // See https://github.com/npm/node-semver/blob/master/CHANGELOG.md#710
@@ -105,7 +119,7 @@ const specialCases = {
105
119
  const arg = statement.expression.right.arguments[0].arguments[0].value;
106
120
  let resolved;
107
121
  try {
108
- const dep = resolve_dependency_1.default(arg, id, job);
122
+ const dep = resolve_dependency_1.default(String(arg), id, job);
109
123
  if (typeof dep === 'string') {
110
124
  resolved = dep;
111
125
  }
@@ -120,7 +134,9 @@ const specialCases = {
120
134
  const relResolved = '/' + path_1.relative(path_1.dirname(id), resolved);
121
135
  statement.expression.right.arguments[0] = {
122
136
  type: 'BinaryExpression',
137
+ // @ts-ignore Its okay if start is undefined
123
138
  start: statement.expression.right.arguments[0].start,
139
+ // @ts-ignore Its okay if end is undefined
124
140
  end: statement.expression.right.arguments[0].end,
125
141
  operator: '+',
126
142
  left: {
@@ -149,18 +165,19 @@ const specialCases = {
149
165
  statement.expression.left.property.type === 'Identifier' &&
150
166
  statement.expression.left.property.name === 'serveClient' &&
151
167
  statement.expression.right.type === 'FunctionExpression') {
152
- let ifStatement;
153
- for (const node of statement.expression.right.body.body)
154
- if (node.type === 'IfStatement')
155
- ifStatement = node;
156
- const ifBody = ifStatement && ifStatement.consequent.body;
157
- let replaced = false;
158
- if (ifBody && ifBody[0] && ifBody[0].type === 'ExpressionStatement')
159
- replaced = replaceResolvePathStatement(ifBody[0]);
160
- const tryBody = ifBody && ifBody[1] && ifBody[1].type === 'TryStatement' && ifBody[1].block.body;
161
- if (tryBody && tryBody[0])
162
- replaced = replaceResolvePathStatement(tryBody[0]) || replaced;
163
- return;
168
+ for (const node of statement.expression.right.body.body) {
169
+ if (node.type === 'IfStatement' && node.consequent && 'body' in node.consequent && node.consequent.body) {
170
+ const ifBody = node.consequent.body;
171
+ let replaced = false;
172
+ if (Array.isArray(ifBody) && ifBody[0] && ifBody[0].type === 'ExpressionStatement') {
173
+ replaced = replaceResolvePathStatement(ifBody[0]);
174
+ }
175
+ if (Array.isArray(ifBody) && ifBody[1] && ifBody[1].type === 'TryStatement' && ifBody[1].block.body && ifBody[1].block.body[0]) {
176
+ replaced = replaceResolvePathStatement(ifBody[1].block.body[0]) || replaced;
177
+ }
178
+ return;
179
+ }
180
+ }
164
181
  }
165
182
  }
166
183
  }
@@ -191,7 +208,12 @@ const specialCases = {
191
208
  emitAssetDirectory(path_1.resolve(id, '../../lib'));
192
209
  emitAsset(path_1.resolve(id, '../exports.js'));
193
210
  }
194
- }
211
+ },
212
+ 'playwright-core'({ id, emitAsset }) {
213
+ if (id.endsWith('playwright-core/index.js')) {
214
+ emitAsset(path_1.resolve(path_1.dirname(id), 'browsers.json'));
215
+ }
216
+ },
195
217
  };
196
218
  function handleSpecialCases({ id, ast, emitAsset, emitAssetDirectory, job }) {
197
219
  const pkgName = get_package_base_1.getPackageName(id);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,6 +7,7 @@ function isUndefinedOrVoid(node) {
7
7
  }
8
8
  // Wrapper detection pretransforms to enable static analysis
9
9
  function handleWrappers(ast) {
10
+ var _a;
10
11
  // UglifyJS will convert function wrappers into !function(){}
11
12
  let wrapper;
12
13
  if (ast.body.length === 1 &&
@@ -36,6 +37,8 @@ function handleWrappers(ast) {
36
37
  ast.body[0].expression.right.arguments.length === 1)
37
38
  wrapper = ast.body[0].expression.right;
38
39
  if (wrapper) {
40
+ let browserifyReturn;
41
+ let webpackModuleObj;
39
42
  // When.js-style AMD wrapper:
40
43
  // (function (define) { 'use strict' define(function (require) { ... }) })
41
44
  // (typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); })
@@ -49,6 +52,7 @@ function handleWrappers(ast) {
49
52
  wrapper.arguments[0].test.left.operator === '===' &&
50
53
  wrapper.arguments[0].test.left.left.type === 'UnaryExpression' &&
51
54
  wrapper.arguments[0].test.left.left.operator === 'typeof' &&
55
+ 'name' in wrapper.arguments[0].test.left.left.argument &&
52
56
  wrapper.arguments[0].test.left.left.argument.name === 'define' &&
53
57
  wrapper.arguments[0].test.left.right.type === 'Literal' &&
54
58
  wrapper.arguments[0].test.left.right.value === 'function' &&
@@ -72,6 +76,9 @@ function handleWrappers(ast) {
72
76
  wrapper.arguments[0].alternate.body.body[0].expression.right.type === 'CallExpression' &&
73
77
  wrapper.arguments[0].alternate.body.body[0].expression.right.callee.type === 'Identifier' &&
74
78
  wrapper.arguments[0].alternate.body.body[0].expression.right.callee.name === wrapper.arguments[0].alternate.params[0].name &&
79
+ 'body' in wrapper.callee &&
80
+ 'body' in wrapper.callee.body &&
81
+ Array.isArray(wrapper.callee.body.body) &&
75
82
  wrapper.arguments[0].alternate.body.body[0].expression.right.arguments.length === 1 &&
76
83
  wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0].type === 'Identifier' &&
77
84
  wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0].name === 'require') {
@@ -91,8 +98,13 @@ function handleWrappers(ast) {
91
98
  body[0].expression.arguments[0].params.length === 1 &&
92
99
  body[0].expression.arguments[0].params[0].type === 'Identifier' &&
93
100
  body[0].expression.arguments[0].params[0].name === 'require') {
94
- delete body[0].expression.arguments[0].scope.declarations.require;
95
- body[0].expression.arguments[0].params = [];
101
+ const arg = body[0].expression.arguments[0];
102
+ arg.params = [];
103
+ try {
104
+ // @ts-ignore If it doesn't exist thats ok
105
+ delete arg.scope.declarations.require;
106
+ }
107
+ catch (e) { }
96
108
  }
97
109
  }
98
110
  // Browserify-style wrapper
@@ -117,32 +129,35 @@ function handleWrappers(ast) {
117
129
  wrapper.arguments[0].body.body.length === 2 &&
118
130
  wrapper.arguments[0].body.body[0].type === 'VariableDeclaration' &&
119
131
  wrapper.arguments[0].body.body[0].declarations.length === 3 &&
120
- wrapper.arguments[0].body.body[0].declarations.every((decl) => decl.init === null && decl.id.type === 'Identifier')) &&
132
+ wrapper.arguments[0].body.body[0].declarations.every(decl => decl.init === null && decl.id.type === 'Identifier')) &&
121
133
  wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].type === 'ReturnStatement' &&
122
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.type === 'CallExpression' &&
123
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.type === 'CallExpression' &&
124
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.arguments.length &&
125
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.arguments.every((arg) => arg && arg.type === 'Literal' && typeof arg.value === 'number') &&
126
- (wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.callee.type === 'FunctionExpression' ||
127
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.callee.type === 'CallExpression' &&
128
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.callee.callee.type === 'FunctionExpression' &&
129
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.callee.arguments.length === 0) &&
134
+ (browserifyReturn = wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]) &&
135
+ ((_a = browserifyReturn.argument) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
136
+ browserifyReturn.argument.arguments.length &&
137
+ browserifyReturn.argument.arguments.every(arg => arg && arg.type === 'Literal' && typeof arg.value === 'number') &&
138
+ browserifyReturn.argument.callee.type === 'CallExpression' &&
139
+ (browserifyReturn.argument.callee.callee.type === 'FunctionExpression' ||
140
+ browserifyReturn.argument.callee.callee.type === 'CallExpression' &&
141
+ browserifyReturn.argument.callee.callee.callee.type === 'FunctionExpression' &&
142
+ browserifyReturn.argument.callee.callee.arguments.length === 0) &&
130
143
  // (dont go deeper into browserify loader internals than this)
131
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.arguments.length === 3 &&
132
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.arguments[0].type === 'ObjectExpression' &&
133
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.arguments[1].type === 'ObjectExpression' &&
134
- wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.arguments[2].type === 'ArrayExpression') {
135
- const modules = wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1].argument.callee.arguments[0].properties;
144
+ browserifyReturn.argument.callee.arguments.length === 3 &&
145
+ browserifyReturn.argument.callee.arguments[0].type === 'ObjectExpression' &&
146
+ browserifyReturn.argument.callee.arguments[1].type === 'ObjectExpression' &&
147
+ browserifyReturn.argument.callee.arguments[2].type === 'ArrayExpression') {
148
+ const modules = browserifyReturn.argument.callee.arguments[0].properties;
136
149
  // verify modules is the expected data structure
137
150
  // in the process, extract external requires
138
151
  const externals = {};
139
- if (modules.every((m) => {
152
+ if (modules.every(m => {
140
153
  if (m.type !== 'Property' ||
141
154
  m.computed !== false ||
142
155
  m.key.type !== 'Literal' ||
143
156
  typeof m.key.value !== 'number' ||
144
157
  m.value.type !== 'ArrayExpression' ||
145
158
  m.value.elements.length !== 2 ||
159
+ !m.value.elements[0] ||
160
+ !m.value.elements[1] ||
146
161
  m.value.elements[0].type !== 'FunctionExpression' ||
147
162
  m.value.elements[1].type !== 'ObjectExpression') {
148
163
  return false;
@@ -158,51 +173,60 @@ function handleWrappers(ast) {
158
173
  return false;
159
174
  }
160
175
  if (isUndefinedOrVoid(prop.value)) {
161
- if (prop.key.type === 'Identifier')
176
+ if (prop.key.type === 'Identifier') {
162
177
  externals[prop.key.name] = {
163
178
  type: 'Literal',
179
+ // @ts-ignore start can be undefined
164
180
  start: prop.key.start,
181
+ // @ts-ignore end can be undefined
165
182
  end: prop.key.end,
166
183
  value: prop.key.name,
167
184
  raw: JSON.stringify(prop.key.name)
168
185
  };
169
- else if (prop.key.type === 'Literal')
170
- externals[prop.key.value] = prop.key;
186
+ }
187
+ else if (prop.key.type === 'Literal') {
188
+ externals[String(prop.key.value)] = prop.key;
189
+ }
171
190
  }
172
191
  }
173
192
  return true;
174
193
  })) {
175
194
  // if we have externals, inline them into the browserify cache for webpack to pick up
176
195
  const externalIds = Object.keys(externals);
177
- if (externalIds.length) {
178
- const cache = (wrapper.arguments[0].body.body[1] || wrapper.arguments[0].body.body[0]).argument.callee.arguments[1];
179
- cache.properties = externalIds.map(ext => {
180
- return {
181
- type: 'Property',
182
- kind: 'init',
183
- key: externals[ext],
184
- value: {
185
- type: 'ObjectExpression',
186
- properties: [{
187
- type: 'Property',
188
- kind: 'init',
189
- key: {
196
+ const cache = browserifyReturn.argument.callee.arguments[1];
197
+ cache.properties = externalIds.map(ext => {
198
+ return {
199
+ type: 'Property',
200
+ method: false,
201
+ shorthand: false,
202
+ computed: false,
203
+ kind: 'init',
204
+ key: externals[ext],
205
+ value: {
206
+ type: 'ObjectExpression',
207
+ properties: [{
208
+ type: 'Property',
209
+ kind: 'init',
210
+ method: false,
211
+ shorthand: false,
212
+ computed: false,
213
+ key: {
214
+ type: 'Identifier',
215
+ name: 'exports'
216
+ },
217
+ value: {
218
+ type: 'CallExpression',
219
+ optional: false,
220
+ callee: {
190
221
  type: 'Identifier',
191
- name: 'exports'
222
+ name: 'require'
192
223
  },
193
- value: {
194
- type: 'CallExpression',
195
- callee: {
196
- type: 'Identifier',
197
- name: 'require'
198
- },
199
- arguments: [externals[ext]]
200
- }
201
- }]
202
- }
203
- };
204
- });
205
- }
224
+ arguments: [externals[ext]]
225
+ }
226
+ }]
227
+ }
228
+ };
229
+ });
206
230
  }
207
231
  }
208
232
  // UMD wrapper
@@ -233,6 +257,9 @@ function handleWrappers(ast) {
233
257
  wrapper.arguments[0].params.length === 2 &&
234
258
  wrapper.arguments[0].params[0].type === 'Identifier' &&
235
259
  wrapper.arguments[0].params[1].type === 'Identifier' &&
260
+ 'body' in wrapper.callee &&
261
+ 'body' in wrapper.callee.body &&
262
+ Array.isArray(wrapper.callee.body.body) &&
236
263
  wrapper.callee.body.body.length === 1) {
237
264
  const statement = wrapper.callee.body.body[0];
238
265
  if (statement.type === 'IfStatement' &&
@@ -272,16 +299,24 @@ function handleWrappers(ast) {
272
299
  callSite = statement.consequent.body[0].expression.right;
273
300
  if (callSite &&
274
301
  callSite.callee.type === 'Identifier' &&
302
+ 'params' in wrapper.callee &&
275
303
  wrapper.callee.params.length > 0 &&
304
+ 'name' in wrapper.callee.params[0] &&
276
305
  callSite.callee.name === wrapper.callee.params[0].name &&
277
306
  callSite.arguments.length === 2 &&
278
307
  callSite.arguments[0].type === 'Identifier' &&
279
308
  callSite.arguments[0].name === 'require' &&
280
309
  callSite.arguments[1].type === 'Identifier' &&
281
310
  callSite.arguments[1].name === 'exports') {
282
- delete wrapper.arguments[0].scope.declarations.require;
283
- delete wrapper.arguments[0].scope.declarations.exports;
284
- wrapper.arguments[0].params = [];
311
+ const funcExpression = wrapper.arguments[0];
312
+ funcExpression.params = [];
313
+ try {
314
+ // @ts-ignore If scope doesn't exist thats ok
315
+ const scope = funcExpression.scope;
316
+ delete scope.declarations.require;
317
+ delete scope.declarations.exports;
318
+ }
319
+ catch (e) { }
285
320
  }
286
321
  }
287
322
  }
@@ -345,12 +380,14 @@ function handleWrappers(ast) {
345
380
  wrapper.callee.body.body[2].type === 'FunctionDeclaration' &&
346
381
  wrapper.callee.body.body[2].params.length === 1 &&
347
382
  wrapper.callee.body.body[2].body.body.length >= 3) && (wrapper.arguments[0] && (wrapper.arguments[0].type === 'ArrayExpression' &&
383
+ (webpackModuleObj = wrapper.arguments[0]) &&
348
384
  wrapper.arguments[0].elements.length > 0 &&
349
- wrapper.arguments[0].elements.every((el) => el && el.type === 'FunctionExpression') ||
385
+ wrapper.arguments[0].elements.every(el => el && el.type === 'FunctionExpression') ||
350
386
  wrapper.arguments[0].type === 'ObjectExpression' &&
387
+ (webpackModuleObj = wrapper.arguments[0]) &&
351
388
  wrapper.arguments[0].properties &&
352
389
  wrapper.arguments[0].properties.length > 0 &&
353
- wrapper.arguments[0].properties.every((prop) => prop && prop.key && prop.key.type === 'Literal' && prop.value && prop.value.type === 'FunctionExpression'))) ||
390
+ wrapper.arguments[0].properties.every(prop => prop && prop.type === 'Property' && !prop.computed && prop.key && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number') && prop.value && prop.value.type === 'FunctionExpression'))) ||
354
391
  wrapper.arguments.length === 0 &&
355
392
  wrapper.callee.type === 'FunctionExpression' &&
356
393
  wrapper.callee.params.length === 0 &&
@@ -371,23 +408,27 @@ function handleWrappers(ast) {
371
408
  wrapper.callee.body.body[3].expression.left.property.type === 'Identifier' &&
372
409
  wrapper.callee.body.body[3].expression.left.property.name === 'modules' &&
373
410
  wrapper.callee.body.body[3].expression.right.type === 'ObjectExpression' &&
411
+ wrapper.callee.body.body[3].expression.right.properties.every(prop => prop && prop.type === 'Property' && !prop.computed && prop.key && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number') && prop.value && prop.value.type === 'FunctionExpression') &&
412
+ (webpackModuleObj = wrapper.callee.body.body[3].expression.right) &&
374
413
  (wrapper.callee.body.body[4].type === 'VariableDeclaration' &&
375
414
  wrapper.callee.body.body[4].declarations.length === 1 &&
415
+ wrapper.callee.body.body[4].declarations[0].init &&
376
416
  wrapper.callee.body.body[4].declarations[0].init.type === 'CallExpression' &&
377
417
  wrapper.callee.body.body[4].declarations[0].init.callee.type === 'Identifier' &&
378
418
  wrapper.callee.body.body[4].declarations[0].init.callee.name === 'require' ||
379
419
  wrapper.callee.body.body[5].type === 'VariableDeclaration' &&
380
420
  wrapper.callee.body.body[5].declarations.length === 1 &&
421
+ wrapper.callee.body.body[5].declarations[0].init &&
381
422
  wrapper.callee.body.body[5].declarations[0].init.type === 'CallExpression' &&
382
423
  wrapper.callee.body.body[5].declarations[0].init.callee.type === 'Identifier' &&
383
424
  wrapper.callee.body.body[5].declarations[0].init.callee.name === 'require')) {
384
425
  const externalMap = new Map();
385
- const moduleObj = wrapper.callee.params.length ? wrapper.arguments[0] : wrapper.callee.body.body[3].expression.right;
386
426
  let modules;
387
- if (moduleObj.type === 'ArrayExpression')
388
- modules = moduleObj.elements.map((el, i) => [i, el]);
427
+ if (webpackModuleObj.type === 'ArrayExpression')
428
+ modules = webpackModuleObj.elements.filter(el => (el === null || el === void 0 ? void 0 : el.type) === 'FunctionExpression').map((el, i) => [String(i), el]);
429
+ // Structure already checked in conditional above
389
430
  else
390
- modules = moduleObj.properties.map((prop) => [prop.key.value, prop.value]);
431
+ modules = webpackModuleObj.properties.map(prop => [String(prop.key.value), prop.value]);
391
432
  for (const [k, m] of modules) {
392
433
  const statement = m.body.body.length === 1 ? m.body.body[0] :
393
434
  (m.body.body.length === 2 || m.body.body.length === 3 && m.body.body[2].type === 'EmptyStatement') &&
@@ -401,7 +442,9 @@ function handleWrappers(ast) {
401
442
  statement.expression.operator === '=' &&
402
443
  statement.expression.left.type === 'MemberExpression' &&
403
444
  statement.expression.left.object.type === 'Identifier' &&
445
+ 'params' in m &&
404
446
  m.params.length > 0 &&
447
+ 'name' in m.params[0] &&
405
448
  statement.expression.left.object.name === m.params[0].name &&
406
449
  statement.expression.left.property.type === 'Identifier' &&
407
450
  statement.expression.left.property.name === 'exports' &&
@@ -414,19 +457,23 @@ function handleWrappers(ast) {
414
457
  }
415
458
  }
416
459
  for (const [, m] of modules) {
417
- if (m.params.length === 3 && m.params[2].type === 'Identifier') {
460
+ if ('params' in m && m.params.length === 3 && m.params[2].type === 'Identifier') {
418
461
  const assignedVars = new Map();
419
462
  estree_walker_1.walk(m.body, {
420
- enter(node, maybeParent) {
463
+ enter(_node, _maybeParent) {
464
+ const node = _node;
465
+ const maybeParent = _maybeParent;
421
466
  if (node.type === 'CallExpression' &&
422
467
  node.callee.type === 'Identifier' &&
468
+ 'name' in m.params[2] &&
423
469
  node.callee.name === m.params[2].name &&
424
470
  node.arguments.length === 1 &&
425
471
  node.arguments[0].type === 'Literal') {
426
- const externalId = externalMap.get(node.arguments[0].value);
472
+ const externalId = externalMap.get(String(node.arguments[0].value));
427
473
  if (externalId) {
428
474
  const replacement = {
429
475
  type: 'CallExpression',
476
+ optional: false,
430
477
  callee: {
431
478
  type: 'Identifier',
432
479
  name: 'require'
@@ -437,22 +484,22 @@ function handleWrappers(ast) {
437
484
  }]
438
485
  };
439
486
  const parent = maybeParent;
440
- if (parent.right === node) {
487
+ if ('right' in parent && parent.right === node) {
441
488
  parent.right = replacement;
442
489
  }
443
- else if (parent.left === node) {
490
+ else if ('left' in parent && parent.left === node) {
444
491
  parent.left = replacement;
445
492
  }
446
- else if (parent.object === node) {
493
+ else if ('object' in parent && parent.object === node) {
447
494
  parent.object = replacement;
448
495
  }
449
- else if (parent.callee === node) {
496
+ else if ('callee' in parent && parent.callee === node) {
450
497
  parent.callee = replacement;
451
498
  }
452
- else if (parent.arguments && parent.arguments.some((arg) => arg === node)) {
453
- parent.arguments = parent.arguments.map((arg) => arg === node ? replacement : arg);
499
+ else if ('arguments' in parent && parent.arguments.some(arg => arg === node)) {
500
+ parent.arguments = parent.arguments.map(arg => arg === node ? replacement : arg);
454
501
  }
455
- else if (parent.init === node) {
502
+ else if ('init' in parent && parent.init === node) {
456
503
  if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier')
457
504
  assignedVars.set(parent.id.name, externalId);
458
505
  parent.init = replacement;
@@ -462,17 +509,21 @@ function handleWrappers(ast) {
462
509
  else if (node.type === 'CallExpression' &&
463
510
  node.callee.type === 'MemberExpression' &&
464
511
  node.callee.object.type === 'Identifier' &&
512
+ 'name' in m.params[2] &&
465
513
  node.callee.object.name === m.params[2].name &&
466
514
  node.callee.property.type === 'Identifier' &&
467
515
  node.callee.property.name === 'n' &&
468
516
  node.arguments.length === 1 &&
469
517
  node.arguments[0].type === 'Identifier') {
470
- if (maybeParent && maybeParent.init === node) {
518
+ if (maybeParent && 'init' in maybeParent && maybeParent.init === node) {
471
519
  const req = node.arguments[0];
472
- maybeParent.init = {
520
+ const callExpression = {
473
521
  type: 'CallExpression',
522
+ optional: false,
474
523
  callee: {
475
524
  type: 'MemberExpression',
525
+ computed: false,
526
+ optional: false,
476
527
  object: {
477
528
  type: 'Identifier',
478
529
  name: 'Object'
@@ -492,7 +543,8 @@ function handleWrappers(ast) {
492
543
  {
493
544
  type: 'ObjectExpression',
494
545
  properties: [{
495
- type: 'ObjectProperty',
546
+ type: 'Property',
547
+ kind: 'init',
496
548
  method: false,
497
549
  computed: false,
498
550
  shorthand: false,
@@ -505,6 +557,7 @@ function handleWrappers(ast) {
505
557
  }
506
558
  ]
507
559
  };
560
+ maybeParent.init = callExpression;
508
561
  }
509
562
  }
510
563
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/nft",
3
- "version": "0.12.1",
3
+ "version": "0.14.0",
4
4
  "repository": "vercel/nft",
5
5
  "license": "MIT",
6
6
  "main": "./out/index.js",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "scripts": {
12
12
  "build": "tsc",
13
- "prepublishOnly": "tsc && rm out/tsconfig.tsbuildinfo",
13
+ "prepublishOnly": "tsc && rm out/utils/*.d.ts && rm out/tsconfig.tsbuildinfo",
14
14
  "test": "jest --verbose",
15
15
  "test-verbose": "tsc --sourceMap && jest --verbose --coverage --globals \"{\\\"coverage\\\":true}\"",
16
16
  "codecov": "codecov"
@@ -20,8 +20,9 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@mapbox/node-pre-gyp": "^1.0.5",
23
- "acorn": "^8.1.0",
23
+ "acorn": "^8.3.0",
24
24
  "acorn-class-fields": "^1.0.0",
25
+ "acorn-private-class-elements": "^1.0.0",
25
26
  "acorn-static-class-features": "^1.0.0",
26
27
  "bindings": "^1.4.0",
27
28
  "estree-walker": "^0.6.1",
@@ -44,6 +45,7 @@
44
45
  "@tensorflow/tfjs-node": "^3.6.1",
45
46
  "@tpluscode/sparql-builder": "^0.3.12",
46
47
  "@types/bindings": "^1.3.0",
48
+ "@types/estree": "^0.0.47",
47
49
  "@types/glob": "^7.1.2",
48
50
  "@types/micromatch": "^4.0.1",
49
51
  "@types/node": "^14.14.37",
@@ -76,7 +78,7 @@
76
78
  "hot-shots": "^6.3.0",
77
79
  "ioredis": "^4.11.1",
78
80
  "isomorphic-unfetch": "^3.0.0",
79
- "jest": "^26.6.3",
81
+ "jest": "^27.0.4",
80
82
  "jimp": "^0.6.4",
81
83
  "jugglingdb": "^2.0.1",
82
84
  "koa": "^2.7.0",
@@ -99,11 +101,15 @@
99
101
  "pdfkit": "^0.10.0",
100
102
  "pg": "^7.11.0",
101
103
  "phantomjs-prebuilt": "^2.1.16",
104
+ "playwright-core": "^1.11.1",
102
105
  "polyfill-library": "3.93.0",
106
+ "prismjs": "^1.24.1",
103
107
  "pug": "^3.0.1",
104
108
  "react": "^16.8.6",
105
109
  "react-dom": "^16.8.6",
106
110
  "redis": "^3.1.1",
111
+ "remark-parse": "^10.0.0",
112
+ "remark-prism": "^1.3.6",
107
113
  "rxjs": "^6.5.2",
108
114
  "saslprep": "^1.0.3",
109
115
  "semver": "^7.1.1",
@@ -117,6 +123,7 @@
117
123
  "twilio": "^3.33.0",
118
124
  "typescript": "^3.9.6",
119
125
  "uglify-js": "^3.6.0",
126
+ "unified": "^10.1.0",
120
127
  "vm2": "^3.8.2",
121
128
  "vue": "^2.6.10",
122
129
  "vue-server-renderer": "^2.6.10",
@@ -1,4 +0,0 @@
1
- import { Node } from 'estree-walker';
2
- export declare function isIdentifierRead(node: Node, parent: Node): any;
3
- export declare function isVarLoop(node: Node): boolean;
4
- export declare function isLoop(node: Node): boolean;
@@ -1,14 +0,0 @@
1
- export declare const pregyp: {
2
- default: {
3
- find: (package_json_path: string, opts: any) => any;
4
- };
5
- find: (package_json_path: string, opts: any) => any;
6
- };
7
- declare type Spec = {
8
- ext: string;
9
- name: string;
10
- type: string;
11
- path?: string;
12
- };
13
- export declare function nbind(basePath?: string): Spec | null;
14
- export {};
@@ -1,2 +0,0 @@
1
- export declare function getPackageBase(id: string): string | undefined;
2
- export declare function getPackageName(id: string): string | undefined;
@@ -1,2 +0,0 @@
1
- export declare function normalizeDefaultRequire(obj: any): any;
2
- export declare function normalizeWildcardRequire(obj: any): any;
@@ -1,2 +0,0 @@
1
- import { Job } from '../node-file-trace';
2
- export declare function sharedLibEmit(path: string, job: Job): Promise<void>;
@@ -1,11 +0,0 @@
1
- import { Job } from '../node-file-trace';
2
- import { Node } from 'estree-walker';
3
- interface SpecialCaseOpts {
4
- id: string;
5
- ast: Node;
6
- emitAsset: (filename: string) => void;
7
- emitAssetDirectory: (dirname: string) => void;
8
- job: Job;
9
- }
10
- export default function handleSpecialCases({ id, ast, emitAsset, emitAssetDirectory, job }: SpecialCaseOpts): void;
11
- export {};
@@ -1,7 +0,0 @@
1
- import { Node } from 'estree-walker';
2
- import { EvaluatedValue } from '../types';
3
- export declare function evaluate(ast: Node, vars?: {}, computeBranches?: boolean): EvaluatedValue;
4
- export declare const UNKNOWN: unique symbol;
5
- export declare const FUNCTION: unique symbol;
6
- export declare const WILDCARD = "\u001A";
7
- export declare const wildcardRegEx: RegExp;
@@ -1,2 +0,0 @@
1
- import { Node } from 'estree-walker';
2
- export declare function handleWrappers(ast: Node): void;