rosetack 0.1.1 → 0.1.2
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/deploy/k8s/rosetack.yaml +107 -0
- package/dist-cli/compiler.mjs +577 -96
- package/dist-cli/edge.mjs +46 -11
- package/dist-cli/rosetack.mjs +963 -144
- package/dist-cli/runtime.mjs +94 -10
- package/dist-cli/test.mjs +610 -104
- package/package.json +1 -1
- package/src/FRAMEWORK_VERSION +1 -1
- package/src/cli/edge.ts +9 -2
- package/src/cli/index.ts +349 -41
- package/src/cli/prompt.ts +127 -0
- package/src/cli/shell.ts +59 -9
- package/src/compiler/errors.ts +74 -0
- package/src/compiler/index.ts +729 -124
- package/src/runtime/index.ts +122 -14
- package/src/types/rosetack.d.ts +9 -0
package/dist-cli/edge.mjs
CHANGED
|
@@ -85,13 +85,34 @@ document.addEventListener('submit', (e) => {
|
|
|
85
85
|
e.preventDefault();
|
|
86
86
|
postForm(new FormData(f));
|
|
87
87
|
});
|
|
88
|
+
// Dev seam: the live signal graph, readable as JSON. Two callers, one
|
|
89
|
+
// implementation: the dev server's reload bridge snapshots it before a
|
|
90
|
+
// rebuild-triggered reload so the edit lands on the state the developer had,
|
|
91
|
+
// and a devtools extension reads it the same way. It is the same
|
|
92
|
+
// serializeState the zero-hydration resume already ships, so the only new
|
|
93
|
+
// bytes are the assignment.
|
|
94
|
+
window.__rosetack = { state: () => serializeState() };
|
|
88
95
|
// initial=true: DOM is SSR output, resume state + wire markers (zero hydration).
|
|
89
96
|
// If the document was rendered for a DIFFERENT route (a static-file server's
|
|
90
97
|
// SPA fallback serves index.html for unknown paths), adopt nothing - let the
|
|
91
98
|
// client router render the requested route from scratch.
|
|
92
99
|
const __st = document.getElementById('__rosetack_state');
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
let __state = __st ? JSON.parse(__st.textContent || '{}') : {};
|
|
101
|
+
// The dev server's reload bridge hands the pre-reload signal graph back inside
|
|
102
|
+
// the next document (window.__rosetack_resume). The resumed values win over the
|
|
103
|
+
// fresh render's, but the ROUTE stays the one the server just rendered - and
|
|
104
|
+
// the route renders client-side from the bundle rather than adopting the SSR
|
|
105
|
+
// DOM, because a resumed list can be longer than the document's rows and
|
|
106
|
+
// adoption could not add them. Absent in every non-dev document.
|
|
107
|
+
const __resumed = window.__rosetack_resume ? JSON.parse(window.__rosetack_resume) : null;
|
|
108
|
+
if (__resumed) {
|
|
109
|
+
const __route = __state.__route;
|
|
110
|
+
__state = Object.assign(__state, __resumed);
|
|
111
|
+
__state.__route = __route;
|
|
112
|
+
}
|
|
113
|
+
if (__resumed) {
|
|
114
|
+
start(__app, window.location.pathname);
|
|
115
|
+
} else if (__state.__route === window.location.pathname) {
|
|
95
116
|
start(__app, window.location.pathname, true);
|
|
96
117
|
} else {
|
|
97
118
|
start(__app, window.location.pathname);
|
|
@@ -151,6 +172,7 @@ var STYLES_MIN = STYLES.replace(
|
|
|
151
172
|
function mergeHeadBlocks(blocks) {
|
|
152
173
|
const byKey = /* @__PURE__ */ new Map();
|
|
153
174
|
const order = [];
|
|
175
|
+
const positional = /* @__PURE__ */ new Map();
|
|
154
176
|
const put = (key, html) => {
|
|
155
177
|
if (!byKey.has(key)) {
|
|
156
178
|
byKey.set(key, html);
|
|
@@ -159,11 +181,20 @@ function mergeHeadBlocks(blocks) {
|
|
|
159
181
|
};
|
|
160
182
|
for (const block of blocks) {
|
|
161
183
|
for (const m of block.matchAll(/<title[^>]*>[\s\S]*?<\/title>/gi)) put("title", m[0]);
|
|
162
|
-
for (const m of block.matchAll(/<(
|
|
184
|
+
for (const m of block.matchAll(/<(\w+)((?:\s+[\w:-]+(?:=(?:"[^"]*"|'[^']*'|[^\s"'>]+))?)*)\s*(?:\/>|>([\s\S]*?)<\/\1\s*>|>)/gi)) {
|
|
163
185
|
const tag = m[1].toLowerCase();
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
const
|
|
186
|
+
if (tag === "title") continue;
|
|
187
|
+
const attrs = m[2];
|
|
188
|
+
const keyMatch = attrs.match(/\s(?:name|property|rel|charset)=(?:"([^"]*)"|'([^']*)')/i);
|
|
189
|
+
const idMatch = attrs.match(/\sid=(?:"([^"]*)"|'([^']*)')/i);
|
|
190
|
+
let key;
|
|
191
|
+
if (keyMatch) key = `${tag}:${keyMatch[1] ?? keyMatch[2]}`;
|
|
192
|
+
else if (idMatch) key = `${tag}:${idMatch[1] ?? idMatch[2]}`;
|
|
193
|
+
else {
|
|
194
|
+
key = `${tag}:#${positional.get(tag) ?? 0}`;
|
|
195
|
+
positional.set(tag, (positional.get(tag) ?? 0) + 1);
|
|
196
|
+
}
|
|
197
|
+
const marked = m[0].replace(/^<\w+/, (t) => `${t} data-rosetack-head="${key}"`);
|
|
167
198
|
put(key, marked);
|
|
168
199
|
}
|
|
169
200
|
}
|
|
@@ -202,16 +233,19 @@ function buildShell(ssrHtml, stateJson, client, head = [], styles = getStyles(),
|
|
|
202
233
|
const jsTail = js ? `
|
|
203
234
|
<script type="application/json" id="__rosetack_state">${stateJson}</script>
|
|
204
235
|
${clientTag}` : "";
|
|
236
|
+
const open = js ? '<div id="app">' : "";
|
|
237
|
+
const close = js ? "</div>" : "";
|
|
238
|
+
const shellStyles = js ? `
|
|
239
|
+
<style>${STYLES_MIN}</style>` : "";
|
|
205
240
|
return `<!DOCTYPE html>
|
|
206
241
|
<html lang="${lang}"${dir ? ` dir="${dir}"` : ""}>
|
|
207
242
|
<head>
|
|
208
243
|
<meta charset="UTF-8">
|
|
209
244
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">${headTags}${iconTag}
|
|
210
|
-
${titleTag}
|
|
211
|
-
<style>${STYLES_MIN}</style>${styleTag}
|
|
245
|
+
${titleTag}${shellStyles}${styleTag}
|
|
212
246
|
</head>
|
|
213
247
|
<body>
|
|
214
|
-
|
|
248
|
+
${open}${ssrHtml}${close}${jsTail}
|
|
215
249
|
</body>
|
|
216
250
|
</html>`;
|
|
217
251
|
}
|
|
@@ -245,7 +279,8 @@ async function createEdgeHandler(outDir) {
|
|
|
245
279
|
return headers;
|
|
246
280
|
};
|
|
247
281
|
return async function handle(request) {
|
|
248
|
-
const { pathname } = new URL(request.url);
|
|
282
|
+
const { pathname, searchParams } = new URL(request.url);
|
|
283
|
+
mod.setQuery?.(Object.fromEntries(searchParams));
|
|
249
284
|
const hookCtx = mod.hasRequestHooks || mod.hasResponseHooks ? { request, url: new URL(request.url), method: request.method, pathname, state: {} } : null;
|
|
250
285
|
if (hookCtx) {
|
|
251
286
|
const short = await mod.runRequestHooks(hookCtx);
|
|
@@ -260,7 +295,7 @@ async function createEdgeHandler(outDir) {
|
|
|
260
295
|
return hookCtx ? mod.runResponseHooks(hookCtx, apiRes) : apiRes;
|
|
261
296
|
}
|
|
262
297
|
const form = request.method === "POST" ? await request.formData() : void 0;
|
|
263
|
-
if (!form && !broken.has(pathname) && mod.canStream(pathname) && !mod.isNoJs(pathname)) {
|
|
298
|
+
if (!form && !broken.has(pathname) && !mod.isBuffered?.(pathname) && mod.canStream(pathname) && !mod.isNoJs(pathname)) {
|
|
264
299
|
const nonce2 = mod.cspNonce?.(pathname) ? mintNonce() : "";
|
|
265
300
|
const streamed = new Response(null, {
|
|
266
301
|
status: 200,
|