swift-rust 1.5.1 → 1.10.2
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 +21 -15
- package/bin/dev-server.mjs +746 -81
- package/bin/runtime/navigator.js +12 -0
- package/bin/swift-rust.js +76 -1
- package/dist/cache.d.ts +37 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +76 -0
- package/dist/cache.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/bin/build.mjs
CHANGED
|
@@ -500,23 +500,29 @@ function simpleHash(s) {
|
|
|
500
500
|
return (h >>> 0).toString(36);
|
|
501
501
|
}
|
|
502
502
|
async function localizeIslands(html) {
|
|
503
|
-
const re = /\/_swift-rust\/island\.js\?p=([^"]+)/g;
|
|
504
|
-
const found = new Set();
|
|
505
|
-
let m;
|
|
506
|
-
while ((m = re.exec(html)) !== null) found.add(m[1]);
|
|
507
|
-
if (found.size === 0) return html;
|
|
508
503
|
let out = html;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
504
|
+
// Page-level islands (/_swift-rust/island.js) and component-level islands
|
|
505
|
+
// (/_swift-rust/island-comp.js) both reference a dev-only bundle keyed by an
|
|
506
|
+
// encoded source path. For the static export we fetch each bundle once, write
|
|
507
|
+
// it as a real file, and rewrite the script src to point at it.
|
|
508
|
+
for (const endpoint of ["island.js", "island-comp.js"]) {
|
|
509
|
+
const re = new RegExp(`/_swift-rust/${endpoint.replace(".", "\\.")}\\?p=([^"]+)`, "g");
|
|
510
|
+
const found = new Set();
|
|
511
|
+
let m;
|
|
512
|
+
while ((m = re.exec(out)) !== null) found.add(m[1]);
|
|
513
|
+
for (const enc of found) {
|
|
514
|
+
const key = `${endpoint}:${enc}`;
|
|
515
|
+
let staticUrl = islandWritten.get(key);
|
|
516
|
+
if (!staticUrl) {
|
|
517
|
+
const { status, body } = await fetchRoute(`/_swift-rust/${endpoint}?p=${enc}`);
|
|
518
|
+
if (status !== 200) continue;
|
|
519
|
+
const rel = `_swift-rust/island/${simpleHash(key)}.js`;
|
|
520
|
+
writeRawFile(STATIC_DIR, rel, body);
|
|
521
|
+
staticUrl = `/${rel}`;
|
|
522
|
+
islandWritten.set(key, staticUrl);
|
|
523
|
+
}
|
|
524
|
+
out = out.split(`/_swift-rust/${endpoint}?p=${enc}`).join(staticUrl);
|
|
518
525
|
}
|
|
519
|
-
out = out.split(`/_swift-rust/island.js?p=${enc}`).join(staticUrl);
|
|
520
526
|
}
|
|
521
527
|
return out;
|
|
522
528
|
}
|