almostnode 0.2.7 → 0.2.9

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 (64) hide show
  1. package/README.md +4 -2
  2. package/dist/CNAME +1 -0
  3. package/dist/__sw__.js +80 -84
  4. package/dist/assets/{runtime-worker-B8_LZkBX.js → runtime-worker-ujGAG2t7.js} +1278 -828
  5. package/dist/assets/runtime-worker-ujGAG2t7.js.map +1 -0
  6. package/dist/frameworks/code-transforms.d.ts.map +1 -1
  7. package/dist/frameworks/next-config-parser.d.ts +16 -0
  8. package/dist/frameworks/next-config-parser.d.ts.map +1 -0
  9. package/dist/frameworks/next-dev-server.d.ts +6 -6
  10. package/dist/frameworks/next-dev-server.d.ts.map +1 -1
  11. package/dist/frameworks/next-html-generator.d.ts +35 -0
  12. package/dist/frameworks/next-html-generator.d.ts.map +1 -0
  13. package/dist/frameworks/next-shims.d.ts +79 -0
  14. package/dist/frameworks/next-shims.d.ts.map +1 -0
  15. package/dist/index.cjs +3024 -2465
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.mjs +3336 -2787
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/og-image.png +0 -0
  22. package/dist/runtime.d.ts +26 -0
  23. package/dist/runtime.d.ts.map +1 -1
  24. package/dist/server-bridge.d.ts +2 -0
  25. package/dist/server-bridge.d.ts.map +1 -1
  26. package/dist/shims/crypto.d.ts +2 -0
  27. package/dist/shims/crypto.d.ts.map +1 -1
  28. package/dist/shims/esbuild.d.ts.map +1 -1
  29. package/dist/shims/fs.d.ts.map +1 -1
  30. package/dist/shims/http.d.ts +29 -0
  31. package/dist/shims/http.d.ts.map +1 -1
  32. package/dist/shims/path.d.ts.map +1 -1
  33. package/dist/shims/stream.d.ts.map +1 -1
  34. package/dist/shims/vfs-adapter.d.ts.map +1 -1
  35. package/dist/shims/ws.d.ts +2 -0
  36. package/dist/shims/ws.d.ts.map +1 -1
  37. package/dist/types/package-json.d.ts +1 -0
  38. package/dist/types/package-json.d.ts.map +1 -1
  39. package/dist/utils/binary-encoding.d.ts +13 -0
  40. package/dist/utils/binary-encoding.d.ts.map +1 -0
  41. package/dist/virtual-fs.d.ts.map +1 -1
  42. package/package.json +4 -4
  43. package/src/convex-app-demo-entry.ts +229 -35
  44. package/src/frameworks/code-transforms.ts +5 -1
  45. package/src/frameworks/next-config-parser.ts +140 -0
  46. package/src/frameworks/next-dev-server.ts +76 -1675
  47. package/src/frameworks/next-html-generator.ts +597 -0
  48. package/src/frameworks/next-shims.ts +1050 -0
  49. package/src/frameworks/tailwind-config-loader.ts +1 -1
  50. package/src/index.ts +2 -0
  51. package/src/runtime.ts +271 -25
  52. package/src/server-bridge.ts +61 -28
  53. package/src/shims/crypto.ts +13 -0
  54. package/src/shims/esbuild.ts +4 -1
  55. package/src/shims/fs.ts +9 -11
  56. package/src/shims/http.ts +312 -3
  57. package/src/shims/path.ts +6 -13
  58. package/src/shims/stream.ts +12 -26
  59. package/src/shims/vfs-adapter.ts +5 -2
  60. package/src/shims/ws.ts +95 -2
  61. package/src/types/package-json.ts +1 -0
  62. package/src/utils/binary-encoding.ts +43 -0
  63. package/src/virtual-fs.ts +7 -15
  64. package/dist/assets/runtime-worker-B8_LZkBX.js.map +0 -1
@@ -6,6 +6,7 @@ export interface PackageJson {
6
6
  version?: string;
7
7
  main?: string;
8
8
  module?: string;
9
+ browser?: string | Record<string, string | false>;
9
10
  types?: string;
10
11
  exports?: Record<string, unknown> | string;
11
12
  dependencies?: Record<string, string>;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Shared binary encoding utilities.
3
+ * Replaces O(n²) string concatenation patterns used throughout the codebase.
4
+ */
5
+
6
+ const CHUNK = 8192;
7
+
8
+ /** Convert Uint8Array to base64 string */
9
+ export function uint8ToBase64(bytes: Uint8Array): string {
10
+ const parts: string[] = [];
11
+ for (let i = 0; i < bytes.length; i += CHUNK) {
12
+ parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
13
+ }
14
+ return btoa(parts.join(''));
15
+ }
16
+
17
+ /** Convert base64 string to Uint8Array */
18
+ export function base64ToUint8(base64: string): Uint8Array {
19
+ const binary = atob(base64);
20
+ const bytes = new Uint8Array(binary.length);
21
+ for (let i = 0; i < binary.length; i++) {
22
+ bytes[i] = binary.charCodeAt(i);
23
+ }
24
+ return bytes;
25
+ }
26
+
27
+ /** Convert Uint8Array to hex string */
28
+ export function uint8ToHex(bytes: Uint8Array): string {
29
+ const hex = new Array(bytes.length);
30
+ for (let i = 0; i < bytes.length; i++) {
31
+ hex[i] = bytes[i].toString(16).padStart(2, '0');
32
+ }
33
+ return hex.join('');
34
+ }
35
+
36
+ /** Convert Uint8Array to binary (latin1) string */
37
+ export function uint8ToBinaryString(bytes: Uint8Array): string {
38
+ const parts: string[] = [];
39
+ for (let i = 0; i < bytes.length; i += CHUNK) {
40
+ parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
41
+ }
42
+ return parts.join('');
43
+ }
package/src/virtual-fs.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { VFSSnapshot, VFSFileEntry } from './runtime-interface';
6
+ import { uint8ToBase64, base64ToUint8 } from './utils/binary-encoding';
6
7
 
7
8
  export interface FSNode {
8
9
  type: 'file' | 'directory';
@@ -174,11 +175,7 @@ export class VirtualFS {
174
175
  // Encode binary content as base64
175
176
  let content = '';
176
177
  if (node.content && node.content.length > 0) {
177
- let binary = '';
178
- for (let i = 0; i < node.content.length; i++) {
179
- binary += String.fromCharCode(node.content[i]);
180
- }
181
- content = btoa(binary);
178
+ content = uint8ToBase64(node.content);
182
179
  }
183
180
  files.push({ path, type: 'file', content });
184
181
  } else if (node.type === 'directory') {
@@ -199,11 +196,10 @@ export class VirtualFS {
199
196
  const vfs = new VirtualFS();
200
197
 
201
198
  // Sort entries to ensure directories are created before their contents
202
- const sortedFiles = [...snapshot.files].sort((a, b) => {
203
- const aDepth = a.path.split('/').length;
204
- const bDepth = b.path.split('/').length;
205
- return aDepth - bDepth;
206
- });
199
+ const sortedFiles = snapshot.files
200
+ .map((entry, i) => ({ entry, depth: entry.path.split('/').length, i }))
201
+ .sort((a, b) => a.depth - b.depth || a.i - b.i)
202
+ .map(x => x.entry);
207
203
 
208
204
  for (const entry of sortedFiles) {
209
205
  if (entry.path === '/') continue; // Skip root
@@ -214,11 +210,7 @@ export class VirtualFS {
214
210
  // Decode base64 content
215
211
  let content: Uint8Array;
216
212
  if (entry.content) {
217
- const binary = atob(entry.content);
218
- content = new Uint8Array(binary.length);
219
- for (let i = 0; i < binary.length; i++) {
220
- content[i] = binary.charCodeAt(i);
221
- }
213
+ content = base64ToUint8(entry.content);
222
214
  } else {
223
215
  content = new Uint8Array(0);
224
216
  }