almostnode 0.2.5 → 0.2.6
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 +1 -1
- package/dist/__sw__.js +25 -16
- package/dist/frameworks/next-dev-server.d.ts +61 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -1
- package/dist/frameworks/tailwind-config-loader.d.ts +32 -0
- package/dist/frameworks/tailwind-config-loader.d.ts.map +1 -0
- package/dist/index.cjs +869 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +845 -27
- package/dist/index.mjs.map +1 -1
- package/dist/macaly-demo.d.ts +42 -0
- package/dist/macaly-demo.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/frameworks/next-dev-server.ts +913 -34
- package/src/frameworks/tailwind-config-loader.ts +206 -0
- package/src/macaly-demo.ts +172 -0
package/LICENSE
CHANGED
package/dist/__sw__.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Service Worker for Mini WebContainers
|
|
3
3
|
* Intercepts fetch requests and routes them to virtual servers
|
|
4
|
-
* Version:
|
|
4
|
+
* Version: 14 - forward ALL requests from virtual context (images, scripts, navigation) to virtual server
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// Communication port with main thread
|
|
@@ -212,26 +212,35 @@ self.addEventListener('fetch', (event) => {
|
|
|
212
212
|
const match = url.pathname.match(/^\/__virtual__\/(\d+)(\/.*)?$/);
|
|
213
213
|
|
|
214
214
|
if (!match) {
|
|
215
|
-
// Not a virtual request - but check if it's
|
|
216
|
-
// This handles plain <a href="/about"> links
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
215
|
+
// Not a virtual request - but check if it's from a virtual context
|
|
216
|
+
// This handles plain <a href="/about"> links and asset requests (images, scripts)
|
|
217
|
+
// that should stay within the virtual server
|
|
218
|
+
const referer = event.request.referrer;
|
|
219
|
+
if (referer) {
|
|
220
|
+
try {
|
|
221
|
+
const refererUrl = new URL(referer);
|
|
222
|
+
const refererMatch = refererUrl.pathname.match(/^\/__virtual__\/(\d+)/);
|
|
223
|
+
if (refererMatch) {
|
|
224
|
+
// Request from within a virtual server context
|
|
225
|
+
const virtualPrefix = refererMatch[0];
|
|
226
|
+
const virtualPort = parseInt(refererMatch[1], 10);
|
|
227
|
+
const targetPath = url.pathname + url.search;
|
|
228
|
+
|
|
229
|
+
if (event.request.mode === 'navigate') {
|
|
230
|
+
// Navigation requests: redirect to include the virtual prefix
|
|
231
|
+
const redirectUrl = url.origin + virtualPrefix + targetPath;
|
|
228
232
|
console.log('[SW] Redirecting navigation from virtual context:', url.pathname, '->', redirectUrl);
|
|
229
233
|
event.respondWith(Response.redirect(redirectUrl, 302));
|
|
230
234
|
return;
|
|
235
|
+
} else {
|
|
236
|
+
// Non-navigation requests (images, scripts, etc.): forward to virtual server
|
|
237
|
+
console.log('[SW] Forwarding resource from virtual context:', url.pathname);
|
|
238
|
+
event.respondWith(handleVirtualRequest(event.request, virtualPort, targetPath));
|
|
239
|
+
return;
|
|
231
240
|
}
|
|
232
|
-
} catch (e) {
|
|
233
|
-
// Invalid referer URL, ignore
|
|
234
241
|
}
|
|
242
|
+
} catch (e) {
|
|
243
|
+
// Invalid referer URL, ignore
|
|
235
244
|
}
|
|
236
245
|
}
|
|
237
246
|
// Not a virtual request, let it pass through
|
|
@@ -16,6 +16,8 @@ export interface NextDevServerOptions extends DevServerOptions {
|
|
|
16
16
|
preferAppRouter?: boolean;
|
|
17
17
|
/** Environment variables (NEXT_PUBLIC_* are available in browser code via process.env) */
|
|
18
18
|
env?: Record<string, string>;
|
|
19
|
+
/** Asset prefix for static files (e.g., '/marketing'). Auto-detected from next.config if not specified. */
|
|
20
|
+
assetPrefix?: string;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* NextDevServer - A lightweight Next.js-compatible development server
|
|
@@ -57,7 +59,31 @@ export declare class NextDevServer extends DevServer {
|
|
|
57
59
|
private options;
|
|
58
60
|
/** Transform result cache for performance */
|
|
59
61
|
private transformCache;
|
|
62
|
+
/** Path aliases from tsconfig.json (e.g., @/* -> ./*) */
|
|
63
|
+
private pathAliases;
|
|
64
|
+
/** Cached Tailwind config script (injected before CDN) */
|
|
65
|
+
private tailwindConfigScript;
|
|
66
|
+
/** Whether Tailwind config has been loaded */
|
|
67
|
+
private tailwindConfigLoaded;
|
|
68
|
+
/** Asset prefix for static files (e.g., '/marketing') */
|
|
69
|
+
private assetPrefix;
|
|
60
70
|
constructor(vfs: VirtualFS, options: NextDevServerOptions);
|
|
71
|
+
/**
|
|
72
|
+
* Load path aliases from tsconfig.json
|
|
73
|
+
* Supports common patterns like @/* -> ./*
|
|
74
|
+
*/
|
|
75
|
+
private loadPathAliases;
|
|
76
|
+
/**
|
|
77
|
+
* Load assetPrefix from options or auto-detect from next.config.ts/js
|
|
78
|
+
* The assetPrefix is used to prefix static asset URLs (e.g., '/marketing')
|
|
79
|
+
*/
|
|
80
|
+
private loadAssetPrefix;
|
|
81
|
+
/**
|
|
82
|
+
* Resolve path aliases in transformed code
|
|
83
|
+
* Converts imports like "@/components/foo" to "/__virtual__/PORT/components/foo"
|
|
84
|
+
* This ensures imports go through the virtual server instead of the main server
|
|
85
|
+
*/
|
|
86
|
+
private resolvePathAliases;
|
|
61
87
|
/**
|
|
62
88
|
* Set an environment variable at runtime
|
|
63
89
|
* NEXT_PUBLIC_* variables will be available via process.env in browser code
|
|
@@ -75,8 +101,14 @@ export declare class NextDevServer extends DevServer {
|
|
|
75
101
|
/**
|
|
76
102
|
* Generate a script tag that defines process.env with NEXT_PUBLIC_* variables
|
|
77
103
|
* This makes environment variables available to browser code via process.env.NEXT_PUBLIC_*
|
|
104
|
+
* Also includes all env variables for Server Component compatibility
|
|
78
105
|
*/
|
|
79
106
|
private generateEnvScript;
|
|
107
|
+
/**
|
|
108
|
+
* Load Tailwind config from tailwind.config.ts and generate a script
|
|
109
|
+
* that configures the Tailwind CDN at runtime
|
|
110
|
+
*/
|
|
111
|
+
private loadTailwindConfigIfNeeded;
|
|
80
112
|
/**
|
|
81
113
|
* Check if App Router is available
|
|
82
114
|
*/
|
|
@@ -89,6 +121,11 @@ export declare class NextDevServer extends DevServer {
|
|
|
89
121
|
* Serve Next.js shims (link, router, head, navigation)
|
|
90
122
|
*/
|
|
91
123
|
private serveNextShim;
|
|
124
|
+
/**
|
|
125
|
+
* Serve route info for client-side navigation
|
|
126
|
+
* Returns params extracted from dynamic route segments
|
|
127
|
+
*/
|
|
128
|
+
private serveRouteInfo;
|
|
92
129
|
/**
|
|
93
130
|
* Serve static assets from /_next/static/
|
|
94
131
|
*/
|
|
@@ -150,6 +187,7 @@ export declare class NextDevServer extends DevServer {
|
|
|
150
187
|
private resolveAppRoute;
|
|
151
188
|
/**
|
|
152
189
|
* Resolve dynamic App Router routes like /app/[id]/page.jsx
|
|
190
|
+
* Also extracts route params from dynamic segments
|
|
153
191
|
*/
|
|
154
192
|
private resolveAppDynamicRoute;
|
|
155
193
|
/**
|
|
@@ -172,6 +210,12 @@ export declare class NextDevServer extends DevServer {
|
|
|
172
210
|
* Serve a basic 404 page
|
|
173
211
|
*/
|
|
174
212
|
private serve404Page;
|
|
213
|
+
/**
|
|
214
|
+
* Try to resolve a file path by adding common extensions
|
|
215
|
+
* e.g., /components/faq -> /components/faq.tsx
|
|
216
|
+
* Also handles index files in directories
|
|
217
|
+
*/
|
|
218
|
+
private resolveFileWithExtension;
|
|
175
219
|
/**
|
|
176
220
|
* Check if a file needs transformation
|
|
177
221
|
*/
|
|
@@ -184,6 +228,14 @@ export declare class NextDevServer extends DevServer {
|
|
|
184
228
|
* Transform JSX/TS code to browser-compatible JavaScript (ESM for browser)
|
|
185
229
|
*/
|
|
186
230
|
private transformCode;
|
|
231
|
+
/**
|
|
232
|
+
* Redirect bare npm package imports to esm.sh CDN
|
|
233
|
+
* e.g., import { Crisp } from "crisp-sdk-web" -> import { Crisp } from "https://esm.sh/crisp-sdk-web?external=react"
|
|
234
|
+
*
|
|
235
|
+
* IMPORTANT: We redirect ALL npm packages to esm.sh URLs (including React)
|
|
236
|
+
* because import maps don't work reliably for dynamically imported modules.
|
|
237
|
+
*/
|
|
238
|
+
private redirectNpmImports;
|
|
187
239
|
/**
|
|
188
240
|
* Strip CSS imports from code (they are loaded via <link> tags instead)
|
|
189
241
|
* Handles: import './styles.css', import '../globals.css', etc.
|
|
@@ -205,6 +257,15 @@ export declare class NextDevServer extends DevServer {
|
|
|
205
257
|
* Handle file change event
|
|
206
258
|
*/
|
|
207
259
|
private handleFileChange;
|
|
260
|
+
/**
|
|
261
|
+
* Override serveFile to wrap JSON files as ES modules
|
|
262
|
+
* This is needed because browsers can't dynamically import raw JSON files
|
|
263
|
+
*/
|
|
264
|
+
protected serveFile(filePath: string): ResponseData;
|
|
265
|
+
/**
|
|
266
|
+
* Resolve a path (helper to access protected method from parent)
|
|
267
|
+
*/
|
|
268
|
+
protected resolvePath(urlPath: string): string;
|
|
208
269
|
/**
|
|
209
270
|
* Stop the server
|
|
210
271
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-dev-server.d.ts","sourceRoot":"","sources":["../../src/frameworks/next-dev-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAa,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"next-dev-server.d.ts","sourceRoot":"","sources":["../../src/frameworks/next-dev-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAa,MAAM,eAAe,CAAC;AACrF,OA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to configure
|
|
5
|
+
* the Tailwind CDN at runtime via window.tailwind.config.
|
|
6
|
+
*/
|
|
7
|
+
import type { VirtualFS } from '../virtual-fs';
|
|
8
|
+
export interface TailwindConfigResult {
|
|
9
|
+
/** JavaScript code to set window.tailwind.config (empty string if no config) */
|
|
10
|
+
configScript: string;
|
|
11
|
+
/** Whether config was successfully loaded */
|
|
12
|
+
success: boolean;
|
|
13
|
+
/** Error message if loading failed */
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Load and parse a Tailwind config file from VirtualFS
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadTailwindConfig(vfs: VirtualFS, root?: string): Promise<TailwindConfigResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Strip TypeScript-specific syntax from config content
|
|
22
|
+
*/
|
|
23
|
+
export declare function stripTypescriptSyntax(content: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Extract the config object from the processed content
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractConfigObject(content: string): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Generate the script to inject the Tailwind config
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateConfigScript(configObject: string): string;
|
|
32
|
+
//# sourceMappingURL=tailwind-config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwind-config-loader.d.ts","sourceRoot":"","sources":["../../src/frameworks/tailwind-config-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC,gFAAgF;IAChF,YAAY,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AASD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,SAAS,EACd,IAAI,GAAE,MAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAyD/B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAwB7D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuElE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOjE"}
|