typescript-virtual-container 1.2.8 → 1.3.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/.vscode/settings.json +0 -1
- package/README.md +462 -44
- package/biome.json +7 -0
- package/dist/SSHMimic/exec.d.ts.map +1 -1
- package/dist/SSHMimic/executor.d.ts.map +1 -1
- package/dist/SSHMimic/executor.js +35 -21
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +20 -6
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
- package/dist/VirtualFileSystem/binaryPack.js +29 -6
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +36 -13
- package/dist/VirtualPackageManager/index.d.ts +202 -0
- package/dist/VirtualPackageManager/index.d.ts.map +1 -0
- package/dist/VirtualPackageManager/index.js +825 -0
- package/dist/VirtualShell/index.d.ts +93 -12
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +95 -13
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +3 -1
- package/dist/VirtualShell/shellParser.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.d.ts +52 -20
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.js +54 -20
- package/dist/commands/adduser.d.ts +6 -0
- package/dist/commands/adduser.d.ts.map +1 -1
- package/dist/commands/adduser.js +6 -0
- package/dist/commands/alias.d.ts +9 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +63 -0
- package/dist/commands/apt.d.ts +9 -0
- package/dist/commands/apt.d.ts.map +1 -0
- package/dist/commands/apt.js +205 -0
- package/dist/commands/awk.d.ts +11 -0
- package/dist/commands/awk.d.ts.map +1 -1
- package/dist/commands/awk.js +15 -2
- package/dist/commands/base64.d.ts +5 -0
- package/dist/commands/base64.d.ts.map +1 -1
- package/dist/commands/base64.js +9 -1
- package/dist/commands/cat.d.ts +5 -0
- package/dist/commands/cat.d.ts.map +1 -1
- package/dist/commands/cat.js +35 -8
- package/dist/commands/cd.d.ts +5 -0
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +5 -0
- package/dist/commands/chmod.d.ts +5 -0
- package/dist/commands/chmod.d.ts.map +1 -1
- package/dist/commands/chmod.js +57 -3
- package/dist/commands/command-helpers.d.ts +78 -4
- package/dist/commands/command-helpers.d.ts.map +1 -1
- package/dist/commands/command-helpers.js +78 -4
- package/dist/commands/cp.d.ts +5 -0
- package/dist/commands/cp.d.ts.map +1 -1
- package/dist/commands/cp.js +5 -0
- package/dist/commands/curl.d.ts +5 -0
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +106 -26
- package/dist/commands/cut.d.ts +5 -0
- package/dist/commands/cut.d.ts.map +1 -1
- package/dist/commands/cut.js +8 -1
- package/dist/commands/date.d.ts +5 -0
- package/dist/commands/date.d.ts.map +1 -1
- package/dist/commands/date.js +7 -1
- package/dist/commands/declare.d.ts +3 -0
- package/dist/commands/declare.d.ts.map +1 -0
- package/dist/commands/declare.js +39 -0
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +5 -0
- package/dist/commands/dpkg.d.ts +9 -0
- package/dist/commands/dpkg.d.ts.map +1 -0
- package/dist/commands/dpkg.js +161 -0
- package/dist/commands/du.d.ts.map +1 -1
- package/dist/commands/du.js +8 -2
- package/dist/commands/echo.d.ts +5 -0
- package/dist/commands/echo.d.ts.map +1 -1
- package/dist/commands/echo.js +33 -12
- package/dist/commands/env.d.ts +5 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +11 -1
- package/dist/commands/exit.d.ts +5 -0
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +12 -2
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +3 -1
- package/dist/commands/find.d.ts +5 -0
- package/dist/commands/find.d.ts.map +1 -1
- package/dist/commands/find.js +5 -0
- package/dist/commands/free.d.ts +8 -0
- package/dist/commands/free.d.ts.map +1 -0
- package/dist/commands/free.js +43 -0
- package/dist/commands/grep.d.ts +5 -0
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +12 -2
- package/dist/commands/gzip.d.ts +5 -0
- package/dist/commands/gzip.d.ts.map +1 -1
- package/dist/commands/gzip.js +18 -2
- package/dist/commands/head.d.ts +5 -0
- package/dist/commands/head.d.ts.map +1 -1
- package/dist/commands/head.js +5 -0
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +98 -45
- package/dist/commands/helpers.d.ts +3 -0
- package/dist/commands/helpers.d.ts.map +1 -1
- package/dist/commands/helpers.js +3 -0
- package/dist/commands/history.d.ts +8 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +26 -0
- package/dist/commands/hostname.d.ts +5 -0
- package/dist/commands/hostname.d.ts.map +1 -1
- package/dist/commands/hostname.js +5 -0
- package/dist/commands/id.d.ts.map +1 -1
- package/dist/commands/id.js +4 -1
- package/dist/commands/index.d.ts +2 -10
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -231
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +6 -3
- package/dist/commands/lsb-release.d.ts +3 -0
- package/dist/commands/lsb-release.d.ts.map +1 -0
- package/dist/commands/lsb-release.js +56 -0
- package/dist/commands/man.d.ts +3 -0
- package/dist/commands/man.d.ts.map +1 -0
- package/dist/commands/man.js +155 -0
- package/dist/commands/nano.js +1 -1
- package/dist/commands/neofetch.d.ts.map +1 -1
- package/dist/commands/neofetch.js +6 -1
- package/dist/commands/node.d.ts +9 -0
- package/dist/commands/node.d.ts.map +1 -0
- package/dist/commands/node.js +316 -0
- package/dist/commands/npm.d.ts +19 -0
- package/dist/commands/npm.d.ts.map +1 -0
- package/dist/commands/npm.js +109 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +7 -2
- package/dist/commands/printf.d.ts +3 -0
- package/dist/commands/printf.d.ts.map +1 -0
- package/dist/commands/printf.js +113 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +30 -6
- package/dist/commands/python.d.ts +30 -0
- package/dist/commands/python.d.ts.map +1 -0
- package/dist/commands/python.js +2058 -0
- package/dist/commands/read.d.ts +3 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +34 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +229 -0
- package/dist/commands/runtime.d.ts +6 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +280 -0
- package/dist/commands/sed.d.ts.map +1 -1
- package/dist/commands/sed.js +11 -3
- package/dist/commands/set.d.ts.map +1 -1
- package/dist/commands/set.js +9 -3
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +69 -30
- package/dist/commands/shift.d.ts +5 -0
- package/dist/commands/shift.d.ts.map +1 -0
- package/dist/commands/shift.js +52 -0
- package/dist/commands/sleep.d.ts.map +1 -1
- package/dist/commands/sort.d.ts.map +1 -1
- package/dist/commands/sort.js +4 -2
- package/dist/commands/source.d.ts +3 -0
- package/dist/commands/source.d.ts.map +1 -0
- package/dist/commands/source.js +34 -0
- package/dist/commands/sudo.js +1 -1
- package/dist/commands/tar.d.ts.map +1 -1
- package/dist/commands/tar.js +11 -3
- package/dist/commands/tee.d.ts.map +1 -1
- package/dist/commands/tee.js +8 -6
- package/dist/commands/test.d.ts +3 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +114 -0
- package/dist/commands/tr.d.ts.map +1 -1
- package/dist/commands/tr.js +3 -1
- package/dist/commands/true.d.ts +4 -0
- package/dist/commands/true.d.ts.map +1 -0
- package/dist/commands/true.js +14 -0
- package/dist/commands/type.d.ts +3 -0
- package/dist/commands/type.d.ts.map +1 -0
- package/dist/commands/type.js +34 -0
- package/dist/commands/uname.d.ts.map +1 -1
- package/dist/commands/uname.js +4 -1
- package/dist/commands/uniq.d.ts.map +1 -1
- package/dist/commands/uptime.d.ts +3 -0
- package/dist/commands/uptime.d.ts.map +1 -0
- package/dist/commands/uptime.js +43 -0
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +92 -96
- package/dist/commands/which.d.ts +3 -0
- package/dist/commands/which.d.ts.map +1 -0
- package/dist/commands/which.js +32 -0
- package/dist/commands/xargs.d.ts.map +1 -1
- package/dist/commands/xargs.js +1 -1
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/modules/linuxRootfs.d.ts +41 -0
- package/dist/modules/linuxRootfs.d.ts.map +1 -0
- package/dist/modules/linuxRootfs.js +440 -0
- package/dist/modules/neofetch.d.ts.map +1 -1
- package/dist/modules/neofetch.js +1 -0
- package/dist/standalone-wo-sftp.d.ts +2 -0
- package/dist/standalone-wo-sftp.d.ts.map +1 -0
- package/dist/standalone-wo-sftp.js +30 -0
- package/dist/utils/expand.d.ts +50 -0
- package/dist/utils/expand.d.ts.map +1 -0
- package/dist/utils/expand.js +183 -0
- package/dist/utils/vfsDiff.d.ts +90 -0
- package/dist/utils/vfsDiff.d.ts.map +1 -0
- package/dist/utils/vfsDiff.js +177 -0
- package/package.json +3 -1
- package/src/SSHMimic/exec.ts +10 -1
- package/src/SSHMimic/executor.ts +105 -21
- package/src/SSHMimic/index.ts +49 -15
- package/src/VirtualFileSystem/binaryPack.ts +35 -8
- package/src/VirtualFileSystem/index.ts +78 -28
- package/src/VirtualPackageManager/index.ts +979 -0
- package/src/VirtualShell/index.ts +133 -14
- package/src/VirtualShell/shell.ts +23 -3
- package/src/VirtualShell/shellParser.ts +134 -36
- package/src/VirtualUserManager/index.ts +62 -22
- package/src/commands/adduser.ts +6 -0
- package/src/commands/alias.ts +64 -0
- package/src/commands/apt.ts +228 -0
- package/src/commands/awk.ts +20 -6
- package/src/commands/base64.ts +13 -2
- package/src/commands/cat.ts +40 -8
- package/src/commands/cd.ts +5 -0
- package/src/commands/chmod.ts +53 -3
- package/src/commands/command-helpers.ts +78 -4
- package/src/commands/cp.ts +5 -0
- package/src/commands/curl.ts +118 -33
- package/src/commands/cut.ts +8 -1
- package/src/commands/date.ts +7 -1
- package/src/commands/declare.ts +44 -0
- package/src/commands/diff.ts +17 -3
- package/src/commands/dpkg.ts +180 -0
- package/src/commands/du.ts +17 -5
- package/src/commands/echo.ts +41 -12
- package/src/commands/env.ts +11 -1
- package/src/commands/exit.ts +12 -2
- package/src/commands/export.ts +3 -1
- package/src/commands/find.ts +5 -0
- package/src/commands/free.ts +47 -0
- package/src/commands/grep.ts +12 -2
- package/src/commands/gzip.ts +28 -4
- package/src/commands/head.ts +5 -0
- package/src/commands/help.ts +121 -47
- package/src/commands/helpers.ts +8 -0
- package/src/commands/history.ts +34 -0
- package/src/commands/hostname.ts +5 -0
- package/src/commands/id.ts +4 -1
- package/src/commands/index.ts +9 -255
- package/src/commands/ls.ts +6 -3
- package/src/commands/lsb-release.ts +58 -0
- package/src/commands/man.ts +166 -0
- package/src/commands/nano.ts +1 -1
- package/src/commands/neofetch.ts +6 -1
- package/src/commands/node.ts +341 -0
- package/src/commands/npm.ts +132 -0
- package/src/commands/ping.ts +10 -3
- package/src/commands/printf.ts +112 -0
- package/src/commands/ps.ts +40 -6
- package/src/commands/python.ts +2229 -0
- package/src/commands/read.ts +41 -0
- package/src/commands/registry.ts +244 -0
- package/src/commands/runtime.ts +353 -0
- package/src/commands/sed.ts +27 -9
- package/src/commands/set.ts +9 -3
- package/src/commands/sh.ts +170 -44
- package/src/commands/shift.ts +53 -0
- package/src/commands/sleep.ts +2 -1
- package/src/commands/sort.ts +10 -6
- package/src/commands/source.ts +47 -0
- package/src/commands/sudo.ts +1 -1
- package/src/commands/tar.ts +28 -7
- package/src/commands/tee.ts +7 -1
- package/src/commands/test.ts +135 -0
- package/src/commands/tr.ts +3 -1
- package/src/commands/true.ts +17 -0
- package/src/commands/type.ts +43 -0
- package/src/commands/uname.ts +5 -1
- package/src/commands/uniq.ts +8 -2
- package/src/commands/uptime.ts +49 -0
- package/src/commands/wget.ts +105 -119
- package/src/commands/which.ts +37 -0
- package/src/commands/xargs.ts +11 -2
- package/src/index.ts +27 -18
- package/src/modules/linuxRootfs.ts +642 -0
- package/src/modules/neofetch.ts +1 -0
- package/src/standalone-wo-sftp.ts +38 -0
- package/src/utils/expand.ts +238 -0
- package/src/utils/vfsDiff.ts +275 -0
- package/standalone-wo-sftp.js +507 -0
- package/standalone-wo-sftp.js.map +7 -0
- package/standalone.js +486 -109
- package/standalone.js.map +4 -4
- package/tests/bun-test-shim.ts +9 -1
- package/tests/command-helpers.test.ts +1 -5
- package/tests/new-features.test.ts +1036 -0
- package/tests/parser-executor.test.ts +27 -27
- package/tests/sftp.test.ts +122 -42
- package/tests/users.test.ts +23 -5
- package/CHANGELOG.md +0 -150
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const MAN_PAGES = {
|
|
2
|
+
ls: `LS(1) User Commands LS(1)
|
|
3
|
+
|
|
4
|
+
NAME
|
|
5
|
+
ls - list directory contents
|
|
6
|
+
|
|
7
|
+
SYNOPSIS
|
|
8
|
+
ls [OPTION]... [FILE]...
|
|
9
|
+
|
|
10
|
+
DESCRIPTION
|
|
11
|
+
List information about the FILEs (the current directory by default).
|
|
12
|
+
|
|
13
|
+
OPTIONS
|
|
14
|
+
-l use a long listing format
|
|
15
|
+
-a do not ignore entries starting with .
|
|
16
|
+
-h with -l, print human readable sizes
|
|
17
|
+
-r reverse order while sorting
|
|
18
|
+
-t sort by modification time
|
|
19
|
+
|
|
20
|
+
AUTHOR
|
|
21
|
+
Written by Richard M. Stallman and David MacKenzie.`,
|
|
22
|
+
cat: `CAT(1) User Commands CAT(1)
|
|
23
|
+
|
|
24
|
+
NAME
|
|
25
|
+
cat - concatenate files and print on the standard output
|
|
26
|
+
|
|
27
|
+
SYNOPSIS
|
|
28
|
+
cat [OPTION]... [FILE]...
|
|
29
|
+
|
|
30
|
+
DESCRIPTION
|
|
31
|
+
Concatenate FILE(s) to standard output.
|
|
32
|
+
|
|
33
|
+
OPTIONS
|
|
34
|
+
-n, --number number all output lines
|
|
35
|
+
-b, --number-nonblank number nonempty output lines`,
|
|
36
|
+
grep: `GREP(1) User Commands GREP(1)
|
|
37
|
+
|
|
38
|
+
NAME
|
|
39
|
+
grep, egrep, fgrep - print lines that match patterns
|
|
40
|
+
|
|
41
|
+
SYNOPSIS
|
|
42
|
+
grep [OPTION]... PATTERNS [FILE]...
|
|
43
|
+
|
|
44
|
+
OPTIONS
|
|
45
|
+
-i, --ignore-case ignore case distinctions in patterns and data
|
|
46
|
+
-v, --invert-match select non-matching lines
|
|
47
|
+
-n, --line-number print line number with output lines
|
|
48
|
+
-r, --recursive read all files under each directory, recursively`,
|
|
49
|
+
apt: `APT(8) APT APT(8)
|
|
50
|
+
|
|
51
|
+
NAME
|
|
52
|
+
apt - command-line interface
|
|
53
|
+
|
|
54
|
+
SYNOPSIS
|
|
55
|
+
apt [options] command
|
|
56
|
+
|
|
57
|
+
DESCRIPTION
|
|
58
|
+
apt provides a high-level commandline interface for the package
|
|
59
|
+
management system.
|
|
60
|
+
|
|
61
|
+
COMMANDS
|
|
62
|
+
install pkg... Install packages
|
|
63
|
+
remove pkg... Remove packages
|
|
64
|
+
update Download package information
|
|
65
|
+
upgrade Upgrade installed packages
|
|
66
|
+
search term Search in package descriptions
|
|
67
|
+
show pkg Show package information
|
|
68
|
+
list List packages`,
|
|
69
|
+
ssh: `SSH(1) OpenSSH SSH(1)
|
|
70
|
+
|
|
71
|
+
NAME
|
|
72
|
+
ssh - OpenSSH remote login client
|
|
73
|
+
|
|
74
|
+
SYNOPSIS
|
|
75
|
+
ssh [-p port] [user@]hostname [command]
|
|
76
|
+
|
|
77
|
+
DESCRIPTION
|
|
78
|
+
ssh (SSH client) is a program for logging into a remote machine and
|
|
79
|
+
for executing commands on a remote machine.`,
|
|
80
|
+
curl: `CURL(1) User Commands CURL(1)
|
|
81
|
+
|
|
82
|
+
NAME
|
|
83
|
+
curl - transfer a URL
|
|
84
|
+
|
|
85
|
+
SYNOPSIS
|
|
86
|
+
curl [options / URLs]
|
|
87
|
+
|
|
88
|
+
DESCRIPTION
|
|
89
|
+
curl is a tool for transferring data with URL syntax.
|
|
90
|
+
|
|
91
|
+
OPTIONS
|
|
92
|
+
-o, --output <file> Write output to <file>
|
|
93
|
+
-X, --request <method> Specify request method
|
|
94
|
+
-d, --data <data> HTTP POST data
|
|
95
|
+
-H, --header <header> Pass custom header
|
|
96
|
+
-s, --silent Silent mode
|
|
97
|
+
-I, --head Show document info only
|
|
98
|
+
-L, --location Follow redirects
|
|
99
|
+
-v, --verbose Make the operation more talkative`,
|
|
100
|
+
chmod: `CHMOD(1) User Commands CHMOD(1)
|
|
101
|
+
|
|
102
|
+
NAME
|
|
103
|
+
chmod - change file mode bits
|
|
104
|
+
|
|
105
|
+
SYNOPSIS
|
|
106
|
+
chmod [OPTION]... MODE[,MODE]... FILE...
|
|
107
|
+
chmod [OPTION]... OCTAL-MODE FILE...
|
|
108
|
+
|
|
109
|
+
DESCRIPTION
|
|
110
|
+
Change the file mode bits of each given file according to MODE.
|
|
111
|
+
|
|
112
|
+
EXAMPLES
|
|
113
|
+
chmod 755 script.sh rwxr-xr-x
|
|
114
|
+
chmod 644 file.txt rw-r--r--
|
|
115
|
+
chmod +x script.sh add execute permission`,
|
|
116
|
+
tar: `TAR(1) GNU tar Manual TAR(1)
|
|
117
|
+
|
|
118
|
+
NAME
|
|
119
|
+
tar - an archiving utility
|
|
120
|
+
|
|
121
|
+
SYNOPSIS
|
|
122
|
+
tar [OPTION...] [FILE]...
|
|
123
|
+
|
|
124
|
+
DESCRIPTION
|
|
125
|
+
tar saves many files together into a single tape or disk archive,
|
|
126
|
+
and can restore individual files from the archive.
|
|
127
|
+
|
|
128
|
+
OPTIONS
|
|
129
|
+
-c, --create create a new archive
|
|
130
|
+
-x, --extract extract files from an archive
|
|
131
|
+
-z, --gzip filter the archive through gzip
|
|
132
|
+
-f, --file=ARCHIVE use archive file or device ARCHIVE
|
|
133
|
+
-v, --verbose verbosely list files processed
|
|
134
|
+
-t, --list list the contents of an archive`,
|
|
135
|
+
};
|
|
136
|
+
export const manCommand = {
|
|
137
|
+
name: "man",
|
|
138
|
+
description: "Interface to the system reference manuals",
|
|
139
|
+
category: "shell",
|
|
140
|
+
params: ["<command>"],
|
|
141
|
+
run: ({ args, shell }) => {
|
|
142
|
+
const name = args[0];
|
|
143
|
+
if (!name)
|
|
144
|
+
return { stderr: "What manual page do you want?", exitCode: 1 };
|
|
145
|
+
// VFS-installed man pages take priority
|
|
146
|
+
const manPath = `/usr/share/man/man1/${name}.1`;
|
|
147
|
+
if (shell.vfs.exists(manPath)) {
|
|
148
|
+
return { stdout: shell.vfs.readFile(manPath), exitCode: 0 };
|
|
149
|
+
}
|
|
150
|
+
const page = MAN_PAGES[name.toLowerCase()];
|
|
151
|
+
if (page)
|
|
152
|
+
return { stdout: page, exitCode: 0 };
|
|
153
|
+
return { stderr: `No manual entry for ${name}`, exitCode: 16 };
|
|
154
|
+
},
|
|
155
|
+
};
|
package/dist/commands/nano.js
CHANGED
|
@@ -3,7 +3,7 @@ import { assertPathAccess, resolvePath } from "./helpers";
|
|
|
3
3
|
export const nanoCommand = {
|
|
4
4
|
name: "nano",
|
|
5
5
|
description: "Text editor",
|
|
6
|
-
category: "
|
|
6
|
+
category: "files",
|
|
7
7
|
params: ["<file>"],
|
|
8
8
|
run: ({ authUser, shell, cwd, args }) => {
|
|
9
9
|
const fileArg = args[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"neofetch.d.ts","sourceRoot":"","sources":["../../src/commands/neofetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"neofetch.d.ts","sourceRoot":"","sources":["../../src/commands/neofetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,eAAe,EAAE,WAsC7B,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { getAllEnvVars } from "./set";
|
|
|
4
4
|
export const neofetchCommand = {
|
|
5
5
|
name: "neofetch",
|
|
6
6
|
description: "System info display",
|
|
7
|
-
category: "
|
|
7
|
+
category: "system",
|
|
8
8
|
params: ["[--off]"],
|
|
9
9
|
run: ({ args, authUser, hostname, shell }) => {
|
|
10
10
|
const env = getAllEnvVars(authUser);
|
|
@@ -27,6 +27,11 @@ export const neofetchCommand = {
|
|
|
27
27
|
shell: env.SHELL,
|
|
28
28
|
shellProps: shell.properties,
|
|
29
29
|
terminal: env.TERM,
|
|
30
|
+
uptimeSeconds: Math.floor((Date.now() - shell.startTime) / 1000),
|
|
31
|
+
packages: (() => {
|
|
32
|
+
const count = shell.packageManager?.installedCount() ?? 0;
|
|
33
|
+
return `${count} (dpkg)`;
|
|
34
|
+
})(),
|
|
30
35
|
}),
|
|
31
36
|
exitCode: 0,
|
|
32
37
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShellModule } from "../types/commands";
|
|
2
|
+
/**
|
|
3
|
+
* `node` virtual runtime command. Executes JS in a safe sandbox with
|
|
4
|
+
* limited globals and no host FS/child process access.
|
|
5
|
+
* @category system
|
|
6
|
+
* @params []
|
|
7
|
+
*/
|
|
8
|
+
export declare const nodeCommand: ShellModule;
|
|
9
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/commands/node.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmPrD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,WAkFzB,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/useNamingConvention: node globals and ENV VAR KEYS */
|
|
2
|
+
/**
|
|
3
|
+
* node.ts — Virtual Node.js runtime.
|
|
4
|
+
*
|
|
5
|
+
* Uses `node:vm` for sandboxed evaluation with a controlled context that
|
|
6
|
+
* intercepts `process`, `require`, `console`, and all standard globals.
|
|
7
|
+
* No host filesystem access, no network, no child processes.
|
|
8
|
+
*/
|
|
9
|
+
import vm from "node:vm";
|
|
10
|
+
import { ifFlag } from "./command-helpers";
|
|
11
|
+
import { resolvePath } from "./helpers";
|
|
12
|
+
const VIRTUAL_VERSION = "v18.19.0";
|
|
13
|
+
const VIRTUAL_VERSIONS = {
|
|
14
|
+
node: VIRTUAL_VERSION,
|
|
15
|
+
npm: "9.2.0",
|
|
16
|
+
v8: "10.2.154.26-node.22",
|
|
17
|
+
};
|
|
18
|
+
// ─── sandbox context ──────────────────────────────────────────────────────────
|
|
19
|
+
function makeContext(outputLines, stderrLines) {
|
|
20
|
+
const fakeProcess = {
|
|
21
|
+
version: VIRTUAL_VERSION,
|
|
22
|
+
versions: VIRTUAL_VERSIONS,
|
|
23
|
+
platform: "linux",
|
|
24
|
+
arch: "x64",
|
|
25
|
+
env: {
|
|
26
|
+
NODE_ENV: "production",
|
|
27
|
+
HOME: "/root",
|
|
28
|
+
PATH: "/usr/local/bin:/usr/bin:/bin",
|
|
29
|
+
},
|
|
30
|
+
argv: ["node"],
|
|
31
|
+
stdout: {
|
|
32
|
+
write: (s) => {
|
|
33
|
+
outputLines.push(s);
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
stderr: {
|
|
38
|
+
write: (s) => {
|
|
39
|
+
stderrLines.push(s);
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
exit: (code = 0) => {
|
|
44
|
+
throw new ExitSignal(code);
|
|
45
|
+
},
|
|
46
|
+
cwd: () => "/root",
|
|
47
|
+
hrtime: () => [0, 0],
|
|
48
|
+
};
|
|
49
|
+
const fakeConsole = {
|
|
50
|
+
log: (...a) => outputLines.push(a.map(formatValue).join(" ")),
|
|
51
|
+
error: (...a) => stderrLines.push(a.map(formatValue).join(" ")),
|
|
52
|
+
warn: (...a) => stderrLines.push(a.map(formatValue).join(" ")),
|
|
53
|
+
info: (...a) => outputLines.push(a.map(formatValue).join(" ")),
|
|
54
|
+
dir: (v) => outputLines.push(formatValue(v)),
|
|
55
|
+
};
|
|
56
|
+
const fakeRequire = (mod) => {
|
|
57
|
+
// Provide stubs for common modules
|
|
58
|
+
switch (mod) {
|
|
59
|
+
case "path":
|
|
60
|
+
return {
|
|
61
|
+
join: (...parts) => parts.join("/").replace(/\/+/g, "/"),
|
|
62
|
+
resolve: (...parts) => `/${parts.join("/").replace(/^\/+/, "")}`,
|
|
63
|
+
dirname: (p) => p.split("/").slice(0, -1).join("/") || "/",
|
|
64
|
+
basename: (p) => p.split("/").pop() ?? "",
|
|
65
|
+
extname: (p) => {
|
|
66
|
+
const b = p.split("/").pop() ?? "";
|
|
67
|
+
const d = b.lastIndexOf(".");
|
|
68
|
+
return d > 0 ? b.slice(d) : "";
|
|
69
|
+
},
|
|
70
|
+
sep: "/",
|
|
71
|
+
delimiter: ":",
|
|
72
|
+
};
|
|
73
|
+
case "os":
|
|
74
|
+
return {
|
|
75
|
+
platform: () => "linux",
|
|
76
|
+
arch: () => "x64",
|
|
77
|
+
type: () => "Linux",
|
|
78
|
+
hostname: () => "fortune-vm",
|
|
79
|
+
homedir: () => "/root",
|
|
80
|
+
tmpdir: () => "/tmp",
|
|
81
|
+
EOL: "\n",
|
|
82
|
+
};
|
|
83
|
+
case "util":
|
|
84
|
+
return {
|
|
85
|
+
format: (...a) => a.map(formatValue).join(" "),
|
|
86
|
+
inspect: (v) => formatValue(v),
|
|
87
|
+
};
|
|
88
|
+
case "fs":
|
|
89
|
+
case "fs/promises":
|
|
90
|
+
throw new Error(`Cannot require '${mod}': filesystem access not available in virtual runtime`);
|
|
91
|
+
case "child_process":
|
|
92
|
+
case "net":
|
|
93
|
+
case "http":
|
|
94
|
+
case "https":
|
|
95
|
+
throw new Error(`Cannot require '${mod}': not available in virtual runtime`);
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Cannot find module '${mod}'`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
fakeRequire.resolve = (id) => {
|
|
101
|
+
throw new Error(`Cannot resolve '${id}'`);
|
|
102
|
+
};
|
|
103
|
+
fakeRequire.cache = {};
|
|
104
|
+
fakeRequire.extensions = {};
|
|
105
|
+
return vm.createContext({
|
|
106
|
+
// Core globals
|
|
107
|
+
console: fakeConsole,
|
|
108
|
+
process: fakeProcess,
|
|
109
|
+
require: fakeRequire,
|
|
110
|
+
// JS built-ins
|
|
111
|
+
Math,
|
|
112
|
+
JSON,
|
|
113
|
+
Object,
|
|
114
|
+
Array,
|
|
115
|
+
String,
|
|
116
|
+
Number,
|
|
117
|
+
Boolean,
|
|
118
|
+
Symbol,
|
|
119
|
+
Date,
|
|
120
|
+
RegExp,
|
|
121
|
+
Error,
|
|
122
|
+
TypeError,
|
|
123
|
+
RangeError,
|
|
124
|
+
SyntaxError,
|
|
125
|
+
Promise,
|
|
126
|
+
Map,
|
|
127
|
+
Set,
|
|
128
|
+
WeakMap,
|
|
129
|
+
WeakSet,
|
|
130
|
+
parseInt,
|
|
131
|
+
parseFloat,
|
|
132
|
+
isNaN,
|
|
133
|
+
isFinite,
|
|
134
|
+
encodeURIComponent,
|
|
135
|
+
decodeURIComponent,
|
|
136
|
+
encodeURI,
|
|
137
|
+
decodeURI,
|
|
138
|
+
setTimeout: () => { },
|
|
139
|
+
clearTimeout: () => { },
|
|
140
|
+
setInterval: () => { },
|
|
141
|
+
clearInterval: () => { },
|
|
142
|
+
queueMicrotask: () => { },
|
|
143
|
+
globalThis: undefined, // set below
|
|
144
|
+
undefined,
|
|
145
|
+
Infinity,
|
|
146
|
+
NaN,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
class ExitSignal {
|
|
150
|
+
code;
|
|
151
|
+
constructor(code) {
|
|
152
|
+
this.code = code;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function formatValue(v) {
|
|
156
|
+
if (v === null)
|
|
157
|
+
return "null";
|
|
158
|
+
if (v === undefined)
|
|
159
|
+
return "undefined";
|
|
160
|
+
if (typeof v === "string")
|
|
161
|
+
return v;
|
|
162
|
+
if (typeof v === "function")
|
|
163
|
+
return `[Function: ${v.name || "(anonymous)"}]`;
|
|
164
|
+
if (Array.isArray(v))
|
|
165
|
+
return `[ ${v.map(formatValue).join(", ")} ]`;
|
|
166
|
+
if (v instanceof Error)
|
|
167
|
+
return `${v.name}: ${v.message}`;
|
|
168
|
+
if (typeof v === "object") {
|
|
169
|
+
try {
|
|
170
|
+
const entries = Object.entries(v)
|
|
171
|
+
.map(([k, val]) => `${k}: ${formatValue(val)}`)
|
|
172
|
+
.join(", ");
|
|
173
|
+
return `{ ${entries} }`;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return "[Object]";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return String(v);
|
|
180
|
+
}
|
|
181
|
+
// ─── execution ────────────────────────────────────────────────────────────────
|
|
182
|
+
function runJs(code) {
|
|
183
|
+
const outputLines = [];
|
|
184
|
+
const stderrLines = [];
|
|
185
|
+
const ctx = makeContext(outputLines, stderrLines);
|
|
186
|
+
let exitCode = 0;
|
|
187
|
+
try {
|
|
188
|
+
const result = vm.runInContext(code, ctx, { timeout: 5000 });
|
|
189
|
+
// If the expression returned a value and nothing was console.log'd, print it
|
|
190
|
+
if (result !== undefined && outputLines.length === 0) {
|
|
191
|
+
outputLines.push(formatValue(result));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
if (err instanceof ExitSignal) {
|
|
196
|
+
exitCode = err.code;
|
|
197
|
+
}
|
|
198
|
+
else if (err instanceof Error) {
|
|
199
|
+
stderrLines.push(`${err.name}: ${err.message}`);
|
|
200
|
+
exitCode = 1;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
stderrLines.push(String(err));
|
|
204
|
+
exitCode = 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
stdout: outputLines.length ? `${outputLines.join("\n")}\n` : "",
|
|
209
|
+
stderr: stderrLines.length ? `${stderrLines.join("\n")}\n` : "",
|
|
210
|
+
exitCode,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function runJsFile(code) {
|
|
214
|
+
// If the code is a single expression (no semicolons, no newlines, no statements),
|
|
215
|
+
// wrap it to capture the return value like a REPL would
|
|
216
|
+
const trimmed = code.trim();
|
|
217
|
+
const isExpression = !trimmed.includes("\n") &&
|
|
218
|
+
!trimmed.startsWith("const ") &&
|
|
219
|
+
!trimmed.startsWith("let ") &&
|
|
220
|
+
!trimmed.startsWith("var ") &&
|
|
221
|
+
!trimmed.startsWith("function ") &&
|
|
222
|
+
!trimmed.startsWith("class ") &&
|
|
223
|
+
!trimmed.startsWith("if ") &&
|
|
224
|
+
!trimmed.startsWith("for ") &&
|
|
225
|
+
!trimmed.startsWith("while ") &&
|
|
226
|
+
!trimmed.startsWith("import ") &&
|
|
227
|
+
!trimmed.startsWith("//");
|
|
228
|
+
if (isExpression)
|
|
229
|
+
return runJs(trimmed);
|
|
230
|
+
// Multi-line: wrap in IIFE
|
|
231
|
+
return runJs(`(async () => { ${code} })()`);
|
|
232
|
+
}
|
|
233
|
+
// ─── command ──────────────────────────────────────────────────────────────────
|
|
234
|
+
/**
|
|
235
|
+
* `node` virtual runtime command. Executes JS in a safe sandbox with
|
|
236
|
+
* limited globals and no host FS/child process access.
|
|
237
|
+
* @category system
|
|
238
|
+
* @params []
|
|
239
|
+
*/
|
|
240
|
+
export const nodeCommand = {
|
|
241
|
+
name: "node",
|
|
242
|
+
description: "JavaScript runtime (virtual)",
|
|
243
|
+
category: "system",
|
|
244
|
+
params: ["[--version] [-e <expr>] [-p <expr>] [file]"],
|
|
245
|
+
run: ({ args, shell, cwd }) => {
|
|
246
|
+
// Require explicit installation via `apt install nodejs`
|
|
247
|
+
if (!shell.packageManager.isInstalled("nodejs")) {
|
|
248
|
+
return {
|
|
249
|
+
stderr: "bash: node: command not found\nHint: install it with: apt install nodejs\n",
|
|
250
|
+
exitCode: 127,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (ifFlag(args, ["--version", "-v"])) {
|
|
254
|
+
return { stdout: `${VIRTUAL_VERSION}\n`, exitCode: 0 };
|
|
255
|
+
}
|
|
256
|
+
if (ifFlag(args, ["--versions"])) {
|
|
257
|
+
return {
|
|
258
|
+
stdout: `${JSON.stringify(VIRTUAL_VERSIONS, null, 2)}\n`,
|
|
259
|
+
exitCode: 0,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
// -e 'expr'
|
|
263
|
+
const eIdx = args.findIndex((a) => a === "-e" || a === "--eval");
|
|
264
|
+
if (eIdx !== -1) {
|
|
265
|
+
const expr = args[eIdx + 1];
|
|
266
|
+
if (!expr)
|
|
267
|
+
return { stderr: "node: -e requires an argument\n", exitCode: 1 };
|
|
268
|
+
const { stdout, stderr, exitCode } = runJs(expr);
|
|
269
|
+
return {
|
|
270
|
+
stdout: stdout || undefined,
|
|
271
|
+
stderr: stderr || undefined,
|
|
272
|
+
exitCode,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// -p 'expr' — print mode
|
|
276
|
+
const pIdx = args.findIndex((a) => a === "-p" || a === "--print");
|
|
277
|
+
if (pIdx !== -1) {
|
|
278
|
+
const expr = args[pIdx + 1];
|
|
279
|
+
if (!expr)
|
|
280
|
+
return { stderr: "node: -p requires an argument\n", exitCode: 1 };
|
|
281
|
+
const { stdout, stderr, exitCode } = runJs(expr);
|
|
282
|
+
return {
|
|
283
|
+
stdout: stdout || (exitCode === 0 ? "\n" : undefined),
|
|
284
|
+
stderr: stderr || undefined,
|
|
285
|
+
exitCode,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
// node <file>
|
|
289
|
+
const file = args.find((a) => !a.startsWith("-"));
|
|
290
|
+
if (file) {
|
|
291
|
+
const filePath = resolvePath(cwd, file);
|
|
292
|
+
if (!shell.vfs.exists(filePath)) {
|
|
293
|
+
return {
|
|
294
|
+
stderr: `node: cannot open file '${file}': No such file or directory\n`,
|
|
295
|
+
exitCode: 1,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const code = shell.vfs.readFile(filePath);
|
|
299
|
+
const { stdout, stderr, exitCode } = runJsFile(code);
|
|
300
|
+
return {
|
|
301
|
+
stdout: stdout || undefined,
|
|
302
|
+
stderr: stderr || undefined,
|
|
303
|
+
exitCode,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// No args — REPL hint
|
|
307
|
+
return {
|
|
308
|
+
stdout: [
|
|
309
|
+
`Welcome to Node.js ${VIRTUAL_VERSION}.`,
|
|
310
|
+
`Type ".exit" to exit the REPL.`,
|
|
311
|
+
`> `,
|
|
312
|
+
].join("\n"),
|
|
313
|
+
exitCode: 0,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* npm.ts — Virtual npm command.
|
|
3
|
+
* Gated behind `apt install npm`. Provides version info and informative
|
|
4
|
+
* stubs for common subcommands.
|
|
5
|
+
*/
|
|
6
|
+
import type { ShellModule } from "../types/commands";
|
|
7
|
+
/**
|
|
8
|
+
* `npm` virtual CLI. Requires `apt install npm` in the virtual package manager.
|
|
9
|
+
* @category system
|
|
10
|
+
* @params ["<command> [args]"]
|
|
11
|
+
*/
|
|
12
|
+
export declare const npmCommand: ShellModule;
|
|
13
|
+
/**
|
|
14
|
+
* `npx` virtual runner. Requires `apt install npm` in the virtual package manager.
|
|
15
|
+
* @category system
|
|
16
|
+
* @params ["<package> [args]"]
|
|
17
|
+
*/
|
|
18
|
+
export declare const npxCommand: ShellModule;
|
|
19
|
+
//# sourceMappingURL=npm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../src/commands/npm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,WAqFxB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,WAuBxB,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ifFlag } from "./command-helpers";
|
|
2
|
+
const NPM_VERSION = "9.2.0";
|
|
3
|
+
const NODE_VERSION = "18.19.0";
|
|
4
|
+
/**
|
|
5
|
+
* `npm` virtual CLI. Requires `apt install npm` in the virtual package manager.
|
|
6
|
+
* @category system
|
|
7
|
+
* @params ["<command> [args]"]
|
|
8
|
+
*/
|
|
9
|
+
export const npmCommand = {
|
|
10
|
+
name: "npm",
|
|
11
|
+
description: "Node.js package manager (virtual)",
|
|
12
|
+
category: "system",
|
|
13
|
+
params: ["<command> [args]"],
|
|
14
|
+
run: ({ args, shell }) => {
|
|
15
|
+
// Require explicit installation
|
|
16
|
+
if (!shell.packageManager.isInstalled("npm")) {
|
|
17
|
+
return {
|
|
18
|
+
stderr: "bash: npm: command not found\nHint: install it with: apt install npm\n",
|
|
19
|
+
exitCode: 127,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (ifFlag(args, ["--version", "-v"])) {
|
|
23
|
+
return { stdout: `${NPM_VERSION}\n`, exitCode: 0 };
|
|
24
|
+
}
|
|
25
|
+
const sub = args[0]?.toLowerCase();
|
|
26
|
+
switch (sub) {
|
|
27
|
+
case "version":
|
|
28
|
+
case "-version":
|
|
29
|
+
return {
|
|
30
|
+
stdout: `{ npm: '${NPM_VERSION}', node: '${NODE_VERSION}', v8: '10.2.154.26' }\n`,
|
|
31
|
+
exitCode: 0,
|
|
32
|
+
};
|
|
33
|
+
case "install":
|
|
34
|
+
case "i":
|
|
35
|
+
case "add":
|
|
36
|
+
return {
|
|
37
|
+
stderr: "npm warn: package installation is not available in the virtual runtime.\nnpm warn: This environment simulates npm CLI behaviour only.\n",
|
|
38
|
+
exitCode: 1,
|
|
39
|
+
};
|
|
40
|
+
case "run":
|
|
41
|
+
case "exec":
|
|
42
|
+
case "x":
|
|
43
|
+
return {
|
|
44
|
+
stderr: `npm error: script execution is not available in the virtual runtime.\n`,
|
|
45
|
+
exitCode: 1,
|
|
46
|
+
};
|
|
47
|
+
case "init":
|
|
48
|
+
return {
|
|
49
|
+
stdout: "Wrote to /home/user/package.json\n",
|
|
50
|
+
exitCode: 0,
|
|
51
|
+
};
|
|
52
|
+
case "list":
|
|
53
|
+
case "ls":
|
|
54
|
+
return {
|
|
55
|
+
stdout: `${sub === "ls" || sub === "list" ? "virtual-env@1.0.0" : ""}\n└── (empty)\n`,
|
|
56
|
+
exitCode: 0,
|
|
57
|
+
};
|
|
58
|
+
case "help":
|
|
59
|
+
case undefined:
|
|
60
|
+
return {
|
|
61
|
+
stdout: `${[
|
|
62
|
+
`npm ${NPM_VERSION}`,
|
|
63
|
+
"",
|
|
64
|
+
"Usage: npm <command>",
|
|
65
|
+
"",
|
|
66
|
+
"Commands:",
|
|
67
|
+
" install (not available in virtual runtime)",
|
|
68
|
+
" run (not available in virtual runtime)",
|
|
69
|
+
" exec (not available in virtual runtime)",
|
|
70
|
+
" list List installed packages",
|
|
71
|
+
" version Print versions",
|
|
72
|
+
" --version Print npm version",
|
|
73
|
+
].join("\n")}\n`,
|
|
74
|
+
exitCode: 0,
|
|
75
|
+
};
|
|
76
|
+
default:
|
|
77
|
+
return {
|
|
78
|
+
stderr: `npm error: unknown command: ${sub}\n`,
|
|
79
|
+
exitCode: 1,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* `npx` virtual runner. Requires `apt install npm` in the virtual package manager.
|
|
86
|
+
* @category system
|
|
87
|
+
* @params ["<package> [args]"]
|
|
88
|
+
*/
|
|
89
|
+
export const npxCommand = {
|
|
90
|
+
name: "npx",
|
|
91
|
+
description: "Node.js package runner (virtual)",
|
|
92
|
+
category: "system",
|
|
93
|
+
params: ["<package> [args]"],
|
|
94
|
+
run: ({ args, shell }) => {
|
|
95
|
+
if (!shell.packageManager.isInstalled("npm")) {
|
|
96
|
+
return {
|
|
97
|
+
stderr: "bash: npx: command not found\nHint: install it with: apt install npm\n",
|
|
98
|
+
exitCode: 127,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (ifFlag(args, ["--version"])) {
|
|
102
|
+
return { stdout: `${NPM_VERSION}\n`, exitCode: 0 };
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
stderr: `npx: package execution is not available in the virtual runtime.\n`,
|
|
106
|
+
exitCode: 1,
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/commands/ping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/commands/ping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,WAAW,EAAE,WAuBzB,CAAC"}
|
package/dist/commands/ping.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { parseArgs } from "./command-helpers";
|
|
1
2
|
export const pingCommand = {
|
|
2
3
|
name: "ping",
|
|
3
4
|
description: "Send ICMP ECHO_REQUEST (mock)",
|
|
4
5
|
category: "network",
|
|
5
6
|
params: ["[-c <count>] <host>"],
|
|
6
7
|
run: ({ args }) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const { flagsWithValues, positionals } = parseArgs(args, {
|
|
9
|
+
flagsWithValue: ["-c", "-i", "-W"],
|
|
10
|
+
});
|
|
11
|
+
const host = positionals[0] ?? "localhost";
|
|
12
|
+
const countArg = flagsWithValues.get("-c");
|
|
13
|
+
const count = countArg ? Math.max(1, parseInt(countArg, 10) || 4) : 4;
|
|
9
14
|
const lines = [`PING ${host}: 56 data bytes`];
|
|
10
15
|
for (let i = 0; i < count; i++) {
|
|
11
16
|
const ms = (Math.random() * 10 + 1).toFixed(3);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printf.d.ts","sourceRoot":"","sources":["../../src/commands/printf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAoGrD,eAAO,MAAM,aAAa,EAAE,WAW3B,CAAC"}
|