@vercel/node 2.6.4 → 2.7.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/dist/index.js CHANGED
@@ -305253,6 +305253,10 @@ function cachedLookup(fn) {
305253
305253
  return cache.get(arg);
305254
305254
  };
305255
305255
  }
305256
+ /**
305257
+ * Maps the config path to a build func
305258
+ */
305259
+ const configFileToBuildMap = new Map();
305256
305260
  /**
305257
305261
  * Register TypeScript compiler.
305258
305262
  */
@@ -305313,17 +305317,21 @@ function register(opts = {}) {
305313
305317
  console.error('\x1b[31m%s\x1b[0m', error);
305314
305318
  }
305315
305319
  }
305316
- // we create a custom build per tsconfig.json instance
305317
- const builds = new Map();
305318
- function getBuild(configFileName = '') {
305319
- let build = builds.get(configFileName);
305320
- if (build)
305321
- return build;
305320
+ function getBuild(configFileName = '', skipTypeCheck) {
305321
+ const cachedGetOutput = configFileToBuildMap.get(configFileName);
305322
+ if (cachedGetOutput) {
305323
+ return cachedGetOutput;
305324
+ }
305325
+ const outFiles = new Map();
305322
305326
  const config = readConfig(configFileName);
305323
305327
  /**
305324
- * Create the basic required function using transpile mode.
305328
+ * Create the basic function for transpile only (ts-node --transpileOnly)
305325
305329
  */
305326
- const getOutput = function (code, fileName) {
305330
+ const getOutputTranspile = (code, fileName) => {
305331
+ const outFile = outFiles.get(fileName);
305332
+ if (outFile) {
305333
+ return outFile;
305334
+ }
305327
305335
  const result = ts.transpileModule(code, {
305328
305336
  fileName,
305329
305337
  transformers,
@@ -305334,86 +305342,94 @@ function register(opts = {}) {
305334
305342
  ? filterDiagnostics(result.diagnostics, ignoreDiagnostics)
305335
305343
  : [];
305336
305344
  reportTSError(diagnosticList, config.options.noEmitOnError);
305337
- return { code: result.outputText, map: result.sourceMapText };
305338
- };
305339
- // Use full language services when the fast option is disabled.
305340
- let getOutputTypeCheck;
305341
- {
305342
- const memoryCache = new MemoryCache(config.fileNames);
305343
- const cachedReadFile = cachedLookup(debugFn('readFile', readFile));
305344
- // Create the compiler host for type checking.
305345
- const serviceHost = {
305346
- getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
305347
- getScriptVersion: (fileName) => {
305348
- const version = memoryCache.fileVersions.get(fileName);
305349
- return version === undefined ? '' : version.toString();
305350
- },
305351
- getScriptSnapshot(fileName) {
305352
- let contents = memoryCache.fileContents.get(fileName);
305353
- // Read contents into TypeScript memory cache.
305354
- if (contents === undefined) {
305355
- contents = cachedReadFile(fileName);
305356
- if (contents === undefined)
305357
- return;
305358
- memoryCache.fileVersions.set(fileName, 1);
305359
- memoryCache.fileContents.set(fileName, contents);
305360
- }
305361
- return ts.ScriptSnapshot.fromString(contents);
305362
- },
305363
- readFile: cachedReadFile,
305364
- readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
305365
- getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
305366
- fileExists: cachedLookup(debugFn('fileExists', fileExists)),
305367
- directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
305368
- getNewLine: () => ts.sys.newLine,
305369
- useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
305370
- getCurrentDirectory: () => cwd,
305371
- getCompilationSettings: () => config.options,
305372
- getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
305373
- getCustomTransformers: () => transformers,
305374
- };
305375
- const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
305376
- const service = ts.createLanguageService(serviceHost, registry);
305377
- // Set the file contents into cache manually.
305378
- const updateMemoryCache = function (contents, fileName) {
305379
- const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
305380
- // Avoid incrementing cache when nothing has changed.
305381
- if (memoryCache.fileContents.get(fileName) === contents)
305382
- return;
305383
- memoryCache.fileVersions.set(fileName, fileVersion + 1);
305384
- memoryCache.fileContents.set(fileName, contents);
305345
+ const file = {
305346
+ code: result.outputText,
305347
+ map: result.sourceMapText,
305385
305348
  };
305386
- getOutputTypeCheck = function (code, fileName) {
305387
- updateMemoryCache(code, fileName);
305388
- const output = service.getEmitOutput(fileName);
305389
- // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
305390
- const diagnostics = service
305391
- .getSemanticDiagnostics(fileName)
305392
- .concat(service.getSyntacticDiagnostics(fileName));
305393
- const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
305394
- reportTSError(diagnosticList, config.options.noEmitOnError);
305395
- if (output.emitSkipped) {
305396
- throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
305397
- }
305398
- // Throw an error when requiring `.d.ts` files.
305399
- if (output.outputFiles.length === 0) {
305400
- throw new TypeError('Unable to require `.d.ts` file.\n' +
305401
- 'This is usually the result of a faulty configuration or import. ' +
305402
- 'Make sure there is a `.js`, `.json` or another executable extension and ' +
305403
- 'loader (attached before `ts-node`) available alongside ' +
305404
- `\`${path_1.basename(fileName)}\`.`);
305349
+ outFiles.set(fileName, file);
305350
+ return file;
305351
+ };
305352
+ const memoryCache = new MemoryCache(config.fileNames);
305353
+ const cachedReadFile = cachedLookup(readFile);
305354
+ // Create the compiler host for type checking.
305355
+ const serviceHost = {
305356
+ getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
305357
+ getScriptVersion: (fileName) => {
305358
+ const version = memoryCache.fileVersions.get(fileName);
305359
+ return version === undefined ? '' : version.toString();
305360
+ },
305361
+ getScriptSnapshot(fileName) {
305362
+ let contents = memoryCache.fileContents.get(fileName);
305363
+ // Read contents into TypeScript memory cache.
305364
+ if (contents === undefined) {
305365
+ contents = cachedReadFile(fileName);
305366
+ if (contents === undefined)
305367
+ return;
305368
+ memoryCache.fileVersions.set(fileName, 1);
305369
+ memoryCache.fileContents.set(fileName, contents);
305405
305370
  }
305406
- return {
305407
- code: output.outputFiles[1].text,
305408
- map: output.outputFiles[0].text,
305409
- };
305371
+ return ts.ScriptSnapshot.fromString(contents);
305372
+ },
305373
+ readFile: cachedReadFile,
305374
+ readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
305375
+ getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
305376
+ fileExists: cachedLookup(debugFn('fileExists', fileExists)),
305377
+ directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
305378
+ getNewLine: () => ts.sys.newLine,
305379
+ useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
305380
+ getCurrentDirectory: () => cwd,
305381
+ getCompilationSettings: () => config.options,
305382
+ getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
305383
+ getCustomTransformers: () => transformers,
305384
+ };
305385
+ const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
305386
+ const service = ts.createLanguageService(serviceHost, registry);
305387
+ // Set the file contents into cache manually.
305388
+ const updateMemoryCache = function (contents, fileName) {
305389
+ const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
305390
+ // Avoid incrementing cache when nothing has changed.
305391
+ if (memoryCache.fileContents.get(fileName) === contents)
305392
+ return;
305393
+ memoryCache.fileVersions.set(fileName, fileVersion + 1);
305394
+ memoryCache.fileContents.set(fileName, contents);
305395
+ };
305396
+ /**
305397
+ * Create complete function with full language services (normal behavior for `tsc`)
305398
+ */
305399
+ const getOutputTypeCheck = (code, fileName) => {
305400
+ const outFile = outFiles.get(fileName);
305401
+ if (outFile) {
305402
+ return outFile;
305403
+ }
305404
+ updateMemoryCache(code, fileName);
305405
+ const output = service.getEmitOutput(fileName);
305406
+ // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
305407
+ const diagnostics = service
305408
+ .getSemanticDiagnostics(fileName)
305409
+ .concat(service.getSyntacticDiagnostics(fileName));
305410
+ const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
305411
+ reportTSError(diagnosticList, config.options.noEmitOnError);
305412
+ if (output.emitSkipped) {
305413
+ throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
305414
+ }
305415
+ // Throw an error when requiring `.d.ts` files.
305416
+ if (output.outputFiles.length === 0) {
305417
+ throw new TypeError('Unable to require `.d.ts` file.\n' +
305418
+ 'This is usually the result of a faulty configuration or import. ' +
305419
+ 'Make sure there is a `.js`, `.json` or another executable extension and ' +
305420
+ 'loader (attached before `ts-node`) available alongside ' +
305421
+ `\`${path_1.basename(fileName)}\`.`);
305422
+ }
305423
+ const file = {
305424
+ code: output.outputFiles[1].text,
305425
+ map: output.outputFiles[0].text,
305410
305426
  };
305411
- }
305412
- builds.set(configFileName, (build = {
305413
- getOutput,
305414
- getOutputTypeCheck,
305415
- }));
305416
- return build;
305427
+ outFiles.set(fileName, file);
305428
+ return file;
305429
+ };
305430
+ const getOutput = skipTypeCheck ? getOutputTranspile : getOutputTypeCheck;
305431
+ configFileToBuildMap.set(configFileName, getOutput);
305432
+ return getOutput;
305417
305433
  }
305418
305434
  // determine the tsconfig.json path for a given folder
305419
305435
  function detectConfig() {
@@ -305467,8 +305483,8 @@ function register(opts = {}) {
305467
305483
  // Create a simple TypeScript compiler proxy.
305468
305484
  function compile(code, fileName, skipTypeCheck) {
305469
305485
  const configFileName = detectConfig();
305470
- const build = getBuild(configFileName);
305471
- const { code: value, map: sourceMap } = (skipTypeCheck ? build.getOutput : build.getOutputTypeCheck)(code, fileName);
305486
+ const buildOutput = getBuild(configFileName, skipTypeCheck);
305487
+ const { code: value, map: sourceMap } = buildOutput(code, fileName);
305472
305488
  const output = {
305473
305489
  code: value,
305474
305490
  map: Object.assign(JSON.parse(sourceMap), {
@@ -77,6 +77,10 @@ function cachedLookup(fn) {
77
77
  return cache.get(arg);
78
78
  };
79
79
  }
80
+ /**
81
+ * Maps the config path to a build func
82
+ */
83
+ const configFileToBuildMap = new Map();
80
84
  /**
81
85
  * Register TypeScript compiler.
82
86
  */
@@ -137,17 +141,21 @@ function register(opts = {}) {
137
141
  console.error('\x1b[31m%s\x1b[0m', error);
138
142
  }
139
143
  }
140
- // we create a custom build per tsconfig.json instance
141
- const builds = new Map();
142
- function getBuild(configFileName = '') {
143
- let build = builds.get(configFileName);
144
- if (build)
145
- return build;
144
+ function getBuild(configFileName = '', skipTypeCheck) {
145
+ const cachedGetOutput = configFileToBuildMap.get(configFileName);
146
+ if (cachedGetOutput) {
147
+ return cachedGetOutput;
148
+ }
149
+ const outFiles = new Map();
146
150
  const config = readConfig(configFileName);
147
151
  /**
148
- * Create the basic required function using transpile mode.
152
+ * Create the basic function for transpile only (ts-node --transpileOnly)
149
153
  */
150
- const getOutput = function (code, fileName) {
154
+ const getOutputTranspile = (code, fileName) => {
155
+ const outFile = outFiles.get(fileName);
156
+ if (outFile) {
157
+ return outFile;
158
+ }
151
159
  const result = ts.transpileModule(code, {
152
160
  fileName,
153
161
  transformers,
@@ -158,86 +166,94 @@ function register(opts = {}) {
158
166
  ? filterDiagnostics(result.diagnostics, ignoreDiagnostics)
159
167
  : [];
160
168
  reportTSError(diagnosticList, config.options.noEmitOnError);
161
- return { code: result.outputText, map: result.sourceMapText };
162
- };
163
- // Use full language services when the fast option is disabled.
164
- let getOutputTypeCheck;
165
- {
166
- const memoryCache = new MemoryCache(config.fileNames);
167
- const cachedReadFile = cachedLookup(debugFn('readFile', readFile));
168
- // Create the compiler host for type checking.
169
- const serviceHost = {
170
- getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
171
- getScriptVersion: (fileName) => {
172
- const version = memoryCache.fileVersions.get(fileName);
173
- return version === undefined ? '' : version.toString();
174
- },
175
- getScriptSnapshot(fileName) {
176
- let contents = memoryCache.fileContents.get(fileName);
177
- // Read contents into TypeScript memory cache.
178
- if (contents === undefined) {
179
- contents = cachedReadFile(fileName);
180
- if (contents === undefined)
181
- return;
182
- memoryCache.fileVersions.set(fileName, 1);
183
- memoryCache.fileContents.set(fileName, contents);
184
- }
185
- return ts.ScriptSnapshot.fromString(contents);
186
- },
187
- readFile: cachedReadFile,
188
- readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
189
- getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
190
- fileExists: cachedLookup(debugFn('fileExists', fileExists)),
191
- directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
192
- getNewLine: () => ts.sys.newLine,
193
- useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
194
- getCurrentDirectory: () => cwd,
195
- getCompilationSettings: () => config.options,
196
- getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
197
- getCustomTransformers: () => transformers,
169
+ const file = {
170
+ code: result.outputText,
171
+ map: result.sourceMapText,
198
172
  };
199
- const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
200
- const service = ts.createLanguageService(serviceHost, registry);
201
- // Set the file contents into cache manually.
202
- const updateMemoryCache = function (contents, fileName) {
203
- const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
204
- // Avoid incrementing cache when nothing has changed.
205
- if (memoryCache.fileContents.get(fileName) === contents)
206
- return;
207
- memoryCache.fileVersions.set(fileName, fileVersion + 1);
208
- memoryCache.fileContents.set(fileName, contents);
209
- };
210
- getOutputTypeCheck = function (code, fileName) {
211
- updateMemoryCache(code, fileName);
212
- const output = service.getEmitOutput(fileName);
213
- // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
214
- const diagnostics = service
215
- .getSemanticDiagnostics(fileName)
216
- .concat(service.getSyntacticDiagnostics(fileName));
217
- const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
218
- reportTSError(diagnosticList, config.options.noEmitOnError);
219
- if (output.emitSkipped) {
220
- throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
221
- }
222
- // Throw an error when requiring `.d.ts` files.
223
- if (output.outputFiles.length === 0) {
224
- throw new TypeError('Unable to require `.d.ts` file.\n' +
225
- 'This is usually the result of a faulty configuration or import. ' +
226
- 'Make sure there is a `.js`, `.json` or another executable extension and ' +
227
- 'loader (attached before `ts-node`) available alongside ' +
228
- `\`${path_1.basename(fileName)}\`.`);
173
+ outFiles.set(fileName, file);
174
+ return file;
175
+ };
176
+ const memoryCache = new MemoryCache(config.fileNames);
177
+ const cachedReadFile = cachedLookup(readFile);
178
+ // Create the compiler host for type checking.
179
+ const serviceHost = {
180
+ getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
181
+ getScriptVersion: (fileName) => {
182
+ const version = memoryCache.fileVersions.get(fileName);
183
+ return version === undefined ? '' : version.toString();
184
+ },
185
+ getScriptSnapshot(fileName) {
186
+ let contents = memoryCache.fileContents.get(fileName);
187
+ // Read contents into TypeScript memory cache.
188
+ if (contents === undefined) {
189
+ contents = cachedReadFile(fileName);
190
+ if (contents === undefined)
191
+ return;
192
+ memoryCache.fileVersions.set(fileName, 1);
193
+ memoryCache.fileContents.set(fileName, contents);
229
194
  }
230
- return {
231
- code: output.outputFiles[1].text,
232
- map: output.outputFiles[0].text,
233
- };
195
+ return ts.ScriptSnapshot.fromString(contents);
196
+ },
197
+ readFile: cachedReadFile,
198
+ readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
199
+ getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
200
+ fileExists: cachedLookup(debugFn('fileExists', fileExists)),
201
+ directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
202
+ getNewLine: () => ts.sys.newLine,
203
+ useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
204
+ getCurrentDirectory: () => cwd,
205
+ getCompilationSettings: () => config.options,
206
+ getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
207
+ getCustomTransformers: () => transformers,
208
+ };
209
+ const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
210
+ const service = ts.createLanguageService(serviceHost, registry);
211
+ // Set the file contents into cache manually.
212
+ const updateMemoryCache = function (contents, fileName) {
213
+ const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
214
+ // Avoid incrementing cache when nothing has changed.
215
+ if (memoryCache.fileContents.get(fileName) === contents)
216
+ return;
217
+ memoryCache.fileVersions.set(fileName, fileVersion + 1);
218
+ memoryCache.fileContents.set(fileName, contents);
219
+ };
220
+ /**
221
+ * Create complete function with full language services (normal behavior for `tsc`)
222
+ */
223
+ const getOutputTypeCheck = (code, fileName) => {
224
+ const outFile = outFiles.get(fileName);
225
+ if (outFile) {
226
+ return outFile;
227
+ }
228
+ updateMemoryCache(code, fileName);
229
+ const output = service.getEmitOutput(fileName);
230
+ // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
231
+ const diagnostics = service
232
+ .getSemanticDiagnostics(fileName)
233
+ .concat(service.getSyntacticDiagnostics(fileName));
234
+ const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
235
+ reportTSError(diagnosticList, config.options.noEmitOnError);
236
+ if (output.emitSkipped) {
237
+ throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
238
+ }
239
+ // Throw an error when requiring `.d.ts` files.
240
+ if (output.outputFiles.length === 0) {
241
+ throw new TypeError('Unable to require `.d.ts` file.\n' +
242
+ 'This is usually the result of a faulty configuration or import. ' +
243
+ 'Make sure there is a `.js`, `.json` or another executable extension and ' +
244
+ 'loader (attached before `ts-node`) available alongside ' +
245
+ `\`${path_1.basename(fileName)}\`.`);
246
+ }
247
+ const file = {
248
+ code: output.outputFiles[1].text,
249
+ map: output.outputFiles[0].text,
234
250
  };
235
- }
236
- builds.set(configFileName, (build = {
237
- getOutput,
238
- getOutputTypeCheck,
239
- }));
240
- return build;
251
+ outFiles.set(fileName, file);
252
+ return file;
253
+ };
254
+ const getOutput = skipTypeCheck ? getOutputTranspile : getOutputTypeCheck;
255
+ configFileToBuildMap.set(configFileName, getOutput);
256
+ return getOutput;
241
257
  }
242
258
  // determine the tsconfig.json path for a given folder
243
259
  function detectConfig() {
@@ -291,8 +307,8 @@ function register(opts = {}) {
291
307
  // Create a simple TypeScript compiler proxy.
292
308
  function compile(code, fileName, skipTypeCheck) {
293
309
  const configFileName = detectConfig();
294
- const build = getBuild(configFileName);
295
- const { code: value, map: sourceMap } = (skipTypeCheck ? build.getOutput : build.getOutputTypeCheck)(code, fileName);
310
+ const buildOutput = getBuild(configFileName, skipTypeCheck);
311
+ const { code: value, map: sourceMap } = buildOutput(code, fileName);
296
312
  const output = {
297
313
  code: value,
298
314
  map: Object.assign(JSON.parse(sourceMap), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "2.6.4",
3
+ "version": "2.7.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@edge-runtime/vm": "2.0.0",
33
33
  "@types/node": "14.18.33",
34
- "@vercel/build-utils": "5.5.9",
34
+ "@vercel/build-utils": "5.7.0",
35
35
  "@vercel/node-bridge": "3.1.2",
36
36
  "@vercel/static-config": "2.0.6",
37
37
  "edge-runtime": "2.0.0",
@@ -61,5 +61,5 @@
61
61
  "source-map-support": "0.5.12",
62
62
  "test-listen": "1.1.0"
63
63
  },
64
- "gitHead": "7003531d5db7895fc3b2fa940c2d83b6e75bbd9e"
64
+ "gitHead": "b37ac5f798acbfb8f04e047301766440ad0d4c59"
65
65
  }