brsh 2.5.5 → 2.6.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/.nvmrc CHANGED
@@ -1 +1 @@
1
- 24
1
+ 24.22.1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [2.6.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.5.6...v2.6.0) (2026-11-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * support POSIX MOTD startup chain and suppress MOTD on initial command ([#24](https://github.com/eliotstocker/Brsh-JS/issues/24)) ([fcb1ea4](https://github.com/eliotstocker/Brsh-JS/commit/fcb1ea49dedc2ec9050cb25cd4aba5aa24e23cdd))
7
+
8
+ ## [2.5.6](https://github.com/eliotstocker/Brsh-JS/compare/v2.5.5...v2.5.6) (2026-11-04)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **security:** pin Node.js to 24.22.1 to address CVE-2026-111497 ([#22](https://github.com/eliotstocker/Brsh-JS/issues/22)) ([593cce5](https://github.com/eliotstocker/Brsh-JS/commit/593cce54d8932d19ccab02c6dcd3998039f6903f))
14
+
1
15
  ## [2.5.5](https://github.com/eliotstocker/Brsh-JS/compare/v2.5.4...v2.5.5) (2026-05-25)
2
16
 
3
17
 
package/Readme.md CHANGED
@@ -68,7 +68,9 @@ All [Shell options](#shell-options) are also accepted and forwarded directly to
68
68
  | option | required | default | description |
69
69
  | ------ | -------- | ------- | ----------- |
70
70
  | path | No | `'/bin'` | Path in which to look for (and register) built-in binaries |
71
- | profile | No | | A script to run before user interactivity (see [scripts](#writing-scripts)) |
71
+ | profile | No | | A script to run before user interactivity (see [scripts](#writing-scripts)). If `/etc/profile` exists on the virtual filesystem, it is sourced first |
72
+ | motd | No | | Optional path to a Message of the Day file/script/directory, or `false` to disable. By default, executable scripts in `/etc/update-motd.d/` and `/etc/motd` are displayed before `profile` on interactive login unless `.hushlogin` exists or an initial `command` is run |
73
+ | command | No | `null` | An initial command string to run after `profile` loads (equivalent to `sh -c <cmd>` / `ssh host <cmd>`). Suppresses MOTD and sets `c` in `$-` during initialization |
72
74
  | hostname | No | `'browser'` | Hostname shown in the prompt |
73
75
  | filesystem | No | `{}` | Object representing the virtual file system. Classes extending `Command` are treated as executables. Use [exportFileSystem](bin/Readme.md) to generate this from a real directory |
74
76
  | permissions | No | `{}` | Map of virtual absolute paths to Unix mode bits (e.g. `{ '/bin/myscript.sh': 0o755 }`). Files without an entry default to `0o644`; function/class entries default to `0o755` |
package/dist/shell.es.js CHANGED
@@ -1859,7 +1859,8 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
1859
1859
  };
1860
1860
  this.sandbox = new r.shell({
1861
1861
  cwd: this.context.fs.cwd,
1862
- ...e
1862
+ ...e,
1863
+ subshell: !0
1863
1864
  }), this.sandbox.context.source(this.context), this.sandbox.on("stdOut", (e) => {
1864
1865
  this.stdOut = e, this.flush();
1865
1866
  }), this.sandbox.on("stdErr", (e) => {
@@ -6261,32 +6262,36 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6261
6262
  }), t.exports = s;
6262
6263
  })), ar = /* @__PURE__ */ t(((e, t) => {
6263
6264
  i();
6264
- var a = ie(), o = G(), s = K(), c = q(), l = W(), u = ce(), d = be(), f = He(), p = ae(), m = C(), h = /\${?([\w\d]+)}?/g, g = p.EventEmitter || p.default || p;
6265
+ var a = ie(), o = G(), s = K(), c = q(), l = W(), u = ce(), d = be(), f = He(), p = ae(), m = C(), h = /\$(?:\{([\w\d?#-]+)\}|([\w\d]+|[?#-]))/g, g = p.EventEmitter || p.default || p;
6265
6266
  String.prototype.regexIndexOf = function(e, t) {
6266
6267
  let n = this.substring(t || 0).search(e);
6267
6268
  return n >= 0 ? n + (t || 0) : n;
6268
6269
  }, ir().shim();
6269
6270
  var _ = class e extends g {
6270
- constructor(t) {
6271
+ constructor(e) {
6271
6272
  super();
6272
- let { path: n = "/bin", profile: r, hostname: i = "browser", filesystem: o = {}, permissions: s = {}, cwd: c = "/", onFsChange: l, useRealFilesystem: u = !1 } = t;
6273
- this.context = new a(Object.assign({}, t, {
6273
+ let { path: t = "/bin", profile: n, motd: r, command: i, interactive: o = !0, subshell: s = !1, hostname: c = "browser", filesystem: l = {}, permissions: u = {}, cwd: d = "/", onFsChange: f, useRealFilesystem: p = !1 } = e;
6274
+ if (this.context = new a(Object.assign({}, e, {
6274
6275
  clearFn: this.clear.bind(this),
6275
6276
  destroyFn: this.destroy.bind(this),
6276
- onFsChange: typeof l == "function" ? l : null
6277
+ onFsChange: typeof f == "function" ? f : null
6277
6278
  })), this._readonlyContext = Object.freeze({
6278
6279
  getVar: (e) => this.context.getVar(e),
6279
6280
  getAlias: (e) => this.context.getAlias(e),
6280
6281
  getCommand: (e) => this.context.getCommand(e)
6281
- }), this.context.setVar("PATH", n), this.context.setVar("HOST", i), u ? this.context.setNodeFilesystem(c) : this.context.setFilesystem(o, s), this.context.setCwd(c);
6282
- let d = u || this.context.fs.exists(this.context.getVar("PATH"));
6283
- this._loadDefaultCommands(), this._loadBuiltinCommands(d), this._lastCode = 0, r ? this._loadProfile(r) : setTimeout(() => this.emit("status", e.STATUS_READY), 0);
6282
+ }), this.context.setVar("PATH", t), this.context.setVar("HOST", c), !s) {
6283
+ let e = (o ? "i" : "") + (i ? "c" : "");
6284
+ e && this.context.setVar("-", e);
6285
+ }
6286
+ p ? this.context.setNodeFilesystem(d) : this.context.setFilesystem(l, u), this.context.setCwd(d);
6287
+ let m = p || this.context.fs.exists(this.context.getVar("PATH"));
6288
+ this._loadDefaultCommands(), this._loadBuiltinCommands(m), this._lastCode = 0, this._subshell = s, this._useRealFilesystem = p, this._profile = n, this._motd = r, this._initialCommand = i || null, this._suppressMotd = !!i, s ? this._initializing = !1 : (this._initializing = !0, setTimeout(() => this._init(), 0));
6284
6289
  }
6285
6290
  get path() {
6286
6291
  return this.context.getVar("PATH");
6287
6292
  }
6288
6293
  set lastCode(e) {
6289
- this.context.setVar("?", e), this._lastCode = e;
6294
+ this.context.setVar("?", String(e)), this._lastCode = e;
6290
6295
  }
6291
6296
  get lastCode() {
6292
6297
  return this._lastCode;
@@ -6322,8 +6327,74 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6322
6327
  this.context.setCommand(e);
6323
6328
  }), e || this.context.fs.setMode(this.context.getVar("PATH"), 365);
6324
6329
  }
6325
- _loadProfile(e) {
6326
- this.onCommand(`source ${e}`);
6330
+ suppressMotd() {
6331
+ this._suppressMotd = !0;
6332
+ let e = this.context.getVar("-");
6333
+ e.includes("c") || this.context.setVar("-", e + "c");
6334
+ }
6335
+ async _init() {
6336
+ try {
6337
+ if (!this._suppressMotd && !this._initialCommand && await this._runMotd(), await this._loadProfile(this._profile), this._initialCommand) {
6338
+ await this.onCommand(this._initialCommand, !1);
6339
+ let e = this.context.getVar("-");
6340
+ e.includes("c") && this.context.setVar("-", e.replace(/c/g, ""));
6341
+ }
6342
+ } finally {
6343
+ this._initializing = !1, this.destroyed || this.emit("status", e.STATUS_READY);
6344
+ }
6345
+ }
6346
+ _hasHushlogin() {
6347
+ if (this.context.fs.exists(".hushlogin")) return !0;
6348
+ let e = this.context.getVar("HOME");
6349
+ return !!(e && this.context.fs.exists(`${e.replace(/\/$/, "")}/.hushlogin`));
6350
+ }
6351
+ async _runMotd() {
6352
+ if (!(this._motd === !1 || this._hasHushlogin())) {
6353
+ if (typeof this._motd == "string") {
6354
+ await this._renderMotdPath(this._motd);
6355
+ return;
6356
+ }
6357
+ this._useRealFilesystem || (this.context.fs.exists("/etc/update-motd.d") && await this._runMotdDir("/etc/update-motd.d"), this.context.fs.exists("/etc/motd") && await this._renderMotdPath("/etc/motd"));
6358
+ }
6359
+ }
6360
+ async _runMotdDir(e) {
6361
+ let t = this.context.fs.getFileByPath(e);
6362
+ if (!t || t.constructor !== Object) return;
6363
+ let n = Object.keys(t).sort(), r = e.endsWith("/") ? e.slice(0, -1) : e;
6364
+ for (let e of n) {
6365
+ let t = `${r}/${e}`, n = this.context.fs.stat(t);
6366
+ !n || n.isDirectory || this.context.fs.isExecutable(t) && await this.onCommand(t, !1);
6367
+ }
6368
+ }
6369
+ async _renderMotdPath(e) {
6370
+ if (!this.context.fs.exists(e)) return;
6371
+ let t = this.context.fs.stat(e);
6372
+ if (!t) return;
6373
+ if (t.isDirectory) {
6374
+ await this._runMotdDir(e);
6375
+ return;
6376
+ }
6377
+ let n = this.context.fs.getFileByPath(e);
6378
+ if (n == null) return;
6379
+ if (typeof n == "function") {
6380
+ this.context.fs.isExecutable(e) && await this.onCommand(e, !1);
6381
+ return;
6382
+ }
6383
+ if (typeof n == "string" && n.startsWith("#!")) {
6384
+ this.context.fs.isExecutable(e) ? await this.onCommand(e, !1) : await this.onCommand(`source ${e}`, !1);
6385
+ return;
6386
+ }
6387
+ let r = n.toString();
6388
+ r.endsWith("\n") && (r = r.slice(0, -1)), r.split(/\r?\n/).forEach((e) => {
6389
+ this.emit("stdOut", e);
6390
+ });
6391
+ }
6392
+ async _loadProfile(e) {
6393
+ if (!this._useRealFilesystem && e !== "/etc/profile" && this.context.fs.exists("/etc/profile")) {
6394
+ let e = this.context.fs.getFileByPath("/etc/profile");
6395
+ typeof e == "string" && e.startsWith("#!") && await this.onCommand("source /etc/profile", !1);
6396
+ }
6397
+ e && await this.onCommand(`source ${e}`, !1);
6327
6398
  }
6328
6399
  onCommand(t, n = !0) {
6329
6400
  let r = this._splitInput(t), i = this._groupPipes(r), a = !0, o = i.reduce((e, { commands: t, op: n }) => e.then(() => {
@@ -6344,7 +6415,7 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6344
6415
  }
6345
6416
  async _runCommand(t) {
6346
6417
  if (!t || t.length < 1) return;
6347
- this.emit("status", e.STATUS_WORKING);
6418
+ this._initializing || this.emit("status", e.STATUS_WORKING);
6348
6419
  let n;
6349
6420
  try {
6350
6421
  n = await this._parseCommandLine(t);
@@ -6523,8 +6594,8 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6523
6594
  }
6524
6595
  let i = t.matchAll(h), a = i.next();
6525
6596
  for (; !a.done;) {
6526
- let n = this.context.getVar(a.value[1]);
6527
- t = t.replace(new RegExp(e._escapeRegExp(a.value[0]), "g"), String(n)), a = i.next();
6597
+ let n = a.value[1] || a.value[2], r = this.context.getVar(n);
6598
+ t = t.replace(new RegExp(e._escapeRegExp(a.value[0]), "g"), String(r)), a = i.next();
6528
6599
  }
6529
6600
  return t;
6530
6601
  }
@@ -6541,7 +6612,8 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6541
6612
  let t = new r.shell({
6542
6613
  cwd: this.context.fs.cwd,
6543
6614
  filesystem: this.context.fs.getRaw(),
6544
- permissions: this.context.fs.getRawPermissions()
6615
+ permissions: this.context.fs.getRawPermissions(),
6616
+ subshell: !0
6545
6617
  });
6546
6618
  t.context.source(this.context);
6547
6619
  let n = [];
@@ -6574,7 +6646,8 @@ var P, F, I, L, R, z, B, ee, V, H, te = e((() => {
6574
6646
  let n = new r.shell({
6575
6647
  cwd: this.context.fs.cwd,
6576
6648
  filesystem: this.context.fs.getRaw(),
6577
- permissions: this.context.fs.getRawPermissions()
6649
+ permissions: this.context.fs.getRawPermissions(),
6650
+ subshell: !0
6578
6651
  });
6579
6652
  n.context.source(this.context), t !== void 0 && (n.stdin = t);
6580
6653
  let i = [];