@sveltejs/adapter-vercel 6.3.3 → 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.
- package/index.js +66 -127
- package/package.json +10 -12
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
|
|
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 {
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
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,10 @@ 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
|
-
|
|
233
|
-
|
|
234
|
-
}`,
|
|
192
|
+
'Bundling edge function with Rolldown failed' +
|
|
193
|
+
(err instanceof Error ? `: ${err.message}` : ''),
|
|
235
194
|
{ cause: err }
|
|
236
195
|
);
|
|
237
196
|
}
|
|
@@ -486,8 +445,7 @@ const plugin = function (defaults = {}) {
|
|
|
486
445
|
}
|
|
487
446
|
}
|
|
488
447
|
|
|
489
|
-
|
|
490
|
-
if (builder.config.kit.router?.resolution === 'server') {
|
|
448
|
+
if (builder.config.kit.router.resolution === 'server') {
|
|
491
449
|
// Create a separate edge function just for server-side route resolution.
|
|
492
450
|
// By omitting all routes we're ensuring it's small (the routes will still be available
|
|
493
451
|
// to the route resolution, because it does not rely on the server routing manifest)
|
|
@@ -516,18 +474,7 @@ const plugin = function (defaults = {}) {
|
|
|
516
474
|
},
|
|
517
475
|
|
|
518
476
|
supports: {
|
|
519
|
-
read: (
|
|
520
|
-
const runtime = config.runtime ?? defaults.runtime;
|
|
521
|
-
|
|
522
|
-
// TODO bump peer dep in next adapter major to simplify this
|
|
523
|
-
if (runtime === 'edge' && kit_major === '2' && kit_minor < '25') {
|
|
524
|
-
throw new Error(
|
|
525
|
-
`${name}: Cannot use \`read\` from \`$app/server\` in route \`${route.id}\` configured with \`runtime: 'edge'\` and SvelteKit < 2.25.0`
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return true;
|
|
530
|
-
},
|
|
477
|
+
read: () => true,
|
|
531
478
|
instrumentation: () => true
|
|
532
479
|
}
|
|
533
480
|
};
|
|
@@ -561,7 +508,7 @@ function write(file, data) {
|
|
|
561
508
|
|
|
562
509
|
// This function is duplicated in adapter-static
|
|
563
510
|
/**
|
|
564
|
-
* @param {
|
|
511
|
+
* @param {import('@sveltejs/kit').Builder} builder
|
|
565
512
|
* @param {import('./index.js').Config} config
|
|
566
513
|
* @param {string} dir
|
|
567
514
|
*/
|
|
@@ -699,7 +646,7 @@ function static_vercel_config(builder, config, dir) {
|
|
|
699
646
|
}
|
|
700
647
|
|
|
701
648
|
/**
|
|
702
|
-
* @param {
|
|
649
|
+
* @param {import('@sveltejs/kit').Builder} builder
|
|
703
650
|
* @param {string} entry
|
|
704
651
|
* @param {string} dir
|
|
705
652
|
* @param {import('./index.js').ServerlessConfig} config
|
|
@@ -820,18 +767,10 @@ async function create_function_bundle(builder, entry, dir, config) {
|
|
|
820
767
|
}
|
|
821
768
|
|
|
822
769
|
/**
|
|
823
|
-
*
|
|
824
|
-
* @param {
|
|
825
|
-
* @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
|
|
826
772
|
*/
|
|
827
773
|
function validate_vercel_json(builder, vercel_config) {
|
|
828
|
-
if (builder.routes.length > 0 && !builder.routes[0].api) {
|
|
829
|
-
// bail — we're on an older SvelteKit version that doesn't
|
|
830
|
-
// populate `route.api.methods`, so we can't check
|
|
831
|
-
// to see if cron paths are valid
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
774
|
const crons = /** @type {Array<unknown>} */ (
|
|
836
775
|
Array.isArray(vercel_config?.crons) ? vercel_config.crons : []
|
|
837
776
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-next.0",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Vercel app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -35,25 +35,23 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@vercel/nft": "^1.3.2",
|
|
38
|
-
"
|
|
38
|
+
"rolldown": "^1.0.0-rc.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"@sveltejs/kit": "^2.53.1"
|
|
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": "^
|
|
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
|
}
|