@pyreon/compiler 0.24.5 → 0.24.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/package.json +11 -13
- package/src/defer-inline.ts +0 -686
- package/src/event-names.ts +0 -65
- package/src/index.ts +0 -61
- package/src/island-audit.ts +0 -675
- package/src/jsx.ts +0 -2792
- package/src/load-native.ts +0 -156
- package/src/lpih.ts +0 -270
- package/src/manifest.ts +0 -280
- package/src/project-scanner.ts +0 -214
- package/src/pyreon-intercept.ts +0 -1029
- package/src/react-intercept.ts +0 -1217
- package/src/reactivity-lens.ts +0 -190
- package/src/ssg-audit.ts +0 -513
- package/src/test-audit.ts +0 -435
- package/src/tests/backend-parity-r7-r9.test.ts +0 -91
- package/src/tests/backend-prop-derived-callback-divergence.test.ts +0 -74
- package/src/tests/collapse-bail-census.test.ts +0 -330
- package/src/tests/collapse-key-source-hygiene.test.ts +0 -88
- package/src/tests/component-child-no-wrap.test.ts +0 -204
- package/src/tests/defer-inline.test.ts +0 -387
- package/src/tests/depth-stress.test.ts +0 -16
- package/src/tests/detector-tag-consistency.test.ts +0 -101
- package/src/tests/dynamic-collapse-detector.test.ts +0 -164
- package/src/tests/dynamic-collapse-emit.test.ts +0 -192
- package/src/tests/dynamic-collapse-scan.test.ts +0 -111
- package/src/tests/element-valued-const-child.test.ts +0 -61
- package/src/tests/falsy-child-characterization.test.ts +0 -48
- package/src/tests/island-audit.test.ts +0 -524
- package/src/tests/jsx.test.ts +0 -2908
- package/src/tests/load-native.test.ts +0 -53
- package/src/tests/lpih.test.ts +0 -404
- package/src/tests/malformed-input-resilience.test.ts +0 -50
- package/src/tests/manifest-snapshot.test.ts +0 -55
- package/src/tests/native-equivalence.test.ts +0 -924
- package/src/tests/partial-collapse-detector.test.ts +0 -121
- package/src/tests/partial-collapse-emit.test.ts +0 -104
- package/src/tests/partial-collapse-robustness.test.ts +0 -53
- package/src/tests/project-scanner.test.ts +0 -269
- package/src/tests/prop-derived-shadow.test.ts +0 -96
- package/src/tests/pure-call-reactive-args.test.ts +0 -50
- package/src/tests/pyreon-intercept.test.ts +0 -816
- package/src/tests/r13-callback-stmt-equivalence.test.ts +0 -58
- package/src/tests/r14-ssr-mode-parity.test.ts +0 -51
- package/src/tests/r15-elemconst-propderived.test.ts +0 -47
- package/src/tests/r19-defer-inline-robust.test.ts +0 -54
- package/src/tests/r20-backend-equivalence-sweep.test.ts +0 -50
- package/src/tests/react-intercept.test.ts +0 -1104
- package/src/tests/reactivity-lens.test.ts +0 -170
- package/src/tests/rocketstyle-collapse.test.ts +0 -208
- package/src/tests/runtime/control-flow.test.ts +0 -159
- package/src/tests/runtime/dom-properties.test.ts +0 -138
- package/src/tests/runtime/events.test.ts +0 -301
- package/src/tests/runtime/harness.ts +0 -94
- package/src/tests/runtime/pr-352-shapes.test.ts +0 -121
- package/src/tests/runtime/reactive-props.test.ts +0 -81
- package/src/tests/runtime/signals.test.ts +0 -129
- package/src/tests/runtime/whitespace.test.ts +0 -106
- package/src/tests/signal-autocall-shadow.test.ts +0 -86
- package/src/tests/sourcemap-fidelity.test.ts +0 -77
- package/src/tests/ssg-audit.test.ts +0 -402
- package/src/tests/static-text-baking.test.ts +0 -64
- package/src/tests/test-audit.test.ts +0 -549
- package/src/tests/transform-state-isolation.test.ts +0 -49
package/src/manifest.ts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { defineManifest } from '@pyreon/manifest'
|
|
2
|
-
|
|
3
|
-
export default defineManifest({
|
|
4
|
-
name: '@pyreon/compiler',
|
|
5
|
-
title: 'JSX Reactive Transform',
|
|
6
|
-
tagline:
|
|
7
|
-
'JSX reactive transform (Rust native + JS fallback) plus the Reactivity-Lens sidecar, React→Pyreon migration, and project audits',
|
|
8
|
-
description:
|
|
9
|
-
"Pyreon's JSX-to-reactive transform. `transformJSX` dispatches to a Rust native binary (napi-rs, 3.7-8.9× faster) and falls back per-call to the pure-JS `transformJSX_JS` when the binary is unavailable (CI, WASM, wrong platform); the two backends are asserted byte-identical by 180+ cross-backend equivalence tests. Emits `_tpl()` (cloneNode templates) + per-text-node `_bind()`, hoists static JSX, inlines `const`-from-`props`, and auto-calls bare signal references in JSX. Also ships the experimental Reactivity-Lens sidecar (`analyzeReactivity` — surfaces the compiler's own per-expression reactive/static decision back to editors), React-pattern detection + one-shot migration, the Pyreon anti-pattern detector behind the MCP `validate` tool, and the syntactic project audits powering `pyreon doctor` (test-environment / islands / SSG).",
|
|
10
|
-
category: 'universal',
|
|
11
|
-
features: [
|
|
12
|
-
'Dual-backend transformJSX — Rust native (napi-rs) with automatic per-call JS fallback, byte-identical output',
|
|
13
|
-
'Reactivity-Lens: analyzeReactivity / formatReactivityLens surface the compiler’s reactive-vs-static decision (experimental)',
|
|
14
|
-
'Scope-aware signal auto-call: bare {count} → {() => count()}, shadowing-correct, knownSignals seeds cross-module',
|
|
15
|
-
'detectReactPatterns + migrateReactCode — "coming from React" diagnostics + one-shot codemod',
|
|
16
|
-
'detectPyreonPatterns — 14 "using Pyreon wrong" anti-pattern codes (the MCP validate detector)',
|
|
17
|
-
'Project audits: auditTestEnvironment / auditIslands / auditSsg (power pyreon doctor)',
|
|
18
|
-
'transformDeferInline — <Defer> namespace-import inlining pass',
|
|
19
|
-
'generateContext — project scanner producing the AI .pyreon/context.json',
|
|
20
|
-
],
|
|
21
|
-
api: [
|
|
22
|
-
{
|
|
23
|
-
name: 'transformJSX',
|
|
24
|
-
kind: 'function',
|
|
25
|
-
signature:
|
|
26
|
-
'transformJSX(code: string, filename?: string, options?: TransformOptions): TransformResult',
|
|
27
|
-
summary:
|
|
28
|
-
'The production entry point. Tries the Rust native binary first (3.7-8.9× faster) and falls back per-call to `transformJSX_JS` inside a try/catch so a native panic never crashes the Vite dev server. Output (`{ code, usesTemplates?, warnings, reactivityLens? }`) is byte-identical across both backends. `options.ssr` skips the `_tpl()` template optimization so `@pyreon/runtime-server` can walk the VNode tree; `options.knownSignals` seeds cross-module signal auto-call; `options.reactivityLens` collects the additive `ReactivitySpan[]` sidecar (codegen is byte-identical whether or not it is collected).',
|
|
29
|
-
example: `import { transformJSX } from "@pyreon/compiler"
|
|
30
|
-
|
|
31
|
-
const { code, warnings } = transformJSX(
|
|
32
|
-
"export const App = () => <div>{count()}</div>",
|
|
33
|
-
"App.tsx",
|
|
34
|
-
{ knownSignals: ["count"] },
|
|
35
|
-
)`,
|
|
36
|
-
mistakes: [
|
|
37
|
-
'Expecting `transformJSX` to throw on a native panic — it never does; it silently falls back to the JS backend (correctness-equivalent, just slower)',
|
|
38
|
-
'Passing user component source WITHOUT `ssr: true` when feeding the result to `@pyreon/runtime-server` — SSR needs the `h()` VNode tree, not `_tpl()` clone templates',
|
|
39
|
-
'Assuming bare `{count}` is auto-called for an IMPORTED signal without seeding `knownSignals` — the compiler only tracks `const count = signal(...)` declared in the same file unless told otherwise',
|
|
40
|
-
],
|
|
41
|
-
seeAlso: ['transformJSX_JS', 'analyzeReactivity'],
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'transformJSX_JS',
|
|
45
|
-
kind: 'function',
|
|
46
|
-
signature:
|
|
47
|
-
'transformJSX_JS(code: string, filename?: string, options?: TransformOptions): TransformResult',
|
|
48
|
-
summary:
|
|
49
|
-
'The pure-JS reactive pass (parses via `oxc-parser`). Same signature and byte-identical output to the native path — `transformJSX` calls it as the fallback. Call it directly only when you need backend-deterministic output (the Reactivity-Lens forces this path so the sidecar is always emitted regardless of whether the native binary is installed).',
|
|
50
|
-
example: `import { transformJSX_JS } from "@pyreon/compiler"
|
|
51
|
-
|
|
52
|
-
// Backend-deterministic — never dispatches to the native binary.
|
|
53
|
-
const { code } = transformJSX_JS("<div>{name()}</div>", "x.tsx")`,
|
|
54
|
-
seeAlso: ['transformJSX'],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: 'analyzeReactivity',
|
|
58
|
-
kind: 'function',
|
|
59
|
-
signature:
|
|
60
|
-
"analyzeReactivity(code: string, filename?: string, options?: { knownSignals?: string[] }): AnalyzeReactivityResult",
|
|
61
|
-
summary:
|
|
62
|
-
"Reactivity-Lens entry point (experimental). The compiler ALREADY decides per-expression whether code is reactive while emitting codegen; this surfaces that ground truth back to the author instead of discarding it. Returns `{ findings, spans }` — `findings` merges the structural codegen decisions (`reactive` / `reactive-prop` / `reactive-attr` / `static-text` / `hoisted-static`) with the EXISTING `detectPyreonPatterns` footguns (`kind: 'footgun'`, carrying the detector `code`) under one (line, column)-sorted taxonomy. Forces the JS backend so the sidecar is always present. Absence of a span is “not asserted”, never an implicit static claim.",
|
|
63
|
-
example: `import { analyzeReactivity, formatReactivityLens } from "@pyreon/compiler"
|
|
64
|
-
|
|
65
|
-
const result = analyzeReactivity(
|
|
66
|
-
"const A = (props) => <div>{props.name}</div>",
|
|
67
|
-
"A.tsx",
|
|
68
|
-
)
|
|
69
|
-
for (const f of result.findings) console.log(f.line, f.kind, f.detail)
|
|
70
|
-
console.log(formatReactivityLens(code, result)) // annotated-source debug view`,
|
|
71
|
-
mistakes: [
|
|
72
|
-
'Treating the absence of a span as a static guarantee — the Lens is asymmetric: positive spans are RECORDS of a codegen branch; silence means "not analyzed", not "proven static"',
|
|
73
|
-
'Expecting it to reflect the native backend — it deliberately forces `transformJSX_JS`; codegen is byte-identical so the analysis is sound, native just does not emit the sidecar at production bundle time (it is an editor-only feature)',
|
|
74
|
-
'Calling it on a hot build path — it is an authoring-time / LSP tool, not part of the production transform pipeline',
|
|
75
|
-
],
|
|
76
|
-
stability: 'experimental',
|
|
77
|
-
seeAlso: ['formatReactivityLens', 'detectPyreonPatterns', 'transformJSX_JS'],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'formatReactivityLens',
|
|
81
|
-
kind: 'function',
|
|
82
|
-
signature:
|
|
83
|
-
'formatReactivityLens(code: string, result: AnalyzeReactivityResult): string',
|
|
84
|
-
summary:
|
|
85
|
-
'Renders an `analyzeReactivity` result as an annotated-source CLI / debug view — each spanned expression gets an inline `live` / `static` / `live·prop` / `hoisted` / footgun tag. The LSP surface in `@pyreon/lint --lsp` consumes the structured `findings` directly (inlay hints + diagnostics); this string renderer is for terminals and bug reports.',
|
|
86
|
-
example: `import { analyzeReactivity, formatReactivityLens } from "@pyreon/compiler"
|
|
87
|
-
|
|
88
|
-
const r = analyzeReactivity(src, "App.tsx")
|
|
89
|
-
process.stdout.write(formatReactivityLens(src, r))`,
|
|
90
|
-
stability: 'experimental',
|
|
91
|
-
seeAlso: ['analyzeReactivity'],
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: 'detectReactPatterns',
|
|
95
|
-
kind: 'function',
|
|
96
|
-
signature:
|
|
97
|
-
"detectReactPatterns(code: string, filename?: string): ReactDiagnostic[]",
|
|
98
|
-
summary:
|
|
99
|
-
'AST-based detector for "coming from React" mistakes — `useState` / `useEffect`, `className` / `htmlFor`, `onChange` on inputs, `.value` writes on signals, React-package imports. Pairs with `detectPyreonPatterns` inside the MCP `validate` tool; the merged result is sorted by line + column.',
|
|
100
|
-
example: `import { detectReactPatterns } from "@pyreon/compiler"
|
|
101
|
-
|
|
102
|
-
const diags = detectReactPatterns("const [n,setN] = useState(0)", "x.tsx")
|
|
103
|
-
console.log(diags[0]?.code) // "react-use-state"`,
|
|
104
|
-
seeAlso: ['migrateReactCode', 'detectPyreonPatterns', 'hasReactPatterns'],
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: 'migrateReactCode',
|
|
108
|
-
kind: 'function',
|
|
109
|
-
signature:
|
|
110
|
-
"migrateReactCode(code: string, filename?: string): MigrationResult",
|
|
111
|
-
summary:
|
|
112
|
-
'One-shot React→Pyreon codemod — `useState`→`signal`, `useEffect`→`effect`/`onMount`, `className`→`class`, etc. Returns the rewritten code plus the list of applied `MigrationChange`s. Mechanical only: shapes it cannot safely rewrite are left as `detectReactPatterns` diagnostics for the human.',
|
|
113
|
-
example: `import { migrateReactCode } from "@pyreon/compiler"
|
|
114
|
-
|
|
115
|
-
const { code, changes } = migrateReactCode(reactSource, "C.tsx")`,
|
|
116
|
-
seeAlso: ['detectReactPatterns'],
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'hasReactPatterns',
|
|
120
|
-
kind: 'function',
|
|
121
|
-
signature: 'hasReactPatterns(code: string): boolean',
|
|
122
|
-
summary:
|
|
123
|
-
'Fast regex pre-filter — returns whether `code` is worth a full `detectReactPatterns` AST walk. Cheap gate for batch scanners; never reports diagnostics itself.',
|
|
124
|
-
example: `import { hasReactPatterns, detectReactPatterns } from "@pyreon/compiler"
|
|
125
|
-
|
|
126
|
-
if (hasReactPatterns(src)) report(detectReactPatterns(src, file))`,
|
|
127
|
-
seeAlso: ['detectReactPatterns'],
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: 'diagnoseError',
|
|
131
|
-
kind: 'function',
|
|
132
|
-
signature: 'diagnoseError(error: string): ErrorDiagnosis | null',
|
|
133
|
-
summary:
|
|
134
|
-
'Maps a raw runtime/build error string to a structured `ErrorDiagnosis` (likely cause + actionable fix) for known Pyreon failure shapes. Returns `null` when the error is unrecognised — callers fall back to the raw message.',
|
|
135
|
-
example: `import { diagnoseError } from "@pyreon/compiler"
|
|
136
|
-
|
|
137
|
-
const d = diagnoseError("props.when is not a function")
|
|
138
|
-
if (d) console.log(d.cause, d.fix)`,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: 'detectPyreonPatterns',
|
|
142
|
-
kind: 'function',
|
|
143
|
-
signature:
|
|
144
|
-
"detectPyreonPatterns(code: string, filename?: string): PyreonDiagnostic[]",
|
|
145
|
-
summary:
|
|
146
|
-
'AST-based (TypeScript compiler API) detector for "using Pyreon wrong" mistakes — 14 codes today (`for-missing-by`, `for-with-key`, `props-destructured`, `props-destructured-body`, `process-dev-gate`, `empty-theme`, `raw-add-event-listener`, `raw-remove-event-listener`, `date-math-random-id`, `on-click-undefined`, `signal-write-as-call`, `static-return-null-conditional`, `as-unknown-as-vnodechild`, `island-never-with-registry-entry`). The detector arm behind the MCP `validate` tool and `pyreon doctor --check-pyreon-patterns`. Every diagnostic reports `fixable: false` (invariant — no `migrate_pyreon` codemod ships yet).',
|
|
147
|
-
example: `import { detectPyreonPatterns } from "@pyreon/compiler"
|
|
148
|
-
|
|
149
|
-
const diags = detectPyreonPatterns(
|
|
150
|
-
"const A = (props) => { const { x } = props; return <i>{x}</i> }",
|
|
151
|
-
"A.tsx",
|
|
152
|
-
)
|
|
153
|
-
console.log(diags[0]?.code) // "props-destructured-body"`,
|
|
154
|
-
mistakes: [
|
|
155
|
-
'Reading `fixable` as sometimes-true — it is an enforced `false` invariant for every Pyreon code; wiring auto-fix UX off it applies nothing',
|
|
156
|
-
'Expecting it to flag `const { x } = props.nested` or an `onMount`-scoped destructure — `props-destructured-body` is deliberately scoped to the canonical `= props` body-scope shape for zero false positives',
|
|
157
|
-
],
|
|
158
|
-
seeAlso: ['hasPyreonPatterns', 'detectReactPatterns', 'analyzeReactivity'],
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: 'hasPyreonPatterns',
|
|
162
|
-
kind: 'function',
|
|
163
|
-
signature: 'hasPyreonPatterns(code: string): boolean',
|
|
164
|
-
summary:
|
|
165
|
-
'Fast regex pre-filter for `detectPyreonPatterns` — deliberately loose (the AST walker is the precise gate); only has to avoid skipping a file that might contain a pattern.',
|
|
166
|
-
example: `import { hasPyreonPatterns, detectPyreonPatterns } from "@pyreon/compiler"
|
|
167
|
-
|
|
168
|
-
if (hasPyreonPatterns(src)) report(detectPyreonPatterns(src, file))`,
|
|
169
|
-
seeAlso: ['detectPyreonPatterns'],
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
name: 'auditTestEnvironment',
|
|
173
|
-
kind: 'function',
|
|
174
|
-
signature: 'auditTestEnvironment(startDir: string): TestAuditResult',
|
|
175
|
-
summary:
|
|
176
|
-
'Scans every `*.test.ts(x)` under `startDir` for the mock-vnode anti-pattern (constructing `{ type, props, children }` literals or a `vnode()` helper instead of going through real `h()`), the bug class behind PR #197’s silent metadata drop. Classifies each file HIGH / MEDIUM / LOW. Powers the MCP `audit_test_environment` tool and `pyreon doctor --audit-tests`.',
|
|
177
|
-
example: `import { auditTestEnvironment, formatTestAudit } from "@pyreon/compiler"
|
|
178
|
-
|
|
179
|
-
const r = auditTestEnvironment(process.cwd())
|
|
180
|
-
console.log(formatTestAudit(r, { minRisk: "high" }))`,
|
|
181
|
-
seeAlso: ['formatTestAudit', 'auditIslands', 'auditSsg'],
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
name: 'formatTestAudit',
|
|
185
|
-
kind: 'function',
|
|
186
|
-
signature:
|
|
187
|
-
'formatTestAudit(result: TestAuditResult, options?: AuditFormatOptions): string',
|
|
188
|
-
summary:
|
|
189
|
-
'Human-readable renderer for an `auditTestEnvironment` result; `options.minRisk` filters the floor (`high` | `medium` | `low`). The CLI / MCP surfaces also have a JSON path — this is the text view.',
|
|
190
|
-
example: `import { auditTestEnvironment, formatTestAudit } from "@pyreon/compiler"
|
|
191
|
-
|
|
192
|
-
console.log(formatTestAudit(auditTestEnvironment("."), { minRisk: "medium" }))`,
|
|
193
|
-
seeAlso: ['auditTestEnvironment'],
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: 'auditIslands',
|
|
197
|
-
kind: 'function',
|
|
198
|
-
signature: 'auditIslands(rootDir: string): IslandAuditResult',
|
|
199
|
-
summary:
|
|
200
|
-
'Project-wide syntactic island audit — five cross-file detectors (`duplicate-name`, `never-with-registry-entry`, `registry-mismatch`, `nested-island`, `dead-island`) that auto-registry and the per-file detector cannot reach. No type-check pass / module resolution; entirely TypeScript-compiler-API syntactic. Powers `pyreon doctor --check-islands` + the MCP `audit_islands` tool.',
|
|
201
|
-
example: `import { auditIslands, formatIslandAudit } from "@pyreon/compiler"
|
|
202
|
-
|
|
203
|
-
const r = auditIslands(process.cwd())
|
|
204
|
-
for (const f of r.findings) console.log(f.code, f.location.file)`,
|
|
205
|
-
seeAlso: ['formatIslandAudit', 'auditTestEnvironment', 'auditSsg'],
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: 'formatIslandAudit',
|
|
209
|
-
kind: 'function',
|
|
210
|
-
signature:
|
|
211
|
-
'formatIslandAudit(result: IslandAuditResult, options?: IslandAuditFormatOptions): string',
|
|
212
|
-
summary:
|
|
213
|
-
'Text renderer for an `auditIslands` result — each finding with file path + line/column + an actionable fix suggestion. The `--json` CLI path bypasses this for CI gates.',
|
|
214
|
-
example: `import { auditIslands, formatIslandAudit } from "@pyreon/compiler"
|
|
215
|
-
|
|
216
|
-
console.log(formatIslandAudit(auditIslands(".")))`,
|
|
217
|
-
seeAlso: ['auditIslands'],
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: 'auditSsg',
|
|
221
|
-
kind: 'function',
|
|
222
|
-
signature: 'auditSsg(rootDir: string): SsgAuditResult',
|
|
223
|
-
summary:
|
|
224
|
-
'Project-wide syntactic SSG audit — three detectors: `404-outside-layout-dir` (`_404.tsx` not co-located with `_layout.tsx` → no layout chrome), `dynamic-route-missing-get-static-paths` (`[id].tsx` without `getStaticPaths` → silently skipped by SSG auto-detect), `non-literal-revalidate-export` (`export const revalidate = TTL` → dropped from the build-time ISR manifest). API routes (`src/routes/api/` or no `export default`) are skipped. Powers `pyreon doctor --check-ssg`.',
|
|
225
|
-
example: `import { auditSsg, formatSsgAudit } from "@pyreon/compiler"
|
|
226
|
-
|
|
227
|
-
const r = auditSsg(process.cwd())
|
|
228
|
-
for (const f of r.findings) console.log(f.code, f.location.file)`,
|
|
229
|
-
seeAlso: ['formatSsgAudit', 'auditIslands'],
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: 'formatSsgAudit',
|
|
233
|
-
kind: 'function',
|
|
234
|
-
signature:
|
|
235
|
-
'formatSsgAudit(result: SsgAuditResult, options?: SsgAuditFormatOptions): string',
|
|
236
|
-
summary:
|
|
237
|
-
'Text renderer for an `auditSsg` result — file path + line/column + actionable fix per finding. CI gates use the JSON path instead.',
|
|
238
|
-
example: `import { auditSsg, formatSsgAudit } from "@pyreon/compiler"
|
|
239
|
-
|
|
240
|
-
console.log(formatSsgAudit(auditSsg(".")))`,
|
|
241
|
-
seeAlso: ['auditSsg'],
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
name: 'transformDeferInline',
|
|
245
|
-
kind: 'function',
|
|
246
|
-
signature:
|
|
247
|
-
'transformDeferInline(code: string, filename?: string): DeferInlineResult',
|
|
248
|
-
summary:
|
|
249
|
-
'Standalone pre-pass that inlines `<Defer>` namespace-import boundaries. Fast-paths out entirely when the source contains no `Defer` mention (no parse). Returns `{ code, changed, warnings }`; runs before the JSX transform in the Vite plugin chain.',
|
|
250
|
-
example: `import { transformDeferInline } from "@pyreon/compiler"
|
|
251
|
-
|
|
252
|
-
const { code, changed } = transformDeferInline(src, "page.tsx")`,
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
name: 'generateContext',
|
|
256
|
-
kind: 'function',
|
|
257
|
-
signature: 'generateContext(cwd: string): ProjectContext',
|
|
258
|
-
summary:
|
|
259
|
-
'Project scanner — walks the source tree and produces a structured `ProjectContext` (routes, islands, components) that `@pyreon/vite-plugin` regenerates into `.pyreon/context.json` for AI agents. Syntactic only; no type-check / bundle.',
|
|
260
|
-
example: `import { generateContext } from "@pyreon/compiler"
|
|
261
|
-
|
|
262
|
-
const ctx = generateContext(process.cwd())
|
|
263
|
-
console.log(ctx.routes.length, ctx.islands.length)`,
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
gotchas: [
|
|
267
|
-
{
|
|
268
|
-
label: 'Dual backend',
|
|
269
|
-
note: 'Reverting `src/jsx.ts` (the JS path) is INVISIBLE to anything that goes through the native binary — the Rust path in `native/src/lib.rs` is a parallel implementation, kept byte-identical by the cross-backend equivalence tests. Edits to transform behavior must land in BOTH; the equivalence suite is the gate.',
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
label: 'Reactivity-Lens is editor-only',
|
|
273
|
-
note: '`analyzeReactivity` / `formatReactivityLens` are authoring-time tools (LSP inlay hints via `@pyreon/lint --lsp`, CLI debug). They are NOT consumed at production bundle time and force the JS backend — they never affect emitted code (`reactivityLens` is an additive, byte-neutral sidecar).',
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
label: 'Detectors are not codemods',
|
|
277
|
-
note: '`detectPyreonPatterns` always reports `fixable: false` (enforced invariant). `detectReactPatterns` is paired with the real `migrateReactCode` codemod; the Pyreon detector has no companion codemod yet, so consumers must not wire auto-fix UX off its `fixable` flag.',
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
})
|
package/src/project-scanner.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project scanner — extracts route, component, and island information from source files.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as fs from 'node:fs'
|
|
6
|
-
import * as path from 'node:path'
|
|
7
|
-
|
|
8
|
-
export interface RouteInfo {
|
|
9
|
-
path: string
|
|
10
|
-
name?: string | undefined
|
|
11
|
-
component?: string | undefined
|
|
12
|
-
hasLoader: boolean
|
|
13
|
-
hasGuard: boolean
|
|
14
|
-
params: string[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ComponentInfo {
|
|
18
|
-
name: string
|
|
19
|
-
file: string
|
|
20
|
-
hasSignals: boolean
|
|
21
|
-
signalNames: string[]
|
|
22
|
-
props: string[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface IslandInfo {
|
|
26
|
-
name: string
|
|
27
|
-
file: string
|
|
28
|
-
hydrate: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ProjectContext {
|
|
32
|
-
framework: 'pyreon'
|
|
33
|
-
version: string
|
|
34
|
-
generatedAt: string
|
|
35
|
-
routes: RouteInfo[]
|
|
36
|
-
components: ComponentInfo[]
|
|
37
|
-
islands: IslandInfo[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function generateContext(cwd: string): ProjectContext {
|
|
41
|
-
const files = collectSourceFiles(cwd)
|
|
42
|
-
const version = readVersion(cwd)
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
framework: 'pyreon',
|
|
46
|
-
version,
|
|
47
|
-
generatedAt: new Date().toISOString(),
|
|
48
|
-
routes: extractRoutes(files, cwd),
|
|
49
|
-
components: extractComponents(files, cwd),
|
|
50
|
-
islands: extractIslands(files, cwd),
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function collectSourceFiles(cwd: string): string[] {
|
|
55
|
-
const results: string[] = []
|
|
56
|
-
const extensions = new Set(['.tsx', '.jsx', '.ts', '.js'])
|
|
57
|
-
const ignoreDirs = new Set(['node_modules', 'dist', 'lib', '.pyreon', '.git', 'build'])
|
|
58
|
-
|
|
59
|
-
function walk(dir: string): void {
|
|
60
|
-
let entries: fs.Dirent[]
|
|
61
|
-
try {
|
|
62
|
-
entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
63
|
-
} catch {
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
for (const entry of entries) {
|
|
67
|
-
if (entry.name.startsWith('.') && entry.isDirectory()) continue
|
|
68
|
-
if (ignoreDirs.has(entry.name) && entry.isDirectory()) continue
|
|
69
|
-
const fullPath = path.join(dir, entry.name)
|
|
70
|
-
if (entry.isDirectory()) {
|
|
71
|
-
walk(fullPath)
|
|
72
|
-
} else if (entry.isFile() && extensions.has(path.extname(entry.name))) {
|
|
73
|
-
results.push(fullPath)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
walk(cwd)
|
|
79
|
-
return results
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function extractRoutes(files: string[], _cwd: string): RouteInfo[] {
|
|
83
|
-
const routes: RouteInfo[] = []
|
|
84
|
-
|
|
85
|
-
for (const file of files) {
|
|
86
|
-
let code: string
|
|
87
|
-
try {
|
|
88
|
-
code = fs.readFileSync(file, 'utf-8')
|
|
89
|
-
} catch {
|
|
90
|
-
continue
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const routeArrayRe =
|
|
94
|
-
/(?:createRouter\s*\(\s*\[|(?:const|let)\s+routes\s*(?::\s*RouteRecord\[\])?\s*=\s*\[)([\s\S]*?)\]/g
|
|
95
|
-
let match: RegExpExecArray | null
|
|
96
|
-
for (match = routeArrayRe.exec(code); match; match = routeArrayRe.exec(code)) {
|
|
97
|
-
const block = match[1] ?? ''
|
|
98
|
-
const routeObjRe = /path\s*:\s*["']([^"']+)["']/g
|
|
99
|
-
let routeMatch: RegExpExecArray | null
|
|
100
|
-
for (routeMatch = routeObjRe.exec(block); routeMatch; routeMatch = routeObjRe.exec(block)) {
|
|
101
|
-
const routePath = routeMatch[1] ?? ''
|
|
102
|
-
const surroundingStart = Math.max(0, routeMatch.index - 50)
|
|
103
|
-
const surroundingEnd = Math.min(block.length, routeMatch.index + 200)
|
|
104
|
-
const surrounding = block.slice(surroundingStart, surroundingEnd)
|
|
105
|
-
|
|
106
|
-
routes.push({
|
|
107
|
-
path: routePath,
|
|
108
|
-
name: surrounding.match(/name\s*:\s*["']([^"']+)["']/)?.[1],
|
|
109
|
-
hasLoader: /loader\s*:/.test(surrounding),
|
|
110
|
-
hasGuard: /beforeEnter\s*:|beforeLeave\s*:/.test(surrounding),
|
|
111
|
-
params: extractParams(routePath),
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return routes
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function extractComponents(files: string[], cwd: string): ComponentInfo[] {
|
|
121
|
-
const components: ComponentInfo[] = []
|
|
122
|
-
|
|
123
|
-
for (const file of files) {
|
|
124
|
-
let code: string
|
|
125
|
-
try {
|
|
126
|
-
code = fs.readFileSync(file, 'utf-8')
|
|
127
|
-
} catch {
|
|
128
|
-
continue
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const componentRe =
|
|
132
|
-
/(?:export\s+)?(?:const|function)\s+([A-Z]\w*)\s*(?::\s*ComponentFn<[^>]+>\s*)?=?\s*\(?(?:\s*\{?\s*([^)]*?)\s*\}?\s*)?\)?\s*(?:=>|{)/g
|
|
133
|
-
let match: RegExpExecArray | null
|
|
134
|
-
|
|
135
|
-
for (match = componentRe.exec(code); match; match = componentRe.exec(code)) {
|
|
136
|
-
const name = match[1] ?? 'Unknown'
|
|
137
|
-
const propsStr = match[2] ?? ''
|
|
138
|
-
const props = propsStr
|
|
139
|
-
.split(/[,;]/)
|
|
140
|
-
.map((p) => p.trim().replace(/[{}]/g, '').trim().split(':')[0]?.split('=')[0]?.trim() ?? '')
|
|
141
|
-
.filter((p) => p && p !== 'props')
|
|
142
|
-
|
|
143
|
-
const bodyStart = match.index + match[0].length
|
|
144
|
-
const body = code.slice(bodyStart, Math.min(code.length, bodyStart + 2000))
|
|
145
|
-
const signalNames: string[] = []
|
|
146
|
-
const signalRe = /(?:const|let)\s+(\w+)\s*=\s*signal\s*[<(]/g
|
|
147
|
-
let sigMatch: RegExpExecArray | null
|
|
148
|
-
for (sigMatch = signalRe.exec(body); sigMatch; sigMatch = signalRe.exec(body)) {
|
|
149
|
-
if (sigMatch[1]) signalNames.push(sigMatch[1])
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
components.push({
|
|
153
|
-
name,
|
|
154
|
-
file: path.relative(cwd, file),
|
|
155
|
-
hasSignals: signalNames.length > 0,
|
|
156
|
-
signalNames,
|
|
157
|
-
props,
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return components
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function extractIslands(files: string[], cwd: string): IslandInfo[] {
|
|
166
|
-
const islands: IslandInfo[] = []
|
|
167
|
-
|
|
168
|
-
for (const file of files) {
|
|
169
|
-
let code: string
|
|
170
|
-
try {
|
|
171
|
-
code = fs.readFileSync(file, 'utf-8')
|
|
172
|
-
} catch {
|
|
173
|
-
continue
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const islandRe =
|
|
177
|
-
/island\s*\(\s*\(\)\s*=>\s*import\(.+?\)\s*,\s*\{[^}]*name\s*:\s*["']([^"']+)["'][^}]*?(?:hydrate\s*:\s*["']([^"']+)["'])?[^}]*\}/g
|
|
178
|
-
let match: RegExpExecArray | null
|
|
179
|
-
for (match = islandRe.exec(code); match; match = islandRe.exec(code)) {
|
|
180
|
-
if (match[1]) {
|
|
181
|
-
islands.push({
|
|
182
|
-
name: match[1],
|
|
183
|
-
file: path.relative(cwd, file),
|
|
184
|
-
hydrate: match[2] ?? 'load',
|
|
185
|
-
})
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return islands
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function extractParams(routePath: string): string[] {
|
|
194
|
-
const params: string[] = []
|
|
195
|
-
const paramRe = /:(\w+)\??/g
|
|
196
|
-
let match: RegExpExecArray | null
|
|
197
|
-
for (match = paramRe.exec(routePath); match; match = paramRe.exec(routePath)) {
|
|
198
|
-
if (match[1]) params.push(match[1])
|
|
199
|
-
}
|
|
200
|
-
return params
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function readVersion(cwd: string): string {
|
|
204
|
-
try {
|
|
205
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'))
|
|
206
|
-
const deps: Record<string, unknown> = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
207
|
-
for (const [name, ver] of Object.entries(deps)) {
|
|
208
|
-
if (name.startsWith('@pyreon/') && typeof ver === 'string') return ver.replace(/^[\^~]/, '')
|
|
209
|
-
}
|
|
210
|
-
return (pkg.version as string) || 'unknown'
|
|
211
|
-
} catch {
|
|
212
|
-
return 'unknown'
|
|
213
|
-
}
|
|
214
|
-
}
|