brsh 3.1.3 → 3.2.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/CHANGELOG.md +14 -0
- package/dist/brsh.css +1 -1
- package/dist/shell.es.js +9 -4
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +4 -3
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +1 -1
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +1 -1
- package/dist/wbt.min.js.map +1 -1
- package/index.js +10 -3
- package/lib/ScriptCommand.js +8 -0
- package/package.json +3 -3
- package/styles/terminal.css +2 -0
- package/test/scripts.test.js +29 -0
package/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const BaseFileSystem = require('./lib/BaseFileSystem');
|
|
|
18
18
|
const BinaryContainer = require('./lib/BinaryContainer');
|
|
19
19
|
const { isAsyncFilesystemSource, resolveFilesystemSource } = BinaryContainer;
|
|
20
20
|
|
|
21
|
-
const variableRegex = /\$(?:\{([\w\d
|
|
21
|
+
const variableRegex = /\$(?:\{([\w\d?#@*-]+)\}|([\w\d]+|[?#@*-]))/g;
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
const EventEmitter = events.EventEmitter || events.default || events;
|
|
@@ -1016,8 +1016,7 @@ class Shell extends EventEmitter {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
|
|
1018
1018
|
_splitInput(input) {
|
|
1019
|
-
|
|
1020
|
-
return this._parseOperators(commentStripped);
|
|
1019
|
+
return this._parseOperators(input);
|
|
1021
1020
|
}
|
|
1022
1021
|
|
|
1023
1022
|
_parseOperators(input) {
|
|
@@ -1031,6 +1030,14 @@ class Shell extends EventEmitter {
|
|
|
1031
1030
|
if (ch === "'" && !dq) { sq = !sq; current += ch; i++; continue; }
|
|
1032
1031
|
if (ch === '"' && !sq) { dq = !dq; current += ch; i++; continue; }
|
|
1033
1032
|
if (!sq && !dq) {
|
|
1033
|
+
if (ch === '#' && (current.trim() === '' || /\s/.test(input[i - 1]))) {
|
|
1034
|
+
const nextNewline = input.indexOf('\n', i);
|
|
1035
|
+
if (nextNewline === -1) {
|
|
1036
|
+
break;
|
|
1037
|
+
}
|
|
1038
|
+
i = nextNewline;
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1034
1041
|
if (ch === '&' && input[i + 1] === '&') {
|
|
1035
1042
|
segments.push({ command: current.trim(), op: '&&' });
|
|
1036
1043
|
current = ''; i += 2; continue;
|
package/lib/ScriptCommand.js
CHANGED
|
@@ -44,6 +44,14 @@ class ScriptCommand extends LocalCommand {
|
|
|
44
44
|
});
|
|
45
45
|
this.sandbox.context.source(this.context);
|
|
46
46
|
|
|
47
|
+
if (Array.isArray(this.arguments)) {
|
|
48
|
+
this.arguments.forEach((arg, i) =>
|
|
49
|
+
this.sandbox.context.setVar(String(i + 1), arg));
|
|
50
|
+
this.sandbox.context.setVar('#', String(this.arguments.length));
|
|
51
|
+
this.sandbox.context.setVar('@', this.arguments.join(' '));
|
|
52
|
+
this.sandbox.context.setVar('*', this.arguments.join(' '));
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
this.sandbox.on('stdOut', data => { this.stdOut = data; this.flush(); });
|
|
48
56
|
this.sandbox.on('stdErr', data => { this.stdErr = data; this.flush(); });
|
|
49
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brsh",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "A unix like shell written in javascript",
|
|
5
5
|
"main": "./dist/shell.min.js",
|
|
6
6
|
"module": "./dist/shell.es.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"brsh": "bin/brsh-shell.js"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"start": "node bin/exportFileSystem.js ./demo/filesystem -o ./demo/fs.js -v fs && vite --config vite.config.js demo/",
|
|
30
|
-
"build:demofs": "node bin/exportFileSystem.js ./demo/filesystem -o ./dist-demo/fs.js -v fs",
|
|
29
|
+
"start": "node bin/exportFileSystem.js ./demo/filesystem -o ./demo/fs.js -v fs --binary -c && vite --config vite.config.js demo/",
|
|
30
|
+
"build:demofs": "node bin/exportFileSystem.js ./demo/filesystem -o ./dist-demo/fs.js -v fs --binary -c",
|
|
31
31
|
"build:demo": "vite build --config vite.config.demo.js && npm run build:demofs",
|
|
32
32
|
"build": "npm run build:shell && npm run build:terminal && npm run build:wbt",
|
|
33
33
|
"build:shell": "vite build --config vite.config.shell.js",
|
package/styles/terminal.css
CHANGED
package/test/scripts.test.js
CHANGED
|
@@ -130,6 +130,35 @@ describe('shell script execution', () => {
|
|
|
130
130
|
expect(errors.length).toBeGreaterThan(0);
|
|
131
131
|
expect(exitCode).toBeGreaterThan(0);
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
it('passes positional parameters to a script', async () => {
|
|
135
|
+
const shell = await createShell({
|
|
136
|
+
filesystem: {
|
|
137
|
+
scripts: {
|
|
138
|
+
'args.sh': '#!/bin/sh\necho 1: $1\necho 2: $2\necho count: $#\necho all: $@\n'
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
permissions: { '/scripts/args.sh': 0o755 }
|
|
142
|
+
});
|
|
143
|
+
const { output } = await run(shell, '/scripts/args.sh "hello world" test');
|
|
144
|
+
expect(output).toContain('1: hello world');
|
|
145
|
+
expect(output).toContain('2: test');
|
|
146
|
+
expect(output).toContain('count: 2');
|
|
147
|
+
expect(output).toContain('all: hello world test');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('forwards "$@" to subcommands within a script', async () => {
|
|
151
|
+
const shell = await createShell({
|
|
152
|
+
filesystem: {
|
|
153
|
+
scripts: {
|
|
154
|
+
'forward.sh': '#!/bin/sh\necho "$@"\n'
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
permissions: { '/scripts/forward.sh': 0o755 }
|
|
158
|
+
});
|
|
159
|
+
const { output } = await run(shell, '/scripts/forward.sh "quoted string"');
|
|
160
|
+
expect(output).toContain('quoted string');
|
|
161
|
+
});
|
|
133
162
|
});
|
|
134
163
|
|
|
135
164
|
// ---------------------------------------------------------------------------
|