@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.
- package/dist/browser-bundle.d.ts +40 -0
- package/dist/builtins.d.ts +22 -0
- package/dist/code-transform.d.ts +7 -0
- package/dist/config/cdn.d.ts +13 -0
- package/dist/container.d.ts +101 -0
- package/dist/dev-server.d.ts +69 -0
- package/dist/errors.d.ts +19 -0
- package/dist/frameworks/code-transforms.d.ts +32 -0
- package/dist/frameworks/next-api-handler.d.ts +72 -0
- package/dist/frameworks/next-dev-server.d.ts +141 -0
- package/dist/frameworks/next-html-generator.d.ts +36 -0
- package/dist/frameworks/next-route-resolver.d.ts +19 -0
- package/dist/frameworks/next-shims.d.ts +78 -0
- package/dist/frameworks/remix-dev-server.d.ts +47 -0
- package/dist/frameworks/sveltekit-dev-server.d.ts +43 -0
- package/dist/frameworks/vite-dev-server.d.ts +50 -0
- package/dist/fs-errors.d.ts +36 -0
- package/dist/index.cjs +14916 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.mjs +14898 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kernel.d.ts +48 -0
- package/dist/memfs.d.ts +144 -0
- package/dist/metrics.d.ts +78 -0
- package/dist/module-resolver.d.ts +60 -0
- package/dist/network-interceptor.d.ts +71 -0
- package/dist/npm/cache.d.ts +76 -0
- package/dist/npm/index.d.ts +60 -0
- package/dist/npm/lockfile-reader.d.ts +32 -0
- package/dist/npm/pnpm.d.ts +18 -0
- package/dist/npm/registry.d.ts +45 -0
- package/dist/npm/resolver.d.ts +39 -0
- package/dist/npm/sync-installer.d.ts +18 -0
- package/dist/npm/tarball.d.ts +4 -0
- package/dist/npm/workspaces.d.ts +46 -0
- package/dist/persistence.d.ts +94 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/polyfills/assert.d.ts +30 -0
- package/dist/polyfills/child_process.d.ts +116 -0
- package/dist/polyfills/chokidar.d.ts +18 -0
- package/dist/polyfills/crypto.d.ts +49 -0
- package/dist/polyfills/events.d.ts +28 -0
- package/dist/polyfills/fs.d.ts +82 -0
- package/dist/polyfills/http.d.ts +147 -0
- package/dist/polyfills/module.d.ts +29 -0
- package/dist/polyfills/net.d.ts +53 -0
- package/dist/polyfills/os.d.ts +91 -0
- package/dist/polyfills/path.d.ts +96 -0
- package/dist/polyfills/perf_hooks.d.ts +21 -0
- package/dist/polyfills/process.d.ts +99 -0
- package/dist/polyfills/querystring.d.ts +15 -0
- package/dist/polyfills/readdirp.d.ts +18 -0
- package/dist/polyfills/readline.d.ts +32 -0
- package/dist/polyfills/stream.d.ts +106 -0
- package/dist/polyfills/stubs.d.ts +737 -0
- package/dist/polyfills/tty.d.ts +25 -0
- package/dist/polyfills/url.d.ts +41 -0
- package/dist/polyfills/util.d.ts +61 -0
- package/dist/polyfills/v8.d.ts +43 -0
- package/dist/polyfills/vm.d.ts +76 -0
- package/dist/polyfills/worker-threads.d.ts +77 -0
- package/dist/polyfills/ws.d.ts +32 -0
- package/dist/polyfills/zlib.d.ts +87 -0
- package/dist/runtime-helpers.d.ts +4 -0
- package/dist/runtime-interface.d.ts +39 -0
- package/dist/sandbox.d.ts +69 -0
- package/dist/server-bridge.d.ts +55 -0
- package/dist/shell-commands.d.ts +2 -0
- package/dist/shell.d.ts +101 -0
- package/dist/transpiler.d.ts +47 -0
- package/dist/type-checker.d.ts +57 -0
- package/dist/types/package-json.d.ts +17 -0
- package/dist/utils/binary-encoding.d.ts +4 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/safe-path.d.ts +6 -0
- package/dist/worker-runtime.d.ts +34 -0
- package/package.json +59 -0
- package/src/browser-bundle.ts +498 -0
- package/src/builtins.ts +222 -0
- package/src/code-transform.ts +183 -0
- package/src/config/cdn.ts +17 -0
- package/src/container.ts +343 -0
- package/src/dev-server.ts +322 -0
- package/src/errors.ts +604 -0
- package/src/frameworks/code-transforms.ts +667 -0
- package/src/frameworks/next-api-handler.ts +366 -0
- package/src/frameworks/next-dev-server.ts +1252 -0
- package/src/frameworks/next-html-generator.ts +585 -0
- package/src/frameworks/next-route-resolver.ts +521 -0
- package/src/frameworks/next-shims.ts +1084 -0
- package/src/frameworks/remix-dev-server.ts +163 -0
- package/src/frameworks/sveltekit-dev-server.ts +197 -0
- package/src/frameworks/vite-dev-server.ts +370 -0
- package/src/fs-errors.ts +118 -0
- package/src/index.ts +188 -0
- package/src/kernel.ts +381 -0
- package/src/memfs.ts +1006 -0
- package/src/metrics.ts +140 -0
- package/src/module-resolver.ts +511 -0
- package/src/network-interceptor.ts +143 -0
- package/src/npm/cache.ts +172 -0
- package/src/npm/index.ts +377 -0
- package/src/npm/lockfile-reader.ts +105 -0
- package/src/npm/pnpm.ts +108 -0
- package/src/npm/registry.ts +120 -0
- package/src/npm/resolver.ts +339 -0
- package/src/npm/sync-installer.ts +217 -0
- package/src/npm/tarball.ts +136 -0
- package/src/npm/workspaces.ts +255 -0
- package/src/persistence.ts +235 -0
- package/src/plugin.ts +293 -0
- package/src/polyfills/assert.ts +164 -0
- package/src/polyfills/child_process.ts +535 -0
- package/src/polyfills/chokidar.ts +52 -0
- package/src/polyfills/crypto.ts +433 -0
- package/src/polyfills/events.ts +178 -0
- package/src/polyfills/fs.ts +297 -0
- package/src/polyfills/http.ts +478 -0
- package/src/polyfills/module.ts +97 -0
- package/src/polyfills/net.ts +123 -0
- package/src/polyfills/os.ts +108 -0
- package/src/polyfills/path.ts +169 -0
- package/src/polyfills/perf_hooks.ts +30 -0
- package/src/polyfills/process.ts +349 -0
- package/src/polyfills/querystring.ts +66 -0
- package/src/polyfills/readdirp.ts +72 -0
- package/src/polyfills/readline.ts +80 -0
- package/src/polyfills/stream.ts +610 -0
- package/src/polyfills/stubs.ts +600 -0
- package/src/polyfills/tty.ts +43 -0
- package/src/polyfills/url.ts +97 -0
- package/src/polyfills/util.ts +173 -0
- package/src/polyfills/v8.ts +62 -0
- package/src/polyfills/vm.ts +111 -0
- package/src/polyfills/worker-threads.ts +189 -0
- package/src/polyfills/ws.ts +73 -0
- package/src/polyfills/zlib.ts +244 -0
- package/src/runtime-helpers.ts +83 -0
- package/src/runtime-interface.ts +46 -0
- package/src/sandbox.ts +178 -0
- package/src/server-bridge.ts +473 -0
- package/src/service-worker.ts +153 -0
- package/src/shell-commands.ts +708 -0
- package/src/shell.ts +795 -0
- package/src/transpiler.ts +282 -0
- package/src/type-checker.ts +241 -0
- package/src/types/package-json.ts +17 -0
- package/src/utils/binary-encoding.ts +38 -0
- package/src/utils/hash.ts +24 -0
- package/src/utils/safe-path.ts +38 -0
- package/src/worker-runtime.ts +42 -0
package/dist/kernel.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MemFS } from "./memfs";
|
|
2
|
+
import type { IExecuteResult } from "./runtime-interface";
|
|
3
|
+
import { FsShim } from "./polyfills/fs";
|
|
4
|
+
import { Process } from "./polyfills/process";
|
|
5
|
+
import { type InitOptions } from "./transpiler";
|
|
6
|
+
import { transformEsmToCjs } from "./code-transform";
|
|
7
|
+
import { type Module, type RuntimeOptions, type RequireFunction } from "./module-resolver";
|
|
8
|
+
import { builtinModules } from "./builtins";
|
|
9
|
+
import type { PluginRegistry } from "./plugin";
|
|
10
|
+
export type { Module, RuntimeOptions, RequireFunction };
|
|
11
|
+
declare function createRequire(vfs: MemFS, fsShim: FsShim, process: Process, currentDir: string, moduleCache: Record<string, Module>, options: RuntimeOptions, processedCodeCache?: Map<string, string>, pluginRegistry?: PluginRegistry): RequireFunction;
|
|
12
|
+
export declare class Kernel {
|
|
13
|
+
vfs: MemFS;
|
|
14
|
+
fsShim: FsShim;
|
|
15
|
+
process: Process;
|
|
16
|
+
moduleCache: Record<string, Module>;
|
|
17
|
+
processedCodeCache: Map<string, string>;
|
|
18
|
+
private options;
|
|
19
|
+
private maxCacheSize;
|
|
20
|
+
private cacheAccessTime;
|
|
21
|
+
private resolver;
|
|
22
|
+
/** Plugin registry for this kernel (shared with child kernels). */
|
|
23
|
+
readonly pluginRegistry?: PluginRegistry;
|
|
24
|
+
constructor(vfs: MemFS, options?: RuntimeOptions, pluginRegistry?: PluginRegistry);
|
|
25
|
+
init(options?: InitOptions): Promise<void>;
|
|
26
|
+
prepareFile(filename: string): Promise<void>;
|
|
27
|
+
private walkImports;
|
|
28
|
+
private patchGlobals;
|
|
29
|
+
execute(code: string, filename?: string): IExecuteResult;
|
|
30
|
+
executeSync(code: string, filename?: string): IExecuteResult;
|
|
31
|
+
executeAsync(code: string, filename?: string): Promise<IExecuteResult>;
|
|
32
|
+
runFile(filename: string): IExecuteResult;
|
|
33
|
+
runFileSync(filename: string): IExecuteResult;
|
|
34
|
+
runFileAsync(filename: string): Promise<IExecuteResult>;
|
|
35
|
+
clearCache(): void;
|
|
36
|
+
invalidateModule(path: string): void;
|
|
37
|
+
invalidateModulesMatching(predicate: (path: string) => boolean): void;
|
|
38
|
+
getVFS(): MemFS;
|
|
39
|
+
getProcess(): Process;
|
|
40
|
+
private trimCacheIfOversized;
|
|
41
|
+
/** Record access time for a module cache entry */
|
|
42
|
+
touchCacheEntry(key: string): void;
|
|
43
|
+
createREPL(): {
|
|
44
|
+
eval: (code: string) => unknown;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { transformEsmToCjs, createRequire, builtinModules };
|
|
48
|
+
export { Kernel as Runtime };
|
package/dist/memfs.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { VFSSnapshot } from "./runtime-interface";
|
|
2
|
+
import { createNodeError, type NodeError, type Stats } from "./fs-errors";
|
|
3
|
+
import { type PersistenceAdapter } from "./persistence";
|
|
4
|
+
import type { SandboxGuard } from "./sandbox";
|
|
5
|
+
export { createNodeError, type NodeError, type Stats };
|
|
6
|
+
export interface FSNode {
|
|
7
|
+
type: "file" | "directory" | "symlink";
|
|
8
|
+
content?: Uint8Array;
|
|
9
|
+
children?: Map<string, FSNode>;
|
|
10
|
+
target?: string;
|
|
11
|
+
mtime: number;
|
|
12
|
+
ino: number;
|
|
13
|
+
}
|
|
14
|
+
type ChangeListener = (path: string, content: string) => void;
|
|
15
|
+
type DeleteListener = (path: string) => void;
|
|
16
|
+
export type WatchEventType = "change" | "rename";
|
|
17
|
+
export type WatchListener = (eventType: WatchEventType, filename: string | null) => void;
|
|
18
|
+
export interface FSWatcher {
|
|
19
|
+
close(): void;
|
|
20
|
+
ref(): this;
|
|
21
|
+
unref(): this;
|
|
22
|
+
}
|
|
23
|
+
/** Options for MemFS construction. */
|
|
24
|
+
export interface MemFSOptions {
|
|
25
|
+
/** Optional persistence adapter. When provided, filesystem mutations are
|
|
26
|
+
* automatically persisted to the backend. */
|
|
27
|
+
persistence?: PersistenceAdapter;
|
|
28
|
+
/** Optional sandbox guard. When provided, all write operations are
|
|
29
|
+
* checked against resource limits and path restrictions. */
|
|
30
|
+
sandbox?: SandboxGuard;
|
|
31
|
+
}
|
|
32
|
+
export declare class MemFS {
|
|
33
|
+
private root;
|
|
34
|
+
private enc;
|
|
35
|
+
private dec;
|
|
36
|
+
private watchers;
|
|
37
|
+
private eventSubs;
|
|
38
|
+
private nodeIndex;
|
|
39
|
+
private symlinkLimit;
|
|
40
|
+
private fdCounter;
|
|
41
|
+
private fdMap;
|
|
42
|
+
/** Persistence adapter (if configured). */
|
|
43
|
+
private persistence?;
|
|
44
|
+
/** Sandbox guard (if configured). */
|
|
45
|
+
private sandboxGuard?;
|
|
46
|
+
constructor(options?: MemFSOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Rehydrate the VFS from the persistence adapter.
|
|
49
|
+
* Call this once during initialisation (e.g. in `Container.init()`) to
|
|
50
|
+
* restore previously persisted state.
|
|
51
|
+
*/
|
|
52
|
+
hydrate(): Promise<number>;
|
|
53
|
+
/**
|
|
54
|
+
* Flush any pending persistence writes immediately.
|
|
55
|
+
* Useful before page unload or when you need to guarantee data is saved.
|
|
56
|
+
*/
|
|
57
|
+
flushPersistence(): Promise<void>;
|
|
58
|
+
/** Queue a node for persistence (fire-and-forget). */
|
|
59
|
+
private persist;
|
|
60
|
+
/** Queue a path deletion for persistence (fire-and-forget). */
|
|
61
|
+
private unpersist;
|
|
62
|
+
/** Queue deletion of a path and all its descendants. */
|
|
63
|
+
private unpersistTree;
|
|
64
|
+
on(event: "change", listener: ChangeListener): this;
|
|
65
|
+
on(event: "delete", listener: DeleteListener): this;
|
|
66
|
+
off(event: "change", listener: ChangeListener): this;
|
|
67
|
+
off(event: "delete", listener: DeleteListener): this;
|
|
68
|
+
private fire;
|
|
69
|
+
toSnapshot(): VFSSnapshot;
|
|
70
|
+
static fromSnapshot(snapshot: VFSSnapshot): MemFS;
|
|
71
|
+
export(path: string, _options?: {
|
|
72
|
+
format?: "json";
|
|
73
|
+
}): Record<string, unknown>;
|
|
74
|
+
private treeToJson;
|
|
75
|
+
private lookupDirect;
|
|
76
|
+
private followLinks;
|
|
77
|
+
private ensureDir;
|
|
78
|
+
private dropIndex;
|
|
79
|
+
existsSync(path: string): boolean;
|
|
80
|
+
statSync(path: string): Stats;
|
|
81
|
+
lstatSync(path: string): Stats;
|
|
82
|
+
private toStats;
|
|
83
|
+
readFileSync(path: string): Uint8Array;
|
|
84
|
+
readFileSync(path: string, encoding: "utf8" | "utf-8"): string;
|
|
85
|
+
writeFileSync(path: string, data: string | Uint8Array): void;
|
|
86
|
+
putFile(path: string, data: string | Uint8Array, notify: boolean): void;
|
|
87
|
+
symlinkSync(target: string, linkPath: string): void;
|
|
88
|
+
readlinkSync(path: string): string;
|
|
89
|
+
mkdirSync(path: string, options?: {
|
|
90
|
+
recursive?: boolean;
|
|
91
|
+
}): void;
|
|
92
|
+
readdirSync(path: string): string[];
|
|
93
|
+
readdirSync(path: string, options: {
|
|
94
|
+
withFileTypes: true;
|
|
95
|
+
}): {
|
|
96
|
+
name: string;
|
|
97
|
+
isFile(): boolean;
|
|
98
|
+
isDirectory(): boolean;
|
|
99
|
+
isSymbolicLink(): boolean;
|
|
100
|
+
}[];
|
|
101
|
+
unlinkSync(path: string): void;
|
|
102
|
+
rmdirSync(path: string, options?: {
|
|
103
|
+
recursive?: boolean;
|
|
104
|
+
}): void;
|
|
105
|
+
rmSync(path: string, options?: {
|
|
106
|
+
recursive?: boolean;
|
|
107
|
+
force?: boolean;
|
|
108
|
+
}): void;
|
|
109
|
+
renameSync(oldPath: string, newPath: string): void;
|
|
110
|
+
copyFileSync(src: string, dest: string): void;
|
|
111
|
+
utimesSync(path: string, _atime: number | Date, mtime: number | Date): void;
|
|
112
|
+
accessSync(path: string, _mode?: number): void;
|
|
113
|
+
realpathSync(path: string): string;
|
|
114
|
+
openSync(path: string, flags?: string | number): number;
|
|
115
|
+
closeSync(fd: number): void;
|
|
116
|
+
readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null): number;
|
|
117
|
+
writeSync(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null): number;
|
|
118
|
+
fstatSync(fd: number): Stats;
|
|
119
|
+
readFile(path: string, optionsOrCb?: {
|
|
120
|
+
encoding?: string;
|
|
121
|
+
} | ((err: Error | null, data?: Uint8Array | string) => void), cb?: (err: Error | null, data?: Uint8Array | string) => void): void;
|
|
122
|
+
stat(path: string, cb: (err: Error | null, stats?: Stats) => void): void;
|
|
123
|
+
lstat(path: string, cb: (err: Error | null, stats?: Stats) => void): void;
|
|
124
|
+
readdir(path: string, optionsOrCb?: {
|
|
125
|
+
withFileTypes?: boolean;
|
|
126
|
+
} | ((err: Error | null, files?: string[]) => void), cb?: (err: Error | null, files?: unknown) => void): void;
|
|
127
|
+
realpath(path: string, cb: (err: Error | null, resolved?: string) => void): void;
|
|
128
|
+
access(path: string, modeOrCb?: number | ((err: Error | null) => void), cb?: (err: Error | null) => void): void;
|
|
129
|
+
watch(filename: string, optionsOrListener?: {
|
|
130
|
+
persistent?: boolean;
|
|
131
|
+
recursive?: boolean;
|
|
132
|
+
encoding?: string;
|
|
133
|
+
} | WatchListener, listener?: WatchListener): FSWatcher;
|
|
134
|
+
private signalWatchers;
|
|
135
|
+
createReadStream(path: string): {
|
|
136
|
+
on: (event: string, cb: (...args: unknown[]) => void) => unknown;
|
|
137
|
+
pipe: (dest: unknown) => unknown;
|
|
138
|
+
};
|
|
139
|
+
createWriteStream(path: string): {
|
|
140
|
+
write: (data: string | Uint8Array) => boolean;
|
|
141
|
+
end: (data?: string | Uint8Array) => void;
|
|
142
|
+
on: (event: string, cb: (...args: unknown[]) => void) => unknown;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance metrics for jiki containers.
|
|
3
|
+
*
|
|
4
|
+
* Tracks timing and counts for key operations: module resolution,
|
|
5
|
+
* transpilation, file I/O, cache hits/misses, and package installs.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const container = boot();
|
|
10
|
+
* // ... do work ...
|
|
11
|
+
* const m = container.metrics.snapshot();
|
|
12
|
+
* console.log(`Resolved ${m.resolveCount} modules in ${m.resolveTimeMs}ms`);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface MetricsSnapshot {
|
|
16
|
+
/** Total module resolutions performed. */
|
|
17
|
+
resolveCount: number;
|
|
18
|
+
/** Total time spent in module resolution (ms). */
|
|
19
|
+
resolveTimeMs: number;
|
|
20
|
+
/** Total transpilation calls. */
|
|
21
|
+
transpileCount: number;
|
|
22
|
+
/** Total time spent in transpilation (ms). */
|
|
23
|
+
transpileTimeMs: number;
|
|
24
|
+
/** Total VFS read operations. */
|
|
25
|
+
vfsReadCount: number;
|
|
26
|
+
/** Total VFS write operations. */
|
|
27
|
+
vfsWriteCount: number;
|
|
28
|
+
/** Module cache hits. */
|
|
29
|
+
cacheHits: number;
|
|
30
|
+
/** Module cache misses. */
|
|
31
|
+
cacheMisses: number;
|
|
32
|
+
/** Cache hit rate (0–1). */
|
|
33
|
+
cacheHitRate: number;
|
|
34
|
+
/** Total shell commands executed. */
|
|
35
|
+
commandCount: number;
|
|
36
|
+
/** Total packages installed. */
|
|
37
|
+
installCount: number;
|
|
38
|
+
/** Total time spent installing packages (ms). */
|
|
39
|
+
installTimeMs: number;
|
|
40
|
+
/** Timestamp of when metrics collection started. */
|
|
41
|
+
startedAt: number;
|
|
42
|
+
/** Elapsed time since metrics collection started (ms). */
|
|
43
|
+
uptimeMs: number;
|
|
44
|
+
}
|
|
45
|
+
export declare class Metrics {
|
|
46
|
+
private _resolveCount;
|
|
47
|
+
private _resolveTimeMs;
|
|
48
|
+
private _transpileCount;
|
|
49
|
+
private _transpileTimeMs;
|
|
50
|
+
private _vfsReadCount;
|
|
51
|
+
private _vfsWriteCount;
|
|
52
|
+
private _cacheHits;
|
|
53
|
+
private _cacheMisses;
|
|
54
|
+
private _commandCount;
|
|
55
|
+
private _installCount;
|
|
56
|
+
private _installTimeMs;
|
|
57
|
+
private _startedAt;
|
|
58
|
+
/** Record a module resolution. */
|
|
59
|
+
trackResolve(durationMs: number): void;
|
|
60
|
+
/** Record a transpilation. */
|
|
61
|
+
trackTranspile(durationMs: number): void;
|
|
62
|
+
/** Record a VFS read. */
|
|
63
|
+
trackRead(): void;
|
|
64
|
+
/** Record a VFS write. */
|
|
65
|
+
trackWrite(): void;
|
|
66
|
+
/** Record a cache hit. */
|
|
67
|
+
trackCacheHit(): void;
|
|
68
|
+
/** Record a cache miss. */
|
|
69
|
+
trackCacheMiss(): void;
|
|
70
|
+
/** Record a shell command execution. */
|
|
71
|
+
trackCommand(): void;
|
|
72
|
+
/** Record a package install. */
|
|
73
|
+
trackInstall(durationMs: number): void;
|
|
74
|
+
/** Get a snapshot of all metrics. */
|
|
75
|
+
snapshot(): MetricsSnapshot;
|
|
76
|
+
/** Reset all metrics. */
|
|
77
|
+
reset(): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MemFS } from "./memfs";
|
|
2
|
+
import type { FsShim } from "./polyfills/fs";
|
|
3
|
+
import type { Process } from "./polyfills/process";
|
|
4
|
+
import type { PluginRegistry } from "./plugin";
|
|
5
|
+
export interface Module {
|
|
6
|
+
id: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
exports: unknown;
|
|
9
|
+
loaded: boolean;
|
|
10
|
+
children: Module[];
|
|
11
|
+
paths: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface AutoInstallProvider {
|
|
14
|
+
installSync(name: string): void;
|
|
15
|
+
}
|
|
16
|
+
export interface RuntimeOptions {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
env?: Record<string, string>;
|
|
19
|
+
onConsole?: (method: string, args: unknown[]) => void;
|
|
20
|
+
onStdout?: (data: string) => void;
|
|
21
|
+
onStderr?: (data: string) => void;
|
|
22
|
+
autoInstall?: boolean;
|
|
23
|
+
autoInstallProvider?: AutoInstallProvider;
|
|
24
|
+
/** Enable inline source maps for TypeScript/JSX transpilation. */
|
|
25
|
+
sourceMaps?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface RequireFunction {
|
|
28
|
+
(id: string): unknown;
|
|
29
|
+
resolve: ((id: string) => string) & {
|
|
30
|
+
paths: (id: string) => string[] | null;
|
|
31
|
+
};
|
|
32
|
+
cache: Record<string, Module>;
|
|
33
|
+
}
|
|
34
|
+
export declare class ModuleResolver {
|
|
35
|
+
private vfs;
|
|
36
|
+
private fsShim;
|
|
37
|
+
private proc;
|
|
38
|
+
private opts;
|
|
39
|
+
private cache;
|
|
40
|
+
private transformedCache;
|
|
41
|
+
private debug;
|
|
42
|
+
private pluginRegistry?;
|
|
43
|
+
private pkgJsonMemo;
|
|
44
|
+
private resolveMemo;
|
|
45
|
+
clearMemos(): void;
|
|
46
|
+
/** Invalidate cached resolution entries that match the given file path.
|
|
47
|
+
* This enables per-entry cache invalidation when a file changes on disk. */
|
|
48
|
+
invalidate(path: string): void;
|
|
49
|
+
constructor(vfs: MemFS, fsShim: FsShim, proc: Process, cache: Record<string, Module>, opts: RuntimeOptions, transformedCache: Map<string, string>, pluginRegistry?: PluginRegistry);
|
|
50
|
+
makeRequire(fromDir: string): RequireFunction;
|
|
51
|
+
resolve(id: string, fromDir: string): string;
|
|
52
|
+
load(resolved: string): Module;
|
|
53
|
+
private cacheAndReturn;
|
|
54
|
+
private readPkg;
|
|
55
|
+
probeFile(base: string): string | null;
|
|
56
|
+
private resolvePackageImport;
|
|
57
|
+
private extractPackageName;
|
|
58
|
+
private resolveFromNodeModules;
|
|
59
|
+
private tryPackageEntry;
|
|
60
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network request interception and mocking for jiki containers.
|
|
3
|
+
*
|
|
4
|
+
* Allows intercepting and mocking outgoing `fetch()` calls from executed
|
|
5
|
+
* code. Useful for testing, offline scenarios, and CORS avoidance.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const container = boot();
|
|
10
|
+
* container.mockFetch('/api/users', { json: [{ name: 'Alice' }] });
|
|
11
|
+
* container.execute('fetch("/api/users").then(r => r.json()).then(console.log)');
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface MockResponse {
|
|
15
|
+
/** HTTP status code. Default: 200. */
|
|
16
|
+
status?: number;
|
|
17
|
+
/** Response headers. */
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** Response body as string. */
|
|
20
|
+
body?: string;
|
|
21
|
+
/** Response body as JSON (auto-serialized). Overrides `body`. */
|
|
22
|
+
json?: unknown;
|
|
23
|
+
}
|
|
24
|
+
export type FetchHandler = (url: string, init?: RequestInit) => MockResponse | null | undefined | Promise<MockResponse | null | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Intercepts fetch calls and returns mock responses when a URL matches
|
|
27
|
+
* a registered pattern.
|
|
28
|
+
*/
|
|
29
|
+
export declare class NetworkInterceptor {
|
|
30
|
+
private rules;
|
|
31
|
+
private handlers;
|
|
32
|
+
/**
|
|
33
|
+
* Register a static mock response for a URL pattern.
|
|
34
|
+
*
|
|
35
|
+
* @param pattern - String (exact match or prefix) or RegExp
|
|
36
|
+
* @param response - Mock response to return
|
|
37
|
+
*/
|
|
38
|
+
mock(pattern: string | RegExp, response: MockResponse): void;
|
|
39
|
+
/**
|
|
40
|
+
* Register a dynamic handler that can inspect the request and return
|
|
41
|
+
* a response. Return `null` to pass through to the next handler or
|
|
42
|
+
* the real network.
|
|
43
|
+
*/
|
|
44
|
+
onFetch(handler: FetchHandler): void;
|
|
45
|
+
/**
|
|
46
|
+
* Remove all mock rules and handlers.
|
|
47
|
+
*/
|
|
48
|
+
clear(): void;
|
|
49
|
+
/** Number of registered rules. */
|
|
50
|
+
get ruleCount(): number;
|
|
51
|
+
/** Number of registered handlers. */
|
|
52
|
+
get handlerCount(): number;
|
|
53
|
+
/**
|
|
54
|
+
* Try to match a URL against registered rules and handlers.
|
|
55
|
+
* Returns a Response-like object if matched, or `null` to pass through.
|
|
56
|
+
*/
|
|
57
|
+
intercept(url: string, init?: RequestInit): Promise<MockResponse | null>;
|
|
58
|
+
private matches;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Convert a MockResponse to a format suitable for the `fetch` polyfill.
|
|
62
|
+
*/
|
|
63
|
+
export declare function mockResponseToFetchResponse(mock: MockResponse): {
|
|
64
|
+
ok: boolean;
|
|
65
|
+
status: number;
|
|
66
|
+
statusText: string;
|
|
67
|
+
headers: Record<string, string>;
|
|
68
|
+
text: () => Promise<string>;
|
|
69
|
+
json: () => Promise<unknown>;
|
|
70
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
71
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package cache for npm manifests and tarballs.
|
|
3
|
+
*
|
|
4
|
+
* Provides an in-memory cache with an optional persistent backing store
|
|
5
|
+
* (IndexedDB or any `PersistenceAdapter`-like backend). Manifests have a
|
|
6
|
+
* configurable TTL; tarballs are immutable by URL and cached indefinitely.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const cache = new PackageCache();
|
|
11
|
+
* const registry = new Registry();
|
|
12
|
+
* // Wrap getManifest with cache
|
|
13
|
+
* const manifest = await cache.getManifest('react', () => registry.getManifest('react'));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { PackageManifest } from "./registry";
|
|
17
|
+
export interface PackageCacheOptions {
|
|
18
|
+
/** Manifest TTL in milliseconds. Default: 1 hour. */
|
|
19
|
+
manifestTtlMs?: number;
|
|
20
|
+
/** Maximum number of manifests to keep in memory. Default: 500. */
|
|
21
|
+
maxManifests?: number;
|
|
22
|
+
/** Maximum number of tarballs to keep in memory. Default: 200. */
|
|
23
|
+
maxTarballs?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* In-memory cache for npm package manifests and tarball data.
|
|
27
|
+
*
|
|
28
|
+
* - **Manifests** are keyed by package name with a configurable TTL (default
|
|
29
|
+
* 1 hour). After TTL expiry the manifest is re-fetched on next access.
|
|
30
|
+
* - **Tarballs** are keyed by URL. Since npm tarball URLs are immutable
|
|
31
|
+
* (content-addressed), they are cached indefinitely.
|
|
32
|
+
*/
|
|
33
|
+
export declare class PackageCache {
|
|
34
|
+
private manifests;
|
|
35
|
+
private tarballs;
|
|
36
|
+
private manifestTtlMs;
|
|
37
|
+
private maxManifests;
|
|
38
|
+
private maxTarballs;
|
|
39
|
+
constructor(options?: PackageCacheOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Get a cached manifest, or fetch and cache it.
|
|
42
|
+
*
|
|
43
|
+
* @param name - Package name
|
|
44
|
+
* @param fetcher - Async function that fetches the manifest from the registry
|
|
45
|
+
* @returns The manifest (from cache or freshly fetched)
|
|
46
|
+
*/
|
|
47
|
+
getManifest(name: string, fetcher: () => Promise<PackageManifest>): Promise<PackageManifest>;
|
|
48
|
+
/** Check if a manifest is cached and not expired. */
|
|
49
|
+
hasManifest(name: string): boolean;
|
|
50
|
+
/** Store a manifest in the cache. */
|
|
51
|
+
setManifest(name: string, manifest: PackageManifest): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get a cached tarball, or fetch and cache it.
|
|
54
|
+
*
|
|
55
|
+
* @param url - Tarball URL (immutable by npm convention)
|
|
56
|
+
* @param fetcher - Async function that downloads the tarball
|
|
57
|
+
* @returns The tarball data
|
|
58
|
+
*/
|
|
59
|
+
getTarball(url: string, fetcher: () => Promise<Uint8Array>): Promise<Uint8Array>;
|
|
60
|
+
/** Check if a tarball is cached. */
|
|
61
|
+
hasTarball(url: string): boolean;
|
|
62
|
+
/** Store a tarball in the cache. */
|
|
63
|
+
setTarball(url: string, data: Uint8Array): void;
|
|
64
|
+
/** Number of cached manifests. */
|
|
65
|
+
get manifestCount(): number;
|
|
66
|
+
/** Number of cached tarballs. */
|
|
67
|
+
get tarballCount(): number;
|
|
68
|
+
/** Total bytes of cached tarballs. */
|
|
69
|
+
get tarballBytes(): number;
|
|
70
|
+
/** Clear all cached manifests. */
|
|
71
|
+
clearManifests(): void;
|
|
72
|
+
/** Clear all cached tarballs. */
|
|
73
|
+
clearTarballs(): void;
|
|
74
|
+
/** Clear all cached data. */
|
|
75
|
+
clear(): void;
|
|
76
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MemFS } from "../memfs";
|
|
2
|
+
import { RegistryOptions } from "./registry";
|
|
3
|
+
import { ResolvedPackage } from "./resolver";
|
|
4
|
+
import { PackageCache } from "./cache";
|
|
5
|
+
export interface LayoutStrategy {
|
|
6
|
+
getPackageDir(cwd: string, pkgName: string, pkgVersion: string): string;
|
|
7
|
+
createTopLevelLink(vfs: MemFS, cwd: string, pkgName: string, pkgVersion: string): void;
|
|
8
|
+
createDependencyLinks(vfs: MemFS, cwd: string, pkg: ResolvedPackage, allResolved: Map<string, ResolvedPackage>): void;
|
|
9
|
+
createBinStub(vfs: MemFS, cwd: string, cmdName: string, targetPath: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class NpmLayout implements LayoutStrategy {
|
|
12
|
+
getPackageDir(cwd: string, pkgName: string, _pkgVersion: string): string;
|
|
13
|
+
createTopLevelLink(): void;
|
|
14
|
+
createDependencyLinks(): void;
|
|
15
|
+
createBinStub(vfs: MemFS, cwd: string, cmdName: string, targetPath: string): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function parsePackageSpec(spec: string): {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
export interface InstallOptions {
|
|
22
|
+
registry?: string;
|
|
23
|
+
save?: boolean;
|
|
24
|
+
saveDev?: boolean;
|
|
25
|
+
includeDev?: boolean;
|
|
26
|
+
includeOptional?: boolean;
|
|
27
|
+
onProgress?: (message: string) => void;
|
|
28
|
+
transform?: boolean;
|
|
29
|
+
concurrency?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface InstallResult {
|
|
32
|
+
installed: Map<string, ResolvedPackage>;
|
|
33
|
+
added: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare class PackageManager {
|
|
36
|
+
private vfs;
|
|
37
|
+
private registry;
|
|
38
|
+
private cwd;
|
|
39
|
+
readonly layout: LayoutStrategy;
|
|
40
|
+
/** Package cache for manifests and tarballs. */
|
|
41
|
+
readonly cache: PackageCache;
|
|
42
|
+
constructor(vfs: MemFS, options?: {
|
|
43
|
+
cwd?: string;
|
|
44
|
+
layout?: LayoutStrategy;
|
|
45
|
+
cache?: PackageCache;
|
|
46
|
+
} & RegistryOptions);
|
|
47
|
+
/** Clear the package cache (manifests and tarballs). */
|
|
48
|
+
clearCache(): void;
|
|
49
|
+
install(packageSpec: string | string[], options?: InstallOptions): Promise<InstallResult>;
|
|
50
|
+
installFromPackageJson(options?: InstallOptions): Promise<InstallResult>;
|
|
51
|
+
list(): string[];
|
|
52
|
+
private updatePackageJson;
|
|
53
|
+
}
|
|
54
|
+
export declare function buildLockfile(vfs: MemFS, resolved: Map<string, ResolvedPackage>, cwd?: string): void;
|
|
55
|
+
export { Registry } from "./registry";
|
|
56
|
+
export type { RegistryOptions } from "./registry";
|
|
57
|
+
export type { ResolvedPackage } from "./resolver";
|
|
58
|
+
export { satisfies, compareVersions } from "./resolver";
|
|
59
|
+
export { readLockfile, lockfileToResolved } from "./lockfile-reader";
|
|
60
|
+
export type { LockfileData, LockfileEntry } from "./lockfile-reader";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lockfile reader for package-lock.json (v3 format).
|
|
3
|
+
*
|
|
4
|
+
* When a lockfile exists, the package manager can skip dependency resolution
|
|
5
|
+
* entirely and use the exact versions and tarball URLs from the lockfile.
|
|
6
|
+
* Combined with the package cache, this enables zero-network deterministic
|
|
7
|
+
* installs.
|
|
8
|
+
*/
|
|
9
|
+
import type { MemFS } from "../memfs";
|
|
10
|
+
import type { ResolvedPackage } from "./resolver";
|
|
11
|
+
/** A single package entry parsed from a lockfile. */
|
|
12
|
+
export interface LockfileEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
version: string;
|
|
15
|
+
resolved: string;
|
|
16
|
+
dependencies?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/** Parsed lockfile data. */
|
|
19
|
+
export interface LockfileData {
|
|
20
|
+
lockfileVersion: number;
|
|
21
|
+
packages: Map<string, LockfileEntry>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Read and parse a package-lock.json (v3 format) from the VFS.
|
|
25
|
+
* Returns `null` if no lockfile exists or it can't be parsed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readLockfile(vfs: MemFS, cwd: string): LockfileData | null;
|
|
28
|
+
/**
|
|
29
|
+
* Convert lockfile entries to ResolvedPackage map for use by the installer.
|
|
30
|
+
* This replaces the full dependency resolution step when a lockfile is available.
|
|
31
|
+
*/
|
|
32
|
+
export declare function lockfileToResolved(lockfile: LockfileData): Map<string, ResolvedPackage>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MemFS } from "../memfs";
|
|
2
|
+
import { LayoutStrategy } from "./index";
|
|
3
|
+
import { ResolvedPackage } from "./resolver";
|
|
4
|
+
/**
|
|
5
|
+
* pnpm-style content-addressable store layout.
|
|
6
|
+
*
|
|
7
|
+
* Structure:
|
|
8
|
+
* node_modules/.pnpm/<name>@<version>/node_modules/<name>/ ← actual files
|
|
9
|
+
* node_modules/<name> → symlink to store path above
|
|
10
|
+
* node_modules/.pnpm/<name>@<version>/node_modules/<dep> → symlink to dep store
|
|
11
|
+
*/
|
|
12
|
+
export declare class PnpmLayout implements LayoutStrategy {
|
|
13
|
+
private storePath;
|
|
14
|
+
getPackageDir(cwd: string, pkgName: string, pkgVersion: string): string;
|
|
15
|
+
createTopLevelLink(vfs: MemFS, cwd: string, pkgName: string, pkgVersion: string): void;
|
|
16
|
+
createDependencyLinks(vfs: MemFS, cwd: string, pkg: ResolvedPackage, allResolved: Map<string, ResolvedPackage>): void;
|
|
17
|
+
createBinStub(vfs: MemFS, cwd: string, cmdName: string, targetPath: string): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PackageCache } from "./cache";
|
|
2
|
+
export interface RegistryOptions {
|
|
3
|
+
registry?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
/** Optional package cache for manifest and tarball caching. */
|
|
6
|
+
cache?: PackageCache;
|
|
7
|
+
}
|
|
8
|
+
export interface PackageManifest {
|
|
9
|
+
name: string;
|
|
10
|
+
"dist-tags": Record<string, string>;
|
|
11
|
+
versions: Record<string, PackageVersion>;
|
|
12
|
+
}
|
|
13
|
+
export interface PackageVersion {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
dependencies?: Record<string, string>;
|
|
17
|
+
devDependencies?: Record<string, string>;
|
|
18
|
+
peerDependencies?: Record<string, string>;
|
|
19
|
+
optionalDependencies?: Record<string, string>;
|
|
20
|
+
peerDependenciesMeta?: Record<string, {
|
|
21
|
+
optional?: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
bin?: string | Record<string, string>;
|
|
24
|
+
main?: string;
|
|
25
|
+
module?: string;
|
|
26
|
+
exports?: unknown;
|
|
27
|
+
dist: {
|
|
28
|
+
tarball: string;
|
|
29
|
+
shasum: string;
|
|
30
|
+
integrity?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare class Registry {
|
|
34
|
+
private baseUrl;
|
|
35
|
+
private token?;
|
|
36
|
+
private inMemoryCache;
|
|
37
|
+
private packageCache?;
|
|
38
|
+
constructor(options?: RegistryOptions);
|
|
39
|
+
getManifest(name: string): Promise<PackageManifest>;
|
|
40
|
+
private fetchManifest;
|
|
41
|
+
getVersion(name: string, version: string): Promise<PackageVersion>;
|
|
42
|
+
downloadTarball(url: string): Promise<ArrayBuffer>;
|
|
43
|
+
private fetchTarball;
|
|
44
|
+
clearCache(): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Registry } from "./registry";
|
|
2
|
+
export interface ResolvedPackage {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
dependencies: Record<string, string>;
|
|
6
|
+
dist: {
|
|
7
|
+
tarball: string;
|
|
8
|
+
shasum: string;
|
|
9
|
+
};
|
|
10
|
+
bin?: string | Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolveOptions {
|
|
13
|
+
registry: Registry;
|
|
14
|
+
includeDev?: boolean;
|
|
15
|
+
includeOptional?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class SemVer {
|
|
18
|
+
readonly major: number;
|
|
19
|
+
readonly minor: number;
|
|
20
|
+
readonly patch: number;
|
|
21
|
+
readonly pre: string;
|
|
22
|
+
constructor(raw: string);
|
|
23
|
+
compareTo(other: SemVer): number;
|
|
24
|
+
matches(range: string): boolean;
|
|
25
|
+
toString(): string;
|
|
26
|
+
}
|
|
27
|
+
declare function satisfies(version: string, range: string): boolean;
|
|
28
|
+
declare function compareVersions(a: string, b: string): number;
|
|
29
|
+
declare function findBestVersion(versions: string[], range: string): string | null;
|
|
30
|
+
export declare function resolveDependencies(name: string, versionRange: string, options: ResolveOptions): Promise<Map<string, ResolvedPackage>>;
|
|
31
|
+
export declare function resolveFromPackageJson(packageJson: {
|
|
32
|
+
dependencies?: Record<string, string>;
|
|
33
|
+
devDependencies?: Record<string, string>;
|
|
34
|
+
}, options: ResolveOptions): Promise<Map<string, ResolvedPackage>>;
|
|
35
|
+
/** Merge non-optional peerDependencies into deps. Existing deps take precedence. */
|
|
36
|
+
export declare function mergePeerDeps(deps: Record<string, string>, peerDeps: Record<string, string>, peerMeta?: Record<string, {
|
|
37
|
+
optional?: boolean;
|
|
38
|
+
}>): Record<string, string>;
|
|
39
|
+
export { satisfies, compareVersions, findBestVersion };
|