@skgo/sveltekit-adapter 0.15.0 → 0.16.0
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/package.json +2 -2
- package/skgo-adapter.js +14 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skgo/sveltekit-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "SvelteKit adapter for skgo: builds a frontend that a Go binary renders and answers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"skgo-adapter/prerender-csp.js"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@sveltejs/kit": "^3.0.0
|
|
43
|
+
"@sveltejs/kit": "^3.0.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/skgo-adapter.js
CHANGED
|
@@ -404,7 +404,7 @@ function writeAppManifest(file, manifest) {
|
|
|
404
404
|
/**
|
|
405
405
|
* Kit's own server manifest, as an object *and* as text. Kit 3 generates a
|
|
406
406
|
* complete server-instance module instead of returning manifest source. We
|
|
407
|
-
* remove its eager
|
|
407
|
+
* remove its eager create_server import and call and export the manifest it
|
|
408
408
|
* wrote; every remaining import sits inside a lazy thunk, so importing the
|
|
409
409
|
* result resolves nothing and runs no application code. The source is worth
|
|
410
410
|
* keeping because those thunks carry information the imported object has
|
|
@@ -413,22 +413,27 @@ function writeAppManifest(file, manifest) {
|
|
|
413
413
|
* @param {import('@sveltejs/kit').Builder} builder
|
|
414
414
|
* @returns {Promise<{ manifest: any, source: string }>}
|
|
415
415
|
*/
|
|
416
|
-
async function readKitManifest(builder) {
|
|
416
|
+
export async function readKitManifest(builder) {
|
|
417
417
|
const dir = builder.getBuildDirectory('skgo');
|
|
418
418
|
const file = join(dir, 'kit-manifest.js');
|
|
419
419
|
mkdirSync(dir, { recursive: true });
|
|
420
420
|
builder.generateServerInstance(file);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (
|
|
421
|
+
const original = readFileSync(file, 'utf8');
|
|
422
|
+
// Kit 3's builder writes this wrapper around its lazy manifest. Strip both
|
|
423
|
+
// sides before importing it: importing Kit's server would execute its module
|
|
424
|
+
// graph, while this read should only discover what the Go binary must serve.
|
|
425
|
+
const serverImport = /^import \{ create_server \} from '[^']+';\n/;
|
|
426
|
+
const serverCall = /\nexport const server = create_server\(manifest\);\n?$/;
|
|
427
|
+
if (!serverImport.test(original) || !serverCall.test(original) ||
|
|
428
|
+
!original.replace(serverImport, '').startsWith('const manifest = ')) {
|
|
428
429
|
throw new Error(
|
|
429
430
|
'skgo: kit generated a server instance in an unknown shape; refusing to guess where its manifest is'
|
|
430
431
|
);
|
|
431
432
|
}
|
|
433
|
+
const source = original
|
|
434
|
+
.replace(serverImport, '')
|
|
435
|
+
.replace(/^const manifest = /, 'export const manifest = ')
|
|
436
|
+
.replace(serverCall, '\n');
|
|
432
437
|
writeFileSync(file, source);
|
|
433
438
|
try {
|
|
434
439
|
// The cache buster matters: `vp build` can run twice in one process.
|