rosetack 0.1.1 → 0.1.3
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/cloudflare/functions/[[path]].ts +61 -0
- package/deploy/cloudflare/wrangler.toml +14 -0
- package/deploy/k8s/rosetack.yaml +107 -0
- package/deploy/netlify/functions/rosetack.ts +38 -0
- package/deploy/netlify.toml +17 -0
- package/devtools/devtools.html +7 -0
- package/devtools/devtools.js +1 -0
- package/devtools/manifest.json +8 -0
- package/devtools/panel.html +28 -0
- package/devtools/panel.js +54 -0
- package/dist-cli/compiler.mjs +1346 -492
- package/dist-cli/edge.mjs +152 -41
- package/dist-cli/rosetack.mjs +1974 -606
- package/dist-cli/runtime.mjs +205 -40
- package/dist-cli/test.mjs +1425 -508
- package/package.json +4 -3
- package/src/FRAMEWORK_VERSION +1 -1
- package/src/cli/edge.ts +76 -61
- package/src/cli/index.ts +516 -293
- package/src/cli/prompt.ts +130 -0
- package/src/cli/shell.ts +113 -65
- package/src/cli/test.ts +9 -70
- package/src/compiler/errors.ts +74 -0
- package/src/compiler/index.ts +1514 -839
- package/src/runtime/index.ts +255 -150
- package/src/types/rosetack.d.ts +18 -59
- package/templates/admin/package.json +14 -0
- package/templates/admin/rosetack.config.js +1 -0
- package/templates/admin/src/pages/_middleware.rose +33 -0
- package/templates/admin/src/pages/api/items.rose +37 -0
- package/templates/admin/src/pages/api/login.rose +25 -0
- package/templates/admin/src/pages/index.rose +79 -0
- package/templates/api/package.json +14 -0
- package/templates/api/rosetack.config.js +1 -0
- package/templates/api/src/pages/api/health.rose +7 -0
- package/templates/api/src/pages/api/items.rose +46 -0
- package/templates/api/src/pages/api/login.rose +24 -0
- package/templates/api/src/pages/index.rose +25 -0
- package/templates/blog/package.json +14 -0
- package/templates/blog/rosetack.config.js +1 -0
- package/templates/blog/src/pages/404.rose +2 -0
- package/templates/blog/src/pages/_layout.rose +42 -0
- package/templates/blog/src/pages/_middleware.rose +74 -0
- package/templates/blog/src/pages/admin.rose +85 -0
- package/templates/blog/src/pages/api/login.rose +46 -0
- package/templates/blog/src/pages/api/posts/[id].rose +37 -0
- package/templates/blog/src/pages/api/posts.rose +72 -0
- package/templates/blog/src/pages/index.rose +31 -0
- package/templates/blog/src/pages/post/[id].rose +36 -0
- package/templates/site/package.json +14 -0
- package/templates/site/rosetack.config.js +1 -0
- package/templates/site/src/pages/404.rose +2 -0
- package/templates/site/src/pages/_layout.rose +40 -0
- package/templates/site/src/pages/about.rose +6 -0
- package/templates/site/src/pages/index.rose +13 -0
- package/templates/site/src/pages/pricing.rose +8 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compiler error shaped for its reader - who is as often an AI agent as a
|
|
3
|
+
* human. Every failure the compiler throws on purpose carries:
|
|
4
|
+
*
|
|
5
|
+
* code a stable identifier (E-EXPORT, E-TEMPLATE, ...) an agent can
|
|
6
|
+
* branch on and a human can grep across a build log
|
|
7
|
+
* file the .rose file (or directory) at fault
|
|
8
|
+
* line the line inside it, when the compiler knows the position
|
|
9
|
+
* hint the fix, in one sentence
|
|
10
|
+
*
|
|
11
|
+
* `rosetack build --json` prints these as a JSON envelope on stdout, so an
|
|
12
|
+
* agent can parse the failure and patch the file without scraping prose.
|
|
13
|
+
* The human output prints the message and the hint. Errors that are NOT
|
|
14
|
+
* RoseErrors (a crash inside a plugin's own code, a framework bug) keep
|
|
15
|
+
* their stack: those are not the developer's to fix from a code alone.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface RoseErrorInfo {
|
|
19
|
+
code: string;
|
|
20
|
+
file?: string;
|
|
21
|
+
line?: number;
|
|
22
|
+
message: string;
|
|
23
|
+
hint?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class RoseError extends Error {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly file?: string;
|
|
29
|
+
readonly line?: number;
|
|
30
|
+
readonly hint?: string;
|
|
31
|
+
|
|
32
|
+
constructor(code: string, message: string, opts: { file?: string; line?: number; hint?: string } = {}) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = 'RoseError';
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.file = opts.file;
|
|
37
|
+
this.line = opts.line;
|
|
38
|
+
this.hint = opts.hint;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
info(): RoseErrorInfo {
|
|
42
|
+
// code -> file -> line -> message -> hint: the order the prompt doc
|
|
43
|
+
// documents, so a reader parsing the envelope finds the location first
|
|
44
|
+
const info = { code: this.code } as RoseErrorInfo;
|
|
45
|
+
if (this.file !== undefined) info.file = this.file;
|
|
46
|
+
if (this.line !== undefined) info.line = this.line;
|
|
47
|
+
info.message = this.message;
|
|
48
|
+
if (this.hint !== undefined) info.hint = this.hint;
|
|
49
|
+
return info;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The 1-based line of `index` inside `src`. */
|
|
54
|
+
export function lineOf(src: string, index: number): number {
|
|
55
|
+
let line = 1;
|
|
56
|
+
const end = Math.min(index, src.length);
|
|
57
|
+
for (let i = 0; i < end; i++) {
|
|
58
|
+
if (src[i] === '\n') line++;
|
|
59
|
+
}
|
|
60
|
+
return line;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The line of a regex match inside `src` - undefined when there is no match
|
|
64
|
+
* (the position is optional on a match array, and the call sites that have
|
|
65
|
+
* one always matched). */
|
|
66
|
+
export function lineAt(src: string, match?: RegExpMatchArray | null): number | undefined {
|
|
67
|
+
return match && match.index !== undefined ? lineOf(src, match.index) : undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Shape any thrown value into the info object the --json envelope prints. */
|
|
71
|
+
export function errorInfo(err: unknown): RoseErrorInfo {
|
|
72
|
+
if (err instanceof RoseError) return err.info();
|
|
73
|
+
return { code: 'E-UNKNOWN', message: err instanceof Error ? err.message : String(err) };
|
|
74
|
+
}
|