@vercel/node 2.9.6 → 2.9.8
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/fork-dev-server.d.ts +34 -0
- package/dist/fork-dev-server.js +81 -0
- package/dist/index.js +104 -49
- package/package.json +5 -5
@@ -0,0 +1,34 @@
|
|
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
|
+
}>;
|
@@ -0,0 +1,81 @@
|
|
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.readMessage = exports.forkDevServer = void 0;
|
7
|
+
const once_1 = __importDefault(require("@tootallnate/once"));
|
8
|
+
const build_utils_1 = require("@vercel/build-utils");
|
9
|
+
const child_process_1 = require("child_process");
|
10
|
+
const url_1 = require("url");
|
11
|
+
const path_1 = require("path");
|
12
|
+
function forkDevServer(options) {
|
13
|
+
let nodeOptions = process.env.NODE_OPTIONS;
|
14
|
+
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.js');
|
18
|
+
if (options.maybeTranspile) {
|
19
|
+
if (options.isTypeScript) {
|
20
|
+
if (options.isEsm) {
|
21
|
+
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
22
|
+
}
|
23
|
+
else {
|
24
|
+
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
if (options.isEsm) {
|
29
|
+
// no transform needed because Node.js supports ESM natively
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
const forkOptions = {
|
37
|
+
cwd: options.workPath,
|
38
|
+
execArgv: [],
|
39
|
+
env: build_utils_1.cloneEnv(process.env, options.meta.env, {
|
40
|
+
VERCEL_DEV_ENTRYPOINT: options.entrypoint,
|
41
|
+
VERCEL_DEV_IS_ESM: options.isEsm ? '1' : undefined,
|
42
|
+
VERCEL_DEV_CONFIG: JSON.stringify(options.config),
|
43
|
+
VERCEL_DEV_BUILD_ENV: JSON.stringify(options.meta.buildEnv || {}),
|
44
|
+
TS_NODE_TRANSPILE_ONLY: '1',
|
45
|
+
TS_NODE_COMPILER_OPTIONS: options.tsConfig?.compilerOptions
|
46
|
+
? JSON.stringify(options.tsConfig.compilerOptions)
|
47
|
+
: undefined,
|
48
|
+
NODE_OPTIONS: nodeOptions,
|
49
|
+
}),
|
50
|
+
};
|
51
|
+
const child = child_process_1.fork(devServerPath, [], forkOptions);
|
52
|
+
checkForPid(devServerPath, child);
|
53
|
+
return child;
|
54
|
+
}
|
55
|
+
exports.forkDevServer = forkDevServer;
|
56
|
+
function checkForPid(path, process) {
|
57
|
+
if (!process.pid) {
|
58
|
+
throw new Error(`Child Process has no "pid" when forking: "${path}"`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* When launching a dev-server, we want to know its state.
|
63
|
+
* This function will be used to know whether it was exited (due to some error),
|
64
|
+
* or it is listening to new requests, and we can start proxying requests.
|
65
|
+
*/
|
66
|
+
async function readMessage(child) {
|
67
|
+
const onMessage = once_1.default(child, 'message');
|
68
|
+
const onExit = once_1.default.spread(child, 'close');
|
69
|
+
const result = await Promise.race([
|
70
|
+
onMessage.then(x => {
|
71
|
+
return { state: 'message', value: x };
|
72
|
+
}),
|
73
|
+
onExit.then(v => {
|
74
|
+
return { state: 'exit', value: v };
|
75
|
+
}),
|
76
|
+
]);
|
77
|
+
onExit.cancel();
|
78
|
+
onMessage.cancel();
|
79
|
+
return result;
|
80
|
+
}
|
81
|
+
exports.readMessage = readMessage;
|
package/dist/index.js
CHANGED
@@ -300955,6 +300955,95 @@ function compile(filename, source) {
|
|
300955
300955
|
exports.M = compile;
|
300956
300956
|
|
300957
300957
|
|
300958
|
+
/***/ }),
|
300959
|
+
|
300960
|
+
/***/ 31158:
|
300961
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
300962
|
+
|
300963
|
+
"use strict";
|
300964
|
+
|
300965
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
300966
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
300967
|
+
};
|
300968
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
300969
|
+
exports.readMessage = exports.forkDevServer = void 0;
|
300970
|
+
const once_1 = __importDefault(__webpack_require__(51));
|
300971
|
+
const build_utils_1 = __webpack_require__(63445);
|
300972
|
+
const child_process_1 = __webpack_require__(63129);
|
300973
|
+
const url_1 = __webpack_require__(78835);
|
300974
|
+
const path_1 = __webpack_require__(85622);
|
300975
|
+
function forkDevServer(options) {
|
300976
|
+
let nodeOptions = process.env.NODE_OPTIONS;
|
300977
|
+
const tsNodePath = options.require_.resolve('ts-node');
|
300978
|
+
const esmLoader = url_1.pathToFileURL(path_1.join(tsNodePath, '..', '..', 'esm.mjs'));
|
300979
|
+
const cjsLoader = path_1.join(tsNodePath, '..', '..', 'register', 'index.js');
|
300980
|
+
const devServerPath = options.devServerPath || path_1.join(__dirname, 'dev-server.js');
|
300981
|
+
if (options.maybeTranspile) {
|
300982
|
+
if (options.isTypeScript) {
|
300983
|
+
if (options.isEsm) {
|
300984
|
+
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
300985
|
+
}
|
300986
|
+
else {
|
300987
|
+
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
300988
|
+
}
|
300989
|
+
}
|
300990
|
+
else {
|
300991
|
+
if (options.isEsm) {
|
300992
|
+
// no transform needed because Node.js supports ESM natively
|
300993
|
+
}
|
300994
|
+
else {
|
300995
|
+
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
300996
|
+
}
|
300997
|
+
}
|
300998
|
+
}
|
300999
|
+
const forkOptions = {
|
301000
|
+
cwd: options.workPath,
|
301001
|
+
execArgv: [],
|
301002
|
+
env: build_utils_1.cloneEnv(process.env, options.meta.env, {
|
301003
|
+
VERCEL_DEV_ENTRYPOINT: options.entrypoint,
|
301004
|
+
VERCEL_DEV_IS_ESM: options.isEsm ? '1' : undefined,
|
301005
|
+
VERCEL_DEV_CONFIG: JSON.stringify(options.config),
|
301006
|
+
VERCEL_DEV_BUILD_ENV: JSON.stringify(options.meta.buildEnv || {}),
|
301007
|
+
TS_NODE_TRANSPILE_ONLY: '1',
|
301008
|
+
TS_NODE_COMPILER_OPTIONS: options.tsConfig?.compilerOptions
|
301009
|
+
? JSON.stringify(options.tsConfig.compilerOptions)
|
301010
|
+
: undefined,
|
301011
|
+
NODE_OPTIONS: nodeOptions,
|
301012
|
+
}),
|
301013
|
+
};
|
301014
|
+
const child = child_process_1.fork(devServerPath, [], forkOptions);
|
301015
|
+
checkForPid(devServerPath, child);
|
301016
|
+
return child;
|
301017
|
+
}
|
301018
|
+
exports.forkDevServer = forkDevServer;
|
301019
|
+
function checkForPid(path, process) {
|
301020
|
+
if (!process.pid) {
|
301021
|
+
throw new Error(`Child Process has no "pid" when forking: "${path}"`);
|
301022
|
+
}
|
301023
|
+
}
|
301024
|
+
/**
|
301025
|
+
* When launching a dev-server, we want to know its state.
|
301026
|
+
* This function will be used to know whether it was exited (due to some error),
|
301027
|
+
* or it is listening to new requests, and we can start proxying requests.
|
301028
|
+
*/
|
301029
|
+
async function readMessage(child) {
|
301030
|
+
const onMessage = once_1.default(child, 'message');
|
301031
|
+
const onExit = once_1.default.spread(child, 'close');
|
301032
|
+
const result = await Promise.race([
|
301033
|
+
onMessage.then(x => {
|
301034
|
+
return { state: 'message', value: x };
|
301035
|
+
}),
|
301036
|
+
onExit.then(v => {
|
301037
|
+
return { state: 'exit', value: v };
|
301038
|
+
}),
|
301039
|
+
]);
|
301040
|
+
onExit.cancel();
|
301041
|
+
onMessage.cancel();
|
301042
|
+
return result;
|
301043
|
+
}
|
301044
|
+
exports.readMessage = readMessage;
|
301045
|
+
|
301046
|
+
|
300958
301047
|
/***/ }),
|
300959
301048
|
|
300960
301049
|
/***/ 39037:
|
@@ -300990,9 +301079,7 @@ Object.defineProperty(exports, "shouldServe", ({ enumerable: true, get: function
|
|
300990
301079
|
const static_config_1 = __webpack_require__(16199);
|
300991
301080
|
const typescript_1 = __webpack_require__(39677);
|
300992
301081
|
const utils_1 = __webpack_require__(76136);
|
300993
|
-
|
300994
|
-
return v && typeof v.port === 'number';
|
300995
|
-
}
|
301082
|
+
const fork_dev_server_1 = __webpack_require__(31158);
|
300996
301083
|
const ALLOWED_RUNTIMES = ['nodejs', ...Object.values(utils_1.EdgeRuntimes)];
|
300997
301084
|
const require_ = eval('require');
|
300998
301085
|
const tscPath = path_1.resolve(path_1.dirname(require_.resolve('typescript')), '../bin/tsc');
|
@@ -301330,16 +301417,11 @@ const startDevServer = async (opts) => {
|
|
301330
301417
|
filename: 'package.json',
|
301331
301418
|
});
|
301332
301419
|
const pkg = pathToPkg ? require_(pathToPkg) : {};
|
301333
|
-
const tsNodePath = require_.resolve('ts-node');
|
301334
|
-
const esmLoader = path_1.join(tsNodePath, '..', '..', 'esm.mjs');
|
301335
|
-
const cjsLoader = path_1.join(tsNodePath, '..', '..', 'register', 'index.js');
|
301336
301420
|
const isTypescript = ['.ts', '.tsx', '.mts', '.cts'].includes(ext);
|
301337
301421
|
const maybeTranspile = isTypescript || !['.cjs', '.mjs'].includes(ext);
|
301338
301422
|
const isEsm = ext === '.mjs' ||
|
301339
301423
|
ext === '.mts' ||
|
301340
301424
|
(pkg.type === 'module' && ['.js', '.ts', '.tsx'].includes(ext));
|
301341
|
-
const devServerPath = path_1.join(__dirname, 'dev-server.js');
|
301342
|
-
let nodeOptions = process.env.NODE_OPTIONS;
|
301343
301425
|
let tsConfig = {};
|
301344
301426
|
if (maybeTranspile) {
|
301345
301427
|
const resolveTypescript = (p) => {
|
@@ -301385,48 +301467,21 @@ const startDevServer = async (opts) => {
|
|
301385
301467
|
// In prod, we emit outputs to the filesystem.
|
301386
301468
|
// In dev, we don't emit because we use ts-node.
|
301387
301469
|
tsConfig.compilerOptions.noEmit = true;
|
301388
|
-
if (isTypescript) {
|
301389
|
-
if (isEsm) {
|
301390
|
-
nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
|
301391
|
-
}
|
301392
|
-
else {
|
301393
|
-
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
301394
|
-
}
|
301395
|
-
}
|
301396
|
-
else {
|
301397
|
-
if (isEsm) {
|
301398
|
-
// no transform needed because Node.js supports ESM natively
|
301399
|
-
}
|
301400
|
-
else {
|
301401
|
-
nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
|
301402
|
-
}
|
301403
|
-
}
|
301404
301470
|
}
|
301405
|
-
const child =
|
301406
|
-
|
301407
|
-
|
301408
|
-
|
301409
|
-
|
301410
|
-
|
301411
|
-
|
301412
|
-
|
301413
|
-
|
301414
|
-
|
301415
|
-
? JSON.stringify(tsConfig.compilerOptions)
|
301416
|
-
: undefined,
|
301417
|
-
NODE_OPTIONS: nodeOptions,
|
301418
|
-
}),
|
301471
|
+
const child = fork_dev_server_1.forkDevServer({
|
301472
|
+
workPath,
|
301473
|
+
config,
|
301474
|
+
entrypoint,
|
301475
|
+
require_,
|
301476
|
+
isEsm,
|
301477
|
+
isTypeScript: isTypescript,
|
301478
|
+
maybeTranspile,
|
301479
|
+
meta,
|
301480
|
+
tsConfig,
|
301419
301481
|
});
|
301420
301482
|
const { pid } = child;
|
301421
|
-
|
301422
|
-
|
301423
|
-
}
|
301424
|
-
const onMessage = once_1.default(child, 'message');
|
301425
|
-
const onExit = once_1.default.spread(child, 'close');
|
301426
|
-
const result = await Promise.race([onMessage, onExit]);
|
301427
|
-
onExit.cancel();
|
301428
|
-
onMessage.cancel();
|
301429
|
-
if (isPortInfo(result)) {
|
301483
|
+
const message = await fork_dev_server_1.readMessage(child);
|
301484
|
+
if (message.state === 'message') {
|
301430
301485
|
// "message" event
|
301431
301486
|
if (isTypescript) {
|
301432
301487
|
// Invoke `tsc --noEmit` asynchronously in the background, so
|
@@ -301435,11 +301490,11 @@ const startDevServer = async (opts) => {
|
|
301435
301490
|
console.error('Type check for %j failed:', entrypoint, err);
|
301436
301491
|
});
|
301437
301492
|
}
|
301438
|
-
return { port:
|
301493
|
+
return { port: message.value.port, pid };
|
301439
301494
|
}
|
301440
301495
|
else {
|
301441
301496
|
// Got "exit" event from child process
|
301442
|
-
const [exitCode, signal] =
|
301497
|
+
const [exitCode, signal] = message.value;
|
301443
301498
|
const reason = signal ? `"${signal}" signal` : `exit code ${exitCode}`;
|
301444
301499
|
throw new Error(`Function \`${entrypoint}\` failed with ${reason}`);
|
301445
301500
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/node",
|
3
|
-
"version": "2.9.
|
3
|
+
"version": "2.9.8",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
@@ -12,7 +12,7 @@
|
|
12
12
|
"scripts": {
|
13
13
|
"build": "node build",
|
14
14
|
"test": "jest --env node --verbose --bail --runInBand",
|
15
|
-
"test-unit": "pnpm test test/prepare-cache.test.ts test/utils.test.ts",
|
15
|
+
"test-unit": "pnpm test test/prepare-cache.test.ts test/utils.test.ts test/dev.test.ts",
|
16
16
|
"test-e2e": "pnpm test test/integration-*.test.js"
|
17
17
|
},
|
18
18
|
"files": [
|
@@ -31,8 +31,8 @@
|
|
31
31
|
"dependencies": {
|
32
32
|
"@edge-runtime/vm": "2.0.0",
|
33
33
|
"@types/node": "14.18.33",
|
34
|
-
"@vercel/build-utils": "6.3.
|
35
|
-
"@vercel/node-bridge": "3.1.
|
34
|
+
"@vercel/build-utils": "6.3.1",
|
35
|
+
"@vercel/node-bridge": "3.1.12",
|
36
36
|
"@vercel/static-config": "2.0.13",
|
37
37
|
"edge-runtime": "2.0.0",
|
38
38
|
"esbuild": "0.14.47",
|
@@ -64,5 +64,5 @@
|
|
64
64
|
"test-listen": "1.1.0",
|
65
65
|
"ts-morph": "12.0.0"
|
66
66
|
},
|
67
|
-
"gitHead": "
|
67
|
+
"gitHead": "7845bef8268b191f422f493fca6e2772bee7ac86"
|
68
68
|
}
|