@vercel/node 2.13.0 → 2.14.1

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.
@@ -7,22 +7,17 @@ import { join } from 'path';
7
7
  import { createEdgeEventHandler } from './edge-functions/edge-handler.mjs';
8
8
  import { createServer } from 'http';
9
9
  import { createServerlessEventHandler } from './serverless-functions/serverless-handler.mjs';
10
- import { EdgeRuntimes, isEdgeRuntime, logError } from './utils.js';
10
+ import { isEdgeRuntime, logError, validateConfiguredRuntime } from './utils.js';
11
11
  import { getConfig } from '@vercel/static-config';
12
12
  import { Project } from 'ts-morph';
13
13
  import asyncListen from 'async-listen';
14
14
  const { default: listen } = asyncListen;
15
15
  const parseConfig = (entryPointPath) => getConfig(new Project(), entryPointPath);
16
- function getRuntime(runtime, entrypoint) {
17
- if (runtime && !isEdgeRuntime(runtime)) {
18
- throw new Error(`Invalid function runtime "${runtime}" for "${entrypoint}". Valid runtimes are: ${JSON.stringify(Object.values(EdgeRuntimes))}. Learn more: https://vercel.link/creating-edge-functions`);
19
- }
20
- return runtime;
21
- }
22
16
  async function createEventHandler(entrypoint, config, options) {
23
17
  const entrypointPath = join(process.cwd(), entrypoint);
24
18
  const staticConfig = parseConfig(entrypointPath);
25
- const runtime = getRuntime(staticConfig?.runtime, entrypoint);
19
+ const runtime = staticConfig?.runtime;
20
+ validateConfiguredRuntime(runtime, entrypoint);
26
21
  // `middleware.js`/`middleware.ts` file is always run as
27
22
  // an Edge Function, otherwise needs to be opted-in via
28
23
  // `export const config = { runtime: 'edge' }`
@@ -96,12 +96,15 @@ async function createEdgeRuntimeServer(params) {
96
96
  }
97
97
  const wasmBindings = await params.wasmAssets.getContext();
98
98
  const nodeCompatBindings = params.nodeCompatBindings.getContext();
99
+ // @ts-ignore
100
+ const WebSocket = (await import('ws')).WebSocket;
99
101
  const runtime = new EdgeRuntime({
100
102
  initialCode: params.userCode,
101
103
  extend: context => {
102
104
  Object.assign(context, {
103
105
  // This is required for esbuild wrapping logic to resolve
104
106
  module: {},
107
+ WebSocket,
105
108
  // This is required for environment variable access.
106
109
  // In production, env var access is provided by static analysis
107
110
  // so that only the used values are available.
@@ -10,7 +10,10 @@ 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
18
  const esmLoader = (0, url_1.pathToFileURL)((0, path_1.join)(tsNodePath, '..', '..', 'esm.mjs'));
16
19
  const cjsLoader = (0, path_1.join)(tsNodePath, '..', '..', 'register', 'index.js');
package/dist/index.js CHANGED
@@ -15545,7 +15545,7 @@ function hoistVariables(path, emit, kind = "var") {
15545
15545
 
15546
15546
  /***/ }),
15547
15547
 
15548
- /***/ 92288:
15548
+ /***/ 60732:
15549
15549
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
15550
15550
 
15551
15551
  "use strict";
@@ -15555,8 +15555,11 @@ Object.defineProperty(exports, "__esModule", ({
15555
15555
  value: true
15556
15556
  }));
15557
15557
  exports.default = void 0;
15558
+
15558
15559
  var _assert = __webpack_require__(42357);
15560
+
15559
15561
  var _t = __webpack_require__(32338);
15562
+
15560
15563
  const {
15561
15564
  callExpression,
15562
15565
  cloneNode,
@@ -15571,6 +15574,7 @@ const {
15571
15574
  variableDeclaration,
15572
15575
  variableDeclarator
15573
15576
  } = _t;
15577
+
15574
15578
  class ImportBuilder {
15575
15579
  constructor(importedSource, scope, hub) {
15576
15580
  this._statements = [];
@@ -15580,102 +15584,139 @@ class ImportBuilder {
15580
15584
  this._hub = hub;
15581
15585
  this._importedSource = importedSource;
15582
15586
  }
15587
+
15583
15588
  done() {
15584
15589
  return {
15585
15590
  statements: this._statements,
15586
15591
  resultName: this._resultName
15587
15592
  };
15588
15593
  }
15594
+
15589
15595
  import() {
15590
15596
  this._statements.push(importDeclaration([], stringLiteral(this._importedSource)));
15597
+
15591
15598
  return this;
15592
15599
  }
15600
+
15593
15601
  require() {
15594
15602
  this._statements.push(expressionStatement(callExpression(identifier("require"), [stringLiteral(this._importedSource)])));
15603
+
15595
15604
  return this;
15596
15605
  }
15606
+
15597
15607
  namespace(name = "namespace") {
15598
15608
  const local = this._scope.generateUidIdentifier(name);
15609
+
15599
15610
  const statement = this._statements[this._statements.length - 1];
15611
+
15600
15612
  _assert(statement.type === "ImportDeclaration");
15613
+
15601
15614
  _assert(statement.specifiers.length === 0);
15615
+
15602
15616
  statement.specifiers = [importNamespaceSpecifier(local)];
15603
15617
  this._resultName = cloneNode(local);
15604
15618
  return this;
15605
15619
  }
15620
+
15606
15621
  default(name) {
15607
15622
  const id = this._scope.generateUidIdentifier(name);
15623
+
15608
15624
  const statement = this._statements[this._statements.length - 1];
15625
+
15609
15626
  _assert(statement.type === "ImportDeclaration");
15627
+
15610
15628
  _assert(statement.specifiers.length === 0);
15629
+
15611
15630
  statement.specifiers = [importDefaultSpecifier(id)];
15612
15631
  this._resultName = cloneNode(id);
15613
15632
  return this;
15614
15633
  }
15634
+
15615
15635
  named(name, importName) {
15616
15636
  if (importName === "default") return this.default(name);
15637
+
15617
15638
  const id = this._scope.generateUidIdentifier(name);
15639
+
15618
15640
  const statement = this._statements[this._statements.length - 1];
15641
+
15619
15642
  _assert(statement.type === "ImportDeclaration");
15643
+
15620
15644
  _assert(statement.specifiers.length === 0);
15645
+
15621
15646
  statement.specifiers = [importSpecifier(id, identifier(importName))];
15622
15647
  this._resultName = cloneNode(id);
15623
15648
  return this;
15624
15649
  }
15650
+
15625
15651
  var(name) {
15626
15652
  const id = this._scope.generateUidIdentifier(name);
15653
+
15627
15654
  let statement = this._statements[this._statements.length - 1];
15655
+
15628
15656
  if (statement.type !== "ExpressionStatement") {
15629
15657
  _assert(this._resultName);
15658
+
15630
15659
  statement = expressionStatement(this._resultName);
15660
+
15631
15661
  this._statements.push(statement);
15632
15662
  }
15663
+
15633
15664
  this._statements[this._statements.length - 1] = variableDeclaration("var", [variableDeclarator(id, statement.expression)]);
15634
15665
  this._resultName = cloneNode(id);
15635
15666
  return this;
15636
15667
  }
15668
+
15637
15669
  defaultInterop() {
15638
15670
  return this._interop(this._hub.addHelper("interopRequireDefault"));
15639
15671
  }
15672
+
15640
15673
  wildcardInterop() {
15641
15674
  return this._interop(this._hub.addHelper("interopRequireWildcard"));
15642
15675
  }
15676
+
15643
15677
  _interop(callee) {
15644
15678
  const statement = this._statements[this._statements.length - 1];
15679
+
15645
15680
  if (statement.type === "ExpressionStatement") {
15646
15681
  statement.expression = callExpression(callee, [statement.expression]);
15647
15682
  } else if (statement.type === "VariableDeclaration") {
15648
15683
  _assert(statement.declarations.length === 1);
15684
+
15649
15685
  statement.declarations[0].init = callExpression(callee, [statement.declarations[0].init]);
15650
15686
  } else {
15651
15687
  _assert.fail("Unexpected type.");
15652
15688
  }
15689
+
15653
15690
  return this;
15654
15691
  }
15692
+
15655
15693
  prop(name) {
15656
15694
  const statement = this._statements[this._statements.length - 1];
15695
+
15657
15696
  if (statement.type === "ExpressionStatement") {
15658
15697
  statement.expression = memberExpression(statement.expression, identifier(name));
15659
15698
  } else if (statement.type === "VariableDeclaration") {
15660
15699
  _assert(statement.declarations.length === 1);
15700
+
15661
15701
  statement.declarations[0].init = memberExpression(statement.declarations[0].init, identifier(name));
15662
15702
  } else {
15663
15703
  _assert.fail("Unexpected type:" + statement.type);
15664
15704
  }
15705
+
15665
15706
  return this;
15666
15707
  }
15708
+
15667
15709
  read(name) {
15668
15710
  this._resultName = memberExpression(this._resultName, identifier(name));
15669
15711
  }
15670
- }
15671
- exports.default = ImportBuilder;
15672
15712
 
15673
- //# sourceMappingURL=import-builder.js.map
15713
+ }
15674
15714
 
15715
+ exports.default = ImportBuilder;
15675
15716
 
15676
15717
  /***/ }),
15677
15718
 
15678
- /***/ 37615:
15719
+ /***/ 27340:
15679
15720
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
15680
15721
 
15681
15722
  "use strict";
@@ -15685,14 +15726,20 @@ Object.defineProperty(exports, "__esModule", ({
15685
15726
  value: true
15686
15727
  }));
15687
15728
  exports.default = void 0;
15729
+
15688
15730
  var _assert = __webpack_require__(42357);
15731
+
15689
15732
  var _t = __webpack_require__(32338);
15690
- var _importBuilder = __webpack_require__(92288);
15691
- var _isModule = __webpack_require__(59462);
15733
+
15734
+ var _importBuilder = __webpack_require__(60732);
15735
+
15736
+ var _isModule = __webpack_require__(77901);
15737
+
15692
15738
  const {
15693
15739
  numericLiteral,
15694
15740
  sequenceExpression
15695
15741
  } = _t;
15742
+
15696
15743
  class ImportInjector {
15697
15744
  constructor(path, importedSource, opts) {
15698
15745
  this._defaultOpts = {
@@ -15710,35 +15757,46 @@ class ImportInjector {
15710
15757
  this._hub = programPath.hub;
15711
15758
  this._defaultOpts = this._applyDefaults(importedSource, opts, true);
15712
15759
  }
15760
+
15713
15761
  addDefault(importedSourceIn, opts) {
15714
15762
  return this.addNamed("default", importedSourceIn, opts);
15715
15763
  }
15764
+
15716
15765
  addNamed(importName, importedSourceIn, opts) {
15717
15766
  _assert(typeof importName === "string");
15767
+
15718
15768
  return this._generateImport(this._applyDefaults(importedSourceIn, opts), importName);
15719
15769
  }
15770
+
15720
15771
  addNamespace(importedSourceIn, opts) {
15721
15772
  return this._generateImport(this._applyDefaults(importedSourceIn, opts), null);
15722
15773
  }
15774
+
15723
15775
  addSideEffect(importedSourceIn, opts) {
15724
15776
  return this._generateImport(this._applyDefaults(importedSourceIn, opts), void 0);
15725
15777
  }
15778
+
15726
15779
  _applyDefaults(importedSource, opts, isInit = false) {
15727
15780
  let newOpts;
15781
+
15728
15782
  if (typeof importedSource === "string") {
15729
15783
  newOpts = Object.assign({}, this._defaultOpts, {
15730
15784
  importedSource
15731
15785
  }, opts);
15732
15786
  } else {
15733
15787
  _assert(!opts, "Unexpected secondary arguments.");
15788
+
15734
15789
  newOpts = Object.assign({}, this._defaultOpts, importedSource);
15735
15790
  }
15791
+
15736
15792
  if (!isInit && opts) {
15737
15793
  if (opts.nameHint !== undefined) newOpts.nameHint = opts.nameHint;
15738
15794
  if (opts.blockHoist !== undefined) newOpts.blockHoist = opts.blockHoist;
15739
15795
  }
15796
+
15740
15797
  return newOpts;
15741
15798
  }
15799
+
15742
15800
  _generateImport(opts, importName) {
15743
15801
  const isDefault = importName === "default";
15744
15802
  const isNamed = !!importName && !isDefault;
@@ -15758,15 +15816,20 @@ class ImportInjector {
15758
15816
  const isMod = (0, _isModule.default)(this._programPath);
15759
15817
  const isModuleForNode = isMod && importingInterop === "node";
15760
15818
  const isModuleForBabel = isMod && importingInterop === "babel";
15819
+
15761
15820
  if (importPosition === "after" && !isMod) {
15762
15821
  throw new Error(`"importPosition": "after" is only supported in modules`);
15763
15822
  }
15823
+
15764
15824
  const builder = new _importBuilder.default(importedSource, this._programScope, this._hub);
15825
+
15765
15826
  if (importedType === "es6") {
15766
15827
  if (!isModuleForNode && !isModuleForBabel) {
15767
15828
  throw new Error("Cannot import an ES6 module from CommonJS");
15768
15829
  }
15830
+
15769
15831
  builder.import();
15832
+
15770
15833
  if (isNamespace) {
15771
15834
  builder.namespace(nameHint || importedSource);
15772
15835
  } else if (isDefault || isNamed) {
@@ -15779,6 +15842,7 @@ class ImportInjector {
15779
15842
  name = name !== "default" ? name : importedSource;
15780
15843
  const es6Default = `${importedSource}$es6Default`;
15781
15844
  builder.import();
15845
+
15782
15846
  if (isNamespace) {
15783
15847
  builder.default(es6Default).var(name || importedSource).wildcardInterop();
15784
15848
  } else if (isDefault) {
@@ -15792,6 +15856,7 @@ class ImportInjector {
15792
15856
  }
15793
15857
  } else if (isModuleForBabel) {
15794
15858
  builder.import();
15859
+
15795
15860
  if (isNamespace) {
15796
15861
  builder.namespace(name || importedSource);
15797
15862
  } else if (isDefault || isNamed) {
@@ -15799,6 +15864,7 @@ class ImportInjector {
15799
15864
  }
15800
15865
  } else {
15801
15866
  builder.require();
15867
+
15802
15868
  if (isNamespace) {
15803
15869
  builder.var(name || importedSource).wildcardInterop();
15804
15870
  } else if ((isDefault || isNamed) && ensureLiveReference) {
@@ -15818,6 +15884,7 @@ class ImportInjector {
15818
15884
  } else if (importedInterop === "compiled") {
15819
15885
  if (isModuleForNode) {
15820
15886
  builder.import();
15887
+
15821
15888
  if (isNamespace) {
15822
15889
  builder.default(name || importedSource);
15823
15890
  } else if (isDefault || isNamed) {
@@ -15825,6 +15892,7 @@ class ImportInjector {
15825
15892
  }
15826
15893
  } else if (isModuleForBabel) {
15827
15894
  builder.import();
15895
+
15828
15896
  if (isNamespace) {
15829
15897
  builder.namespace(name || importedSource);
15830
15898
  } else if (isDefault || isNamed) {
@@ -15832,6 +15900,7 @@ class ImportInjector {
15832
15900
  }
15833
15901
  } else {
15834
15902
  builder.require();
15903
+
15835
15904
  if (isNamespace) {
15836
15905
  builder.var(name || importedSource);
15837
15906
  } else if (isDefault || isNamed) {
@@ -15846,8 +15915,10 @@ class ImportInjector {
15846
15915
  if (isDefault && ensureLiveReference) {
15847
15916
  throw new Error("No live reference for commonjs default");
15848
15917
  }
15918
+
15849
15919
  if (isModuleForNode) {
15850
15920
  builder.import();
15921
+
15851
15922
  if (isNamespace) {
15852
15923
  builder.default(name || importedSource);
15853
15924
  } else if (isDefault) {
@@ -15857,6 +15928,7 @@ class ImportInjector {
15857
15928
  }
15858
15929
  } else if (isModuleForBabel) {
15859
15930
  builder.import();
15931
+
15860
15932
  if (isNamespace) {
15861
15933
  builder.default(name || importedSource);
15862
15934
  } else if (isDefault) {
@@ -15866,6 +15938,7 @@ class ImportInjector {
15866
15938
  }
15867
15939
  } else {
15868
15940
  builder.require();
15941
+
15869
15942
  if (isNamespace) {
15870
15943
  builder.var(name || importedSource);
15871
15944
  } else if (isDefault) {
@@ -15881,18 +15954,24 @@ class ImportInjector {
15881
15954
  } else {
15882
15955
  throw new Error(`Unknown importedInterop "${importedInterop}".`);
15883
15956
  }
15957
+
15884
15958
  const {
15885
15959
  statements,
15886
15960
  resultName
15887
15961
  } = builder.done();
15962
+
15888
15963
  this._insertStatements(statements, importPosition, blockHoist);
15964
+
15889
15965
  if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") {
15890
15966
  return sequenceExpression([numericLiteral(0), resultName]);
15891
15967
  }
15968
+
15892
15969
  return resultName;
15893
15970
  }
15971
+
15894
15972
  _insertStatements(statements, importPosition = "before", blockHoist = 3) {
15895
15973
  const body = this._programPath.get("body");
15974
+
15896
15975
  if (importPosition === "after") {
15897
15976
  for (let i = body.length - 1; i >= 0; i--) {
15898
15977
  if (body[i].isImportDeclaration()) {
@@ -15908,22 +15987,23 @@ class ImportInjector {
15908
15987
  const val = p.node._blockHoist;
15909
15988
  return Number.isFinite(val) && val < 4;
15910
15989
  });
15990
+
15911
15991
  if (targetPath) {
15912
15992
  targetPath.insertBefore(statements);
15913
15993
  return;
15914
15994
  }
15915
15995
  }
15996
+
15916
15997
  this._programPath.unshiftContainer("body", statements);
15917
15998
  }
15918
- }
15919
- exports.default = ImportInjector;
15920
15999
 
15921
- //# sourceMappingURL=import-injector.js.map
16000
+ }
15922
16001
 
16002
+ exports.default = ImportInjector;
15923
16003
 
15924
16004
  /***/ }),
15925
16005
 
15926
- /***/ 10742:
16006
+ /***/ 96150:
15927
16007
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
15928
16008
 
15929
16009
  "use strict";
@@ -15948,27 +16028,30 @@ Object.defineProperty(exports, "isModule", ({
15948
16028
  return _isModule.default;
15949
16029
  }
15950
16030
  }));
15951
- var _importInjector = __webpack_require__(37615);
15952
- var _isModule = __webpack_require__(59462);
16031
+
16032
+ var _importInjector = __webpack_require__(27340);
16033
+
16034
+ var _isModule = __webpack_require__(77901);
16035
+
15953
16036
  function addDefault(path, importedSource, opts) {
15954
16037
  return new _importInjector.default(path).addDefault(importedSource, opts);
15955
16038
  }
16039
+
15956
16040
  function addNamed(path, name, importedSource, opts) {
15957
16041
  return new _importInjector.default(path).addNamed(name, importedSource, opts);
15958
16042
  }
16043
+
15959
16044
  function addNamespace(path, importedSource, opts) {
15960
16045
  return new _importInjector.default(path).addNamespace(importedSource, opts);
15961
16046
  }
16047
+
15962
16048
  function addSideEffect(path, importedSource, opts) {
15963
16049
  return new _importInjector.default(path).addSideEffect(importedSource, opts);
15964
16050
  }
15965
16051
 
15966
- //# sourceMappingURL=index.js.map
15967
-
15968
-
15969
16052
  /***/ }),
15970
16053
 
15971
- /***/ 59462:
16054
+ /***/ 77901:
15972
16055
  /***/ ((__unused_webpack_module, exports) => {
15973
16056
 
15974
16057
  "use strict";
@@ -15978,12 +16061,18 @@ Object.defineProperty(exports, "__esModule", ({
15978
16061
  value: true
15979
16062
  }));
15980
16063
  exports.default = isModule;
16064
+
15981
16065
  function isModule(path) {
15982
- return path.node.sourceType === "module";
15983
- }
16066
+ const {
16067
+ sourceType
16068
+ } = path.node;
15984
16069
 
15985
- //# sourceMappingURL=is-module.js.map
16070
+ if (sourceType !== "module" && sourceType !== "script") {
16071
+ throw path.buildCodeFrameError(`Unknown sourceType "${sourceType}", cannot transform.`);
16072
+ }
15986
16073
 
16074
+ return path.node.sourceType === "module";
16075
+ }
15987
16076
 
15988
16077
  /***/ }),
15989
16078
 
@@ -16163,7 +16252,7 @@ exports.wrapInterop = wrapInterop;
16163
16252
  var _assert = __webpack_require__(42357);
16164
16253
  var _t = __webpack_require__(32338);
16165
16254
  var _template = __webpack_require__(82272);
16166
- var _helperModuleImports = __webpack_require__(10742);
16255
+ var _helperModuleImports = __webpack_require__(96150);
16167
16256
  var _rewriteThis = __webpack_require__(52831);
16168
16257
  var _rewriteLiveReferences = __webpack_require__(72337);
16169
16258
  var _normalizeAndLoadMetadata = __webpack_require__(34376);
@@ -139947,7 +140036,10 @@ const child_process_1 = __webpack_require__(63129);
139947
140036
  const url_1 = __webpack_require__(78835);
139948
140037
  const path_1 = __webpack_require__(85622);
139949
140038
  function forkDevServer(options) {
139950
- let nodeOptions = process.env.NODE_OPTIONS;
140039
+ let nodeOptions = process.env.NODE_OPTIONS || '';
140040
+ if (!nodeOptions.includes('--no-warnings')) {
140041
+ nodeOptions += ' --no-warnings';
140042
+ }
139951
140043
  const tsNodePath = options.require_.resolve('ts-node');
139952
140044
  const esmLoader = (0, url_1.pathToFileURL)((0, path_1.join)(tsNodePath, '..', '..', 'esm.mjs'));
139953
140045
  const cjsLoader = (0, path_1.join)(tsNodePath, '..', '..', 'register', 'index.js');
@@ -140053,7 +140145,6 @@ const static_config_1 = __webpack_require__(27167);
140053
140145
  const typescript_1 = __webpack_require__(39677);
140054
140146
  const utils_1 = __webpack_require__(76136);
140055
140147
  const fork_dev_server_1 = __webpack_require__(31158);
140056
- const ALLOWED_RUNTIMES = ['nodejs', ...Object.values(utils_1.EdgeRuntimes)];
140057
140148
  const require_ = eval('require');
140058
140149
  const tscPath = (0, path_1.resolve)((0, path_1.dirname)(require_.resolve('typescript')), '../bin/tsc');
140059
140150
  // eslint-disable-next-line no-useless-escape
@@ -140076,7 +140167,7 @@ function renameTStoJS(path) {
140076
140167
  }
140077
140168
  return path;
140078
140169
  }
140079
- async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction) {
140170
+ async function compile(workPath, baseDir, entrypointPath, config, meta, nodeVersion, isEdgeFunction) {
140080
140171
  const inputFiles = new Set([entrypointPath]);
140081
140172
  const preparedFiles = {};
140082
140173
  const sourceCache = new Map();
@@ -140224,7 +140315,8 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
140224
140315
  !file.endsWith('.tsx') &&
140225
140316
  !file.endsWith('.mjs') &&
140226
140317
  !file.match(libPathRegEx));
140227
- if (esmPaths.length) {
140318
+ const babelCompileEnabled = !isEdgeFunction || process.env.VERCEL_EDGE_NO_BABEL !== '1';
140319
+ if (babelCompileEnabled && esmPaths.length) {
140228
140320
  const babelCompile = __webpack_require__(20007)/* .compile */ .M;
140229
140321
  for (const path of esmPaths) {
140230
140322
  const pathDir = (0, path_1.join)(workPath, (0, path_1.dirname)(path));
@@ -140248,6 +140340,11 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, i
140248
140340
  const { data: source } = await build_utils_1.FileBlob.fromStream({
140249
140341
  stream: preparedFiles[path].toStream(),
140250
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...`);
140251
140348
  const { code, map } = babelCompile(filename, source);
140252
140349
  shouldAddSourcemapSupport = true;
140253
140350
  preparedFiles[path] = new build_utils_1.FileBlob({
@@ -140297,18 +140394,14 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
140297
140394
  let isEdgeFunction = isMiddleware;
140298
140395
  const project = new ts_morph_1.Project();
140299
140396
  const staticConfig = (0, static_config_1.getConfig)(project, entrypointPath);
140300
- if (staticConfig?.runtime) {
140301
- if (!ALLOWED_RUNTIMES.includes(staticConfig.runtime)) {
140302
- throw new Error(`Unsupported "runtime" property in \`config\`: ${JSON.stringify(staticConfig.runtime)} (must be one of: ${JSON.stringify(ALLOWED_RUNTIMES)})`);
140303
- }
140304
- if (staticConfig.runtime === 'nodejs') {
140305
- console.log(`Detected unused static config runtime "nodejs" in "${entrypointPath}"`);
140306
- }
140307
- isEdgeFunction = (0, utils_1.isEdgeRuntime)(staticConfig.runtime);
140397
+ const runtime = staticConfig?.runtime;
140398
+ (0, utils_1.validateConfiguredRuntime)(runtime, entrypoint);
140399
+ if (runtime) {
140400
+ isEdgeFunction = (0, utils_1.isEdgeRuntime)(runtime);
140308
140401
  }
140309
140402
  (0, build_utils_1.debug)('Tracing input files...');
140310
140403
  const traceTime = Date.now();
140311
- const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction);
140404
+ const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, meta, nodeVersion, isEdgeFunction);
140312
140405
  (0, build_utils_1.debug)(`Trace complete [${Date.now() - traceTime}ms]`);
140313
140406
  let routes;
140314
140407
  let output;
@@ -140938,7 +141031,7 @@ function filterDiagnostics(diagnostics, ignore) {
140938
141031
  "use strict";
140939
141032
 
140940
141033
  Object.defineProperty(exports, "__esModule", ({ value: true }));
140941
- 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;
140942
141035
  const build_utils_1 = __webpack_require__(63445);
140943
141036
  const path_to_regexp_1 = __webpack_require__(91344);
140944
141037
  const path_1 = __webpack_require__(85622);
@@ -141004,6 +141097,18 @@ function isEdgeRuntime(runtime) {
141004
141097
  Object.values(EdgeRuntimes).includes(runtime));
141005
141098
  }
141006
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;
141007
141112
  async function serializeBody(request) {
141008
141113
  return request.method !== 'GET' && request.method !== 'HEAD'
141009
141114
  ? await (0, build_utils_1.streamToBuffer)(request)
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");
@@ -66,6 +66,18 @@ 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
83
  ? await (0, build_utils_1.streamToBuffer)(request)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "2.13.0",
3
+ "version": "2.14.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
@@ -33,7 +33,8 @@
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.9.5"
36
+ "typescript": "4.9.5",
37
+ "ws": "8.13.0"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@babel/core": "7.5.0",
@@ -56,5 +57,5 @@
56
57
  "source-map-support": "0.5.12",
57
58
  "test-listen": "1.1.0"
58
59
  },
59
- "gitHead": "2de365f9cfea3ce283d2bf855507c71209f1e3d8"
60
+ "gitHead": "672c1681cc453744e30f985d3e532111d4d7b120"
60
61
  }