@sveltejs/adapter-netlify 7.0.1 → 7.1.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.
- package/index.d.ts +26 -7
- package/index.js +44 -32
- package/package.json +3 -3
- package/utils.js +34 -0
package/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Adapter } from '@sveltejs/kit';
|
|
2
2
|
import './ambient.d.ts';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
edge?: boolean;
|
|
4
|
+
/** A Node.js runtime supported by Netlify. */
|
|
5
|
+
export type Runtime = 'nodejs22.x' | 'nodejs24.x';
|
|
6
|
+
|
|
7
|
+
export type AdapterOptions = {
|
|
10
8
|
/**
|
|
11
9
|
* If `true`, your app will be split into multiple functions instead of a single one for the entire app.
|
|
12
10
|
* @default false
|
|
@@ -18,6 +16,27 @@ export interface AdapterOptions {
|
|
|
18
16
|
* @since 7.0.0
|
|
19
17
|
*/
|
|
20
18
|
publish?: string;
|
|
21
|
-
}
|
|
19
|
+
} & (
|
|
20
|
+
| {
|
|
21
|
+
/**
|
|
22
|
+
* If `true`, your app will be deployed as a [Netlify Edge Function](https://docs.netlify.com/build/edge-functions/overview/) rather than the standard Node-based function.
|
|
23
|
+
* Cannot be combined with the `nodeVersion` option.
|
|
24
|
+
*/
|
|
25
|
+
edge: true;
|
|
26
|
+
nodeVersion?: undefined;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
/**
|
|
30
|
+
* If `true`, your app will be deployed as a [Netlify Edge Function](https://docs.netlify.com/build/edge-functions/overview/) rather than the standard Node-based function.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
edge?: false;
|
|
34
|
+
/**
|
|
35
|
+
* The [Node.js version](https://docs.netlify.com/build/functions/configuration/#nodejs-version-for-runtime) used for the serverless function. The supported values are `'nodejs22.x'` and `'nodejs24.x'`.
|
|
36
|
+
* Cannot be combined with `edge: true`.
|
|
37
|
+
*/
|
|
38
|
+
nodeVersion?: Runtime | undefined;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
22
41
|
|
|
23
42
|
export default function plugin(opts?: AdapterOptions): Adapter;
|
package/index.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
/** @import { Builder, RouteDefinition } from '@sveltejs/kit' */
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { join } from 'node:path';
|
|
5
|
+
import { join, posix } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { builtinModules } from 'node:module';
|
|
8
|
-
import process from 'node:process';
|
|
9
8
|
import { build } from 'rolldown';
|
|
10
|
-
import { matches, s } from './utils.js';
|
|
9
|
+
import { matches, resolve_runtime, s } from './utils.js';
|
|
11
10
|
|
|
12
11
|
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
|
|
13
12
|
const adapter_version = pkg.version;
|
|
@@ -15,20 +14,21 @@ const adapter_version = pkg.version;
|
|
|
15
14
|
const name = '@sveltejs/adapter-netlify';
|
|
16
15
|
const files = fileURLToPath(new URL('./files', import.meta.url).href);
|
|
17
16
|
|
|
18
|
-
const edge_set_in_env_var =
|
|
19
|
-
process.env.NETLIFY_SVELTEKIT_USE_EDGE === 'true' ||
|
|
20
|
-
process.env.NETLIFY_SVELTEKIT_USE_EDGE === '1';
|
|
21
|
-
|
|
22
17
|
const netlify_framework_config_path = '.netlify/v1/config.json';
|
|
23
18
|
const netlify_framework_serverless_path = '.netlify/v1/functions';
|
|
24
19
|
const netlify_framework_edge_path = '.netlify/v1/edge-functions';
|
|
25
20
|
|
|
21
|
+
// https://github.com/netlify/cli/issues/12568
|
|
22
|
+
const sveltekit_internal_path = '.netlify/v1/sveltekit';
|
|
23
|
+
|
|
26
24
|
const FUNCTION_PREFIX = 'sveltekit-';
|
|
27
25
|
|
|
28
26
|
// "build" is the default publish directory when Netlify detects SvelteKit
|
|
29
27
|
|
|
30
28
|
/** @type {typeof import('./index.js').default} */
|
|
31
|
-
export default function ({ split = false, edge
|
|
29
|
+
export default function ({ split = false, edge, nodeVersion, publish = 'build' } = {}) {
|
|
30
|
+
const { edge: use_edge, node_version } = resolve_runtime({ edge, nodeVersion });
|
|
31
|
+
|
|
32
32
|
return {
|
|
33
33
|
name,
|
|
34
34
|
async adapt(builder) {
|
|
@@ -89,10 +89,10 @@ export default function ({ split = false, edge = edge_set_in_env_var, publish =
|
|
|
89
89
|
builder.log.minor('Writing Netlify config...');
|
|
90
90
|
write_frameworks_config({ builder });
|
|
91
91
|
|
|
92
|
-
if (
|
|
92
|
+
if (use_edge) {
|
|
93
93
|
await generate_edge_functions({ builder, split });
|
|
94
94
|
} else {
|
|
95
|
-
generate_serverless_functions(builder, split);
|
|
95
|
+
generate_serverless_functions(builder, split, node_version);
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
|
|
@@ -106,30 +106,36 @@ export default function ({ split = false, edge = edge_set_in_env_var, publish =
|
|
|
106
106
|
/**
|
|
107
107
|
* @param {Builder} builder
|
|
108
108
|
* @param {boolean} split
|
|
109
|
+
* @param {string} [node_version]
|
|
109
110
|
*/
|
|
110
|
-
function generate_serverless_functions(builder, split) {
|
|
111
|
+
function generate_serverless_functions(builder, split, node_version) {
|
|
111
112
|
// https://docs.netlify.com/build/frameworks/frameworks-api/#netlifyv1functions
|
|
112
113
|
mkdirSync(netlify_framework_serverless_path, { recursive: true });
|
|
113
114
|
|
|
114
|
-
builder.writeServer(
|
|
115
|
+
builder.writeServer(`${sveltekit_internal_path}/server`);
|
|
115
116
|
|
|
116
|
-
builder.copy(`${files}/serverless.js`,
|
|
117
|
+
builder.copy(`${files}/serverless.js`, `${sveltekit_internal_path}/serverless.js`);
|
|
117
118
|
|
|
118
119
|
builder.log.minor('Generating serverless functions...');
|
|
119
120
|
|
|
120
121
|
if (split) {
|
|
121
122
|
const uuid = crypto.randomUUID();
|
|
122
123
|
for (const fn of get_split_functions(builder)) {
|
|
123
|
-
generate_serverless_function(builder, fn, uuid);
|
|
124
|
+
generate_serverless_function(builder, fn, uuid, node_version);
|
|
124
125
|
}
|
|
125
126
|
} else {
|
|
126
|
-
generate_serverless_function(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
generate_serverless_function(
|
|
128
|
+
builder,
|
|
129
|
+
{
|
|
130
|
+
type: 'singular',
|
|
131
|
+
routes: undefined,
|
|
132
|
+
patterns: ['/*'],
|
|
133
|
+
name: `${FUNCTION_PREFIX}render`,
|
|
134
|
+
display_name: 'SvelteKit server'
|
|
135
|
+
},
|
|
136
|
+
undefined,
|
|
137
|
+
node_version
|
|
138
|
+
);
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
|
|
@@ -245,32 +251,34 @@ function get_split_functions(builder) {
|
|
|
245
251
|
* @param {Builder} builder
|
|
246
252
|
* @param {EntrypointMetadata} fn
|
|
247
253
|
* @param {string} [uuid]
|
|
254
|
+
* @param {string} [node_version]
|
|
248
255
|
*/
|
|
249
|
-
function generate_serverless_function(builder, fn, uuid) {
|
|
250
|
-
builder.generateServerInstance(
|
|
256
|
+
function generate_serverless_function(builder, fn, uuid, node_version) {
|
|
257
|
+
builder.generateServerInstance(`${sveltekit_internal_path}/server-${fn.name}.js`, {
|
|
251
258
|
routes: fn.routes,
|
|
252
|
-
serverDirectory:
|
|
259
|
+
serverDirectory: `${sveltekit_internal_path}/server`
|
|
253
260
|
});
|
|
254
261
|
|
|
255
262
|
const filename = `${netlify_framework_serverless_path}/${fn.name}.mjs`;
|
|
263
|
+
const internal = posix.relative(netlify_framework_serverless_path, sveltekit_internal_path);
|
|
256
264
|
const code = generate_function_module(
|
|
257
265
|
fn.type,
|
|
258
|
-
|
|
259
|
-
|
|
266
|
+
`${internal}/serverless.js`,
|
|
267
|
+
`${internal}/server-${fn.name}.js`,
|
|
260
268
|
uuid
|
|
261
269
|
);
|
|
262
|
-
const config = create_function_config('serverless', fn);
|
|
270
|
+
const config = create_function_config('serverless', fn, node_version);
|
|
263
271
|
|
|
264
272
|
if (builder.hasServerInstrumentationFile()) {
|
|
265
273
|
writeFileSync(filename, code);
|
|
266
274
|
const initializer = builder.createInstrumentationInitializer({
|
|
267
275
|
outputDirectory: netlify_framework_serverless_path,
|
|
268
|
-
serverDirectory:
|
|
276
|
+
serverDirectory: `${sveltekit_internal_path}/server`
|
|
269
277
|
});
|
|
270
278
|
builder.instrument({
|
|
271
279
|
entrypoint: filename,
|
|
272
|
-
instrumentation:
|
|
273
|
-
start:
|
|
280
|
+
instrumentation: `${sveltekit_internal_path}/server/instrumentation.server.js`,
|
|
281
|
+
start: `${sveltekit_internal_path}/${fn.name}.start.mjs`,
|
|
274
282
|
initializer,
|
|
275
283
|
module: {
|
|
276
284
|
generateText: generate_traced_module(config)
|
|
@@ -361,10 +369,11 @@ const generator_string = `@sveltejs/adapter-netlify@${adapter_version}`;
|
|
|
361
369
|
/**
|
|
362
370
|
* @param {'serverless' | 'edge'} runtime
|
|
363
371
|
* @param {EntrypointMetadata} fn
|
|
372
|
+
* @param {string} [node_version]
|
|
364
373
|
* @returns {string}
|
|
365
374
|
*/
|
|
366
|
-
function create_function_config(runtime, fn) {
|
|
367
|
-
/** @type {IntegrationsConfig & { preferStatic?: boolean }} */
|
|
375
|
+
function create_function_config(runtime, fn, node_version) {
|
|
376
|
+
/** @type {IntegrationsConfig & { preferStatic?: boolean; nodeVersion?: string }} */
|
|
368
377
|
const config = {
|
|
369
378
|
name: fn.display_name,
|
|
370
379
|
generator: generator_string,
|
|
@@ -374,6 +383,9 @@ function create_function_config(runtime, fn) {
|
|
|
374
383
|
|
|
375
384
|
if (runtime === 'serverless') {
|
|
376
385
|
config.preferStatic = true;
|
|
386
|
+
if (node_version !== undefined) {
|
|
387
|
+
config.nodeVersion = node_version;
|
|
388
|
+
}
|
|
377
389
|
}
|
|
378
390
|
|
|
379
391
|
return `export const config = ${s(config)};\n`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@netlify/edge-functions": "^4.0.0",
|
|
42
|
-
"@sveltejs/kit": "^3.0
|
|
42
|
+
"@sveltejs/kit": "^3.5.0",
|
|
43
43
|
"@types/deno": "^2.7.0",
|
|
44
44
|
"@types/node": "^22.19.19",
|
|
45
|
-
"@typescript/native": "npm:typescript
|
|
45
|
+
"@typescript/native": "npm:typescript@7.1.0-dev.20261202.1",
|
|
46
46
|
"vitest": "^5.0.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
package/utils.js
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
/** @import { Runtime } from './index.js' */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {unknown} node_version
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
export function parse_node_version(node_version) {
|
|
8
|
+
const match = typeof node_version === 'string' && /^nodejs([1-9]\d*)\.x$/.exec(node_version);
|
|
9
|
+
if (!match) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`@sveltejs/adapter-netlify: Invalid \`nodeVersion\` ${JSON.stringify(node_version)}. Use \`nodejs<major>.x\` with a positive integer major version, for example \`nodejs24.x\`.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return match[1];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {{ edge?: boolean; nodeVersion?: Runtime }} options
|
|
19
|
+
* @returns {{ edge: boolean; node_version?: string }}
|
|
20
|
+
*/
|
|
21
|
+
export function resolve_runtime({ edge, nodeVersion }) {
|
|
22
|
+
if (edge === true && nodeVersion !== undefined) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'@sveltejs/adapter-netlify: Cannot combine `edge: true` with `nodeVersion`. Remove `nodeVersion` to use Edge Functions, or set `edge: false` to use a Node.js runtime.'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (nodeVersion !== undefined) {
|
|
29
|
+
return { edge: false, node_version: parse_node_version(nodeVersion) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { edge: edge ?? false };
|
|
33
|
+
}
|
|
34
|
+
|
|
1
35
|
/**
|
|
2
36
|
* @typedef {{ rest: boolean, dynamic: boolean, content: string }} RouteSegment
|
|
3
37
|
*/
|