@vercel/node 2.9.5 → 2.9.7

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.
@@ -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
@@ -300794,7 +300794,6 @@ exports.BaseFunctionConfigSchema = {
300794
300794
  type: 'object',
300795
300795
  properties: {
300796
300796
  runtime: { type: 'string' },
300797
- cron: { type: 'string' },
300798
300797
  memory: { type: 'number' },
300799
300798
  maxDuration: { type: 'number' },
300800
300799
  regions: {
@@ -300956,6 +300955,95 @@ function compile(filename, source) {
300956
300955
  exports.M = compile;
300957
300956
 
300958
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
+
300959
301047
  /***/ }),
300960
301048
 
300961
301049
  /***/ 39037:
@@ -300991,9 +301079,7 @@ Object.defineProperty(exports, "shouldServe", ({ enumerable: true, get: function
300991
301079
  const static_config_1 = __webpack_require__(16199);
300992
301080
  const typescript_1 = __webpack_require__(39677);
300993
301081
  const utils_1 = __webpack_require__(76136);
300994
- function isPortInfo(v) {
300995
- return v && typeof v.port === 'number';
300996
- }
301082
+ const fork_dev_server_1 = __webpack_require__(31158);
300997
301083
  const ALLOWED_RUNTIMES = ['nodejs', ...Object.values(utils_1.EdgeRuntimes)];
300998
301084
  const require_ = eval('require');
300999
301085
  const tscPath = path_1.resolve(path_1.dirname(require_.resolve('typescript')), '../bin/tsc');
@@ -301244,7 +301330,6 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
301244
301330
  }
301245
301331
  isEdgeFunction = utils_1.isEdgeRuntime(staticConfig.runtime);
301246
301332
  }
301247
- const cron = staticConfig?.cron;
301248
301333
  build_utils_1.debug('Tracing input files...');
301249
301334
  const traceTime = Date.now();
301250
301335
  const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction);
@@ -301278,7 +301363,6 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
301278
301363
  // TODO: remove - these two properties should not be required
301279
301364
  name: outputPath,
301280
301365
  deploymentTarget: 'v8-worker',
301281
- cron,
301282
301366
  });
301283
301367
  }
301284
301368
  else {
@@ -301293,7 +301377,6 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
301293
301377
  shouldAddSourcemapSupport,
301294
301378
  awsLambdaHandler,
301295
301379
  experimentalResponseStreaming,
301296
- cron,
301297
301380
  });
301298
301381
  }
301299
301382
  return { routes, output };
@@ -301334,16 +301417,11 @@ const startDevServer = async (opts) => {
301334
301417
  filename: 'package.json',
301335
301418
  });
301336
301419
  const pkg = pathToPkg ? require_(pathToPkg) : {};
301337
- const tsNodePath = require_.resolve('ts-node');
301338
- const esmLoader = path_1.join(tsNodePath, '..', '..', 'esm.mjs');
301339
- const cjsLoader = path_1.join(tsNodePath, '..', '..', 'register', 'index.js');
301340
301420
  const isTypescript = ['.ts', '.tsx', '.mts', '.cts'].includes(ext);
301341
301421
  const maybeTranspile = isTypescript || !['.cjs', '.mjs'].includes(ext);
301342
301422
  const isEsm = ext === '.mjs' ||
301343
301423
  ext === '.mts' ||
301344
301424
  (pkg.type === 'module' && ['.js', '.ts', '.tsx'].includes(ext));
301345
- const devServerPath = path_1.join(__dirname, 'dev-server.js');
301346
- let nodeOptions = process.env.NODE_OPTIONS;
301347
301425
  let tsConfig = {};
301348
301426
  if (maybeTranspile) {
301349
301427
  const resolveTypescript = (p) => {
@@ -301389,48 +301467,21 @@ const startDevServer = async (opts) => {
301389
301467
  // In prod, we emit outputs to the filesystem.
301390
301468
  // In dev, we don't emit because we use ts-node.
301391
301469
  tsConfig.compilerOptions.noEmit = true;
301392
- if (isTypescript) {
301393
- if (isEsm) {
301394
- nodeOptions = `--loader ${esmLoader} ${nodeOptions || ''}`;
301395
- }
301396
- else {
301397
- nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
301398
- }
301399
- }
301400
- else {
301401
- if (isEsm) {
301402
- // no transform needed because Node.js supports ESM natively
301403
- }
301404
- else {
301405
- nodeOptions = `--require ${cjsLoader} ${nodeOptions || ''}`;
301406
- }
301407
- }
301408
301470
  }
301409
- const child = child_process_1.fork(devServerPath, [], {
301410
- cwd: workPath,
301411
- execArgv: [],
301412
- env: build_utils_1.cloneEnv(process.env, meta.env, {
301413
- VERCEL_DEV_ENTRYPOINT: entrypoint,
301414
- VERCEL_DEV_IS_ESM: isEsm ? '1' : undefined,
301415
- VERCEL_DEV_CONFIG: JSON.stringify(config),
301416
- VERCEL_DEV_BUILD_ENV: JSON.stringify(meta.buildEnv || {}),
301417
- TS_NODE_TRANSPILE_ONLY: '1',
301418
- TS_NODE_COMPILER_OPTIONS: tsConfig?.compilerOptions
301419
- ? JSON.stringify(tsConfig.compilerOptions)
301420
- : undefined,
301421
- NODE_OPTIONS: nodeOptions,
301422
- }),
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,
301423
301481
  });
301424
301482
  const { pid } = child;
301425
- if (!pid) {
301426
- throw new Error(`Child Process has no "pid" when forking: "${devServerPath}"`);
301427
- }
301428
- const onMessage = once_1.default(child, 'message');
301429
- const onExit = once_1.default.spread(child, 'close');
301430
- const result = await Promise.race([onMessage, onExit]);
301431
- onExit.cancel();
301432
- onMessage.cancel();
301433
- if (isPortInfo(result)) {
301483
+ const message = await fork_dev_server_1.readMessage(child);
301484
+ if (message.state === 'message') {
301434
301485
  // "message" event
301435
301486
  if (isTypescript) {
301436
301487
  // Invoke `tsc --noEmit` asynchronously in the background, so
@@ -301439,11 +301490,11 @@ const startDevServer = async (opts) => {
301439
301490
  console.error('Type check for %j failed:', entrypoint, err);
301440
301491
  });
301441
301492
  }
301442
- return { port: result.port, pid };
301493
+ return { port: message.value.port, pid };
301443
301494
  }
301444
301495
  else {
301445
301496
  // Got "exit" event from child process
301446
- const [exitCode, signal] = result;
301497
+ const [exitCode, signal] = message.value;
301447
301498
  const reason = signal ? `"${signal}" signal` : `exit code ${exitCode}`;
301448
301499
  throw new Error(`Function \`${entrypoint}\` failed with ${reason}`);
301449
301500
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
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,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@edge-runtime/vm": "2.0.0",
33
33
  "@types/node": "14.18.33",
34
- "@vercel/build-utils": "6.2.4",
34
+ "@vercel/build-utils": "6.3.1",
35
35
  "@vercel/node-bridge": "3.1.11",
36
- "@vercel/static-config": "2.0.12",
36
+ "@vercel/static-config": "2.0.13",
37
37
  "edge-runtime": "2.0.0",
38
38
  "esbuild": "0.14.47",
39
39
  "exit-hook": "2.2.1",
@@ -64,5 +64,5 @@
64
64
  "test-listen": "1.1.0",
65
65
  "ts-morph": "12.0.0"
66
66
  },
67
- "gitHead": "9308a0fda5e14ee8a07b9a3506e4480f5f67d212"
67
+ "gitHead": "34d199bd4925fab1fb32b8dae507e2383d38493a"
68
68
  }