@sveltejs/adapter-netlify 6.0.2 → 6.0.3
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.js +54 -45
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -237,13 +237,14 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
237
237
|
|
|
238
238
|
const routes = [route];
|
|
239
239
|
|
|
240
|
+
/** @type {string[]} */
|
|
240
241
|
const parts = [];
|
|
241
|
-
|
|
242
|
-
//
|
|
242
|
+
|
|
243
|
+
// The parts should conform to URLPattern syntax
|
|
244
|
+
// https://docs.netlify.com/build/functions/get-started/?fn-language=ts&data-tab=TypeScript#route-requests
|
|
243
245
|
for (const segment of route.segments) {
|
|
244
246
|
if (segment.rest) {
|
|
245
247
|
parts.push('*');
|
|
246
|
-
break; // Netlify redirects don't allow anything after a *
|
|
247
248
|
} else if (segment.dynamic) {
|
|
248
249
|
// URLPattern requires params to start with letters
|
|
249
250
|
parts.push(`:param${parts.length}`);
|
|
@@ -252,6 +253,7 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
// Netlify handles trailing slashes for us, so we don't need to include them in the pattern
|
|
255
257
|
const pattern = `/${parts.join('/')}`;
|
|
256
258
|
const name =
|
|
257
259
|
FUNCTION_PREFIX + (parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index');
|
|
@@ -270,49 +272,22 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
270
272
|
}
|
|
271
273
|
}
|
|
272
274
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
routes
|
|
275
|
+
generate_serverless_function({
|
|
276
|
+
builder,
|
|
277
|
+
routes,
|
|
278
|
+
patterns: [pattern, `${pattern === '/' ? '' : pattern}/__data.json`],
|
|
279
|
+
name
|
|
276
280
|
});
|
|
277
|
-
|
|
278
|
-
const fn = generate_serverless_function_module(manifest);
|
|
279
|
-
const config = generate_config_export(pattern);
|
|
280
|
-
|
|
281
|
-
if (builder.hasServerInstrumentationFile()) {
|
|
282
|
-
writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
|
|
283
|
-
builder.instrument({
|
|
284
|
-
entrypoint: `.netlify/functions-internal/${name}.mjs`,
|
|
285
|
-
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
286
|
-
start: `.netlify/functions-start/${name}.start.mjs`,
|
|
287
|
-
module: {
|
|
288
|
-
generateText: generate_traced_module(config)
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
} else {
|
|
292
|
-
writeFileSync(`.netlify/functions-internal/${name}.mjs`, `${fn}\n${config}`);
|
|
293
|
-
}
|
|
294
281
|
}
|
|
282
|
+
|
|
283
|
+
// TODO: add a catch-all to display a 404 page if no other functions are invoked, similar to the Vercel adapter
|
|
295
284
|
} else {
|
|
296
|
-
|
|
297
|
-
|
|
285
|
+
generate_serverless_function({
|
|
286
|
+
builder,
|
|
287
|
+
routes: undefined,
|
|
288
|
+
patterns: ['/*'],
|
|
289
|
+
name: `${FUNCTION_PREFIX}render`
|
|
298
290
|
});
|
|
299
|
-
|
|
300
|
-
const fn = generate_serverless_function_module(manifest);
|
|
301
|
-
const config = generate_config_export('/*');
|
|
302
|
-
|
|
303
|
-
if (builder.hasServerInstrumentationFile()) {
|
|
304
|
-
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`, fn);
|
|
305
|
-
builder.instrument({
|
|
306
|
-
entrypoint: `.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`,
|
|
307
|
-
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
308
|
-
start: `.netlify/functions-start/${FUNCTION_PREFIX}render.start.mjs`,
|
|
309
|
-
module: {
|
|
310
|
-
generateText: generate_traced_module(config)
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`, `${fn}\n${config}`);
|
|
315
|
-
}
|
|
316
291
|
}
|
|
317
292
|
|
|
318
293
|
// Copy user's custom _redirects file if it exists
|
|
@@ -394,6 +369,39 @@ function matches(a, b) {
|
|
|
394
369
|
}
|
|
395
370
|
}
|
|
396
371
|
|
|
372
|
+
/**
|
|
373
|
+
*
|
|
374
|
+
* @param {{
|
|
375
|
+
* builder: import('@sveltejs/kit').Builder,
|
|
376
|
+
* routes: import('@sveltejs/kit').RouteDefinition[] | undefined,
|
|
377
|
+
* patterns: string[],
|
|
378
|
+
* name: string
|
|
379
|
+
* }} opts
|
|
380
|
+
*/
|
|
381
|
+
function generate_serverless_function({ builder, routes, patterns, name }) {
|
|
382
|
+
const manifest = builder.generateManifest({
|
|
383
|
+
relativePath: '../server',
|
|
384
|
+
routes
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const fn = generate_serverless_function_module(manifest);
|
|
388
|
+
const config = generate_config_export(patterns);
|
|
389
|
+
|
|
390
|
+
if (builder.hasServerInstrumentationFile()) {
|
|
391
|
+
writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
|
|
392
|
+
builder.instrument({
|
|
393
|
+
entrypoint: `.netlify/functions-internal/${name}.mjs`,
|
|
394
|
+
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
395
|
+
start: `.netlify/functions-start/${name}.start.mjs`,
|
|
396
|
+
module: {
|
|
397
|
+
generateText: generate_traced_module(config)
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
} else {
|
|
401
|
+
writeFileSync(`.netlify/functions-internal/${name}.mjs`, `${fn}\n${config}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
397
405
|
/**
|
|
398
406
|
* @param {string} manifest
|
|
399
407
|
* @returns {string}
|
|
@@ -407,13 +415,14 @@ export default init(${manifest});
|
|
|
407
415
|
}
|
|
408
416
|
|
|
409
417
|
/**
|
|
410
|
-
* @param {string}
|
|
418
|
+
* @param {string[]} patterns
|
|
411
419
|
* @returns {string}
|
|
412
420
|
*/
|
|
413
|
-
function generate_config_export(
|
|
421
|
+
function generate_config_export(patterns) {
|
|
422
|
+
// TODO: add a human friendly name for the function https://docs.netlify.com/build/frameworks/frameworks-api/#configuration-options-2
|
|
414
423
|
return `\
|
|
415
424
|
export const config = {
|
|
416
|
-
path:
|
|
425
|
+
path: [${patterns.map((s) => JSON.stringify(s)).join(', ')}],
|
|
417
426
|
excludedPath: "/.netlify/*",
|
|
418
427
|
preferStatic: true
|
|
419
428
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"esbuild": "^0.25.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@netlify/dev": "^4.
|
|
40
|
+
"@netlify/dev": "^4.11.2",
|
|
41
41
|
"@netlify/edge-functions": "^3.0.0",
|
|
42
42
|
"@netlify/functions": "^5.0.0",
|
|
43
43
|
"@netlify/node-cookies": "^0.1.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"rollup": "^4.14.2",
|
|
51
51
|
"typescript": "^5.3.3",
|
|
52
52
|
"vitest": "^4.0.0",
|
|
53
|
-
"@sveltejs/kit": "^2.
|
|
53
|
+
"@sveltejs/kit": "^2.53.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@sveltejs/kit": "^2.31.0"
|