@vercel/node 2.12.0 → 2.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/dist/{dev-server.js → dev-server.mjs} +20 -33
- package/dist/edge-functions/{edge-handler.js → edge-handler.mjs} +40 -53
- package/dist/edge-functions/{edge-node-compat-plugin.js → edge-node-compat-plugin.mjs} +12 -20
- package/dist/edge-functions/{edge-wasm-plugin.js → edge-wasm-plugin.mjs} +7 -12
- package/dist/fork-dev-server.js +11 -14
- package/dist/index.d.ts +13 -12
- package/dist/index.js +123 -96
- package/dist/serverless-functions/helpers.js +1 -1
- package/dist/serverless-functions/serverless-handler.mjs +65 -0
- package/dist/typescript.js +4 -4
- package/dist/utils.js +18 -6
- package/package.json +10 -9
- package/dist/edge-functions/edge-handler.d.ts +0 -4
- package/dist/edge-functions/edge-node-compat-plugin.d.ts +0 -15
- package/dist/edge-functions/edge-wasm-plugin.d.ts +0 -21
- package/dist/fork-dev-server.d.ts +0 -34
- package/dist/serverless-functions/dynamic-import.js +0 -13
- package/dist/serverless-functions/helpers.d.ts +0 -22
- package/dist/serverless-functions/serverless-handler.d.ts +0 -10
- package/dist/serverless-functions/serverless-handler.js +0 -70
package/dist/index.js
CHANGED
@@ -140036,19 +140036,17 @@ const child_process_1 = __webpack_require__(63129);
|
|
140036
140036
|
const url_1 = __webpack_require__(78835);
|
140037
140037
|
const path_1 = __webpack_require__(85622);
|
140038
140038
|
function forkDevServer(options) {
|
140039
|
-
let nodeOptions = process.env.NODE_OPTIONS;
|
140039
|
+
let nodeOptions = process.env.NODE_OPTIONS || '';
|
140040
|
+
if (!nodeOptions.includes('--no-warnings')) {
|
140041
|
+
nodeOptions += ' --no-warnings';
|
140042
|
+
}
|
140040
140043
|
const tsNodePath = options.require_.resolve('ts-node');
|
140041
|
-
const esmLoader = url_1.pathToFileURL(path_1.join(tsNodePath, '..', '..', 'esm.mjs'));
|
140042
|
-
const cjsLoader = path_1.join(tsNodePath, '..', '..', 'register', 'index.js');
|
140043
|
-
const devServerPath = options.devServerPath || path_1.join(__dirname, 'dev-server.
|
140044
|
+
const esmLoader = (0, url_1.pathToFileURL)((0, path_1.join)(tsNodePath, '..', '..', 'esm.mjs'));
|
140045
|
+
const cjsLoader = (0, path_1.join)(tsNodePath, '..', '..', 'register', 'index.js');
|
140046
|
+
const devServerPath = options.devServerPath || (0, path_1.join)(__dirname, 'dev-server.mjs');
|
140044
140047
|
if (options.maybeTranspile) {
|
140045
140048
|
if (options.isTypeScript) {
|
140046
|
-
|
140047
|
-
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
140048
|
-
}
|
140049
|
-
else {
|
140050
|
-
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
140051
|
-
}
|
140049
|
+
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
140052
140050
|
}
|
140053
140051
|
else {
|
140054
140052
|
if (options.isEsm) {
|
@@ -140062,9 +140060,8 @@ function forkDevServer(options) {
|
|
140062
140060
|
const forkOptions = {
|
140063
140061
|
cwd: options.workPath,
|
140064
140062
|
execArgv: [],
|
140065
|
-
env: build_utils_1.cloneEnv(process.env, options.meta.env, {
|
140063
|
+
env: (0, build_utils_1.cloneEnv)(process.env, options.meta.env, {
|
140066
140064
|
VERCEL_DEV_ENTRYPOINT: options.entrypoint,
|
140067
|
-
VERCEL_DEV_IS_ESM: options.isEsm ? '1' : undefined,
|
140068
140065
|
VERCEL_DEV_CONFIG: JSON.stringify(options.config),
|
140069
140066
|
VERCEL_DEV_BUILD_ENV: JSON.stringify(options.meta.buildEnv || {}),
|
140070
140067
|
TS_NODE_TRANSPILE_ONLY: '1',
|
@@ -140074,7 +140071,7 @@ function forkDevServer(options) {
|
|
140074
140071
|
NODE_OPTIONS: nodeOptions,
|
140075
140072
|
}),
|
140076
140073
|
};
|
140077
|
-
const child = child_process_1.fork(devServerPath, [], forkOptions);
|
140074
|
+
const child = (0, child_process_1.fork)(devServerPath, [], forkOptions);
|
140078
140075
|
checkForPid(devServerPath, child);
|
140079
140076
|
return child;
|
140080
140077
|
}
|
@@ -140090,7 +140087,7 @@ function checkForPid(path, process) {
|
|
140090
140087
|
* or it is listening to new requests, and we can start proxying requests.
|
140091
140088
|
*/
|
140092
140089
|
async function readMessage(child) {
|
140093
|
-
const onMessage = once_1.default(child, 'message');
|
140090
|
+
const onMessage = (0, once_1.default)(child, 'message');
|
140094
140091
|
const onExit = once_1.default.spread(child, 'close');
|
140095
140092
|
const result = await Promise.race([
|
140096
140093
|
onMessage.then(x => {
|
@@ -140116,7 +140113,11 @@ exports.readMessage = readMessage;
|
|
140116
140113
|
|
140117
140114
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
140118
140115
|
if (k2 === undefined) k2 = k;
|
140119
|
-
Object.
|
140116
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
140117
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
140118
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
140119
|
+
}
|
140120
|
+
Object.defineProperty(o, k2, desc);
|
140120
140121
|
}) : (function(o, m, k, k2) {
|
140121
140122
|
if (k2 === undefined) k2 = k;
|
140122
140123
|
o[k2] = m[k];
|
@@ -140144,17 +140145,16 @@ const static_config_1 = __webpack_require__(27167);
|
|
140144
140145
|
const typescript_1 = __webpack_require__(39677);
|
140145
140146
|
const utils_1 = __webpack_require__(76136);
|
140146
140147
|
const fork_dev_server_1 = __webpack_require__(31158);
|
140147
|
-
const ALLOWED_RUNTIMES = ['nodejs', ...Object.values(utils_1.EdgeRuntimes)];
|
140148
140148
|
const require_ = eval('require');
|
140149
|
-
const tscPath = path_1.resolve(path_1.dirname(require_.resolve('typescript')), '../bin/tsc');
|
140149
|
+
const tscPath = (0, path_1.resolve)((0, path_1.dirname)(require_.resolve('typescript')), '../bin/tsc');
|
140150
140150
|
// eslint-disable-next-line no-useless-escape
|
140151
140151
|
const libPathRegEx = /^node_modules|[\/\\]node_modules[\/\\]/;
|
140152
140152
|
async function downloadInstallAndBundle({ files, entrypoint, workPath, config, meta, }) {
|
140153
|
-
const downloadedFiles = await build_utils_1.download(files, workPath, meta);
|
140154
|
-
const entrypointFsDirname = path_1.join(workPath, path_1.dirname(entrypoint));
|
140155
|
-
const nodeVersion = await build_utils_1.getNodeVersion(entrypointFsDirname, undefined, config, meta);
|
140156
|
-
const spawnOpts = build_utils_1.getSpawnOptions(meta, nodeVersion);
|
140157
|
-
await build_utils_1.runNpmInstall(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
|
140153
|
+
const downloadedFiles = await (0, build_utils_1.download)(files, workPath, meta);
|
140154
|
+
const entrypointFsDirname = (0, path_1.join)(workPath, (0, path_1.dirname)(entrypoint));
|
140155
|
+
const nodeVersion = await (0, build_utils_1.getNodeVersion)(entrypointFsDirname, undefined, config, meta);
|
140156
|
+
const spawnOpts = (0, build_utils_1.getSpawnOptions)(meta, nodeVersion);
|
140157
|
+
await (0, build_utils_1.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
|
140158
140158
|
const entrypointPath = downloadedFiles[entrypoint].fsPath;
|
140159
140159
|
return { entrypointPath, entrypointFsDirname, nodeVersion, spawnOpts };
|
140160
140160
|
}
|
@@ -140167,7 +140167,7 @@ function renameTStoJS(path) {
|
|
140167
140167
|
}
|
140168
140168
|
return path;
|
140169
140169
|
}
|
140170
|
-
async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction) {
|
140170
|
+
async function compile(workPath, baseDir, entrypointPath, config, meta, nodeVersion, isEdgeFunction) {
|
140171
140171
|
const inputFiles = new Set([entrypointPath]);
|
140172
140172
|
const preparedFiles = {};
|
140173
140173
|
const sourceCache = new Map();
|
@@ -140180,10 +140180,10 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140180
140180
|
? [config.includeFiles]
|
140181
140181
|
: config.includeFiles;
|
140182
140182
|
for (const pattern of includeFiles) {
|
140183
|
-
const files = await build_utils_1.glob(pattern, workPath);
|
140183
|
+
const files = await (0, build_utils_1.glob)(pattern, workPath);
|
140184
140184
|
await Promise.all(Object.values(files).map(async (entry) => {
|
140185
140185
|
const { fsPath } = entry;
|
140186
|
-
const relPath = path_1.relative(baseDir, fsPath);
|
140186
|
+
const relPath = (0, path_1.relative)(baseDir, fsPath);
|
140187
140187
|
fsCache.set(relPath, entry);
|
140188
140188
|
preparedFiles[relPath] = entry;
|
140189
140189
|
}));
|
@@ -140191,9 +140191,9 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140191
140191
|
}
|
140192
140192
|
let tsCompile;
|
140193
140193
|
function compileTypeScript(path, source) {
|
140194
|
-
const relPath = path_1.relative(baseDir, path);
|
140194
|
+
const relPath = (0, path_1.relative)(baseDir, path);
|
140195
140195
|
if (!tsCompile) {
|
140196
|
-
tsCompile = typescript_1.register({
|
140196
|
+
tsCompile = (0, typescript_1.register)({
|
140197
140197
|
basePath: workPath,
|
140198
140198
|
project: path,
|
140199
140199
|
files: true,
|
@@ -140212,7 +140212,7 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140212
140212
|
const conditions = isEdgeFunction
|
140213
140213
|
? ['edge-light', 'browser', 'module', 'import', 'require']
|
140214
140214
|
: undefined;
|
140215
|
-
const { fileList, esmFileList, warnings } = await nft_1.nodeFileTrace([...inputFiles], {
|
140215
|
+
const { fileList, esmFileList, warnings } = await (0, nft_1.nodeFileTrace)([...inputFiles], {
|
140216
140216
|
base: baseDir,
|
140217
140217
|
processCwd: workPath,
|
140218
140218
|
ts: true,
|
@@ -140220,29 +140220,29 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140220
140220
|
conditions,
|
140221
140221
|
resolve(id, parent, job, cjsResolve) {
|
140222
140222
|
const normalizedWasmImports = id.replace(/\.wasm\?module$/i, '.wasm');
|
140223
|
-
return resolve_dependency_1.default(normalizedWasmImports, parent, job, cjsResolve);
|
140223
|
+
return (0, resolve_dependency_1.default)(normalizedWasmImports, parent, job, cjsResolve);
|
140224
140224
|
},
|
140225
140225
|
ignore: config.excludeFiles,
|
140226
140226
|
async readFile(fsPath) {
|
140227
|
-
const relPath = path_1.relative(baseDir, fsPath);
|
140227
|
+
const relPath = (0, path_1.relative)(baseDir, fsPath);
|
140228
140228
|
// If this file has already been read then return from the cache
|
140229
140229
|
const cached = sourceCache.get(relPath);
|
140230
140230
|
if (typeof cached !== 'undefined')
|
140231
140231
|
return cached;
|
140232
140232
|
try {
|
140233
140233
|
let entry;
|
140234
|
-
let source = fs_1.readFileSync(fsPath);
|
140235
|
-
const { mode } = fs_1.lstatSync(fsPath);
|
140236
|
-
if (build_utils_1.isSymbolicLink(mode)) {
|
140234
|
+
let source = (0, fs_1.readFileSync)(fsPath);
|
140235
|
+
const { mode } = (0, fs_1.lstatSync)(fsPath);
|
140236
|
+
if ((0, build_utils_1.isSymbolicLink)(mode)) {
|
140237
140237
|
entry = new build_utils_1.FileFsRef({ fsPath, mode });
|
140238
140238
|
}
|
140239
|
-
if (isEdgeFunction && path_1.basename(fsPath) === 'package.json') {
|
140239
|
+
if (isEdgeFunction && (0, path_1.basename)(fsPath) === 'package.json') {
|
140240
140240
|
// For Edge Functions, patch "main" field to prefer "browser" or "module"
|
140241
140241
|
const pkgJson = JSON.parse(source.toString());
|
140242
140242
|
for (const prop of ['browser', 'module']) {
|
140243
140243
|
const val = pkgJson[prop];
|
140244
140244
|
if (typeof val === 'string') {
|
140245
|
-
build_utils_1.debug(`Using "${prop}" field in ${fsPath}`);
|
140245
|
+
(0, build_utils_1.debug)(`Using "${prop}" field in ${fsPath}`);
|
140246
140246
|
pkgJson.main = val;
|
140247
140247
|
// Create the `entry` with the original so that the output is unmodified
|
140248
140248
|
if (!entry) {
|
@@ -140266,7 +140266,7 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140266
140266
|
return source;
|
140267
140267
|
}
|
140268
140268
|
catch (error) {
|
140269
|
-
if (error_utils_1.isErrnoException(error) &&
|
140269
|
+
if ((0, error_utils_1.isErrnoException)(error) &&
|
140270
140270
|
(error.code === 'ENOENT' || error.code === 'EISDIR')) {
|
140271
140271
|
// `null` represents a not found
|
140272
140272
|
sourceCache.set(relPath, null);
|
@@ -140277,27 +140277,27 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140277
140277
|
},
|
140278
140278
|
});
|
140279
140279
|
for (const warning of warnings) {
|
140280
|
-
build_utils_1.debug(`Warning from trace: ${warning.message}`);
|
140280
|
+
(0, build_utils_1.debug)(`Warning from trace: ${warning.message}`);
|
140281
140281
|
}
|
140282
140282
|
for (const path of fileList) {
|
140283
140283
|
let entry = fsCache.get(path);
|
140284
140284
|
if (!entry) {
|
140285
|
-
const fsPath = path_1.resolve(baseDir, path);
|
140286
|
-
const { mode } = fs_1.lstatSync(fsPath);
|
140287
|
-
if (build_utils_1.isSymbolicLink(mode)) {
|
140285
|
+
const fsPath = (0, path_1.resolve)(baseDir, path);
|
140286
|
+
const { mode } = (0, fs_1.lstatSync)(fsPath);
|
140287
|
+
if ((0, build_utils_1.isSymbolicLink)(mode)) {
|
140288
140288
|
entry = new build_utils_1.FileFsRef({ fsPath, mode });
|
140289
140289
|
}
|
140290
140290
|
else {
|
140291
|
-
const source = fs_1.readFileSync(fsPath);
|
140291
|
+
const source = (0, fs_1.readFileSync)(fsPath);
|
140292
140292
|
entry = new build_utils_1.FileBlob({ data: source, mode });
|
140293
140293
|
}
|
140294
140294
|
}
|
140295
|
-
if (build_utils_1.isSymbolicLink(entry.mode) && entry.type === 'FileFsRef') {
|
140295
|
+
if ((0, build_utils_1.isSymbolicLink)(entry.mode) && entry.type === 'FileFsRef') {
|
140296
140296
|
// ensure the symlink target is added to the file list
|
140297
|
-
const symlinkTarget = path_1.relative(baseDir, path_1.resolve(path_1.dirname(entry.fsPath), fs_1.readlinkSync(entry.fsPath)));
|
140297
|
+
const symlinkTarget = (0, path_1.relative)(baseDir, (0, path_1.resolve)((0, path_1.dirname)(entry.fsPath), (0, fs_1.readlinkSync)(entry.fsPath)));
|
140298
140298
|
if (!symlinkTarget.startsWith('..' + path_1.sep) &&
|
140299
140299
|
!fileList.has(symlinkTarget)) {
|
140300
|
-
const stats = fs_1.statSync(path_1.resolve(baseDir, symlinkTarget));
|
140300
|
+
const stats = (0, fs_1.statSync)((0, path_1.resolve)(baseDir, symlinkTarget));
|
140301
140301
|
if (stats.isFile()) {
|
140302
140302
|
fileList.add(symlinkTarget);
|
140303
140303
|
}
|
@@ -140315,12 +140315,13 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140315
140315
|
!file.endsWith('.tsx') &&
|
140316
140316
|
!file.endsWith('.mjs') &&
|
140317
140317
|
!file.match(libPathRegEx));
|
140318
|
-
|
140318
|
+
const babelCompileEnabled = !isEdgeFunction || process.env.VERCEL_EDGE_NO_BABEL !== '1';
|
140319
|
+
if (babelCompileEnabled && esmPaths.length) {
|
140319
140320
|
const babelCompile = __webpack_require__(20007)/* .compile */ .M;
|
140320
140321
|
for (const path of esmPaths) {
|
140321
|
-
const pathDir = path_1.join(workPath, path_1.dirname(path));
|
140322
|
+
const pathDir = (0, path_1.join)(workPath, (0, path_1.dirname)(path));
|
140322
140323
|
if (!pkgCache.has(pathDir)) {
|
140323
|
-
const pathToPkg = await build_utils_1.walkParentDirs({
|
140324
|
+
const pathToPkg = await (0, build_utils_1.walkParentDirs)({
|
140324
140325
|
base: workPath,
|
140325
140326
|
start: pathDir,
|
140326
140327
|
filename: 'package.json',
|
@@ -140335,10 +140336,15 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
|
|
140335
140336
|
// https://nodejs.org/api/packages.html#packages_type
|
140336
140337
|
continue;
|
140337
140338
|
}
|
140338
|
-
const filename = path_1.basename(path);
|
140339
|
+
const filename = (0, path_1.basename)(path);
|
140339
140340
|
const { data: source } = await build_utils_1.FileBlob.fromStream({
|
140340
140341
|
stream: preparedFiles[path].toStream(),
|
140341
140342
|
});
|
140343
|
+
if (!meta.compiledToCommonJS) {
|
140344
|
+
meta.compiledToCommonJS = true;
|
140345
|
+
console.warn('Warning: Node.js functions are compiled from ESM to CommonJS. If this is not intended, add "type": "module" to your package.json file.');
|
140346
|
+
}
|
140347
|
+
console.log(`Compiling "${filename}" from ESM to CommonJS...`);
|
140342
140348
|
const { code, map } = babelCompile(filename, source);
|
140343
140349
|
shouldAddSourcemapSupport = true;
|
140344
140350
|
preparedFiles[path] = new build_utils_1.FileBlob({
|
@@ -140360,7 +140366,7 @@ function getAWSLambdaHandler(entrypoint, config) {
|
|
140360
140366
|
return config.awsLambdaHandler;
|
140361
140367
|
}
|
140362
140368
|
if (process.env.NODEJS_AWS_HANDLER_NAME) {
|
140363
|
-
const { dir, name } = path_1.parse(entrypoint);
|
140369
|
+
const { dir, name } = (0, path_1.parse)(entrypoint);
|
140364
140370
|
return `${dir}${dir ? path_1.sep : ''}${name}.${process.env.NODEJS_AWS_HANDLER_NAME}`;
|
140365
140371
|
}
|
140366
140372
|
return '';
|
@@ -140378,7 +140384,7 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
140378
140384
|
config,
|
140379
140385
|
meta,
|
140380
140386
|
});
|
140381
|
-
await build_utils_1.runPackageJsonScript(entrypointFsDirname,
|
140387
|
+
await (0, build_utils_1.runPackageJsonScript)(entrypointFsDirname,
|
140382
140388
|
// Don't consider "build" script since its intended for frontend code
|
140383
140389
|
['vercel-build', 'now-build'], spawnOpts);
|
140384
140390
|
const isMiddleware = config.middleware === true;
|
@@ -140387,24 +140393,20 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
140387
140393
|
// `export const config = { runtime: 'edge' }`
|
140388
140394
|
let isEdgeFunction = isMiddleware;
|
140389
140395
|
const project = new ts_morph_1.Project();
|
140390
|
-
const staticConfig = static_config_1.getConfig(project, entrypointPath);
|
140391
|
-
|
140392
|
-
|
140393
|
-
|
140394
|
-
|
140395
|
-
if (staticConfig.runtime === 'nodejs') {
|
140396
|
-
console.log(`Detected unused static config runtime "nodejs" in "${entrypointPath}"`);
|
140397
|
-
}
|
140398
|
-
isEdgeFunction = utils_1.isEdgeRuntime(staticConfig.runtime);
|
140396
|
+
const staticConfig = (0, static_config_1.getConfig)(project, entrypointPath);
|
140397
|
+
const runtime = staticConfig?.runtime;
|
140398
|
+
(0, utils_1.validateConfiguredRuntime)(runtime, entrypoint);
|
140399
|
+
if (runtime) {
|
140400
|
+
isEdgeFunction = (0, utils_1.isEdgeRuntime)(runtime);
|
140399
140401
|
}
|
140400
|
-
build_utils_1.debug('Tracing input files...');
|
140402
|
+
(0, build_utils_1.debug)('Tracing input files...');
|
140401
140403
|
const traceTime = Date.now();
|
140402
|
-
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction);
|
140403
|
-
build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
|
140404
|
+
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, meta, nodeVersion, isEdgeFunction);
|
140405
|
+
(0, build_utils_1.debug)(`Trace complete [${Date.now() - traceTime}ms]`);
|
140404
140406
|
let routes;
|
140405
140407
|
let output;
|
140406
|
-
const handler = renameTStoJS(path_1.relative(baseDir, entrypointPath));
|
140407
|
-
const outputPath = utils_1.entrypointToOutputPath(entrypoint, config.zeroConfig);
|
140408
|
+
const handler = renameTStoJS((0, path_1.relative)(baseDir, entrypointPath));
|
140409
|
+
const outputPath = (0, utils_1.entrypointToOutputPath)(entrypoint, config.zeroConfig);
|
140408
140410
|
// Add a `route` for Middleware
|
140409
140411
|
if (isMiddleware) {
|
140410
140412
|
if (!isEdgeFunction) {
|
@@ -140412,7 +140414,7 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
140412
140414
|
throw new Error(`Middleware file can not be a Node.js Serverless Function`);
|
140413
140415
|
}
|
140414
140416
|
// Middleware is a catch-all for all paths unless a `matcher` property is defined
|
140415
|
-
const src = utils_1.getRegExpFromMatchers(staticConfig?.matcher);
|
140417
|
+
const src = (0, utils_1.getRegExpFromMatchers)(staticConfig?.matcher);
|
140416
140418
|
const middlewareRawSrc = [];
|
140417
140419
|
if (staticConfig?.matcher) {
|
140418
140420
|
if (Array.isArray(staticConfig.matcher)) {
|
@@ -140463,19 +140465,19 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
140463
140465
|
};
|
140464
140466
|
exports.build = build;
|
140465
140467
|
const prepareCache = ({ repoRootPath, workPath }) => {
|
140466
|
-
return build_utils_1.glob('**/node_modules/**', repoRootPath || workPath);
|
140468
|
+
return (0, build_utils_1.glob)('**/node_modules/**', repoRootPath || workPath);
|
140467
140469
|
};
|
140468
140470
|
exports.prepareCache = prepareCache;
|
140469
140471
|
const startDevServer = async (opts) => {
|
140470
140472
|
const { entrypoint, workPath, config, meta = {} } = opts;
|
140471
|
-
const entrypointPath = path_1.join(workPath, entrypoint);
|
140473
|
+
const entrypointPath = (0, path_1.join)(workPath, entrypoint);
|
140472
140474
|
if (config.middleware === true && typeof meta.requestUrl === 'string') {
|
140473
140475
|
// TODO: static config is also parsed in `dev-server.ts`.
|
140474
140476
|
// we should pass in this version as an env var instead.
|
140475
140477
|
const project = new ts_morph_1.Project();
|
140476
|
-
const staticConfig = static_config_1.getConfig(project, entrypointPath);
|
140478
|
+
const staticConfig = (0, static_config_1.getConfig)(project, entrypointPath);
|
140477
140479
|
// Middleware is a catch-all for all paths unless a `matcher` property is defined
|
140478
|
-
const matchers = new RegExp(utils_1.getRegExpFromMatchers(staticConfig?.matcher));
|
140480
|
+
const matchers = new RegExp((0, utils_1.getRegExpFromMatchers)(staticConfig?.matcher));
|
140479
140481
|
const parsed = url_1.default.parse(meta.requestUrl, true);
|
140480
140482
|
if (typeof parsed.pathname !== 'string' ||
|
140481
140483
|
!matchers.test(parsed.pathname)) {
|
@@ -140484,14 +140486,14 @@ const startDevServer = async (opts) => {
|
|
140484
140486
|
return null;
|
140485
140487
|
}
|
140486
140488
|
}
|
140487
|
-
const entryDir = path_1.dirname(entrypointPath);
|
140488
|
-
const ext = path_1.extname(entrypoint);
|
140489
|
-
const pathToTsConfig = await build_utils_1.walkParentDirs({
|
140489
|
+
const entryDir = (0, path_1.dirname)(entrypointPath);
|
140490
|
+
const ext = (0, path_1.extname)(entrypoint);
|
140491
|
+
const pathToTsConfig = await (0, build_utils_1.walkParentDirs)({
|
140490
140492
|
base: workPath,
|
140491
140493
|
start: entryDir,
|
140492
140494
|
filename: 'tsconfig.json',
|
140493
140495
|
});
|
140494
|
-
const pathToPkg = await build_utils_1.walkParentDirs({
|
140496
|
+
const pathToPkg = await (0, build_utils_1.walkParentDirs)({
|
140495
140497
|
base: workPath,
|
140496
140498
|
start: entryDir,
|
140497
140499
|
filename: 'package.json',
|
@@ -140523,7 +140525,7 @@ const startDevServer = async (opts) => {
|
|
140523
140525
|
}
|
140524
140526
|
// Otherwise fall back to using the copy that `@vercel/node` uses
|
140525
140527
|
if (!ts) {
|
140526
|
-
compiler = resolveTypescript(path_1.join(__dirname, '..'));
|
140528
|
+
compiler = resolveTypescript((0, path_1.join)(__dirname, '..'));
|
140527
140529
|
ts = requireTypescript(compiler);
|
140528
140530
|
}
|
140529
140531
|
if (pathToTsConfig) {
|
@@ -140531,14 +140533,27 @@ const startDevServer = async (opts) => {
|
|
140531
140533
|
tsConfig = ts.readConfigFile(pathToTsConfig, ts.sys.readFile).config;
|
140532
140534
|
}
|
140533
140535
|
catch (error) {
|
140534
|
-
if (error_utils_1.isErrnoException(error) && error.code !== 'ENOENT') {
|
140536
|
+
if ((0, error_utils_1.isErrnoException)(error) && error.code !== 'ENOENT') {
|
140535
140537
|
console.error(`Error while parsing "${pathToTsConfig}"`);
|
140536
140538
|
throw error;
|
140537
140539
|
}
|
140538
140540
|
}
|
140539
140541
|
}
|
140542
|
+
// if we're using ESM, we need to tell TypeScript to use `nodenext` to
|
140543
|
+
// preserve the `import` semantics
|
140544
|
+
if (isEsm) {
|
140545
|
+
if (!tsConfig.compilerOptions) {
|
140546
|
+
tsConfig.compilerOptions = {};
|
140547
|
+
}
|
140548
|
+
if (tsConfig.compilerOptions.module === undefined) {
|
140549
|
+
tsConfig.compilerOptions.module = 'nodenext';
|
140550
|
+
}
|
140551
|
+
if (tsConfig.compilerOptions.moduleResolution === undefined) {
|
140552
|
+
tsConfig.compilerOptions.moduleResolution = 'nodenext';
|
140553
|
+
}
|
140554
|
+
}
|
140540
140555
|
const nodeVersionMajor = Number(process.versions.node.split('.')[0]);
|
140541
|
-
typescript_1.fixConfig(tsConfig, nodeVersionMajor);
|
140556
|
+
(0, typescript_1.fixConfig)(tsConfig, nodeVersionMajor);
|
140542
140557
|
// In prod, `.ts` inputs use TypeScript and
|
140543
140558
|
// `.js` inputs use Babel to convert ESM to CJS.
|
140544
140559
|
// In dev, both `.ts` and `.js` inputs use ts-node
|
@@ -140548,7 +140563,7 @@ const startDevServer = async (opts) => {
|
|
140548
140563
|
// In dev, we don't emit because we use ts-node.
|
140549
140564
|
tsConfig.compilerOptions.noEmit = true;
|
140550
140565
|
}
|
140551
|
-
const child = fork_dev_server_1.forkDevServer({
|
140566
|
+
const child = (0, fork_dev_server_1.forkDevServer)({
|
140552
140567
|
workPath,
|
140553
140568
|
config,
|
140554
140569
|
entrypoint,
|
@@ -140560,7 +140575,7 @@ const startDevServer = async (opts) => {
|
|
140560
140575
|
tsConfig,
|
140561
140576
|
});
|
140562
140577
|
const { pid } = child;
|
140563
|
-
const message = await fork_dev_server_1.readMessage(child);
|
140578
|
+
const message = await (0, fork_dev_server_1.readMessage)(child);
|
140564
140579
|
if (message.state === 'message') {
|
140565
140580
|
// "message" event
|
140566
140581
|
if (isTypeScript) {
|
@@ -140581,22 +140596,22 @@ const startDevServer = async (opts) => {
|
|
140581
140596
|
};
|
140582
140597
|
exports.startDevServer = startDevServer;
|
140583
140598
|
async function doTypeCheck({ entrypoint, workPath, meta = {} }, projectTsConfig) {
|
140584
|
-
const { devCacheDir = path_1.join(workPath, '.vercel', 'cache') } = meta;
|
140585
|
-
const entrypointCacheDir = path_1.join(devCacheDir, 'node', entrypoint);
|
140599
|
+
const { devCacheDir = (0, path_1.join)(workPath, '.vercel', 'cache') } = meta;
|
140600
|
+
const entrypointCacheDir = (0, path_1.join)(devCacheDir, 'node', entrypoint);
|
140586
140601
|
// In order to type-check a single file, a standalone tsconfig
|
140587
140602
|
// file needs to be created that inherits from the base one :(
|
140588
140603
|
// See: https://stackoverflow.com/a/44748041/376773
|
140589
140604
|
//
|
140590
140605
|
// A different filename needs to be used for different `extends` tsconfig.json
|
140591
140606
|
const tsconfigName = projectTsConfig
|
140592
|
-
? `tsconfig-with-${path_1.relative(workPath, projectTsConfig).replace(/[\\/.]/g, '-')}.json`
|
140607
|
+
? `tsconfig-with-${(0, path_1.relative)(workPath, projectTsConfig).replace(/[\\/.]/g, '-')}.json`
|
140593
140608
|
: 'tsconfig.json';
|
140594
|
-
const tsconfigPath = path_1.join(entrypointCacheDir, tsconfigName);
|
140609
|
+
const tsconfigPath = (0, path_1.join)(entrypointCacheDir, tsconfigName);
|
140595
140610
|
const tsconfig = {
|
140596
140611
|
extends: projectTsConfig
|
140597
|
-
? path_1.relative(entrypointCacheDir, projectTsConfig)
|
140612
|
+
? (0, path_1.relative)(entrypointCacheDir, projectTsConfig)
|
140598
140613
|
: undefined,
|
140599
|
-
include: [path_1.relative(entrypointCacheDir, path_1.join(workPath, entrypoint))],
|
140614
|
+
include: [(0, path_1.relative)(entrypointCacheDir, (0, path_1.join)(workPath, entrypoint))],
|
140600
140615
|
};
|
140601
140616
|
try {
|
140602
140617
|
const json = JSON.stringify(tsconfig, null, '\t');
|
@@ -140604,10 +140619,10 @@ async function doTypeCheck({ entrypoint, workPath, meta = {} }, projectTsConfig)
|
|
140604
140619
|
await fs_1.promises.writeFile(tsconfigPath, json, { flag: 'wx' });
|
140605
140620
|
}
|
140606
140621
|
catch (error) {
|
140607
|
-
if (error_utils_1.isErrnoException(error) && error.code !== 'EEXIST')
|
140622
|
+
if ((0, error_utils_1.isErrnoException)(error) && error.code !== 'EEXIST')
|
140608
140623
|
throw error;
|
140609
140624
|
}
|
140610
|
-
const child = child_process_1.spawn(process.execPath, [
|
140625
|
+
const child = (0, child_process_1.spawn)(process.execPath, [
|
140611
140626
|
tscPath,
|
140612
140627
|
'--project',
|
140613
140628
|
tsconfigPath,
|
@@ -140869,7 +140884,7 @@ function register(opts = {}) {
|
|
140869
140884
|
const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
|
140870
140885
|
reportTSError(diagnosticList, config.options.noEmitOnError);
|
140871
140886
|
if (output.emitSkipped) {
|
140872
|
-
throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
|
140887
|
+
throw new TypeError(`${(0, path_1.relative)(cwd, fileName)}: Emit skipped`);
|
140873
140888
|
}
|
140874
140889
|
// Throw an error when requiring `.d.ts` files.
|
140875
140890
|
if (output.outputFiles.length === 0) {
|
@@ -140877,7 +140892,7 @@ function register(opts = {}) {
|
|
140877
140892
|
'This is usually the result of a faulty configuration or import. ' +
|
140878
140893
|
'Make sure there is a `.js`, `.json` or another executable extension and ' +
|
140879
140894
|
'loader (attached before `ts-node`) available alongside ' +
|
140880
|
-
`\`${path_1.basename(fileName)}\`.`);
|
140895
|
+
`\`${(0, path_1.basename)(fileName)}\`.`);
|
140881
140896
|
}
|
140882
140897
|
const file = {
|
140883
140898
|
code: output.outputFiles[1].text,
|
@@ -140905,7 +140920,7 @@ function register(opts = {}) {
|
|
140905
140920
|
*/
|
140906
140921
|
function readConfig(configFileName) {
|
140907
140922
|
let config = { compilerOptions: {} };
|
140908
|
-
const basePath = normalizeSlashes(path_1.dirname(configFileName));
|
140923
|
+
const basePath = normalizeSlashes((0, path_1.dirname)(configFileName));
|
140909
140924
|
// Read project configuration when available.
|
140910
140925
|
if (configFileName) {
|
140911
140926
|
const result = ts.readConfigFile(configFileName, readFile);
|
@@ -140947,7 +140962,7 @@ function register(opts = {}) {
|
|
140947
140962
|
const output = {
|
140948
140963
|
code: value,
|
140949
140964
|
map: Object.assign(JSON.parse(sourceMap), {
|
140950
|
-
file: path_1.basename(fileName),
|
140965
|
+
file: (0, path_1.basename)(fileName),
|
140951
140966
|
sources: [fileName],
|
140952
140967
|
}),
|
140953
140968
|
};
|
@@ -141016,7 +141031,7 @@ function filterDiagnostics(diagnostics, ignore) {
|
|
141016
141031
|
"use strict";
|
141017
141032
|
|
141018
141033
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
141019
|
-
exports.serializeBody = exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
|
141034
|
+
exports.serializeBody = exports.validateConfiguredRuntime = exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
|
141020
141035
|
const build_utils_1 = __webpack_require__(63445);
|
141021
141036
|
const path_to_regexp_1 = __webpack_require__(91344);
|
141022
141037
|
const path_1 = __webpack_require__(85622);
|
@@ -141038,9 +141053,9 @@ function getRegExpFromMatcher(matcher, index, allMatchers) {
|
|
141038
141053
|
if (!matcher.startsWith('/')) {
|
141039
141054
|
throw new Error(`Middleware's \`config.matcher\` values must start with "/". Received: ${matcher}`);
|
141040
141055
|
}
|
141041
|
-
const regExps = [path_to_regexp_1.pathToRegexp(matcher).source];
|
141056
|
+
const regExps = [(0, path_to_regexp_1.pathToRegexp)(matcher).source];
|
141042
141057
|
if (matcher === '/' && !allMatchers.includes('/index')) {
|
141043
|
-
regExps.push(path_to_regexp_1.pathToRegexp('/index').source);
|
141058
|
+
regExps.push((0, path_to_regexp_1.pathToRegexp)('/index').source);
|
141044
141059
|
}
|
141045
141060
|
return regExps;
|
141046
141061
|
}
|
@@ -141055,7 +141070,7 @@ function getRegExpFromMatcher(matcher, index, allMatchers) {
|
|
141055
141070
|
*/
|
141056
141071
|
function entrypointToOutputPath(entrypoint, zeroConfig) {
|
141057
141072
|
if (zeroConfig) {
|
141058
|
-
const ext = path_1.extname(entrypoint);
|
141073
|
+
const ext = (0, path_1.extname)(entrypoint);
|
141059
141074
|
return entrypoint.slice(0, entrypoint.length - ext.length);
|
141060
141075
|
}
|
141061
141076
|
return entrypoint;
|
@@ -141068,7 +141083,7 @@ function logError(error) {
|
|
141068
141083
|
// because it points to internals, not user code
|
141069
141084
|
const errorPrefixLength = 'Error: '.length;
|
141070
141085
|
const errorMessageLength = errorPrefixLength + error.message.length;
|
141071
|
-
build_utils_1.debug(error.stack.substring(errorMessageLength + 1));
|
141086
|
+
(0, build_utils_1.debug)(error.stack.substring(errorMessageLength + 1));
|
141072
141087
|
}
|
141073
141088
|
}
|
141074
141089
|
exports.logError = logError;
|
@@ -141082,9 +141097,21 @@ function isEdgeRuntime(runtime) {
|
|
141082
141097
|
Object.values(EdgeRuntimes).includes(runtime));
|
141083
141098
|
}
|
141084
141099
|
exports.isEdgeRuntime = isEdgeRuntime;
|
141100
|
+
const ALLOWED_RUNTIMES = Object.values(EdgeRuntimes);
|
141101
|
+
function validateConfiguredRuntime(runtime, entrypoint) {
|
141102
|
+
if (runtime) {
|
141103
|
+
if (runtime === 'nodejs') {
|
141104
|
+
throw new Error(`${entrypoint}: \`config.runtime: "nodejs"\` semantics will evolve soon. Please remove the \`runtime\` key to keep the existing behavior.`);
|
141105
|
+
}
|
141106
|
+
if (!ALLOWED_RUNTIMES.includes(runtime)) {
|
141107
|
+
throw new Error(`${entrypoint}: unsupported "runtime" value in \`config\`: ${JSON.stringify(runtime)} (must be one of: ${JSON.stringify(ALLOWED_RUNTIMES)}). Learn more: https://vercel.link/creating-edge-functions`);
|
141108
|
+
}
|
141109
|
+
}
|
141110
|
+
}
|
141111
|
+
exports.validateConfiguredRuntime = validateConfiguredRuntime;
|
141085
141112
|
async function serializeBody(request) {
|
141086
141113
|
return request.method !== 'GET' && request.method !== 'HEAD'
|
141087
|
-
? await build_utils_1.streamToBuffer(request)
|
141114
|
+
? await (0, build_utils_1.streamToBuffer)(request)
|
141088
141115
|
: undefined;
|
141089
141116
|
}
|
141090
141117
|
exports.serializeBody = serializeBody;
|
@@ -201,7 +201,7 @@ function restoreBody(req, body) {
|
|
201
201
|
replicateBody.end();
|
202
202
|
}
|
203
203
|
async function readBody(req) {
|
204
|
-
const body = (await utils_1.serializeBody(req)) || Buffer.from('');
|
204
|
+
const body = (await (0, utils_1.serializeBody)(req)) || Buffer.from('');
|
205
205
|
restoreBody(req, body);
|
206
206
|
return body;
|
207
207
|
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { addHelpers } from './helpers.js';
|
2
|
+
import { createServer } from 'http';
|
3
|
+
import { serializeBody } from '../utils.js';
|
4
|
+
import { streamToBuffer } from '@vercel/build-utils';
|
5
|
+
import exitHook from 'exit-hook';
|
6
|
+
import fetch from 'node-fetch';
|
7
|
+
import asyncListen from 'async-listen';
|
8
|
+
import { isAbsolute } from 'path';
|
9
|
+
import { pathToFileURL } from 'url';
|
10
|
+
const { default: listen } = asyncListen;
|
11
|
+
async function createServerlessServer(userCode, options) {
|
12
|
+
const server = createServer(async (req, res) => {
|
13
|
+
if (options.shouldAddHelpers)
|
14
|
+
await addHelpers(req, res);
|
15
|
+
return userCode(req, res);
|
16
|
+
});
|
17
|
+
exitHook(() => server.close());
|
18
|
+
return { url: await listen(server) };
|
19
|
+
}
|
20
|
+
async function compileUserCode(entrypointPath) {
|
21
|
+
const id = isAbsolute(entrypointPath)
|
22
|
+
? pathToFileURL(entrypointPath).href
|
23
|
+
: entrypointPath;
|
24
|
+
let fn = await import(id);
|
25
|
+
/**
|
26
|
+
* In some cases we might have nested default props due to TS => JS
|
27
|
+
*/
|
28
|
+
for (let i = 0; i < 5; i++) {
|
29
|
+
if (fn.default)
|
30
|
+
fn = fn.default;
|
31
|
+
}
|
32
|
+
return fn;
|
33
|
+
}
|
34
|
+
export async function createServerlessEventHandler(entrypointPath, options) {
|
35
|
+
const userCode = await compileUserCode(entrypointPath);
|
36
|
+
const server = await createServerlessServer(userCode, options);
|
37
|
+
return async function (request) {
|
38
|
+
const url = new URL(request.url ?? '/', server.url);
|
39
|
+
// @ts-expect-error
|
40
|
+
const response = await fetch(url, {
|
41
|
+
body: await serializeBody(request),
|
42
|
+
headers: {
|
43
|
+
...request.headers,
|
44
|
+
host: request.headers['x-forwarded-host'],
|
45
|
+
},
|
46
|
+
method: request.method,
|
47
|
+
redirect: 'manual',
|
48
|
+
});
|
49
|
+
let body;
|
50
|
+
if (options.mode === 'streaming') {
|
51
|
+
body = response.body;
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
body = await streamToBuffer(response.body);
|
55
|
+
response.headers.delete('transfer-encoding');
|
56
|
+
response.headers.set('content-length', body.length);
|
57
|
+
}
|
58
|
+
return {
|
59
|
+
status: response.status,
|
60
|
+
headers: response.headers,
|
61
|
+
body,
|
62
|
+
encoding: 'utf8',
|
63
|
+
};
|
64
|
+
};
|
65
|
+
}
|