@vercel/node 2.7.0 → 2.8.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.
@@ -71,13 +71,12 @@ function listen(server, port, host) {
71
71
  });
72
72
  });
73
73
  }
74
- const validRuntimes = ['experimental-edge'];
75
74
  function parseRuntime(entrypoint, entryPointPath) {
76
75
  const project = new ts_morph_1.Project();
77
76
  const staticConfig = static_config_1.getConfig(project, entryPointPath);
78
77
  const runtime = staticConfig?.runtime;
79
- if (runtime && !validRuntimes.includes(runtime)) {
80
- throw new Error(`Invalid function runtime "${runtime}" for "${entrypoint}". Valid runtimes are: ${JSON.stringify(validRuntimes)}. Learn more: https://vercel.link/creating-edge-functions`);
78
+ if (runtime && !utils_1.isEdgeRuntime(runtime)) {
79
+ throw new Error(`Invalid function runtime "${runtime}" for "${entrypoint}". Valid runtimes are: ${JSON.stringify(Object.values(utils_1.EdgeRuntimes))}. Learn more: https://vercel.link/creating-edge-functions`);
81
80
  }
82
81
  return runtime;
83
82
  }
@@ -86,8 +85,8 @@ async function createEventHandler(entrypoint, config, options) {
86
85
  const runtime = parseRuntime(entrypoint, entrypointPath);
87
86
  // `middleware.js`/`middleware.ts` file is always run as
88
87
  // an Edge Function, otherwise needs to be opted-in via
89
- // `export const config = { runtime: 'experimental-edge' }`
90
- if (config.middleware === true || runtime === 'experimental-edge') {
88
+ // `export const config = { runtime: 'edge' }`
89
+ if (config.middleware === true || utils_1.isEdgeRuntime(runtime)) {
91
90
  return edge_handler_1.createEdgeEventHandler(entrypointPath, entrypoint, config.middleware || false);
92
91
  }
93
92
  return serverless_handler_1.createServerlessEventHandler(entrypointPath, {
package/dist/index.js CHANGED
@@ -304740,7 +304740,7 @@ const utils_1 = __webpack_require__(84411);
304740
304740
  function isPortInfo(v) {
304741
304741
  return v && typeof v.port === 'number';
304742
304742
  }
304743
- const ALLOWED_RUNTIMES = ['nodejs', 'experimental-edge'];
304743
+ const ALLOWED_RUNTIMES = ['nodejs', ...Object.values(utils_1.EdgeRuntimes)];
304744
304744
  const require_ = eval('require');
304745
304745
  const tscPath = path_1.resolve(path_1.dirname(require_.resolve('typescript')), '../bin/tsc');
304746
304746
  // eslint-disable-next-line no-useless-escape
@@ -304975,7 +304975,7 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
304975
304975
  const isMiddleware = config.middleware === true;
304976
304976
  // Will output an `EdgeFunction` for when `config.middleware = true`
304977
304977
  // (i.e. for root-level "middleware" file) or if source code contains:
304978
- // `export const config = { runtime: 'experimental-edge' }`
304978
+ // `export const config = { runtime: 'edge' }`
304979
304979
  let isEdgeFunction = isMiddleware;
304980
304980
  const project = new ts_morph_1.Project();
304981
304981
  const staticConfig = static_config_1.getConfig(project, entrypointPath);
@@ -304983,7 +304983,7 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
304983
304983
  if (!ALLOWED_RUNTIMES.includes(staticConfig.runtime)) {
304984
304984
  throw new Error(`Unsupported "runtime" property in \`config\`: ${JSON.stringify(staticConfig.runtime)} (must be one of: ${JSON.stringify(ALLOWED_RUNTIMES)})`);
304985
304985
  }
304986
- isEdgeFunction = staticConfig.runtime === 'experimental-edge';
304986
+ isEdgeFunction = utils_1.isEdgeRuntime(staticConfig.runtime);
304987
304987
  }
304988
304988
  build_utils_1.debug('Tracing input files...');
304989
304989
  const traceTime = Date.now();
@@ -305317,15 +305317,21 @@ function register(opts = {}) {
305317
305317
  console.error('\x1b[31m%s\x1b[0m', error);
305318
305318
  }
305319
305319
  }
305320
- function getBuild(configFileName = '') {
305321
- let build = configFileToBuildMap.get(configFileName);
305322
- if (build)
305323
- 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();
305324
305326
  const config = readConfig(configFileName);
305325
305327
  /**
305326
- * Create the basic required function using transpile mode.
305328
+ * Create the basic function for transpile only (ts-node --transpileOnly)
305327
305329
  */
305328
- const getOutput = function (code, fileName) {
305330
+ const getOutputTranspile = (code, fileName) => {
305331
+ const outFile = outFiles.get(fileName);
305332
+ if (outFile) {
305333
+ return outFile;
305334
+ }
305329
305335
  const result = ts.transpileModule(code, {
305330
305336
  fileName,
305331
305337
  transformers,
@@ -305336,84 +305342,94 @@ function register(opts = {}) {
305336
305342
  ? filterDiagnostics(result.diagnostics, ignoreDiagnostics)
305337
305343
  : [];
305338
305344
  reportTSError(diagnosticList, config.options.noEmitOnError);
305339
- return { code: result.outputText, map: result.sourceMapText };
305340
- };
305341
- // Use full language services when the fast option is disabled.
305342
- let getOutputTypeCheck;
305343
- {
305344
- const memoryCache = new MemoryCache(config.fileNames);
305345
- const cachedReadFile = cachedLookup(debugFn('readFile', readFile));
305346
- // Create the compiler host for type checking.
305347
- const serviceHost = {
305348
- getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
305349
- getScriptVersion: (fileName) => {
305350
- const version = memoryCache.fileVersions.get(fileName);
305351
- return version === undefined ? '' : version.toString();
305352
- },
305353
- getScriptSnapshot(fileName) {
305354
- let contents = memoryCache.fileContents.get(fileName);
305355
- // Read contents into TypeScript memory cache.
305356
- if (contents === undefined) {
305357
- contents = cachedReadFile(fileName);
305358
- if (contents === undefined)
305359
- return;
305360
- memoryCache.fileVersions.set(fileName, 1);
305361
- memoryCache.fileContents.set(fileName, contents);
305362
- }
305363
- return ts.ScriptSnapshot.fromString(contents);
305364
- },
305365
- readFile: cachedReadFile,
305366
- readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
305367
- getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
305368
- fileExists: cachedLookup(debugFn('fileExists', fileExists)),
305369
- directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
305370
- getNewLine: () => ts.sys.newLine,
305371
- useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
305372
- getCurrentDirectory: () => cwd,
305373
- getCompilationSettings: () => config.options,
305374
- getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
305375
- getCustomTransformers: () => transformers,
305376
- };
305377
- const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
305378
- const service = ts.createLanguageService(serviceHost, registry);
305379
- // Set the file contents into cache manually.
305380
- const updateMemoryCache = function (contents, fileName) {
305381
- const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
305382
- // Avoid incrementing cache when nothing has changed.
305383
- if (memoryCache.fileContents.get(fileName) === contents)
305384
- return;
305385
- memoryCache.fileVersions.set(fileName, fileVersion + 1);
305386
- memoryCache.fileContents.set(fileName, contents);
305345
+ const file = {
305346
+ code: result.outputText,
305347
+ map: result.sourceMapText,
305387
305348
  };
305388
- getOutputTypeCheck = function (code, fileName) {
305389
- updateMemoryCache(code, fileName);
305390
- const output = service.getEmitOutput(fileName);
305391
- // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
305392
- const diagnostics = service
305393
- .getSemanticDiagnostics(fileName)
305394
- .concat(service.getSyntacticDiagnostics(fileName));
305395
- const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
305396
- reportTSError(diagnosticList, config.options.noEmitOnError);
305397
- if (output.emitSkipped) {
305398
- throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
305399
- }
305400
- // Throw an error when requiring `.d.ts` files.
305401
- if (output.outputFiles.length === 0) {
305402
- throw new TypeError('Unable to require `.d.ts` file.\n' +
305403
- 'This is usually the result of a faulty configuration or import. ' +
305404
- 'Make sure there is a `.js`, `.json` or another executable extension and ' +
305405
- 'loader (attached before `ts-node`) available alongside ' +
305406
- `\`${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);
305407
305370
  }
305408
- return {
305409
- code: output.outputFiles[1].text,
305410
- map: output.outputFiles[0].text,
305411
- };
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,
305412
305426
  };
305413
- }
305414
- build = { getOutput, getOutputTypeCheck };
305415
- configFileToBuildMap.set(configFileName, build);
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), {
@@ -305539,7 +305555,7 @@ function filterDiagnostics(diagnostics, ignore) {
305539
305555
  "use strict";
305540
305556
 
305541
305557
  Object.defineProperty(exports, "__esModule", ({ value: true }));
305542
- exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
305558
+ exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
305543
305559
  const path_1 = __webpack_require__(85622);
305544
305560
  const path_to_regexp_1 = __webpack_require__(91786);
305545
305561
  const build_utils_1 = __webpack_require__(63445);
@@ -305595,6 +305611,16 @@ function logError(error) {
305595
305611
  }
305596
305612
  }
305597
305613
  exports.logError = logError;
305614
+ var EdgeRuntimes;
305615
+ (function (EdgeRuntimes) {
305616
+ EdgeRuntimes["Edge"] = "edge";
305617
+ EdgeRuntimes["ExperimentalEdge"] = "experimental-edge";
305618
+ })(EdgeRuntimes = exports.EdgeRuntimes || (exports.EdgeRuntimes = {}));
305619
+ function isEdgeRuntime(runtime) {
305620
+ return (runtime !== undefined &&
305621
+ Object.values(EdgeRuntimes).includes(runtime));
305622
+ }
305623
+ exports.isEdgeRuntime = isEdgeRuntime;
305598
305624
 
305599
305625
 
305600
305626
  /***/ }),
@@ -141,15 +141,21 @@ function register(opts = {}) {
141
141
  console.error('\x1b[31m%s\x1b[0m', error);
142
142
  }
143
143
  }
144
- function getBuild(configFileName = '') {
145
- let build = configFileToBuildMap.get(configFileName);
146
- if (build)
147
- 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();
148
150
  const config = readConfig(configFileName);
149
151
  /**
150
- * Create the basic required function using transpile mode.
152
+ * Create the basic function for transpile only (ts-node --transpileOnly)
151
153
  */
152
- const getOutput = function (code, fileName) {
154
+ const getOutputTranspile = (code, fileName) => {
155
+ const outFile = outFiles.get(fileName);
156
+ if (outFile) {
157
+ return outFile;
158
+ }
153
159
  const result = ts.transpileModule(code, {
154
160
  fileName,
155
161
  transformers,
@@ -160,84 +166,94 @@ function register(opts = {}) {
160
166
  ? filterDiagnostics(result.diagnostics, ignoreDiagnostics)
161
167
  : [];
162
168
  reportTSError(diagnosticList, config.options.noEmitOnError);
163
- return { code: result.outputText, map: result.sourceMapText };
164
- };
165
- // Use full language services when the fast option is disabled.
166
- let getOutputTypeCheck;
167
- {
168
- const memoryCache = new MemoryCache(config.fileNames);
169
- const cachedReadFile = cachedLookup(debugFn('readFile', readFile));
170
- // Create the compiler host for type checking.
171
- const serviceHost = {
172
- getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
173
- getScriptVersion: (fileName) => {
174
- const version = memoryCache.fileVersions.get(fileName);
175
- return version === undefined ? '' : version.toString();
176
- },
177
- getScriptSnapshot(fileName) {
178
- let contents = memoryCache.fileContents.get(fileName);
179
- // Read contents into TypeScript memory cache.
180
- if (contents === undefined) {
181
- contents = cachedReadFile(fileName);
182
- if (contents === undefined)
183
- return;
184
- memoryCache.fileVersions.set(fileName, 1);
185
- memoryCache.fileContents.set(fileName, contents);
186
- }
187
- return ts.ScriptSnapshot.fromString(contents);
188
- },
189
- readFile: cachedReadFile,
190
- readDirectory: cachedLookup(debugFn('readDirectory', ts.sys.readDirectory)),
191
- getDirectories: cachedLookup(debugFn('getDirectories', ts.sys.getDirectories)),
192
- fileExists: cachedLookup(debugFn('fileExists', fileExists)),
193
- directoryExists: cachedLookup(debugFn('directoryExists', ts.sys.directoryExists)),
194
- getNewLine: () => ts.sys.newLine,
195
- useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
196
- getCurrentDirectory: () => cwd,
197
- getCompilationSettings: () => config.options,
198
- getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
199
- getCustomTransformers: () => transformers,
169
+ const file = {
170
+ code: result.outputText,
171
+ map: result.sourceMapText,
200
172
  };
201
- const registry = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames, cwd);
202
- const service = ts.createLanguageService(serviceHost, registry);
203
- // Set the file contents into cache manually.
204
- const updateMemoryCache = function (contents, fileName) {
205
- const fileVersion = memoryCache.fileVersions.get(fileName) || 0;
206
- // Avoid incrementing cache when nothing has changed.
207
- if (memoryCache.fileContents.get(fileName) === contents)
208
- return;
209
- memoryCache.fileVersions.set(fileName, fileVersion + 1);
210
- memoryCache.fileContents.set(fileName, contents);
211
- };
212
- getOutputTypeCheck = function (code, fileName) {
213
- updateMemoryCache(code, fileName);
214
- const output = service.getEmitOutput(fileName);
215
- // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
216
- const diagnostics = service
217
- .getSemanticDiagnostics(fileName)
218
- .concat(service.getSyntacticDiagnostics(fileName));
219
- const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
220
- reportTSError(diagnosticList, config.options.noEmitOnError);
221
- if (output.emitSkipped) {
222
- throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
223
- }
224
- // Throw an error when requiring `.d.ts` files.
225
- if (output.outputFiles.length === 0) {
226
- throw new TypeError('Unable to require `.d.ts` file.\n' +
227
- 'This is usually the result of a faulty configuration or import. ' +
228
- 'Make sure there is a `.js`, `.json` or another executable extension and ' +
229
- 'loader (attached before `ts-node`) available alongside ' +
230
- `\`${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);
231
194
  }
232
- return {
233
- code: output.outputFiles[1].text,
234
- map: output.outputFiles[0].text,
235
- };
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,
236
250
  };
237
- }
238
- build = { getOutput, getOutputTypeCheck };
239
- configFileToBuildMap.set(configFileName, build);
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/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
3
+ exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
4
4
  const path_1 = require("path");
5
5
  const path_to_regexp_1 = require("path-to-regexp");
6
6
  const build_utils_1 = require("@vercel/build-utils");
@@ -56,3 +56,13 @@ function logError(error) {
56
56
  }
57
57
  }
58
58
  exports.logError = logError;
59
+ var EdgeRuntimes;
60
+ (function (EdgeRuntimes) {
61
+ EdgeRuntimes["Edge"] = "edge";
62
+ EdgeRuntimes["ExperimentalEdge"] = "experimental-edge";
63
+ })(EdgeRuntimes = exports.EdgeRuntimes || (exports.EdgeRuntimes = {}));
64
+ function isEdgeRuntime(runtime) {
65
+ return (runtime !== undefined &&
66
+ Object.values(EdgeRuntimes).includes(runtime));
67
+ }
68
+ exports.isEdgeRuntime = isEdgeRuntime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
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.6.0",
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": "a19447f9cdc8c7be8aa3646dfb441dd9469d2ed3"
64
+ "gitHead": "584d0ea8535f1fad5588a4dc51269d4985a32875"
65
65
  }