@sveltejs/adapter-netlify 7.0.0-next.5 → 7.0.0-next.6
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/files/edge.js +24 -12
- package/files/serverless.js +11 -22
- package/index.js +17 -16
- package/package.json +3 -5
package/files/edge.js
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
import { Server } from "0SERVER";
|
|
2
|
-
import { manifest } from "MANIFEST";
|
|
3
|
-
//#region src/edge.js
|
|
4
1
|
/** @import {} from 'deno' */
|
|
2
|
+
import { Server } from '0SERVER';
|
|
3
|
+
import { manifest } from 'MANIFEST';
|
|
4
|
+
|
|
5
5
|
const server = new Server(manifest);
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
|
-
* We don't know the origin until we receive a request, but
|
|
8
|
-
* that's guaranteed to happen before we call `read`
|
|
9
|
-
* @type {string}
|
|
10
|
-
*/
|
|
8
|
+
* We don't know the origin until we receive a request, but
|
|
9
|
+
* that's guaranteed to happen before we call `read`
|
|
10
|
+
* @type {string}
|
|
11
|
+
*/
|
|
11
12
|
let origin;
|
|
13
|
+
|
|
12
14
|
const initialized = server.init({
|
|
13
15
|
env: Deno.env.toObject(),
|
|
14
16
|
read: async (file) => {
|
|
15
17
|
const url = `${origin}/${file}`;
|
|
16
18
|
const response = await fetch(url);
|
|
17
|
-
|
|
19
|
+
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
return response.body;
|
|
19
27
|
}
|
|
20
28
|
});
|
|
29
|
+
|
|
21
30
|
/** @type {import('@netlify/edge-functions').EdgeFunction} */
|
|
22
|
-
async function handler(request, context) {
|
|
23
|
-
if (!origin)
|
|
31
|
+
export default async function handler(request, context) {
|
|
32
|
+
if (!origin) {
|
|
33
|
+
origin = new URL(request.url).origin;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// always await initialization to prevent race condition with concurrent requests
|
|
24
37
|
await initialized;
|
|
38
|
+
|
|
25
39
|
return server.respond(request, {
|
|
26
40
|
platform: { context },
|
|
27
41
|
getClientAddress() {
|
|
@@ -29,5 +43,3 @@ async function handler(request, context) {
|
|
|
29
43
|
}
|
|
30
44
|
});
|
|
31
45
|
}
|
|
32
|
-
//#endregion
|
|
33
|
-
export { handler as default };
|
package/files/serverless.js
CHANGED
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
import { Server } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
//#region ../kit/src/exports/node/index.js
|
|
1
|
+
import { Server } from '0SERVER';
|
|
2
|
+
import { createReadableStream } from '@sveltejs/kit/node';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
function createReadableStream(file) {
|
|
13
|
-
return Readable.toWeb(createReadStream(file));
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/serverless.js
|
|
17
|
-
/**
|
|
18
|
-
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
19
|
-
* @returns {(request: Request, context: import('@netlify/types').Context) => Promise<Response>}
|
|
20
|
-
*/
|
|
21
|
-
function init(manifest) {
|
|
6
|
+
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
7
|
+
* @returns {(request: Request, context: import('@netlify/types').Context) => Promise<Response>}
|
|
8
|
+
*/
|
|
9
|
+
export function init(manifest) {
|
|
22
10
|
const server = new Server(manifest);
|
|
11
|
+
|
|
23
12
|
/** @type {Promise<void> | null} */
|
|
24
13
|
let init_promise = server.init({
|
|
25
14
|
env: process.env,
|
|
26
15
|
read: (file) => createReadableStream(`.netlify/server/${file}`)
|
|
27
16
|
});
|
|
17
|
+
|
|
28
18
|
return async (request, context) => {
|
|
29
19
|
if (init_promise !== null) {
|
|
30
20
|
await init_promise;
|
|
31
21
|
init_promise = null;
|
|
32
22
|
}
|
|
23
|
+
|
|
33
24
|
return server.respond(request, {
|
|
34
25
|
platform: { context },
|
|
35
26
|
getClientAddress() {
|
|
@@ -38,5 +29,3 @@ function init(manifest) {
|
|
|
38
29
|
});
|
|
39
30
|
};
|
|
40
31
|
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { init };
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join, posix } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { builtinModules } from 'node:module';
|
|
@@ -60,19 +60,19 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
|
|
|
60
60
|
const publish = get_publish_directory(netlify_config, builder) || 'build';
|
|
61
61
|
|
|
62
62
|
// empty out existing build directories
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
rmSync(publish, { force: true, recursive: true });
|
|
64
|
+
rmSync('.netlify/v1', { force: true, recursive: true });
|
|
65
65
|
|
|
66
66
|
// clean up legacy directories from older adapter versions to avoid
|
|
67
67
|
// gnarly edge cases when an existing project is upgraded to this version
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
rmSync('.netlify/edge-functions', { force: true, recursive: true });
|
|
69
|
+
rmSync('.netlify/server', { force: true, recursive: true });
|
|
70
|
+
rmSync('.netlify/package.json', { force: true, recursive: true });
|
|
71
|
+
rmSync('.netlify/serverless.js', { force: true, recursive: true });
|
|
72
72
|
if (existsSync('.netlify/functions-internal')) {
|
|
73
73
|
for (const file of readdirSync('.netlify/functions-internal')) {
|
|
74
74
|
if (file.startsWith(FUNCTION_PREFIX)) {
|
|
75
|
-
|
|
75
|
+
rmSync(join('.netlify/functions-internal', file), { force: true, recursive: true });
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -118,7 +118,7 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
|
|
|
118
118
|
*/
|
|
119
119
|
function generate_serverless_functions({ builder, publish, split }) {
|
|
120
120
|
// https://docs.netlify.com/build/frameworks/frameworks-api/#netlifyv1functions
|
|
121
|
-
|
|
121
|
+
mkdirSync(netlify_framework_serverless_path, { recursive: true });
|
|
122
122
|
|
|
123
123
|
builder.writeServer('.netlify/v1/server');
|
|
124
124
|
|
|
@@ -243,7 +243,7 @@ function write_frameworks_config({ builder }) {
|
|
|
243
243
|
]
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
mkdirSync('.netlify/v1', { recursive: true });
|
|
247
247
|
writeFileSync(netlify_framework_config_path, s(config));
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -264,7 +264,7 @@ function generate_serverless_function({ builder, routes, patterns, name, exclude
|
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
const fn = generate_serverless_function_module(manifest);
|
|
267
|
-
const config = generate_config_export(patterns, exclude);
|
|
267
|
+
const config = generate_config_export(name, patterns, exclude);
|
|
268
268
|
|
|
269
269
|
if (builder.hasServerInstrumentationFile()) {
|
|
270
270
|
writeFileSync(`${netlify_framework_serverless_path}/${name}.mjs`, fn);
|
|
@@ -296,17 +296,18 @@ export default init(${manifest});
|
|
|
296
296
|
const generator_string = `@sveltejs/adapter-netlify@${adapter_version}`;
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
|
+
* @param {string} name The name that shows up in the logs & metrics functions list
|
|
299
300
|
* @param {string[]} patterns
|
|
300
301
|
* @param {string[]} [exclude]
|
|
301
302
|
* @returns {string}
|
|
302
303
|
*/
|
|
303
|
-
function generate_config_export(patterns, exclude = []) {
|
|
304
|
+
function generate_config_export(name, patterns, exclude = []) {
|
|
304
305
|
// TODO: add a human friendly name for the function https://docs.netlify.com/build/frameworks/frameworks-api/#configuration-options-2
|
|
305
306
|
|
|
306
307
|
// https://docs.netlify.com/build/frameworks/frameworks-api/#configuration-options-2
|
|
307
308
|
return `\
|
|
308
309
|
export const config = {
|
|
309
|
-
name:
|
|
310
|
+
name: ${JSON.stringify(name)},
|
|
310
311
|
generator: '${generator_string}',
|
|
311
312
|
path: [${patterns.map(s).join(', ')}],
|
|
312
313
|
excludedPath: [${['/.netlify/*', ...exclude].map(s).join(', ')}],
|
|
@@ -354,11 +355,11 @@ const rolldown_config = {
|
|
|
354
355
|
*/
|
|
355
356
|
async function generate_edge_functions({ builder }) {
|
|
356
357
|
const tmp = builder.getBuildDirectory('netlify-tmp');
|
|
357
|
-
|
|
358
|
-
|
|
358
|
+
rmSync(tmp, { force: true, recursive: true });
|
|
359
|
+
mkdirSync(tmp, { recursive: true });
|
|
359
360
|
|
|
360
361
|
// https://docs.netlify.com/build/frameworks/frameworks-api/#edge-functions
|
|
361
|
-
|
|
362
|
+
mkdirSync('.netlify/v1/edge-functions', { recursive: true });
|
|
362
363
|
|
|
363
364
|
builder.log.minor('Generating Edge Function...');
|
|
364
365
|
const relativePath = posix.relative(tmp, builder.getServerDirectory());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.6",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -44,19 +44,17 @@
|
|
|
44
44
|
"@types/node": "^22.19.19",
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
46
|
"vitest": "^4.1.10",
|
|
47
|
-
"@sveltejs/kit": "^3.0.0-next.
|
|
47
|
+
"@sveltejs/kit": "^3.0.0-next.15"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@sveltejs/kit": "^2.31.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"dev": "rolldown -cw",
|
|
54
|
-
"build": "rolldown -c",
|
|
55
53
|
"check": "tsc",
|
|
56
54
|
"lint": "prettier --check .",
|
|
57
55
|
"format": "pnpm lint --write",
|
|
58
56
|
"test:unit": "vitest run",
|
|
59
|
-
"test:build": "pnpm
|
|
57
|
+
"test:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" build",
|
|
60
58
|
"test": "pnpm test:unit && pnpm test:build"
|
|
61
59
|
}
|
|
62
60
|
}
|