brsh 2.1.1 → 2.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/.github/workflows/pages.yml +12 -1
- package/.nvmrc +1 -0
- package/CHANGELOG.md +14 -0
- package/Readme.md +191 -3
- package/bin/brsh-shell.js +65 -0
- package/dist/brsh.css +1 -1
- package/dist/shell.es.js +854 -577
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +13 -9
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.es.js +874 -588
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +16 -12
- package/dist/terminal.min.js.map +1 -1
- package/index.js +65 -10
- package/lib/BaseFileSystem.js +82 -0
- package/lib/Command.js +3 -1
- package/lib/Context.js +3 -2
- package/lib/FileSystem.js +55 -26
- package/lib/NodeFileSystem.js +31 -17
- package/lib/Terminal.js +34 -5
- package/lib/WasmCommand.js +14 -7
- package/lib/buildFilesystemStructure.js +9 -4
- package/lib/builtins/cat.js +4 -1
- package/lib/builtins/echo.js +2 -0
- package/lib/builtins/false.js +1 -1
- package/lib/builtins/grep.js +10 -2
- package/lib/builtins/ls.js +6 -2
- package/lib/builtins/test.js +2 -4
- package/lib/builtins/true.js +1 -1
- package/lib/local/alias.js +2 -0
- package/lib/local/cd.js +5 -3
- package/lib/local/chmod.js +2 -3
- package/lib/local/clear.js +2 -0
- package/lib/local/cp.js +13 -8
- package/lib/local/curl.js +138 -0
- package/lib/local/exit.js +2 -0
- package/lib/local/export.js +2 -0
- package/lib/local/index.js +2 -1
- package/lib/local/jsfunction.js +1 -1
- package/lib/local/mkdir.js +3 -3
- package/lib/local/mv.js +12 -6
- package/lib/local/pwd.js +2 -0
- package/lib/local/read.js +2 -0
- package/lib/local/rm.js +1 -1
- package/lib/local/source.js +5 -4
- package/lib/local/which.js +2 -0
- package/package.json +9 -4
- package/styles/terminal.css +8 -1
- package/test/builtins.test.js +11 -0
- package/test/exportFileSystem.test.js +28 -8
- package/test/local-commands.test.js +11 -0
- package/test/scripts.test.js +57 -0
- package/test/shell.test.js +42 -0
- package/vite.config.demo.js +35 -0
- package/vite.config.js +34 -0
package/lib/builtins/grep.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const Command = require('../Command');
|
|
4
4
|
|
|
5
5
|
class Grep extends Command {
|
|
6
|
+
static get name() { return 'grep'; }
|
|
7
|
+
|
|
6
8
|
get requiresFilesystem() { return true; }
|
|
7
9
|
|
|
8
10
|
run() {
|
|
@@ -89,7 +91,10 @@ class Grep extends Command {
|
|
|
89
91
|
} else {
|
|
90
92
|
const pf = this.fs.getFileByPath(patternFile);
|
|
91
93
|
if (pf === null || pf === undefined) {
|
|
92
|
-
if (!suppressErrors)
|
|
94
|
+
if (!suppressErrors) {
|
|
95
|
+
const msg = this.fs.exists(patternFile) ? 'Permission denied' : 'No such file or directory';
|
|
96
|
+
this.stdErr = `grep: ${patternFile}: ${msg}`;
|
|
97
|
+
}
|
|
93
98
|
this.exitCode = 2;
|
|
94
99
|
return Promise.resolve();
|
|
95
100
|
}
|
|
@@ -136,7 +141,10 @@ class Grep extends Command {
|
|
|
136
141
|
const collectFiles = (p, topLevel = false) => {
|
|
137
142
|
const entry = this.fs.getFileByPath(p);
|
|
138
143
|
if (entry === null || entry === undefined) {
|
|
139
|
-
if (!suppressErrors)
|
|
144
|
+
if (!suppressErrors) {
|
|
145
|
+
const msg = this.fs.exists(p) ? 'Permission denied' : 'No such file or directory';
|
|
146
|
+
this.stdErr = `grep: ${p}: ${msg}`;
|
|
147
|
+
}
|
|
140
148
|
hasError = true;
|
|
141
149
|
return;
|
|
142
150
|
}
|
package/lib/builtins/ls.js
CHANGED
|
@@ -4,6 +4,8 @@ const Command = require('../Command');
|
|
|
4
4
|
const commandLineArgs = require('command-line-args');
|
|
5
5
|
|
|
6
6
|
class Ls extends Command {
|
|
7
|
+
static get name() { return 'ls'; }
|
|
8
|
+
|
|
7
9
|
get requiresFilesystem() {
|
|
8
10
|
return true;
|
|
9
11
|
}
|
|
@@ -30,7 +32,8 @@ class Ls extends Command {
|
|
|
30
32
|
const file = this.fs.getFileByPath(options.path);
|
|
31
33
|
|
|
32
34
|
if(!file) {
|
|
33
|
-
|
|
35
|
+
const msg = this.fs.exists(options.path) ? 'Permission denied' : 'No such file or directory';
|
|
36
|
+
return Promise.reject(`${options.path}: ${msg}`);
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
if(file.constructor === Object) {
|
|
@@ -94,8 +97,9 @@ class Ls extends Command {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
printLong(items, basePath) {
|
|
100
|
+
const base = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
|
|
97
101
|
Object.entries(items).forEach(([name, content]) => {
|
|
98
|
-
const itemPath =
|
|
102
|
+
const itemPath = base + '/' + name;
|
|
99
103
|
const isDir = content !== null && content !== undefined && content.constructor === Object;
|
|
100
104
|
const rawMode = this.fs.getMode(itemPath);
|
|
101
105
|
const mode = rawMode !== null ? rawMode : (isDir ? 0o755 : 0o644);
|
package/lib/builtins/test.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const Command = require('../Command');
|
|
4
4
|
|
|
5
5
|
class Test extends Command {
|
|
6
|
-
get name() { return 'test'; }
|
|
6
|
+
static get name() { return 'test'; }
|
|
7
7
|
get requiresFilesystem() { return true; }
|
|
8
8
|
|
|
9
9
|
run() {
|
|
@@ -97,9 +97,7 @@ class Test extends Command {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
class TestBracket extends Test {
|
|
100
|
-
get name() { return '['; }
|
|
100
|
+
static get name() { return '['; }
|
|
101
101
|
}
|
|
102
|
-
// Override the class name so Context.setCommand stores it under '[' not 'testbracket'
|
|
103
|
-
Object.defineProperty(TestBracket, 'name', { value: '[' });
|
|
104
102
|
|
|
105
103
|
module.exports = { Test, TestBracket };
|
package/lib/builtins/true.js
CHANGED
package/lib/local/alias.js
CHANGED
package/lib/local/cd.js
CHANGED
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
const LocalCommand = require('./LocalCommand');
|
|
4
4
|
|
|
5
5
|
class CD extends LocalCommand {
|
|
6
|
+
static get name() { return 'cd'; }
|
|
7
|
+
|
|
6
8
|
run() {
|
|
7
9
|
if(this.arguments.length !== 1) {
|
|
8
10
|
return Promise.reject('cd requires a single argument');
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
const
|
|
13
|
+
const s = this.context.fs.stat(this.arguments[0]);
|
|
12
14
|
|
|
13
|
-
if(!
|
|
15
|
+
if(!s) {
|
|
14
16
|
return Promise.reject('file or directory not found');
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
if(
|
|
19
|
+
if(s.isDirectory) {
|
|
18
20
|
this.context.setCwd(this.arguments[0]);
|
|
19
21
|
return Promise.resolve();
|
|
20
22
|
}
|
package/lib/local/chmod.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const LocalCommand = require('./LocalCommand');
|
|
4
4
|
|
|
5
5
|
class Chmod extends LocalCommand {
|
|
6
|
-
get name() { return 'chmod'; }
|
|
6
|
+
static get name() { return 'chmod'; }
|
|
7
7
|
get requiresFilesystem() { return true; }
|
|
8
8
|
|
|
9
9
|
run() {
|
|
@@ -18,8 +18,7 @@ class Chmod extends LocalCommand {
|
|
|
18
18
|
const paths = args.slice(1);
|
|
19
19
|
|
|
20
20
|
for (const p of paths) {
|
|
21
|
-
|
|
22
|
-
if (file === null || file === undefined) {
|
|
21
|
+
if (!this.fs.exists(p)) {
|
|
23
22
|
this.stdErr = `chmod: cannot access '${p}': No such file or directory`;
|
|
24
23
|
this.exitCode = 1;
|
|
25
24
|
continue;
|
package/lib/local/clear.js
CHANGED
package/lib/local/cp.js
CHANGED
|
@@ -4,7 +4,7 @@ const LocalCommand = require('./LocalCommand');
|
|
|
4
4
|
const nodeFs = require('fs');
|
|
5
5
|
|
|
6
6
|
class Cp extends LocalCommand {
|
|
7
|
-
get name() { return 'cp'; }
|
|
7
|
+
static get name() { return 'cp'; }
|
|
8
8
|
get requiresFilesystem() { return true; }
|
|
9
9
|
|
|
10
10
|
run() {
|
|
@@ -55,8 +55,8 @@ class Cp extends LocalCommand {
|
|
|
55
55
|
|
|
56
56
|
const dest = paths[paths.length - 1];
|
|
57
57
|
const sources = paths.slice(0, -1);
|
|
58
|
-
const
|
|
59
|
-
const destIsDir =
|
|
58
|
+
const destStat = this.fs.stat(dest);
|
|
59
|
+
const destIsDir = destStat !== null && destStat.isDirectory;
|
|
60
60
|
|
|
61
61
|
// Determine per-item copy mode and the mode for recursive children.
|
|
62
62
|
// -H always takes effect for CL-level symlinks (follow), regardless of which mode wins.
|
|
@@ -71,8 +71,8 @@ class Cp extends LocalCommand {
|
|
|
71
71
|
const isLink = this.fs.isSymlink ? this.fs.isSymlink(src) : false;
|
|
72
72
|
|
|
73
73
|
// Stat (follows symlinks) to get effective type
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
74
|
+
const srcStat = this.fs.stat(src);
|
|
75
|
+
if (srcStat === null) {
|
|
76
76
|
this.stdErr = `cp: cannot stat '${src}': No such file or directory`;
|
|
77
77
|
this.exitCode = 1;
|
|
78
78
|
continue;
|
|
@@ -81,7 +81,7 @@ class Cp extends LocalCommand {
|
|
|
81
81
|
// If we're preserving this symlink, it won't become a directory
|
|
82
82
|
const effectiveIsDir = (isLink && clItemMode === 'preserve')
|
|
83
83
|
? false
|
|
84
|
-
:
|
|
84
|
+
: srcStat.isDirectory;
|
|
85
85
|
|
|
86
86
|
if (effectiveIsDir && !recursive) {
|
|
87
87
|
this.stdErr = `cp: omitting directory '${src}'`;
|
|
@@ -118,7 +118,8 @@ class Cp extends LocalCommand {
|
|
|
118
118
|
|
|
119
119
|
const content = this.fs.getFileByPath(src);
|
|
120
120
|
if (content === null || content === undefined) {
|
|
121
|
-
|
|
121
|
+
const msg = this.fs.exists(src) ? 'Permission denied' : 'No such file or directory';
|
|
122
|
+
return `cp: cannot stat '${src}': ${msg}`;
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
if (content.constructor === Object) {
|
|
@@ -147,7 +148,11 @@ class Cp extends LocalCommand {
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
} else {
|
|
150
|
-
|
|
151
|
+
try {
|
|
152
|
+
this.fs.setFileByPath(dest, content, true);
|
|
153
|
+
} catch(e) {
|
|
154
|
+
return `cp: cannot create '${dest}': ${e.message}`;
|
|
155
|
+
}
|
|
151
156
|
}
|
|
152
157
|
return null;
|
|
153
158
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LocalCommand = require('./LocalCommand');
|
|
4
|
+
|
|
5
|
+
class Curl extends LocalCommand {
|
|
6
|
+
static get name() { return 'curl'; }
|
|
7
|
+
get requiresFilesystem() { return true; }
|
|
8
|
+
|
|
9
|
+
run() {
|
|
10
|
+
const args = [...this.arguments];
|
|
11
|
+
let method = null;
|
|
12
|
+
const headers = {};
|
|
13
|
+
let body = null;
|
|
14
|
+
let includeHeaders = false;
|
|
15
|
+
let silent = false;
|
|
16
|
+
let outputFile = null;
|
|
17
|
+
let url = null;
|
|
18
|
+
|
|
19
|
+
let i = 0;
|
|
20
|
+
while (i < args.length) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
switch (arg) {
|
|
23
|
+
case '-X': case '--request':
|
|
24
|
+
method = args[++i];
|
|
25
|
+
break;
|
|
26
|
+
case '-H': case '--header': {
|
|
27
|
+
const raw = args[++i] || '';
|
|
28
|
+
const colon = raw.indexOf(':');
|
|
29
|
+
if (colon > 0) {
|
|
30
|
+
headers[raw.slice(0, colon).trim()] = raw.slice(colon + 1).trim();
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case '-d': case '--data': case '--data-raw':
|
|
35
|
+
body = args[++i];
|
|
36
|
+
if (!method) method = 'POST';
|
|
37
|
+
break;
|
|
38
|
+
case '-u': case '--user': {
|
|
39
|
+
const creds = args[++i] || '';
|
|
40
|
+
headers['Authorization'] = 'Basic ' + btoa(creds);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case '-o': case '--output':
|
|
44
|
+
outputFile = args[++i];
|
|
45
|
+
break;
|
|
46
|
+
case '-i': case '--include':
|
|
47
|
+
includeHeaders = true;
|
|
48
|
+
break;
|
|
49
|
+
case '-s': case '--silent':
|
|
50
|
+
silent = true;
|
|
51
|
+
break;
|
|
52
|
+
case '-L': case '--location':
|
|
53
|
+
// fetch follows redirects by default — accepted and ignored
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
if (!arg.startsWith('-')) {
|
|
57
|
+
url = arg;
|
|
58
|
+
} else if (!silent) {
|
|
59
|
+
this.stdErr = `curl: unknown option '${arg}'`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!url) {
|
|
66
|
+
this.stdErr = 'curl: no URL specified';
|
|
67
|
+
this.exitCode = 1;
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Validate URL scheme to prevent file:// or data: abuse
|
|
72
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
73
|
+
this.stdErr = `curl: unsupported protocol in URL: ${url}`;
|
|
74
|
+
this.exitCode = 1;
|
|
75
|
+
return Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const fetchOptions = {
|
|
79
|
+
method: method || 'GET',
|
|
80
|
+
headers,
|
|
81
|
+
};
|
|
82
|
+
if (body !== null) fetchOptions.body = body;
|
|
83
|
+
|
|
84
|
+
return fetch(url, fetchOptions)
|
|
85
|
+
.then(async (res) => {
|
|
86
|
+
if (includeHeaders) {
|
|
87
|
+
this.stdOut = `HTTP/1.1 ${res.status} ${res.statusText}`;
|
|
88
|
+
res.headers.forEach((value, name) => {
|
|
89
|
+
this.stdOut = `${name}: ${value}`;
|
|
90
|
+
});
|
|
91
|
+
this.stdOut = '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const text = await res.text();
|
|
95
|
+
|
|
96
|
+
if (outputFile) {
|
|
97
|
+
try {
|
|
98
|
+
this.fs.setFileByPath(outputFile, text, false);
|
|
99
|
+
} catch(e) {
|
|
100
|
+
this.stdErr = `curl: cannot write to '${outputFile}': ${e.message}`;
|
|
101
|
+
this.exitCode = 1;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
text.split(/\r?\n/).forEach(line => { this.stdOut = line; });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!res.ok) {
|
|
108
|
+
this.exitCode = 22;
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.catch((err) => {
|
|
112
|
+
if (!silent) {
|
|
113
|
+
const msg = (err && err.message) ? err.message : String(err);
|
|
114
|
+
// Browsers surface CORS and mixed-content failures as opaque TypeErrors
|
|
115
|
+
// with no status — the actual reason is intentionally hidden by the browser.
|
|
116
|
+
const likelyNetworkBlock =
|
|
117
|
+
err instanceof TypeError &&
|
|
118
|
+
/failed to fetch|networkerror|load failed|fetch is aborted/i.test(msg);
|
|
119
|
+
|
|
120
|
+
if (likelyNetworkBlock) {
|
|
121
|
+
const isHttps = /^https:\/\//i.test(url);
|
|
122
|
+
const pageSsl = typeof location !== 'undefined' && location.protocol === 'https:';
|
|
123
|
+
if (!isHttps && pageSsl) {
|
|
124
|
+
this.stdErr = `curl: (35) Mixed content blocked — the page is served over HTTPS but the target URL is HTTP. Browsers block insecure requests from secure pages.`;
|
|
125
|
+
} else {
|
|
126
|
+
this.stdErr = `curl: (6) Network request failed — this is likely a CORS error. The server at ${url} did not include the required 'Access-Control-Allow-Origin' response header. You can only fetch cross-origin resources that explicitly allow it.`;
|
|
127
|
+
this.stdErr = ` Hint: try a public CORS proxy, or ensure the server sends 'Access-Control-Allow-Origin: *'.`;
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
this.stdErr = `curl: (6) Could not connect: ${msg}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.exitCode = 6;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = Curl;
|
package/lib/local/exit.js
CHANGED
package/lib/local/export.js
CHANGED
package/lib/local/index.js
CHANGED
package/lib/local/jsfunction.js
CHANGED
|
@@ -4,7 +4,7 @@ const LocalCommand = require('./LocalCommand');
|
|
|
4
4
|
const Command = require('../Command');
|
|
5
5
|
|
|
6
6
|
class JsFunction extends LocalCommand {
|
|
7
|
-
get name() { return 'jsfunction'; }
|
|
7
|
+
static get name() { return 'jsfunction'; }
|
|
8
8
|
|
|
9
9
|
run() {
|
|
10
10
|
const [name, ...bodyParts] = this.arguments;
|
package/lib/local/mkdir.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const LocalCommand = require('./LocalCommand');
|
|
4
4
|
|
|
5
5
|
class Mkdir extends LocalCommand {
|
|
6
|
-
get name() { return 'mkdir'; }
|
|
6
|
+
static get name() { return 'mkdir'; }
|
|
7
7
|
get requiresFilesystem() { return true; }
|
|
8
8
|
|
|
9
9
|
run() {
|
|
@@ -22,8 +22,8 @@ class Mkdir extends LocalCommand {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
for (const dir of paths) {
|
|
25
|
-
const existing = this.fs.
|
|
26
|
-
if (existing
|
|
25
|
+
const existing = this.fs.exists(dir);
|
|
26
|
+
if (existing) {
|
|
27
27
|
if (!createParents) {
|
|
28
28
|
this.stdErr = `mkdir: cannot create directory '${dir}': File exists`;
|
|
29
29
|
this.exitCode = 1;
|
package/lib/local/mv.js
CHANGED
|
@@ -4,7 +4,7 @@ const LocalCommand = require('./LocalCommand');
|
|
|
4
4
|
const nodeFs = require('fs');
|
|
5
5
|
|
|
6
6
|
class Mv extends LocalCommand {
|
|
7
|
-
get name() { return 'mv'; }
|
|
7
|
+
static get name() { return 'mv'; }
|
|
8
8
|
get requiresFilesystem() { return true; }
|
|
9
9
|
|
|
10
10
|
run() {
|
|
@@ -44,8 +44,8 @@ class Mv extends LocalCommand {
|
|
|
44
44
|
return Promise.resolve();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
const destIsDir =
|
|
47
|
+
const destStat = this.fs.stat(dest);
|
|
48
|
+
const destIsDir = destStat !== null && destStat.isDirectory;
|
|
49
49
|
|
|
50
50
|
for (const src of sources) {
|
|
51
51
|
const targetPath = destIsDir
|
|
@@ -73,12 +73,18 @@ class Mv extends LocalCommand {
|
|
|
73
73
|
} else {
|
|
74
74
|
const srcEntry = this.fs.getFileByPath(src);
|
|
75
75
|
if (srcEntry === null || srcEntry === undefined) {
|
|
76
|
-
|
|
76
|
+
const msg = this.fs.exists(src) ? 'Permission denied' : 'No such file or directory';
|
|
77
|
+
this.stdErr = `mv: cannot stat '${src}': ${msg}`;
|
|
77
78
|
this.exitCode = 1;
|
|
78
79
|
continue;
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
try {
|
|
82
|
+
this.fs.setFileByPath(targetPath, this._deepCopy(srcEntry), true);
|
|
83
|
+
this.fs.deleteFileByPath(src);
|
|
84
|
+
} catch(e) {
|
|
85
|
+
this.stdErr = `mv: cannot move '${src}' to '${targetPath}': ${e.message}`;
|
|
86
|
+
this.exitCode = 1;
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
return Promise.resolve();
|
package/lib/local/pwd.js
CHANGED
package/lib/local/read.js
CHANGED
package/lib/local/rm.js
CHANGED
package/lib/local/source.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const ScriptCommand = require('../ScriptCommand');
|
|
4
4
|
const LocalCommand = require('./LocalCommand');
|
|
5
5
|
|
|
6
|
-
const Shell = require('../../index');
|
|
7
|
-
|
|
8
6
|
class Source extends LocalCommand {
|
|
7
|
+
static get name() { return 'source'; }
|
|
8
|
+
|
|
9
9
|
constructor(args, context) {
|
|
10
10
|
super(args, context);
|
|
11
11
|
if(this.arguments.length !== 1) {
|
|
@@ -30,14 +30,15 @@ class Source extends LocalCommand {
|
|
|
30
30
|
const handle = this.context.fs.getFileByPath(script);
|
|
31
31
|
|
|
32
32
|
if (!handle) {
|
|
33
|
-
|
|
33
|
+
const msg = this.context.fs.exists(script) ? 'Permission denied' : 'No such file or directory';
|
|
34
|
+
return Promise.reject(`${script}: ${msg}`);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
if (handle.constructor === Object) {
|
|
37
38
|
return Promise.reject(`${script}: is a directory`);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
if (handle.prototype && handle.prototype
|
|
41
|
+
if (handle.prototype && typeof handle.prototype.run === 'function' && typeof handle.prototype.runCommand === 'function') {
|
|
41
42
|
return Promise.reject(`${script}: command not found`);
|
|
42
43
|
}
|
|
43
44
|
|
package/lib/local/which.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brsh",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "A unix like shell written in javascript",
|
|
5
5
|
"main": "./dist/shell.min.js",
|
|
6
6
|
"module": "./dist/shell.es.js",
|
|
@@ -17,13 +17,17 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"bin": {
|
|
20
|
-
"exportFileSystem": "bin/exportFileSystem.js"
|
|
20
|
+
"exportFileSystem": "bin/exportFileSystem.js",
|
|
21
|
+
"brsh": "bin/brsh-shell.js"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
|
-
"start": "vite demo/",
|
|
24
|
+
"start": "node bin/exportFileSystem.js ./demo/filesystem -o ./demo/fs.js -v fs && vite --config vite.config.js demo/",
|
|
25
|
+
"build:demofs": "node bin/exportFileSystem.js ./demo/filesystem -o ./dist-demo/fs.js -v fs",
|
|
26
|
+
"build:demo": "vite build --config vite.config.demo.js && npm run build:demofs",
|
|
24
27
|
"build": "npm run build:shell && npm run build:terminal",
|
|
25
28
|
"build:shell": "vite build --config vite.config.shell.js",
|
|
26
29
|
"build:terminal": "vite build --config vite.config.terminal.js",
|
|
30
|
+
"shell": "node bin/brsh-shell.js",
|
|
27
31
|
"test": "vitest run",
|
|
28
32
|
"test:watch": "vitest",
|
|
29
33
|
"prepublishOnly": "npm run build"
|
|
@@ -35,10 +39,10 @@
|
|
|
35
39
|
"author": "Eliot Stocker",
|
|
36
40
|
"license": "GPL-3.0",
|
|
37
41
|
"devDependencies": {
|
|
42
|
+
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
38
43
|
"@semantic-release/changelog": "^6.0.3",
|
|
39
44
|
"@semantic-release/git": "^10.0.1",
|
|
40
45
|
"@vitest/coverage-v8": "^4.1.5",
|
|
41
|
-
"esbuild": "^0.25.9",
|
|
42
46
|
"semantic-release": "^25.0.3",
|
|
43
47
|
"vite": "^8.0.10",
|
|
44
48
|
"vite-plugin-node-polyfills": "^0.26.0",
|
|
@@ -46,6 +50,7 @@
|
|
|
46
50
|
},
|
|
47
51
|
"dependencies": {
|
|
48
52
|
"ansi_up": "git+https://github.com/eliotstocker/ansi_up.git",
|
|
53
|
+
"ansi-colors": "^4.1.3",
|
|
49
54
|
"command-line-args": "^6.0.1",
|
|
50
55
|
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
51
56
|
"string.prototype.matchall": "^4.0.12",
|
package/styles/terminal.css
CHANGED
|
@@ -7,11 +7,18 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.terminal__line {
|
|
10
|
-
white-space: pre
|
|
10
|
+
white-space: pre;
|
|
11
|
+
overflow: hidden;
|
|
11
12
|
min-height: 1.15em;
|
|
12
13
|
line-height: 1.15em;
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
.terminal--wrap .terminal__line,
|
|
17
|
+
.terminal--wrap li {
|
|
18
|
+
white-space: pre-wrap;
|
|
19
|
+
overflow: visible;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
@keyframes blink {
|
|
16
23
|
from, to {
|
|
17
24
|
opacity: 0;
|
package/test/builtins.test.js
CHANGED
|
@@ -136,6 +136,17 @@ describe('cat', () => {
|
|
|
136
136
|
expect(errors.length).toBeGreaterThan(0);
|
|
137
137
|
expect(exitCode).toBeGreaterThan(0);
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
it('errors when reading a file without read permission', async () => {
|
|
141
|
+
const shell = await createShell({
|
|
142
|
+
filesystem: { home: { 'secret.txt': 'private' } },
|
|
143
|
+
permissions: { '/home/secret.txt': 0o000 }
|
|
144
|
+
});
|
|
145
|
+
const { errors, exitCode } = await run(shell, 'cat /home/secret.txt');
|
|
146
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
147
|
+
expect(errors.join(' ')).toMatch(/permission denied/i);
|
|
148
|
+
expect(exitCode).toBeGreaterThan(0);
|
|
149
|
+
});
|
|
139
150
|
});
|
|
140
151
|
|
|
141
152
|
describe('true / false', () => {
|