brsh 3.1.1 → 3.1.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.
package/dist/wbt.es.js CHANGED
@@ -1198,26 +1198,26 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
1198
1198
  this.sandbox && this.sandbox.onInput(e);
1199
1199
  }
1200
1200
  run() {
1201
- let e = this.context.fs.isRealFilesystem ? { useRealFilesystem: !0 } : {
1202
- filesystem: this.context.fs.getRaw(),
1203
- permissions: this.context.fs.getRawPermissions()
1201
+ let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
1202
+ filesystem: e && e.getRaw() || {},
1203
+ permissions: e && e.getRawPermissions() || {}
1204
1204
  };
1205
1205
  this.sandbox = new globalThis.shell({
1206
- cwd: this.context.fs.cwd,
1207
- ...e,
1206
+ cwd: e && e.cwd || "/",
1207
+ ...t,
1208
1208
  subshell: !0
1209
1209
  }), this.sandbox.context.source(this.context), this.sandbox.on("stdOut", (e) => {
1210
1210
  this.stdOut = e, this.flush();
1211
1211
  }), this.sandbox.on("stdErr", (e) => {
1212
1212
  this.stdErr = e, this.flush();
1213
1213
  }), this._scriptFunctions = {};
1214
- let t = this.script.split(/\r?\n/);
1215
- if (!r(t[0])) {
1216
- let e = t[0].startsWith("#!") ? t[0].slice(2).split(/\s/)[0] : t[0];
1214
+ let n = this.script.split(/\r?\n/);
1215
+ if (!r(n[0])) {
1216
+ let e = n[0].startsWith("#!") ? n[0].slice(2).split(/\s/)[0] : n[0];
1217
1217
  return Promise.reject(`${e}: bad interpreter: No such file or directory`);
1218
1218
  }
1219
- let n = this._parseLines(t.slice(1));
1220
- return this._executeNodes(n).catch((e) => {
1219
+ let i = this._parseLines(n.slice(1));
1220
+ return this._executeNodes(i).catch((e) => {
1221
1221
  if (e && e.__type === "return") this.sandbox.lastCode = e.code;
1222
1222
  else if (e && e.__type === "errexit") this.sandbox.lastCode = e.code;
1223
1223
  else if (e && (e.__type === "break" || e.__type === "continue")) this.stdErr = `${e.__type}: only meaningful in a for or while loop`, this.sandbox.lastCode = 1;
@@ -2417,21 +2417,23 @@ var R, z, B, V, H, U, W, G, ee, K, te = e((() => {
2417
2417
  });
2418
2418
  }
2419
2419
  _loadBytes(e, t) {
2420
- if (this.context.fs.isRealFilesystem && t) try {
2421
- let n = t.readFileSync(this.context.fs.absolutePath(e)), r = new Uint8Array(n);
2420
+ let n = this.context && this.context.fs || this.fs;
2421
+ if (!n) return Promise.reject(/* @__PURE__ */ Error(`${e}: Filesystem is not available`));
2422
+ if (n.isRealFilesystem && t) try {
2423
+ let r = t.readFileSync(n.absolutePath(e)), i = new Uint8Array(r);
2422
2424
  return Promise.resolve({
2423
- bytes: r,
2424
- isWat: this._isWat(e, r)
2425
+ bytes: i,
2426
+ isWat: this._isWat(e, i)
2425
2427
  });
2426
2428
  } catch (t) {
2427
2429
  return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
2428
2430
  }
2429
- let n = this.context.fs.getFileByPath(e);
2430
- if (n == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
2431
- let r = this._contentToBytes(n);
2431
+ let r = n.getFileByPath(e);
2432
+ if (r == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
2433
+ let i = this._contentToBytes(r);
2432
2434
  return Promise.resolve({
2433
- bytes: r,
2434
- isWat: this._isWat(e, r)
2435
+ bytes: i,
2436
+ isWat: this._isWat(e, i)
2435
2437
  });
2436
2438
  }
2437
2439
  _isWat(e, t) {
@@ -4462,8 +4464,11 @@ var R, z, B, V, H, U, W, G, ee, K, te = e((() => {
4462
4464
  get name() {
4463
4465
  return e;
4464
4466
  }
4467
+ get requiresFilesystem() {
4468
+ return !0;
4469
+ }
4465
4470
  constructor(e, r) {
4466
- super(t, e, r), this.script = t, this.arguments = e || [], this.context = r || null, this._pkgMeta = n;
4471
+ super(t, e, r), this.script = t, this.arguments = e || [], this.context = r || null, r && r.fs && !this.fs && (this.fs = r.fs), this._pkgMeta = n;
4467
4472
  }
4468
4473
  }
4469
4474
  return r;