@sveltejs/adapter-netlify 7.0.1 → 7.1.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.d.ts +26 -7
- package/index.js +30 -22
- package/package.json +2 -2
- 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
|
@@ -5,9 +5,8 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync
|
|
|
5
5
|
import { join } 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,10 +14,6 @@ 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';
|
|
@@ -28,7 +23,9 @@ const FUNCTION_PREFIX = 'sveltekit-';
|
|
|
28
23
|
// "build" is the default publish directory when Netlify detects SvelteKit
|
|
29
24
|
|
|
30
25
|
/** @type {typeof import('./index.js').default} */
|
|
31
|
-
export default function ({ split = false, edge
|
|
26
|
+
export default function ({ split = false, edge, nodeVersion, publish = 'build' } = {}) {
|
|
27
|
+
const { edge: use_edge, node_version } = resolve_runtime({ edge, nodeVersion });
|
|
28
|
+
|
|
32
29
|
return {
|
|
33
30
|
name,
|
|
34
31
|
async adapt(builder) {
|
|
@@ -89,10 +86,10 @@ export default function ({ split = false, edge = edge_set_in_env_var, publish =
|
|
|
89
86
|
builder.log.minor('Writing Netlify config...');
|
|
90
87
|
write_frameworks_config({ builder });
|
|
91
88
|
|
|
92
|
-
if (
|
|
89
|
+
if (use_edge) {
|
|
93
90
|
await generate_edge_functions({ builder, split });
|
|
94
91
|
} else {
|
|
95
|
-
generate_serverless_functions(builder, split);
|
|
92
|
+
generate_serverless_functions(builder, split, node_version);
|
|
96
93
|
}
|
|
97
94
|
},
|
|
98
95
|
|
|
@@ -106,8 +103,9 @@ export default function ({ split = false, edge = edge_set_in_env_var, publish =
|
|
|
106
103
|
/**
|
|
107
104
|
* @param {Builder} builder
|
|
108
105
|
* @param {boolean} split
|
|
106
|
+
* @param {string} [node_version]
|
|
109
107
|
*/
|
|
110
|
-
function generate_serverless_functions(builder, split) {
|
|
108
|
+
function generate_serverless_functions(builder, split, node_version) {
|
|
111
109
|
// https://docs.netlify.com/build/frameworks/frameworks-api/#netlifyv1functions
|
|
112
110
|
mkdirSync(netlify_framework_serverless_path, { recursive: true });
|
|
113
111
|
|
|
@@ -120,16 +118,21 @@ function generate_serverless_functions(builder, split) {
|
|
|
120
118
|
if (split) {
|
|
121
119
|
const uuid = crypto.randomUUID();
|
|
122
120
|
for (const fn of get_split_functions(builder)) {
|
|
123
|
-
generate_serverless_function(builder, fn, uuid);
|
|
121
|
+
generate_serverless_function(builder, fn, uuid, node_version);
|
|
124
122
|
}
|
|
125
123
|
} else {
|
|
126
|
-
generate_serverless_function(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
generate_serverless_function(
|
|
125
|
+
builder,
|
|
126
|
+
{
|
|
127
|
+
type: 'singular',
|
|
128
|
+
routes: undefined,
|
|
129
|
+
patterns: ['/*'],
|
|
130
|
+
name: `${FUNCTION_PREFIX}render`,
|
|
131
|
+
display_name: 'SvelteKit server'
|
|
132
|
+
},
|
|
133
|
+
undefined,
|
|
134
|
+
node_version
|
|
135
|
+
);
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -245,8 +248,9 @@ function get_split_functions(builder) {
|
|
|
245
248
|
* @param {Builder} builder
|
|
246
249
|
* @param {EntrypointMetadata} fn
|
|
247
250
|
* @param {string} [uuid]
|
|
251
|
+
* @param {string} [node_version]
|
|
248
252
|
*/
|
|
249
|
-
function generate_serverless_function(builder, fn, uuid) {
|
|
253
|
+
function generate_serverless_function(builder, fn, uuid, node_version) {
|
|
250
254
|
builder.generateServerInstance(`.netlify/v1/server-${fn.name}.js`, {
|
|
251
255
|
routes: fn.routes,
|
|
252
256
|
serverDirectory: '.netlify/v1/server'
|
|
@@ -259,7 +263,7 @@ function generate_serverless_function(builder, fn, uuid) {
|
|
|
259
263
|
`../server-${fn.name}.js`,
|
|
260
264
|
uuid
|
|
261
265
|
);
|
|
262
|
-
const config = create_function_config('serverless', fn);
|
|
266
|
+
const config = create_function_config('serverless', fn, node_version);
|
|
263
267
|
|
|
264
268
|
if (builder.hasServerInstrumentationFile()) {
|
|
265
269
|
writeFileSync(filename, code);
|
|
@@ -361,10 +365,11 @@ const generator_string = `@sveltejs/adapter-netlify@${adapter_version}`;
|
|
|
361
365
|
/**
|
|
362
366
|
* @param {'serverless' | 'edge'} runtime
|
|
363
367
|
* @param {EntrypointMetadata} fn
|
|
368
|
+
* @param {string} [node_version]
|
|
364
369
|
* @returns {string}
|
|
365
370
|
*/
|
|
366
|
-
function create_function_config(runtime, fn) {
|
|
367
|
-
/** @type {IntegrationsConfig & { preferStatic?: boolean }} */
|
|
371
|
+
function create_function_config(runtime, fn, node_version) {
|
|
372
|
+
/** @type {IntegrationsConfig & { preferStatic?: boolean; nodeVersion?: string }} */
|
|
368
373
|
const config = {
|
|
369
374
|
name: fn.display_name,
|
|
370
375
|
generator: generator_string,
|
|
@@ -374,6 +379,9 @@ function create_function_config(runtime, fn) {
|
|
|
374
379
|
|
|
375
380
|
if (runtime === 'serverless') {
|
|
376
381
|
config.preferStatic = true;
|
|
382
|
+
if (node_version !== undefined) {
|
|
383
|
+
config.nodeVersion = node_version;
|
|
384
|
+
}
|
|
377
385
|
}
|
|
378
386
|
|
|
379
387
|
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.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@netlify/edge-functions": "^4.0.0",
|
|
42
|
-
"@sveltejs/kit": "^3.
|
|
42
|
+
"@sveltejs/kit": "^3.4.1",
|
|
43
43
|
"@types/deno": "^2.7.0",
|
|
44
44
|
"@types/node": "^22.19.19",
|
|
45
45
|
"@typescript/native": "npm:typescript@^7.0.2",
|
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
|
*/
|