@sveltejs/adapter-vercel 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +54 -56
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -25,48 +25,7 @@ const plugin = function ({ external = [], edge, split } = {}) {
25
25
  functions: `${dir}/functions`
26
26
  };
27
27
 
28
- /** @type {any[]} */
29
- const prerendered_redirects = [];
30
-
31
- /** @type {Record<string, { path: string }>} */
32
- const overrides = {};
33
-
34
- for (const [src, redirect] of builder.prerendered.redirects) {
35
- prerendered_redirects.push({
36
- src,
37
- headers: {
38
- Location: redirect.location
39
- },
40
- status: redirect.status
41
- });
42
- }
43
-
44
- for (const [path, page] of builder.prerendered.pages) {
45
- if (path.endsWith('/') && path !== '/') {
46
- prerendered_redirects.push(
47
- { src: path, dest: path.slice(0, -1) },
48
- { src: path.slice(0, -1), status: 308, headers: { Location: path } }
49
- );
50
-
51
- overrides[page.file] = { path: path.slice(1, -1) };
52
- } else {
53
- overrides[page.file] = { path: path.slice(1) };
54
- }
55
- }
56
-
57
- /** @type {any[]} */
58
- const routes = [
59
- ...prerendered_redirects,
60
- {
61
- src: `/${builder.getAppPath()}/.+`,
62
- headers: {
63
- 'cache-control': 'public, immutable, max-age=31536000'
64
- }
65
- },
66
- {
67
- handle: 'filesystem'
68
- }
69
- ];
28
+ const config = static_vercel_config(builder);
70
29
 
71
30
  builder.log.minor('Generating serverless function...');
72
31
 
@@ -97,7 +56,7 @@ const plugin = function ({ external = [], edge, split } = {}) {
97
56
  `nodejs${node_version.major}.x`
98
57
  );
99
58
 
100
- routes.push({ src: pattern, dest: `/${name}` });
59
+ config.routes.push({ src: pattern, dest: `/${name}` });
101
60
  }
102
61
 
103
62
  /**
@@ -142,7 +101,7 @@ const plugin = function ({ external = [], edge, split } = {}) {
142
101
  })
143
102
  );
144
103
 
145
- routes.push({ src: pattern, dest: `/${name}` });
104
+ config.routes.push({ src: pattern, dest: `/${name}` });
146
105
  }
147
106
 
148
107
  const generate_function = edge ? generate_edge_function : generate_serverless_function;
@@ -182,18 +141,7 @@ const plugin = function ({ external = [], edge, split } = {}) {
182
141
 
183
142
  builder.log.minor('Writing routes...');
184
143
 
185
- write(
186
- `${dir}/config.json`,
187
- JSON.stringify(
188
- {
189
- version: 3,
190
- routes,
191
- overrides
192
- },
193
- null,
194
- ' '
195
- )
196
- );
144
+ write(`${dir}/config.json`, JSON.stringify(config, null, ' '));
197
145
  }
198
146
  };
199
147
  };
@@ -225,6 +173,56 @@ function get_node_version() {
225
173
  return { major, full };
226
174
  }
227
175
 
176
+ // This function is duplicated in adapter-static
177
+ /** @param {import('@sveltejs/kit').Builder} builder */
178
+ function static_vercel_config(builder) {
179
+ /** @type {any[]} */
180
+ const prerendered_redirects = [];
181
+
182
+ /** @type {Record<string, { path: string }>} */
183
+ const overrides = {};
184
+
185
+ for (const [src, redirect] of builder.prerendered.redirects) {
186
+ prerendered_redirects.push({
187
+ src,
188
+ headers: {
189
+ Location: redirect.location
190
+ },
191
+ status: redirect.status
192
+ });
193
+ }
194
+
195
+ for (const [path, page] of builder.prerendered.pages) {
196
+ if (path.endsWith('/') && path !== '/') {
197
+ prerendered_redirects.push(
198
+ { src: path, dest: path.slice(0, -1) },
199
+ { src: path.slice(0, -1), status: 308, headers: { Location: path } }
200
+ );
201
+
202
+ overrides[page.file] = { path: path.slice(1, -1) };
203
+ } else {
204
+ overrides[page.file] = { path: path.slice(1) };
205
+ }
206
+ }
207
+
208
+ return {
209
+ version: 3,
210
+ routes: [
211
+ ...prerendered_redirects,
212
+ {
213
+ src: `/${builder.getAppPath()}/immutable/.+`,
214
+ headers: {
215
+ 'cache-control': 'public, immutable, max-age=31536000'
216
+ }
217
+ },
218
+ {
219
+ handle: 'filesystem'
220
+ }
221
+ ],
222
+ overrides
223
+ };
224
+ }
225
+
228
226
  /**
229
227
  * @param {import('@sveltejs/kit').Builder} builder
230
228
  * @param {string} entry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^16.18.6",
31
- "typescript": "^4.9.3",
32
- "@sveltejs/kit": "^1.0.0"
31
+ "typescript": "^4.9.4",
32
+ "@sveltejs/kit": "^1.0.5"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.0.0"