@vercel/redwood 2.0.9 → 2.1.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.
Files changed (2) hide show
  1. package/dist/index.js +22 -15
  2. package/package.json +6 -7
package/dist/index.js CHANGED
@@ -26,6 +26,8 @@ __export(src_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
28
  var import_path = require("path");
29
+ var import_ts_morph = require("ts-morph");
30
+ var import_static_config = require("@vercel/static-config");
29
31
  var import_fs = require("fs");
30
32
  var import_semver = require("semver");
31
33
  var import_build_utils = require("@vercel/build-utils");
@@ -60,12 +62,14 @@ var build = async ({
60
62
  if (!spawnOpts.env) {
61
63
  spawnOpts.env = {};
62
64
  }
63
- const { cliType, lockfileVersion } = await (0, import_build_utils.scanParentDirs)(
64
- entrypointFsDirname
65
+ const { cliType, lockfileVersion, packageJson } = await (0, import_build_utils.scanParentDirs)(
66
+ entrypointFsDirname,
67
+ true
65
68
  );
66
69
  spawnOpts.env = (0, import_build_utils.getEnvForPackageManager)({
67
70
  cliType,
68
71
  lockfileVersion,
72
+ packageJsonPackageManager: packageJson?.packageManager,
69
73
  nodeVersion,
70
74
  env: spawnOpts.env || {}
71
75
  });
@@ -140,20 +144,21 @@ var build = async ({
140
144
  staticOutputs[(0, import_path.relative)(webDistPath, pathWithoutHtmlExtension)] = fileFsRef;
141
145
  }
142
146
  }
143
- const functionFiles = {
144
- ...await (0, import_build_utils.glob)("*.js", apiDistPath),
145
- // top-level
146
- ...await (0, import_build_utils.glob)("*/*.js", apiDistPath)
147
- // one-level deep
148
- };
147
+ const functionFiles = await (0, import_build_utils.glob)("**/*.{js,ts}", apiDistPath);
149
148
  const sourceCache = /* @__PURE__ */ new Map();
150
149
  const fsCache = /* @__PURE__ */ new Map();
150
+ const project = new import_ts_morph.Project();
151
151
  for (const [funcName, fileFsRef] of Object.entries(functionFiles)) {
152
152
  const outputName = (0, import_path.join)(apiDir, (0, import_path.parse)(funcName).name);
153
153
  const absEntrypoint = fileFsRef.fsPath;
154
154
  const relativeEntrypoint = (0, import_path.relative)(workPath, absEntrypoint);
155
155
  const awsLambdaHandler = getAWSLambdaHandler(relativeEntrypoint, "handler");
156
- const sourceFile = relativeEntrypoint.replace("/dist/", "/src/");
156
+ let sourceFile = relativeEntrypoint.replace("/dist/", "/src/");
157
+ const sourceFileBase = (0, import_path.basename)(sourceFile, ".js");
158
+ const sourceFileDir = (0, import_path.dirname)(sourceFile);
159
+ if ((0, import_fs.existsSync)((0, import_path.join)(sourceFileDir, `${sourceFileBase}.ts`))) {
160
+ sourceFile = (0, import_path.join)(sourceFileDir, `${sourceFileBase}.ts`);
161
+ }
157
162
  const { fileList, esmFileList, warnings } = await (0, import_nft.nodeFileTrace)(
158
163
  [absEntrypoint],
159
164
  {
@@ -202,18 +207,20 @@ var build = async ({
202
207
  });
203
208
  }
204
209
  lambdaFiles[(0, import_path.relative)(workPath, fileFsRef.fsPath)] = fileFsRef;
205
- const lambdaOptions = await (0, import_build_utils.getLambdaOptionsFromFunction)({
206
- sourceFile,
207
- config
208
- });
210
+ const staticConfig = (0, import_static_config.getConfig)(project, sourceFile);
211
+ const regions = staticConfig?.regions;
212
+ if (regions && !Array.isArray(regions)) {
213
+ throw new Error('"regions" configuration must be an array');
214
+ }
209
215
  const lambda = new import_build_utils.NodejsLambda({
216
+ ...staticConfig,
217
+ regions,
210
218
  files: lambdaFiles,
211
219
  handler: relativeEntrypoint,
212
220
  runtime: nodeVersion.runtime,
213
221
  shouldAddHelpers: false,
214
222
  shouldAddSourcemapSupport: false,
215
- awsLambdaHandler,
216
- ...lambdaOptions
223
+ awsLambdaHandler
217
224
  });
218
225
  lambdaOutputs[outputName] = lambda;
219
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/redwood",
3
- "version": "2.0.9",
3
+ "version": "2.1.0",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs",
@@ -13,24 +13,23 @@
13
13
  "directory": "packages/redwood"
14
14
  },
15
15
  "dependencies": {
16
- "@vercel/nft": "0.27.0",
16
+ "@vercel/nft": "0.27.2",
17
17
  "@vercel/routing-utils": "3.1.0",
18
- "semver": "6.3.1"
18
+ "@vercel/static-config": "3.0.0",
19
+ "semver": "6.3.1",
20
+ "ts-morph": "12.0.0"
19
21
  },
20
22
  "devDependencies": {
21
23
  "@types/aws-lambda": "8.10.19",
22
24
  "@types/node": "14.18.33",
23
25
  "@types/semver": "6.0.0",
24
- "@vercel/build-utils": "8.1.0",
26
+ "@vercel/build-utils": "8.3.0",
25
27
  "execa": "3.2.0",
26
28
  "fs-extra": "11.1.0",
27
29
  "jest-junit": "16.0.0"
28
30
  },
29
31
  "scripts": {
30
32
  "build": "node ../../utils/build-builder.mjs",
31
- "test-e2e": "pnpm test test/test.js",
32
- "test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail --runInBand",
33
- "test-unit": "pnpm test test/prepare-cache.test.js",
34
33
  "type-check": "tsc --noEmit"
35
34
  }
36
35
  }