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 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
- for (const enc of found) {
510
- let staticUrl = islandWritten.get(enc);
511
- if (!staticUrl) {
512
- const { status, body } = await fetchRoute(`/_swift-rust/island.js?p=${enc}`);
513
- if (status !== 200) continue;
514
- const rel = `_swift-rust/island/${simpleHash(enc)}.js`;
515
- writeRawFile(STATIC_DIR, rel, body);
516
- staticUrl = `/${rel}`;
517
- islandWritten.set(enc, staticUrl);
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
  }