@skgo/sveltekit-adapter 0.16.2 → 0.16.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/skgo-adapter.js +37 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skgo/sveltekit-adapter",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "SvelteKit adapter for skgo: builds a frontend that a Go binary renders and answers",
5
5
  "keywords": [
6
6
  "adapter",
package/skgo-adapter.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ linkSync,
2
3
  existsSync,
3
4
  mkdtempSync,
4
5
  mkdirSync,
@@ -7,12 +8,14 @@ import {
7
8
  realpathSync,
8
9
  rmSync,
9
10
  statSync,
11
+ unlinkSync,
10
12
  writeFileSync
11
13
  } from 'node:fs';
14
+ import { createHash } from 'node:crypto';
12
15
  import { spawn } from 'node:child_process';
13
16
  import { createRequire } from 'node:module';
14
17
  import { tmpdir } from 'node:os';
15
- import { basename, dirname, join, relative, resolve } from 'node:path';
18
+ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
16
19
  import { pathToFileURL } from 'node:url';
17
20
  import { gojaDevEnvironment, gojaDevUnchangedFiles, gojaEnvironment, goEnvironmentValues, nodeTable, SSR_TARGET } from './skgo-adapter/env.js';
18
21
  import { identity } from './skgo-adapter/identity.js';
@@ -250,6 +253,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
250
253
  await builder.compress(`${out}/client`);
251
254
  if (existsSync(`${out}/prerendered`)) await builder.compress(`${out}/prerendered`);
252
255
  }
256
+ const prerenderedFiles = relocateQueryPrerenderedFiles(`${out}/prerendered`, out);
253
257
 
254
258
  // `builder` has no writeJson in kit 3.0.0-next.27 (it existed on the
255
259
  // kit 2 line); write the manifest ourselves.
@@ -314,6 +318,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
314
318
  })),
315
319
  remotes: generated.remotes,
316
320
  prerendered,
321
+ ...(Object.keys(prerenderedFiles).length > 0 ? { prerenderedFiles } : {}),
317
322
  precompressed: precompress
318
323
  },
319
324
  null,
@@ -331,6 +336,37 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
331
336
  };
332
337
  }
333
338
 
339
+ /**
340
+ * Kit's native prerender filenames include query strings. Move only the
341
+ * adapter-owned copy of those files to safe build paths so Go's embed patterns
342
+ * can include them, while retaining the exact Kit filename as the manifest key.
343
+ * Hard-link-then-unlink publishes without replacing an existing destination.
344
+ *
345
+ * @param {string} root
346
+ * @param {string} out
347
+ * @returns {Record<string, string>}
348
+ */
349
+ function relocateQueryPrerenderedFiles(root, out) {
350
+ if (!existsSync(root)) return {};
351
+ const mapping = {};
352
+ for (const file of walk(root)) {
353
+ const logical = relative(root, file).split(sep).join('/');
354
+ if (!logical.includes('?')) continue;
355
+ const digest = createHash('sha256').update(logical, 'utf8').digest('hex');
356
+ const physical = `prerendered-files/${digest}`;
357
+ const destination = join(out, physical);
358
+ mkdirSync(dirname(destination), { recursive: true });
359
+ try {
360
+ linkSync(file, destination);
361
+ } catch (error) {
362
+ throw new Error(`skgo: cannot publish query prerendered file ${logical} at ${physical}: ${error}`);
363
+ }
364
+ unlinkSync(file);
365
+ mapping[logical] = physical;
366
+ }
367
+ return mapping;
368
+ }
369
+
334
370
  /**
335
371
  * Reads what `skgo generate` emitted.
336
372
  *