brsh 3.1.1 → 3.1.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.
@@ -33,11 +33,12 @@ class ScriptCommand extends LocalCommand {
33
33
  }
34
34
 
35
35
  run() {
36
- const fsOpts = this.context.fs.isRealFilesystem
36
+ const fs = (this.context && this.context.fs) || this.fs;
37
+ const fsOpts = fs && fs.isRealFilesystem
37
38
  ? { useRealFilesystem: true }
38
- : { filesystem: this.context.fs.getRaw(), permissions: this.context.fs.getRawPermissions() };
39
+ : { filesystem: (fs && fs.getRaw()) || {}, permissions: (fs && fs.getRawPermissions()) || {} };
39
40
  this.sandbox = new globalThis.shell({
40
- cwd: this.context.fs.cwd,
41
+ cwd: (fs && fs.cwd) || '/',
41
42
  ...fsOpts,
42
43
  subshell: true
43
44
  });
@@ -47,16 +47,18 @@ class WasmCommand extends ScriptCommand {
47
47
  }
48
48
 
49
49
  _loadBytes(filepath, nodeFs) {
50
- if (this.context.fs.isRealFilesystem && nodeFs) {
50
+ const fs = (this.context && this.context.fs) || this.fs;
51
+ if (!fs) return Promise.reject(new Error(`${filepath}: Filesystem is not available`));
52
+ if (fs.isRealFilesystem && nodeFs) {
51
53
  try {
52
- const buf = nodeFs.readFileSync(this.context.fs.absolutePath(filepath));
54
+ const buf = nodeFs.readFileSync(fs.absolutePath(filepath));
53
55
  const bytes = new Uint8Array(buf);
54
56
  return Promise.resolve({ bytes, isWat: this._isWat(filepath, bytes) });
55
57
  } catch(e) {
56
58
  return Promise.reject(new Error(`${filepath}: ${e.message}`));
57
59
  }
58
60
  }
59
- const content = this.context.fs.getFileByPath(filepath);
61
+ const content = fs.getFileByPath(filepath);
60
62
  if (content == null) return Promise.reject(new Error(`${filepath}: No such file or directory`));
61
63
  const bytes = this._contentToBytes(content);
62
64
  return Promise.resolve({ bytes, isWat: this._isWat(filepath, bytes) });
package/lib/wbt/index.js CHANGED
@@ -17,12 +17,16 @@ function createCustomWasmBinCommand(binName, wasmPath, pkgMeta = {}) {
17
17
  class CustomWasmBin extends WasmCommand {
18
18
  static get name() { return binName; }
19
19
  get name() { return binName; }
20
+ get requiresFilesystem() { return true; }
20
21
 
21
22
  constructor(args, context) {
22
23
  super(wasmPath, args, context);
23
24
  this.script = wasmPath;
24
25
  this.arguments = args || [];
25
26
  this.context = context || null;
27
+ if (context && context.fs && !this.fs) {
28
+ this.fs = context.fs;
29
+ }
26
30
  this._pkgMeta = pkgMeta;
27
31
  }
28
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brsh",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "A unix like shell written in javascript",
5
5
  "main": "./dist/shell.min.js",
6
6
  "module": "./dist/shell.es.js",
package/test/wbt.test.js CHANGED
@@ -1279,6 +1279,23 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
1279
1279
  expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(false);
1280
1280
  expect(shell.context.fs.exists('/var/lib/wbt/wasm/nano.wasm')).toBe(false);
1281
1281
  });
1282
+
1283
+ it('runs nano even when invoked with readonlyContext without context.fs', async () => {
1284
+ await run(shell, 'wbt install nano');
1285
+ const NanoCmd = shell.context.fs.getFileByPath('/bin/nano');
1286
+ expect(NanoCmd).toBeDefined();
1287
+
1288
+ const readonlyCtx = Object.freeze({
1289
+ getVar: (k) => shell.context.getVar(k),
1290
+ getAlias: (k) => shell.context.getAlias(k),
1291
+ getCommand: (k) => shell.context.getCommand(k)
1292
+ });
1293
+ const instance = new NanoCmd(['--version'], readonlyCtx);
1294
+ instance.fs = shell.context.fs.sandbox();
1295
+ const res = await instance.runCommand();
1296
+ expect(res.getExitCode()).toBe(0);
1297
+ expect(res.getStdOutput().map(l => l.string).join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.0.*wasm/i);
1298
+ });
1282
1299
  });
1283
1300
 
1284
1301