@vercel/redwood 0.6.0 → 0.6.1-canary.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 +50 -3
  2. package/package.json +5 -4
package/dist/index.js CHANGED
@@ -6,6 +6,9 @@ const fs_1 = require("fs");
6
6
  const semver_1 = require("semver");
7
7
  const build_utils_1 = require("@vercel/build-utils");
8
8
  const nft_1 = require("@vercel/nft");
9
+ const routing_utils_1 = require("@vercel/routing-utils");
10
+ // Do not change this version for RW specific config,
11
+ // it refers to Vercels builder version
9
12
  exports.version = 2;
10
13
  const build = async ({ workPath, files, entrypoint, meta = {}, config = {}, }) => {
11
14
  var _a, _b, _c;
@@ -102,9 +105,36 @@ const build = async ({ workPath, files, entrypoint, meta = {}, config = {}, }) =
102
105
  const apiDistPath = path_1.join(workPath, 'api', 'dist', 'functions');
103
106
  const webDistPath = path_1.join(workPath, 'web', 'dist');
104
107
  const lambdaOutputs = {};
105
- const staticOutputs = await build_utils_1.glob('**', webDistPath);
108
+ // Strip out the .html extensions
109
+ // And populate staticOutputs map with updated paths and contentType
110
+ const webDistFiles = await build_utils_1.glob('**', webDistPath);
111
+ const staticOutputs = {};
112
+ for (const [fileName, fileFsRef] of Object.entries(webDistFiles)) {
113
+ const parsedPath = path_1.parse(fileFsRef.fsPath);
114
+ if (parsedPath.ext !== '.html') {
115
+ // No need to transform non-html files
116
+ staticOutputs[fileName] = fileFsRef;
117
+ }
118
+ else {
119
+ const fileNameWithoutExtension = path_1.basename(fileName, '.html');
120
+ const pathWithoutHtmlExtension = path_1.join(parsedPath.dir, fileNameWithoutExtension);
121
+ fileFsRef.contentType = 'text/html; charset=utf-8';
122
+ // @NOTE: Filename is relative to webDistPath
123
+ // e.g. {'./200': fsRef}
124
+ staticOutputs[path_1.relative(webDistPath, pathWithoutHtmlExtension)] =
125
+ fileFsRef;
126
+ }
127
+ }
106
128
  // Each file in the `functions` dir will become a lambda
107
- const functionFiles = await build_utils_1.glob('*.js', apiDistPath);
129
+ // Also supports nested functions like:
130
+ // ├── functions
131
+ // │ ├── bazinga
132
+ // │ │ ├── bazinga.js
133
+ // │ ├── graphql.js
134
+ const functionFiles = {
135
+ ...(await build_utils_1.glob('*.js', apiDistPath)),
136
+ ...(await build_utils_1.glob('*/*.js', apiDistPath)), // one-level deep
137
+ };
108
138
  const sourceCache = new Map();
109
139
  const fsCache = new Map();
110
140
  for (const [funcName, fileFsRef] of Object.entries(functionFiles)) {
@@ -179,9 +209,26 @@ const build = async ({ workPath, files, entrypoint, meta = {}, config = {}, }) =
179
209
  });
180
210
  lambdaOutputs[outputName] = lambda;
181
211
  }
212
+ // Older versions of redwood did not create 200.html automatically
213
+ // From v0.50.0+ 200.html is always generated as part of web build
214
+ // Note that in builder post-processing, we remove the .html extension
215
+ const fallbackHtmlPage = fs_1.existsSync(path_1.join(webDistPath, '200.html'))
216
+ ? '/200'
217
+ : '/index';
218
+ const defaultRoutesConfig = routing_utils_1.getTransformedRoutes({
219
+ nowConfig: {
220
+ // this makes sure we send back 200.html for unprerendered pages
221
+ rewrites: [{ source: '/(.*)', destination: fallbackHtmlPage }],
222
+ cleanUrls: true,
223
+ trailingSlash: false,
224
+ },
225
+ });
226
+ if (defaultRoutesConfig.error) {
227
+ throw new Error(defaultRoutesConfig.error.message);
228
+ }
182
229
  return {
183
230
  output: { ...staticOutputs, ...lambdaOutputs },
184
- routes: [{ handle: 'filesystem' }, { src: '/.*', dest: '/index.html' }],
231
+ routes: defaultRoutesConfig.routes,
185
232
  };
186
233
  };
187
234
  exports.build = build;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/redwood",
3
- "version": "0.6.0",
3
+ "version": "0.6.1-canary.0",
4
4
  "main": "./dist/index.js",
5
5
  "license": "MIT",
6
6
  "homepage": "https://vercel.com/docs",
@@ -14,18 +14,19 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "node build.js",
17
- "test-integration-once": "jest --env node --verbose --runInBand --bail",
17
+ "test-integration-once": "jest --env node --verbose --runInBand --bail test/test.js",
18
18
  "prepublishOnly": "node build.js"
19
19
  },
20
20
  "dependencies": {
21
21
  "@vercel/nft": "0.17.5",
22
+ "@vercel/routing-utils": "1.13.1-canary.0",
22
23
  "semver": "6.1.1"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/aws-lambda": "8.10.19",
26
27
  "@types/node": "*",
27
28
  "@types/semver": "6.0.0",
28
- "@vercel/build-utils": "2.15.0"
29
+ "@vercel/build-utils": "2.15.1-canary.0"
29
30
  },
30
- "gitHead": "c76781fac978fee923d8180706103bad13ca33a0"
31
+ "gitHead": "c76dfbe8c9e1055113fe7ced8850bca4a64ad232"
31
32
  }