@reactra/babel-plugin 0.1.0-alpha.0
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 +21 -0
- package/README.md +17 -0
- package/dist/ast/index.d.ts +2 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +3 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/nodes.d.ts +437 -0
- package/dist/ast/nodes.d.ts.map +1 -0
- package/dist/ast/nodes.js +35 -0
- package/dist/ast/nodes.js.map +1 -0
- package/dist/behaviours/index.d.ts +18 -0
- package/dist/behaviours/index.d.ts.map +1 -0
- package/dist/behaviours/index.js +36 -0
- package/dist/behaviours/index.js.map +1 -0
- package/dist/behaviours/plugin.d.ts +22 -0
- package/dist/behaviours/plugin.d.ts.map +1 -0
- package/dist/behaviours/plugin.js +70 -0
- package/dist/behaviours/plugin.js.map +1 -0
- package/dist/behaviours/replayable.d.ts +10 -0
- package/dist/behaviours/replayable.d.ts.map +1 -0
- package/dist/behaviours/replayable.js +86 -0
- package/dist/behaviours/replayable.js.map +1 -0
- package/dist/behaviours/types.d.ts +77 -0
- package/dist/behaviours/types.d.ts.map +1 -0
- package/dist/behaviours/types.js +10 -0
- package/dist/behaviours/types.js.map +1 -0
- package/dist/behaviours/undoable.d.ts +10 -0
- package/dist/behaviours/undoable.d.ts.map +1 -0
- package/dist/behaviours/undoable.js +62 -0
- package/dist/behaviours/undoable.js.map +1 -0
- package/dist/compile.d.ts +69 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +75 -0
- package/dist/compile.js.map +1 -0
- package/dist/conventions/index.d.ts +110 -0
- package/dist/conventions/index.d.ts.map +1 -0
- package/dist/conventions/index.js +193 -0
- package/dist/conventions/index.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/passes/index.d.ts +5 -0
- package/dist/passes/index.d.ts.map +1 -0
- package/dist/passes/index.js +6 -0
- package/dist/passes/index.js.map +1 -0
- package/dist/passes/pass-1-parse.d.ts +3 -0
- package/dist/passes/pass-1-parse.d.ts.map +1 -0
- package/dist/passes/pass-1-parse.js +21 -0
- package/dist/passes/pass-1-parse.js.map +1 -0
- package/dist/passes/pass-2-extract.d.ts +4 -0
- package/dist/passes/pass-2-extract.d.ts.map +1 -0
- package/dist/passes/pass-2-extract.js +762 -0
- package/dist/passes/pass-2-extract.js.map +1 -0
- package/dist/passes/pass-3-readset.d.ts +11 -0
- package/dist/passes/pass-3-readset.d.ts.map +1 -0
- package/dist/passes/pass-3-readset.js +338 -0
- package/dist/passes/pass-3-readset.js.map +1 -0
- package/dist/passes/pass-9-codegen.d.ts +27 -0
- package/dist/passes/pass-9-codegen.d.ts.map +1 -0
- package/dist/passes/pass-9-codegen.js +2755 -0
- package/dist/passes/pass-9-codegen.js.map +1 -0
- package/dist/preprocess/helpers.d.ts +71 -0
- package/dist/preprocess/helpers.d.ts.map +1 -0
- package/dist/preprocess/helpers.js +342 -0
- package/dist/preprocess/helpers.js.map +1 -0
- package/dist/preprocess/index.d.ts +6 -0
- package/dist/preprocess/index.d.ts.map +1 -0
- package/dist/preprocess/index.js +11 -0
- package/dist/preprocess/index.js.map +1 -0
- package/dist/preprocess/keywords.d.ts +28 -0
- package/dist/preprocess/keywords.d.ts.map +1 -0
- package/dist/preprocess/keywords.js +99 -0
- package/dist/preprocess/keywords.js.map +1 -0
- package/dist/preprocess/lexer.d.ts +8 -0
- package/dist/preprocess/lexer.d.ts.map +1 -0
- package/dist/preprocess/lexer.js +143 -0
- package/dist/preprocess/lexer.js.map +1 -0
- package/dist/preprocess/preprocess.d.ts +3 -0
- package/dist/preprocess/preprocess.d.ts.map +1 -0
- package/dist/preprocess/preprocess.js +568 -0
- package/dist/preprocess/preprocess.js.map +1 -0
- package/dist/preprocess/rewriters.d.ts +35 -0
- package/dist/preprocess/rewriters.d.ts.map +1 -0
- package/dist/preprocess/rewriters.js +1391 -0
- package/dist/preprocess/rewriters.js.map +1 -0
- package/dist/preprocess/source-map.d.ts +70 -0
- package/dist/preprocess/source-map.d.ts.map +1 -0
- package/dist/preprocess/source-map.js +253 -0
- package/dist/preprocess/source-map.js.map +1 -0
- package/dist/preprocess/types.d.ts +57 -0
- package/dist/preprocess/types.d.ts.map +1 -0
- package/dist/preprocess/types.js +7 -0
- package/dist/preprocess/types.js.map +1 -0
- package/dist/sidecar.d.ts +137 -0
- package/dist/sidecar.d.ts.map +1 -0
- package/dist/sidecar.js +172 -0
- package/dist/sidecar.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { FileGraph } from "./ast/nodes.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Per-file metadata manifest emitted alongside compiled TSX. Schema is
|
|
4
|
+
* frozen at `"1.0"`; field additions land via additive shape changes only.
|
|
5
|
+
*/
|
|
6
|
+
export interface ReactraSidecar {
|
|
7
|
+
readonly schema: "1.0";
|
|
8
|
+
readonly source: string;
|
|
9
|
+
readonly generated: string;
|
|
10
|
+
readonly components: readonly ComponentMetadata[];
|
|
11
|
+
readonly stores: readonly StoreMetadata[];
|
|
12
|
+
readonly services: readonly ServiceMetadata[];
|
|
13
|
+
}
|
|
14
|
+
/** Surface info for one `export component Foo { … }`. */
|
|
15
|
+
export interface ComponentMetadata {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly kind: "page" | "regular";
|
|
18
|
+
readonly params: readonly ParamMetadata[];
|
|
19
|
+
readonly query: readonly QueryMetadata[];
|
|
20
|
+
readonly meta: {
|
|
21
|
+
readonly static: Record<string, unknown>;
|
|
22
|
+
readonly dynamicFields: readonly string[];
|
|
23
|
+
};
|
|
24
|
+
readonly state: readonly StateMetadata[];
|
|
25
|
+
readonly derived: readonly DerivedMetadata[];
|
|
26
|
+
readonly actions: readonly ActionMetadata[];
|
|
27
|
+
readonly resources: readonly ResourceMetadata[];
|
|
28
|
+
readonly uses: UsesMetadata;
|
|
29
|
+
readonly storeUses: readonly StoreUseMetadata[];
|
|
30
|
+
readonly injects: readonly InjectMetadata[];
|
|
31
|
+
readonly awaitBlocks: readonly AwaitMetadata[];
|
|
32
|
+
readonly hasErrorBoundary: boolean;
|
|
33
|
+
readonly hasSuspense: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface ParamMetadata {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
}
|
|
38
|
+
export interface QueryMetadata {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly hasDefault: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface StateMetadata {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
}
|
|
45
|
+
export interface DerivedMetadata {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ActionMetadata {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly isAsync: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ResourceMetadata {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
}
|
|
55
|
+
export interface UsesMetadata {
|
|
56
|
+
readonly behaviors: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export interface StoreUseMetadata {
|
|
59
|
+
readonly storeName: string;
|
|
60
|
+
readonly classification: "bare" | "argumented" | "keyed";
|
|
61
|
+
}
|
|
62
|
+
export interface InjectMetadata {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* One `await(r) { … } pending { … } error(e) { … }` block. Populated
|
|
67
|
+
* by Pass 2's view walker as of Day 23 / `#7b`. `resourceName` is the
|
|
68
|
+
* text of the resource expression (typically a bare identifier like
|
|
69
|
+
* `"customer"` but tolerates richer forms like `"profile.data"`).
|
|
70
|
+
* `hasPending` / `hasError` mirror whether the optional branches are
|
|
71
|
+
* present in the source.
|
|
72
|
+
*/
|
|
73
|
+
export interface AwaitMetadata {
|
|
74
|
+
readonly resourceName: string;
|
|
75
|
+
readonly hasPending: boolean;
|
|
76
|
+
readonly hasError: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Surface info for one store binding. */
|
|
79
|
+
export interface StoreMetadata {
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly scope: "export" | "session" | "route" | "subtree" | "parameterized";
|
|
82
|
+
readonly inputs: readonly InputMetadata[];
|
|
83
|
+
/** State field names listed under `preserved state X, Y, …`. Empty until Pass 8d lands. */
|
|
84
|
+
readonly preservedFields: readonly string[];
|
|
85
|
+
/** State field names declared in the store body. Consumed by Pass 5b cross-file `use storeX` resolution to emit the right destructure shape. */
|
|
86
|
+
readonly state: readonly string[];
|
|
87
|
+
/** Derived field names declared in the store body. Consumed by Pass 5b alongside `state`. */
|
|
88
|
+
readonly derived: readonly string[];
|
|
89
|
+
readonly resources: readonly string[];
|
|
90
|
+
readonly actions: readonly string[];
|
|
91
|
+
/** Set only when `scope === "subtree"`. */
|
|
92
|
+
readonly forSubtree?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface InputMetadata {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/** False when the source uses `input X = default`; true otherwise. */
|
|
97
|
+
readonly required: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Surface info for one service binding. Phase-1 services are all
|
|
101
|
+
* Strategy A (ServiceRegistry singletons); Strategy B emission lands
|
|
102
|
+
* with Wave 3.
|
|
103
|
+
*/
|
|
104
|
+
export interface ServiceMetadata {
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly strategy: "A" | "B";
|
|
107
|
+
readonly injects: readonly InjectMetadata[];
|
|
108
|
+
}
|
|
109
|
+
/** Options for {@link buildSidecar}. */
|
|
110
|
+
export interface BuildSidecarOptions {
|
|
111
|
+
/**
|
|
112
|
+
* ISO timestamp to stamp the manifest with. Defaults to the current
|
|
113
|
+
* wall-clock time; tests pin this to keep snapshots byte-stable.
|
|
114
|
+
*/
|
|
115
|
+
readonly generated?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Construct a `ReactraSidecar` from a compiled `FileGraph`. Pure function:
|
|
119
|
+
* given the same graph + options, returns an equivalent shape (the only
|
|
120
|
+
* non-determinism is `generated`, which is injectable for tests).
|
|
121
|
+
*/
|
|
122
|
+
export declare const buildSidecar: (graph: FileGraph, sourcePath: string, options?: BuildSidecarOptions) => ReactraSidecar;
|
|
123
|
+
/**
|
|
124
|
+
* Compute the on-disk sidecar path per Compiler §6. The sidecar lives
|
|
125
|
+
* under `<projectRoot>/node_modules/.reactra/sidecars/` with the source
|
|
126
|
+
* file's project-relative path appended verbatim (extension and all),
|
|
127
|
+
* plus a `.reactra.json` suffix.
|
|
128
|
+
*
|
|
129
|
+
* sourcePath = C:/proj/src/pages/customers/[id].tsx
|
|
130
|
+
* projectRoot = C:/proj
|
|
131
|
+
* ⇒ C:/proj/node_modules/.reactra/sidecars/src/pages/customers/[id].tsx.reactra.json
|
|
132
|
+
*
|
|
133
|
+
* Both inputs may use forward or back slashes; the returned path uses
|
|
134
|
+
* forward slashes for portability across `node:fs` calls on Windows.
|
|
135
|
+
*/
|
|
136
|
+
export declare const sidecarPathFor: (projectRoot: string, sourcePath: string) => string;
|
|
137
|
+
//# sourceMappingURL=sidecar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar.d.ts","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAEV,SAAS,EACV,MAAM,gBAAgB,CAAA;AAEvB;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,SAAS,iBAAiB,EAAE,CAAA;IACjD,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAA;IACzC,QAAQ,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EAAE,CAAA;IACnC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAC5C;AAED,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,EAChB,YAAY,MAAM,EAClB,UAAS,mBAAwB,KAChC,cA6BF,CAAA;AA6FD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,MAAM,EAAE,YAAY,MAAM,KAAG,MAaxE,CAAA"}
|
package/dist/sidecar.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Metadata sidecar builder — Compiler §6 (`.reactra.json`).
|
|
2
|
+
//
|
|
3
|
+
// Builds an in-memory `ReactraSidecar` from a compiled `FileGraph`. The
|
|
4
|
+
// sidecar is the per-file manifest of what each Reactra source declares
|
|
5
|
+
// — components, stores, services — consumed downstream by:
|
|
6
|
+
//
|
|
7
|
+
// - Compiler Pass 5b: cross-file `use storeX` surface resolution
|
|
8
|
+
// (today bare `use storeX` only works same-file because there's no
|
|
9
|
+
// manifest to look up). Closing #7 unblocks the writer; Pass 5b
|
|
10
|
+
// consumes it in a later session.
|
|
11
|
+
// - Compiler Pass 5c: cross-file `provide`-presence check for
|
|
12
|
+
// Strategy-B services (Wave 3).
|
|
13
|
+
// - Devtools, LSP, replay (all Wave 3).
|
|
14
|
+
//
|
|
15
|
+
// Phase-1 writer scope:
|
|
16
|
+
// - Schema matches Compiler §6 exactly so future passes can consume it
|
|
17
|
+
// without renaming fields.
|
|
18
|
+
// - Fields the compiler doesn't yet populate (`preservedFields`,
|
|
19
|
+
// `meta.dynamicFields`, `prefetch`, `transition`, page `routeId`)
|
|
20
|
+
// come out empty / omitted so consumers don't need v0-vs-v1 branches.
|
|
21
|
+
// - The on-disk write lives in `@reactra/vite-plugin` per Compiler §6
|
|
22
|
+
// (`node_modules/.reactra/sidecars/<src-path>.reactra.json`). This
|
|
23
|
+
// module only constructs the in-memory object.
|
|
24
|
+
/**
|
|
25
|
+
* Construct a `ReactraSidecar` from a compiled `FileGraph`. Pure function:
|
|
26
|
+
* given the same graph + options, returns an equivalent shape (the only
|
|
27
|
+
* non-determinism is `generated`, which is injectable for tests).
|
|
28
|
+
*/
|
|
29
|
+
export const buildSidecar = (graph, sourcePath, options = {}) => {
|
|
30
|
+
const components = [];
|
|
31
|
+
const stores = [];
|
|
32
|
+
const services = [];
|
|
33
|
+
for (const container of graph.containers) {
|
|
34
|
+
switch (container.kind) {
|
|
35
|
+
case "component":
|
|
36
|
+
components.push(buildComponentMetadata(container));
|
|
37
|
+
break;
|
|
38
|
+
case "export-store":
|
|
39
|
+
case "session-store":
|
|
40
|
+
case "route-store":
|
|
41
|
+
stores.push(buildStoreMetadata(container));
|
|
42
|
+
break;
|
|
43
|
+
case "service":
|
|
44
|
+
services.push(buildServiceMetadata(container));
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
schema: "1.0",
|
|
50
|
+
source: sourcePath,
|
|
51
|
+
generated: options.generated ?? new Date().toISOString(),
|
|
52
|
+
components,
|
|
53
|
+
stores,
|
|
54
|
+
services,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
// A component counts as a "page" when it carries any route surface — `param`,
|
|
58
|
+
// `query`, `meta`, `prefetch`, or `transition`. This matches the file-walker
|
|
59
|
+
// convention (anything under `src/pages/` is a page) without needing the
|
|
60
|
+
// walker's path info here.
|
|
61
|
+
const isPage = (c) => c.params.length > 0 ||
|
|
62
|
+
c.queries.length > 0 ||
|
|
63
|
+
c.meta != null ||
|
|
64
|
+
c.prefetch != null ||
|
|
65
|
+
c.transition != null;
|
|
66
|
+
const buildComponentMetadata = (c) => ({
|
|
67
|
+
name: c.name,
|
|
68
|
+
kind: isPage(c) ? "page" : "regular",
|
|
69
|
+
params: c.params.map((p) => ({ name: p.name })),
|
|
70
|
+
query: c.queries.map((q) => ({ name: q.name, hasDefault: q.defaultExpr != null })),
|
|
71
|
+
// Static/dynamic classification of `meta { … }` waits on #5c. We surface
|
|
72
|
+
// presence-only today: an empty `static`/`dynamicFields` for components
|
|
73
|
+
// that have a meta block, omitted-equivalent for those that don't.
|
|
74
|
+
meta: { static: {}, dynamicFields: [] },
|
|
75
|
+
state: c.states.map((s) => ({ name: s.name })),
|
|
76
|
+
derived: c.deriveds.map((d) => ({ name: d.name })),
|
|
77
|
+
actions: c.actions.map((a) => ({ name: a.name, isAsync: a.isAsync })),
|
|
78
|
+
resources: c.resources.map((r) => ({ name: r.name })),
|
|
79
|
+
uses: { behaviors: c.uses?.names ?? [] },
|
|
80
|
+
storeUses: c.storeUses.map((su) => ({
|
|
81
|
+
storeName: su.storeName,
|
|
82
|
+
classification: su.classification,
|
|
83
|
+
})),
|
|
84
|
+
injects: c.injects.map((i) => ({ name: i.name })),
|
|
85
|
+
// Day 23 / `#7b`: derived from Pass 2's view walker
|
|
86
|
+
// (`extractAwaitBlocks`). Each entry mirrors one `await(r) { ... }
|
|
87
|
+
// [pending { ... }] [error(e) { ... }]` site in the component's view.
|
|
88
|
+
awaitBlocks: c.awaitBlocks.map((b) => ({
|
|
89
|
+
resourceName: b.resourceName,
|
|
90
|
+
hasPending: b.hasPending,
|
|
91
|
+
hasError: b.hasError,
|
|
92
|
+
})),
|
|
93
|
+
hasErrorBoundary: c.errorBoundary != null,
|
|
94
|
+
hasSuspense: c.suspense != null,
|
|
95
|
+
});
|
|
96
|
+
const buildStoreMetadata = (c) => {
|
|
97
|
+
const scope = storeScope(c);
|
|
98
|
+
return {
|
|
99
|
+
name: c.name,
|
|
100
|
+
scope,
|
|
101
|
+
inputs: c.inputs.map(inputToMetadata),
|
|
102
|
+
// `preserved state X, Y` extraction in Pass 8d isn't wired up yet —
|
|
103
|
+
// the AST has the field list but no pass consumes it. Empty today.
|
|
104
|
+
preservedFields: c.preserved?.fields ?? [],
|
|
105
|
+
// Pass 5b destructures the cross-file `use storeX` reference as
|
|
106
|
+
// `const { state…, derived…, actions… } = useReactraStore("storeX")`.
|
|
107
|
+
// Names come straight from Pass 2 extraction.
|
|
108
|
+
state: c.states.map((s) => s.name),
|
|
109
|
+
derived: c.deriveds.map((d) => d.name),
|
|
110
|
+
// Phase-1 stores don't yet support `resource` or `effect`/`mount`
|
|
111
|
+
// bodies, but the AST nodes exist. Surface what's there.
|
|
112
|
+
resources: c.resources.map((r) => r.name),
|
|
113
|
+
actions: c.actions.map((a) => a.name),
|
|
114
|
+
...(scope === "subtree" && c.subtreePath != null
|
|
115
|
+
? { forSubtree: c.subtreePath }
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
// Map container kind + optional subtree/key signature to the spec's
|
|
120
|
+
// 5-value scope enum. Plain `route store X` is "route"; `for "/path"` adds
|
|
121
|
+
// "subtree"; keyed-by-`(key)` adds "parameterized".
|
|
122
|
+
const storeScope = (c) => {
|
|
123
|
+
if (c.kind === "export-store")
|
|
124
|
+
return "export";
|
|
125
|
+
if (c.kind === "session-store")
|
|
126
|
+
return "session";
|
|
127
|
+
if (c.subtreePath != null)
|
|
128
|
+
return "subtree";
|
|
129
|
+
if (c.keySig != null)
|
|
130
|
+
return "parameterized";
|
|
131
|
+
return "route";
|
|
132
|
+
};
|
|
133
|
+
const inputToMetadata = (i) => ({
|
|
134
|
+
name: i.name,
|
|
135
|
+
required: i.requirement === "required",
|
|
136
|
+
});
|
|
137
|
+
const buildServiceMetadata = (c) => ({
|
|
138
|
+
name: c.name,
|
|
139
|
+
// Phase-1 services are all Strategy A (ServiceRegistry singletons).
|
|
140
|
+
// Strategy B emission lands when the cross-file `provide`-presence
|
|
141
|
+
// pass is built; the field is here so consumers can branch on it.
|
|
142
|
+
strategy: "A",
|
|
143
|
+
injects: c.injects.map((i) => ({ name: i.name })),
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* Compute the on-disk sidecar path per Compiler §6. The sidecar lives
|
|
147
|
+
* under `<projectRoot>/node_modules/.reactra/sidecars/` with the source
|
|
148
|
+
* file's project-relative path appended verbatim (extension and all),
|
|
149
|
+
* plus a `.reactra.json` suffix.
|
|
150
|
+
*
|
|
151
|
+
* sourcePath = C:/proj/src/pages/customers/[id].tsx
|
|
152
|
+
* projectRoot = C:/proj
|
|
153
|
+
* ⇒ C:/proj/node_modules/.reactra/sidecars/src/pages/customers/[id].tsx.reactra.json
|
|
154
|
+
*
|
|
155
|
+
* Both inputs may use forward or back slashes; the returned path uses
|
|
156
|
+
* forward slashes for portability across `node:fs` calls on Windows.
|
|
157
|
+
*/
|
|
158
|
+
export const sidecarPathFor = (projectRoot, sourcePath) => {
|
|
159
|
+
const norm = (s) => s.replace(/\\/g, "/");
|
|
160
|
+
const root = norm(projectRoot).replace(/\/+$/, "");
|
|
161
|
+
const src = norm(sourcePath);
|
|
162
|
+
// Case-insensitive prefix match: on Windows the drive letter / directory
|
|
163
|
+
// casing can differ between Vite's module id (`C:/Temp/...`) and the computed
|
|
164
|
+
// projectRoot (`C:/temp/...`). A case-sensitive `startsWith` would miss, fall
|
|
165
|
+
// back to the absolute `src`, and produce a doubled path
|
|
166
|
+
// (`node_modules/.reactra/sidecars/C:/Temp/...`) whose mkdir then ENOENTs.
|
|
167
|
+
// The slice uses `root.length` so `rel` keeps the source's real casing.
|
|
168
|
+
const isPrefix = src.toLowerCase().startsWith(root.toLowerCase() + "/");
|
|
169
|
+
const rel = isPrefix ? src.slice(root.length + 1) : src;
|
|
170
|
+
return `${root}/node_modules/.reactra/sidecars/${rel}.reactra.json`;
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=sidecar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar.js","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,gEAAgE;AAChE,oCAAoC;AACpC,0CAA0C;AAC1C,EAAE;AACF,wBAAwB;AACxB,yEAAyE;AACzE,+BAA+B;AAC/B,mEAAmE;AACnE,sEAAsE;AACtE,0EAA0E;AAC1E,wEAAwE;AACxE,uEAAuE;AACvE,mDAAmD;AA0InD;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAgB,EAChB,UAAkB,EAClB,UAA+B,EAAE,EACjB,EAAE;IAClB,MAAM,UAAU,GAAwB,EAAE,CAAA;IAC1C,MAAM,MAAM,GAAoB,EAAE,CAAA;IAClC,MAAM,QAAQ,GAAsB,EAAE,CAAA;IAEtC,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACzC,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;YACvB,KAAK,WAAW;gBACd,UAAU,CAAC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAA;gBAClD,MAAK;YACP,KAAK,cAAc,CAAC;YACpB,KAAK,eAAe,CAAC;YACrB,KAAK,aAAa;gBAChB,M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AI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,CAAA;IAC5B,yEAAyE;IACzE,8EAA8E;IAC9E,8EAA8E;IAC9E,yDAAyD;IACzD,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,CAAA;IACvE,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;IACvD,OAAO,GAAG,IAAI,mCAAmC,GAAG,eAAe,CAAA;AACrE,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reactra/babel-plugin",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./conventions": {
|
|
12
|
+
"types": "./dist/conventions/index.d.ts",
|
|
13
|
+
"default": "./dist/conventions/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/parser": "^7.26.0",
|
|
18
|
+
"@babel/types": "^7.26.0",
|
|
19
|
+
"@babel/traverse": "^7.26.0"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"tag": "alpha",
|
|
28
|
+
"provenance": false
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/akhilshastri/reactra.git",
|
|
33
|
+
"directory": "packages/babel-plugin"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://reactra-docs.vercel.app",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.18"
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"description": "The Reactra compiler — transforms the Reactra DSL into standard React 19 TSX."
|
|
42
|
+
}
|