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.
- package/README.md +4 -2
- package/dist/CNAME +1 -0
- package/dist/__sw__.js +80 -84
- package/dist/assets/{runtime-worker-B8_LZkBX.js → runtime-worker-ujGAG2t7.js} +1278 -828
- package/dist/assets/runtime-worker-ujGAG2t7.js.map +1 -0
- package/dist/frameworks/code-transforms.d.ts.map +1 -1
- package/dist/frameworks/next-config-parser.d.ts +16 -0
- package/dist/frameworks/next-config-parser.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +6 -6
- package/dist/frameworks/next-dev-server.d.ts.map +1 -1
- package/dist/frameworks/next-html-generator.d.ts +35 -0
- package/dist/frameworks/next-html-generator.d.ts.map +1 -0
- package/dist/frameworks/next-shims.d.ts +79 -0
- package/dist/frameworks/next-shims.d.ts.map +1 -0
- package/dist/index.cjs +3024 -2465
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +3336 -2787
- package/dist/index.mjs.map +1 -1
- package/dist/og-image.png +0 -0
- package/dist/runtime.d.ts +26 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/server-bridge.d.ts +2 -0
- package/dist/server-bridge.d.ts.map +1 -1
- package/dist/shims/crypto.d.ts +2 -0
- package/dist/shims/crypto.d.ts.map +1 -1
- package/dist/shims/esbuild.d.ts.map +1 -1
- package/dist/shims/fs.d.ts.map +1 -1
- package/dist/shims/http.d.ts +29 -0
- package/dist/shims/http.d.ts.map +1 -1
- package/dist/shims/path.d.ts.map +1 -1
- package/dist/shims/stream.d.ts.map +1 -1
- package/dist/shims/vfs-adapter.d.ts.map +1 -1
- package/dist/shims/ws.d.ts +2 -0
- package/dist/shims/ws.d.ts.map +1 -1
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/package-json.d.ts.map +1 -1
- package/dist/utils/binary-encoding.d.ts +13 -0
- package/dist/utils/binary-encoding.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/convex-app-demo-entry.ts +229 -35
- package/src/frameworks/code-transforms.ts +5 -1
- package/src/frameworks/next-config-parser.ts +140 -0
- package/src/frameworks/next-dev-server.ts +76 -1675
- package/src/frameworks/next-html-generator.ts +597 -0
- package/src/frameworks/next-shims.ts +1050 -0
- package/src/frameworks/tailwind-config-loader.ts +1 -1
- package/src/index.ts +2 -0
- package/src/runtime.ts +271 -25
- package/src/server-bridge.ts +61 -28
- package/src/shims/crypto.ts +13 -0
- package/src/shims/esbuild.ts +4 -1
- package/src/shims/fs.ts +9 -11
- package/src/shims/http.ts +312 -3
- package/src/shims/path.ts +6 -13
- package/src/shims/stream.ts +12 -26
- package/src/shims/vfs-adapter.ts +5 -2
- package/src/shims/ws.ts +95 -2
- package/src/types/package-json.ts +1 -0
- package/src/utils/binary-encoding.ts +43 -0
- package/src/virtual-fs.ts +7 -15
- package/dist/assets/runtime-worker-B8_LZkBX.js.map +0 -1
|
@@ -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
|
-
|
|
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 =
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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
|
}
|