@sveltejs/adapter-vercel 1.0.0 → 1.0.2

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 (3) hide show
  1. package/README.md +6 -0
  2. package/index.js +54 -56
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -74,6 +74,12 @@ Projects created before a certain date will default to using Node 14, while Svel
74
74
 
75
75
  ![Vercel project settings](settings.png)
76
76
 
77
+ ## Troubleshooting
78
+
79
+ ### Accessing the file system
80
+
81
+ You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content.
82
+
77
83
  ## Changelog
78
84
 
79
85
  [The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-vercel/CHANGELOG.md).
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.2",
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.12"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.0.0"