brsh 1.4.0 → 2.0.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/.github/workflows/busybox-compat.yml +166 -0
- package/.github/workflows/release.yml +40 -0
- package/.releaserc.json +18 -0
- package/CHANGELOG.md +355 -0
- package/bin/brsh-cmd.js +78 -0
- package/bin/exportFileSystem.js +81 -156
- package/busybox-testsuite/cat.tests +49 -0
- package/busybox-testsuite/cp.tests +206 -0
- package/busybox-testsuite/grep.tests +237 -0
- package/busybox-testsuite/testing.sh +180 -0
- package/dist/brsh.css +2 -0
- package/dist/shell.es.js +5667 -0
- package/dist/shell.es.js.map +1 -0
- package/dist/shell.min.js +14 -222
- package/dist/shell.min.js.map +1 -149
- package/dist/terminal.es.js +6228 -0
- package/dist/terminal.es.js.map +1 -0
- package/dist/terminal.min.js +113 -18
- package/dist/terminal.min.js.map +1 -21
- package/index.js +206 -49
- package/lib/Context.js +12 -4
- package/lib/FileSystem.js +99 -6
- package/lib/NodeFileSystem.js +238 -0
- package/lib/ScriptCommand.js +193 -15
- package/lib/Terminal.js +188 -12
- package/lib/WasmCommand.js +252 -0
- package/lib/buildFilesystemStructure.js +58 -0
- package/lib/builtins/cat.js +67 -9
- package/lib/builtins/echo.js +36 -5
- package/lib/builtins/false.js +13 -0
- package/lib/builtins/grep.js +267 -0
- package/lib/builtins/index.js +9 -2
- package/lib/builtins/ls.js +86 -18
- package/lib/builtins/test.js +105 -0
- package/lib/builtins/true.js +10 -0
- package/lib/local/chmod.js +72 -0
- package/lib/local/cp.js +156 -0
- package/lib/local/index.js +8 -1
- package/lib/local/jsfunction.js +58 -0
- package/lib/local/mkdir.js +44 -0
- package/lib/local/mv.js +96 -0
- package/lib/local/pwd.js +13 -0
- package/lib/local/read.js +6 -4
- package/lib/local/rm.js +71 -0
- package/lib/local/which.js +2 -2
- package/package.json +31 -34
- package/test/builtins.test.js +505 -0
- package/test/exportFileSystem.test.js +226 -0
- package/test/helpers.js +35 -0
- package/test/local-commands.test.js +593 -0
- package/test/node-filesystem.test.js +133 -0
- package/test/scripts.test.js +277 -0
- package/test/shell.test.js +245 -0
- package/test/streaming.test.js +113 -0
- package/vite.config.shell.js +21 -0
- package/vite.config.terminal.js +27 -0
- package/vitest.config.js +15 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
3
|
+
import { createShell } from './helpers.js';
|
|
4
|
+
|
|
5
|
+
// Use createRequire so Command shares the same CJS module instance as
|
|
6
|
+
// index.js's internal require() — required for instanceof checks.
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const Command = require('../lib/Command.js');
|
|
9
|
+
|
|
10
|
+
// A command that flushes output in chunks before completing.
|
|
11
|
+
class ProgressCommand extends Command {
|
|
12
|
+
get name() { return 'progress'; }
|
|
13
|
+
|
|
14
|
+
run() {
|
|
15
|
+
this.stdOut = 'step:1';
|
|
16
|
+
this.flush();
|
|
17
|
+
this.stdOut = 'step:2';
|
|
18
|
+
this.flush();
|
|
19
|
+
// step:3 arrives via the resolved value (not flushed early)
|
|
20
|
+
return Promise.resolve('step:3');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// A command with an async pause between flushes.
|
|
25
|
+
class AsyncProgressCommand extends Command {
|
|
26
|
+
get name() { return 'async-progress'; }
|
|
27
|
+
|
|
28
|
+
run() {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
this.stdOut = 'async:1';
|
|
31
|
+
this.flush();
|
|
32
|
+
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
this.stdOut = 'async:2';
|
|
35
|
+
this.flush();
|
|
36
|
+
resolve('async:3');
|
|
37
|
+
}, 20);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('real-time streaming output', () => {
|
|
43
|
+
let shell;
|
|
44
|
+
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
shell = await createShell({
|
|
47
|
+
filesystem: {
|
|
48
|
+
bin: {
|
|
49
|
+
progress: ProgressCommand,
|
|
50
|
+
'async-progress': AsyncProgressCommand
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('receives flushed output before the command finishes (sync)', async () => {
|
|
57
|
+
const received = [];
|
|
58
|
+
shell.on('stdOut', (line) => received.push(line));
|
|
59
|
+
await shell.onCommand('./bin/progress');
|
|
60
|
+
shell.removeAllListeners('stdOut');
|
|
61
|
+
|
|
62
|
+
expect(received).toContain('step:1');
|
|
63
|
+
expect(received).toContain('step:2');
|
|
64
|
+
expect(received).toContain('step:3');
|
|
65
|
+
expect(received.indexOf('step:1')).toBeLessThan(received.indexOf('step:3'));
|
|
66
|
+
expect(received.indexOf('step:2')).toBeLessThan(received.indexOf('step:3'));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('receives flushed output in order (sync)', async () => {
|
|
70
|
+
const received = [];
|
|
71
|
+
shell.on('stdOut', (line) => received.push(line));
|
|
72
|
+
await shell.onCommand('./bin/progress');
|
|
73
|
+
shell.removeAllListeners('stdOut');
|
|
74
|
+
|
|
75
|
+
expect(received).toEqual(['step:1', 'step:2', 'step:3']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('receives flushed output before the command finishes (async)', async () => {
|
|
79
|
+
const received = [];
|
|
80
|
+
shell.on('stdOut', (line) => received.push(line));
|
|
81
|
+
await shell.onCommand('./bin/async-progress');
|
|
82
|
+
shell.removeAllListeners('stdOut');
|
|
83
|
+
|
|
84
|
+
expect(received).toContain('async:1');
|
|
85
|
+
expect(received).toContain('async:2');
|
|
86
|
+
expect(received).toContain('async:3');
|
|
87
|
+
expect(received.indexOf('async:1')).toBeLessThan(received.indexOf('async:3'));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('does not double-emit flushed lines in the final output', async () => {
|
|
91
|
+
const received = [];
|
|
92
|
+
shell.on('stdOut', (line) => received.push(line));
|
|
93
|
+
await shell.onCommand('./bin/progress');
|
|
94
|
+
shell.removeAllListeners('stdOut');
|
|
95
|
+
|
|
96
|
+
expect(received.filter((l) => l === 'step:1').length).toBe(1);
|
|
97
|
+
expect(received.filter((l) => l === 'step:2').length).toBe(1);
|
|
98
|
+
expect(received.filter((l) => l === 'step:3').length).toBe(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('read command streams its prompt before blocking', () => {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const tid = setTimeout(() => reject(new Error('prompt not streamed')), 500);
|
|
104
|
+
shell.once('stdErr', (line) => {
|
|
105
|
+
clearTimeout(tid);
|
|
106
|
+
expect(line).toBe('> ');
|
|
107
|
+
shell.onInput('x');
|
|
108
|
+
resolve();
|
|
109
|
+
});
|
|
110
|
+
shell.onCommand('read -p "> " -n 1 V');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
nodePolyfills()
|
|
8
|
+
],
|
|
9
|
+
build: {
|
|
10
|
+
lib: {
|
|
11
|
+
entry: path.resolve(import.meta.dirname, 'index.js'),
|
|
12
|
+
name: 'Shell',
|
|
13
|
+
formats: ['es', 'iife'],
|
|
14
|
+
fileName: (format) => format === 'iife' ? 'shell.min.js' : 'shell.es.js'
|
|
15
|
+
},
|
|
16
|
+
minify: true,
|
|
17
|
+
sourcemap: true,
|
|
18
|
+
outDir: 'dist',
|
|
19
|
+
emptyOutDir: false
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [
|
|
7
|
+
nodePolyfills()
|
|
8
|
+
],
|
|
9
|
+
resolve: {
|
|
10
|
+
// Terminal.js does require('Shell') — point that at the real entry
|
|
11
|
+
alias: {
|
|
12
|
+
Shell: path.resolve(import.meta.dirname, 'index.js')
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
build: {
|
|
16
|
+
lib: {
|
|
17
|
+
entry: path.resolve(import.meta.dirname, 'lib/Terminal.js'),
|
|
18
|
+
name: 'Terminal',
|
|
19
|
+
formats: ['es', 'iife'],
|
|
20
|
+
fileName: (format) => format === 'iife' ? 'terminal.min.js' : 'terminal.es.js'
|
|
21
|
+
},
|
|
22
|
+
minify: true,
|
|
23
|
+
sourcemap: true,
|
|
24
|
+
outDir: 'dist',
|
|
25
|
+
emptyOutDir: false
|
|
26
|
+
}
|
|
27
|
+
});
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
environment: 'node',
|
|
6
|
+
globals: false,
|
|
7
|
+
include: ['test/**/*.test.js'],
|
|
8
|
+
testTimeout: 10000,
|
|
9
|
+
coverage: {
|
|
10
|
+
provider: 'v8',
|
|
11
|
+
include: ['index.js', 'lib/**/*.js', 'bin/exportFileSystem.js'],
|
|
12
|
+
exclude: ['lib/Terminal.js', 'lib/terminal.css']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|