@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,297 @@
1
+ import type { BuiltinFn } from "../shell-types";
2
+ import {
3
+ ok,
4
+ fail,
5
+ resolvePath,
6
+ parseArgs,
7
+ humanSize,
8
+ pathModule,
9
+ MONTHS_SHORT,
10
+ RESET,
11
+ DIM,
12
+ GREEN,
13
+ CYAN,
14
+ BOLD_BLUE,
15
+ } from "../shell-helpers";
16
+ import { LS_BLOCK_SIZE } from "../../constants/config";
17
+
18
+ /* ------------------------------------------------------------------ */
19
+ /* Helpers */
20
+ /* ------------------------------------------------------------------ */
21
+
22
+ function colorName(name: string, isDir: boolean): string {
23
+ if (isDir) return `${BOLD_BLUE}${name}${RESET}`;
24
+ const dot = name.lastIndexOf(".");
25
+ const ext = dot >= 0 ? name.slice(dot) : "";
26
+ if (ext === ".sh" || ext === ".bin") return `${GREEN}${name}${RESET}`;
27
+ return name;
28
+ }
29
+
30
+ function lsDate(d: Date): string {
31
+ const mon = MONTHS_SHORT[d.getMonth()];
32
+ const day = String(d.getDate()).padStart(2, " ");
33
+ const now = new Date();
34
+ const sixMonthsAgo = new Date(
35
+ now.getFullYear(),
36
+ now.getMonth() - 6,
37
+ now.getDate(),
38
+ );
39
+ if (d < sixMonthsAgo || d > now) {
40
+ return `${mon} ${day} ${d.getFullYear()}`;
41
+ }
42
+ const hh = String(d.getHours()).padStart(2, "0");
43
+ const mm = String(d.getMinutes()).padStart(2, "0");
44
+ return `${mon} ${day} ${hh}:${mm}`;
45
+ }
46
+
47
+ function hashCode(s: string): number {
48
+ let h = 0;
49
+ for (let i = 0; i < s.length; i++) h = ((h << 5) - h + s.charCodeAt(i)) | 0;
50
+ return h;
51
+ }
52
+
53
+ /* ------------------------------------------------------------------ */
54
+ /* Commands */
55
+ /* ------------------------------------------------------------------ */
56
+
57
+ const ls: BuiltinFn = (args, ctx) => {
58
+ const { flags, positional } = parseArgs(args, [
59
+ "l",
60
+ "a",
61
+ "A",
62
+ "R",
63
+ "1",
64
+ "h",
65
+ "S",
66
+ "t",
67
+ "r",
68
+ "F",
69
+ "d",
70
+ "i",
71
+ ]);
72
+ const showAll = flags.has("a");
73
+ const showAlmostAll = flags.has("A");
74
+ const longForm = flags.has("l");
75
+ const recursive = flags.has("R");
76
+ const onePerLine = flags.has("1") || longForm;
77
+ const humanReadable = flags.has("h");
78
+ const sortBySize = flags.has("S");
79
+ const sortByTime = flags.has("t");
80
+ const reverseSort = flags.has("r");
81
+ const classify = flags.has("F");
82
+ const dirOnly = flags.has("d");
83
+ const showInode = flags.has("i");
84
+
85
+ const dir =
86
+ positional.length > 0 ? resolvePath(positional[0], ctx.cwd) : ctx.cwd;
87
+
88
+ const lsDir = (d: string, prefix: string): string => {
89
+ if (dirOnly) {
90
+ const name = positional[0] || d;
91
+ if (longForm) {
92
+ const st = ctx.volume.statSync(d);
93
+ const isDir = st.isDirectory();
94
+ const mode = isDir
95
+ ? `${CYAN}drwxr-xr-x${RESET}`
96
+ : `${DIM}-rw-r--r--${RESET}`;
97
+ return `${mode} 1 user user ${String(0).padStart(6)} ${lsDate(new Date(st.mtimeMs || Date.now()))} ${colorName(name, isDir)}\n`;
98
+ }
99
+ return colorName(name, true) + "\n";
100
+ }
101
+
102
+ let entries: string[];
103
+ try {
104
+ entries = ctx.volume.readdirSync(d);
105
+ } catch {
106
+ return `ls: cannot access '${d}': No such file or directory\n`;
107
+ }
108
+
109
+ if (showAll) {
110
+ /* all */
111
+ } else if (showAlmostAll)
112
+ entries = entries.filter((e) => e !== "." && e !== "..");
113
+ else entries = entries.filter((e) => !e.startsWith("."));
114
+
115
+ interface EntryInfo {
116
+ name: string;
117
+ isDir: boolean;
118
+ size: number;
119
+ mtime: number;
120
+ }
121
+ const infos: EntryInfo[] = entries.map((name) => {
122
+ const full = d === "/" ? `/${name}` : `${d}/${name}`;
123
+ try {
124
+ const st = ctx.volume.statSync(full);
125
+ const isDir = st.isDirectory();
126
+ let size = 0;
127
+ if (!isDir) {
128
+ try {
129
+ size = ctx.volume.readFileSync(full).length;
130
+ } catch {
131
+ /* */
132
+ }
133
+ }
134
+ return { name, isDir, size, mtime: st.mtimeMs || 0 };
135
+ } catch {
136
+ return { name, isDir: false, size: 0, mtime: 0 };
137
+ }
138
+ });
139
+
140
+ if (sortBySize) infos.sort((a, b) => b.size - a.size);
141
+ else if (sortByTime) infos.sort((a, b) => b.mtime - a.mtime);
142
+ else infos.sort((a, b) => a.name.localeCompare(b.name));
143
+ if (reverseSort) infos.reverse();
144
+
145
+ let out = prefix ? `${BOLD_BLUE}${prefix}${RESET}:\n` : "";
146
+
147
+ if (longForm) {
148
+ const totalBlocks = infos.reduce(
149
+ (s, e) => s + Math.ceil(e.size / LS_BLOCK_SIZE),
150
+ 0,
151
+ );
152
+ out += `total ${totalBlocks}\n`;
153
+ for (const info of infos) {
154
+ const mode = info.isDir
155
+ ? `${CYAN}drwxr-xr-x${RESET}`
156
+ : `${DIM}-rw-r--r--${RESET}`;
157
+ const sizeStr = humanReadable
158
+ ? humanSize(info.size).padStart(5)
159
+ : String(info.size).padStart(6);
160
+ const date = lsDate(new Date(info.mtime || Date.now()));
161
+ const colored = colorName(info.name, info.isDir);
162
+ const suffix = classify
163
+ ? info.isDir
164
+ ? "/"
165
+ : ""
166
+ : info.isDir
167
+ ? "/"
168
+ : "";
169
+ const inode = showInode
170
+ ? `${String(Math.abs(hashCode(d + "/" + info.name))).padStart(7)} `
171
+ : "";
172
+ out += `${inode}${mode} 1 user user ${sizeStr} ${date} ${colored}${suffix}\n`;
173
+ }
174
+ } else if (onePerLine) {
175
+ for (const info of infos) {
176
+ const inode = showInode
177
+ ? `${String(Math.abs(hashCode(d + "/" + info.name))).padStart(7)} `
178
+ : "";
179
+ const suffix = classify ? (info.isDir ? "/" : "") : "";
180
+ out += `${inode}${colorName(info.name, info.isDir)}${suffix}\n`;
181
+ }
182
+ } else {
183
+ const colored = infos.map((info) => {
184
+ const suffix = classify ? (info.isDir ? "/" : "") : "";
185
+ return colorName(info.name, info.isDir) + suffix;
186
+ });
187
+ out += colored.join(" ") + "\n";
188
+ }
189
+
190
+ if (recursive) {
191
+ for (const info of infos) {
192
+ if (info.isDir) {
193
+ const full = d === "/" ? `/${info.name}` : `${d}/${info.name}`;
194
+ out += "\n" + lsDir(full, full);
195
+ }
196
+ }
197
+ }
198
+
199
+ return out;
200
+ };
201
+
202
+ try {
203
+ const st = ctx.volume.statSync(dir);
204
+ if (st.isFile() && !dirOnly) {
205
+ if (longForm) {
206
+ let size = 0;
207
+ try {
208
+ size = ctx.volume.readFileSync(dir).length;
209
+ } catch {
210
+ /* */
211
+ }
212
+ const sizeStr = humanReadable
213
+ ? humanSize(size).padStart(5)
214
+ : String(size).padStart(6);
215
+ const date = lsDate(new Date(st.mtimeMs || Date.now()));
216
+ return ok(
217
+ `${DIM}-rw-r--r--${RESET} 1 user user ${sizeStr} ${date} ${positional[0]}\n`,
218
+ );
219
+ }
220
+ return ok(positional[0] + "\n");
221
+ }
222
+ } catch {
223
+ return fail(
224
+ `ls: cannot access '${positional[0] || dir}': No such file or directory\n`,
225
+ );
226
+ }
227
+
228
+ return ok(lsDir(dir, positional.length > 1 ? dir : ""));
229
+ };
230
+
231
+ const cd: BuiltinFn = (args, ctx) => {
232
+ const target = args[0] || ctx.env.HOME || "/";
233
+ let newDir: string;
234
+
235
+ if (target === "-") {
236
+ newDir = ctx.env.OLDPWD || ctx.cwd;
237
+ } else {
238
+ newDir = resolvePath(target, ctx.cwd);
239
+ }
240
+
241
+ try {
242
+ const st = ctx.volume.statSync(newDir);
243
+ if (!st.isDirectory()) return fail(`cd: not a directory: ${target}\n`);
244
+ ctx.env.OLDPWD = ctx.cwd;
245
+ ctx.cwd = newDir;
246
+ ctx.env.PWD = newDir;
247
+ // keep process.cwd() in sync
248
+ try {
249
+ (globalThis as any).process?.chdir?.(newDir);
250
+ } catch {}
251
+ return ok();
252
+ } catch {
253
+ return fail(`cd: no such file or directory: ${target}\n`);
254
+ }
255
+ };
256
+
257
+ const pwd: BuiltinFn = (_args, ctx) => {
258
+ return ok(ctx.cwd + "\n");
259
+ };
260
+
261
+ const basename_cmd: BuiltinFn = (args) => {
262
+ const { positional } = parseArgs(args, ["a", "z"], ["s"]);
263
+ if (positional.length === 0) return fail("basename: missing operand\n");
264
+
265
+ const suffix = positional[1] || "";
266
+ let result = pathModule.basename(positional[0]);
267
+ if (suffix && result.endsWith(suffix)) {
268
+ result = result.slice(0, -suffix.length);
269
+ }
270
+ return ok(result + "\n");
271
+ };
272
+
273
+ const dirname_cmd: BuiltinFn = (args) => {
274
+ if (args.length === 0) return fail("dirname: missing operand\n");
275
+ return ok(pathModule.dirname(args[0]) + "\n");
276
+ };
277
+
278
+ const realpath_cmd: BuiltinFn = (args, ctx) => {
279
+ if (args.length === 0) return fail("realpath: missing operand\n");
280
+ const p = resolvePath(args[0], ctx.cwd);
281
+ if (!ctx.volume.existsSync(p))
282
+ return fail(`realpath: ${args[0]}: No such file or directory\n`);
283
+ return ok(p + "\n");
284
+ };
285
+
286
+ /* ------------------------------------------------------------------ */
287
+ /* Registry */
288
+ /* ------------------------------------------------------------------ */
289
+
290
+ export const directoryCommands: [string, BuiltinFn][] = [
291
+ ["ls", ls],
292
+ ["cd", cd],
293
+ ["pwd", pwd],
294
+ ["basename", basename_cmd],
295
+ ["dirname", dirname_cmd],
296
+ ["realpath", realpath_cmd],
297
+ ];