@ng-desktop/builders 0.0.0-stage → 0.3.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.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -2
  3. package/bin/ng-desktop.mjs +191 -0
  4. package/builders.json +10 -0
  5. package/fesm2022/ast-metadata-extractor.d.mts +40 -0
  6. package/fesm2022/ast-metadata-extractor.mjs +420 -0
  7. package/fesm2022/build-bundle.d.mts +36 -0
  8. package/fesm2022/build-bundle.mjs +315 -0
  9. package/fesm2022/builder.d.ts +67 -0
  10. package/fesm2022/builder.d.ts.map +1 -0
  11. package/fesm2022/builder.js +124 -0
  12. package/fesm2022/builder.js.map +1 -0
  13. package/fesm2022/dev-server.mjs +47 -0
  14. package/fesm2022/hmr-client.d.mts +19 -0
  15. package/fesm2022/hmr-client.mjs +77 -0
  16. package/fesm2022/icon-compiler.d.mts +6 -0
  17. package/fesm2022/icon-compiler.mjs +148 -0
  18. package/fesm2022/index.d.ts +11 -0
  19. package/fesm2022/index.d.ts.map +1 -0
  20. package/fesm2022/index.js +11 -0
  21. package/fesm2022/index.js.map +1 -0
  22. package/fesm2022/permission-analyzer.d.mts +45 -0
  23. package/fesm2022/permission-analyzer.mjs +313 -0
  24. package/fesm2022/resolve-engine-binary.d.mts +35 -0
  25. package/fesm2022/resolve-engine-binary.mjs +130 -0
  26. package/fesm2022/style-compiler.d.mts +14 -0
  27. package/fesm2022/style-compiler.mjs +97 -0
  28. package/fesm2022/template-compiler.d.mts +53 -0
  29. package/fesm2022/template-compiler.mjs +810 -0
  30. package/fesm2022/workspace-resolver.d.mts +24 -0
  31. package/fesm2022/workspace-resolver.mjs +199 -0
  32. package/package.json +78 -4
  33. package/schema/angular-native-schema.json +52 -0
  34. package/schema/native-builder-schema.json +79 -0
  35. package/schematics/collection.json +10 -0
  36. package/schematics/ng-add/index.d.mts +20 -0
  37. package/schematics/ng-add/index.mjs +56 -0
  38. package/schematics/ng-add/schema.json +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gaspar1992 and NgDesktop Engine Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # @ng-desktop/builders
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Angular 22+ CLI & Nx Architect builder, AST permission analyzer, CLI, and schematics
4
+
5
+ Part of **[NgDesktop Engine](https://github.com/Gaspar1992/ng-desktop-engine)** — Native desktop rendering engine for Angular 22+ (`GTK4`, `WinUI 3`, `AppKit`).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @ng-desktop/builders
11
+ ```
12
+
13
+ - Repository path: `packages/builders-native`
14
+ - Documentation & Ecosystem Guide: https://github.com/Gaspar1992/ng-desktop-engine/blob/main/docs/ECOSYSTEM_COMPATIBILITY.md
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { dirname, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const SRC_ROOT = existsSync(resolve(__dirname, '../fesm2022/build-bundle.mjs'))
9
+ ? resolve(__dirname, '../fesm2022')
10
+ : resolve(__dirname, '../src');
11
+
12
+ const [
13
+ { compileBundle, watchBundle },
14
+ { analyzeProjectPermissions },
15
+ { resolveEngineBinaryPath },
16
+ { resolveWorkspaceProject },
17
+ ] = await Promise.all([
18
+ import(resolve(SRC_ROOT, 'build-bundle.mjs')),
19
+ import(resolve(SRC_ROOT, 'permission-analyzer.mjs')),
20
+ import(resolve(SRC_ROOT, 'resolve-engine-binary.mjs')),
21
+ import(resolve(SRC_ROOT, 'workspace-resolver.mjs')),
22
+ ]);
23
+
24
+ function getFlag(args, name) {
25
+ const prefix = `${name}=`;
26
+ for (let i = 0; i < args.length; i += 1) {
27
+ if (args[i].startsWith(prefix)) {
28
+ return args[i].slice(prefix.length).trim();
29
+ }
30
+ if (args[i] === name && i + 1 < args.length && !args[i + 1].startsWith('--')) {
31
+ return args[i + 1].trim();
32
+ }
33
+ }
34
+ return undefined;
35
+ }
36
+
37
+ function printHelp() {
38
+ process.stdout.write(
39
+ [
40
+ 'ng-desktop — Angular Desktop Engine CLI (Angular CLI + Nx)',
41
+ '',
42
+ 'Usage:',
43
+ ' ng-desktop build [--project=<name>] [--config=<path>] [--version=<ver>] [--watch]',
44
+ ' ng-desktop run [--project=<name>] [--config=<path>] [--version=<ver>] [--batch]',
45
+ ' ng-desktop permissions [--project=<name>] [--config=<path>] [--strict]',
46
+ ' ng-desktop package [--project=<name>] [--config=<path>] [--version=<ver>] [--all]',
47
+ ' ng-desktop init [--project=<name>] [--target=<linux-gtk4|windows-winui|macos-appkit>]',
48
+ '',
49
+ ].join('\n'),
50
+ );
51
+ }
52
+
53
+ function handleInit(args) {
54
+ const cwd = process.cwd();
55
+ const targetPlatform = getFlag(args, '--target') || 'linux-gtk4';
56
+ const projectHint = getFlag(args, '--project');
57
+ const nativeConfigBlock = {
58
+ builder: '@ng-desktop/builders:application',
59
+ options: {
60
+ targetPlatform,
61
+ permissions: { mode: 'auto' },
62
+ },
63
+ };
64
+
65
+ const angularJsonPath = resolve(cwd, 'angular.json');
66
+ if (existsSync(angularJsonPath)) {
67
+ const raw = JSON.parse(readFileSync(angularJsonPath, 'utf8'));
68
+ const projectName = projectHint || raw.defaultProject || Object.keys(raw.projects ?? {})[0];
69
+ if (!projectName || !raw.projects?.[projectName]) {
70
+ throw new Error('Could not locate a target project inside angular.json');
71
+ }
72
+ raw.projects[projectName].architect ??= {};
73
+ raw.projects[projectName].architect.native ??= nativeConfigBlock;
74
+ writeFileSync(angularJsonPath, `${JSON.stringify(raw, null, 2)}\n`, 'utf8');
75
+ process.stdout.write(`[ng-desktop init] Configured 'architect.native' for '${projectName}'.\n`);
76
+ return;
77
+ }
78
+
79
+ const nxProjectPath = resolve(cwd, 'project.json');
80
+ if (existsSync(nxProjectPath)) {
81
+ const raw = JSON.parse(readFileSync(nxProjectPath, 'utf8'));
82
+ raw.targets ??= {};
83
+ raw.targets.native ??= {
84
+ executor: '@ng-desktop/builders:application',
85
+ options: nativeConfigBlock.options,
86
+ };
87
+ writeFileSync(nxProjectPath, `${JSON.stringify(raw, null, 2)}\n`, 'utf8');
88
+ process.stdout.write(`[ng-desktop init] Configured Nx 'targets.native' for '${raw.name}'.\n`);
89
+ return;
90
+ }
91
+
92
+ throw new Error('No angular.json or project.json found in current working directory.');
93
+ }
94
+
95
+ function launchHostEngine(ws, engineArgs, { preferReleaseCargo = false, envExtra = {} } = {}) {
96
+ const resolvedEngine = resolveEngineBinaryPath({
97
+ cwd: process.cwd(),
98
+ workspaceRoot: ws.workspaceRoot,
99
+ });
100
+ const baseArgs =
101
+ resolvedEngine.mode === 'cargo' && preferReleaseCargo
102
+ ? ['run', '--release', '--']
103
+ : resolvedEngine.args;
104
+ const run = spawnSync(resolvedEngine.command, [...baseArgs, ...engineArgs], {
105
+ stdio: 'inherit',
106
+ cwd: ws.workspaceRoot,
107
+ env: { ...process.env, ...envExtra },
108
+ });
109
+ process.exitCode = run.status ?? 1;
110
+ }
111
+
112
+ function main() {
113
+ const args = process.argv.slice(2);
114
+ const cmd = args[0];
115
+ if (!cmd || cmd === '--help' || cmd === '-h') {
116
+ printHelp();
117
+ return;
118
+ }
119
+
120
+ const projectName = getFlag(args, '--project');
121
+ const configPath = getFlag(args, '--config');
122
+ const version = getFlag(args, '--version');
123
+
124
+ if (cmd === 'build') {
125
+ if (args.includes('--watch')) {
126
+ watchBundle({ configPath, projectName, version });
127
+ } else {
128
+ const result = compileBundle({ configPath, projectName, version, rebuildIcons: true });
129
+ process.stdout.write(
130
+ `[ng-desktop build] Emitted bundle '${result.bundleFile}' and permissions '${result.permissionsFile}'.\n`,
131
+ );
132
+ }
133
+ return;
134
+ }
135
+
136
+ if (cmd === 'run') {
137
+ const ws = resolveWorkspaceProject({ configPath, projectName });
138
+ launchHostEngine(
139
+ ws,
140
+ [
141
+ `--config=${ws.configFile}`,
142
+ `--project=${ws.projectName}`,
143
+ `--version=${version || ws.version}`,
144
+ ],
145
+ { envExtra: args.includes('--batch') ? { NG_NATIVE_BATCH: '1' } : {} },
146
+ );
147
+ return;
148
+ }
149
+
150
+ if (cmd === 'permissions') {
151
+ const ws = resolveWorkspaceProject({ configPath, projectName });
152
+ const srcRoot = resolve(ws.workspaceRoot, ws.sourceRoot);
153
+ const basePolicy = ws.nativeOptions?.permissions ?? {};
154
+ const policy = args.includes('--strict') ? { ...basePolicy, mode: 'strict' } : basePolicy;
155
+ const manifest = analyzeProjectPermissions(srcRoot, policy);
156
+ process.stdout.write(`${JSON.stringify(manifest, null, 2)}\n`);
157
+ return;
158
+ }
159
+
160
+ if (cmd === 'package') {
161
+ const ws = resolveWorkspaceProject({ configPath, projectName });
162
+ const pkgFlag = args.includes('--all') ? '--package-all' : '--package';
163
+ launchHostEngine(
164
+ ws,
165
+ [
166
+ pkgFlag,
167
+ `--config=${ws.configFile}`,
168
+ `--project=${ws.projectName}`,
169
+ `--version=${version || ws.version}`,
170
+ ],
171
+ { preferReleaseCargo: true },
172
+ );
173
+ return;
174
+ }
175
+
176
+ if (cmd === 'init') {
177
+ handleInit(args);
178
+ return;
179
+ }
180
+
181
+ process.stderr.write(`Unknown command '${cmd}'.\n`);
182
+ printHelp();
183
+ process.exitCode = 1;
184
+ }
185
+
186
+ try {
187
+ main();
188
+ } catch (err) {
189
+ process.stderr.write(`[ng-desktop error] ${err instanceof Error ? err.message : String(err)}\n`);
190
+ process.exitCode = 1;
191
+ }
package/builders.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../../node_modules/@angular-devkit/architect/src/builders-schema.json",
3
+ "builders": {
4
+ "application": {
5
+ "implementation": "./fesm2022/index.js",
6
+ "schema": "./schema/native-builder-schema.json",
7
+ "description": "Compile Angular templates/signals to native OS .ngb bundle with static least-privilege permissions."
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,40 @@
1
+ export interface ComponentDecoratorMeta {
2
+ selector: string;
3
+ templateUrl: string;
4
+ styleUrl: string;
5
+ imports: string[];
6
+ }
7
+
8
+ export interface MethodMutationMeta {
9
+ kind: 'set' | 'add';
10
+ signalName: string;
11
+ value: number;
12
+ }
13
+
14
+ export interface SignalInputOrModelMeta {
15
+ required: boolean;
16
+ defaultValue: unknown;
17
+ }
18
+
19
+ export interface ResourceMetadata {
20
+ kind: 'httpResource';
21
+ url: string;
22
+ }
23
+
24
+ export interface ExtractedComponentMetadata {
25
+ state: Record<string, unknown>;
26
+ numericSignals: Record<string, number>;
27
+ computedSignals: Record<string, unknown>;
28
+ inputs: Record<string, SignalInputOrModelMeta>;
29
+ models: Record<string, SignalInputOrModelMeta>;
30
+ outputs: Record<string, boolean>;
31
+ resources: Record<string, ResourceMetadata>;
32
+ methods: Record<string, MethodMutationMeta>;
33
+ component: ComponentDecoratorMeta;
34
+ relativeImports: Record<string, string>;
35
+ }
36
+
37
+ export function extractComponentMetadata(
38
+ tsSource: string,
39
+ filename?: string,
40
+ ): ExtractedComponentMetadata;
@@ -0,0 +1,420 @@
1
+ import { parseSync } from 'oxc-parser';
2
+
3
+ function extractScalarLiteral(node) {
4
+ if (!node) return null;
5
+
6
+ if (node.type === 'Literal') {
7
+ if (typeof node.value === 'number') {
8
+ return { kind: 'number', value: node.value, raw: String(node.value) };
9
+ }
10
+ if (typeof node.value === 'string') {
11
+ return { kind: 'string', value: node.value, raw: node.value };
12
+ }
13
+ if (typeof node.value === 'boolean') {
14
+ return { kind: 'boolean', value: node.value, raw: String(node.value) };
15
+ }
16
+ }
17
+
18
+ if (
19
+ node.type === 'UnaryExpression' &&
20
+ (node.operator === '-' || node.operator === '+') &&
21
+ node.argument?.type === 'Literal' &&
22
+ typeof node.argument.value === 'number'
23
+ ) {
24
+ const value = node.operator === '-' ? -node.argument.value : node.argument.value;
25
+ return { kind: 'number', value, raw: String(value) };
26
+ }
27
+
28
+ return null;
29
+ }
30
+
31
+ function evaluateDerivedExpression(node, state) {
32
+ if (!node) return null;
33
+ const lit = extractScalarLiteral(node);
34
+ if (lit) return lit.value;
35
+
36
+ if (
37
+ node.type === 'CallExpression' &&
38
+ node.callee?.type === 'MemberExpression' &&
39
+ node.callee.object?.type === 'ThisExpression' &&
40
+ node.callee.property?.type === 'Identifier'
41
+ ) {
42
+ const key = node.callee.property.name;
43
+ if (key in state) {
44
+ const raw = state[key];
45
+ const num = Number(raw);
46
+ return raw !== '' && !Number.isNaN(num) ? num : raw;
47
+ }
48
+ }
49
+
50
+ if (
51
+ node.type === 'MemberExpression' &&
52
+ node.object?.type === 'ThisExpression' &&
53
+ node.property?.type === 'Identifier'
54
+ ) {
55
+ const key = node.property.name;
56
+ if (key in state) return state[key];
57
+ }
58
+
59
+ if (node.type === 'TemplateLiteral') {
60
+ let out = '';
61
+ for (let i = 0; i < node.quasis.length; i++) {
62
+ out += node.quasis[i].value?.cooked ?? node.quasis[i].value?.raw ?? '';
63
+ if (i < (node.expressions?.length ?? 0)) {
64
+ const val = evaluateDerivedExpression(node.expressions[i], state);
65
+ if (val !== null && val !== undefined) out += String(val);
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+
71
+ if (node.type === 'BinaryExpression') {
72
+ const left = evaluateDerivedExpression(node.left, state);
73
+ const right = evaluateDerivedExpression(node.right, state);
74
+ if (left === null || right === null) return null;
75
+ if (node.operator === '+') {
76
+ return typeof left === 'string' || typeof right === 'string'
77
+ ? `${left}${right}`
78
+ : Number(left) + Number(right);
79
+ }
80
+ if (node.operator === '-') return Number(left) - Number(right);
81
+ if (node.operator === '*') return Number(left) * Number(right);
82
+ if (node.operator === '/') return Number(right) === 0 ? 0 : Number(left) / Number(right);
83
+ if (node.operator === '===' || node.operator === '==') return left === right;
84
+ if (node.operator === '!==' || node.operator === '!=') return left !== right;
85
+ if (node.operator === '>') return Number(left) > Number(right);
86
+ if (node.operator === '<') return Number(left) < Number(right);
87
+ }
88
+
89
+ if (node.type === 'ArrayExpression') {
90
+ return (node.elements || []).map((el) => evaluateDerivedExpression(el, state));
91
+ }
92
+
93
+ if (node.type === 'ObjectExpression') {
94
+ const obj = {};
95
+ for (const prop of node.properties || []) {
96
+ const k = prop.key?.name ?? prop.key?.value;
97
+ if (k !== undefined) {
98
+ obj[String(k)] = evaluateDerivedExpression(prop.value, state);
99
+ }
100
+ }
101
+ return obj;
102
+ }
103
+
104
+ return null;
105
+ }
106
+
107
+ function extractDecoratorMetadata(decorators = []) {
108
+ const component = {
109
+ selector: 'app-root',
110
+ templateUrl: './app.html',
111
+ styleUrl: './app.css',
112
+ imports: [],
113
+ };
114
+
115
+ for (const dec of decorators) {
116
+ const expr = dec.expression;
117
+ if (
118
+ expr?.type !== 'CallExpression' ||
119
+ expr.callee?.type !== 'Identifier' ||
120
+ expr.callee.name !== 'Component'
121
+ ) {
122
+ continue;
123
+ }
124
+
125
+ const arg = expr.arguments?.[0];
126
+ if (arg?.type !== 'ObjectExpression') continue;
127
+
128
+ for (const prop of arg.properties || []) {
129
+ if (prop.type !== 'Property' || prop.key?.type !== 'Identifier') continue;
130
+
131
+ if (prop.key.name === 'imports' && prop.value?.type === 'ArrayExpression') {
132
+ component.imports = (prop.value.elements || [])
133
+ .filter((el) => el?.type === 'Identifier')
134
+ .map((el) => el.name);
135
+ continue;
136
+ }
137
+
138
+ const lit = extractScalarLiteral(prop.value);
139
+ if (!lit || lit.kind !== 'string') continue;
140
+
141
+ if (prop.key.name === 'selector') component.selector = lit.value;
142
+ if (prop.key.name === 'templateUrl') component.templateUrl = lit.value;
143
+ if (prop.key.name === 'styleUrl') component.styleUrl = lit.value;
144
+ }
145
+ }
146
+
147
+ return component;
148
+ }
149
+
150
+ function resolveReturnedExpression(fnNode) {
151
+ if (!fnNode?.body) return null;
152
+ if (fnNode.body.type !== 'BlockStatement') {
153
+ return fnNode.body;
154
+ }
155
+
156
+ for (const stmt of fnNode.body.body || []) {
157
+ if (stmt.type === 'ReturnStatement') {
158
+ return stmt.argument;
159
+ }
160
+ }
161
+ return null;
162
+ }
163
+
164
+ function extractMethodMutation(methodDef, methods) {
165
+ const methodName = methodDef.key?.type === 'Identifier' ? methodDef.key.name : null;
166
+ if (!methodName) return;
167
+
168
+ const statements = methodDef.value?.body?.body || [];
169
+ for (const stmt of statements) {
170
+ if (stmt.type !== 'ExpressionStatement' || stmt.expression?.type !== 'CallExpression') {
171
+ continue;
172
+ }
173
+
174
+ const callExpr = stmt.expression;
175
+ const callee = callExpr.callee;
176
+ if (
177
+ callee?.type !== 'MemberExpression' ||
178
+ callee.property?.type !== 'Identifier' ||
179
+ callee.object?.type !== 'MemberExpression' ||
180
+ callee.object.object?.type !== 'ThisExpression' ||
181
+ callee.object.property?.type !== 'Identifier'
182
+ ) {
183
+ continue;
184
+ }
185
+
186
+ const signalName = callee.object.property.name;
187
+ const action = callee.property.name;
188
+
189
+ if (action === 'set') {
190
+ const lit = extractScalarLiteral(callExpr.arguments?.[0]);
191
+ if (lit?.kind === 'number') {
192
+ methods[methodName] = { kind: 'set', signalName, value: lit.value };
193
+ }
194
+ continue;
195
+ }
196
+
197
+ if (action === 'update') {
198
+ const fnArg = callExpr.arguments?.[0];
199
+ const retExpr = resolveReturnedExpression(fnArg);
200
+ if (
201
+ retExpr?.type === 'BinaryExpression' &&
202
+ (retExpr.operator === '+' || retExpr.operator === '-')
203
+ ) {
204
+ const rightLit = extractScalarLiteral(retExpr.right);
205
+ if (rightLit?.kind === 'number') {
206
+ const delta = retExpr.operator === '-' ? -rightLit.value : rightLit.value;
207
+ methods[methodName] = { kind: 'add', signalName, value: delta };
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Parses an Angular 22 TypeScript component source file using the Rust-based `oxc-parser` AST
216
+ * and extracts `@Component` decorator paths/imports, `signal(...)`, `computed(...)`,
217
+ * `linkedSignal(...)`, `input(...)`, `model(...)`, `output()`, `httpResource(...)`,
218
+ * class properties, and signal mutation methods.
219
+ */
220
+ export function extractComponentMetadata(tsSource, filename = 'app.ts') {
221
+ const parsed = parseSync(filename, tsSource);
222
+ const state = {};
223
+ const numericSignals = {};
224
+ const computedSignals = {};
225
+ const inputs = {};
226
+ const models = {};
227
+ const outputs = {};
228
+ const resources = {};
229
+ const methods = {};
230
+ const relativeImports = {};
231
+ let component = {
232
+ selector: 'app-root',
233
+ templateUrl: './app.html',
234
+ styleUrl: './app.css',
235
+ imports: [],
236
+ };
237
+
238
+ for (const stmt of parsed.program.body || []) {
239
+ if (stmt.type === 'ImportDeclaration' && stmt.source?.value?.startsWith('.')) {
240
+ for (const spec of stmt.specifiers || []) {
241
+ if (spec.local?.name) {
242
+ relativeImports[spec.local.name] = stmt.source.value;
243
+ }
244
+ }
245
+ continue;
246
+ }
247
+
248
+ const decl =
249
+ stmt.type === 'ExportNamedDeclaration' || stmt.type === 'ExportDefaultDeclaration'
250
+ ? stmt.declaration
251
+ : stmt;
252
+
253
+ if (decl?.type !== 'ClassDeclaration') continue;
254
+
255
+ component = extractDecoratorMetadata(decl.decorators);
256
+
257
+ for (const member of decl.body?.body || []) {
258
+ if (member.type === 'PropertyDefinition' && member.key?.type === 'Identifier') {
259
+ const propName = member.key.name;
260
+ const valNode = member.value;
261
+
262
+ if (
263
+ valNode?.type === 'CallExpression' &&
264
+ valNode.callee?.type === 'Identifier' &&
265
+ valNode.callee.name === 'signal'
266
+ ) {
267
+ const arg0 = valNode.arguments?.[0];
268
+ const lit = extractScalarLiteral(arg0);
269
+ if (lit) {
270
+ state[propName] = lit.raw;
271
+ if (lit.kind === 'number') {
272
+ numericSignals[propName] = lit.value;
273
+ }
274
+ } else {
275
+ const evaluated = evaluateDerivedExpression(arg0, state);
276
+ if (evaluated !== null) {
277
+ state[propName] = evaluated;
278
+ }
279
+ }
280
+ continue;
281
+ }
282
+
283
+ if (
284
+ valNode?.type === 'CallExpression' &&
285
+ valNode.callee?.type === 'Identifier' &&
286
+ valNode.callee.name === 'computed'
287
+ ) {
288
+ const retExpr = resolveReturnedExpression(valNode.arguments?.[0]);
289
+ const evaluated = evaluateDerivedExpression(retExpr, state);
290
+ if (evaluated !== null) {
291
+ state[propName] = typeof evaluated === 'object' ? evaluated : String(evaluated);
292
+ computedSignals[propName] = state[propName];
293
+ }
294
+ continue;
295
+ }
296
+
297
+ if (
298
+ valNode?.type === 'CallExpression' &&
299
+ valNode.callee?.type === 'Identifier' &&
300
+ valNode.callee.name === 'linkedSignal'
301
+ ) {
302
+ const arg0 = valNode.arguments?.[0];
303
+ const computationProp =
304
+ arg0?.type === 'ObjectExpression'
305
+ ? (arg0.properties || []).find((p) => (p.key?.name ?? p.key?.value) === 'computation')
306
+ ?.value
307
+ : arg0;
308
+ const retExpr = resolveReturnedExpression(computationProp);
309
+ const evaluated = evaluateDerivedExpression(retExpr, state);
310
+ if (evaluated !== null) {
311
+ if (typeof evaluated === 'number') {
312
+ numericSignals[propName] = evaluated;
313
+ }
314
+ state[propName] = typeof evaluated === 'object' ? evaluated : String(evaluated);
315
+ }
316
+ continue;
317
+ }
318
+
319
+ const isInputCall =
320
+ valNode?.type === 'CallExpression' &&
321
+ ((valNode.callee?.type === 'Identifier' && valNode.callee.name === 'input') ||
322
+ (valNode.callee?.type === 'MemberExpression' &&
323
+ valNode.callee.object?.type === 'Identifier' &&
324
+ valNode.callee.object.name === 'input' &&
325
+ valNode.callee.property?.type === 'Identifier' &&
326
+ valNode.callee.property.name === 'required'));
327
+ if (isInputCall) {
328
+ const isRequired = valNode.callee?.type === 'MemberExpression';
329
+ const arg0 = isRequired ? undefined : valNode.arguments?.[0];
330
+ const lit = extractScalarLiteral(arg0);
331
+ if (lit) {
332
+ state[propName] = lit.raw;
333
+ inputs[propName] = { required: false, defaultValue: lit.value };
334
+ } else {
335
+ const evaluated = evaluateDerivedExpression(arg0, state);
336
+ if (evaluated !== null) {
337
+ state[propName] = evaluated;
338
+ }
339
+ inputs[propName] = { required: isRequired, defaultValue: evaluated };
340
+ }
341
+ continue;
342
+ }
343
+
344
+ const isModelCall =
345
+ valNode?.type === 'CallExpression' &&
346
+ ((valNode.callee?.type === 'Identifier' && valNode.callee.name === 'model') ||
347
+ (valNode.callee?.type === 'MemberExpression' &&
348
+ valNode.callee.object?.type === 'Identifier' &&
349
+ valNode.callee.object.name === 'model' &&
350
+ valNode.callee.property?.type === 'Identifier' &&
351
+ valNode.callee.property.name === 'required'));
352
+ if (isModelCall) {
353
+ const isRequired = valNode.callee?.type === 'MemberExpression';
354
+ const arg0 = isRequired ? undefined : valNode.arguments?.[0];
355
+ const lit = extractScalarLiteral(arg0);
356
+ if (lit) {
357
+ state[propName] = lit.raw;
358
+ if (lit.kind === 'number') {
359
+ numericSignals[propName] = lit.value;
360
+ }
361
+ models[propName] = { required: false, defaultValue: lit.value };
362
+ } else {
363
+ const evaluated = evaluateDerivedExpression(arg0, state);
364
+ if (evaluated !== null) {
365
+ state[propName] = evaluated;
366
+ }
367
+ models[propName] = { required: isRequired, defaultValue: evaluated };
368
+ }
369
+ continue;
370
+ }
371
+
372
+ if (
373
+ valNode?.type === 'CallExpression' &&
374
+ valNode.callee?.type === 'Identifier' &&
375
+ valNode.callee.name === 'output'
376
+ ) {
377
+ outputs[propName] = true;
378
+ continue;
379
+ }
380
+
381
+ if (
382
+ valNode?.type === 'CallExpression' &&
383
+ valNode.callee?.type === 'Identifier' &&
384
+ (valNode.callee.name === 'httpResource' ||
385
+ valNode.callee.name === 'createNativeHttpResource')
386
+ ) {
387
+ const retExpr = resolveReturnedExpression(valNode.arguments?.[0]);
388
+ const evaluated = evaluateDerivedExpression(retExpr, state);
389
+ resources[propName] = { kind: 'httpResource', url: String(evaluated ?? '') };
390
+ continue;
391
+ }
392
+
393
+ const lit = extractScalarLiteral(valNode);
394
+ if (lit && !(propName in state)) {
395
+ state[propName] = lit.raw;
396
+ } else if (!(propName in state)) {
397
+ const evaluated = evaluateDerivedExpression(valNode, state);
398
+ if (evaluated !== null) {
399
+ state[propName] = evaluated;
400
+ }
401
+ }
402
+ } else if (member.type === 'MethodDefinition' && member.kind === 'method') {
403
+ extractMethodMutation(member, methods);
404
+ }
405
+ }
406
+ }
407
+
408
+ return {
409
+ state,
410
+ numericSignals,
411
+ computedSignals,
412
+ inputs,
413
+ models,
414
+ outputs,
415
+ resources,
416
+ methods,
417
+ component,
418
+ relativeImports,
419
+ };
420
+ }