typescript-virtual-container 1.2.4 → 1.2.5

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 (66) hide show
  1. package/README.md +868 -1245
  2. package/benchmark-results.txt +21 -21
  3. package/dist/SSHMimic/index.d.ts +19 -2
  4. package/dist/SSHMimic/index.d.ts.map +1 -1
  5. package/dist/SSHMimic/index.js +116 -20
  6. package/dist/VirtualFileSystem/index.d.ts +115 -88
  7. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  8. package/dist/VirtualFileSystem/index.js +406 -258
  9. package/dist/VirtualShell/index.d.ts +3 -4
  10. package/dist/VirtualShell/index.d.ts.map +1 -1
  11. package/dist/VirtualShell/index.js +4 -6
  12. package/dist/VirtualUserManager/index.d.ts +25 -0
  13. package/dist/VirtualUserManager/index.d.ts.map +1 -1
  14. package/dist/VirtualUserManager/index.js +33 -0
  15. package/dist/commands/chmod.d.ts +3 -0
  16. package/dist/commands/chmod.d.ts.map +1 -0
  17. package/dist/commands/chmod.js +31 -0
  18. package/dist/commands/cp.d.ts +3 -0
  19. package/dist/commands/cp.d.ts.map +1 -0
  20. package/dist/commands/cp.js +68 -0
  21. package/dist/commands/find.d.ts +3 -0
  22. package/dist/commands/find.d.ts.map +1 -0
  23. package/dist/commands/find.js +48 -0
  24. package/dist/commands/grep.d.ts.map +1 -1
  25. package/dist/commands/grep.js +61 -35
  26. package/dist/commands/head.d.ts +3 -0
  27. package/dist/commands/head.d.ts.map +1 -0
  28. package/dist/commands/head.js +30 -0
  29. package/dist/commands/index.d.ts.map +1 -1
  30. package/dist/commands/index.js +25 -35
  31. package/dist/commands/ln.d.ts +3 -0
  32. package/dist/commands/ln.d.ts.map +1 -0
  33. package/dist/commands/ln.js +42 -0
  34. package/dist/commands/mv.d.ts +3 -0
  35. package/dist/commands/mv.d.ts.map +1 -0
  36. package/dist/commands/mv.js +35 -0
  37. package/dist/commands/tail.d.ts +3 -0
  38. package/dist/commands/tail.d.ts.map +1 -0
  39. package/dist/commands/tail.js +33 -0
  40. package/dist/commands/wc.d.ts +3 -0
  41. package/dist/commands/wc.d.ts.map +1 -0
  42. package/dist/commands/wc.js +48 -0
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/package.json +5 -2
  46. package/scripts/publish-package.sh +70 -0
  47. package/src/SSHMimic/index.ts +143 -28
  48. package/src/VirtualFileSystem/index.ts +500 -280
  49. package/src/VirtualShell/index.ts +4 -6
  50. package/src/VirtualUserManager/index.ts +41 -0
  51. package/src/commands/chmod.ts +33 -0
  52. package/src/commands/cp.ts +76 -0
  53. package/src/commands/find.ts +61 -0
  54. package/src/commands/grep.ts +54 -38
  55. package/src/commands/head.ts +35 -0
  56. package/src/commands/index.ts +25 -43
  57. package/src/commands/ln.ts +47 -0
  58. package/src/commands/mv.ts +43 -0
  59. package/src/commands/tail.ts +37 -0
  60. package/src/commands/wc.ts +48 -0
  61. package/src/index.ts +1 -0
  62. package/standalone.js +62 -52
  63. package/standalone.js.map +4 -4
  64. package/tests/bun-test-shim.ts +1 -0
  65. package/tests/sftp.test.ts +115 -191
  66. package/tests/users.test.ts +66 -83
@@ -0,0 +1,37 @@
1
+ import type { ShellModule } from "../types/commands";
2
+ import { getFlag } from "./command-helpers";
3
+ import { assertPathAccess, resolvePath } from "./helpers";
4
+
5
+ export const tailCommand: ShellModule = {
6
+ name: "tail",
7
+ params: ["[-n <lines>] [file...]"],
8
+ run: ({ authUser, shell, cwd, args, stdin }) => {
9
+ const nArg = getFlag(args, ["-n"]);
10
+ const n = typeof nArg === "string" ? parseInt(nArg, 10) : 10;
11
+ const positionals = args.filter((a) => !a.startsWith("-") && a !== nArg);
12
+
13
+ const take = (content: string) => {
14
+ const lines = content.split("\n");
15
+ return lines.slice(Math.max(0, lines.length - n)).join("\n");
16
+ };
17
+
18
+ if (positionals.length === 0) {
19
+ return { stdout: take(stdin ?? ""), exitCode: 0 };
20
+ }
21
+
22
+ const results: string[] = [];
23
+ for (const file of positionals) {
24
+ const filePath = resolvePath(cwd, file);
25
+ try {
26
+ assertPathAccess(authUser, filePath, "tail");
27
+ results.push(take(shell.vfs.readFile(filePath)));
28
+ } catch {
29
+ return {
30
+ stderr: `tail: ${file}: No such file or directory`,
31
+ exitCode: 1,
32
+ };
33
+ }
34
+ }
35
+ return { stdout: results.join("\n"), exitCode: 0 };
36
+ },
37
+ };
@@ -0,0 +1,48 @@
1
+ import type { ShellModule } from "../types/commands";
2
+ import { ifFlag } from "./command-helpers";
3
+ import { assertPathAccess, resolvePath } from "./helpers";
4
+
5
+ export const wcCommand: ShellModule = {
6
+ name: "wc",
7
+ params: ["[-l] [-w] [-c] [file...]"],
8
+ run: ({ authUser, shell, cwd, args, stdin }) => {
9
+ const lines = ifFlag(args, ["-l"]);
10
+ const words = ifFlag(args, ["-w"]);
11
+ const bytes = ifFlag(args, ["-c"]);
12
+ const showAll = !lines && !words && !bytes;
13
+ const positionals = args.filter((a) => !a.startsWith("-"));
14
+
15
+ const count = (content: string, label: string): string => {
16
+ const l = content.split("\n").length - (content.endsWith("\n") ? 1 : 0);
17
+ const w = content.trim().split(/\s+/).filter(Boolean).length;
18
+ const c = Buffer.byteLength(content, "utf8");
19
+ const parts: string[] = [];
20
+ if (showAll || lines) parts.push(String(l).padStart(7));
21
+ if (showAll || words) parts.push(String(w).padStart(7));
22
+ if (showAll || bytes) parts.push(String(c).padStart(7));
23
+ if (label) parts.push(` ${label}`);
24
+ return parts.join("");
25
+ };
26
+
27
+ if (positionals.length === 0) {
28
+ const content = stdin ?? "";
29
+ return { stdout: count(content, ""), exitCode: 0 };
30
+ }
31
+
32
+ const results: string[] = [];
33
+ for (const file of positionals) {
34
+ const filePath = resolvePath(cwd, file);
35
+ try {
36
+ assertPathAccess(authUser, filePath, "wc");
37
+ const content = shell.vfs.readFile(filePath);
38
+ results.push(count(content, file));
39
+ } catch {
40
+ return {
41
+ stderr: `wc: ${file}: No such file or directory`,
42
+ exitCode: 1,
43
+ };
44
+ }
45
+ }
46
+ return { stdout: results.join("\n"), exitCode: 0 };
47
+ },
48
+ };
package/src/index.ts CHANGED
@@ -33,6 +33,7 @@ export type {
33
33
  VfsSnapshotNode,
34
34
  WriteFileOptions,
35
35
  } from "./types/vfs";
36
+ export type { VfsOptions, VfsPersistenceMode } from "./VirtualFileSystem/index";
36
37
 
37
38
  export {
38
39
  HoneyPot,