@sveltejs/adapter-vercel 6.3.2 → 7.0.0-next.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 (3) hide show
  1. package/index.js +67 -127
  2. package/package.json +11 -13
  3. package/utils.js +4 -6
package/index.js CHANGED
@@ -1,32 +1,45 @@
1
- /** @import { BuildOptions } from 'esbuild' */
2
1
  import fs from 'node:fs';
3
2
  import path from 'node:path';
4
3
  import process from 'node:process';
5
4
  import { fileURLToPath } from 'node:url';
5
+ import { VERSION } from '@sveltejs/kit';
6
6
  import { nodeFileTrace } from '@vercel/nft';
7
- import esbuild from 'esbuild';
7
+ import { build } from 'rolldown';
8
8
  import { get_pathname, parse_isr_expiration, pattern_to_src, resolve_runtime } from './utils.js';
9
- import { VERSION } from '@sveltejs/kit';
10
-
11
- /**
12
- * @template T
13
- * @template {keyof T} K
14
- * @typedef {Partial<Omit<T, K>> & Required<Pick<T, K>>} PartialExcept
15
- */
16
-
17
- /**
18
- * We use a custom `Builder` type here to support the minimum version of SvelteKit.
19
- * @typedef {PartialExcept<import('@sveltejs/kit').Builder, 'log' | 'rimraf' | 'mkdirp' | 'config' | 'prerendered' | 'routes' | 'createEntries' | 'findServerAssets' | 'generateFallback' | 'generateEnvModule' | 'generateManifest' | 'getBuildDirectory' | 'getClientDirectory' | 'getServerDirectory' | 'getAppPath' | 'writeClient' | 'writePrerendered' | 'writePrerendered' | 'writeServer' | 'copy' | 'compress'>} Builder2_4_0
20
- */
21
9
 
22
10
  const name = '@sveltejs/adapter-vercel';
23
11
  const INTERNAL = '![-]'; // this name is guaranteed not to conflict with user routes
24
12
 
25
- const [kit_major, kit_minor] = VERSION.split('.');
26
-
27
13
  // https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules
28
14
  const compatible_node_modules = ['async_hooks', 'events', 'buffer', 'assert', 'util'];
29
15
 
16
+ /** @satisfies {import('rolldown').BuildOptions} */
17
+ const rolldown_config = {
18
+ platform: 'browser',
19
+ resolve: {
20
+ conditionNames: [
21
+ // Vercel's Edge runtime key https://runtime-keys.proposal.wintercg.org/#edge-light
22
+ 'edge-light',
23
+ // re-include these since they are included by default when no conditions are specified
24
+ 'import',
25
+ 'browser',
26
+ 'default'
27
+ ]
28
+ },
29
+ external: [...compatible_node_modules, ...compatible_node_modules.map((id) => `node:${id}`)],
30
+ transform: {
31
+ // minimum Node.js version supported is v14.6.0 that is mapped to ES2019
32
+ // https://edge-runtime.vercel.app/features/polyfills
33
+ // TODO verify the latest ES version the edge runtime supports
34
+ target: 'es2022'
35
+ },
36
+ output: {
37
+ sourcemap: true,
38
+ banner: () => 'globalThis.global = globalThis;',
39
+ codeSplitting: false
40
+ }
41
+ };
42
+
30
43
  /** @type {import('./index.js').default} **/
31
44
  const plugin = function (defaults = {}) {
32
45
  if ('edge' in defaults) {
@@ -35,7 +48,7 @@ const plugin = function (defaults = {}) {
35
48
 
36
49
  return {
37
50
  name,
38
- /** @param {Builder2_4_0} builder */
51
+ /** @param {import('@sveltejs/kit').Builder} builder */
39
52
  async adapt(builder) {
40
53
  if (!builder.routes) {
41
54
  throw new Error(
@@ -87,8 +100,8 @@ const plugin = function (defaults = {}) {
87
100
  MANIFEST: './manifest.js'
88
101
  }
89
102
  });
90
- if (builder.hasServerInstrumentationFile?.()) {
91
- builder.instrument?.({
103
+ if (builder.hasServerInstrumentationFile()) {
104
+ builder.instrument({
92
105
  entrypoint: `${tmp}/index.js`,
93
106
  instrumentation: `${builder.getServerDirectory()}/instrumentation.server.js`
94
107
  });
@@ -139,53 +152,34 @@ const plugin = function (defaults = {}) {
139
152
 
140
153
  try {
141
154
  const outdir = `${dirs.functions}/${name}.func`;
142
- /** @type {BuildOptions} */
143
- const esbuild_config = {
144
- // minimum Node.js version supported is v14.6.0 that is mapped to ES2019
145
- // https://edge-runtime.vercel.app/features/polyfills
146
- // TODO verify the latest ES version the edge runtime supports
147
- target: 'es2020',
148
- bundle: true,
149
- platform: 'browser',
150
- conditions: [
151
- // Vercel's Edge runtime key https://runtime-keys.proposal.wintercg.org/#edge-light
152
- 'edge-light',
153
- // re-include these since they are included by default when no conditions are specified
154
- // https://esbuild.github.io/api/#conditions
155
- 'module'
156
- ],
157
- format: 'esm',
158
- external: [
159
- ...compatible_node_modules,
160
- ...compatible_node_modules.map((id) => `node:${id}`),
161
- ...(config.external || [])
162
- ],
163
- sourcemap: 'linked',
164
- banner: { js: 'globalThis.global = globalThis;' },
165
- loader: {
166
- '.wasm': 'copy',
167
- '.woff': 'copy',
168
- '.woff2': 'copy',
169
- '.ttf': 'copy',
170
- '.eot': 'copy',
171
- '.otf': 'copy'
172
- }
173
- };
174
- const result = await esbuild.build({
175
- entryPoints: [`${tmp}/edge.js`],
176
- outfile: `${outdir}/index.js`,
177
- ...esbuild_config
178
- });
179
155
 
180
- let instrumentation_result;
181
- if (builder.hasServerInstrumentationFile?.()) {
182
- instrumentation_result = await esbuild.build({
183
- entryPoints: [`${builder.getServerDirectory()}/instrumentation.server.js`],
184
- outfile: `${outdir}/instrumentation.server.js`,
185
- ...esbuild_config
186
- });
156
+ const build_config = {
157
+ ...rolldown_config,
158
+ external: [...rolldown_config.external, ...(config.external || [])]
159
+ };
187
160
 
188
- builder.instrument?.({
161
+ await Promise.all([
162
+ build({
163
+ ...build_config,
164
+ input: `${tmp}/edge.js`,
165
+ output: {
166
+ ...build_config.output,
167
+ file: `${outdir}/index.js`
168
+ }
169
+ }),
170
+ builder.hasServerInstrumentationFile() &&
171
+ build({
172
+ ...build_config,
173
+ input: `${builder.getServerDirectory()}/instrumentation.server.js`,
174
+ output: {
175
+ ...build_config.output,
176
+ file: `${outdir}/instrumentation.server.js`
177
+ }
178
+ })
179
+ ]);
180
+
181
+ if (builder.hasServerInstrumentationFile()) {
182
+ builder.instrument({
189
183
  entrypoint: `${outdir}/index.js`,
190
184
  instrumentation: `${outdir}/instrumentation.server.js`,
191
185
  module: {
@@ -193,45 +187,11 @@ const plugin = function (defaults = {}) {
193
187
  }
194
188
  });
195
189
  }
196
-
197
- const warnings = instrumentation_result
198
- ? [...result.warnings, ...instrumentation_result.warnings]
199
- : result.warnings;
200
-
201
- if (warnings.length > 0) {
202
- const formatted = await esbuild.formatMessages(warnings, {
203
- kind: 'warning',
204
- color: true
205
- });
206
-
207
- console.error(formatted.join('\n'));
208
- }
209
190
  } catch (err) {
210
- const error = /** @type {import('esbuild').BuildFailure} */ (err);
211
- for (const e of error.errors) {
212
- for (const node of e.notes) {
213
- const match =
214
- /The package "(.+)" wasn't found on the file system but is built into node/.exec(
215
- node.text
216
- );
217
-
218
- if (match) {
219
- node.text = `Cannot use "${match[1]}" when deploying to Vercel Edge Functions.`;
220
- }
221
- }
222
- }
223
-
224
- const formatted = await esbuild.formatMessages(error.errors, {
225
- kind: 'error',
226
- color: true
227
- });
228
-
229
- console.error(formatted.join('\n'));
230
-
231
191
  throw new Error(
232
- `Bundling with esbuild failed with ${error.errors.length} ${
233
- error.errors.length === 1 ? 'error' : 'errors'
234
- }`
192
+ 'Bundling edge function with Rolldown failed' +
193
+ (err instanceof Error ? `: ${err.message}` : ''),
194
+ { cause: err }
235
195
  );
236
196
  }
237
197
 
@@ -485,8 +445,7 @@ const plugin = function (defaults = {}) {
485
445
  }
486
446
  }
487
447
 
488
- // optional chaining to support older versions that don't have this setting yet
489
- if (builder.config.kit.router?.resolution === 'server') {
448
+ if (builder.config.kit.router.resolution === 'server') {
490
449
  // Create a separate edge function just for server-side route resolution.
491
450
  // By omitting all routes we're ensuring it's small (the routes will still be available
492
451
  // to the route resolution, because it does not rely on the server routing manifest)
@@ -515,18 +474,7 @@ const plugin = function (defaults = {}) {
515
474
  },
516
475
 
517
476
  supports: {
518
- read: ({ config, route }) => {
519
- const runtime = config.runtime ?? defaults.runtime;
520
-
521
- // TODO bump peer dep in next adapter major to simplify this
522
- if (runtime === 'edge' && kit_major === '2' && kit_minor < '25') {
523
- throw new Error(
524
- `${name}: Cannot use \`read\` from \`$app/server\` in route \`${route.id}\` configured with \`runtime: 'edge'\` and SvelteKit < 2.25.0`
525
- );
526
- }
527
-
528
- return true;
529
- },
477
+ read: () => true,
530
478
  instrumentation: () => true
531
479
  }
532
480
  };
@@ -560,7 +508,7 @@ function write(file, data) {
560
508
 
561
509
  // This function is duplicated in adapter-static
562
510
  /**
563
- * @param {Builder2_4_0} builder
511
+ * @param {import('@sveltejs/kit').Builder} builder
564
512
  * @param {import('./index.js').Config} config
565
513
  * @param {string} dir
566
514
  */
@@ -698,7 +646,7 @@ function static_vercel_config(builder, config, dir) {
698
646
  }
699
647
 
700
648
  /**
701
- * @param {Builder2_4_0} builder
649
+ * @param {import('@sveltejs/kit').Builder} builder
702
650
  * @param {string} entry
703
651
  * @param {string} dir
704
652
  * @param {import('./index.js').ServerlessConfig} config
@@ -819,18 +767,10 @@ async function create_function_bundle(builder, entry, dir, config) {
819
767
  }
820
768
 
821
769
  /**
822
- *
823
- * @param {Builder2_4_0} builder
824
- * @param {any} vercel_config
770
+ * @param {import('@sveltejs/kit').Builder} builder
771
+ * @param {any} vercel_config see https://vercel.com/docs/project-configuration/vercel-json
825
772
  */
826
773
  function validate_vercel_json(builder, vercel_config) {
827
- if (builder.routes.length > 0 && !builder.routes[0].api) {
828
- // bail — we're on an older SvelteKit version that doesn't
829
- // populate `route.api.methods`, so we can't check
830
- // to see if cron paths are valid
831
- return;
832
- }
833
-
834
774
  const crons = /** @type {Array<unknown>} */ (
835
775
  Array.isArray(vercel_config?.crons) ? vercel_config.crons : []
836
776
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "6.3.2",
3
+ "version": "7.0.0-next.0",
4
4
  "description": "A SvelteKit adapter that creates a Vercel app",
5
5
  "keywords": [
6
6
  "adapter",
@@ -34,26 +34,24 @@
34
34
  "ambient.d.ts"
35
35
  ],
36
36
  "dependencies": {
37
- "@vercel/nft": "^1.0.0",
38
- "esbuild": "^0.25.4"
37
+ "@vercel/nft": "^1.3.2",
38
+ "rolldown": "^1.0.0-rc.6"
39
39
  },
40
40
  "devDependencies": {
41
- "@sveltejs/vite-plugin-svelte": "^6.0.0-next.3",
42
- "@types/node": "^18.19.119",
43
- "typescript": "^5.3.3",
44
- "vitest": "^4.0.0",
45
- "@sveltejs/kit": "^2.52.2"
41
+ "@types/node": "^22.19.19",
42
+ "typescript": "^6.0.3",
43
+ "vitest": "^4.1.7",
44
+ "@sveltejs/kit": "^3.0.0-next.0"
46
45
  },
47
46
  "peerDependencies": {
48
- "@sveltejs/kit": "^2.4.0"
49
- },
50
- "engines": {
51
- "node": ">=20.0"
47
+ "@sveltejs/kit": "^3.0.0"
52
48
  },
53
49
  "scripts": {
54
50
  "lint": "prettier --check .",
55
51
  "format": "pnpm lint --write",
56
52
  "check": "tsc",
57
- "test": "vitest run"
53
+ "test:unit": "vitest run",
54
+ "test:build": "cd test/apps/basic && pnpm build",
55
+ "test": "pnpm test:unit && pnpm test:build"
58
56
  }
59
57
  }
package/utils.js CHANGED
@@ -11,7 +11,6 @@ export function get_pathname(route) {
11
11
  }
12
12
 
13
13
  const parts = segment.content.split(/\[(.+?)\](?!\])/);
14
- let result = '';
15
14
 
16
15
  if (
17
16
  parts.length === 3 &&
@@ -21,9 +20,9 @@ export function get_pathname(route) {
21
20
  ) {
22
21
  // Special case: segment is a single optional or rest parameter.
23
22
  // In that case we don't prepend a slash (also see comment in pattern_to_src).
24
- result = `$${i++}`;
23
+ return `$${i++}`;
25
24
  } else {
26
- result =
25
+ return (
27
26
  '/' +
28
27
  parts
29
28
  .map((content, j) => {
@@ -33,10 +32,9 @@ export function get_pathname(route) {
33
32
  return content;
34
33
  }
35
34
  })
36
- .join('');
35
+ .join('')
36
+ );
37
37
  }
38
-
39
- return result;
40
38
  })
41
39
  .join('');
42
40