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
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base DevServer class for framework-specific dev servers
|
|
3
|
+
* This is a framework-agnostic base that can be extended for Vite, Next.js, etc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from './shims/events';
|
|
7
|
+
import { VirtualFS } from './virtual-fs';
|
|
8
|
+
import { Buffer } from './shims/stream';
|
|
9
|
+
|
|
10
|
+
export interface DevServerOptions {
|
|
11
|
+
port: number;
|
|
12
|
+
root?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ResponseData {
|
|
16
|
+
statusCode: number;
|
|
17
|
+
statusMessage: string;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
body: Buffer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface HMRUpdate {
|
|
23
|
+
type: 'update' | 'full-reload';
|
|
24
|
+
path: string;
|
|
25
|
+
timestamp?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* MIME type mapping for common file extensions
|
|
30
|
+
*/
|
|
31
|
+
const MIME_TYPES: Record<string, string> = {
|
|
32
|
+
html: 'text/html; charset=utf-8',
|
|
33
|
+
htm: 'text/html; charset=utf-8',
|
|
34
|
+
css: 'text/css; charset=utf-8',
|
|
35
|
+
js: 'application/javascript; charset=utf-8',
|
|
36
|
+
mjs: 'application/javascript; charset=utf-8',
|
|
37
|
+
cjs: 'application/javascript; charset=utf-8',
|
|
38
|
+
jsx: 'application/javascript; charset=utf-8',
|
|
39
|
+
ts: 'application/javascript; charset=utf-8',
|
|
40
|
+
tsx: 'application/javascript; charset=utf-8',
|
|
41
|
+
json: 'application/json; charset=utf-8',
|
|
42
|
+
png: 'image/png',
|
|
43
|
+
jpg: 'image/jpeg',
|
|
44
|
+
jpeg: 'image/jpeg',
|
|
45
|
+
gif: 'image/gif',
|
|
46
|
+
svg: 'image/svg+xml',
|
|
47
|
+
ico: 'image/x-icon',
|
|
48
|
+
webp: 'image/webp',
|
|
49
|
+
woff: 'font/woff',
|
|
50
|
+
woff2: 'font/woff2',
|
|
51
|
+
ttf: 'font/ttf',
|
|
52
|
+
otf: 'font/otf',
|
|
53
|
+
eot: 'application/vnd.ms-fontobject',
|
|
54
|
+
mp3: 'audio/mpeg',
|
|
55
|
+
mp4: 'video/mp4',
|
|
56
|
+
webm: 'video/webm',
|
|
57
|
+
ogg: 'audio/ogg',
|
|
58
|
+
wav: 'audio/wav',
|
|
59
|
+
pdf: 'application/pdf',
|
|
60
|
+
xml: 'application/xml',
|
|
61
|
+
txt: 'text/plain; charset=utf-8',
|
|
62
|
+
md: 'text/markdown; charset=utf-8',
|
|
63
|
+
wasm: 'application/wasm',
|
|
64
|
+
map: 'application/json',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Base class for framework-specific dev servers.
|
|
69
|
+
* Extend this to create Vite, Next.js, etc. implementations.
|
|
70
|
+
*/
|
|
71
|
+
export abstract class DevServer extends EventEmitter {
|
|
72
|
+
protected vfs: VirtualFS;
|
|
73
|
+
protected port: number;
|
|
74
|
+
protected root: string;
|
|
75
|
+
protected running: boolean = false;
|
|
76
|
+
|
|
77
|
+
constructor(vfs: VirtualFS, options: DevServerOptions) {
|
|
78
|
+
super();
|
|
79
|
+
this.vfs = vfs;
|
|
80
|
+
this.port = options.port;
|
|
81
|
+
this.root = options.root || '/';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Handle an incoming HTTP request
|
|
86
|
+
* Must be implemented by framework-specific subclass
|
|
87
|
+
*/
|
|
88
|
+
abstract handleRequest(
|
|
89
|
+
method: string,
|
|
90
|
+
url: string,
|
|
91
|
+
headers: Record<string, string>,
|
|
92
|
+
body?: Buffer
|
|
93
|
+
): Promise<ResponseData>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Start file watching for HMR
|
|
97
|
+
* Must be implemented by framework-specific subclass
|
|
98
|
+
*/
|
|
99
|
+
abstract startWatching(): void;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Stop the server and cleanup
|
|
103
|
+
*/
|
|
104
|
+
stop(): void {
|
|
105
|
+
this.running = false;
|
|
106
|
+
this.emit('close');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Start the server
|
|
111
|
+
*/
|
|
112
|
+
start(): void {
|
|
113
|
+
this.running = true;
|
|
114
|
+
this.startWatching();
|
|
115
|
+
this.emit('listening', this.port);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Check if server is running
|
|
120
|
+
*/
|
|
121
|
+
isRunning(): boolean {
|
|
122
|
+
return this.running;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the server's port
|
|
127
|
+
*/
|
|
128
|
+
getPort(): number {
|
|
129
|
+
return this.port;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Serve a static file from the virtual filesystem
|
|
134
|
+
*/
|
|
135
|
+
protected serveFile(filePath: string): ResponseData {
|
|
136
|
+
try {
|
|
137
|
+
// Normalize path
|
|
138
|
+
const normalizedPath = this.resolvePath(filePath);
|
|
139
|
+
const content = this.vfs.readFileSync(normalizedPath);
|
|
140
|
+
// Ensure we have a Buffer
|
|
141
|
+
const buffer = typeof content === 'string'
|
|
142
|
+
? Buffer.from(content)
|
|
143
|
+
: Buffer.from(content);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
statusCode: 200,
|
|
147
|
+
statusMessage: 'OK',
|
|
148
|
+
headers: {
|
|
149
|
+
'Content-Type': this.getMimeType(filePath),
|
|
150
|
+
'Content-Length': String(buffer.length),
|
|
151
|
+
'Cache-Control': 'no-cache',
|
|
152
|
+
},
|
|
153
|
+
body: buffer,
|
|
154
|
+
};
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
157
|
+
return this.notFound(filePath);
|
|
158
|
+
}
|
|
159
|
+
return this.serverError(error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Resolve a URL path to a filesystem path
|
|
165
|
+
*/
|
|
166
|
+
protected resolvePath(urlPath: string): string {
|
|
167
|
+
// Remove query string and hash
|
|
168
|
+
let path = urlPath.split('?')[0].split('#')[0];
|
|
169
|
+
|
|
170
|
+
// Normalize path
|
|
171
|
+
if (!path.startsWith('/')) {
|
|
172
|
+
path = '/' + path;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Join with root
|
|
176
|
+
if (this.root !== '/') {
|
|
177
|
+
path = this.root + path;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return path;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Create a 404 Not Found response
|
|
185
|
+
*/
|
|
186
|
+
protected notFound(path: string): ResponseData {
|
|
187
|
+
const body = `Not found: ${path}`;
|
|
188
|
+
return {
|
|
189
|
+
statusCode: 404,
|
|
190
|
+
statusMessage: 'Not Found',
|
|
191
|
+
headers: {
|
|
192
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
193
|
+
'Content-Length': String(Buffer.byteLength(body)),
|
|
194
|
+
},
|
|
195
|
+
body: Buffer.from(body),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Create a 500 Server Error response
|
|
201
|
+
*/
|
|
202
|
+
protected serverError(error: unknown): ResponseData {
|
|
203
|
+
const message = error instanceof Error ? error.message : 'Internal Server Error';
|
|
204
|
+
const body = `Server Error: ${message}`;
|
|
205
|
+
return {
|
|
206
|
+
statusCode: 500,
|
|
207
|
+
statusMessage: 'Internal Server Error',
|
|
208
|
+
headers: {
|
|
209
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
210
|
+
'Content-Length': String(Buffer.byteLength(body)),
|
|
211
|
+
},
|
|
212
|
+
body: Buffer.from(body),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Create a redirect response
|
|
218
|
+
*/
|
|
219
|
+
protected redirect(location: string, status: 301 | 302 | 307 | 308 = 302): ResponseData {
|
|
220
|
+
return {
|
|
221
|
+
statusCode: status,
|
|
222
|
+
statusMessage: status === 301 ? 'Moved Permanently' : 'Found',
|
|
223
|
+
headers: {
|
|
224
|
+
Location: location,
|
|
225
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
226
|
+
'Content-Length': '0',
|
|
227
|
+
},
|
|
228
|
+
body: Buffer.from(''),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get MIME type for a file path
|
|
234
|
+
*/
|
|
235
|
+
protected getMimeType(path: string): string {
|
|
236
|
+
const ext = path.split('.').pop()?.toLowerCase() || '';
|
|
237
|
+
return MIME_TYPES[ext] || 'application/octet-stream';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Check if a path exists in the virtual filesystem
|
|
242
|
+
*/
|
|
243
|
+
protected exists(path: string): boolean {
|
|
244
|
+
try {
|
|
245
|
+
this.vfs.statSync(path);
|
|
246
|
+
return true;
|
|
247
|
+
} catch {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Check if a path is a directory
|
|
254
|
+
*/
|
|
255
|
+
protected isDirectory(path: string): boolean {
|
|
256
|
+
try {
|
|
257
|
+
return this.vfs.statSync(path).isDirectory();
|
|
258
|
+
} catch {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Emit an HMR update event
|
|
265
|
+
*/
|
|
266
|
+
protected emitHMRUpdate(update: HMRUpdate): void {
|
|
267
|
+
this.emit('hmr-update', {
|
|
268
|
+
...update,
|
|
269
|
+
timestamp: update.timestamp || Date.now(),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export default DevServer;
|