@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/typescript.js
CHANGED
@@ -229,7 +229,7 @@ function register(opts = {}) {
|
|
229
229
|
const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics);
|
230
230
|
reportTSError(diagnosticList, config.options.noEmitOnError);
|
231
231
|
if (output.emitSkipped) {
|
232
|
-
throw new TypeError(`${path_1.relative(cwd, fileName)}: Emit skipped`);
|
232
|
+
throw new TypeError(`${(0, path_1.relative)(cwd, fileName)}: Emit skipped`);
|
233
233
|
}
|
234
234
|
// Throw an error when requiring `.d.ts` files.
|
235
235
|
if (output.outputFiles.length === 0) {
|
@@ -237,7 +237,7 @@ function register(opts = {}) {
|
|
237
237
|
'This is usually the result of a faulty configuration or import. ' +
|
238
238
|
'Make sure there is a `.js`, `.json` or another executable extension and ' +
|
239
239
|
'loader (attached before `ts-node`) available alongside ' +
|
240
|
-
`\`${path_1.basename(fileName)}\`.`);
|
240
|
+
`\`${(0, path_1.basename)(fileName)}\`.`);
|
241
241
|
}
|
242
242
|
const file = {
|
243
243
|
code: output.outputFiles[1].text,
|
@@ -265,7 +265,7 @@ function register(opts = {}) {
|
|
265
265
|
*/
|
266
266
|
function readConfig(configFileName) {
|
267
267
|
let config = { compilerOptions: {} };
|
268
|
-
const basePath = normalizeSlashes(path_1.dirname(configFileName));
|
268
|
+
const basePath = normalizeSlashes((0, path_1.dirname)(configFileName));
|
269
269
|
// Read project configuration when available.
|
270
270
|
if (configFileName) {
|
271
271
|
const result = ts.readConfigFile(configFileName, readFile);
|
@@ -307,7 +307,7 @@ function register(opts = {}) {
|
|
307
307
|
const output = {
|
308
308
|
code: value,
|
309
309
|
map: Object.assign(JSON.parse(sourceMap), {
|
310
|
-
file: path_1.basename(fileName),
|
310
|
+
file: (0, path_1.basename)(fileName),
|
311
311
|
sources: [fileName],
|
312
312
|
}),
|
313
313
|
};
|
package/dist/utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.serializeBody = exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
|
3
|
+
exports.serializeBody = exports.validateConfiguredRuntime = exports.isEdgeRuntime = exports.EdgeRuntimes = exports.logError = exports.entrypointToOutputPath = exports.getRegExpFromMatchers = void 0;
|
4
4
|
const build_utils_1 = require("@vercel/build-utils");
|
5
5
|
const path_to_regexp_1 = require("path-to-regexp");
|
6
6
|
const path_1 = require("path");
|
@@ -22,9 +22,9 @@ function getRegExpFromMatcher(matcher, index, allMatchers) {
|
|
22
22
|
if (!matcher.startsWith('/')) {
|
23
23
|
throw new Error(`Middleware's \`config.matcher\` values must start with "/". Received: ${matcher}`);
|
24
24
|
}
|
25
|
-
const regExps = [path_to_regexp_1.pathToRegexp(matcher).source];
|
25
|
+
const regExps = [(0, path_to_regexp_1.pathToRegexp)(matcher).source];
|
26
26
|
if (matcher === '/' && !allMatchers.includes('/index')) {
|
27
|
-
regExps.push(path_to_regexp_1.pathToRegexp('/index').source);
|
27
|
+
regExps.push((0, path_to_regexp_1.pathToRegexp)('/index').source);
|
28
28
|
}
|
29
29
|
return regExps;
|
30
30
|
}
|
@@ -39,7 +39,7 @@ function getRegExpFromMatcher(matcher, index, allMatchers) {
|
|
39
39
|
*/
|
40
40
|
function entrypointToOutputPath(entrypoint, zeroConfig) {
|
41
41
|
if (zeroConfig) {
|
42
|
-
const ext = path_1.extname(entrypoint);
|
42
|
+
const ext = (0, path_1.extname)(entrypoint);
|
43
43
|
return entrypoint.slice(0, entrypoint.length - ext.length);
|
44
44
|
}
|
45
45
|
return entrypoint;
|
@@ -52,7 +52,7 @@ function logError(error) {
|
|
52
52
|
// because it points to internals, not user code
|
53
53
|
const errorPrefixLength = 'Error: '.length;
|
54
54
|
const errorMessageLength = errorPrefixLength + error.message.length;
|
55
|
-
build_utils_1.debug(error.stack.substring(errorMessageLength + 1));
|
55
|
+
(0, build_utils_1.debug)(error.stack.substring(errorMessageLength + 1));
|
56
56
|
}
|
57
57
|
}
|
58
58
|
exports.logError = logError;
|
@@ -66,9 +66,21 @@ function isEdgeRuntime(runtime) {
|
|
66
66
|
Object.values(EdgeRuntimes).includes(runtime));
|
67
67
|
}
|
68
68
|
exports.isEdgeRuntime = isEdgeRuntime;
|
69
|
+
const ALLOWED_RUNTIMES = Object.values(EdgeRuntimes);
|
70
|
+
function validateConfiguredRuntime(runtime, entrypoint) {
|
71
|
+
if (runtime) {
|
72
|
+
if (runtime === 'nodejs') {
|
73
|
+
throw new Error(`${entrypoint}: \`config.runtime: "nodejs"\` semantics will evolve soon. Please remove the \`runtime\` key to keep the existing behavior.`);
|
74
|
+
}
|
75
|
+
if (!ALLOWED_RUNTIMES.includes(runtime)) {
|
76
|
+
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`);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
exports.validateConfiguredRuntime = validateConfiguredRuntime;
|
69
81
|
async function serializeBody(request) {
|
70
82
|
return request.method !== 'GET' && request.method !== 'HEAD'
|
71
|
-
? await build_utils_1.streamToBuffer(request)
|
83
|
+
? await (0, build_utils_1.streamToBuffer)(request)
|
72
84
|
: undefined;
|
73
85
|
}
|
74
86
|
exports.serializeBody = serializeBody;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/node",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.14.0",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
@@ -21,19 +21,21 @@
|
|
21
21
|
"dependencies": {
|
22
22
|
"@edge-runtime/vm": "2.0.0",
|
23
23
|
"@types/node": "14.18.33",
|
24
|
-
"@
|
24
|
+
"@types/node-fetch": "2.6.3",
|
25
|
+
"@vercel/build-utils": "6.7.2",
|
25
26
|
"@vercel/error-utils": "1.0.8",
|
26
|
-
"@vercel/
|
27
|
-
"@vercel/static-config": "2.0.16",
|
27
|
+
"@vercel/static-config": "2.0.17",
|
28
28
|
"async-listen": "1.2.0",
|
29
29
|
"edge-runtime": "2.1.4",
|
30
30
|
"esbuild": "0.14.47",
|
31
31
|
"exit-hook": "2.2.1",
|
32
|
-
"node-fetch": "2.6.
|
32
|
+
"node-fetch": "2.6.9",
|
33
33
|
"path-to-regexp": "6.2.1",
|
34
34
|
"ts-morph": "12.0.0",
|
35
35
|
"ts-node": "10.9.1",
|
36
|
-
"typescript": "4.
|
36
|
+
"typescript": "4.9.5",
|
37
|
+
"undici": "5.22.0",
|
38
|
+
"ws": "8.13.0"
|
37
39
|
},
|
38
40
|
"devDependencies": {
|
39
41
|
"@babel/core": "7.5.0",
|
@@ -43,8 +45,7 @@
|
|
43
45
|
"@types/content-type": "1.1.3",
|
44
46
|
"@types/cookie": "0.3.3",
|
45
47
|
"@types/etag": "1.8.0",
|
46
|
-
"@types/jest": "
|
47
|
-
"@types/node-fetch": "^2.6.1",
|
48
|
+
"@types/jest": "29.5.0",
|
48
49
|
"@types/test-listen": "1.1.0",
|
49
50
|
"@vercel/ncc": "0.24.0",
|
50
51
|
"@vercel/nft": "0.22.5",
|
@@ -57,5 +58,5 @@
|
|
57
58
|
"source-map-support": "0.5.12",
|
58
59
|
"test-listen": "1.1.0"
|
59
60
|
},
|
60
|
-
"gitHead": "
|
61
|
+
"gitHead": "b5db13c97035d0eae04a5e075ae74e488d1298d6"
|
61
62
|
}
|
@@ -1,4 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import type { VercelProxyResponse } from '../types';
|
3
|
-
import type { IncomingMessage } from 'http';
|
4
|
-
export declare function createEdgeEventHandler(entrypointFullPath: string, entrypointRelativePath: string, isMiddleware: boolean, isZeroConfig?: boolean): Promise<(request: IncomingMessage) => Promise<VercelProxyResponse>>;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import type { Plugin } from 'esbuild';
|
2
|
-
export declare class NodeCompatBindings {
|
3
|
-
private bindings;
|
4
|
-
use(modulePath: `node:${string}`): string;
|
5
|
-
getContext(): Record<string, unknown>;
|
6
|
-
}
|
7
|
-
/**
|
8
|
-
* Allows to enable Node.js compatibility by detecting namespaced `node:`
|
9
|
-
* imports and producing metadata to bind global variables for each.
|
10
|
-
* It requires from the consumer to add the imports.
|
11
|
-
*/
|
12
|
-
export declare function createNodeCompatPlugin(): {
|
13
|
-
plugin: Plugin;
|
14
|
-
bindings: NodeCompatBindings;
|
15
|
-
};
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import type { Plugin } from 'esbuild';
|
2
|
-
export declare class WasmAssets {
|
3
|
-
private readonly assets;
|
4
|
-
/**
|
5
|
-
* Declare a WebAssembly binding
|
6
|
-
*/
|
7
|
-
declare(filePath: string): Promise<string>;
|
8
|
-
/**
|
9
|
-
* Get an object with the context needed to execute the code
|
10
|
-
* built with the plugin
|
11
|
-
*/
|
12
|
-
getContext(): Promise<Record<string, WebAssembly.Module>>;
|
13
|
-
/**
|
14
|
-
* Allow to iterate easily
|
15
|
-
*/
|
16
|
-
[Symbol.iterator](): IterableIterator<[string, string]>;
|
17
|
-
}
|
18
|
-
export declare function createEdgeWasmPlugin(): {
|
19
|
-
plugin: Plugin;
|
20
|
-
wasmAssets: WasmAssets;
|
21
|
-
};
|
@@ -1,34 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import { Config, Meta } from '@vercel/build-utils';
|
3
|
-
import { ChildProcess } from 'child_process';
|
4
|
-
export declare function forkDevServer(options: {
|
5
|
-
tsConfig: any;
|
6
|
-
config: Config;
|
7
|
-
maybeTranspile: boolean;
|
8
|
-
workPath: string | undefined;
|
9
|
-
isTypeScript: boolean;
|
10
|
-
isEsm: boolean;
|
11
|
-
require_: NodeRequire;
|
12
|
-
entrypoint: string;
|
13
|
-
meta: Meta;
|
14
|
-
/**
|
15
|
-
* A path to the dev-server path. This is used in tests.
|
16
|
-
*/
|
17
|
-
devServerPath?: string;
|
18
|
-
}): ChildProcess & {
|
19
|
-
pid: number;
|
20
|
-
};
|
21
|
-
/**
|
22
|
-
* When launching a dev-server, we want to know its state.
|
23
|
-
* This function will be used to know whether it was exited (due to some error),
|
24
|
-
* or it is listening to new requests, and we can start proxying requests.
|
25
|
-
*/
|
26
|
-
export declare function readMessage(child: ChildProcess): Promise<{
|
27
|
-
state: 'message';
|
28
|
-
value: {
|
29
|
-
port: number;
|
30
|
-
};
|
31
|
-
} | {
|
32
|
-
state: 'exit';
|
33
|
-
value: [number, string | null];
|
34
|
-
}>;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const { pathToFileURL } = require('url');
|
4
|
-
const { isAbsolute } = require('path');
|
5
|
-
|
6
|
-
function dynamicImport(filepath) {
|
7
|
-
const id = isAbsolute(filepath) ? pathToFileURL(filepath).href : filepath;
|
8
|
-
return import(id);
|
9
|
-
}
|
10
|
-
|
11
|
-
module.exports = {
|
12
|
-
dynamicImport,
|
13
|
-
};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import type { ServerResponse, IncomingMessage } from 'http';
|
3
|
-
declare type VercelRequestCookies = {
|
4
|
-
[key: string]: string;
|
5
|
-
};
|
6
|
-
declare type VercelRequestQuery = {
|
7
|
-
[key: string]: string | string[];
|
8
|
-
};
|
9
|
-
declare type VercelRequestBody = any;
|
10
|
-
export declare type VercelRequest = IncomingMessage & {
|
11
|
-
query: VercelRequestQuery;
|
12
|
-
cookies: VercelRequestCookies;
|
13
|
-
body: VercelRequestBody;
|
14
|
-
};
|
15
|
-
export declare type VercelResponse = ServerResponse & {
|
16
|
-
send: (body: any) => VercelResponse;
|
17
|
-
json: (jsonBody: any) => VercelResponse;
|
18
|
-
status: (statusCode: number) => VercelResponse;
|
19
|
-
redirect: (statusOrUrl: string | number, url?: string) => VercelResponse;
|
20
|
-
};
|
21
|
-
export declare function addHelpers(_req: IncomingMessage, _res: ServerResponse): Promise<void>;
|
22
|
-
export {};
|
@@ -1,10 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import type { IncomingMessage } from 'http';
|
3
|
-
import type { VercelProxyResponse } from '../types';
|
4
|
-
declare type ServerlessServerOptions = {
|
5
|
-
shouldAddHelpers: boolean;
|
6
|
-
useRequire: boolean;
|
7
|
-
mode: 'streaming' | 'buffer';
|
8
|
-
};
|
9
|
-
export declare function createServerlessEventHandler(entrypointPath: string, options: ServerlessServerOptions): Promise<(request: IncomingMessage) => Promise<VercelProxyResponse>>;
|
10
|
-
export {};
|
@@ -1,70 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.createServerlessEventHandler = void 0;
|
7
|
-
const helpers_1 = require("./helpers");
|
8
|
-
const http_1 = require("http");
|
9
|
-
// @ts-expect-error
|
10
|
-
const dynamic_import_js_1 = require("./dynamic-import.js");
|
11
|
-
const utils_1 = require("../utils");
|
12
|
-
const build_utils_1 = require("@vercel/build-utils");
|
13
|
-
const exit_hook_1 = __importDefault(require("exit-hook"));
|
14
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
15
|
-
const async_listen_1 = __importDefault(require("async-listen"));
|
16
|
-
async function createServerlessServer(userCode, options) {
|
17
|
-
const server = http_1.createServer(async (req, res) => {
|
18
|
-
if (options.shouldAddHelpers)
|
19
|
-
await helpers_1.addHelpers(req, res);
|
20
|
-
return userCode(req, res);
|
21
|
-
});
|
22
|
-
exit_hook_1.default(() => server.close());
|
23
|
-
return { url: await async_listen_1.default(server) };
|
24
|
-
}
|
25
|
-
async function compileUserCode(entrypointPath, options) {
|
26
|
-
let fn = options.useRequire
|
27
|
-
? require(entrypointPath)
|
28
|
-
: await dynamic_import_js_1.dynamicImport(entrypointPath);
|
29
|
-
/**
|
30
|
-
* In some cases we might have nested default props due to TS => JS
|
31
|
-
*/
|
32
|
-
for (let i = 0; i < 5; i++) {
|
33
|
-
if (fn.default)
|
34
|
-
fn = fn.default;
|
35
|
-
}
|
36
|
-
return fn;
|
37
|
-
}
|
38
|
-
async function createServerlessEventHandler(entrypointPath, options) {
|
39
|
-
const userCode = await compileUserCode(entrypointPath, options);
|
40
|
-
const server = await createServerlessServer(userCode, options);
|
41
|
-
return async function (request) {
|
42
|
-
const url = new URL(request.url ?? '/', server.url);
|
43
|
-
const response = await node_fetch_1.default(url, {
|
44
|
-
body: await utils_1.serializeBody(request),
|
45
|
-
headers: {
|
46
|
-
...request.headers,
|
47
|
-
host: request.headers['x-forwarded-host'],
|
48
|
-
},
|
49
|
-
method: request.method,
|
50
|
-
redirect: 'manual',
|
51
|
-
});
|
52
|
-
let body;
|
53
|
-
if (options.mode === 'streaming') {
|
54
|
-
body = response.body;
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
body = await build_utils_1.streamToBuffer(response.body);
|
58
|
-
response.headers.delete('transfer-encoding');
|
59
|
-
//@ts-expect-error
|
60
|
-
response.headers.set('content-length', body.length);
|
61
|
-
}
|
62
|
-
return {
|
63
|
-
status: response.status,
|
64
|
-
headers: response.headers,
|
65
|
-
body,
|
66
|
-
encoding: 'utf8',
|
67
|
-
};
|
68
|
-
};
|
69
|
-
}
|
70
|
-
exports.createServerlessEventHandler = createServerlessEventHandler;
|