@sveltejs/adapter-vercel 1.0.0-next.50 → 1.0.0-next.53

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 +22 -18
  2. package/index.js +37 -10
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -6,7 +6,7 @@ If you're using [adapter-auto](../adapter-auto), you don't need to install this
6
6
 
7
7
  ## Usage
8
8
 
9
- > The `edge` and `split` options depend on the Vercel Build Output API which is currently in beta. For now, you must opt in by visiting `https://vercel.com/svelte/[YOUR_PROJECT]/settings/environment-variables` and adding `ENABLE_VC_BUILD` with the value `1`.
9
+ > The `edge` and `split` options depend on the Vercel Build Output API which is currently in beta. For now, you must opt in by visiting `https://vercel.com/[YOUR_USERNAME]/[YOUR_PROJECT]/settings/environment-variables` and adding `ENABLE_VC_BUILD` with the value `1`.
10
10
 
11
11
  Add `"@sveltejs/adapter-vercel": "next"` to the `devDependencies` in your `package.json` and run `npm install`.
12
12
 
@@ -16,26 +16,30 @@ Then in your `svelte.config.js`:
16
16
  import vercel from '@sveltejs/adapter-vercel';
17
17
 
18
18
  export default {
19
- kit: {
20
- // default options are shown
21
- adapter: vercel({
22
- // if true, will deploy the app using edge functions
23
- // (https://vercel.com/docs/concepts/functions/edge-functions)
24
- // rather than serverless functions
25
- edge: false,
26
-
27
- // an array of dependencies that esbuild should treat
28
- // as external when bundling functions
29
- external: [],
30
-
31
- // if true, will split your app into multiple functions
32
- // instead of creating a single one for the entire app
33
- split: false
34
- })
35
- }
19
+ kit: {
20
+ // default options are shown
21
+ adapter: vercel({
22
+ // if true, will deploy the app using edge functions
23
+ // (https://vercel.com/docs/concepts/functions/edge-functions)
24
+ // rather than serverless functions
25
+ edge: false,
26
+
27
+ // an array of dependencies that esbuild should treat
28
+ // as external when bundling functions
29
+ external: [],
30
+
31
+ // if true, will split your app into multiple functions
32
+ // instead of creating a single one for the entire app
33
+ split: false
34
+ })
35
+ }
36
36
  };
37
37
  ```
38
38
 
39
+ ## Notes
40
+
41
+ Vercel functions contained in the `/api` directory at the project's root will _not_ be included in the deployment — these should be implemented as [endpoints](https://kit.svelte.dev/docs/routing#endpoints) in your SvelteKit app.
42
+
39
43
  ## Changelog
40
44
 
41
45
  [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
@@ -90,7 +90,7 @@ export default function ({ external = [], edge, split } = {}) {
90
90
  await v3(builder, external, edge, split);
91
91
  } else {
92
92
  if (edge || split) {
93
- throw new Error('edge and split options can only be used with ENABLE_VC_BUILD');
93
+ throw new Error('`edge` and `split` options can only be used with ENABLE_VC_BUILD');
94
94
  }
95
95
 
96
96
  await v1(builder, external);
@@ -104,6 +104,8 @@ export default function ({ external = [], edge, split } = {}) {
104
104
  * @param {string[]} external
105
105
  */
106
106
  async function v1(builder, external) {
107
+ const node_version = get_node_version();
108
+
107
109
  const dir = '.vercel_build_output';
108
110
 
109
111
  const tmp = builder.getBuildDirectory('vercel-tmp');
@@ -139,10 +141,11 @@ async function v1(builder, external) {
139
141
  await esbuild.build({
140
142
  entryPoints: [`${tmp}/serverless.js`],
141
143
  outfile: `${dirs.lambda}/index.js`,
142
- target: 'node14',
144
+ target: `node${node_version.full}`,
143
145
  bundle: true,
144
146
  platform: 'node',
145
- external
147
+ external,
148
+ format: 'cjs'
146
149
  });
147
150
 
148
151
  writeFileSync(`${dirs.lambda}/package.json`, JSON.stringify({ type: 'commonjs' }));
@@ -200,6 +203,8 @@ async function v1(builder, external) {
200
203
  * @param {boolean} split
201
204
  */
202
205
  async function v3(builder, external, edge, split) {
206
+ const node_version = get_node_version();
207
+
203
208
  const dir = '.vercel/output';
204
209
 
205
210
  const tmp = builder.getBuildDirectory('vercel-tmp');
@@ -263,7 +268,7 @@ async function v3(builder, external, edge, split) {
263
268
  await esbuild.build({
264
269
  entryPoints: [`${tmp}/serverless.js`],
265
270
  outfile: `${dirs.functions}/${name}.func/index.js`,
266
- target: 'node14',
271
+ target: `node${node_version.full}`,
267
272
  bundle: true,
268
273
  platform: 'node',
269
274
  format: 'cjs',
@@ -273,7 +278,7 @@ async function v3(builder, external, edge, split) {
273
278
  write(
274
279
  `${dirs.functions}/${name}.func/.vc-config.json`,
275
280
  JSON.stringify({
276
- runtime: 'nodejs14.x',
281
+ runtime: `nodejs${node_version.major}.x`,
277
282
  handler: 'index.js',
278
283
  launcherType: 'Nodejs'
279
284
  })
@@ -308,7 +313,7 @@ async function v3(builder, external, edge, split) {
308
313
  await esbuild.build({
309
314
  entryPoints: [`${tmp}/edge.js`],
310
315
  outfile: `${dirs.functions}/${name}.func/index.js`,
311
- target: 'node14',
316
+ target: 'es2020', // TODO verify what the edge runtime supports
312
317
  bundle: true,
313
318
  platform: 'node',
314
319
  format: 'esm',
@@ -324,7 +329,7 @@ async function v3(builder, external, edge, split) {
324
329
  })
325
330
  );
326
331
 
327
- routes.push({ src: pattern, middlewarePath: name });
332
+ routes.push({ src: pattern, dest: `/${name}` });
328
333
  }
329
334
 
330
335
  const generate_function = edge ? generate_edge_function : generate_serverless_function;
@@ -335,10 +340,19 @@ async function v3(builder, external, edge, split) {
335
340
  id: route.pattern.toString(), // TODO is `id` necessary?
336
341
  filter: (other) => route.pattern.toString() === other.pattern.toString(),
337
342
  complete: async (entry) => {
338
- const src = `${route.pattern
343
+ let sliced_pattern = route.pattern
339
344
  .toString()
340
- .slice(1, -2) // remove leading / and trailing $/
341
- .replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
345
+ // remove leading / and trailing $/
346
+ .slice(1, -2)
347
+ // replace escaped \/ with /
348
+ .replace(/\\\//g, '/');
349
+
350
+ // replace the root route "^/" with "^/?"
351
+ if (sliced_pattern === '^/') {
352
+ sliced_pattern = '^/?';
353
+ }
354
+
355
+ const src = `${sliced_pattern}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
342
356
 
343
357
  await generate_function(route.id || 'index', src, entry.generateManifest);
344
358
  }
@@ -385,3 +399,16 @@ function write(file, data) {
385
399
 
386
400
  writeFileSync(file, data);
387
401
  }
402
+
403
+ function get_node_version() {
404
+ const full = process.version.slice(1); // 'v16.5.0' --> '16.5.0'
405
+ const major = parseInt(full.split('.')[0]); // '16.5.0' --> 16
406
+
407
+ if (major < 16) {
408
+ throw new Error(
409
+ `SvelteKit only supports Node.js version 16 or greater (currently using v${full}). Consult the documentation: https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version`
410
+ );
411
+ }
412
+
413
+ return { major, full };
414
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "1.0.0-next.50",
3
+ "version": "1.0.0-next.53",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -22,10 +22,11 @@
22
22
  "index.d.ts"
23
23
  ],
24
24
  "dependencies": {
25
- "esbuild": "^0.14.21"
25
+ "esbuild": "^0.14.29"
26
26
  },
27
27
  "devDependencies": {
28
- "@sveltejs/kit": "1.0.0-next.321",
28
+ "@sveltejs/kit": "1.0.0-next.338",
29
+ "@types/node": "^14.14.20",
29
30
  "typescript": "^4.6.2"
30
31
  },
31
32
  "scripts": {