@skgo/sveltekit-adapter 0.12.0 → 0.13.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 +1 -1
- package/skgo-adapter/app-server.js +9 -1
- package/skgo-adapter.js +15 -2
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// host binding is the only path by which a value can reach the engine.
|
|
19
19
|
//
|
|
20
20
|
// Everything this file does not name is kit's, by `export *`: `read`,
|
|
21
|
-
// `getRequestEvent
|
|
21
|
+
// `getRequestEvent` and `requested` come from kit's own module,
|
|
22
22
|
// and an export kit adds arrives without an edit here. An explicit export
|
|
23
23
|
// below shadows the star, which is how the four substitutions take effect.
|
|
24
24
|
import * as real from 'skgo:kit/remote';
|
|
@@ -62,6 +62,14 @@ export function query(validate_or_fn, maybe_fn) {
|
|
|
62
62
|
return wrapper;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
export function prerender(validate_or_fn, maybe_fn, options) {
|
|
66
|
+
const fn = (arg) => host(wrapper.__.id, stringify_remote_arg(arg));
|
|
67
|
+
const wrapper = typeof maybe_fn === 'function'
|
|
68
|
+
? real.prerender(validate_or_fn, fn, options)
|
|
69
|
+
: real.prerender(fn, maybe_fn);
|
|
70
|
+
return wrapper;
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
/**
|
|
66
74
|
* Calls Go once for a whole batch. Kit's own enqueue has already collected
|
|
67
75
|
* every call made to this function in one macrotask and deduplicated them by
|
package/skgo-adapter.js
CHANGED
|
@@ -84,6 +84,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
|
|
|
84
84
|
let prerenderRoot;
|
|
85
85
|
let prerenderBuild;
|
|
86
86
|
let unflatten;
|
|
87
|
+
let stringify;
|
|
87
88
|
let transportDecoders = {};
|
|
88
89
|
async function buildPrerenderBinary() {
|
|
89
90
|
if (!prerenderBuild) {
|
|
@@ -92,11 +93,11 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
|
|
|
92
93
|
if (!generated.prerender) throw new Error('skgo: generated prerender command is missing');
|
|
93
94
|
prerenderRoot = resolve(process.cwd(), generated.prerender.root);
|
|
94
95
|
const dir = mkdtempSync(join(tmpdir(), 'skgo-prerender-'));
|
|
95
|
-
prerenderBinary = join(dir, '
|
|
96
|
+
prerenderBinary = join(dir, 'build');
|
|
96
97
|
await runPrerenderCommand('go', ['build', '-o', prerenderBinary, generated.prerender.package], prerenderRoot);
|
|
97
98
|
process.on('exit', () => rmSync(dir, { recursive: true, force: true }));
|
|
98
99
|
const fromKit = createRequire(realpathSync(join(process.cwd(), 'node_modules/@sveltejs/kit/package.json')));
|
|
99
|
-
({ unflatten } = await import(pathToFileURL(fromKit.resolve('devalue')).href));
|
|
100
|
+
({ unflatten, stringify } = await import(pathToFileURL(fromKit.resolve('devalue')).href));
|
|
100
101
|
const hooks = join(process.cwd(), '.svelte-kit/output/server/entries/hooks.universal.js');
|
|
101
102
|
if (existsSync(hooks)) {
|
|
102
103
|
const { transport = {} } = await import(pathToFileURL(hooks).href);
|
|
@@ -122,6 +123,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
|
|
|
122
123
|
headers.cookie = [cookies.map(({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join('; ')];
|
|
123
124
|
}
|
|
124
125
|
const request = {
|
|
126
|
+
kind: 'load',
|
|
125
127
|
module,
|
|
126
128
|
url: event.url.href,
|
|
127
129
|
routeId: event.route.id,
|
|
@@ -165,6 +167,17 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
|
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
return answer;
|
|
170
|
+
},
|
|
171
|
+
async skgoPrerenderRemote(module, name, arg, event) {
|
|
172
|
+
await buildPrerenderBinary();
|
|
173
|
+
const payload = arg === undefined ? '' : Buffer.from(stringify(arg)).toString('base64url');
|
|
174
|
+
const request = {
|
|
175
|
+
kind: 'remote', module, name, payload, url: event.url.href,
|
|
176
|
+
headers: Object.fromEntries([...event.request.headers].map(([key, value]) => [key, [value]]))
|
|
177
|
+
};
|
|
178
|
+
const raw = await runPrerenderCommand(prerenderBinary, [], prerenderRoot, JSON.stringify(request));
|
|
179
|
+
const answer = JSON.parse(raw);
|
|
180
|
+
return unflatten(JSON.parse(answer.data), transportDecoders)._;
|
|
168
181
|
}
|
|
169
182
|
})
|
|
170
183
|
};
|