@vercel/node 2.5.0 → 2.5.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.
@@ -210,10 +210,11 @@ async function createEdgeRuntime(params) {
210
210
  initialCode: params.userCode,
211
211
  extend: (context) => {
212
212
  Object.assign(context, {
213
- __dirname: '',
214
- module: {
215
- exports: {},
216
- },
213
+ // This is required for esbuild wrapping logic to resolve
214
+ module: {},
215
+ // This is required for environment variable access.
216
+ // In production, env var access is provided by static analysis
217
+ // so that only the used values are available.
217
218
  process: {
218
219
  env: process.env,
219
220
  },
package/dist/index.js CHANGED
@@ -304374,7 +304374,7 @@ function renameTStoJS(path) {
304374
304374
  }
304375
304375
  return path;
304376
304376
  }
304377
- async function compile(workPath, baseDir, entrypointPath, config, nodeVersion) {
304377
+ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction) {
304378
304378
  const inputFiles = new Set([entrypointPath]);
304379
304379
  const preparedFiles = {};
304380
304380
  const sourceCache = new Map();
@@ -304430,32 +304430,49 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion) {
304430
304430
  ignore: config.excludeFiles,
304431
304431
  async readFile(fsPath) {
304432
304432
  const relPath = path_1.relative(baseDir, fsPath);
304433
+ // If this file has already been read then return from the cache
304433
304434
  const cached = sourceCache.get(relPath);
304434
- if (cached)
304435
- return cached.toString();
304436
- // null represents a not found
304437
- if (cached === null)
304438
- return null;
304435
+ if (typeof cached !== 'undefined')
304436
+ return cached;
304439
304437
  try {
304438
+ let entry;
304440
304439
  let source = fs_1.readFileSync(fsPath);
304441
- if ((fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) ||
304442
- fsPath.endsWith('.tsx')) {
304443
- source = compileTypeScript(fsPath, source.toString());
304444
- }
304445
304440
  const { mode } = fs_1.lstatSync(fsPath);
304446
- let entry;
304447
304441
  if (build_utils_1.isSymbolicLink(mode)) {
304448
304442
  entry = new build_utils_1.FileFsRef({ fsPath, mode });
304449
304443
  }
304450
- else {
304444
+ if (isEdgeFunction && path_1.basename(fsPath) === 'package.json') {
304445
+ // For Edge Functions, patch "main" field to prefer "browser" or "module"
304446
+ const pkgJson = JSON.parse(source.toString());
304447
+ for (const prop of ['browser', 'module']) {
304448
+ const val = pkgJson[prop];
304449
+ if (typeof val === 'string') {
304450
+ build_utils_1.debug(`Using "${prop}" field in ${fsPath}`);
304451
+ pkgJson.main = val;
304452
+ // Create the `entry` with the original so that the output is unmodified
304453
+ if (!entry) {
304454
+ entry = new build_utils_1.FileBlob({ data: source, mode });
304455
+ }
304456
+ // Return the modified `package.json` to nft
304457
+ source = JSON.stringify(pkgJson);
304458
+ break;
304459
+ }
304460
+ }
304461
+ }
304462
+ if ((fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) ||
304463
+ fsPath.endsWith('.tsx')) {
304464
+ source = compileTypeScript(fsPath, source.toString());
304465
+ }
304466
+ if (!entry) {
304451
304467
  entry = new build_utils_1.FileBlob({ data: source, mode });
304452
304468
  }
304453
304469
  fsCache.set(relPath, entry);
304454
304470
  sourceCache.set(relPath, source);
304455
- return source.toString();
304471
+ return source;
304456
304472
  }
304457
304473
  catch (e) {
304458
304474
  if (e.code === 'ENOENT' || e.code === 'EISDIR') {
304475
+ // `null` represents a not found
304459
304476
  sourceCache.set(relPath, null);
304460
304477
  return null;
304461
304478
  }
@@ -304570,14 +304587,6 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
304570
304587
  await build_utils_1.runPackageJsonScript(entrypointFsDirname,
304571
304588
  // Don't consider "build" script since its intended for frontend code
304572
304589
  ['vercel-build', 'now-build'], spawnOpts);
304573
- build_utils_1.debug('Tracing input files...');
304574
- const traceTime = Date.now();
304575
- const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion);
304576
- build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
304577
- let routes;
304578
- let output;
304579
- const handler = renameTStoJS(path_1.relative(baseDir, entrypointPath));
304580
- const outputPath = utils_1.entrypointToOutputPath(entrypoint, config.zeroConfig);
304581
304590
  const isMiddleware = config.middleware === true;
304582
304591
  // Will output an `EdgeFunction` for when `config.middleware = true`
304583
304592
  // (i.e. for root-level "middleware" file) or if source code contains:
@@ -304591,6 +304600,14 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
304591
304600
  }
304592
304601
  isEdgeFunction = staticConfig.runtime === 'experimental-edge';
304593
304602
  }
304603
+ build_utils_1.debug('Tracing input files...');
304604
+ const traceTime = Date.now();
304605
+ const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction);
304606
+ build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
304607
+ let routes;
304608
+ let output;
304609
+ const handler = renameTStoJS(path_1.relative(baseDir, entrypointPath));
304610
+ const outputPath = utils_1.entrypointToOutputPath(entrypoint, config.zeroConfig);
304594
304611
  // Add a `route` for Middleware
304595
304612
  if (isMiddleware) {
304596
304613
  if (!isEdgeFunction) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@types/node": "*",
34
- "@vercel/build-utils": "5.0.5",
34
+ "@vercel/build-utils": "5.0.6",
35
35
  "@vercel/node-bridge": "3.0.0",
36
36
  "@vercel/static-config": "2.0.1",
37
37
  "edge-runtime": "1.0.1",
@@ -61,5 +61,5 @@
61
61
  "source-map-support": "0.5.12",
62
62
  "test-listen": "1.1.0"
63
63
  },
64
- "gitHead": "4773ff5efd84a6dbf698c6f1f0a08718110ffa2d"
64
+ "gitHead": "90c18959498cfa852bc56adffcdd16a8bbcbcce6"
65
65
  }