rosetack 0.1.2 → 0.1.4

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 (57) hide show
  1. package/deploy/cloudflare/functions/[[path]].ts +61 -0
  2. package/deploy/cloudflare/wrangler.toml +14 -0
  3. package/deploy/netlify/functions/rosetack.ts +38 -0
  4. package/deploy/netlify.toml +17 -0
  5. package/devtools/devtools.html +7 -0
  6. package/devtools/devtools.js +1 -0
  7. package/devtools/manifest.json +8 -0
  8. package/devtools/panel.html +28 -0
  9. package/devtools/panel.js +54 -0
  10. package/dist-cli/compiler.mjs +2194 -561
  11. package/dist-cli/edge.mjs +159 -48
  12. package/dist-cli/rosetack.mjs +2899 -739
  13. package/dist-cli/runtime.mjs +305 -43
  14. package/dist-cli/test.mjs +2332 -630
  15. package/package.json +4 -3
  16. package/src/FRAMEWORK_VERSION +1 -1
  17. package/src/cli/content.ts +186 -0
  18. package/src/cli/edge.ts +78 -62
  19. package/src/cli/image-size.ts +83 -0
  20. package/src/cli/index.ts +391 -334
  21. package/src/cli/prod-server.ts +324 -0
  22. package/src/cli/prompt.ts +51 -20
  23. package/src/cli/shell.ts +105 -74
  24. package/src/cli/test.ts +9 -70
  25. package/src/compiler/index.ts +2107 -913
  26. package/src/runtime/index.ts +367 -168
  27. package/src/types/rosetack.d.ts +16 -66
  28. package/templates/admin/package.json +14 -0
  29. package/templates/admin/rosetack.config.js +1 -0
  30. package/templates/admin/src/pages/_middleware.rose +33 -0
  31. package/templates/admin/src/pages/api/items.rose +37 -0
  32. package/templates/admin/src/pages/api/login.rose +25 -0
  33. package/templates/admin/src/pages/index.rose +79 -0
  34. package/templates/api/package.json +14 -0
  35. package/templates/api/rosetack.config.js +1 -0
  36. package/templates/api/src/pages/api/health.rose +7 -0
  37. package/templates/api/src/pages/api/items.rose +46 -0
  38. package/templates/api/src/pages/api/login.rose +24 -0
  39. package/templates/api/src/pages/index.rose +25 -0
  40. package/templates/blog/package.json +14 -0
  41. package/templates/blog/rosetack.config.js +1 -0
  42. package/templates/blog/src/pages/404.rose +2 -0
  43. package/templates/blog/src/pages/_layout.rose +42 -0
  44. package/templates/blog/src/pages/_middleware.rose +74 -0
  45. package/templates/blog/src/pages/admin.rose +85 -0
  46. package/templates/blog/src/pages/api/login.rose +46 -0
  47. package/templates/blog/src/pages/api/posts/[id].rose +37 -0
  48. package/templates/blog/src/pages/api/posts.rose +72 -0
  49. package/templates/blog/src/pages/index.rose +31 -0
  50. package/templates/blog/src/pages/post/[id].rose +36 -0
  51. package/templates/site/package.json +14 -0
  52. package/templates/site/rosetack.config.js +1 -0
  53. package/templates/site/src/pages/404.rose +2 -0
  54. package/templates/site/src/pages/_layout.rose +40 -0
  55. package/templates/site/src/pages/about.rose +6 -0
  56. package/templates/site/src/pages/index.rose +13 -0
  57. package/templates/site/src/pages/pricing.rose +8 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The rosetack Cloudflare Pages function - the dynamic half of a Pages
3
+ * deploy.
4
+ *
5
+ * Pages answers static assets (everything in dist/: prerendered
6
+ * documents, bundles, baked API bodies) from its own asset server and
7
+ * invokes this function only for the paths that are NOT files. So the
8
+ * split is the same as on every other target - the static half never
9
+ * pays a function invocation, and the dynamic half (dynamic routes, live
10
+ * /api routes, POST server actions) renders here, one request per page.
11
+ *
12
+ * The `[[path]]` filename is Pages' catch-all: this file handles every
13
+ * incoming URL the asset layer did not answer.
14
+ *
15
+ * workerd has NO filesystem, which is the one real difference from the
16
+ * Node targets: the adapter cannot read dist/ at boot. Two things close
17
+ * that gap, both visible below:
18
+ *
19
+ * 1. `import * as server from '../../dist/server.js'` - a STATIC import,
20
+ * so Pages' deploy-time compiler bundles the server module into the
21
+ * function. (The generated bundle has zero Node built-in imports, so
22
+ * it runs on workerd as-is.)
23
+ * 2. the client bundle, the component styles and the broken-route
24
+ * manifest are fetched from this very site once per isolate - they
25
+ * are static assets of the same deployment, and the function only
26
+ * ever sees non-asset paths, so the fetch cannot re-enter it.
27
+ *
28
+ * The CSP is then computed from the exact fetched bytes, identical to what
29
+ * the Node server hashes: same documents, same headers, every target.
30
+ *
31
+ * Install: copy this file to <project>/functions/[[path]].ts and
32
+ * deploy/cloudflare/wrangler.toml to <project>/wrangler.toml, then
33
+ * `npx wrangler pages deploy` (or push, with the Pages git integration).
34
+ * In a project that depends on the published package the import below
35
+ * becomes:
36
+ * import { createEdgeHandler } from 'rosetack/edge';
37
+ */
38
+ import { createEdgeHandler } from '../src/cli/edge.ts';
39
+ import * as server from '../dist/server.js';
40
+
41
+ // Built on the first request this isolate serves, then cached: one cold start, three
42
+ // internal asset fetches, and every later request is the same single-request page.
43
+ let handle: ((request: Request) => Promise<Response>) | null = null;
44
+
45
+ export const onRequest = async (context: { request: Request }): Promise<Response> => {
46
+ if (!handle) {
47
+ const base = new URL(context.request.url);
48
+ const [client, styles, broken] = await Promise.all([
49
+ fetch(new URL('/client.js', base)).then((r) => r.text()),
50
+ fetch(new URL('/styles.css', base)).then((r) => (r.ok ? r.text() : '')),
51
+ fetch(new URL('/broken.json', base)).then((r) => (r.ok ? r.json() : [])),
52
+ ]);
53
+ handle = await createEdgeHandler('./dist', {
54
+ server,
55
+ client,
56
+ styles,
57
+ broken: broken as string[],
58
+ });
59
+ }
60
+ return handle(context.request);
61
+ };
@@ -0,0 +1,14 @@
1
+ # Cloudflare Pages - rosetack. `pages_build_output_dir` makes this file the
2
+ # source of truth for the project, so it lives in the repo next to the app.
3
+ name = "rosetack"
4
+ pages_build_output_dir = "./dist"
5
+
6
+ # The build writes dist/ exactly like every other target; Pages then serves
7
+ # it as static assets and deploys ./functions alongside it.
8
+ [build]
9
+ command = "npm run build"
10
+
11
+ # workerd has no Node filesystem: the function imports the adapter, which
12
+ # imports node:url / node:path. nodejs_compat provides both.
13
+ compatibility_date = "2024-09-23"
14
+ compatibility_flags = ["nodejs_compat"]
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The rosetack Netlify function - the dynamic half of a Netlify deploy.
3
+ *
4
+ * Every request that is NOT a static file in dist/ lands here: dynamic
5
+ * pages (/sign, anything reading getContext() or $store()), /api routes,
6
+ * and POST server actions. Static answers - prerendered documents, the
7
+ * bundles, baked API bodies - are served by the CDN straight from dist/
8
+ * (the `publish` directory) and never touch this code. That split is the
9
+ * whole rosetack story: the static half costs zero function invocations.
10
+ *
11
+ * It reuses the framework's own edge adapter (the same Web-standard fetch
12
+ * handler the edge adapter test exercises) over the built server bundle,
13
+ * on Netlify's Functions v2 Web-standard signature - `export default`
14
+ * taking a Request and returning a Response. Netlify compiles TypeScript
15
+ * entrypoints and their imports, so this file and the adapter it pulls in
16
+ * stay .ts. The Lambda runtime has a filesystem, so `included_files`
17
+ * (`dist/**` in netlify.toml) carries dist/ into the bundle and the
18
+ * adapter reads server.js / client.js from it at boot.
19
+ *
20
+ * Install: copy this file to <project>/netlify/functions/rosetack.ts and
21
+ * deploy/netlify.toml to <project>/netlify.toml, then push (or
22
+ * `netlify deploy --prod`). In a project that depends on the published
23
+ * package the import below becomes:
24
+ * import { createEdgeHandler } from 'rosetack/edge';
25
+ */
26
+ import { createEdgeHandler } from '../../src/cli/edge.ts';
27
+ import { fileURLToPath } from 'node:url';
28
+
29
+ // dist/ two levels up from netlify/functions/, whatever the working directory is. Built on
30
+ // the first request (a cold start reads the files once per isolate) and cached for the …
31
+ let handle: ((request: Request) => Promise<Response>) | null = null;
32
+
33
+ export default async function rosetack(request: Request): Promise<Response> {
34
+ if (!handle) {
35
+ handle = await createEdgeHandler(fileURLToPath(new URL('../../dist', import.meta.url)));
36
+ }
37
+ return handle(request);
38
+ }
@@ -0,0 +1,17 @@
1
+ [build]
2
+ command = "npm run build"
3
+ publish = "dist"
4
+
5
+ [functions]
6
+ directory = "netlify/functions"
7
+ included_files = ["dist/**"]
8
+
9
+ # Netlify answers the publish directory first, so a prerendered document, a
10
+ # bundle or a baked API body is served by the CDN and never invokes the
11
+ # function. Everything else - dynamic routes, live /api routes, POST server
12
+ # actions - falls through to the catch-all below (status 200 = rewrite, not
13
+ # redirect; the browser keeps its URL).
14
+ [[redirects]]
15
+ from = "/*"
16
+ to = "/.netlify/functions/rosetack"
17
+ status = 200
@@ -0,0 +1,7 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><meta charset="utf-8"><title>rosetack Devtools</title></head>
4
+ <body>
5
+ <script src="devtools.js"></script>
6
+ </body>
7
+ </html>
@@ -0,0 +1 @@
1
+ chrome.devtools.panels.create('rosetack', null, 'panel.html');
@@ -0,0 +1,8 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "rosetack Devtools",
4
+ "version": "0.0.8",
5
+ "description": "The live signal graph and prefetch counters of a rosetack page - the same JSON the zero-hydration resume ships.",
6
+ "devtools_page": "devtools.html",
7
+ "minimum_chrome_version": "114"
8
+ }
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>RoseTack</title>
6
+ <style>
7
+ :root { color-scheme: light dark; }
8
+ body { font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; padding: 10px; }
9
+ h2 { font: 600 11px/1 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em;
10
+ opacity: .6; margin: 14px 0 6px; }
11
+ h2:first-child { margin-top: 0; }
12
+ #url { font-weight: 600; }
13
+ pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
14
+ .dim { opacity: .55; }
15
+ .bar { display: flex; gap: 14px; flex-wrap: wrap; }
16
+ .bar b { font-weight: 600; }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <h2>Page</h2>
21
+ <div id="url" class="dim">reading&hellip;</div>
22
+ <h2>Signal graph <span class="dim">(window.__rosetack.state())</span></h2>
23
+ <pre id="state" class="dim">&hellip;</pre>
24
+ <h2>Prefetch <span class="dim">(window.__rosetack.prefetch())</span></h2>
25
+ <pre id="prefetch" class="dim">&hellip;</pre>
26
+ <script src="panel.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,54 @@
1
+ (() => {
2
+ const url = document.getElementById('url');
3
+ const stateEl = document.getElementById('state');
4
+ const prefetchEl = document.getElementById('prefetch');
5
+
6
+ const READ = `(function () {
7
+ var r = window.__rosetack;
8
+ if (!r || typeof r.state !== 'function') return JSON.stringify({ rosetack: false });
9
+ var out = { rosetack: true, url: location.pathname };
10
+ try { out.state = JSON.parse(r.state()); } catch (e) { out.state = '(unreadable: ' + e + ')'; }
11
+ try { out.prefetch = typeof r.prefetch === 'function' ? r.prefetch() : null; }
12
+ catch (e) { out.prefetch = '(unreadable: ' + e + ')'; }
13
+ return JSON.stringify(out);
14
+ })()`;
15
+
16
+ const show = (el, value, dim) => {
17
+ el.textContent = typeof value === 'string' ? value : JSON.stringify(value, null, 2);
18
+ el.classList.toggle('dim', !!dim);
19
+ };
20
+
21
+ let alive = true;
22
+ window.addEventListener('unload', () => { alive = false; });
23
+
24
+ const read = () => {
25
+ if (!alive) return;
26
+ chrome.devtools.inspectedWindow.eval(READ, (result, exception) => {
27
+ if (!alive) return;
28
+ if (exception || !result) {
29
+ url.textContent = exception ? `evaluation failed: ${exception.description || exception.code}` : 'no page';
30
+ url.classList.add('dim');
31
+ return;
32
+ }
33
+ let data;
34
+ try { data = JSON.parse(result); } catch { return; }
35
+ url.classList.remove('dim');
36
+ if (!data.rosetack) {
37
+ url.textContent = data.url || '(unknown)';
38
+ stateEl.textContent = 'no rosetack runtime in this document - a zero-JS route (the compiler ships no bundle) or a page this framework did not render';
39
+ stateEl.classList.add('dim');
40
+ prefetchEl.textContent = '-';
41
+ prefetchEl.classList.add('dim');
42
+ return;
43
+ }
44
+ url.textContent = data.url;
45
+ const entries = data.state && typeof data.state === 'object' ? Object.keys(data.state) : [];
46
+ show(stateEl, data.state, entries.length === 0);
47
+ if (entries.length === 0) stateEl.textContent = '(no signals yet - the route declares none, or none have been read)';
48
+ show(prefetchEl, data.prefetch ?? '(the seam answered nothing)', data.prefetch == null);
49
+ });
50
+ };
51
+
52
+ read();
53
+ setInterval(read, 1000);
54
+ })();