@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.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/bin/ng-desktop.mjs +191 -0
- package/builders.json +10 -0
- package/fesm2022/ast-metadata-extractor.d.mts +40 -0
- package/fesm2022/ast-metadata-extractor.mjs +420 -0
- package/fesm2022/build-bundle.d.mts +36 -0
- package/fesm2022/build-bundle.mjs +315 -0
- package/fesm2022/builder.d.ts +67 -0
- package/fesm2022/builder.d.ts.map +1 -0
- package/fesm2022/builder.js +124 -0
- package/fesm2022/builder.js.map +1 -0
- package/fesm2022/dev-server.mjs +47 -0
- package/fesm2022/hmr-client.d.mts +19 -0
- package/fesm2022/hmr-client.mjs +77 -0
- package/fesm2022/icon-compiler.d.mts +6 -0
- package/fesm2022/icon-compiler.mjs +148 -0
- package/fesm2022/index.d.ts +11 -0
- package/fesm2022/index.d.ts.map +1 -0
- package/fesm2022/index.js +11 -0
- package/fesm2022/index.js.map +1 -0
- package/fesm2022/permission-analyzer.d.mts +45 -0
- package/fesm2022/permission-analyzer.mjs +313 -0
- package/fesm2022/resolve-engine-binary.d.mts +35 -0
- package/fesm2022/resolve-engine-binary.mjs +130 -0
- package/fesm2022/style-compiler.d.mts +14 -0
- package/fesm2022/style-compiler.mjs +97 -0
- package/fesm2022/template-compiler.d.mts +53 -0
- package/fesm2022/template-compiler.mjs +810 -0
- package/fesm2022/workspace-resolver.d.mts +24 -0
- package/fesm2022/workspace-resolver.mjs +199 -0
- package/package.json +78 -4
- package/schema/angular-native-schema.json +52 -0
- package/schema/native-builder-schema.json +79 -0
- package/schematics/collection.json +10 -0
- package/schematics/ng-add/index.d.mts +20 -0
- package/schematics/ng-add/index.mjs +56 -0
- package/schematics/ng-add/schema.json +24 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const ENGINE_BINARY_PACKAGES = {
|
|
6
|
+
'linux-x64': {
|
|
7
|
+
pkgName: '@ng-desktop/engine-linux-x64-gnu',
|
|
8
|
+
dirName: 'engine-linux-x64-gnu',
|
|
9
|
+
os: 'linux',
|
|
10
|
+
cpu: 'x64',
|
|
11
|
+
libc: 'glibc',
|
|
12
|
+
binaryName: 'ng-native-engine',
|
|
13
|
+
},
|
|
14
|
+
'linux-arm64': {
|
|
15
|
+
pkgName: '@ng-desktop/engine-linux-arm64-gnu',
|
|
16
|
+
dirName: 'engine-linux-arm64-gnu',
|
|
17
|
+
os: 'linux',
|
|
18
|
+
cpu: 'arm64',
|
|
19
|
+
libc: 'glibc',
|
|
20
|
+
binaryName: 'ng-native-engine',
|
|
21
|
+
},
|
|
22
|
+
'win32-x64': {
|
|
23
|
+
pkgName: '@ng-desktop/engine-win32-x64-msvc',
|
|
24
|
+
dirName: 'engine-win32-x64-msvc',
|
|
25
|
+
os: 'win32',
|
|
26
|
+
cpu: 'x64',
|
|
27
|
+
binaryName: 'ng-native-engine.exe',
|
|
28
|
+
},
|
|
29
|
+
'darwin-arm64': {
|
|
30
|
+
pkgName: '@ng-desktop/engine-darwin-arm64',
|
|
31
|
+
dirName: 'engine-darwin-arm64',
|
|
32
|
+
os: 'darwin',
|
|
33
|
+
cpu: 'arm64',
|
|
34
|
+
binaryName: 'ng-native-engine',
|
|
35
|
+
},
|
|
36
|
+
'darwin-x64': {
|
|
37
|
+
pkgName: '@ng-desktop/engine-darwin-x64',
|
|
38
|
+
dirName: 'engine-darwin-x64',
|
|
39
|
+
os: 'darwin',
|
|
40
|
+
cpu: 'x64',
|
|
41
|
+
binaryName: 'ng-native-engine',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function defaultResolvePkgJsonPath(pkgName, cwd) {
|
|
46
|
+
try {
|
|
47
|
+
const req = createRequire(resolve(cwd, 'package.json'));
|
|
48
|
+
return req.resolve(`${pkgName}/package.json`);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the prebuilt `ng-native-engine` host executable in priority order:
|
|
56
|
+
* 1. Explicit `NG_DESKTOP_ENGINE_BIN` / `NG_NATIVE_ENGINE_BIN` environment override
|
|
57
|
+
* 2. Installed platform-specific `@ng-desktop/engine-*` npm `optionalDependencies` package
|
|
58
|
+
* 3. Local Cargo build artifact (`target/release` then `target/debug`)
|
|
59
|
+
* 4. Fallback to `cargo run --` for source-checkout development
|
|
60
|
+
*/
|
|
61
|
+
export function resolveEngineBinaryPath({
|
|
62
|
+
env = process.env,
|
|
63
|
+
platform = process.platform,
|
|
64
|
+
arch = process.arch,
|
|
65
|
+
cwd = process.cwd(),
|
|
66
|
+
workspaceRoot,
|
|
67
|
+
resolvePkgPath,
|
|
68
|
+
fileExists = existsSync,
|
|
69
|
+
} = {}) {
|
|
70
|
+
const targetKey = `${platform}-${arch}`;
|
|
71
|
+
const entry = ENGINE_BINARY_PACKAGES[targetKey] ?? null;
|
|
72
|
+
const fallbackBinName = platform === 'win32' ? 'ng-native-engine.exe' : 'ng-native-engine';
|
|
73
|
+
const binName = entry?.binaryName ?? fallbackBinName;
|
|
74
|
+
|
|
75
|
+
const envOverride =
|
|
76
|
+
env?.['NG_DESKTOP_ENGINE_BIN']?.trim() || env?.['NG_NATIVE_ENGINE_BIN']?.trim();
|
|
77
|
+
if (envOverride) {
|
|
78
|
+
return {
|
|
79
|
+
mode: 'binary',
|
|
80
|
+
command: envOverride,
|
|
81
|
+
args: [],
|
|
82
|
+
source: 'env',
|
|
83
|
+
packageName: entry?.pkgName ?? null,
|
|
84
|
+
targetKey,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (entry) {
|
|
89
|
+
const pkgJsonPath = resolvePkgPath
|
|
90
|
+
? resolvePkgPath(entry.pkgName)
|
|
91
|
+
: defaultResolvePkgJsonPath(entry.pkgName, cwd);
|
|
92
|
+
if (pkgJsonPath) {
|
|
93
|
+
const candidateBin = resolve(dirname(pkgJsonPath), 'bin', entry.binaryName);
|
|
94
|
+
if (fileExists(candidateBin)) {
|
|
95
|
+
return {
|
|
96
|
+
mode: 'binary',
|
|
97
|
+
command: candidateBin,
|
|
98
|
+
args: [],
|
|
99
|
+
source: 'optional-package',
|
|
100
|
+
packageName: entry.pkgName,
|
|
101
|
+
targetKey,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const searchRoot = workspaceRoot ?? cwd;
|
|
108
|
+
for (const profile of ['release', 'debug']) {
|
|
109
|
+
const localBin = resolve(searchRoot, 'target', profile, binName);
|
|
110
|
+
if (fileExists(localBin)) {
|
|
111
|
+
return {
|
|
112
|
+
mode: 'binary',
|
|
113
|
+
command: localBin,
|
|
114
|
+
args: [],
|
|
115
|
+
source: 'cargo-target',
|
|
116
|
+
packageName: entry?.pkgName ?? null,
|
|
117
|
+
targetKey,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
mode: 'cargo',
|
|
124
|
+
command: 'cargo',
|
|
125
|
+
args: ['run', '--'],
|
|
126
|
+
source: 'cargo-fallback',
|
|
127
|
+
packageName: entry?.pkgName ?? null,
|
|
128
|
+
targetKey,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface StyleRuleIr {
|
|
2
|
+
className: string;
|
|
3
|
+
background: string;
|
|
4
|
+
color: string;
|
|
5
|
+
padding: string;
|
|
6
|
+
spacing: string;
|
|
7
|
+
borderRadius: number | null;
|
|
8
|
+
fontSize: number | null;
|
|
9
|
+
fontWeight: number | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function parseStylesCss(cssSource: string, from?: string): StyleRuleIr[];
|
|
13
|
+
|
|
14
|
+
export function emitStyleInstruction(rule: StyleRuleIr): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
|
|
3
|
+
const SIMPLE_CLASS_SELECTOR = /^\.([a-zA-Z0-9_-]+)$/;
|
|
4
|
+
|
|
5
|
+
function toPixelInt(raw) {
|
|
6
|
+
const parsed = Number.parseInt(String(raw).trim().replace(/px$/, ''), 10);
|
|
7
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function createEmptyRule(className) {
|
|
11
|
+
return {
|
|
12
|
+
className,
|
|
13
|
+
background: 'none',
|
|
14
|
+
color: 'none',
|
|
15
|
+
padding: '0',
|
|
16
|
+
spacing: '0',
|
|
17
|
+
borderRadius: null,
|
|
18
|
+
fontSize: null,
|
|
19
|
+
fontWeight: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function applyDeclaration(rule, prop, value) {
|
|
24
|
+
switch (prop) {
|
|
25
|
+
case 'background':
|
|
26
|
+
case 'background-color':
|
|
27
|
+
rule.background = value;
|
|
28
|
+
break;
|
|
29
|
+
case 'color':
|
|
30
|
+
rule.color = value;
|
|
31
|
+
break;
|
|
32
|
+
case 'padding': {
|
|
33
|
+
const px = toPixelInt(value);
|
|
34
|
+
if (px !== null) rule.padding = String(px);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'gap':
|
|
38
|
+
case 'spacing': {
|
|
39
|
+
const px = toPixelInt(value);
|
|
40
|
+
if (px !== null) rule.spacing = String(px);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'border-radius':
|
|
44
|
+
rule.borderRadius = toPixelInt(value);
|
|
45
|
+
break;
|
|
46
|
+
case 'font-size':
|
|
47
|
+
rule.fontSize = toPixelInt(value);
|
|
48
|
+
break;
|
|
49
|
+
case 'font-weight': {
|
|
50
|
+
const keyword = { normal: 400, bold: 700 }[value];
|
|
51
|
+
rule.fontWeight = keyword ?? toPixelInt(value);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parses component CSS with the `postcss` AST into the native Style IR.
|
|
61
|
+
* Only simple class selectors (`.name`, including selector lists) are mapped;
|
|
62
|
+
* pseudo-classes, combinators, and at-rules are skipped because the native
|
|
63
|
+
* backends have no equivalent for them yet.
|
|
64
|
+
*/
|
|
65
|
+
export function parseStylesCss(cssSource, from = 'app.css') {
|
|
66
|
+
const root = postcss.parse(cssSource, { from });
|
|
67
|
+
const rulesByClass = new Map();
|
|
68
|
+
|
|
69
|
+
root.walkRules((cssRule) => {
|
|
70
|
+
if (cssRule.parent?.type === 'atrule') return;
|
|
71
|
+
|
|
72
|
+
for (const selector of cssRule.selectors) {
|
|
73
|
+
const match = selector.trim().match(SIMPLE_CLASS_SELECTOR);
|
|
74
|
+
if (!match) continue;
|
|
75
|
+
|
|
76
|
+
const className = match[1];
|
|
77
|
+
const rule = rulesByClass.get(className) ?? createEmptyRule(className);
|
|
78
|
+
cssRule.walkDecls((decl) => applyDeclaration(rule, decl.prop, decl.value.trim()));
|
|
79
|
+
rulesByClass.set(className, rule);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return [...rulesByClass.values()];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Serializes a Style IR rule into a `.ngb` `style` instruction, appending optional
|
|
88
|
+
* `key=value` extensions only when declared (keeps legacy bundles byte-identical).
|
|
89
|
+
*/
|
|
90
|
+
export function emitStyleInstruction(rule) {
|
|
91
|
+
const base = `style ${rule.className} ${rule.background} ${rule.color} ${rule.padding} ${rule.spacing}`;
|
|
92
|
+
const extensions = [];
|
|
93
|
+
if (rule.borderRadius !== null) extensions.push(`radius=${rule.borderRadius}`);
|
|
94
|
+
if (rule.fontSize !== null) extensions.push(`font-size=${rule.fontSize}`);
|
|
95
|
+
if (rule.fontWeight !== null) extensions.push(`font-weight=${rule.fontWeight}`);
|
|
96
|
+
return extensions.length > 0 ? `${base} ${extensions.join(' ')}` : base;
|
|
97
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface ReactiveBindingIr {
|
|
2
|
+
signalName: string;
|
|
3
|
+
template: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ReactiveAttrBindingIr {
|
|
7
|
+
attrKey: string;
|
|
8
|
+
signalName: string;
|
|
9
|
+
template: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface VisibilityBindingIr {
|
|
13
|
+
signalName: string;
|
|
14
|
+
op: string;
|
|
15
|
+
rhs: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TemplateAstNode {
|
|
19
|
+
id: string;
|
|
20
|
+
tag: string;
|
|
21
|
+
isComment?: boolean;
|
|
22
|
+
text: string | null;
|
|
23
|
+
title: string | null;
|
|
24
|
+
classes: string[];
|
|
25
|
+
attributes: Record<string, string>;
|
|
26
|
+
reactiveBinding: ReactiveBindingIr | null;
|
|
27
|
+
reactiveAttrs?: ReactiveAttrBindingIr[];
|
|
28
|
+
visibilityBinding?: VisibilityBindingIr | null;
|
|
29
|
+
events: Record<string, string>;
|
|
30
|
+
children: TemplateAstNode[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ComponentDefinitionIr {
|
|
34
|
+
templateHtml: string;
|
|
35
|
+
templateUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TemplateIdState {
|
|
39
|
+
next: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function applyPipeTransform(value: unknown, pipeName: string, args?: unknown[]): unknown;
|
|
43
|
+
|
|
44
|
+
export function parseTemplateHtml(
|
|
45
|
+
html: string,
|
|
46
|
+
state: Record<string, unknown>,
|
|
47
|
+
numericSignals: Record<string, number>,
|
|
48
|
+
templateUrl?: string,
|
|
49
|
+
componentRegistry?: Record<string, ComponentDefinitionIr>,
|
|
50
|
+
projectedChildren?: TemplateAstNode[] | null,
|
|
51
|
+
idState?: TemplateIdState,
|
|
52
|
+
signalAliases?: Record<string, string>,
|
|
53
|
+
): TemplateAstNode[];
|