brsh 3.1.0 → 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/CHANGELOG.md +21 -0
- package/dist/shell.es.js +33 -19
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +2 -2
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +2 -2
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +5 -5
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +2 -2
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +25 -20
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +2 -2
- package/dist/wbt.min.js.map +1 -1
- package/index.js +20 -0
- package/lib/ScriptCommand.js +4 -3
- package/lib/Terminal.js +32 -5
- package/lib/WasmCommand.js +5 -3
- package/lib/wbt/index.js +4 -0
- package/package.json +1 -1
- package/test/shell.test.js +49 -0
- package/test/terminal.test.js +51 -0
- package/test/wbt.test.js +17 -0
package/index.js
CHANGED
|
@@ -1286,6 +1286,26 @@ class Shell extends EventEmitter {
|
|
|
1286
1286
|
continue;
|
|
1287
1287
|
}
|
|
1288
1288
|
|
|
1289
|
+
// Escape handling inside double quotes
|
|
1290
|
+
if (doubleQuoteOpen && ch === '\\' && i + 1 < string.length) {
|
|
1291
|
+
const next = string[i + 1];
|
|
1292
|
+
if (next === '"' || next === '\\' || next === '$') {
|
|
1293
|
+
tokenBuffer.push(next);
|
|
1294
|
+
i++;
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// Escape handling outside quotes
|
|
1300
|
+
if (!singleQuoteOpen && !doubleQuoteOpen && ch === '\\' && i + 1 < string.length) {
|
|
1301
|
+
const next = string[++i];
|
|
1302
|
+
tokenBuffer.push(next);
|
|
1303
|
+
if (next === '"' || next === "'") {
|
|
1304
|
+
tokenHasQuote = true;
|
|
1305
|
+
}
|
|
1306
|
+
continue;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1289
1309
|
// Quote handling
|
|
1290
1310
|
if (ch === "'" && !doubleQuoteOpen) {
|
|
1291
1311
|
singleQuoteOpen = !singleQuoteOpen;
|
package/lib/ScriptCommand.js
CHANGED
|
@@ -33,11 +33,12 @@ class ScriptCommand extends LocalCommand {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
run() {
|
|
36
|
-
const
|
|
36
|
+
const fs = (this.context && this.context.fs) || this.fs;
|
|
37
|
+
const fsOpts = fs && fs.isRealFilesystem
|
|
37
38
|
? { useRealFilesystem: true }
|
|
38
|
-
: { filesystem:
|
|
39
|
+
: { filesystem: (fs && fs.getRaw()) || {}, permissions: (fs && fs.getRawPermissions()) || {} };
|
|
39
40
|
this.sandbox = new globalThis.shell({
|
|
40
|
-
cwd:
|
|
41
|
+
cwd: (fs && fs.cwd) || '/',
|
|
41
42
|
...fsOpts,
|
|
42
43
|
subshell: true
|
|
43
44
|
});
|
package/lib/Terminal.js
CHANGED
|
@@ -133,6 +133,8 @@ class Terminal {
|
|
|
133
133
|
this._titleListeners = [];
|
|
134
134
|
this._mouseButtonDown = null;
|
|
135
135
|
|
|
136
|
+
this._mobileInputElement = null;
|
|
137
|
+
this._onMobileInputClick = null;
|
|
136
138
|
this._typeQueue = '';
|
|
137
139
|
this._typeTimer = null;
|
|
138
140
|
this._isHandlingInput = false;
|
|
@@ -872,14 +874,28 @@ class Terminal {
|
|
|
872
874
|
if (typeof document === 'undefined' || !this._el) return;
|
|
873
875
|
const input = document.createElement('input');
|
|
874
876
|
input.type = 'text';
|
|
875
|
-
input.style.position = '
|
|
876
|
-
input.style.
|
|
877
|
+
input.style.position = 'fixed';
|
|
878
|
+
input.style.top = '0';
|
|
879
|
+
input.style.left = '0';
|
|
880
|
+
input.style.width = '0';
|
|
881
|
+
input.style.height = '0';
|
|
882
|
+
input.style.opacity = '0';
|
|
883
|
+
input.style.pointerEvents = 'none';
|
|
884
|
+
input.style.zIndex = '-1';
|
|
885
|
+
input.setAttribute('aria-hidden', 'true');
|
|
886
|
+
input.setAttribute('tabindex', '-1');
|
|
877
887
|
this._el.appendChild(input);
|
|
888
|
+
this._mobileInputElement = input;
|
|
878
889
|
this._mobileInputBuffer = '';
|
|
879
890
|
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
891
|
+
this._onMobileInputClick = (e) => {
|
|
892
|
+
// Avoid stealing focus when clicking hyperlinks
|
|
893
|
+
if (e && e.target && e.target.tagName === 'A') return;
|
|
894
|
+
if (typeof input.focus === 'function') {
|
|
895
|
+
input.focus({ preventScroll: true });
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
this._el.addEventListener('click', this._onMobileInputClick);
|
|
883
899
|
|
|
884
900
|
input.addEventListener('keypress', e => {
|
|
885
901
|
if (e.key === 'Enter') {
|
|
@@ -931,6 +947,17 @@ class Terminal {
|
|
|
931
947
|
if (this._onKeyDown) window.removeEventListener('keydown', this._onKeyDown);
|
|
932
948
|
if (this._onPaste) window.removeEventListener('paste', this._onPaste);
|
|
933
949
|
}
|
|
950
|
+
if (this._mobileInputElement) {
|
|
951
|
+
if (this._onMobileInputClick && this._el && typeof this._el.removeEventListener === 'function') {
|
|
952
|
+
this._el.removeEventListener('click', this._onMobileInputClick);
|
|
953
|
+
}
|
|
954
|
+
if (this._mobileInputElement.parentNode) {
|
|
955
|
+
this._mobileInputElement.parentNode.removeChild(this._mobileInputElement);
|
|
956
|
+
} else if (typeof this._mobileInputElement.remove === 'function') {
|
|
957
|
+
this._mobileInputElement.remove();
|
|
958
|
+
}
|
|
959
|
+
this._mobileInputElement = null;
|
|
960
|
+
}
|
|
934
961
|
this._dataListeners = [];
|
|
935
962
|
this._resizeListeners = [];
|
|
936
963
|
this._titleListeners = [];
|
package/lib/WasmCommand.js
CHANGED
|
@@ -47,16 +47,18 @@ class WasmCommand extends ScriptCommand {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
_loadBytes(filepath, nodeFs) {
|
|
50
|
-
|
|
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(
|
|
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 =
|
|
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
package/test/shell.test.js
CHANGED
|
@@ -215,6 +215,55 @@ describe('unclosed quote error', () => {
|
|
|
215
215
|
});
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
+
describe('backslash quote escaping', () => {
|
|
219
|
+
let shell;
|
|
220
|
+
beforeEach(async () => { shell = await createShell(); });
|
|
221
|
+
|
|
222
|
+
it('parses echo "hello \\"world\\"" to [\'echo\', \'hello "world"\']', async () => {
|
|
223
|
+
const cmd = 'echo "hello \\"world\\""';
|
|
224
|
+
const parts = Shell._splitCommand(cmd).map(p => p.value);
|
|
225
|
+
expect(parts).toEqual(['echo', 'hello "world"']);
|
|
226
|
+
|
|
227
|
+
const { output, errors, exitCode } = await run(shell, cmd);
|
|
228
|
+
expect(errors).toHaveLength(0);
|
|
229
|
+
expect(exitCode).toBe(0);
|
|
230
|
+
expect(output).toEqual(['hello "world"']);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('parses echo "Eliot\'s CV with \\"nested quotes\\"" cleanly without throwing quote expression not closed', async () => {
|
|
234
|
+
const cmd = 'echo "Eliot\'s CV with \\"nested quotes\\""';
|
|
235
|
+
const parts = Shell._splitCommand(cmd).map(p => p.value);
|
|
236
|
+
expect(parts).toEqual(['echo', 'Eliot\'s CV with "nested quotes"']);
|
|
237
|
+
|
|
238
|
+
const { output, errors, exitCode } = await run(shell, cmd);
|
|
239
|
+
expect(errors).toHaveLength(0);
|
|
240
|
+
expect(exitCode).toBe(0);
|
|
241
|
+
expect(output).toEqual(['Eliot\'s CV with "nested quotes"']);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('parses echo \'Eliot\'\\\'\'s experience\' correctly into [\'echo\', "Eliot\'s experience"]', async () => {
|
|
245
|
+
const cmd = "echo 'Eliot'\\''s experience'";
|
|
246
|
+
const parts = Shell._splitCommand(cmd).map(p => p.value);
|
|
247
|
+
expect(parts).toEqual(['echo', "Eliot's experience"]);
|
|
248
|
+
|
|
249
|
+
const { output, errors, exitCode } = await run(shell, cmd);
|
|
250
|
+
expect(errors).toHaveLength(0);
|
|
251
|
+
expect(exitCode).toBe(0);
|
|
252
|
+
expect(output).toEqual(["Eliot's experience"]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('parses echo \\"unquoted\\" to [\'echo\', \'"unquoted"\']', async () => {
|
|
256
|
+
const cmd = 'echo \\"unquoted\\"';
|
|
257
|
+
const parts = Shell._splitCommand(cmd).map(p => p.value);
|
|
258
|
+
expect(parts).toEqual(['echo', '"unquoted"']);
|
|
259
|
+
|
|
260
|
+
const { output, errors, exitCode } = await run(shell, cmd);
|
|
261
|
+
expect(errors).toHaveLength(0);
|
|
262
|
+
expect(exitCode).toBe(0);
|
|
263
|
+
expect(output).toEqual(['"unquoted"']);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
218
267
|
describe('output redirection', () => {
|
|
219
268
|
it('writes command stdout to a file with >', async () => {
|
|
220
269
|
const shell = await createShell({ filesystem: { home: {} } });
|
package/test/terminal.test.js
CHANGED
|
@@ -39,6 +39,12 @@ function createMockDom() {
|
|
|
39
39
|
if (!this._listeners[ev]) this._listeners[ev] = [];
|
|
40
40
|
this._listeners[ev].push(fn);
|
|
41
41
|
},
|
|
42
|
+
removeEventListener(ev, fn) {
|
|
43
|
+
const list = this._listeners[ev];
|
|
44
|
+
if (!list) return;
|
|
45
|
+
const i = list.indexOf(fn);
|
|
46
|
+
if (i !== -1) list.splice(i, 1);
|
|
47
|
+
},
|
|
42
48
|
dispatchEvent(ev, payload = {}) {
|
|
43
49
|
const fns = this._listeners[ev] || [];
|
|
44
50
|
for (const fn of fns) fn(payload);
|
|
@@ -832,4 +838,49 @@ describe('Output Typing Animation Suppression', () => {
|
|
|
832
838
|
term.reset();
|
|
833
839
|
}
|
|
834
840
|
});
|
|
841
|
+
|
|
842
|
+
describe('mobileInput and destroy cleanup', () => {
|
|
843
|
+
it('anchors off-screen input at fixed (0, 0) and uses preventScroll', () => {
|
|
844
|
+
const el = document.createElement('div');
|
|
845
|
+
const term = new Terminal({
|
|
846
|
+
el,
|
|
847
|
+
Shell: false,
|
|
848
|
+
mobileInput: 'click'
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
const input = term._mobileInputElement;
|
|
852
|
+
expect(input).toBeDefined();
|
|
853
|
+
expect(input.style.position).toBe('fixed');
|
|
854
|
+
expect(input.style.top).toBe('0');
|
|
855
|
+
expect(input.style.left).toBe('0');
|
|
856
|
+
expect(input.style.width).toBe('0');
|
|
857
|
+
expect(input.style.height).toBe('0');
|
|
858
|
+
expect(input.style.opacity).toBe('0');
|
|
859
|
+
expect(input.style.pointerEvents).toBe('none');
|
|
860
|
+
expect(input.style.zIndex).toBe('-1');
|
|
861
|
+
expect(input['aria-hidden']).toBe('true');
|
|
862
|
+
expect(input.tabindex).toBe('-1');
|
|
863
|
+
|
|
864
|
+
let focusedWith = null;
|
|
865
|
+
input.focus = (opts) => {
|
|
866
|
+
focusedWith = opts;
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
// Clicking terminal focuses with preventScroll: true
|
|
870
|
+
el.dispatchEvent('click', { target: el });
|
|
871
|
+
expect(focusedWith).toEqual({ preventScroll: true });
|
|
872
|
+
|
|
873
|
+
// Clicking a link does not trigger focus
|
|
874
|
+
focusedWith = null;
|
|
875
|
+
const link = document.createElement('a');
|
|
876
|
+
el.dispatchEvent('click', { target: link });
|
|
877
|
+
expect(focusedWith).toBeNull();
|
|
878
|
+
|
|
879
|
+
// Destroy removes input from DOM and cleans up
|
|
880
|
+
expect(el.children).toContain(input);
|
|
881
|
+
term.destroy();
|
|
882
|
+
expect(el.children).not.toContain(input);
|
|
883
|
+
expect(term._mobileInputElement).toBeNull();
|
|
884
|
+
});
|
|
885
|
+
});
|
|
835
886
|
});
|
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
|
|