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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +731 -0
  3. package/dist/__sw__.js +394 -0
  4. package/dist/ai-chatbot-demo-entry.d.ts +6 -0
  5. package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
  6. package/dist/ai-chatbot-demo.d.ts +42 -0
  7. package/dist/ai-chatbot-demo.d.ts.map +1 -0
  8. package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
  9. package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
  10. package/dist/convex-app-demo-entry.d.ts +6 -0
  11. package/dist/convex-app-demo-entry.d.ts.map +1 -0
  12. package/dist/convex-app-demo.d.ts +68 -0
  13. package/dist/convex-app-demo.d.ts.map +1 -0
  14. package/dist/cors-proxy.d.ts +46 -0
  15. package/dist/cors-proxy.d.ts.map +1 -0
  16. package/dist/create-runtime.d.ts +42 -0
  17. package/dist/create-runtime.d.ts.map +1 -0
  18. package/dist/demo.d.ts +6 -0
  19. package/dist/demo.d.ts.map +1 -0
  20. package/dist/dev-server.d.ts +97 -0
  21. package/dist/dev-server.d.ts.map +1 -0
  22. package/dist/frameworks/next-dev-server.d.ts +202 -0
  23. package/dist/frameworks/next-dev-server.d.ts.map +1 -0
  24. package/dist/frameworks/vite-dev-server.d.ts +85 -0
  25. package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
  26. package/dist/index.cjs +14965 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.ts +71 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.mjs +14867 -0
  31. package/dist/index.mjs.map +1 -0
  32. package/dist/next-demo.d.ts +49 -0
  33. package/dist/next-demo.d.ts.map +1 -0
  34. package/dist/npm/index.d.ts +71 -0
  35. package/dist/npm/index.d.ts.map +1 -0
  36. package/dist/npm/registry.d.ts +66 -0
  37. package/dist/npm/registry.d.ts.map +1 -0
  38. package/dist/npm/resolver.d.ts +52 -0
  39. package/dist/npm/resolver.d.ts.map +1 -0
  40. package/dist/npm/tarball.d.ts +29 -0
  41. package/dist/npm/tarball.d.ts.map +1 -0
  42. package/dist/runtime-interface.d.ts +90 -0
  43. package/dist/runtime-interface.d.ts.map +1 -0
  44. package/dist/runtime.d.ts +103 -0
  45. package/dist/runtime.d.ts.map +1 -0
  46. package/dist/sandbox-helpers.d.ts +43 -0
  47. package/dist/sandbox-helpers.d.ts.map +1 -0
  48. package/dist/sandbox-runtime.d.ts +65 -0
  49. package/dist/sandbox-runtime.d.ts.map +1 -0
  50. package/dist/server-bridge.d.ts +89 -0
  51. package/dist/server-bridge.d.ts.map +1 -0
  52. package/dist/shims/assert.d.ts +51 -0
  53. package/dist/shims/assert.d.ts.map +1 -0
  54. package/dist/shims/async_hooks.d.ts +37 -0
  55. package/dist/shims/async_hooks.d.ts.map +1 -0
  56. package/dist/shims/buffer.d.ts +20 -0
  57. package/dist/shims/buffer.d.ts.map +1 -0
  58. package/dist/shims/child_process-browser.d.ts +92 -0
  59. package/dist/shims/child_process-browser.d.ts.map +1 -0
  60. package/dist/shims/child_process.d.ts +93 -0
  61. package/dist/shims/child_process.d.ts.map +1 -0
  62. package/dist/shims/chokidar.d.ts +55 -0
  63. package/dist/shims/chokidar.d.ts.map +1 -0
  64. package/dist/shims/cluster.d.ts +52 -0
  65. package/dist/shims/cluster.d.ts.map +1 -0
  66. package/dist/shims/crypto.d.ts +122 -0
  67. package/dist/shims/crypto.d.ts.map +1 -0
  68. package/dist/shims/dgram.d.ts +34 -0
  69. package/dist/shims/dgram.d.ts.map +1 -0
  70. package/dist/shims/diagnostics_channel.d.ts +80 -0
  71. package/dist/shims/diagnostics_channel.d.ts.map +1 -0
  72. package/dist/shims/dns.d.ts +87 -0
  73. package/dist/shims/dns.d.ts.map +1 -0
  74. package/dist/shims/domain.d.ts +25 -0
  75. package/dist/shims/domain.d.ts.map +1 -0
  76. package/dist/shims/esbuild.d.ts +105 -0
  77. package/dist/shims/esbuild.d.ts.map +1 -0
  78. package/dist/shims/events.d.ts +37 -0
  79. package/dist/shims/events.d.ts.map +1 -0
  80. package/dist/shims/fs.d.ts +115 -0
  81. package/dist/shims/fs.d.ts.map +1 -0
  82. package/dist/shims/fsevents.d.ts +67 -0
  83. package/dist/shims/fsevents.d.ts.map +1 -0
  84. package/dist/shims/http.d.ts +217 -0
  85. package/dist/shims/http.d.ts.map +1 -0
  86. package/dist/shims/http2.d.ts +81 -0
  87. package/dist/shims/http2.d.ts.map +1 -0
  88. package/dist/shims/https.d.ts +36 -0
  89. package/dist/shims/https.d.ts.map +1 -0
  90. package/dist/shims/inspector.d.ts +25 -0
  91. package/dist/shims/inspector.d.ts.map +1 -0
  92. package/dist/shims/module.d.ts +22 -0
  93. package/dist/shims/module.d.ts.map +1 -0
  94. package/dist/shims/net.d.ts +100 -0
  95. package/dist/shims/net.d.ts.map +1 -0
  96. package/dist/shims/os.d.ts +159 -0
  97. package/dist/shims/os.d.ts.map +1 -0
  98. package/dist/shims/path.d.ts +72 -0
  99. package/dist/shims/path.d.ts.map +1 -0
  100. package/dist/shims/perf_hooks.d.ts +50 -0
  101. package/dist/shims/perf_hooks.d.ts.map +1 -0
  102. package/dist/shims/process.d.ts +93 -0
  103. package/dist/shims/process.d.ts.map +1 -0
  104. package/dist/shims/querystring.d.ts +23 -0
  105. package/dist/shims/querystring.d.ts.map +1 -0
  106. package/dist/shims/readdirp.d.ts +52 -0
  107. package/dist/shims/readdirp.d.ts.map +1 -0
  108. package/dist/shims/readline.d.ts +62 -0
  109. package/dist/shims/readline.d.ts.map +1 -0
  110. package/dist/shims/rollup.d.ts +34 -0
  111. package/dist/shims/rollup.d.ts.map +1 -0
  112. package/dist/shims/sentry.d.ts +163 -0
  113. package/dist/shims/sentry.d.ts.map +1 -0
  114. package/dist/shims/stream.d.ts +181 -0
  115. package/dist/shims/stream.d.ts.map +1 -0
  116. package/dist/shims/tls.d.ts +53 -0
  117. package/dist/shims/tls.d.ts.map +1 -0
  118. package/dist/shims/tty.d.ts +30 -0
  119. package/dist/shims/tty.d.ts.map +1 -0
  120. package/dist/shims/url.d.ts +64 -0
  121. package/dist/shims/url.d.ts.map +1 -0
  122. package/dist/shims/util.d.ts +106 -0
  123. package/dist/shims/util.d.ts.map +1 -0
  124. package/dist/shims/v8.d.ts +73 -0
  125. package/dist/shims/v8.d.ts.map +1 -0
  126. package/dist/shims/vfs-adapter.d.ts +126 -0
  127. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  128. package/dist/shims/vm.d.ts +45 -0
  129. package/dist/shims/vm.d.ts.map +1 -0
  130. package/dist/shims/worker_threads.d.ts +66 -0
  131. package/dist/shims/worker_threads.d.ts.map +1 -0
  132. package/dist/shims/ws.d.ts +66 -0
  133. package/dist/shims/ws.d.ts.map +1 -0
  134. package/dist/shims/zlib.d.ts +161 -0
  135. package/dist/shims/zlib.d.ts.map +1 -0
  136. package/dist/transform.d.ts +24 -0
  137. package/dist/transform.d.ts.map +1 -0
  138. package/dist/virtual-fs.d.ts +226 -0
  139. package/dist/virtual-fs.d.ts.map +1 -0
  140. package/dist/vite-demo.d.ts +35 -0
  141. package/dist/vite-demo.d.ts.map +1 -0
  142. package/dist/vite-sw.js +132 -0
  143. package/dist/worker/runtime-worker.d.ts +8 -0
  144. package/dist/worker/runtime-worker.d.ts.map +1 -0
  145. package/dist/worker-runtime.d.ts +50 -0
  146. package/dist/worker-runtime.d.ts.map +1 -0
  147. package/package.json +85 -0
  148. package/src/ai-chatbot-demo-entry.ts +244 -0
  149. package/src/ai-chatbot-demo.ts +509 -0
  150. package/src/convex-app-demo-entry.ts +1107 -0
  151. package/src/convex-app-demo.ts +1316 -0
  152. package/src/cors-proxy.ts +81 -0
  153. package/src/create-runtime.ts +147 -0
  154. package/src/demo.ts +304 -0
  155. package/src/dev-server.ts +274 -0
  156. package/src/frameworks/next-dev-server.ts +2224 -0
  157. package/src/frameworks/vite-dev-server.ts +702 -0
  158. package/src/index.ts +101 -0
  159. package/src/next-demo.ts +1784 -0
  160. package/src/npm/index.ts +347 -0
  161. package/src/npm/registry.ts +152 -0
  162. package/src/npm/resolver.ts +385 -0
  163. package/src/npm/tarball.ts +209 -0
  164. package/src/runtime-interface.ts +103 -0
  165. package/src/runtime.ts +1046 -0
  166. package/src/sandbox-helpers.ts +173 -0
  167. package/src/sandbox-runtime.ts +252 -0
  168. package/src/server-bridge.ts +426 -0
  169. package/src/shims/assert.ts +664 -0
  170. package/src/shims/async_hooks.ts +86 -0
  171. package/src/shims/buffer.ts +75 -0
  172. package/src/shims/child_process-browser.ts +217 -0
  173. package/src/shims/child_process.ts +463 -0
  174. package/src/shims/chokidar.ts +313 -0
  175. package/src/shims/cluster.ts +67 -0
  176. package/src/shims/crypto.ts +830 -0
  177. package/src/shims/dgram.ts +47 -0
  178. package/src/shims/diagnostics_channel.ts +196 -0
  179. package/src/shims/dns.ts +172 -0
  180. package/src/shims/domain.ts +58 -0
  181. package/src/shims/esbuild.ts +805 -0
  182. package/src/shims/events.ts +195 -0
  183. package/src/shims/fs.ts +803 -0
  184. package/src/shims/fsevents.ts +63 -0
  185. package/src/shims/http.ts +904 -0
  186. package/src/shims/http2.ts +96 -0
  187. package/src/shims/https.ts +86 -0
  188. package/src/shims/inspector.ts +30 -0
  189. package/src/shims/module.ts +82 -0
  190. package/src/shims/net.ts +359 -0
  191. package/src/shims/os.ts +195 -0
  192. package/src/shims/path.ts +199 -0
  193. package/src/shims/perf_hooks.ts +92 -0
  194. package/src/shims/process.ts +346 -0
  195. package/src/shims/querystring.ts +97 -0
  196. package/src/shims/readdirp.ts +228 -0
  197. package/src/shims/readline.ts +110 -0
  198. package/src/shims/rollup.ts +80 -0
  199. package/src/shims/sentry.ts +133 -0
  200. package/src/shims/stream.ts +1126 -0
  201. package/src/shims/tls.ts +95 -0
  202. package/src/shims/tty.ts +64 -0
  203. package/src/shims/url.ts +171 -0
  204. package/src/shims/util.ts +312 -0
  205. package/src/shims/v8.ts +113 -0
  206. package/src/shims/vfs-adapter.ts +402 -0
  207. package/src/shims/vm.ts +83 -0
  208. package/src/shims/worker_threads.ts +111 -0
  209. package/src/shims/ws.ts +382 -0
  210. package/src/shims/zlib.ts +289 -0
  211. package/src/transform.ts +313 -0
  212. package/src/types/external.d.ts +67 -0
  213. package/src/virtual-fs.ts +903 -0
  214. package/src/vite-demo.ts +577 -0
  215. package/src/worker/runtime-worker.ts +128 -0
  216. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * async_hooks shim - Async tracking is not available in browser
3
+ */
4
+
5
+ export class AsyncResource {
6
+ constructor(_type: string, _options?: object) {}
7
+
8
+ runInAsyncScope<T>(fn: (...args: unknown[]) => T, thisArg?: unknown, ...args: unknown[]): T {
9
+ return fn.apply(thisArg, args);
10
+ }
11
+
12
+ emitDestroy(): this { return this; }
13
+ asyncId(): number { return 0; }
14
+ triggerAsyncId(): number { return 0; }
15
+
16
+ static bind<T extends (...args: unknown[]) => unknown>(fn: T, _type?: string): T {
17
+ return fn;
18
+ }
19
+ }
20
+
21
+ export class AsyncLocalStorage<T> {
22
+ private store: T | undefined;
23
+
24
+ disable(): void {}
25
+
26
+ getStore(): T | undefined {
27
+ return this.store;
28
+ }
29
+
30
+ run<R>(store: T, callback: () => R): R {
31
+ const prev = this.store;
32
+ this.store = store;
33
+ try {
34
+ return callback();
35
+ } finally {
36
+ this.store = prev;
37
+ }
38
+ }
39
+
40
+ exit<R>(callback: () => R): R {
41
+ const prev = this.store;
42
+ this.store = undefined;
43
+ try {
44
+ return callback();
45
+ } finally {
46
+ this.store = prev;
47
+ }
48
+ }
49
+
50
+ enterWith(store: T): void {
51
+ this.store = store;
52
+ }
53
+ }
54
+
55
+ export interface AsyncHook {
56
+ enable(): this;
57
+ disable(): this;
58
+ }
59
+
60
+ export function createHook(_callbacks: object): AsyncHook {
61
+ return {
62
+ enable(): AsyncHook { return this; },
63
+ disable(): AsyncHook { return this; },
64
+ };
65
+ }
66
+
67
+ export function executionAsyncId(): number {
68
+ return 0;
69
+ }
70
+
71
+ export function executionAsyncResource(): object {
72
+ return {};
73
+ }
74
+
75
+ export function triggerAsyncId(): number {
76
+ return 0;
77
+ }
78
+
79
+ export default {
80
+ AsyncResource,
81
+ AsyncLocalStorage,
82
+ createHook,
83
+ executionAsyncId,
84
+ executionAsyncResource,
85
+ triggerAsyncId,
86
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Node.js buffer module shim
3
+ * Provides Buffer class for browser environment
4
+ */
5
+
6
+ // Re-export Buffer from stream where it's defined
7
+ import { Buffer as BufferClass } from './stream';
8
+
9
+ // The buffer module exports Buffer as a named export
10
+ export const Buffer = BufferClass;
11
+
12
+ // SlowBuffer is deprecated but some packages still use it
13
+ export const SlowBuffer = BufferClass;
14
+
15
+ // kMaxLength is the maximum size of a Buffer
16
+ export const kMaxLength = 2147483647;
17
+
18
+ // INSPECT_MAX_BYTES controls how many bytes are shown when calling inspect()
19
+ export const INSPECT_MAX_BYTES = 50;
20
+
21
+ // Constants for Buffer pooling
22
+ export const constants = {
23
+ MAX_LENGTH: kMaxLength,
24
+ MAX_STRING_LENGTH: 536870888,
25
+ };
26
+
27
+ // transcode function - simplified
28
+ export function transcode(
29
+ source: Uint8Array,
30
+ _fromEnc: string,
31
+ _toEnc: string
32
+ ): InstanceType<typeof Buffer> {
33
+ // Simplified - just return a copy
34
+ return Buffer.from(source);
35
+ }
36
+
37
+ // resolveObjectURL - returns undefined (no blob support)
38
+ export function resolveObjectURL(id: string): undefined {
39
+ return undefined;
40
+ }
41
+
42
+ // atob and btoa wrappers
43
+ export function atob(data: string): string {
44
+ return globalThis.atob(data);
45
+ }
46
+
47
+ export function btoa(data: string): string {
48
+ return globalThis.btoa(data);
49
+ }
50
+
51
+ // Default export as a plain object with all exports
52
+ // Using Object.create(null) and then assigning doesn't work well,
53
+ // so we use a regular object that has hasOwnProperty
54
+ const bufferModule: Record<string, unknown> = {
55
+ Buffer,
56
+ SlowBuffer,
57
+ kMaxLength,
58
+ INSPECT_MAX_BYTES,
59
+ constants,
60
+ transcode,
61
+ resolveObjectURL,
62
+ atob,
63
+ btoa,
64
+ };
65
+
66
+ // Ensure hasOwnProperty is accessible (should already be from Object.prototype)
67
+ // but we make it explicit
68
+ Object.defineProperty(bufferModule, 'hasOwnProperty', {
69
+ value: Object.prototype.hasOwnProperty,
70
+ enumerable: false,
71
+ configurable: true,
72
+ writable: true,
73
+ });
74
+
75
+ export default bufferModule;
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Browser-compatible child_process shim
3
+ * This version doesn't use just-bash and throws errors for commands
4
+ * Most CLI tools (like Convex CLI) don't actually need shell execution
5
+ */
6
+
7
+ import { EventEmitter } from './events';
8
+ import { Readable, Writable, Buffer } from './stream';
9
+
10
+ export interface ExecOptions {
11
+ cwd?: string;
12
+ env?: Record<string, string>;
13
+ encoding?: BufferEncoding | 'buffer';
14
+ timeout?: number;
15
+ maxBuffer?: number;
16
+ shell?: string | boolean;
17
+ }
18
+
19
+ export interface ExecResult {
20
+ stdout: string | Buffer;
21
+ stderr: string | Buffer;
22
+ }
23
+
24
+ export type ExecCallback = (
25
+ error: Error | null,
26
+ stdout: string | Buffer,
27
+ stderr: string | Buffer
28
+ ) => void;
29
+
30
+ /**
31
+ * Initialize child_process - no-op in browser version
32
+ */
33
+ export function initChildProcess(): void {
34
+ // No-op - just-bash not used in browser version
35
+ }
36
+
37
+ /**
38
+ * Execute a command in a shell
39
+ */
40
+ export function exec(
41
+ command: string,
42
+ optionsOrCallback?: ExecOptions | ExecCallback,
43
+ callback?: ExecCallback
44
+ ): ChildProcess {
45
+ let cb: ExecCallback | undefined;
46
+
47
+ if (typeof optionsOrCallback === 'function') {
48
+ cb = optionsOrCallback;
49
+ } else {
50
+ cb = callback;
51
+ }
52
+
53
+ const child = new ChildProcess();
54
+
55
+ // Execute asynchronously - emit error
56
+ setTimeout(() => {
57
+ const error = new Error(
58
+ `exec is not supported in browser environment: ${command}`
59
+ );
60
+ child.emit('error', error);
61
+ if (cb) cb(error, '', '');
62
+ }, 0);
63
+
64
+ return child;
65
+ }
66
+
67
+ /**
68
+ * Execute a command synchronously
69
+ */
70
+ export function execSync(
71
+ command: string,
72
+ options?: ExecOptions
73
+ ): string | Buffer {
74
+ throw new Error(
75
+ `execSync is not supported in browser environment: ${command}`
76
+ );
77
+ }
78
+
79
+ export interface SpawnOptions {
80
+ cwd?: string;
81
+ env?: Record<string, string>;
82
+ shell?: boolean | string;
83
+ stdio?: 'pipe' | 'inherit' | 'ignore' | Array<'pipe' | 'inherit' | 'ignore'>;
84
+ }
85
+
86
+ /**
87
+ * Spawn a new process
88
+ */
89
+ export function spawn(
90
+ command: string,
91
+ args?: string[] | SpawnOptions,
92
+ options?: SpawnOptions
93
+ ): ChildProcess {
94
+ const child = new ChildProcess();
95
+
96
+ // Execute asynchronously - emit error
97
+ setTimeout(() => {
98
+ const error = new Error(
99
+ `spawn is not supported in browser environment: ${command}`
100
+ );
101
+ child.emit('error', error);
102
+ }, 0);
103
+
104
+ return child;
105
+ }
106
+
107
+ /**
108
+ * Spawn a new process synchronously
109
+ */
110
+ export function spawnSync(
111
+ command: string,
112
+ args?: string[],
113
+ options?: SpawnOptions
114
+ ): { stdout: Buffer; stderr: Buffer; status: number; error?: Error } {
115
+ throw new Error(
116
+ `spawnSync is not supported in browser environment: ${command}`
117
+ );
118
+ }
119
+
120
+ /**
121
+ * Execute a file
122
+ */
123
+ export function execFile(
124
+ file: string,
125
+ args?: string[] | ExecOptions | ExecCallback,
126
+ options?: ExecOptions | ExecCallback,
127
+ callback?: ExecCallback
128
+ ): ChildProcess {
129
+ let cb: ExecCallback | undefined;
130
+
131
+ if (typeof args === 'function') {
132
+ cb = args;
133
+ } else if (typeof options === 'function') {
134
+ cb = options;
135
+ } else {
136
+ cb = callback;
137
+ }
138
+
139
+ const child = new ChildProcess();
140
+
141
+ setTimeout(() => {
142
+ const error = new Error(
143
+ `execFile is not supported in browser environment: ${file}`
144
+ );
145
+ child.emit('error', error);
146
+ if (cb) cb(error, '', '');
147
+ }, 0);
148
+
149
+ return child;
150
+ }
151
+
152
+ /**
153
+ * Fork is not supported in browser
154
+ */
155
+ export function fork(): never {
156
+ throw new Error('fork is not supported in browser environment');
157
+ }
158
+
159
+ /**
160
+ * ChildProcess class
161
+ */
162
+ export class ChildProcess extends EventEmitter {
163
+ pid: number;
164
+ connected: boolean = false;
165
+ killed: boolean = false;
166
+ exitCode: number | null = null;
167
+ signalCode: string | null = null;
168
+ spawnargs: string[] = [];
169
+ spawnfile: string = '';
170
+
171
+ stdin: Writable | null;
172
+ stdout: Readable | null;
173
+ stderr: Readable | null;
174
+
175
+ constructor() {
176
+ super();
177
+ this.pid = Math.floor(Math.random() * 10000) + 1000;
178
+ this.stdin = new Writable();
179
+ this.stdout = new Readable();
180
+ this.stderr = new Readable();
181
+ }
182
+
183
+ kill(signal?: string): boolean {
184
+ this.killed = true;
185
+ this.emit('exit', null, signal || 'SIGTERM');
186
+ return true;
187
+ }
188
+
189
+ disconnect(): void {
190
+ this.connected = false;
191
+ }
192
+
193
+ send(message: unknown, callback?: (error: Error | null) => void): boolean {
194
+ // IPC not supported
195
+ if (callback) callback(new Error('IPC not supported'));
196
+ return false;
197
+ }
198
+
199
+ ref(): this {
200
+ return this;
201
+ }
202
+
203
+ unref(): this {
204
+ return this;
205
+ }
206
+ }
207
+
208
+ export default {
209
+ exec,
210
+ execSync,
211
+ execFile,
212
+ spawn,
213
+ spawnSync,
214
+ fork,
215
+ ChildProcess,
216
+ initChildProcess,
217
+ };