@sveltejs/adapter-netlify 5.0.2 → 5.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/files/edge.js +24 -8
- package/index.js +10 -27
- package/package.json +14 -11
- /package/files/{esm/serverless.js → serverless.js} +0 -0
- /package/files/{esm/shims.js → shims.js} +0 -0
package/files/edge.js
CHANGED
|
@@ -3,18 +3,32 @@ import { manifest } from 'MANIFEST';
|
|
|
3
3
|
|
|
4
4
|
const server = new Server(manifest);
|
|
5
5
|
|
|
6
|
+
/**
|
|
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
|
+
*/
|
|
11
|
+
let origin;
|
|
12
|
+
|
|
6
13
|
const initialized = server.init({
|
|
7
14
|
// @ts-ignore
|
|
8
|
-
env: Deno.env.toObject()
|
|
15
|
+
env: Deno.env.toObject(),
|
|
16
|
+
read: async (file) => {
|
|
17
|
+
const response = await fetch(`${origin}/${file}`);
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new Error(`Failed to fetch ${file}: ${response.status} ${response.statusText}`);
|
|
20
|
+
}
|
|
21
|
+
return response.body;
|
|
22
|
+
}
|
|
9
23
|
});
|
|
10
24
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
/** @type {import('@netlify/edge-functions').EdgeFunction} */
|
|
26
|
+
async function handler(request, context) {
|
|
27
|
+
if (!origin) {
|
|
28
|
+
origin = new URL(request.url).origin;
|
|
29
|
+
await initialized;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
return server.respond(request, {
|
|
19
33
|
platform: { context },
|
|
20
34
|
getClientAddress() {
|
|
@@ -22,3 +36,5 @@ export default async function handler(request, context) {
|
|
|
22
36
|
}
|
|
23
37
|
});
|
|
24
38
|
}
|
|
39
|
+
|
|
40
|
+
export { handler as default };
|
package/index.js
CHANGED
|
@@ -5,6 +5,9 @@ import { builtinModules } from 'node:module';
|
|
|
5
5
|
import process from 'node:process';
|
|
6
6
|
import esbuild from 'esbuild';
|
|
7
7
|
import toml from '@iarna/toml';
|
|
8
|
+
import { VERSION } from '@sveltejs/kit';
|
|
9
|
+
|
|
10
|
+
const [kit_major, kit_minor] = VERSION.split('.');
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* @typedef {{
|
|
@@ -13,26 +16,6 @@ import toml from '@iarna/toml';
|
|
|
13
16
|
* } & toml.JsonMap} NetlifyConfig
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
|
-
/**
|
|
17
|
-
* TODO(serhalp) Replace this custom type with an import from `@netlify/edge-functions`,
|
|
18
|
-
* once that type is fixed to include `excludedPath` and `function`.
|
|
19
|
-
* @typedef {{
|
|
20
|
-
* functions: Array<
|
|
21
|
-
* | {
|
|
22
|
-
* function: string;
|
|
23
|
-
* path: string;
|
|
24
|
-
* excludedPath?: string | string[];
|
|
25
|
-
* }
|
|
26
|
-
* | {
|
|
27
|
-
* function: string;
|
|
28
|
-
* pattern: string;
|
|
29
|
-
* excludedPattern?: string | string[];
|
|
30
|
-
* }
|
|
31
|
-
* >;
|
|
32
|
-
* version: 1;
|
|
33
|
-
* }} HandlerManifest
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
19
|
const name = '@sveltejs/adapter-netlify';
|
|
37
20
|
const files = fileURLToPath(new URL('./files', import.meta.url).href);
|
|
38
21
|
|
|
@@ -114,11 +97,11 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
|
|
|
114
97
|
},
|
|
115
98
|
|
|
116
99
|
supports: {
|
|
117
|
-
// reading from the filesystem only works in serverless functions
|
|
118
100
|
read: ({ route }) => {
|
|
119
|
-
|
|
101
|
+
// TODO bump peer dep in next adapter major to simplify this
|
|
102
|
+
if (edge && kit_major === '2' && kit_minor < '25') {
|
|
120
103
|
throw new Error(
|
|
121
|
-
`${name}: Cannot use \`read\` from \`$app/server\` in route \`${route.id}\` when using edge functions`
|
|
104
|
+
`${name}: Cannot use \`read\` from \`$app/server\` in route \`${route.id}\` when using edge functions and SvelteKit < 2.25.0`
|
|
122
105
|
);
|
|
123
106
|
}
|
|
124
107
|
|
|
@@ -161,7 +144,7 @@ async function generate_edge_functions({ builder }) {
|
|
|
161
144
|
const path = '/*';
|
|
162
145
|
// We only need to specify paths without the trailing slash because
|
|
163
146
|
// Netlify will handle the optional trailing slash for us
|
|
164
|
-
const
|
|
147
|
+
const excluded = [
|
|
165
148
|
// Contains static files
|
|
166
149
|
`/${builder.getAppPath()}/*`,
|
|
167
150
|
...builder.prerendered.paths,
|
|
@@ -179,13 +162,13 @@ async function generate_edge_functions({ builder }) {
|
|
|
179
162
|
'/.netlify/*'
|
|
180
163
|
];
|
|
181
164
|
|
|
182
|
-
/** @type {
|
|
165
|
+
/** @type {import('@netlify/edge-functions').Manifest} */
|
|
183
166
|
const edge_manifest = {
|
|
184
167
|
functions: [
|
|
185
168
|
{
|
|
186
169
|
function: 'render',
|
|
187
170
|
path,
|
|
188
|
-
excludedPath
|
|
171
|
+
excludedPath: /** @type {`/${string}`[]} */ (excluded)
|
|
189
172
|
}
|
|
190
173
|
],
|
|
191
174
|
version: 1
|
|
@@ -232,7 +215,7 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
232
215
|
'0SERVER': './server/index.js' // digit prefix prevents CJS build from using this as a variable name, which would also get replaced
|
|
233
216
|
};
|
|
234
217
|
|
|
235
|
-
builder.copy(
|
|
218
|
+
builder.copy(files, '.netlify', { replace });
|
|
236
219
|
|
|
237
220
|
// Configuring the function to use ESM as the output format.
|
|
238
221
|
const fn_config = JSON.stringify({ config: { nodeModuleFormat: 'esm' }, version: 1 });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/sveltejs/kit",
|
|
15
|
+
"url": "git+https://github.com/sveltejs/kit.git",
|
|
16
16
|
"directory": "packages/adapter-netlify"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
@@ -37,27 +37,30 @@
|
|
|
37
37
|
"set-cookie-parser": "^2.6.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@netlify/functions": "^
|
|
40
|
+
"@netlify/edge-functions": "^2.15.1",
|
|
41
|
+
"@netlify/functions": "^4.0.0",
|
|
41
42
|
"@rollup/plugin-commonjs": "^28.0.1",
|
|
42
43
|
"@rollup/plugin-json": "^6.1.0",
|
|
43
44
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
44
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
45
|
-
"@types/node": "^18.19.
|
|
45
|
+
"@sveltejs/vite-plugin-svelte": "^6.0.0-next.3",
|
|
46
|
+
"@types/node": "^18.19.119",
|
|
46
47
|
"@types/set-cookie-parser": "^2.4.7",
|
|
47
48
|
"rollup": "^4.14.2",
|
|
48
49
|
"typescript": "^5.3.3",
|
|
49
|
-
"vitest": "^3.
|
|
50
|
-
"@sveltejs/kit": "^2.
|
|
50
|
+
"vitest": "^3.2.3",
|
|
51
|
+
"@sveltejs/kit": "^2.27.3"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"@sveltejs/kit": "^2.4.0"
|
|
54
55
|
},
|
|
55
56
|
"scripts": {
|
|
56
|
-
"dev": "
|
|
57
|
-
"build": "
|
|
58
|
-
"test": "vitest run",
|
|
57
|
+
"dev": "rollup -cw",
|
|
58
|
+
"build": "rollup -c",
|
|
59
59
|
"check": "tsc",
|
|
60
60
|
"lint": "prettier --check .",
|
|
61
|
-
"format": "pnpm lint --write"
|
|
61
|
+
"format": "pnpm lint --write",
|
|
62
|
+
"test": "pnpm test:unit && pnpm test:integration",
|
|
63
|
+
"test:unit": "vitest run",
|
|
64
|
+
"test:integration": "pnpm build && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test"
|
|
62
65
|
}
|
|
63
66
|
}
|
|
File without changes
|
|
File without changes
|