@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
@@ -1,44 +1,32 @@
|
|
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.onDevRequest = void 0;
|
7
1
|
const entrypoint = process.env.VERCEL_DEV_ENTRYPOINT;
|
8
2
|
delete process.env.VERCEL_DEV_ENTRYPOINT;
|
9
3
|
if (!entrypoint) {
|
10
4
|
throw new Error('`VERCEL_DEV_ENTRYPOINT` must be defined');
|
11
5
|
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
const
|
21
|
-
const parseConfig = (entryPointPath) =>
|
22
|
-
function getRuntime(runtime, entrypoint) {
|
23
|
-
if (runtime && !utils_1.isEdgeRuntime(runtime)) {
|
24
|
-
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`);
|
25
|
-
}
|
26
|
-
return runtime;
|
27
|
-
}
|
6
|
+
import { join } from 'path';
|
7
|
+
import { createEdgeEventHandler } from './edge-functions/edge-handler.mjs';
|
8
|
+
import { createServer } from 'http';
|
9
|
+
import { createServerlessEventHandler } from './serverless-functions/serverless-handler.mjs';
|
10
|
+
import { isEdgeRuntime, logError, validateConfiguredRuntime } from './utils.js';
|
11
|
+
import { getConfig } from '@vercel/static-config';
|
12
|
+
import { Project } from 'ts-morph';
|
13
|
+
import asyncListen from 'async-listen';
|
14
|
+
const { default: listen } = asyncListen;
|
15
|
+
const parseConfig = (entryPointPath) => getConfig(new Project(), entryPointPath);
|
28
16
|
async function createEventHandler(entrypoint, config, options) {
|
29
|
-
const entrypointPath =
|
17
|
+
const entrypointPath = join(process.cwd(), entrypoint);
|
30
18
|
const staticConfig = parseConfig(entrypointPath);
|
31
|
-
const runtime =
|
19
|
+
const runtime = staticConfig?.runtime;
|
20
|
+
validateConfiguredRuntime(runtime, entrypoint);
|
32
21
|
// `middleware.js`/`middleware.ts` file is always run as
|
33
22
|
// an Edge Function, otherwise needs to be opted-in via
|
34
23
|
// `export const config = { runtime: 'edge' }`
|
35
|
-
if (config.middleware === true ||
|
36
|
-
return
|
24
|
+
if (config.middleware === true || isEdgeRuntime(runtime)) {
|
25
|
+
return createEdgeEventHandler(entrypointPath, entrypoint, config.middleware || false, config.zeroConfig);
|
37
26
|
}
|
38
|
-
return
|
27
|
+
return createServerlessEventHandler(entrypointPath, {
|
39
28
|
mode: staticConfig?.supportsResponseStreaming ? 'streaming' : 'buffer',
|
40
29
|
shouldAddHelpers: options.shouldAddHelpers,
|
41
|
-
useRequire,
|
42
30
|
});
|
43
31
|
}
|
44
32
|
let handleEvent;
|
@@ -49,15 +37,15 @@ async function main() {
|
|
49
37
|
const buildEnv = JSON.parse(process.env.VERCEL_DEV_BUILD_ENV || '{}');
|
50
38
|
delete process.env.VERCEL_DEV_BUILD_ENV;
|
51
39
|
const shouldAddHelpers = !(config.helpers === false || buildEnv.NODEJS_HELPERS === '0');
|
52
|
-
const proxyServer =
|
53
|
-
await
|
40
|
+
const proxyServer = createServer(onDevRequest);
|
41
|
+
await listen(proxyServer, { host: '127.0.0.1', port: 0 });
|
54
42
|
try {
|
55
43
|
handleEvent = await createEventHandler(entrypoint, config, {
|
56
44
|
shouldAddHelpers,
|
57
45
|
});
|
58
46
|
}
|
59
47
|
catch (error) {
|
60
|
-
|
48
|
+
logError(error);
|
61
49
|
handlerEventError = error;
|
62
50
|
}
|
63
51
|
const address = proxyServer.address();
|
@@ -100,8 +88,7 @@ async function onDevRequest(req, res) {
|
|
100
88
|
res.end(error.stack);
|
101
89
|
}
|
102
90
|
}
|
103
|
-
exports.onDevRequest = onDevRequest;
|
104
91
|
main().catch(err => {
|
105
|
-
|
92
|
+
logError(err);
|
106
93
|
process.exit(1);
|
107
94
|
});
|
@@ -1,49 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}) : function(o, v) {
|
12
|
-
o["default"] = v;
|
13
|
-
});
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
-
if (mod && mod.__esModule) return mod;
|
16
|
-
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
-
__setModuleDefault(result, mod);
|
19
|
-
return result;
|
20
|
-
};
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
23
|
-
};
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
25
|
-
exports.createEdgeEventHandler = void 0;
|
26
|
-
const edge_wasm_plugin_1 = require("./edge-wasm-plugin");
|
27
|
-
const edge_node_compat_plugin_1 = require("./edge-node-compat-plugin");
|
28
|
-
const edge_runtime_1 = require("edge-runtime");
|
29
|
-
const node_fetch_1 = __importStar(require("node-fetch"));
|
30
|
-
const error_utils_1 = require("@vercel/error-utils");
|
31
|
-
const fs_1 = require("fs");
|
32
|
-
const utils_1 = require("../utils");
|
33
|
-
const esbuild_1 = __importDefault(require("esbuild"));
|
34
|
-
const exit_hook_1 = __importDefault(require("exit-hook"));
|
35
|
-
const url_1 = require("url");
|
1
|
+
import { createEdgeWasmPlugin } from './edge-wasm-plugin.mjs';
|
2
|
+
import { createNodeCompatPlugin, } from './edge-node-compat-plugin.mjs';
|
3
|
+
import { EdgeRuntime, runServer } from 'edge-runtime';
|
4
|
+
import fetch, { Headers } from 'node-fetch';
|
5
|
+
import { isError } from '@vercel/error-utils';
|
6
|
+
import { readFileSync } from 'fs';
|
7
|
+
import { serializeBody, entrypointToOutputPath, logError } from '../utils.js';
|
8
|
+
import esbuild from 'esbuild';
|
9
|
+
import exitHook from 'exit-hook';
|
10
|
+
import { fileURLToPath } from 'url';
|
36
11
|
const NODE_VERSION_MAJOR = process.version.match(/^v(\d+)\.\d+/)?.[1];
|
37
12
|
const NODE_VERSION_IDENTIFIER = `node${NODE_VERSION_MAJOR}`;
|
38
13
|
if (!NODE_VERSION_MAJOR) {
|
39
14
|
throw new Error(`Unable to determine current node version: process.version=${process.version}`);
|
40
15
|
}
|
41
|
-
const
|
16
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
17
|
+
const edgeHandlerTemplate = readFileSync(`${__dirname}/edge-handler-template.js`);
|
42
18
|
async function compileUserCode(entrypointFullPath, entrypointRelativePath, isMiddleware) {
|
43
|
-
const { wasmAssets, plugin: edgeWasmPlugin } =
|
44
|
-
const nodeCompatPlugin =
|
19
|
+
const { wasmAssets, plugin: edgeWasmPlugin } = createEdgeWasmPlugin();
|
20
|
+
const nodeCompatPlugin = createNodeCompatPlugin();
|
45
21
|
try {
|
46
|
-
const result = await
|
22
|
+
const result = await esbuild.build({
|
47
23
|
// bundling behavior: use globals (like "browser") instead
|
48
24
|
// of "require" statements for core libraries (like "node")
|
49
25
|
platform: 'browser',
|
@@ -60,8 +36,8 @@ async function compileUserCode(entrypointFullPath, entrypointRelativePath, isMid
|
|
60
36
|
name: 'import.meta.url',
|
61
37
|
setup({ onLoad }) {
|
62
38
|
onLoad({ filter: /\.[cm]?js$/, namespace: 'file' }, args => {
|
63
|
-
let code =
|
64
|
-
code = code.replace(/\bimport\.meta\.url\b/g, JSON.stringify(
|
39
|
+
let code = readFileSync(args.path, 'utf8');
|
40
|
+
code = code.replace(/\bimport\.meta\.url\b/g, JSON.stringify(import.meta.url));
|
65
41
|
return { contents: code };
|
66
42
|
});
|
67
43
|
},
|
@@ -108,8 +84,8 @@ async function compileUserCode(entrypointFullPath, entrypointRelativePath, isMid
|
|
108
84
|
// We can't easily show a meaningful stack trace from ncc -> edge-runtime.
|
109
85
|
// So, stick with just the message for now.
|
110
86
|
console.error(`Failed to compile user code for edge runtime.`);
|
111
|
-
if (
|
112
|
-
|
87
|
+
if (isError(error))
|
88
|
+
logError(error);
|
113
89
|
return undefined;
|
114
90
|
}
|
115
91
|
}
|
@@ -120,12 +96,23 @@ async function createEdgeRuntimeServer(params) {
|
|
120
96
|
}
|
121
97
|
const wasmBindings = await params.wasmAssets.getContext();
|
122
98
|
const nodeCompatBindings = params.nodeCompatBindings.getContext();
|
123
|
-
|
99
|
+
let WebSocket;
|
100
|
+
// undici's WebSocket handling is only available in Node.js >= 18
|
101
|
+
// so fallback to using ws for v16
|
102
|
+
if (Number(process.version.split('.')[0].substring(1)) < 18) {
|
103
|
+
// @ts-ignore
|
104
|
+
WebSocket = (await import('ws')).WebSocket;
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
WebSocket = (await import('undici')).WebSocket;
|
108
|
+
}
|
109
|
+
const runtime = new EdgeRuntime({
|
124
110
|
initialCode: params.userCode,
|
125
111
|
extend: context => {
|
126
112
|
Object.assign(context, {
|
127
113
|
// This is required for esbuild wrapping logic to resolve
|
128
114
|
module: {},
|
115
|
+
WebSocket,
|
129
116
|
// This is required for environment variable access.
|
130
117
|
// In production, env var access is provided by static analysis
|
131
118
|
// so that only the used values are available.
|
@@ -140,19 +127,19 @@ async function createEdgeRuntimeServer(params) {
|
|
140
127
|
return context;
|
141
128
|
},
|
142
129
|
});
|
143
|
-
const server = await
|
144
|
-
|
130
|
+
const server = await runServer({ runtime });
|
131
|
+
exitHook(() => server.close());
|
145
132
|
return server;
|
146
133
|
}
|
147
134
|
catch (error) {
|
148
135
|
// We can't easily show a meaningful stack trace from ncc -> edge-runtime.
|
149
136
|
// So, stick with just the message for now.
|
150
137
|
console.error('Failed to instantiate edge runtime.');
|
151
|
-
|
138
|
+
logError(error);
|
152
139
|
return undefined;
|
153
140
|
}
|
154
141
|
}
|
155
|
-
async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath, isMiddleware, isZeroConfig) {
|
142
|
+
export async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath, isMiddleware, isZeroConfig) {
|
156
143
|
const userCode = await compileUserCode(entrypointFullPath, entrypointRelativePath, isMiddleware);
|
157
144
|
const server = await createEdgeRuntimeServer(userCode);
|
158
145
|
return async function (request) {
|
@@ -162,12 +149,13 @@ async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath
|
|
162
149
|
// an error is thrown in the function
|
163
150
|
process.exit(1);
|
164
151
|
}
|
165
|
-
const headers = new
|
166
|
-
const body = await
|
152
|
+
const headers = new Headers(request.headers);
|
153
|
+
const body = await serializeBody(request);
|
167
154
|
if (body !== undefined)
|
168
155
|
headers.set('content-length', String(body.length));
|
169
156
|
const url = new URL(request.url ?? '/', server.url);
|
170
|
-
|
157
|
+
// @ts-expect-error
|
158
|
+
const response = await fetch(url, {
|
171
159
|
body,
|
172
160
|
headers,
|
173
161
|
method: request.method,
|
@@ -193,9 +181,8 @@ async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath
|
|
193
181
|
};
|
194
182
|
};
|
195
183
|
}
|
196
|
-
exports.createEdgeEventHandler = createEdgeEventHandler;
|
197
184
|
function entrypointToRequestPath(entrypointRelativePath, isZeroConfig) {
|
198
185
|
// ensure the path starts with a slash to match conventions used elsewhere,
|
199
186
|
// notably when rendering serverless function paths in error messages
|
200
|
-
return '/' +
|
187
|
+
return '/' + entrypointToOutputPath(entrypointRelativePath, isZeroConfig);
|
201
188
|
}
|
@@ -1,14 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
exports.createNodeCompatPlugin = exports.NodeCompatBindings = void 0;
|
7
|
-
const buffer_1 = __importDefault(require("buffer"));
|
8
|
-
const events_1 = __importDefault(require("events"));
|
9
|
-
const async_hooks_1 = __importDefault(require("async_hooks"));
|
10
|
-
const assert_1 = __importDefault(require("assert"));
|
11
|
-
const util_1 = __importDefault(require("util"));
|
1
|
+
import BufferImplementation from 'buffer';
|
2
|
+
import EventsImplementation from 'events';
|
3
|
+
import AsyncHooksImplementation from 'async_hooks';
|
4
|
+
import AssertImplementation from 'assert';
|
5
|
+
import UtilImplementation from 'util';
|
12
6
|
const SUPPORTED_NODE_MODULES = [
|
13
7
|
'buffer',
|
14
8
|
'events',
|
@@ -26,14 +20,14 @@ function pick(obj, keys) {
|
|
26
20
|
}
|
27
21
|
const NativeModuleMap = () => {
|
28
22
|
const mods = {
|
29
|
-
buffer: pick(
|
23
|
+
buffer: pick(BufferImplementation, [
|
30
24
|
'constants',
|
31
25
|
'kMaxLength',
|
32
26
|
'kStringMaxLength',
|
33
27
|
'Buffer',
|
34
28
|
'SlowBuffer',
|
35
29
|
]),
|
36
|
-
events: pick(
|
30
|
+
events: pick(EventsImplementation, [
|
37
31
|
'EventEmitter',
|
38
32
|
'captureRejectionSymbol',
|
39
33
|
'defaultMaxListeners',
|
@@ -42,11 +36,11 @@ const NativeModuleMap = () => {
|
|
42
36
|
'on',
|
43
37
|
'once',
|
44
38
|
]),
|
45
|
-
async_hooks: pick(
|
39
|
+
async_hooks: pick(AsyncHooksImplementation, [
|
46
40
|
'AsyncLocalStorage',
|
47
41
|
'AsyncResource',
|
48
42
|
]),
|
49
|
-
assert: pick(
|
43
|
+
assert: pick(AssertImplementation, [
|
50
44
|
'AssertionError',
|
51
45
|
'deepEqual',
|
52
46
|
'deepStrictEqual',
|
@@ -67,7 +61,7 @@ const NativeModuleMap = () => {
|
|
67
61
|
'strictEqual',
|
68
62
|
'throws',
|
69
63
|
]),
|
70
|
-
util: pick(
|
64
|
+
util: pick(UtilImplementation, [
|
71
65
|
'_extend',
|
72
66
|
'callbackify',
|
73
67
|
'format',
|
@@ -79,7 +73,7 @@ const NativeModuleMap = () => {
|
|
79
73
|
return new Map(Object.entries(mods));
|
80
74
|
};
|
81
75
|
const NODE_COMPAT_NAMESPACE = 'vercel-node-compat';
|
82
|
-
class NodeCompatBindings {
|
76
|
+
export class NodeCompatBindings {
|
83
77
|
constructor() {
|
84
78
|
this.bindings = new Map();
|
85
79
|
}
|
@@ -107,13 +101,12 @@ class NodeCompatBindings {
|
|
107
101
|
return context;
|
108
102
|
}
|
109
103
|
}
|
110
|
-
exports.NodeCompatBindings = NodeCompatBindings;
|
111
104
|
/**
|
112
105
|
* Allows to enable Node.js compatibility by detecting namespaced `node:`
|
113
106
|
* imports and producing metadata to bind global variables for each.
|
114
107
|
* It requires from the consumer to add the imports.
|
115
108
|
*/
|
116
|
-
function createNodeCompatPlugin() {
|
109
|
+
export function createNodeCompatPlugin() {
|
117
110
|
const bindings = new NodeCompatBindings();
|
118
111
|
const plugin = {
|
119
112
|
name: 'vc-node-compat',
|
@@ -145,4 +138,3 @@ function createNodeCompatPlugin() {
|
|
145
138
|
bindings,
|
146
139
|
};
|
147
140
|
}
|
148
|
-
exports.createNodeCompatPlugin = createNodeCompatPlugin;
|
@@ -1,11 +1,8 @@
|
|
1
|
-
"use strict";
|
2
1
|
// copied from `edge-functions-bridge`:
|
3
2
|
// https://github.com/vercel/runtimes/blob/c076db9e3ce5635f7c2690396e3d9f791a0fd808/packages/edge-functions-bridge/src/get-edge-function-source.ts#L282-L317
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
const fs_1 = require("fs");
|
8
|
-
class WasmAssets {
|
3
|
+
import { createHash } from 'crypto';
|
4
|
+
import { promises as fs } from 'fs';
|
5
|
+
export class WasmAssets {
|
9
6
|
constructor() {
|
10
7
|
this.assets = new Map();
|
11
8
|
}
|
@@ -13,7 +10,7 @@ class WasmAssets {
|
|
13
10
|
* Declare a WebAssembly binding
|
14
11
|
*/
|
15
12
|
async declare(filePath) {
|
16
|
-
const hash = sha1(await
|
13
|
+
const hash = sha1(await fs.readFile(filePath));
|
17
14
|
const name = `wasm_${hash}`;
|
18
15
|
this.assets.set(name, filePath);
|
19
16
|
return name;
|
@@ -27,7 +24,7 @@ class WasmAssets {
|
|
27
24
|
const context = {};
|
28
25
|
for (const [name, filePath] of this.assets) {
|
29
26
|
promises.push((async () => {
|
30
|
-
const bytes = await
|
27
|
+
const bytes = await fs.readFile(filePath);
|
31
28
|
context[name] = await WebAssembly.compile(bytes);
|
32
29
|
})());
|
33
30
|
}
|
@@ -41,8 +38,7 @@ class WasmAssets {
|
|
41
38
|
return this.assets[Symbol.iterator]();
|
42
39
|
}
|
43
40
|
}
|
44
|
-
|
45
|
-
function createEdgeWasmPlugin() {
|
41
|
+
export function createEdgeWasmPlugin() {
|
46
42
|
const wasmAssets = new WasmAssets();
|
47
43
|
const plugin = {
|
48
44
|
name: 'vercel-wasm',
|
@@ -76,7 +72,6 @@ function createEdgeWasmPlugin() {
|
|
76
72
|
};
|
77
73
|
return { plugin, wasmAssets };
|
78
74
|
}
|
79
|
-
exports.createEdgeWasmPlugin = createEdgeWasmPlugin;
|
80
75
|
function sha1(data) {
|
81
|
-
return
|
76
|
+
return createHash('sha1').update(data).digest('hex');
|
82
77
|
}
|
package/dist/fork-dev-server.js
CHANGED
@@ -10,19 +10,17 @@ const child_process_1 = require("child_process");
|
|
10
10
|
const url_1 = require("url");
|
11
11
|
const path_1 = require("path");
|
12
12
|
function forkDevServer(options) {
|
13
|
-
let nodeOptions = process.env.NODE_OPTIONS;
|
13
|
+
let nodeOptions = process.env.NODE_OPTIONS || '';
|
14
|
+
if (!nodeOptions.includes('--no-warnings')) {
|
15
|
+
nodeOptions += ' --no-warnings';
|
16
|
+
}
|
14
17
|
const tsNodePath = options.require_.resolve('ts-node');
|
15
|
-
const esmLoader = url_1.pathToFileURL(path_1.join(tsNodePath, '..', '..', 'esm.mjs'));
|
16
|
-
const cjsLoader = path_1.join(tsNodePath, '..', '..', 'register', 'index.js');
|
17
|
-
const devServerPath = options.devServerPath || path_1.join(__dirname, 'dev-server.
|
18
|
+
const esmLoader = (0, url_1.pathToFileURL)((0, path_1.join)(tsNodePath, '..', '..', 'esm.mjs'));
|
19
|
+
const cjsLoader = (0, path_1.join)(tsNodePath, '..', '..', 'register', 'index.js');
|
20
|
+
const devServerPath = options.devServerPath || (0, path_1.join)(__dirname, 'dev-server.mjs');
|
18
21
|
if (options.maybeTranspile) {
|
19
22
|
if (options.isTypeScript) {
|
20
|
-
|
21
|
-
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
25
|
-
}
|
23
|
+
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
26
24
|
}
|
27
25
|
else {
|
28
26
|
if (options.isEsm) {
|
@@ -36,9 +34,8 @@ function forkDevServer(options) {
|
|
36
34
|
const forkOptions = {
|
37
35
|
cwd: options.workPath,
|
38
36
|
execArgv: [],
|
39
|
-
env: build_utils_1.cloneEnv(process.env, options.meta.env, {
|
37
|
+
env: (0, build_utils_1.cloneEnv)(process.env, options.meta.env, {
|
40
38
|
VERCEL_DEV_ENTRYPOINT: options.entrypoint,
|
41
|
-
VERCEL_DEV_IS_ESM: options.isEsm ? '1' : undefined,
|
42
39
|
VERCEL_DEV_CONFIG: JSON.stringify(options.config),
|
43
40
|
VERCEL_DEV_BUILD_ENV: JSON.stringify(options.meta.buildEnv || {}),
|
44
41
|
TS_NODE_TRANSPILE_ONLY: '1',
|
@@ -48,7 +45,7 @@ function forkDevServer(options) {
|
|
48
45
|
NODE_OPTIONS: nodeOptions,
|
49
46
|
}),
|
50
47
|
};
|
51
|
-
const child = child_process_1.fork(devServerPath, [], forkOptions);
|
48
|
+
const child = (0, child_process_1.fork)(devServerPath, [], forkOptions);
|
52
49
|
checkForPid(devServerPath, child);
|
53
50
|
return child;
|
54
51
|
}
|
@@ -64,7 +61,7 @@ function checkForPid(path, process) {
|
|
64
61
|
* or it is listening to new requests, and we can start proxying requests.
|
65
62
|
*/
|
66
63
|
async function readMessage(child) {
|
67
|
-
const onMessage = once_1.default(child, 'message');
|
64
|
+
const onMessage = (0, once_1.default)(child, 'message');
|
68
65
|
const onExit = once_1.default.spread(child, 'close');
|
69
66
|
const result = await Promise.race([
|
70
67
|
onMessage.then(x => {
|
package/dist/index.d.ts
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
2
3
|
import { ServerResponse, IncomingMessage } from 'http';
|
3
4
|
import type { Headers } from 'node-fetch';
|
4
|
-
export
|
5
|
+
export type VercelRequestCookies = {
|
5
6
|
[key: string]: string;
|
6
7
|
};
|
7
|
-
export
|
8
|
+
export type VercelRequestQuery = {
|
8
9
|
[key: string]: string | string[];
|
9
10
|
};
|
10
|
-
export
|
11
|
-
export
|
11
|
+
export type VercelRequestBody = any;
|
12
|
+
export type VercelRequest = IncomingMessage & {
|
12
13
|
query: VercelRequestQuery;
|
13
14
|
cookies: VercelRequestCookies;
|
14
15
|
body: VercelRequestBody;
|
15
16
|
};
|
16
|
-
export
|
17
|
+
export type VercelResponse = ServerResponse & {
|
17
18
|
send: (body: any) => VercelResponse;
|
18
19
|
json: (jsonBody: any) => VercelResponse;
|
19
20
|
status: (statusCode: number) => VercelResponse;
|
20
21
|
redirect: (statusOrUrl: string | number, url?: string) => VercelResponse;
|
21
22
|
};
|
22
|
-
export
|
23
|
+
export type VercelApiHandler = (req: VercelRequest, res: VercelResponse) => void | Promise<void>;
|
23
24
|
/** @deprecated Use VercelRequestCookies instead. */
|
24
|
-
export
|
25
|
+
export type NowRequestCookies = VercelRequestCookies;
|
25
26
|
/** @deprecated Use VercelRequestQuery instead. */
|
26
|
-
export
|
27
|
+
export type NowRequestQuery = VercelRequestQuery;
|
27
28
|
/** @deprecated Use VercelRequestBody instead. */
|
28
|
-
export
|
29
|
+
export type NowRequestBody = any;
|
29
30
|
/** @deprecated Use VercelRequest instead. */
|
30
|
-
export
|
31
|
+
export type NowRequest = VercelRequest;
|
31
32
|
/** @deprecated Use VercelResponse instead. */
|
32
|
-
export
|
33
|
+
export type NowResponse = VercelResponse;
|
33
34
|
/** @deprecated Use VercelApiHandler instead. */
|
34
|
-
export
|
35
|
+
export type NowApiHandler = VercelApiHandler;
|
35
36
|
export interface VercelProxyResponse {
|
36
37
|
status: number;
|
37
38
|
headers: Headers;
|