@ng-desktop/builders 0.0.0-stage → 0.4.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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -2
  3. package/bin/ng-desktop.mjs +200 -0
  4. package/builders.json +15 -0
  5. package/fesm2022/application-builder.d.mts +62 -0
  6. package/fesm2022/application-builder.mjs +58 -0
  7. package/fesm2022/ast-metadata-extractor.d.mts +40 -0
  8. package/fesm2022/ast-metadata-extractor.mjs +460 -0
  9. package/fesm2022/build-bundle.d.mts +45 -0
  10. package/fesm2022/build-bundle.mjs +462 -0
  11. package/fesm2022/builder.d.ts +66 -0
  12. package/fesm2022/builder.js +123 -0
  13. package/fesm2022/dev-server-builder.d.mts +26 -0
  14. package/fesm2022/dev-server-builder.mjs +24 -0
  15. package/fesm2022/dev-server.mjs +47 -0
  16. package/fesm2022/hmr-client.d.mts +24 -0
  17. package/fesm2022/hmr-client.mjs +84 -0
  18. package/fesm2022/icon-compiler.d.mts +6 -0
  19. package/fesm2022/icon-compiler.mjs +148 -0
  20. package/fesm2022/index.d.ts +13 -0
  21. package/fesm2022/index.js +13 -0
  22. package/fesm2022/permission-analyzer.d.mts +45 -0
  23. package/fesm2022/permission-analyzer.mjs +333 -0
  24. package/fesm2022/resolve-engine-binary.d.mts +35 -0
  25. package/fesm2022/resolve-engine-binary.mjs +130 -0
  26. package/fesm2022/server-compiler.d.mts +29 -0
  27. package/fesm2022/server-compiler.mjs +236 -0
  28. package/fesm2022/style-compiler.d.mts +26 -0
  29. package/fesm2022/style-compiler.mjs +258 -0
  30. package/fesm2022/template-compiler.d.mts +53 -0
  31. package/fesm2022/template-compiler.mjs +892 -0
  32. package/fesm2022/workspace-resolver.d.mts +24 -0
  33. package/fesm2022/workspace-resolver.mjs +199 -0
  34. package/package.json +79 -4
  35. package/schema/angular-native-schema.json +52 -0
  36. package/schema/native-builder-schema.json +97 -0
  37. package/schematics/collection.json +10 -0
  38. package/schematics/ng-add/index.d.mts +20 -0
  39. package/schematics/ng-add/index.mjs +56 -0
  40. package/schematics/ng-add/schema.json +24 -0
@@ -0,0 +1,460 @@
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 extractStaticStringValue(node) {
108
+ const lit = extractScalarLiteral(node);
109
+ if (lit?.kind === 'string') {
110
+ return lit.value;
111
+ }
112
+ if (node?.type === 'TemplateLiteral' && (node.expressions?.length ?? 0) === 0) {
113
+ return (node.quasis ?? []).map((q) => q.value?.cooked ?? q.value?.raw ?? '').join('');
114
+ }
115
+ return null;
116
+ }
117
+
118
+ function extractDecoratorMetadata(decorators = [], isRootApp = false) {
119
+ const component = {
120
+ selector: 'app-root',
121
+ template: null,
122
+ templateUrl: isRootApp ? './app.html' : null,
123
+ styleUrl: isRootApp ? './app.css' : null,
124
+ styleUrls: [],
125
+ styles: [],
126
+ imports: [],
127
+ hasComponentDecorator: false,
128
+ };
129
+
130
+ for (const dec of decorators) {
131
+ const expr = dec.expression;
132
+ if (
133
+ expr?.type !== 'CallExpression' ||
134
+ expr.callee?.type !== 'Identifier' ||
135
+ expr.callee.name !== 'Component'
136
+ ) {
137
+ continue;
138
+ }
139
+
140
+ component.hasComponentDecorator = true;
141
+ const arg = expr.arguments?.[0];
142
+ if (arg?.type !== 'ObjectExpression') continue;
143
+
144
+ for (const prop of arg.properties || []) {
145
+ if (prop.type !== 'Property' || prop.key?.type !== 'Identifier') continue;
146
+
147
+ if (prop.key.name === 'imports' && prop.value?.type === 'ArrayExpression') {
148
+ component.imports = (prop.value.elements || [])
149
+ .filter((el) => el?.type === 'Identifier')
150
+ .map((el) => el.name);
151
+ continue;
152
+ }
153
+
154
+ if (prop.key.name === 'styleUrls' && prop.value?.type === 'ArrayExpression') {
155
+ component.styleUrls = (prop.value.elements || [])
156
+ .map((el) => extractStaticStringValue(el))
157
+ .filter((v) => typeof v === 'string' && v.length > 0);
158
+ continue;
159
+ }
160
+
161
+ if (prop.key.name === 'styles' && prop.value?.type === 'ArrayExpression') {
162
+ component.styles = (prop.value.elements || [])
163
+ .map((el) => extractStaticStringValue(el))
164
+ .filter((v) => typeof v === 'string' && v.length > 0);
165
+ continue;
166
+ }
167
+
168
+ const strVal = extractStaticStringValue(prop.value);
169
+ if (strVal === null) continue;
170
+
171
+ if (prop.key.name === 'selector') component.selector = strVal;
172
+ if (prop.key.name === 'template') component.template = strVal;
173
+ if (prop.key.name === 'templateUrl') component.templateUrl = strVal;
174
+ if (prop.key.name === 'styleUrl') component.styleUrl = strVal;
175
+ }
176
+ }
177
+
178
+ return component;
179
+ }
180
+
181
+ function resolveReturnedExpression(fnNode) {
182
+ if (!fnNode?.body) return null;
183
+ if (fnNode.body.type !== 'BlockStatement') {
184
+ return fnNode.body;
185
+ }
186
+
187
+ for (const stmt of fnNode.body.body || []) {
188
+ if (stmt.type === 'ReturnStatement') {
189
+ return stmt.argument;
190
+ }
191
+ }
192
+ return null;
193
+ }
194
+
195
+ function extractMethodMutation(methodDef, methods) {
196
+ const methodName = methodDef.key?.type === 'Identifier' ? methodDef.key.name : null;
197
+ if (!methodName) return;
198
+
199
+ const statements = methodDef.value?.body?.body || [];
200
+ for (const stmt of statements) {
201
+ if (stmt.type !== 'ExpressionStatement' || stmt.expression?.type !== 'CallExpression') {
202
+ continue;
203
+ }
204
+
205
+ const callExpr = stmt.expression;
206
+ const callee = callExpr.callee;
207
+ if (
208
+ callee?.type !== 'MemberExpression' ||
209
+ callee.property?.type !== 'Identifier' ||
210
+ callee.object?.type !== 'MemberExpression' ||
211
+ callee.object.object?.type !== 'ThisExpression' ||
212
+ callee.object.property?.type !== 'Identifier'
213
+ ) {
214
+ continue;
215
+ }
216
+
217
+ const signalName = callee.object.property.name;
218
+ const action = callee.property.name;
219
+
220
+ if (action === 'set') {
221
+ const lit = extractScalarLiteral(callExpr.arguments?.[0]);
222
+ if (lit?.kind === 'number') {
223
+ methods[methodName] = { kind: 'set', signalName, value: lit.value };
224
+ }
225
+ continue;
226
+ }
227
+
228
+ if (action === 'update') {
229
+ const fnArg = callExpr.arguments?.[0];
230
+ const retExpr = resolveReturnedExpression(fnArg);
231
+ if (
232
+ retExpr?.type === 'BinaryExpression' &&
233
+ (retExpr.operator === '+' || retExpr.operator === '-')
234
+ ) {
235
+ const rightLit = extractScalarLiteral(retExpr.right);
236
+ if (rightLit?.kind === 'number') {
237
+ const delta = retExpr.operator === '-' ? -rightLit.value : rightLit.value;
238
+ methods[methodName] = { kind: 'add', signalName, value: delta };
239
+ }
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Parses an Angular 22 TypeScript component source file using the Rust-based `oxc-parser` AST
247
+ * and extracts `@Component` decorator paths/imports, `signal(...)`, `computed(...)`,
248
+ * `linkedSignal(...)`, `input(...)`, `model(...)`, `output()`, `httpResource(...)`,
249
+ * class properties, and signal mutation methods.
250
+ */
251
+ export function extractComponentMetadata(tsSource, filename = 'app.ts') {
252
+ const parsed = parseSync(filename, tsSource);
253
+ const state = {};
254
+ const numericSignals = {};
255
+ const computedSignals = {};
256
+ const inputs = {};
257
+ const models = {};
258
+ const outputs = {};
259
+ const resources = {};
260
+ const methods = {};
261
+ const relativeImports = {};
262
+ const isRootApp =
263
+ filename === 'app.ts' || filename.endsWith('/app.ts') || filename.endsWith('\\app.ts');
264
+ let component = {
265
+ selector: 'app-root',
266
+ template: null,
267
+ templateUrl: isRootApp ? './app.html' : null,
268
+ styleUrl: isRootApp ? './app.css' : null,
269
+ styleUrls: [],
270
+ styles: [],
271
+ imports: [],
272
+ hasComponentDecorator: false,
273
+ };
274
+
275
+ for (const stmt of parsed.program.body || []) {
276
+ if (stmt.type === 'ImportDeclaration' && stmt.source?.value?.startsWith('.')) {
277
+ for (const spec of stmt.specifiers || []) {
278
+ if (spec.local?.name) {
279
+ relativeImports[spec.local.name] = stmt.source.value;
280
+ }
281
+ }
282
+ continue;
283
+ }
284
+
285
+ const decl =
286
+ stmt.type === 'ExportNamedDeclaration' || stmt.type === 'ExportDefaultDeclaration'
287
+ ? stmt.declaration
288
+ : stmt;
289
+
290
+ if (decl?.type !== 'ClassDeclaration') continue;
291
+
292
+ const extractedDec = extractDecoratorMetadata(decl.decorators, isRootApp);
293
+ if (extractedDec.hasComponentDecorator) {
294
+ component = extractedDec;
295
+ }
296
+
297
+ for (const member of decl.body?.body || []) {
298
+ if (member.type === 'PropertyDefinition' && member.key?.type === 'Identifier') {
299
+ const propName = member.key.name;
300
+ const valNode = member.value;
301
+
302
+ if (
303
+ valNode?.type === 'CallExpression' &&
304
+ valNode.callee?.type === 'Identifier' &&
305
+ valNode.callee.name === 'signal'
306
+ ) {
307
+ const arg0 = valNode.arguments?.[0];
308
+ const lit = extractScalarLiteral(arg0);
309
+ if (lit) {
310
+ state[propName] = lit.raw;
311
+ if (lit.kind === 'number') {
312
+ numericSignals[propName] = lit.value;
313
+ }
314
+ } else {
315
+ const evaluated = evaluateDerivedExpression(arg0, state);
316
+ if (evaluated !== null) {
317
+ state[propName] = evaluated;
318
+ }
319
+ }
320
+ continue;
321
+ }
322
+
323
+ if (
324
+ valNode?.type === 'CallExpression' &&
325
+ valNode.callee?.type === 'Identifier' &&
326
+ valNode.callee.name === 'computed'
327
+ ) {
328
+ const retExpr = resolveReturnedExpression(valNode.arguments?.[0]);
329
+ const evaluated = evaluateDerivedExpression(retExpr, state);
330
+ if (evaluated !== null) {
331
+ state[propName] = typeof evaluated === 'object' ? evaluated : String(evaluated);
332
+ computedSignals[propName] = state[propName];
333
+ }
334
+ continue;
335
+ }
336
+
337
+ if (
338
+ valNode?.type === 'CallExpression' &&
339
+ valNode.callee?.type === 'Identifier' &&
340
+ valNode.callee.name === 'linkedSignal'
341
+ ) {
342
+ const arg0 = valNode.arguments?.[0];
343
+ const computationProp =
344
+ arg0?.type === 'ObjectExpression'
345
+ ? (arg0.properties || []).find((p) => (p.key?.name ?? p.key?.value) === 'computation')
346
+ ?.value
347
+ : arg0;
348
+ const retExpr = resolveReturnedExpression(computationProp);
349
+ const evaluated = evaluateDerivedExpression(retExpr, state);
350
+ if (evaluated !== null) {
351
+ if (typeof evaluated === 'number') {
352
+ numericSignals[propName] = evaluated;
353
+ }
354
+ state[propName] = typeof evaluated === 'object' ? evaluated : String(evaluated);
355
+ }
356
+ continue;
357
+ }
358
+
359
+ const isInputCall =
360
+ valNode?.type === 'CallExpression' &&
361
+ ((valNode.callee?.type === 'Identifier' && valNode.callee.name === 'input') ||
362
+ (valNode.callee?.type === 'MemberExpression' &&
363
+ valNode.callee.object?.type === 'Identifier' &&
364
+ valNode.callee.object.name === 'input' &&
365
+ valNode.callee.property?.type === 'Identifier' &&
366
+ valNode.callee.property.name === 'required'));
367
+ if (isInputCall) {
368
+ const isRequired = valNode.callee?.type === 'MemberExpression';
369
+ const arg0 = isRequired ? undefined : valNode.arguments?.[0];
370
+ const lit = extractScalarLiteral(arg0);
371
+ if (lit) {
372
+ state[propName] = lit.raw;
373
+ inputs[propName] = { required: false, defaultValue: lit.value };
374
+ } else {
375
+ const evaluated = evaluateDerivedExpression(arg0, state);
376
+ if (evaluated !== null) {
377
+ state[propName] = evaluated;
378
+ }
379
+ inputs[propName] = { required: isRequired, defaultValue: evaluated };
380
+ }
381
+ continue;
382
+ }
383
+
384
+ const isModelCall =
385
+ valNode?.type === 'CallExpression' &&
386
+ ((valNode.callee?.type === 'Identifier' && valNode.callee.name === 'model') ||
387
+ (valNode.callee?.type === 'MemberExpression' &&
388
+ valNode.callee.object?.type === 'Identifier' &&
389
+ valNode.callee.object.name === 'model' &&
390
+ valNode.callee.property?.type === 'Identifier' &&
391
+ valNode.callee.property.name === 'required'));
392
+ if (isModelCall) {
393
+ const isRequired = valNode.callee?.type === 'MemberExpression';
394
+ const arg0 = isRequired ? undefined : valNode.arguments?.[0];
395
+ const lit = extractScalarLiteral(arg0);
396
+ if (lit) {
397
+ state[propName] = lit.raw;
398
+ if (lit.kind === 'number') {
399
+ numericSignals[propName] = lit.value;
400
+ }
401
+ models[propName] = { required: false, defaultValue: lit.value };
402
+ } else {
403
+ const evaluated = evaluateDerivedExpression(arg0, state);
404
+ if (evaluated !== null) {
405
+ state[propName] = evaluated;
406
+ }
407
+ models[propName] = { required: isRequired, defaultValue: evaluated };
408
+ }
409
+ continue;
410
+ }
411
+
412
+ if (
413
+ valNode?.type === 'CallExpression' &&
414
+ valNode.callee?.type === 'Identifier' &&
415
+ valNode.callee.name === 'output'
416
+ ) {
417
+ outputs[propName] = true;
418
+ continue;
419
+ }
420
+
421
+ if (
422
+ valNode?.type === 'CallExpression' &&
423
+ valNode.callee?.type === 'Identifier' &&
424
+ (valNode.callee.name === 'httpResource' ||
425
+ valNode.callee.name === 'createNativeHttpResource')
426
+ ) {
427
+ const retExpr = resolveReturnedExpression(valNode.arguments?.[0]);
428
+ const evaluated = evaluateDerivedExpression(retExpr, state);
429
+ resources[propName] = { kind: 'httpResource', url: String(evaluated ?? '') };
430
+ continue;
431
+ }
432
+
433
+ const lit = extractScalarLiteral(valNode);
434
+ if (lit && !(propName in state)) {
435
+ state[propName] = lit.raw;
436
+ } else if (!(propName in state)) {
437
+ const evaluated = evaluateDerivedExpression(valNode, state);
438
+ if (evaluated !== null) {
439
+ state[propName] = evaluated;
440
+ }
441
+ }
442
+ } else if (member.type === 'MethodDefinition' && member.kind === 'method') {
443
+ extractMethodMutation(member, methods);
444
+ }
445
+ }
446
+ }
447
+
448
+ return {
449
+ state,
450
+ numericSignals,
451
+ computedSignals,
452
+ inputs,
453
+ models,
454
+ outputs,
455
+ resources,
456
+ methods,
457
+ component,
458
+ relativeImports,
459
+ };
460
+ }
@@ -0,0 +1,45 @@
1
+ import { FSWatcher } from 'node:fs';
2
+ import { PermissionAnalysisManifest } from './permission-analyzer.mjs';
3
+ import { StyleRuleIr } from './style-compiler.mjs';
4
+ import { TemplateAstNode } from './template-compiler.mjs';
5
+
6
+ export interface CompileBundleOptions {
7
+ rebuildIcons?: boolean;
8
+ cwd?: string;
9
+ configPath?: string;
10
+ projectName?: string;
11
+ version?: string;
12
+ }
13
+
14
+ export interface HmrDeltaSummary {
15
+ ngbChanged: boolean;
16
+ appBundleChanged: boolean;
17
+ serverBundleChanged: boolean;
18
+ }
19
+
20
+ export interface CompileBundleResult {
21
+ projectName: string;
22
+ version: string;
23
+ sourceRoot: string;
24
+ bundleFile: string;
25
+ entryBundleFile?: string;
26
+ serverBundleFile?: string;
27
+ permissionsFile: string;
28
+ runtimeConfigFile: string;
29
+ permissions: PermissionAnalysisManifest;
30
+ socketPath: string;
31
+ hmrDelta: HmrDeltaSummary;
32
+ }
33
+
34
+ export function emitNgbBundle(
35
+ styleRules: StyleRuleIr[],
36
+ numericSignals: Record<string, number>,
37
+ methods: Record<string, { kind: 'set' | 'add'; signalName: string; value: number }>,
38
+ astRoots: TemplateAstNode[],
39
+ iconMeta: { appId: string; relPath: string } | null,
40
+ sourceLabel: string,
41
+ ): string;
42
+
43
+ export function compileBundle(options?: CompileBundleOptions): CompileBundleResult;
44
+
45
+ export function watchBundle(options?: CompileBundleOptions): FSWatcher;