swift-rust 1.0.0 → 1.1.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/bin/build.mjs +47 -1
- package/bin/dev-server.mjs +760 -24
- package/bin/runtime/hmr-client.js +102 -0
- package/dist/router.d.ts +103 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +58 -0
- package/dist/router.js.map +1 -1
- package/package.json +9 -8
package/bin/build.mjs
CHANGED
|
@@ -214,6 +214,41 @@ function writeRawFile(outDir, name, contents) {
|
|
|
214
214
|
writeFileSync(outPath, contents);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
// Client-island hydration: a "use client" page's HTML references the dev-only
|
|
218
|
+
// bundle at /_swift-rust/island.js?p=<file>. For the static export we fetch
|
|
219
|
+
// that bundle, write it as a real file, and rewrite the script src to point at
|
|
220
|
+
// it — so hydration works on the deployed site, not just in `bun dev`.
|
|
221
|
+
const islandWritten = new Map();
|
|
222
|
+
function simpleHash(s) {
|
|
223
|
+
let h = 2166136261;
|
|
224
|
+
for (let i = 0; i < s.length; i++) {
|
|
225
|
+
h ^= s.charCodeAt(i);
|
|
226
|
+
h = Math.imul(h, 16777619);
|
|
227
|
+
}
|
|
228
|
+
return (h >>> 0).toString(36);
|
|
229
|
+
}
|
|
230
|
+
async function localizeIslands(html) {
|
|
231
|
+
const re = /\/_swift-rust\/island\.js\?p=([^"]+)/g;
|
|
232
|
+
const found = new Set();
|
|
233
|
+
let m;
|
|
234
|
+
while ((m = re.exec(html)) !== null) found.add(m[1]);
|
|
235
|
+
if (found.size === 0) return html;
|
|
236
|
+
let out = html;
|
|
237
|
+
for (const enc of found) {
|
|
238
|
+
let staticUrl = islandWritten.get(enc);
|
|
239
|
+
if (!staticUrl) {
|
|
240
|
+
const { status, body } = await fetchRoute(`/_swift-rust/island.js?p=${enc}`);
|
|
241
|
+
if (status !== 200) continue;
|
|
242
|
+
const rel = `_swift-rust/island/${simpleHash(enc)}.js`;
|
|
243
|
+
writeRawFile(STATIC_DIR, rel, body);
|
|
244
|
+
staticUrl = `/${rel}`;
|
|
245
|
+
islandWritten.set(enc, staticUrl);
|
|
246
|
+
}
|
|
247
|
+
out = out.split(`/_swift-rust/island.js?p=${enc}`).join(staticUrl);
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
217
252
|
function writeConfigJson(outDir, _hasPublic) {
|
|
218
253
|
// Build Output API v3 config. Only schema-valid fields here — unknown
|
|
219
254
|
// top-level fields or route properties are rejected at "Deploying outputs".
|
|
@@ -290,7 +325,7 @@ async function main() {
|
|
|
290
325
|
try {
|
|
291
326
|
const { status, body } = await fetchRoute(route);
|
|
292
327
|
if (status === 200) {
|
|
293
|
-
const cleaned = stripHmrScript(body);
|
|
328
|
+
const cleaned = await localizeIslands(stripHmrScript(body));
|
|
294
329
|
writeStaticFile(STATIC_DIR, route, cleaned);
|
|
295
330
|
okCount++;
|
|
296
331
|
process.stdout.write(` ${paint("green", "✓")} ${route}\n`);
|
|
@@ -347,6 +382,17 @@ async function main() {
|
|
|
347
382
|
process.stdout.write(` ${paint("green", "✓")} copied public/\n`);
|
|
348
383
|
}
|
|
349
384
|
|
|
385
|
+
// App-directory metadata icons (app/favicon.ico, app/icon.svg, …) → static root.
|
|
386
|
+
// The <link> tags are already baked into the rendered HTML by the dev server.
|
|
387
|
+
const APP_ICON_FILES = ["favicon.ico", "favicon.svg", "icon.svg", "icon.png", "apple-icon.png"];
|
|
388
|
+
for (const name of APP_ICON_FILES) {
|
|
389
|
+
const src = join(APP_DIR, name);
|
|
390
|
+
if (existsSync(src)) {
|
|
391
|
+
cpSync(src, join(STATIC_DIR, name));
|
|
392
|
+
process.stdout.write(` ${paint("green", "✓")} ${name}\n`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
350
396
|
writeConfigJson(OUT_DIR, hasPublic);
|
|
351
397
|
|
|
352
398
|
const total = Date.now() - start;
|