almostnode 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/LICENSE +21 -0
- package/README.md +731 -0
- package/dist/__sw__.js +394 -0
- package/dist/ai-chatbot-demo-entry.d.ts +6 -0
- package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
- package/dist/ai-chatbot-demo.d.ts +42 -0
- package/dist/ai-chatbot-demo.d.ts.map +1 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
- package/dist/convex-app-demo-entry.d.ts +6 -0
- package/dist/convex-app-demo-entry.d.ts.map +1 -0
- package/dist/convex-app-demo.d.ts +68 -0
- package/dist/convex-app-demo.d.ts.map +1 -0
- package/dist/cors-proxy.d.ts +46 -0
- package/dist/cors-proxy.d.ts.map +1 -0
- package/dist/create-runtime.d.ts +42 -0
- package/dist/create-runtime.d.ts.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/dev-server.d.ts +97 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +202 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -0
- package/dist/frameworks/vite-dev-server.d.ts +85 -0
- package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
- package/dist/index.cjs +14965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +14867 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-demo.d.ts +49 -0
- package/dist/next-demo.d.ts.map +1 -0
- package/dist/npm/index.d.ts +71 -0
- package/dist/npm/index.d.ts.map +1 -0
- package/dist/npm/registry.d.ts +66 -0
- package/dist/npm/registry.d.ts.map +1 -0
- package/dist/npm/resolver.d.ts +52 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/tarball.d.ts +29 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/runtime-interface.d.ts +90 -0
- package/dist/runtime-interface.d.ts.map +1 -0
- package/dist/runtime.d.ts +103 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/sandbox-helpers.d.ts +43 -0
- package/dist/sandbox-helpers.d.ts.map +1 -0
- package/dist/sandbox-runtime.d.ts +65 -0
- package/dist/sandbox-runtime.d.ts.map +1 -0
- package/dist/server-bridge.d.ts +89 -0
- package/dist/server-bridge.d.ts.map +1 -0
- package/dist/shims/assert.d.ts +51 -0
- package/dist/shims/assert.d.ts.map +1 -0
- package/dist/shims/async_hooks.d.ts +37 -0
- package/dist/shims/async_hooks.d.ts.map +1 -0
- package/dist/shims/buffer.d.ts +20 -0
- package/dist/shims/buffer.d.ts.map +1 -0
- package/dist/shims/child_process-browser.d.ts +92 -0
- package/dist/shims/child_process-browser.d.ts.map +1 -0
- package/dist/shims/child_process.d.ts +93 -0
- package/dist/shims/child_process.d.ts.map +1 -0
- package/dist/shims/chokidar.d.ts +55 -0
- package/dist/shims/chokidar.d.ts.map +1 -0
- package/dist/shims/cluster.d.ts +52 -0
- package/dist/shims/cluster.d.ts.map +1 -0
- package/dist/shims/crypto.d.ts +122 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/dgram.d.ts +34 -0
- package/dist/shims/dgram.d.ts.map +1 -0
- package/dist/shims/diagnostics_channel.d.ts +80 -0
- package/dist/shims/diagnostics_channel.d.ts.map +1 -0
- package/dist/shims/dns.d.ts +87 -0
- package/dist/shims/dns.d.ts.map +1 -0
- package/dist/shims/domain.d.ts +25 -0
- package/dist/shims/domain.d.ts.map +1 -0
- package/dist/shims/esbuild.d.ts +105 -0
- package/dist/shims/esbuild.d.ts.map +1 -0
- package/dist/shims/events.d.ts +37 -0
- package/dist/shims/events.d.ts.map +1 -0
- package/dist/shims/fs.d.ts +115 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/fsevents.d.ts +67 -0
- package/dist/shims/fsevents.d.ts.map +1 -0
- package/dist/shims/http.d.ts +217 -0
- package/dist/shims/http.d.ts.map +1 -0
- package/dist/shims/http2.d.ts +81 -0
- package/dist/shims/http2.d.ts.map +1 -0
- package/dist/shims/https.d.ts +36 -0
- package/dist/shims/https.d.ts.map +1 -0
- package/dist/shims/inspector.d.ts +25 -0
- package/dist/shims/inspector.d.ts.map +1 -0
- package/dist/shims/module.d.ts +22 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/net.d.ts +100 -0
- package/dist/shims/net.d.ts.map +1 -0
- package/dist/shims/os.d.ts +159 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/path.d.ts +72 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/perf_hooks.d.ts +50 -0
- package/dist/shims/perf_hooks.d.ts.map +1 -0
- package/dist/shims/process.d.ts +93 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/querystring.d.ts +23 -0
- package/dist/shims/querystring.d.ts.map +1 -0
- package/dist/shims/readdirp.d.ts +52 -0
- package/dist/shims/readdirp.d.ts.map +1 -0
- package/dist/shims/readline.d.ts +62 -0
- package/dist/shims/readline.d.ts.map +1 -0
- package/dist/shims/rollup.d.ts +34 -0
- package/dist/shims/rollup.d.ts.map +1 -0
- package/dist/shims/sentry.d.ts +163 -0
- package/dist/shims/sentry.d.ts.map +1 -0
- package/dist/shims/stream.d.ts +181 -0
- package/dist/shims/stream.d.ts.map +1 -0
- package/dist/shims/tls.d.ts +53 -0
- package/dist/shims/tls.d.ts.map +1 -0
- package/dist/shims/tty.d.ts +30 -0
- package/dist/shims/tty.d.ts.map +1 -0
- package/dist/shims/url.d.ts +64 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/util.d.ts +106 -0
- package/dist/shims/util.d.ts.map +1 -0
- package/dist/shims/v8.d.ts +73 -0
- package/dist/shims/v8.d.ts.map +1 -0
- package/dist/shims/vfs-adapter.d.ts +126 -0
- package/dist/shims/vfs-adapter.d.ts.map +1 -0
- package/dist/shims/vm.d.ts +45 -0
- package/dist/shims/vm.d.ts.map +1 -0
- package/dist/shims/worker_threads.d.ts +66 -0
- package/dist/shims/worker_threads.d.ts.map +1 -0
- package/dist/shims/ws.d.ts +66 -0
- package/dist/shims/ws.d.ts.map +1 -0
- package/dist/shims/zlib.d.ts +161 -0
- package/dist/shims/zlib.d.ts.map +1 -0
- package/dist/transform.d.ts +24 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +226 -0
- package/dist/virtual-fs.d.ts.map +1 -0
- package/dist/vite-demo.d.ts +35 -0
- package/dist/vite-demo.d.ts.map +1 -0
- package/dist/vite-sw.js +132 -0
- package/dist/worker/runtime-worker.d.ts +8 -0
- package/dist/worker/runtime-worker.d.ts.map +1 -0
- package/dist/worker-runtime.d.ts +50 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/ai-chatbot-demo-entry.ts +244 -0
- package/src/ai-chatbot-demo.ts +509 -0
- package/src/convex-app-demo-entry.ts +1107 -0
- package/src/convex-app-demo.ts +1316 -0
- package/src/cors-proxy.ts +81 -0
- package/src/create-runtime.ts +147 -0
- package/src/demo.ts +304 -0
- package/src/dev-server.ts +274 -0
- package/src/frameworks/next-dev-server.ts +2224 -0
- package/src/frameworks/vite-dev-server.ts +702 -0
- package/src/index.ts +101 -0
- package/src/next-demo.ts +1784 -0
- package/src/npm/index.ts +347 -0
- package/src/npm/registry.ts +152 -0
- package/src/npm/resolver.ts +385 -0
- package/src/npm/tarball.ts +209 -0
- package/src/runtime-interface.ts +103 -0
- package/src/runtime.ts +1046 -0
- package/src/sandbox-helpers.ts +173 -0
- package/src/sandbox-runtime.ts +252 -0
- package/src/server-bridge.ts +426 -0
- package/src/shims/assert.ts +664 -0
- package/src/shims/async_hooks.ts +86 -0
- package/src/shims/buffer.ts +75 -0
- package/src/shims/child_process-browser.ts +217 -0
- package/src/shims/child_process.ts +463 -0
- package/src/shims/chokidar.ts +313 -0
- package/src/shims/cluster.ts +67 -0
- package/src/shims/crypto.ts +830 -0
- package/src/shims/dgram.ts +47 -0
- package/src/shims/diagnostics_channel.ts +196 -0
- package/src/shims/dns.ts +172 -0
- package/src/shims/domain.ts +58 -0
- package/src/shims/esbuild.ts +805 -0
- package/src/shims/events.ts +195 -0
- package/src/shims/fs.ts +803 -0
- package/src/shims/fsevents.ts +63 -0
- package/src/shims/http.ts +904 -0
- package/src/shims/http2.ts +96 -0
- package/src/shims/https.ts +86 -0
- package/src/shims/inspector.ts +30 -0
- package/src/shims/module.ts +82 -0
- package/src/shims/net.ts +359 -0
- package/src/shims/os.ts +195 -0
- package/src/shims/path.ts +199 -0
- package/src/shims/perf_hooks.ts +92 -0
- package/src/shims/process.ts +346 -0
- package/src/shims/querystring.ts +97 -0
- package/src/shims/readdirp.ts +228 -0
- package/src/shims/readline.ts +110 -0
- package/src/shims/rollup.ts +80 -0
- package/src/shims/sentry.ts +133 -0
- package/src/shims/stream.ts +1126 -0
- package/src/shims/tls.ts +95 -0
- package/src/shims/tty.ts +64 -0
- package/src/shims/url.ts +171 -0
- package/src/shims/util.ts +312 -0
- package/src/shims/v8.ts +113 -0
- package/src/shims/vfs-adapter.ts +402 -0
- package/src/shims/vm.ts +83 -0
- package/src/shims/worker_threads.ts +111 -0
- package/src/shims/ws.ts +382 -0
- package/src/shims/zlib.ts +289 -0
- package/src/transform.ts +313 -0
- package/src/types/external.d.ts +67 -0
- package/src/virtual-fs.ts +903 -0
- package/src/vite-demo.ts +577 -0
- package/src/worker/runtime-worker.ts +128 -0
- package/src/worker-runtime.ts +145 -0
package/src/shims/os.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js os module shim
|
|
3
|
+
* Provides operating system utilities
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function hostname(): string {
|
|
7
|
+
return 'localhost';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function platform(): string {
|
|
11
|
+
return 'linux';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function arch(): string {
|
|
15
|
+
return 'x64';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function type(): string {
|
|
19
|
+
return 'Linux';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function release(): string {
|
|
23
|
+
return '5.10.0';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function version(): string {
|
|
27
|
+
return '#1 SMP';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function machine(): string {
|
|
31
|
+
return 'x86_64';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function tmpdir(): string {
|
|
35
|
+
return '/tmp';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function homedir(): string {
|
|
39
|
+
return '/home/user';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function cpus(): Array<{
|
|
43
|
+
model: string;
|
|
44
|
+
speed: number;
|
|
45
|
+
times: { user: number; nice: number; sys: number; idle: number; irq: number };
|
|
46
|
+
}> {
|
|
47
|
+
const cpu = {
|
|
48
|
+
model: 'Virtual CPU',
|
|
49
|
+
speed: 2400,
|
|
50
|
+
times: { user: 0, nice: 0, sys: 0, idle: 0, irq: 0 },
|
|
51
|
+
};
|
|
52
|
+
return [cpu, cpu]; // Simulate 2 CPUs
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function totalmem(): number {
|
|
56
|
+
return 4 * 1024 * 1024 * 1024; // 4GB
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function freemem(): number {
|
|
60
|
+
return 2 * 1024 * 1024 * 1024; // 2GB
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function uptime(): number {
|
|
64
|
+
return Math.floor(performance.now() / 1000);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function loadavg(): [number, number, number] {
|
|
68
|
+
return [0.5, 0.5, 0.5];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function networkInterfaces(): Record<
|
|
72
|
+
string,
|
|
73
|
+
Array<{
|
|
74
|
+
address: string;
|
|
75
|
+
netmask: string;
|
|
76
|
+
family: string;
|
|
77
|
+
mac: string;
|
|
78
|
+
internal: boolean;
|
|
79
|
+
cidr: string;
|
|
80
|
+
}>
|
|
81
|
+
> {
|
|
82
|
+
return {
|
|
83
|
+
lo: [
|
|
84
|
+
{
|
|
85
|
+
address: '127.0.0.1',
|
|
86
|
+
netmask: '255.0.0.0',
|
|
87
|
+
family: 'IPv4',
|
|
88
|
+
mac: '00:00:00:00:00:00',
|
|
89
|
+
internal: true,
|
|
90
|
+
cidr: '127.0.0.1/8',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function userInfo(): {
|
|
97
|
+
username: string;
|
|
98
|
+
uid: number;
|
|
99
|
+
gid: number;
|
|
100
|
+
shell: string;
|
|
101
|
+
homedir: string;
|
|
102
|
+
} {
|
|
103
|
+
return {
|
|
104
|
+
username: 'user',
|
|
105
|
+
uid: 1000,
|
|
106
|
+
gid: 1000,
|
|
107
|
+
shell: '/bin/bash',
|
|
108
|
+
homedir: '/home/user',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function endianness(): 'BE' | 'LE' {
|
|
113
|
+
return 'LE';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function getPriority(pid?: number): number {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function setPriority(pid: number | number, priority?: number): void {
|
|
121
|
+
// No-op
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const EOL = '\n';
|
|
125
|
+
|
|
126
|
+
export const constants = {
|
|
127
|
+
signals: {
|
|
128
|
+
SIGHUP: 1,
|
|
129
|
+
SIGINT: 2,
|
|
130
|
+
SIGQUIT: 3,
|
|
131
|
+
SIGILL: 4,
|
|
132
|
+
SIGTRAP: 5,
|
|
133
|
+
SIGABRT: 6,
|
|
134
|
+
SIGBUS: 7,
|
|
135
|
+
SIGFPE: 8,
|
|
136
|
+
SIGKILL: 9,
|
|
137
|
+
SIGUSR1: 10,
|
|
138
|
+
SIGSEGV: 11,
|
|
139
|
+
SIGUSR2: 12,
|
|
140
|
+
SIGPIPE: 13,
|
|
141
|
+
SIGALRM: 14,
|
|
142
|
+
SIGTERM: 15,
|
|
143
|
+
SIGCHLD: 17,
|
|
144
|
+
SIGCONT: 18,
|
|
145
|
+
SIGSTOP: 19,
|
|
146
|
+
SIGTSTP: 20,
|
|
147
|
+
SIGTTIN: 21,
|
|
148
|
+
SIGTTOU: 22,
|
|
149
|
+
SIGURG: 23,
|
|
150
|
+
SIGXCPU: 24,
|
|
151
|
+
SIGXFSZ: 25,
|
|
152
|
+
SIGVTALRM: 26,
|
|
153
|
+
SIGPROF: 27,
|
|
154
|
+
SIGWINCH: 28,
|
|
155
|
+
SIGIO: 29,
|
|
156
|
+
SIGPWR: 30,
|
|
157
|
+
SIGSYS: 31,
|
|
158
|
+
},
|
|
159
|
+
errno: {},
|
|
160
|
+
priority: {
|
|
161
|
+
PRIORITY_LOW: 19,
|
|
162
|
+
PRIORITY_BELOW_NORMAL: 10,
|
|
163
|
+
PRIORITY_NORMAL: 0,
|
|
164
|
+
PRIORITY_ABOVE_NORMAL: -7,
|
|
165
|
+
PRIORITY_HIGH: -14,
|
|
166
|
+
PRIORITY_HIGHEST: -20,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const devNull = '/dev/null';
|
|
171
|
+
|
|
172
|
+
export default {
|
|
173
|
+
hostname,
|
|
174
|
+
platform,
|
|
175
|
+
arch,
|
|
176
|
+
type,
|
|
177
|
+
release,
|
|
178
|
+
version,
|
|
179
|
+
machine,
|
|
180
|
+
tmpdir,
|
|
181
|
+
homedir,
|
|
182
|
+
cpus,
|
|
183
|
+
totalmem,
|
|
184
|
+
freemem,
|
|
185
|
+
uptime,
|
|
186
|
+
loadavg,
|
|
187
|
+
networkInterfaces,
|
|
188
|
+
userInfo,
|
|
189
|
+
endianness,
|
|
190
|
+
getPriority,
|
|
191
|
+
setPriority,
|
|
192
|
+
EOL,
|
|
193
|
+
constants,
|
|
194
|
+
devNull,
|
|
195
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js path module shim
|
|
3
|
+
* Implements POSIX path operations for virtual file system
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const sep = '/';
|
|
7
|
+
export const delimiter = ':';
|
|
8
|
+
|
|
9
|
+
export function normalize(path: string): string {
|
|
10
|
+
if (!path) return '.';
|
|
11
|
+
|
|
12
|
+
const isAbsolute = path.startsWith('/');
|
|
13
|
+
const parts = path.split('/').filter(Boolean);
|
|
14
|
+
const resolved: string[] = [];
|
|
15
|
+
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
if (part === '..') {
|
|
18
|
+
if (resolved.length > 0 && resolved[resolved.length - 1] !== '..') {
|
|
19
|
+
resolved.pop();
|
|
20
|
+
} else if (!isAbsolute) {
|
|
21
|
+
resolved.push('..');
|
|
22
|
+
}
|
|
23
|
+
} else if (part !== '.') {
|
|
24
|
+
resolved.push(part);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let result = resolved.join('/');
|
|
29
|
+
if (isAbsolute) {
|
|
30
|
+
result = '/' + result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result || '.';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Track join calls to debug infinite recursion
|
|
37
|
+
let joinCallCount = 0;
|
|
38
|
+
|
|
39
|
+
export function join(...paths: string[]): string {
|
|
40
|
+
if (paths.length === 0) return '.';
|
|
41
|
+
const result = normalize(paths.filter(Boolean).join('/'));
|
|
42
|
+
// Debug: Log _generated path joins
|
|
43
|
+
if (paths.some(p => p && p.includes('_generated'))) {
|
|
44
|
+
joinCallCount++;
|
|
45
|
+
if (joinCallCount <= 20) {
|
|
46
|
+
console.log(`[path.join] (${paths.join(', ')}) -> ${result}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function resolve(...paths: string[]): string {
|
|
53
|
+
let resolvedPath = '';
|
|
54
|
+
|
|
55
|
+
for (let i = paths.length - 1; i >= 0 && !resolvedPath.startsWith('/'); i--) {
|
|
56
|
+
const path = paths[i];
|
|
57
|
+
if (!path) continue;
|
|
58
|
+
resolvedPath = path + (resolvedPath ? '/' + resolvedPath : '');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!resolvedPath.startsWith('/')) {
|
|
62
|
+
resolvedPath = '/' + resolvedPath;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return normalize(resolvedPath);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function isAbsolute(path: string): boolean {
|
|
69
|
+
return path.startsWith('/');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function dirname(path: string): string {
|
|
73
|
+
if (!path) return '.';
|
|
74
|
+
|
|
75
|
+
const normalized = normalize(path);
|
|
76
|
+
const lastSlash = normalized.lastIndexOf('/');
|
|
77
|
+
|
|
78
|
+
if (lastSlash === -1) return '.';
|
|
79
|
+
if (lastSlash === 0) return '/';
|
|
80
|
+
|
|
81
|
+
return normalized.slice(0, lastSlash);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function basename(path: string, ext?: string): string {
|
|
85
|
+
if (!path) return '';
|
|
86
|
+
|
|
87
|
+
const normalized = normalize(path);
|
|
88
|
+
let base = normalized.slice(normalized.lastIndexOf('/') + 1);
|
|
89
|
+
|
|
90
|
+
if (ext && base.endsWith(ext)) {
|
|
91
|
+
base = base.slice(0, -ext.length);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return base;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function extname(path: string): string {
|
|
98
|
+
const base = basename(path);
|
|
99
|
+
const dotIndex = base.lastIndexOf('.');
|
|
100
|
+
|
|
101
|
+
if (dotIndex <= 0) return '';
|
|
102
|
+
|
|
103
|
+
return base.slice(dotIndex);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function relative(from: string, to: string): string {
|
|
107
|
+
from = resolve(from);
|
|
108
|
+
to = resolve(to);
|
|
109
|
+
|
|
110
|
+
if (from === to) return '';
|
|
111
|
+
|
|
112
|
+
const fromParts = from.split('/').filter(Boolean);
|
|
113
|
+
const toParts = to.split('/').filter(Boolean);
|
|
114
|
+
|
|
115
|
+
let commonLength = 0;
|
|
116
|
+
for (let i = 0; i < Math.min(fromParts.length, toParts.length); i++) {
|
|
117
|
+
if (fromParts[i] !== toParts[i]) break;
|
|
118
|
+
commonLength++;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const upCount = fromParts.length - commonLength;
|
|
122
|
+
const remainingPath = toParts.slice(commonLength);
|
|
123
|
+
|
|
124
|
+
const result = [...Array(upCount).fill('..'), ...remainingPath];
|
|
125
|
+
|
|
126
|
+
return result.join('/') || '.';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function parse(path: string): {
|
|
130
|
+
root: string;
|
|
131
|
+
dir: string;
|
|
132
|
+
base: string;
|
|
133
|
+
ext: string;
|
|
134
|
+
name: string;
|
|
135
|
+
} {
|
|
136
|
+
const normalized = normalize(path);
|
|
137
|
+
const isAbs = isAbsolute(normalized);
|
|
138
|
+
const dir = dirname(normalized);
|
|
139
|
+
const base = basename(normalized);
|
|
140
|
+
const ext = extname(normalized);
|
|
141
|
+
const name = base.slice(0, base.length - ext.length);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
root: isAbs ? '/' : '',
|
|
145
|
+
dir,
|
|
146
|
+
base,
|
|
147
|
+
ext,
|
|
148
|
+
name,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function format(pathObject: {
|
|
153
|
+
root?: string;
|
|
154
|
+
dir?: string;
|
|
155
|
+
base?: string;
|
|
156
|
+
ext?: string;
|
|
157
|
+
name?: string;
|
|
158
|
+
}): string {
|
|
159
|
+
const dir = pathObject.dir || pathObject.root || '';
|
|
160
|
+
const base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
161
|
+
|
|
162
|
+
if (!dir) return base;
|
|
163
|
+
if (dir === pathObject.root) return dir + base;
|
|
164
|
+
|
|
165
|
+
return dir + '/' + base;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// POSIX interface (we only support POSIX)
|
|
169
|
+
export const posix = {
|
|
170
|
+
sep,
|
|
171
|
+
delimiter,
|
|
172
|
+
normalize,
|
|
173
|
+
join,
|
|
174
|
+
resolve,
|
|
175
|
+
isAbsolute,
|
|
176
|
+
dirname,
|
|
177
|
+
basename,
|
|
178
|
+
extname,
|
|
179
|
+
relative,
|
|
180
|
+
parse,
|
|
181
|
+
format,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// Default export for CommonJS compatibility
|
|
185
|
+
export default {
|
|
186
|
+
sep,
|
|
187
|
+
delimiter,
|
|
188
|
+
normalize,
|
|
189
|
+
join,
|
|
190
|
+
resolve,
|
|
191
|
+
isAbsolute,
|
|
192
|
+
dirname,
|
|
193
|
+
basename,
|
|
194
|
+
extname,
|
|
195
|
+
relative,
|
|
196
|
+
parse,
|
|
197
|
+
format,
|
|
198
|
+
posix,
|
|
199
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* perf_hooks shim - Performance measurement APIs
|
|
3
|
+
* Wraps browser Performance API
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const performance = globalThis.performance || {
|
|
7
|
+
now: () => Date.now(),
|
|
8
|
+
timeOrigin: Date.now(),
|
|
9
|
+
mark: () => {},
|
|
10
|
+
measure: () => {},
|
|
11
|
+
getEntries: () => [],
|
|
12
|
+
getEntriesByName: () => [],
|
|
13
|
+
getEntriesByType: () => [],
|
|
14
|
+
clearMarks: () => {},
|
|
15
|
+
clearMeasures: () => {},
|
|
16
|
+
clearResourceTimings: () => {},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class PerformanceObserver {
|
|
20
|
+
private callback: (list: PerformanceObserverEntryList) => void;
|
|
21
|
+
private entryTypes: string[] = [];
|
|
22
|
+
|
|
23
|
+
constructor(callback: (list: PerformanceObserverEntryList) => void) {
|
|
24
|
+
this.callback = callback;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
observe(options: { entryTypes?: string[]; type?: string }): void {
|
|
28
|
+
this.entryTypes = options.entryTypes || (options.type ? [options.type] : []);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnect(): void {
|
|
32
|
+
this.entryTypes = [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
takeRecords(): PerformanceEntry[] {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static supportedEntryTypes = ['mark', 'measure', 'resource', 'navigation'];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PerformanceObserverEntryList {
|
|
43
|
+
getEntries(): PerformanceEntry[];
|
|
44
|
+
getEntriesByName(name: string, type?: string): PerformanceEntry[];
|
|
45
|
+
getEntriesByType(type: string): PerformanceEntry[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PerformanceEntry {
|
|
49
|
+
name: string;
|
|
50
|
+
entryType: string;
|
|
51
|
+
startTime: number;
|
|
52
|
+
duration: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Histogram stub
|
|
56
|
+
export class Histogram {
|
|
57
|
+
min = 0;
|
|
58
|
+
max = 0;
|
|
59
|
+
mean = 0;
|
|
60
|
+
stddev = 0;
|
|
61
|
+
percentiles = new Map<number, number>();
|
|
62
|
+
exceeds = 0;
|
|
63
|
+
|
|
64
|
+
reset(): void {
|
|
65
|
+
this.min = 0;
|
|
66
|
+
this.max = 0;
|
|
67
|
+
this.mean = 0;
|
|
68
|
+
this.stddev = 0;
|
|
69
|
+
this.percentiles.clear();
|
|
70
|
+
this.exceeds = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
percentile(percentile: number): number {
|
|
74
|
+
return this.percentiles.get(percentile) || 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createHistogram(): Histogram {
|
|
79
|
+
return new Histogram();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function monitorEventLoopDelay(options?: { resolution?: number }): Histogram {
|
|
83
|
+
const histogram = new Histogram();
|
|
84
|
+
return histogram;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
performance,
|
|
89
|
+
PerformanceObserver,
|
|
90
|
+
createHistogram,
|
|
91
|
+
monitorEventLoopDelay,
|
|
92
|
+
};
|