@sveltejs/adapter-netlify 5.1.1 → 5.2.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/serverless.js +5 -6
- package/index.js +64 -10
- package/package.json +2 -2
package/files/serverless.js
CHANGED
|
@@ -290,8 +290,9 @@ function createReadableStream(file) {
|
|
|
290
290
|
function init(manifest) {
|
|
291
291
|
const server = new Server(manifest);
|
|
292
292
|
|
|
293
|
+
/** @type {Promise<void> | null} */
|
|
293
294
|
let init_promise = server.init({
|
|
294
|
-
env: process.env,
|
|
295
|
+
env: /** @type {Record<string, string>} */ (process.env),
|
|
295
296
|
read: (file) => createReadableStream(`.netlify/server/${file}`)
|
|
296
297
|
});
|
|
297
298
|
|
|
@@ -304,7 +305,7 @@ function init(manifest) {
|
|
|
304
305
|
const response = await server.respond(to_request(event), {
|
|
305
306
|
platform: { context },
|
|
306
307
|
getClientAddress() {
|
|
307
|
-
return event.headers['x-nf-client-connection-ip'];
|
|
308
|
+
return /** @type {string} */ (event.headers['x-nf-client-connection-ip']);
|
|
308
309
|
}
|
|
309
310
|
});
|
|
310
311
|
|
|
@@ -335,13 +336,11 @@ function init(manifest) {
|
|
|
335
336
|
* @param {import('@netlify/functions').HandlerEvent} event
|
|
336
337
|
* @returns {Request}
|
|
337
338
|
*/
|
|
338
|
-
function to_request(
|
|
339
|
-
const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
|
|
340
|
-
|
|
339
|
+
function to_request({ httpMethod, headers, rawUrl, body, isBase64Encoded }) {
|
|
341
340
|
/** @type {RequestInit} */
|
|
342
341
|
const init = {
|
|
343
342
|
method: httpMethod,
|
|
344
|
-
headers: new Headers(headers)
|
|
343
|
+
headers: new Headers(/** @type {Record<string, string>} */ (headers))
|
|
345
344
|
};
|
|
346
345
|
|
|
347
346
|
if (httpMethod !== 'GET' && httpMethod !== 'HEAD') {
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { BuildOptions } from 'esbuild' */
|
|
1
2
|
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { dirname, join, resolve, posix } from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
@@ -16,6 +17,17 @@ const [kit_major, kit_minor] = VERSION.split('.');
|
|
|
16
17
|
* } & toml.JsonMap} NetlifyConfig
|
|
17
18
|
*/
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @template T
|
|
22
|
+
* @template {keyof T} K
|
|
23
|
+
* @typedef {Partial<Omit<T, K>> & Required<Pick<T, K>>} PartialExcept
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* We use a custom `Builder` type here to support the minimum version of SvelteKit.
|
|
28
|
+
* @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
|
|
29
|
+
*/
|
|
30
|
+
|
|
19
31
|
const name = '@sveltejs/adapter-netlify';
|
|
20
32
|
const files = fileURLToPath(new URL('./files', import.meta.url).href);
|
|
21
33
|
|
|
@@ -29,7 +41,7 @@ const FUNCTION_PREFIX = 'sveltekit-';
|
|
|
29
41
|
export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
|
|
30
42
|
return {
|
|
31
43
|
name,
|
|
32
|
-
|
|
44
|
+
/** @param {Builder2_4_0} builder */
|
|
33
45
|
async adapt(builder) {
|
|
34
46
|
if (!builder.routes) {
|
|
35
47
|
throw new Error(
|
|
@@ -106,13 +118,14 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
|
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
return true;
|
|
109
|
-
}
|
|
121
|
+
},
|
|
122
|
+
instrumentation: () => true
|
|
110
123
|
}
|
|
111
124
|
};
|
|
112
125
|
}
|
|
113
126
|
/**
|
|
114
127
|
* @param { object } params
|
|
115
|
-
* @param {
|
|
128
|
+
* @param {Builder2_4_0} params.builder
|
|
116
129
|
*/
|
|
117
130
|
async function generate_edge_functions({ builder }) {
|
|
118
131
|
const tmp = builder.getBuildDirectory('netlify-tmp');
|
|
@@ -174,9 +187,8 @@ async function generate_edge_functions({ builder }) {
|
|
|
174
187
|
version: 1
|
|
175
188
|
};
|
|
176
189
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
outfile: '.netlify/edge-functions/render.js',
|
|
190
|
+
/** @type {BuildOptions} */
|
|
191
|
+
const esbuild_config = {
|
|
180
192
|
bundle: true,
|
|
181
193
|
format: 'esm',
|
|
182
194
|
platform: 'browser',
|
|
@@ -194,13 +206,34 @@ async function generate_edge_functions({ builder }) {
|
|
|
194
206
|
// https://docs.netlify.com/edge-functions/api/#runtime-environment
|
|
195
207
|
external: builtinModules.map((id) => `node:${id}`),
|
|
196
208
|
alias: Object.fromEntries(builtinModules.map((id) => [id, `node:${id}`]))
|
|
197
|
-
}
|
|
209
|
+
};
|
|
210
|
+
await Promise.all([
|
|
211
|
+
esbuild.build({
|
|
212
|
+
entryPoints: [`${tmp}/entry.js`],
|
|
213
|
+
outfile: '.netlify/edge-functions/render.js',
|
|
214
|
+
...esbuild_config
|
|
215
|
+
}),
|
|
216
|
+
builder.hasServerInstrumentationFile?.() &&
|
|
217
|
+
esbuild.build({
|
|
218
|
+
entryPoints: [`${builder.getServerDirectory()}/instrumentation.server.js`],
|
|
219
|
+
outfile: '.netlify/edge/instrumentation.server.js',
|
|
220
|
+
...esbuild_config
|
|
221
|
+
})
|
|
222
|
+
]);
|
|
223
|
+
|
|
224
|
+
if (builder.hasServerInstrumentationFile?.()) {
|
|
225
|
+
builder.instrument?.({
|
|
226
|
+
entrypoint: '.netlify/edge-functions/render.js',
|
|
227
|
+
instrumentation: '.netlify/edge/instrumentation.server.js',
|
|
228
|
+
start: '.netlify/edge/start.js'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
198
231
|
|
|
199
232
|
writeFileSync('.netlify/edge-functions/manifest.json', JSON.stringify(edge_manifest));
|
|
200
233
|
}
|
|
201
234
|
/**
|
|
202
235
|
* @param { object } params
|
|
203
|
-
* @param {
|
|
236
|
+
* @param {Builder2_4_0} params.builder
|
|
204
237
|
* @param { string } params.publish
|
|
205
238
|
* @param { boolean } params.split
|
|
206
239
|
*/
|
|
@@ -272,6 +305,16 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
272
305
|
|
|
273
306
|
writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
|
|
274
307
|
writeFileSync(`.netlify/functions-internal/${name}.json`, fn_config);
|
|
308
|
+
if (builder.hasServerInstrumentationFile?.()) {
|
|
309
|
+
builder.instrument?.({
|
|
310
|
+
entrypoint: `.netlify/functions-internal/${name}.mjs`,
|
|
311
|
+
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
312
|
+
start: `.netlify/functions-start/${name}.start.mjs`,
|
|
313
|
+
module: {
|
|
314
|
+
exports: ['handler']
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
275
318
|
|
|
276
319
|
const redirect = `/.netlify/functions/${name} 200`;
|
|
277
320
|
redirects.push(`${pattern} ${redirect}`);
|
|
@@ -286,6 +329,17 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
286
329
|
|
|
287
330
|
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.json`, fn_config);
|
|
288
331
|
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`, fn);
|
|
332
|
+
if (builder.hasServerInstrumentationFile?.()) {
|
|
333
|
+
builder.instrument?.({
|
|
334
|
+
entrypoint: `.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`,
|
|
335
|
+
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
336
|
+
start: `.netlify/functions-start/${FUNCTION_PREFIX}render.start.mjs`,
|
|
337
|
+
module: {
|
|
338
|
+
exports: ['handler']
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
289
343
|
redirects.push(`* /.netlify/functions/${FUNCTION_PREFIX}render 200`);
|
|
290
344
|
}
|
|
291
345
|
|
|
@@ -313,8 +367,8 @@ function get_netlify_config() {
|
|
|
313
367
|
}
|
|
314
368
|
|
|
315
369
|
/**
|
|
316
|
-
* @param {NetlifyConfig} netlify_config
|
|
317
|
-
* @param {
|
|
370
|
+
* @param {NetlifyConfig | null} netlify_config
|
|
371
|
+
* @param {Builder2_4_0} builder
|
|
318
372
|
**/
|
|
319
373
|
function get_publish_directory(netlify_config, builder) {
|
|
320
374
|
if (netlify_config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"rollup": "^4.14.2",
|
|
49
49
|
"typescript": "^5.3.3",
|
|
50
50
|
"vitest": "^3.2.3",
|
|
51
|
-
"@sveltejs/kit": "^2.
|
|
51
|
+
"@sveltejs/kit": "^2.31.1"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@sveltejs/kit": "^2.4.0"
|