sandboxedjs 0.1.47 → 0.1.48

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/dist/index.cjs CHANGED
@@ -20582,7 +20582,9 @@ function safeTarget(destination, name) {
20582
20582
  return join(destination, clean2);
20583
20583
  }
20584
20584
  function stripPackageRoot(name) {
20585
- return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
20585
+ const clean2 = name.replace(/^\.\//, "").replace(/\/$/, "");
20586
+ const slash = clean2.indexOf("/");
20587
+ return slash === -1 ? "" : clean2.slice(slash + 1);
20586
20588
  }
20587
20589
  function text(bytes2, start2, length) {
20588
20590
  return new TextDecoder().decode(bytes2.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
@@ -26628,15 +26630,91 @@ var MirroringVolume = class {
26628
26630
  mirror.writeFileSync(path, this.inner.readFileSync(path));
26629
26631
  });
26630
26632
  }
26631
- // ── reads: straight through ───────────────────────────────────────────────
26633
+ // ── reads: straight through, then the mirror ──────────────────────────────
26634
+ /*
26635
+ * A file the bundler produced exists only in the mirror until something
26636
+ * asks for it here.
26637
+ *
26638
+ * {@link absorb} was the original answer and is not enough on its own. It
26639
+ * runs when a process ends — a dev server never ends — and it skips
26640
+ * `node_modules`, where Vite keeps the one output that a dev server depends
26641
+ * on: `node_modules/.vite/deps`. Between those two, the entire pre-bundled
26642
+ * dependency set stayed invisible to the container that had to serve it.
26643
+ *
26644
+ * The symptom was almost perfectly disguised. Vite writes `_metadata.json`
26645
+ * itself, through this volume, so the directory looked half-populated and
26646
+ * the metadata listed every dependency as optimized. Rolldown wrote the
26647
+ * actual bundles through WASI into the mirror, where nothing brought them
26648
+ * back. Vite then read a file that was not there — and reports a failed read
26649
+ * of an optimized dependency as `504 Outdated Optimize Dep`, which describes
26650
+ * a stale hash and sends everyone looking at hashes. The hash was never
26651
+ * wrong. The file was missing.
26652
+ *
26653
+ * Falling back on read fixes it wherever it happens, for any path, without
26654
+ * polling and without depending on how the engine chose to write.
26655
+ */
26632
26656
  readFileSync(path) {
26633
- return this.inner.readFileSync(path);
26657
+ try {
26658
+ return this.inner.readFileSync(path);
26659
+ } catch (error) {
26660
+ const produced = this.fromMirror(path);
26661
+ if (!produced) throw error;
26662
+ try {
26663
+ this.ensureDirectory(dirname(path));
26664
+ this.inner.writeFileSync(path, produced);
26665
+ } catch {
26666
+ }
26667
+ return produced;
26668
+ }
26634
26669
  }
26635
26670
  readdirSync(path) {
26636
- return this.inner.readdirSync(path);
26671
+ let here = [];
26672
+ let missing;
26673
+ try {
26674
+ here = this.inner.readdirSync(path);
26675
+ } catch (error) {
26676
+ missing = error;
26677
+ }
26678
+ const mirrored = this.mirrorNames(path);
26679
+ if (!mirrored) {
26680
+ if (missing) throw missing;
26681
+ return here;
26682
+ }
26683
+ return [.../* @__PURE__ */ new Set([...here, ...mirrored])].sort();
26637
26684
  }
26638
26685
  lstatSync(path) {
26639
- return this.inner.lstatSync(path);
26686
+ try {
26687
+ return this.inner.lstatSync(path);
26688
+ } catch (error) {
26689
+ if (this.fromMirror(path)) {
26690
+ try {
26691
+ this.readFileSync(path);
26692
+ return this.inner.lstatSync(path);
26693
+ } catch {
26694
+ }
26695
+ }
26696
+ throw error;
26697
+ }
26698
+ }
26699
+ /** The mirror's copy of a file, if it has one and we are allowed to look. */
26700
+ fromMirror(path) {
26701
+ const mirror = this.mirror;
26702
+ if (!mirror?.readFileSync || !mirror.lstatSync || !this.mirrored(path)) return void 0;
26703
+ try {
26704
+ if (!mirror.lstatSync(path).isDirectory()) return mirror.readFileSync(path);
26705
+ } catch {
26706
+ }
26707
+ return void 0;
26708
+ }
26709
+ /** The mirror's entries for a directory, for merging into a listing. */
26710
+ mirrorNames(path) {
26711
+ const mirror = this.mirror;
26712
+ if (!mirror?.readdirSync || !this.mirrored(path)) return void 0;
26713
+ try {
26714
+ return mirror.readdirSync(path);
26715
+ } catch {
26716
+ return void 0;
26717
+ }
26640
26718
  }
26641
26719
  readlinkSync(path) {
26642
26720
  return this.inner.readlinkSync(path);
@@ -26665,11 +26743,76 @@ var MirroringVolume = class {
26665
26743
  this.inner.unlinkSync(path);
26666
26744
  this.sync(path);
26667
26745
  }
26746
+ /**
26747
+ * Rename, carrying anything the mirrored engine put there.
26748
+ *
26749
+ * This is the operation the dependency optimizer is built on, and the one
26750
+ * that used to destroy its output. Vite bundles into a temporary directory
26751
+ * and renames it into place when it is complete — but only half of that
26752
+ * directory is ever on this volume. Vite writes `_metadata.json` and
26753
+ * `package.json` through here; Rolldown writes the actual bundles through
26754
+ * WASI into the mirror. Renaming moved the half that was here and then
26755
+ * `sync(from)` deleted the half that was not, because from this side the
26756
+ * source directory had simply gone.
26757
+ *
26758
+ * What survived was a `deps` directory holding metadata that described five
26759
+ * optimized dependencies and contained none of them — which Vite reports, on
26760
+ * the failed read, as `504 Outdated Optimize Dep`. Nothing in that message is
26761
+ * true, and following it leads to hashes rather than to a missing file.
26762
+ *
26763
+ * So the mirror's side of the move is collected first, and lands here as
26764
+ * part of the rename.
26765
+ */
26668
26766
  renameSync(from, to) {
26669
26767
  this.inner.renameSync(from, to);
26768
+ this.collect(from, to);
26670
26769
  this.sync(from);
26671
26770
  this.sync(to);
26672
26771
  }
26772
+ /**
26773
+ * Copy whatever the mirror holds under `from` into this volume under `to`.
26774
+ *
26775
+ * Deliberately not filtered the way {@link absorb} is: this walks one
26776
+ * directory that is being renamed, not the whole project, so the subtree is
26777
+ * small and `node_modules` is exactly where the interesting case lives.
26778
+ */
26779
+ collect(from, to) {
26780
+ const mirror = this.mirror;
26781
+ if (!mirror?.readdirSync || !mirror.readFileSync || !mirror.lstatSync) return;
26782
+ if (!this.mirrored(from)) return;
26783
+ const walk = (source, destination) => {
26784
+ let stat2;
26785
+ try {
26786
+ stat2 = mirror.lstatSync(source);
26787
+ } catch {
26788
+ return;
26789
+ }
26790
+ if (stat2.isSymbolicLink()) return;
26791
+ if (stat2.isDirectory()) {
26792
+ let names;
26793
+ try {
26794
+ names = mirror.readdirSync(source);
26795
+ } catch {
26796
+ return;
26797
+ }
26798
+ this.ensureDirectory(destination);
26799
+ for (const name of names) walk(join(source, name), join(destination, name));
26800
+ return;
26801
+ }
26802
+ try {
26803
+ this.inner.lstatSync(destination);
26804
+ return;
26805
+ } catch {
26806
+ }
26807
+ try {
26808
+ const bytes2 = mirror.readFileSync(source);
26809
+ this.ensureDirectory(dirname(destination));
26810
+ this.inner.writeFileSync(destination, bytes2);
26811
+ } catch {
26812
+ }
26813
+ };
26814
+ this.safely(() => walk(from, to));
26815
+ }
26673
26816
  symlinkSync(target, path) {
26674
26817
  this.inner.symlinkSync(target, path);
26675
26818
  this.sync(path);