@run0/jiki 0.1.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 (152) hide show
  1. package/dist/browser-bundle.d.ts +40 -0
  2. package/dist/builtins.d.ts +22 -0
  3. package/dist/code-transform.d.ts +7 -0
  4. package/dist/config/cdn.d.ts +13 -0
  5. package/dist/container.d.ts +101 -0
  6. package/dist/dev-server.d.ts +69 -0
  7. package/dist/errors.d.ts +19 -0
  8. package/dist/frameworks/code-transforms.d.ts +32 -0
  9. package/dist/frameworks/next-api-handler.d.ts +72 -0
  10. package/dist/frameworks/next-dev-server.d.ts +141 -0
  11. package/dist/frameworks/next-html-generator.d.ts +36 -0
  12. package/dist/frameworks/next-route-resolver.d.ts +19 -0
  13. package/dist/frameworks/next-shims.d.ts +78 -0
  14. package/dist/frameworks/remix-dev-server.d.ts +47 -0
  15. package/dist/frameworks/sveltekit-dev-server.d.ts +43 -0
  16. package/dist/frameworks/vite-dev-server.d.ts +50 -0
  17. package/dist/fs-errors.d.ts +36 -0
  18. package/dist/index.cjs +14916 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +61 -0
  21. package/dist/index.mjs +14898 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/kernel.d.ts +48 -0
  24. package/dist/memfs.d.ts +144 -0
  25. package/dist/metrics.d.ts +78 -0
  26. package/dist/module-resolver.d.ts +60 -0
  27. package/dist/network-interceptor.d.ts +71 -0
  28. package/dist/npm/cache.d.ts +76 -0
  29. package/dist/npm/index.d.ts +60 -0
  30. package/dist/npm/lockfile-reader.d.ts +32 -0
  31. package/dist/npm/pnpm.d.ts +18 -0
  32. package/dist/npm/registry.d.ts +45 -0
  33. package/dist/npm/resolver.d.ts +39 -0
  34. package/dist/npm/sync-installer.d.ts +18 -0
  35. package/dist/npm/tarball.d.ts +4 -0
  36. package/dist/npm/workspaces.d.ts +46 -0
  37. package/dist/persistence.d.ts +94 -0
  38. package/dist/plugin.d.ts +156 -0
  39. package/dist/polyfills/assert.d.ts +30 -0
  40. package/dist/polyfills/child_process.d.ts +116 -0
  41. package/dist/polyfills/chokidar.d.ts +18 -0
  42. package/dist/polyfills/crypto.d.ts +49 -0
  43. package/dist/polyfills/events.d.ts +28 -0
  44. package/dist/polyfills/fs.d.ts +82 -0
  45. package/dist/polyfills/http.d.ts +147 -0
  46. package/dist/polyfills/module.d.ts +29 -0
  47. package/dist/polyfills/net.d.ts +53 -0
  48. package/dist/polyfills/os.d.ts +91 -0
  49. package/dist/polyfills/path.d.ts +96 -0
  50. package/dist/polyfills/perf_hooks.d.ts +21 -0
  51. package/dist/polyfills/process.d.ts +99 -0
  52. package/dist/polyfills/querystring.d.ts +15 -0
  53. package/dist/polyfills/readdirp.d.ts +18 -0
  54. package/dist/polyfills/readline.d.ts +32 -0
  55. package/dist/polyfills/stream.d.ts +106 -0
  56. package/dist/polyfills/stubs.d.ts +737 -0
  57. package/dist/polyfills/tty.d.ts +25 -0
  58. package/dist/polyfills/url.d.ts +41 -0
  59. package/dist/polyfills/util.d.ts +61 -0
  60. package/dist/polyfills/v8.d.ts +43 -0
  61. package/dist/polyfills/vm.d.ts +76 -0
  62. package/dist/polyfills/worker-threads.d.ts +77 -0
  63. package/dist/polyfills/ws.d.ts +32 -0
  64. package/dist/polyfills/zlib.d.ts +87 -0
  65. package/dist/runtime-helpers.d.ts +4 -0
  66. package/dist/runtime-interface.d.ts +39 -0
  67. package/dist/sandbox.d.ts +69 -0
  68. package/dist/server-bridge.d.ts +55 -0
  69. package/dist/shell-commands.d.ts +2 -0
  70. package/dist/shell.d.ts +101 -0
  71. package/dist/transpiler.d.ts +47 -0
  72. package/dist/type-checker.d.ts +57 -0
  73. package/dist/types/package-json.d.ts +17 -0
  74. package/dist/utils/binary-encoding.d.ts +4 -0
  75. package/dist/utils/hash.d.ts +6 -0
  76. package/dist/utils/safe-path.d.ts +6 -0
  77. package/dist/worker-runtime.d.ts +34 -0
  78. package/package.json +59 -0
  79. package/src/browser-bundle.ts +498 -0
  80. package/src/builtins.ts +222 -0
  81. package/src/code-transform.ts +183 -0
  82. package/src/config/cdn.ts +17 -0
  83. package/src/container.ts +343 -0
  84. package/src/dev-server.ts +322 -0
  85. package/src/errors.ts +604 -0
  86. package/src/frameworks/code-transforms.ts +667 -0
  87. package/src/frameworks/next-api-handler.ts +366 -0
  88. package/src/frameworks/next-dev-server.ts +1252 -0
  89. package/src/frameworks/next-html-generator.ts +585 -0
  90. package/src/frameworks/next-route-resolver.ts +521 -0
  91. package/src/frameworks/next-shims.ts +1084 -0
  92. package/src/frameworks/remix-dev-server.ts +163 -0
  93. package/src/frameworks/sveltekit-dev-server.ts +197 -0
  94. package/src/frameworks/vite-dev-server.ts +370 -0
  95. package/src/fs-errors.ts +118 -0
  96. package/src/index.ts +188 -0
  97. package/src/kernel.ts +381 -0
  98. package/src/memfs.ts +1006 -0
  99. package/src/metrics.ts +140 -0
  100. package/src/module-resolver.ts +511 -0
  101. package/src/network-interceptor.ts +143 -0
  102. package/src/npm/cache.ts +172 -0
  103. package/src/npm/index.ts +377 -0
  104. package/src/npm/lockfile-reader.ts +105 -0
  105. package/src/npm/pnpm.ts +108 -0
  106. package/src/npm/registry.ts +120 -0
  107. package/src/npm/resolver.ts +339 -0
  108. package/src/npm/sync-installer.ts +217 -0
  109. package/src/npm/tarball.ts +136 -0
  110. package/src/npm/workspaces.ts +255 -0
  111. package/src/persistence.ts +235 -0
  112. package/src/plugin.ts +293 -0
  113. package/src/polyfills/assert.ts +164 -0
  114. package/src/polyfills/child_process.ts +535 -0
  115. package/src/polyfills/chokidar.ts +52 -0
  116. package/src/polyfills/crypto.ts +433 -0
  117. package/src/polyfills/events.ts +178 -0
  118. package/src/polyfills/fs.ts +297 -0
  119. package/src/polyfills/http.ts +478 -0
  120. package/src/polyfills/module.ts +97 -0
  121. package/src/polyfills/net.ts +123 -0
  122. package/src/polyfills/os.ts +108 -0
  123. package/src/polyfills/path.ts +169 -0
  124. package/src/polyfills/perf_hooks.ts +30 -0
  125. package/src/polyfills/process.ts +349 -0
  126. package/src/polyfills/querystring.ts +66 -0
  127. package/src/polyfills/readdirp.ts +72 -0
  128. package/src/polyfills/readline.ts +80 -0
  129. package/src/polyfills/stream.ts +610 -0
  130. package/src/polyfills/stubs.ts +600 -0
  131. package/src/polyfills/tty.ts +43 -0
  132. package/src/polyfills/url.ts +97 -0
  133. package/src/polyfills/util.ts +173 -0
  134. package/src/polyfills/v8.ts +62 -0
  135. package/src/polyfills/vm.ts +111 -0
  136. package/src/polyfills/worker-threads.ts +189 -0
  137. package/src/polyfills/ws.ts +73 -0
  138. package/src/polyfills/zlib.ts +244 -0
  139. package/src/runtime-helpers.ts +83 -0
  140. package/src/runtime-interface.ts +46 -0
  141. package/src/sandbox.ts +178 -0
  142. package/src/server-bridge.ts +473 -0
  143. package/src/service-worker.ts +153 -0
  144. package/src/shell-commands.ts +708 -0
  145. package/src/shell.ts +795 -0
  146. package/src/transpiler.ts +282 -0
  147. package/src/type-checker.ts +241 -0
  148. package/src/types/package-json.ts +17 -0
  149. package/src/utils/binary-encoding.ts +38 -0
  150. package/src/utils/hash.ts +24 -0
  151. package/src/utils/safe-path.ts +38 -0
  152. package/src/worker-runtime.ts +42 -0
@@ -0,0 +1,297 @@
1
+ import type { MemFS, Stats } from "../memfs";
2
+ import * as pathShim from "./path";
3
+ import { BufferImpl } from "./stream";
4
+
5
+ export interface FsShim {
6
+ readFileSync: (
7
+ path: string,
8
+ encoding?: string | { encoding?: string },
9
+ ) => string | Uint8Array;
10
+ writeFileSync: (path: string, data: string | Uint8Array) => void;
11
+ existsSync: (path: string) => boolean;
12
+ mkdirSync: (path: string, options?: { recursive?: boolean }) => void;
13
+ readdirSync: (path: string, options?: { withFileTypes?: boolean }) => unknown;
14
+ statSync: (path: string) => Stats;
15
+ lstatSync: (path: string) => Stats;
16
+ unlinkSync: (path: string) => void;
17
+ rmdirSync: (path: string, options?: { recursive?: boolean }) => void;
18
+ rmSync: (
19
+ path: string,
20
+ options?: { recursive?: boolean; force?: boolean },
21
+ ) => void;
22
+ renameSync: (old: string, n: string) => void;
23
+ copyFileSync: (src: string, dest: string) => void;
24
+ accessSync: (path: string, mode?: number) => void;
25
+ realpathSync: (path: string) => string;
26
+ symlinkSync: (target: string, linkPath: string) => void;
27
+ readlinkSync: (path: string) => string;
28
+ chmodSync: (path: string, mode: number) => void;
29
+ chownSync: (path: string, uid: number, gid: number) => void;
30
+ lchmodSync: (path: string, mode: number) => void;
31
+ lchownSync: (path: string, uid: number, gid: number) => void;
32
+ openSync: (path: string, flags?: string | number) => number;
33
+ closeSync: (fd: number) => void;
34
+ readSync: (
35
+ fd: number,
36
+ buffer: Uint8Array,
37
+ offset: number,
38
+ length: number,
39
+ position: number | null,
40
+ ) => number;
41
+ writeSync: (
42
+ fd: number,
43
+ buffer: Uint8Array,
44
+ offset: number,
45
+ length: number,
46
+ position: number | null,
47
+ ) => number;
48
+ fstatSync: (fd: number) => Stats;
49
+ watch: MemFS["watch"];
50
+ createReadStream: MemFS["createReadStream"];
51
+ createWriteStream: MemFS["createWriteStream"];
52
+ readFile: MemFS["readFile"];
53
+ stat: MemFS["stat"];
54
+ lstat: MemFS["lstat"];
55
+ readdir: MemFS["readdir"];
56
+ realpath: MemFS["realpath"];
57
+ access: MemFS["access"];
58
+ promises: {
59
+ readFile: (
60
+ path: string,
61
+ encoding?: string | { encoding?: string },
62
+ ) => Promise<string | Uint8Array>;
63
+ writeFile: (path: string, data: string | Uint8Array) => Promise<void>;
64
+ mkdir: (path: string, options?: { recursive?: boolean }) => Promise<void>;
65
+ readdir: (
66
+ path: string,
67
+ options?: { withFileTypes?: boolean },
68
+ ) => Promise<unknown>;
69
+ stat: (path: string) => Promise<Stats>;
70
+ lstat: (path: string) => Promise<Stats>;
71
+ unlink: (path: string) => Promise<void>;
72
+ rmdir: (path: string, options?: { recursive?: boolean }) => Promise<void>;
73
+ rm: (
74
+ path: string,
75
+ options?: { recursive?: boolean; force?: boolean },
76
+ ) => Promise<void>;
77
+ rename: (old: string, n: string) => Promise<void>;
78
+ access: (path: string, mode?: number) => Promise<void>;
79
+ realpath: (path: string) => Promise<string>;
80
+ copyFile: (src: string, dest: string) => Promise<void>;
81
+ symlink: (target: string, linkPath: string) => Promise<void>;
82
+ readlink: (path: string) => Promise<string>;
83
+ chmod: (path: string, mode: number) => Promise<void>;
84
+ chown: (path: string, uid: number, gid: number) => Promise<void>;
85
+ lchmod: (path: string, mode: number) => Promise<void>;
86
+ lchown: (path: string, uid: number, gid: number) => Promise<void>;
87
+ };
88
+ constants: Record<string, number>;
89
+ }
90
+
91
+ export function createFsShim(vfs: MemFS, getCwd: () => string): FsShim {
92
+ const resolvePath = (p: string): string => {
93
+ if (typeof p !== "string") p = String(p);
94
+ if (p.startsWith("file://")) p = p.replace(/^file:\/\//, "");
95
+ return pathShim.isAbsolute(p) ? p : pathShim.resolve(getCwd(), p);
96
+ };
97
+
98
+ const parseEncoding = (
99
+ enc?: string | { encoding?: string },
100
+ ): string | undefined => {
101
+ if (typeof enc === "string") return enc;
102
+ if (enc && typeof enc === "object") return enc.encoding;
103
+ return undefined;
104
+ };
105
+
106
+ const shim: FsShim = {
107
+ readFileSync(path, encoding?) {
108
+ const enc = parseEncoding(encoding);
109
+ if (enc) return vfs.readFileSync(resolvePath(path), enc as "utf8");
110
+ const raw = vfs.readFileSync(resolvePath(path));
111
+ return raw instanceof Uint8Array ? BufferImpl.from(raw) : raw;
112
+ },
113
+ writeFileSync(path, data) {
114
+ vfs.writeFileSync(resolvePath(path), data);
115
+ },
116
+ existsSync(path) {
117
+ return vfs.existsSync(resolvePath(path));
118
+ },
119
+ mkdirSync(path, opts?) {
120
+ vfs.mkdirSync(resolvePath(path), opts);
121
+ },
122
+ readdirSync(path, opts?) {
123
+ if (opts?.withFileTypes)
124
+ return vfs.readdirSync(resolvePath(path), { withFileTypes: true });
125
+ return vfs.readdirSync(resolvePath(path));
126
+ },
127
+ statSync(path) {
128
+ return vfs.statSync(resolvePath(path));
129
+ },
130
+ lstatSync(path) {
131
+ return vfs.lstatSync(resolvePath(path));
132
+ },
133
+ unlinkSync(path) {
134
+ vfs.unlinkSync(resolvePath(path));
135
+ },
136
+ rmdirSync(path, opts?) {
137
+ vfs.rmdirSync(resolvePath(path), opts);
138
+ },
139
+ rmSync(path, opts?) {
140
+ vfs.rmSync(resolvePath(path), opts);
141
+ },
142
+ renameSync(old, n) {
143
+ vfs.renameSync(resolvePath(old), resolvePath(n));
144
+ },
145
+ copyFileSync(src, dest) {
146
+ vfs.copyFileSync(resolvePath(src), resolvePath(dest));
147
+ },
148
+ accessSync(path, mode?) {
149
+ vfs.accessSync(resolvePath(path), mode);
150
+ },
151
+ realpathSync: Object.assign(
152
+ (path: string) => vfs.realpathSync(resolvePath(path)),
153
+ { native: (path: string) => vfs.realpathSync(resolvePath(path)) },
154
+ ),
155
+ symlinkSync(target, linkPath) {
156
+ vfs.symlinkSync(target, resolvePath(linkPath));
157
+ },
158
+ readlinkSync(path) {
159
+ return vfs.readlinkSync(resolvePath(path));
160
+ },
161
+ chmodSync(path: string, _mode: number) {
162
+ console.warn(
163
+ `[jiki] fs.chmodSync('${resolvePath(path)}') is a no-op — file permissions not supported in browser runtime`,
164
+ );
165
+ },
166
+ chownSync(path: string, _uid: number, _gid: number) {
167
+ console.warn(
168
+ `[jiki] fs.chownSync('${resolvePath(path)}') is a no-op — file ownership not supported in browser runtime`,
169
+ );
170
+ },
171
+ lchmodSync(path: string, _mode: number) {
172
+ console.warn(
173
+ `[jiki] fs.lchmodSync('${resolvePath(path)}') is a no-op — file permissions not supported in browser runtime`,
174
+ );
175
+ },
176
+ lchownSync(path: string, _uid: number, _gid: number) {
177
+ console.warn(
178
+ `[jiki] fs.lchownSync('${resolvePath(path)}') is a no-op — file ownership not supported in browser runtime`,
179
+ );
180
+ },
181
+ openSync(path, flags?) {
182
+ return vfs.openSync(resolvePath(path), flags);
183
+ },
184
+ closeSync(fd) {
185
+ vfs.closeSync(fd);
186
+ },
187
+ readSync(fd, buffer, offset, length, position) {
188
+ return vfs.readSync(fd, buffer, offset, length, position);
189
+ },
190
+ writeSync(fd, buffer, offset, length, position) {
191
+ return vfs.writeSync(fd, buffer, offset, length, position);
192
+ },
193
+ fstatSync(fd) {
194
+ return vfs.fstatSync(fd);
195
+ },
196
+ watch: vfs.watch.bind(vfs),
197
+ createReadStream: vfs.createReadStream.bind(vfs),
198
+ createWriteStream: vfs.createWriteStream.bind(vfs),
199
+ readFile: vfs.readFile.bind(vfs),
200
+ stat: vfs.stat.bind(vfs),
201
+ lstat: vfs.lstat.bind(vfs),
202
+ readdir: vfs.readdir.bind(vfs),
203
+ realpath: vfs.realpath.bind(vfs),
204
+ access: vfs.access.bind(vfs),
205
+ promises: {
206
+ async readFile(path, encoding?) {
207
+ const enc = parseEncoding(encoding);
208
+ if (enc) return vfs.readFileSync(resolvePath(path), enc as "utf8");
209
+ const raw = vfs.readFileSync(resolvePath(path));
210
+ return raw instanceof Uint8Array ? BufferImpl.from(raw) : raw;
211
+ },
212
+ async writeFile(path, data) {
213
+ vfs.writeFileSync(resolvePath(path), data);
214
+ },
215
+ async mkdir(path, opts?) {
216
+ vfs.mkdirSync(resolvePath(path), opts);
217
+ },
218
+ async readdir(path, opts?) {
219
+ if (opts?.withFileTypes)
220
+ return vfs.readdirSync(resolvePath(path), { withFileTypes: true });
221
+ return vfs.readdirSync(resolvePath(path));
222
+ },
223
+ async stat(path) {
224
+ return vfs.statSync(resolvePath(path));
225
+ },
226
+ async lstat(path) {
227
+ return vfs.lstatSync(resolvePath(path));
228
+ },
229
+ async unlink(path) {
230
+ vfs.unlinkSync(resolvePath(path));
231
+ },
232
+ async rmdir(path, opts?) {
233
+ vfs.rmdirSync(resolvePath(path), opts);
234
+ },
235
+ async rm(path, opts?) {
236
+ vfs.rmSync(resolvePath(path), opts);
237
+ },
238
+ async rename(old, n) {
239
+ vfs.renameSync(resolvePath(old), resolvePath(n));
240
+ },
241
+ async access(path, mode?) {
242
+ vfs.accessSync(resolvePath(path), mode);
243
+ },
244
+ async realpath(path) {
245
+ return vfs.realpathSync(resolvePath(path));
246
+ },
247
+ async copyFile(src, dest) {
248
+ vfs.copyFileSync(resolvePath(src), resolvePath(dest));
249
+ },
250
+ async symlink(target, linkPath) {
251
+ vfs.symlinkSync(target, resolvePath(linkPath));
252
+ },
253
+ async readlink(path) {
254
+ return vfs.readlinkSync(resolvePath(path));
255
+ },
256
+ async chmod(path: string, _mode: number) {
257
+ console.warn(
258
+ `[jiki] fs.promises.chmod('${resolvePath(path)}') is a no-op — file permissions not supported in browser runtime`,
259
+ );
260
+ },
261
+ async chown(path: string, _uid: number, _gid: number) {
262
+ console.warn(
263
+ `[jiki] fs.promises.chown('${resolvePath(path)}') is a no-op — file ownership not supported in browser runtime`,
264
+ );
265
+ },
266
+ async lchmod(path: string, _mode: number) {
267
+ console.warn(
268
+ `[jiki] fs.promises.lchmod('${resolvePath(path)}') is a no-op — file permissions not supported in browser runtime`,
269
+ );
270
+ },
271
+ async lchown(path: string, _uid: number, _gid: number) {
272
+ console.warn(
273
+ `[jiki] fs.promises.lchown('${resolvePath(path)}') is a no-op — file ownership not supported in browser runtime`,
274
+ );
275
+ },
276
+ },
277
+ constants: {
278
+ F_OK: 0,
279
+ R_OK: 4,
280
+ W_OK: 2,
281
+ X_OK: 1,
282
+ O_RDONLY: 0,
283
+ O_WRONLY: 1,
284
+ O_RDWR: 2,
285
+ O_CREAT: 64,
286
+ O_EXCL: 128,
287
+ O_TRUNC: 512,
288
+ O_APPEND: 1024,
289
+ S_IFMT: 61440,
290
+ S_IFREG: 32768,
291
+ S_IFDIR: 16384,
292
+ S_IFLNK: 40960,
293
+ },
294
+ };
295
+
296
+ return shim;
297
+ }