@scelar/nodepod 1.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.
Files changed (134) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +240 -0
  3. package/dist/child_process-BJOMsZje.js +8233 -0
  4. package/dist/child_process-BJOMsZje.js.map +1 -0
  5. package/dist/child_process-Cj8vOcuc.cjs +7434 -0
  6. package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
  7. package/dist/index-Cb1Cgdnd.js +35308 -0
  8. package/dist/index-Cb1Cgdnd.js.map +1 -0
  9. package/dist/index-DsMGS-xc.cjs +37195 -0
  10. package/dist/index-DsMGS-xc.cjs.map +1 -0
  11. package/dist/index.cjs +65 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.mjs +59 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/package.json +95 -0
  16. package/src/__tests__/smoke.test.ts +11 -0
  17. package/src/constants/cdn-urls.ts +18 -0
  18. package/src/constants/config.ts +236 -0
  19. package/src/cross-origin.ts +26 -0
  20. package/src/engine-factory.ts +176 -0
  21. package/src/engine-types.ts +56 -0
  22. package/src/helpers/byte-encoding.ts +39 -0
  23. package/src/helpers/digest.ts +9 -0
  24. package/src/helpers/event-loop.ts +96 -0
  25. package/src/helpers/wasm-cache.ts +133 -0
  26. package/src/iframe-sandbox.ts +141 -0
  27. package/src/index.ts +192 -0
  28. package/src/isolation-helpers.ts +148 -0
  29. package/src/memory-volume.ts +941 -0
  30. package/src/module-transformer.ts +368 -0
  31. package/src/packages/archive-extractor.ts +248 -0
  32. package/src/packages/browser-bundler.ts +284 -0
  33. package/src/packages/installer.ts +396 -0
  34. package/src/packages/registry-client.ts +131 -0
  35. package/src/packages/version-resolver.ts +411 -0
  36. package/src/polyfills/assert.ts +384 -0
  37. package/src/polyfills/async_hooks.ts +144 -0
  38. package/src/polyfills/buffer.ts +628 -0
  39. package/src/polyfills/child_process.ts +2288 -0
  40. package/src/polyfills/chokidar.ts +336 -0
  41. package/src/polyfills/cluster.ts +106 -0
  42. package/src/polyfills/console.ts +136 -0
  43. package/src/polyfills/constants.ts +123 -0
  44. package/src/polyfills/crypto.ts +885 -0
  45. package/src/polyfills/dgram.ts +87 -0
  46. package/src/polyfills/diagnostics_channel.ts +76 -0
  47. package/src/polyfills/dns.ts +134 -0
  48. package/src/polyfills/domain.ts +68 -0
  49. package/src/polyfills/esbuild.ts +854 -0
  50. package/src/polyfills/events.ts +276 -0
  51. package/src/polyfills/fs.ts +2888 -0
  52. package/src/polyfills/fsevents.ts +79 -0
  53. package/src/polyfills/http.ts +1449 -0
  54. package/src/polyfills/http2.ts +199 -0
  55. package/src/polyfills/https.ts +76 -0
  56. package/src/polyfills/inspector.ts +62 -0
  57. package/src/polyfills/lightningcss.ts +105 -0
  58. package/src/polyfills/module.ts +191 -0
  59. package/src/polyfills/net.ts +353 -0
  60. package/src/polyfills/os.ts +238 -0
  61. package/src/polyfills/path.ts +206 -0
  62. package/src/polyfills/perf_hooks.ts +102 -0
  63. package/src/polyfills/process.ts +690 -0
  64. package/src/polyfills/punycode.ts +159 -0
  65. package/src/polyfills/querystring.ts +93 -0
  66. package/src/polyfills/quic.ts +118 -0
  67. package/src/polyfills/readdirp.ts +229 -0
  68. package/src/polyfills/readline.ts +692 -0
  69. package/src/polyfills/repl.ts +134 -0
  70. package/src/polyfills/rollup.ts +119 -0
  71. package/src/polyfills/sea.ts +33 -0
  72. package/src/polyfills/sqlite.ts +78 -0
  73. package/src/polyfills/stream.ts +1620 -0
  74. package/src/polyfills/string_decoder.ts +25 -0
  75. package/src/polyfills/tailwindcss-oxide.ts +309 -0
  76. package/src/polyfills/test.ts +197 -0
  77. package/src/polyfills/timers.ts +32 -0
  78. package/src/polyfills/tls.ts +105 -0
  79. package/src/polyfills/trace_events.ts +50 -0
  80. package/src/polyfills/tty.ts +71 -0
  81. package/src/polyfills/url.ts +174 -0
  82. package/src/polyfills/util.ts +559 -0
  83. package/src/polyfills/v8.ts +126 -0
  84. package/src/polyfills/vm.ts +132 -0
  85. package/src/polyfills/volume-registry.ts +15 -0
  86. package/src/polyfills/wasi.ts +44 -0
  87. package/src/polyfills/worker_threads.ts +326 -0
  88. package/src/polyfills/ws.ts +595 -0
  89. package/src/polyfills/zlib.ts +881 -0
  90. package/src/request-proxy.ts +716 -0
  91. package/src/script-engine.ts +3375 -0
  92. package/src/sdk/nodepod-fs.ts +93 -0
  93. package/src/sdk/nodepod-process.ts +86 -0
  94. package/src/sdk/nodepod-terminal.ts +350 -0
  95. package/src/sdk/nodepod.ts +509 -0
  96. package/src/sdk/types.ts +70 -0
  97. package/src/shell/commands/bun.ts +121 -0
  98. package/src/shell/commands/directory.ts +297 -0
  99. package/src/shell/commands/file-ops.ts +525 -0
  100. package/src/shell/commands/git.ts +2142 -0
  101. package/src/shell/commands/node.ts +80 -0
  102. package/src/shell/commands/npm.ts +198 -0
  103. package/src/shell/commands/pm-types.ts +45 -0
  104. package/src/shell/commands/pnpm.ts +82 -0
  105. package/src/shell/commands/search.ts +264 -0
  106. package/src/shell/commands/shell-env.ts +352 -0
  107. package/src/shell/commands/text-processing.ts +1152 -0
  108. package/src/shell/commands/yarn.ts +84 -0
  109. package/src/shell/shell-builtins.ts +19 -0
  110. package/src/shell/shell-helpers.ts +250 -0
  111. package/src/shell/shell-interpreter.ts +514 -0
  112. package/src/shell/shell-parser.ts +429 -0
  113. package/src/shell/shell-types.ts +85 -0
  114. package/src/syntax-transforms.ts +561 -0
  115. package/src/threading/engine-worker.ts +64 -0
  116. package/src/threading/inline-worker.ts +372 -0
  117. package/src/threading/offload-types.ts +112 -0
  118. package/src/threading/offload-worker.ts +383 -0
  119. package/src/threading/offload.ts +271 -0
  120. package/src/threading/process-context.ts +92 -0
  121. package/src/threading/process-handle.ts +275 -0
  122. package/src/threading/process-manager.ts +956 -0
  123. package/src/threading/process-worker-entry.ts +854 -0
  124. package/src/threading/shared-vfs.ts +352 -0
  125. package/src/threading/sync-channel.ts +135 -0
  126. package/src/threading/task-queue.ts +177 -0
  127. package/src/threading/vfs-bridge.ts +231 -0
  128. package/src/threading/worker-pool.ts +233 -0
  129. package/src/threading/worker-protocol.ts +358 -0
  130. package/src/threading/worker-vfs.ts +218 -0
  131. package/src/types/externals.d.ts +38 -0
  132. package/src/types/fs-streams.ts +142 -0
  133. package/src/types/manifest.ts +17 -0
  134. package/src/worker-sandbox.ts +90 -0
@@ -0,0 +1,84 @@
1
+ import type { ShellCommand } from "../shell-types";
2
+ import type { PmDeps } from "./pm-types";
3
+ import { VERSIONS } from "../../constants/config";
4
+
5
+ const A_RESET = "\x1b[0m";
6
+ const A_BOLD = "\x1b[1m";
7
+ const A_CYAN = "\x1b[36m";
8
+
9
+ export function createYarnCommand(deps: PmDeps): ShellCommand {
10
+ return {
11
+ name: "yarn",
12
+ async execute(params, ctx) {
13
+ if (!deps.hasFile("/"))
14
+ return { stdout: "", stderr: "Volume unavailable\n", exitCode: 1 };
15
+
16
+ const sub = params[0];
17
+ if (!sub) return deps.installPackages([], ctx, "yarn");
18
+ if (sub === "help" || sub === "--help") {
19
+ return {
20
+ stdout:
21
+ `${A_BOLD}Usage:${A_RESET} yarn <command>\n\n` +
22
+ `${A_BOLD}Commands:${A_RESET}\n` +
23
+ ` ${A_CYAN}add${A_RESET} [pkg] Install packages\n` +
24
+ ` ${A_CYAN}install${A_RESET} Install from manifest\n` +
25
+ ` ${A_CYAN}remove${A_RESET} <pkg> Remove a package\n` +
26
+ ` ${A_CYAN}list${A_RESET} List installed packages\n` +
27
+ ` ${A_CYAN}run${A_RESET} <script> Run a script\n` +
28
+ ` ${A_CYAN}dlx${A_RESET} <pkg> Download and execute a package\n` +
29
+ ` ${A_CYAN}init${A_RESET} Create a package.json\n` +
30
+ ` ${A_CYAN}create${A_RESET} <pkg> Create a project\n` +
31
+ ` ${A_CYAN}version${A_RESET} Show version info\n`,
32
+ stderr: "",
33
+ exitCode: 0,
34
+ };
35
+ }
36
+
37
+ switch (sub) {
38
+ case "add":
39
+ return deps.installPackages(params.slice(1), ctx, "yarn");
40
+ case "install":
41
+ case "i":
42
+ return deps.installPackages(params.slice(1), ctx, "yarn");
43
+ case "remove":
44
+ case "rm":
45
+ case "uninstall":
46
+ return deps.uninstallPackages(params.slice(1), ctx, "yarn");
47
+ case "list":
48
+ case "ls":
49
+ return deps.listPackages(ctx, "yarn");
50
+ case "run":
51
+ return deps.runScript(params.slice(1), ctx);
52
+ case "start":
53
+ return deps.runScript(["start"], ctx);
54
+ case "test":
55
+ case "t":
56
+ return deps.runScript(["test"], ctx);
57
+ case "exec":
58
+ return deps.npxExecute(params.slice(1), ctx);
59
+ case "dlx":
60
+ return deps.npxExecute(params.slice(1), ctx);
61
+ case "init":
62
+ case "create":
63
+ return deps.npmInitOrCreate(params.slice(1), sub, ctx);
64
+ case "version":
65
+ case "-v":
66
+ case "--version":
67
+ return { stdout: VERSIONS.YARN + "\n", stderr: "", exitCode: 0 };
68
+ case "info":
69
+ return deps.npmInfo(params.slice(1), ctx);
70
+ case "audit":
71
+ return { stdout: "0 vulnerabilities found\n", stderr: "", exitCode: 0 };
72
+ case "outdated":
73
+ return { stdout: "", stderr: "", exitCode: 0 };
74
+ case "why":
75
+ return { stdout: "", stderr: deps.formatWarn("why: not available in nodepod", "yarn"), exitCode: 0 };
76
+ case "global":
77
+ return { stdout: "", stderr: deps.formatWarn("global: not available in nodepod", "yarn"), exitCode: 0 };
78
+ default:
79
+ // yarn classic treats unknown commands as `yarn run <cmd>`
80
+ return deps.runScript(params, ctx);
81
+ }
82
+ },
83
+ };
84
+ }
@@ -0,0 +1,19 @@
1
+ // Assembles all builtin commands from category modules into one map.
2
+
3
+ import type { BuiltinFn } from "./shell-types";
4
+ import { fileOpsCommands } from "./commands/file-ops";
5
+ import { directoryCommands } from "./commands/directory";
6
+ import { textProcessingCommands } from "./commands/text-processing";
7
+ import { searchCommands } from "./commands/search";
8
+ import { shellEnvCommands, setBuiltinsRef } from "./commands/shell-env";
9
+
10
+ export const builtins = new Map<string, BuiltinFn>([
11
+ ...fileOpsCommands,
12
+ ...directoryCommands,
13
+ ...textProcessingCommands,
14
+ ...searchCommands,
15
+ ...shellEnvCommands,
16
+ ]);
17
+
18
+ // shell-env needs the builtins ref for `which` and `type`
19
+ setBuiltinsRef(builtins);
@@ -0,0 +1,250 @@
1
+ // Shared utilities for shell builtins: colors, arg parsing, path helpers, result builders.
2
+
3
+ import type { ShellResult } from "./shell-types";
4
+ import * as pathModule from "../polyfills/path";
5
+
6
+ /* ------------------------------------------------------------------ */
7
+ /* ANSI color helpers */
8
+ /* ------------------------------------------------------------------ */
9
+
10
+ export const RESET = "\x1b[0m";
11
+ export const DIM = "\x1b[2m";
12
+ export const GREEN = "\x1b[32m";
13
+ export const MAGENTA = "\x1b[35m";
14
+ export const CYAN = "\x1b[36m";
15
+ export const BOLD_BLUE = "\x1b[1;34m";
16
+ export const BOLD_RED = "\x1b[1;31m";
17
+
18
+ /* ------------------------------------------------------------------ */
19
+ /* ShellResult builders */
20
+ /* ------------------------------------------------------------------ */
21
+
22
+ export const ok = (stdout = ""): ShellResult => ({
23
+ stdout,
24
+ stderr: "",
25
+ exitCode: 0,
26
+ });
27
+
28
+ export const fail = (stderr: string, code = 1): ShellResult => ({
29
+ stdout: "",
30
+ stderr,
31
+ exitCode: code,
32
+ });
33
+
34
+ export const EXIT_OK: ShellResult = { stdout: "", stderr: "", exitCode: 0 };
35
+ export const EXIT_FAIL: ShellResult = { stdout: "", stderr: "", exitCode: 1 };
36
+
37
+ /* ------------------------------------------------------------------ */
38
+ /* Date / time constants */
39
+ /* ------------------------------------------------------------------ */
40
+
41
+ export const MONTHS_SHORT = [
42
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
43
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
44
+ ] as const;
45
+
46
+ export const MONTHS_LONG = [
47
+ "January", "February", "March", "April", "May", "June",
48
+ "July", "August", "September", "October", "November", "December",
49
+ ] as const;
50
+
51
+ export const DAYS_SHORT = [
52
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
53
+ ] as const;
54
+
55
+ export const DAYS_LONG = [
56
+ "Sunday", "Monday", "Tuesday", "Wednesday",
57
+ "Thursday", "Friday", "Saturday",
58
+ ] as const;
59
+
60
+ /* ------------------------------------------------------------------ */
61
+ /* Path resolution */
62
+ /* ------------------------------------------------------------------ */
63
+
64
+ export function resolvePath(p: string, cwd: string): string {
65
+ if (p.startsWith("/")) return pathModule.normalize(p);
66
+ return pathModule.normalize(`${cwd}/${p}`);
67
+ }
68
+
69
+ export { pathModule };
70
+
71
+ /* ------------------------------------------------------------------ */
72
+ /* Argument parsing */
73
+ /* ------------------------------------------------------------------ */
74
+
75
+ export function parseArgs(
76
+ args: string[],
77
+ knownFlags: string[],
78
+ knownOpts: string[] = [],
79
+ ): { flags: Set<string>; opts: Record<string, string>; positional: string[] } {
80
+ const flags = new Set<string>();
81
+ const opts: Record<string, string> = {};
82
+ const positional: string[] = [];
83
+ for (let i = 0; i < args.length; i++) {
84
+ const a = args[i];
85
+ if (a === "--") {
86
+ positional.push(...args.slice(i + 1));
87
+ break;
88
+ }
89
+ if (a.startsWith("--")) {
90
+ const eq = a.indexOf("=");
91
+ if (eq > 0) {
92
+ opts[a.slice(2, eq)] = a.slice(eq + 1);
93
+ } else {
94
+ flags.add(a.slice(2));
95
+ }
96
+ } else if (a.startsWith("-") && a.length > 1 && !/^-\d/.test(a)) {
97
+ for (let j = 1; j < a.length; j++) {
98
+ const ch = a[j];
99
+ if (knownOpts.includes(ch) && j + 1 < a.length) {
100
+ opts[ch] = a.slice(j + 1);
101
+ break;
102
+ } else if (knownOpts.includes(ch) && i + 1 < args.length) {
103
+ opts[ch] = args[++i];
104
+ break;
105
+ } else if (knownFlags.includes(ch)) {
106
+ flags.add(ch);
107
+ }
108
+ }
109
+ } else {
110
+ positional.push(a);
111
+ }
112
+ }
113
+ return { flags, opts, positional };
114
+ }
115
+
116
+ /* ------------------------------------------------------------------ */
117
+ /* String processing */
118
+ /* ------------------------------------------------------------------ */
119
+
120
+ // Expand POSIX character classes like [:upper:], [:lower:], etc. for `tr`
121
+ export function expandCharClass(s: string): string {
122
+ return s
123
+ .replace(/\[:upper:\]/g, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
124
+ .replace(/\[:lower:\]/g, "abcdefghijklmnopqrstuvwxyz")
125
+ .replace(
126
+ /\[:alpha:\]/g,
127
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
128
+ )
129
+ .replace(/\[:digit:\]/g, "0123456789")
130
+ .replace(
131
+ /\[:alnum:\]/g,
132
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
133
+ )
134
+ .replace(/\[:space:\]/g, " \t\n\r\x0b\x0c")
135
+ .replace(/\[:blank:\]/g, " \t")
136
+ .replace(/\[:punct:\]/g, "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
137
+ .replace(
138
+ /\[:print:\]/g,
139
+ (() => {
140
+ let r = "";
141
+ for (let i = 32; i < 127; i++) r += String.fromCharCode(i);
142
+ return r;
143
+ })(),
144
+ )
145
+ .replace(
146
+ /\[:graph:\]/g,
147
+ (() => {
148
+ let r = "";
149
+ for (let i = 33; i < 127; i++) r += String.fromCharCode(i);
150
+ return r;
151
+ })(),
152
+ )
153
+ .replace(
154
+ /\[:cntrl:\]/g,
155
+ (() => {
156
+ let r = "";
157
+ for (let i = 0; i < 32; i++) r += String.fromCharCode(i);
158
+ r += String.fromCharCode(127);
159
+ return r;
160
+ })(),
161
+ );
162
+ }
163
+
164
+ export function processEscapes(s: string): string {
165
+ let out = "";
166
+ for (let i = 0; i < s.length; i++) {
167
+ if (s[i] === "\\" && i + 1 < s.length) {
168
+ const c = s[i + 1];
169
+ if (c === "n") {
170
+ out += "\n";
171
+ i++;
172
+ continue;
173
+ }
174
+ if (c === "t") {
175
+ out += "\t";
176
+ i++;
177
+ continue;
178
+ }
179
+ if (c === "r") {
180
+ out += "\r";
181
+ i++;
182
+ continue;
183
+ }
184
+ if (c === "a") {
185
+ out += "\x07";
186
+ i++;
187
+ continue;
188
+ }
189
+ if (c === "b") {
190
+ out += "\b";
191
+ i++;
192
+ continue;
193
+ }
194
+ if (c === "f") {
195
+ out += "\f";
196
+ i++;
197
+ continue;
198
+ }
199
+ if (c === "v") {
200
+ out += "\x0b";
201
+ i++;
202
+ continue;
203
+ }
204
+ if (c === "\\") {
205
+ out += "\\";
206
+ i++;
207
+ continue;
208
+ }
209
+ if (c === "0") {
210
+ let oct = "";
211
+ let j = i + 2;
212
+ while (j < s.length && j < i + 5 && s[j] >= "0" && s[j] <= "7")
213
+ oct += s[j++];
214
+ out += String.fromCharCode(parseInt(oct || "0", 8));
215
+ i = j - 1;
216
+ continue;
217
+ }
218
+ if (c === "x") {
219
+ const hex = s.slice(i + 2, i + 4);
220
+ if (/^[0-9a-fA-F]{1,2}$/.test(hex)) {
221
+ out += String.fromCharCode(parseInt(hex, 16));
222
+ i += 1 + hex.length;
223
+ continue;
224
+ }
225
+ }
226
+ out += s[i];
227
+ } else {
228
+ out += s[i];
229
+ }
230
+ }
231
+ return out;
232
+ }
233
+
234
+ export function humanSize(bytes: number): string {
235
+ if (bytes < 1024) return String(bytes);
236
+ const units = ["K", "M", "G", "T"];
237
+ let size = bytes;
238
+ for (const u of units) {
239
+ size /= 1024;
240
+ if (size < 1024 || u === "T") return size.toFixed(size < 10 ? 1 : 0) + u;
241
+ }
242
+ return String(bytes);
243
+ }
244
+
245
+ export function globToRegex(pattern: string): string {
246
+ return pattern
247
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
248
+ .replace(/\*/g, ".*")
249
+ .replace(/\?/g, ".");
250
+ }