@sveltejs/adapter-netlify 6.0.2 → 6.0.4
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 +66 -47
- 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,13 +253,16 @@ 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');
|
|
258
260
|
|
|
259
261
|
// skip routes with identical patterns, they were already folded into another function
|
|
260
262
|
if (seen.has(pattern)) continue;
|
|
261
|
-
|
|
263
|
+
|
|
264
|
+
const patterns = [pattern, `${pattern === '/' ? '' : pattern}/__data.json`];
|
|
265
|
+
patterns.forEach((p) => seen.add(p));
|
|
262
266
|
|
|
263
267
|
// figure out which lower priority routes should be considered fallbacks
|
|
264
268
|
for (let j = i + 1; j < builder.routes.length; j += 1) {
|
|
@@ -270,49 +274,28 @@ function generate_lambda_functions({ builder, publish, split }) {
|
|
|
270
274
|
}
|
|
271
275
|
}
|
|
272
276
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
routes
|
|
277
|
+
generate_serverless_function({
|
|
278
|
+
builder,
|
|
279
|
+
routes,
|
|
280
|
+
patterns,
|
|
281
|
+
name
|
|
276
282
|
});
|
|
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
283
|
}
|
|
284
|
+
|
|
285
|
+
generate_serverless_function({
|
|
286
|
+
builder,
|
|
287
|
+
routes: [],
|
|
288
|
+
patterns: ['/*'],
|
|
289
|
+
name: `${FUNCTION_PREFIX}catch-all`,
|
|
290
|
+
exclude: Array.from(seen)
|
|
291
|
+
});
|
|
295
292
|
} else {
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
generate_serverless_function({
|
|
294
|
+
builder,
|
|
295
|
+
routes: undefined,
|
|
296
|
+
patterns: ['/*'],
|
|
297
|
+
name: `${FUNCTION_PREFIX}render`
|
|
298
298
|
});
|
|
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
299
|
}
|
|
317
300
|
|
|
318
301
|
// Copy user's custom _redirects file if it exists
|
|
@@ -394,6 +377,40 @@ function matches(a, b) {
|
|
|
394
377
|
}
|
|
395
378
|
}
|
|
396
379
|
|
|
380
|
+
/**
|
|
381
|
+
*
|
|
382
|
+
* @param {{
|
|
383
|
+
* builder: import('@sveltejs/kit').Builder,
|
|
384
|
+
* routes: import('@sveltejs/kit').RouteDefinition[] | undefined,
|
|
385
|
+
* patterns: string[],
|
|
386
|
+
* name: string,
|
|
387
|
+
* exclude?: string[]
|
|
388
|
+
* }} opts
|
|
389
|
+
*/
|
|
390
|
+
function generate_serverless_function({ builder, routes, patterns, name, exclude }) {
|
|
391
|
+
const manifest = builder.generateManifest({
|
|
392
|
+
relativePath: '../server',
|
|
393
|
+
routes
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
const fn = generate_serverless_function_module(manifest);
|
|
397
|
+
const config = generate_config_export(patterns, exclude);
|
|
398
|
+
|
|
399
|
+
if (builder.hasServerInstrumentationFile()) {
|
|
400
|
+
writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
|
|
401
|
+
builder.instrument({
|
|
402
|
+
entrypoint: `.netlify/functions-internal/${name}.mjs`,
|
|
403
|
+
instrumentation: '.netlify/server/instrumentation.server.js',
|
|
404
|
+
start: `.netlify/functions-start/${name}.start.mjs`,
|
|
405
|
+
module: {
|
|
406
|
+
generateText: generate_traced_module(config)
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
} else {
|
|
410
|
+
writeFileSync(`.netlify/functions-internal/${name}.mjs`, `${fn}\n${config}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
397
414
|
/**
|
|
398
415
|
* @param {string} manifest
|
|
399
416
|
* @returns {string}
|
|
@@ -407,14 +424,16 @@ export default init(${manifest});
|
|
|
407
424
|
}
|
|
408
425
|
|
|
409
426
|
/**
|
|
410
|
-
* @param {string}
|
|
427
|
+
* @param {string[]} patterns
|
|
428
|
+
* @param {string[]} [exclude]
|
|
411
429
|
* @returns {string}
|
|
412
430
|
*/
|
|
413
|
-
function generate_config_export(
|
|
431
|
+
function generate_config_export(patterns, exclude = []) {
|
|
432
|
+
// TODO: add a human friendly name for the function https://docs.netlify.com/build/frameworks/frameworks-api/#configuration-options-2
|
|
414
433
|
return `\
|
|
415
434
|
export const config = {
|
|
416
|
-
path:
|
|
417
|
-
excludedPath:
|
|
435
|
+
path: [${patterns.map((s) => JSON.stringify(s)).join(', ')}],
|
|
436
|
+
excludedPath: [${['/.netlify/*', ...exclude].map((s) => JSON.stringify(s)).join(', ')}],
|
|
418
437
|
preferStatic: true
|
|
419
438
|
};
|
|
420
439
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
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.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@sveltejs/kit": "^2.31.0"
|