@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,77 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import net from 'node:net';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sends an HMR IPC message to the running native Rust engine over a local Unix domain socket.
|
|
6
|
+
* Gracefully resolves with `{ connected: false }` if the engine is not currently running.
|
|
7
|
+
*/
|
|
8
|
+
export function sendHmrMessage(socketPath, message, { timeoutMs = 1500 } = {}) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
if (!existsSync(socketPath)) {
|
|
11
|
+
resolve({ connected: false, error: 'Socket file not found' });
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const client = net.createConnection(socketPath);
|
|
16
|
+
let resolved = false;
|
|
17
|
+
let responseData = '';
|
|
18
|
+
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
if (!resolved) {
|
|
21
|
+
resolved = true;
|
|
22
|
+
client.destroy();
|
|
23
|
+
resolve({ connected: true, timeout: true });
|
|
24
|
+
}
|
|
25
|
+
}, timeoutMs);
|
|
26
|
+
|
|
27
|
+
client.on('connect', () => {
|
|
28
|
+
client.write(JSON.stringify(message) + '\n');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
client.on('data', (chunk) => {
|
|
32
|
+
responseData += chunk.toString();
|
|
33
|
+
if (responseData.includes('\n')) {
|
|
34
|
+
const line = responseData.split('\n')[0].trim();
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
if (!resolved) {
|
|
37
|
+
resolved = true;
|
|
38
|
+
client.end();
|
|
39
|
+
try {
|
|
40
|
+
resolve({ connected: true, response: JSON.parse(line) });
|
|
41
|
+
} catch {
|
|
42
|
+
resolve({ connected: true, rawResponse: line });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
client.on('error', (err) => {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
if (!resolved) {
|
|
51
|
+
resolved = true;
|
|
52
|
+
resolve({ connected: false, error: err.message });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Pushes a newly compiled `.ngb` bundle to the live running desktop window.
|
|
60
|
+
*/
|
|
61
|
+
export async function pushHmrReload(socketPath, bundleScript) {
|
|
62
|
+
return sendHmrMessage(socketPath, { type: 'reload', script: bundleScript });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Evaluates arbitrary JavaScript inside the active runtime of the running desktop window.
|
|
67
|
+
*/
|
|
68
|
+
export async function pushHmrEval(socketPath, jsCode) {
|
|
69
|
+
return sendHmrMessage(socketPath, { type: 'eval', code: jsCode });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Pings the running desktop engine to check IPC connectivity.
|
|
74
|
+
*/
|
|
75
|
+
export async function pingHmr(socketPath) {
|
|
76
|
+
return sendHmrMessage(socketPath, { type: 'ping' });
|
|
77
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { deflateSync } from 'node:zlib';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Multi-Resolution Icon Compiler (SRP):
|
|
8
|
+
* Decodes 32-bit DIB frames from `favicon.ico` and emits multi-DPI PNGs (`16x16`..`256x256`)
|
|
9
|
+
* for the Freedesktop `hicolor` theme and desktop taskbar integration.
|
|
10
|
+
*/
|
|
11
|
+
function crc32(buf) {
|
|
12
|
+
let crc = 0xffffffff;
|
|
13
|
+
for (let i = 0; i < buf.length; i++) {
|
|
14
|
+
crc ^= buf[i];
|
|
15
|
+
for (let j = 0; j < 8; j++) {
|
|
16
|
+
crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function makePngChunk(type, data) {
|
|
23
|
+
const len = Buffer.alloc(4);
|
|
24
|
+
len.writeUInt32BE(data.length, 0);
|
|
25
|
+
const typeBuf = Buffer.from(type, 'ascii');
|
|
26
|
+
const crcBuf = Buffer.alloc(4);
|
|
27
|
+
crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])), 0);
|
|
28
|
+
return Buffer.concat([len, typeBuf, data, crcBuf]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function encodeRgbaToPng(width, height, rgba) {
|
|
32
|
+
const signature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
33
|
+
const ihdr = Buffer.alloc(13);
|
|
34
|
+
ihdr.writeUInt32BE(width, 0);
|
|
35
|
+
ihdr.writeUInt32BE(height, 4);
|
|
36
|
+
ihdr[8] = 8;
|
|
37
|
+
ihdr[9] = 6;
|
|
38
|
+
|
|
39
|
+
const stride = width * 4;
|
|
40
|
+
const rawScanlines = Buffer.alloc((stride + 1) * height);
|
|
41
|
+
for (let y = 0; y < height; y++) {
|
|
42
|
+
const rowStart = y * (stride + 1);
|
|
43
|
+
rawScanlines[rowStart] = 0;
|
|
44
|
+
rgba.copy(rawScanlines, rowStart + 1, y * stride, (y + 1) * stride);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const idat = deflateSync(rawScanlines);
|
|
48
|
+
return Buffer.concat([
|
|
49
|
+
signature,
|
|
50
|
+
makePngChunk('IHDR', ihdr),
|
|
51
|
+
makePngChunk('IDAT', idat),
|
|
52
|
+
makePngChunk('IEND', Buffer.alloc(0)),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function extractIcoFrames(icoBuf) {
|
|
57
|
+
const count = icoBuf.readUInt16LE(4);
|
|
58
|
+
const frames = [];
|
|
59
|
+
for (let i = 0; i < count; i++) {
|
|
60
|
+
const entryOff = 6 + i * 16;
|
|
61
|
+
const width = icoBuf[entryOff] || 256;
|
|
62
|
+
const height = icoBuf[entryOff + 1] || 256;
|
|
63
|
+
const bpp = icoBuf.readUInt16LE(entryOff + 6);
|
|
64
|
+
const imgOff = icoBuf.readUInt32LE(entryOff + 12);
|
|
65
|
+
|
|
66
|
+
if (bpp !== 32) continue;
|
|
67
|
+
const headerSize = icoBuf.readUInt32LE(imgOff);
|
|
68
|
+
const pixelStart = imgOff + headerSize;
|
|
69
|
+
const rgba = Buffer.alloc(width * height * 4);
|
|
70
|
+
|
|
71
|
+
for (let y = 0; y < height; y++) {
|
|
72
|
+
const srcRow = height - 1 - y;
|
|
73
|
+
for (let x = 0; x < width; x++) {
|
|
74
|
+
const srcIdx = pixelStart + (srcRow * width + x) * 4;
|
|
75
|
+
const dstIdx = (y * width + x) * 4;
|
|
76
|
+
rgba[dstIdx] = icoBuf[srcIdx + 2];
|
|
77
|
+
rgba[dstIdx + 1] = icoBuf[srcIdx + 1];
|
|
78
|
+
rgba[dstIdx + 2] = icoBuf[srcIdx];
|
|
79
|
+
rgba[dstIdx + 3] = icoBuf[srcIdx + 3];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
frames.push({ width, height, rgba });
|
|
83
|
+
}
|
|
84
|
+
return frames;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function scaleNearest(frame, targetSize) {
|
|
88
|
+
if (frame.width === targetSize && frame.height === targetSize) {
|
|
89
|
+
return frame.rgba;
|
|
90
|
+
}
|
|
91
|
+
const out = Buffer.alloc(targetSize * targetSize * 4);
|
|
92
|
+
for (let y = 0; y < targetSize; y++) {
|
|
93
|
+
const srcY = Math.min(frame.height - 1, Math.floor((y * frame.height) / targetSize));
|
|
94
|
+
for (let x = 0; x < targetSize; x++) {
|
|
95
|
+
const srcX = Math.min(frame.width - 1, Math.floor((x * frame.width) / targetSize));
|
|
96
|
+
const srcIdx = (srcY * frame.width + srcX) * 4;
|
|
97
|
+
const dstIdx = (y * targetSize + x) * 4;
|
|
98
|
+
frame.rgba.copy(out, dstIdx, srcIdx, srcIdx + 4);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function buildMultiResolutionIcons(icoAbsPath, appId, outDir, windowTitle) {
|
|
105
|
+
const icoBuf = readFileSync(icoAbsPath);
|
|
106
|
+
const frames = extractIcoFrames(icoBuf);
|
|
107
|
+
if (frames.length === 0) return;
|
|
108
|
+
|
|
109
|
+
frames.sort((a, b) => b.width - a.width);
|
|
110
|
+
const targetSizes = [16, 24, 32, 48, 64, 128, 256];
|
|
111
|
+
const localShare = resolve(homedir(), '.local/share');
|
|
112
|
+
|
|
113
|
+
for (const size of targetSizes) {
|
|
114
|
+
const exact = frames.find((f) => f.width === size) || frames[0];
|
|
115
|
+
const scaledRgba = scaleNearest(exact, size);
|
|
116
|
+
const pngBytes = encodeRgbaToPng(size, size, scaledRgba);
|
|
117
|
+
|
|
118
|
+
const distIconDir = resolve(outDir, 'icons/hicolor', `${size}x${size}`, 'apps');
|
|
119
|
+
mkdirSync(distIconDir, { recursive: true });
|
|
120
|
+
writeFileSync(resolve(distIconDir, `${appId}.png`), pngBytes);
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const userIconDir = resolve(localShare, 'icons/hicolor', `${size}x${size}`, 'apps');
|
|
124
|
+
mkdirSync(userIconDir, { recursive: true });
|
|
125
|
+
writeFileSync(resolve(userIconDir, `${appId}.png`), pngBytes);
|
|
126
|
+
} catch {
|
|
127
|
+
// Ignore if running in a restricted sandbox without ~/.local/share write access
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const appsDir = resolve(localShare, 'applications');
|
|
133
|
+
mkdirSync(appsDir, { recursive: true });
|
|
134
|
+
const desktopEntry = [
|
|
135
|
+
'[Desktop Entry]',
|
|
136
|
+
'Type=Application',
|
|
137
|
+
`Name=${windowTitle || appId}`,
|
|
138
|
+
`Icon=${appId}`,
|
|
139
|
+
`StartupWMClass=${appId}`,
|
|
140
|
+
'NoDisplay=true',
|
|
141
|
+
'Terminal=false',
|
|
142
|
+
'',
|
|
143
|
+
].join('\n');
|
|
144
|
+
writeFileSync(resolve(appsDir, `${appId}.desktop`), desktopEntry, 'utf8');
|
|
145
|
+
} catch {
|
|
146
|
+
// Ignore if ~/.local/share/applications is not writable
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { extractComponentMetadata, type ComponentDecoratorMeta, type ExtractedComponentMetadata, type MethodMutationMeta, } from './ast-metadata-extractor.mjs';
|
|
2
|
+
export { compileBundle, emitNgbBundle, watchBundle, type CompileBundleOptions, type CompileBundleResult, } from './build-bundle.mjs';
|
|
3
|
+
export { analyzeProjectPermissions, analyzeSourcePermissions, type NativeCapabilitiesObject, type PermissionAnalysisManifest, type PermissionEvidence, type PermissionPolicyMode, type PermissionsPolicyConfig, } from './permission-analyzer.mjs';
|
|
4
|
+
export { resolveWorkspaceProject, type ResolvedWorkspaceProject, type ResolveWorkspaceOptions, type WorkspaceKind, } from './workspace-resolver.mjs';
|
|
5
|
+
export { ENGINE_BINARY_PACKAGES, resolveEngineBinaryPath, type EngineBinaryPackageMeta, type EngineBinaryResolution, type EngineBinarySource, type ResolveEngineBinaryOptions, } from './resolve-engine-binary.mjs';
|
|
6
|
+
export { createNativeTargetConfig, executeNativeBuilder, resolveNativeBuilderConfig, type LinuxPackageFormat, type NativeArchKind, type NativeBuilderOptions, type NativeBuilderResult, type NativeCpuProfile, type NativeJsEngineKind, type NativeOsKind, type NativePackageFormat, type NativePermissionsMode, type NativePermissionsOptions, type NativePlatformTarget, type ResolvedNativeBuilderConfig, } from './builder';
|
|
7
|
+
export { pingHmr, pushHmrEval, pushHmrReload, sendHmrMessage, type HmrClientResult, } from './hmr-client.mjs';
|
|
8
|
+
export { buildMultiResolutionIcons } from './icon-compiler.mjs';
|
|
9
|
+
export { emitStyleInstruction, parseStylesCss, type StyleRuleIr } from './style-compiler.mjs';
|
|
10
|
+
export { applyPipeTransform, parseTemplateHtml, type ComponentDefinitionIr, type ReactiveBindingIr, type TemplateAstNode, type TemplateIdState, } from './template-compiler.mjs';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/builders-native/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,aAAa,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,GAChC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,GACjC,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,EACd,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { extractComponentMetadata, } from './ast-metadata-extractor.mjs';
|
|
2
|
+
export { compileBundle, emitNgbBundle, watchBundle, } from './build-bundle.mjs';
|
|
3
|
+
export { analyzeProjectPermissions, analyzeSourcePermissions, } from './permission-analyzer.mjs';
|
|
4
|
+
export { resolveWorkspaceProject, } from './workspace-resolver.mjs';
|
|
5
|
+
export { ENGINE_BINARY_PACKAGES, resolveEngineBinaryPath, } from './resolve-engine-binary.mjs';
|
|
6
|
+
export { createNativeTargetConfig, executeNativeBuilder, resolveNativeBuilderConfig, } from './builder.js';
|
|
7
|
+
export { pingHmr, pushHmrEval, pushHmrReload, sendHmrMessage, } from './hmr-client.mjs';
|
|
8
|
+
export { buildMultiResolutionIcons } from './icon-compiler.mjs';
|
|
9
|
+
export { emitStyleInstruction, parseStylesCss } from './style-compiler.mjs';
|
|
10
|
+
export { applyPipeTransform, parseTemplateHtml, } from './template-compiler.mjs';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/builders-native/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAIzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,GAGZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,yBAAyB,EACzB,wBAAwB,GAMzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,GAIxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAKxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,GAa3B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAoB,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAKlB,MAAM,yBAAyB,CAAC","sourcesContent":["export {\n extractComponentMetadata,\n type ComponentDecoratorMeta,\n type ExtractedComponentMetadata,\n type MethodMutationMeta,\n} from './ast-metadata-extractor.mjs';\nexport {\n compileBundle,\n emitNgbBundle,\n watchBundle,\n type CompileBundleOptions,\n type CompileBundleResult,\n} from './build-bundle.mjs';\nexport {\n analyzeProjectPermissions,\n analyzeSourcePermissions,\n type NativeCapabilitiesObject,\n type PermissionAnalysisManifest,\n type PermissionEvidence,\n type PermissionPolicyMode,\n type PermissionsPolicyConfig,\n} from './permission-analyzer.mjs';\nexport {\n resolveWorkspaceProject,\n type ResolvedWorkspaceProject,\n type ResolveWorkspaceOptions,\n type WorkspaceKind,\n} from './workspace-resolver.mjs';\nexport {\n ENGINE_BINARY_PACKAGES,\n resolveEngineBinaryPath,\n type EngineBinaryPackageMeta,\n type EngineBinaryResolution,\n type EngineBinarySource,\n type ResolveEngineBinaryOptions,\n} from './resolve-engine-binary.mjs';\nexport {\n createNativeTargetConfig,\n executeNativeBuilder,\n resolveNativeBuilderConfig,\n type LinuxPackageFormat,\n type NativeArchKind,\n type NativeBuilderOptions,\n type NativeBuilderResult,\n type NativeCpuProfile,\n type NativeJsEngineKind,\n type NativeOsKind,\n type NativePackageFormat,\n type NativePermissionsMode,\n type NativePermissionsOptions,\n type NativePlatformTarget,\n type ResolvedNativeBuilderConfig,\n} from './builder';\nexport {\n pingHmr,\n pushHmrEval,\n pushHmrReload,\n sendHmrMessage,\n type HmrClientResult,\n} from './hmr-client.mjs';\nexport { buildMultiResolutionIcons } from './icon-compiler.mjs';\nexport { emitStyleInstruction, parseStylesCss, type StyleRuleIr } from './style-compiler.mjs';\nexport {\n applyPipeTransform,\n parseTemplateHtml,\n type ComponentDefinitionIr,\n type ReactiveBindingIr,\n type TemplateAstNode,\n type TemplateIdState,\n} from './template-compiler.mjs';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type PermissionPolicyMode = 'auto' | 'strict';
|
|
2
|
+
|
|
3
|
+
export interface PermissionsPolicyConfig {
|
|
4
|
+
mode?: PermissionPolicyMode;
|
|
5
|
+
allow?: string[];
|
|
6
|
+
deny?: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PermissionEvidence {
|
|
10
|
+
capability: string;
|
|
11
|
+
file: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NativeCapabilitiesObject {
|
|
16
|
+
network: boolean;
|
|
17
|
+
sqlite: boolean;
|
|
18
|
+
filesystem: {
|
|
19
|
+
xdg: boolean;
|
|
20
|
+
dialogs: boolean;
|
|
21
|
+
drop: boolean;
|
|
22
|
+
};
|
|
23
|
+
clipboard: boolean;
|
|
24
|
+
notifications: boolean;
|
|
25
|
+
computeThreads: boolean;
|
|
26
|
+
fullSystemAccess: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface PermissionAnalysisManifest {
|
|
30
|
+
schemaVersion: 1;
|
|
31
|
+
mode: PermissionPolicyMode;
|
|
32
|
+
capabilities: NativeCapabilitiesObject;
|
|
33
|
+
evidence: PermissionEvidence[];
|
|
34
|
+
warnings: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function analyzeSourcePermissions(
|
|
38
|
+
files: ReadonlyArray<{ file: string; content: string }>,
|
|
39
|
+
permissionsConfig?: PermissionsPolicyConfig,
|
|
40
|
+
): PermissionAnalysisManifest;
|
|
41
|
+
|
|
42
|
+
export function analyzeProjectPermissions(
|
|
43
|
+
sourceRoot: string,
|
|
44
|
+
permissionsConfig?: PermissionsPolicyConfig,
|
|
45
|
+
): PermissionAnalysisManifest;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { parseSync } from 'oxc-parser';
|
|
4
|
+
|
|
5
|
+
function createEmptyCapabilities() {
|
|
6
|
+
return {
|
|
7
|
+
network: false,
|
|
8
|
+
sqlite: false,
|
|
9
|
+
filesystem: {
|
|
10
|
+
xdg: false,
|
|
11
|
+
dialogs: false,
|
|
12
|
+
drop: false,
|
|
13
|
+
},
|
|
14
|
+
clipboard: false,
|
|
15
|
+
notifications: false,
|
|
16
|
+
computeThreads: false,
|
|
17
|
+
fullSystemAccess: false,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeToken(token) {
|
|
22
|
+
return String(token ?? '')
|
|
23
|
+
.trim()
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.replaceAll('_', '-');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function applyCapabilityToken(capabilities, token, enabled) {
|
|
29
|
+
switch (normalizeToken(token)) {
|
|
30
|
+
case 'network':
|
|
31
|
+
case 'http':
|
|
32
|
+
capabilities.network = enabled;
|
|
33
|
+
break;
|
|
34
|
+
case 'sqlite':
|
|
35
|
+
case 'database':
|
|
36
|
+
capabilities.sqlite = enabled;
|
|
37
|
+
break;
|
|
38
|
+
case 'filesystem':
|
|
39
|
+
case 'fs':
|
|
40
|
+
capabilities.filesystem.xdg = enabled;
|
|
41
|
+
capabilities.filesystem.dialogs = enabled;
|
|
42
|
+
capabilities.filesystem.drop = enabled;
|
|
43
|
+
break;
|
|
44
|
+
case 'filesystem:xdg':
|
|
45
|
+
case 'filesystem-xdg':
|
|
46
|
+
case 'filesystemxdg':
|
|
47
|
+
case 'xdg':
|
|
48
|
+
capabilities.filesystem.xdg = enabled;
|
|
49
|
+
break;
|
|
50
|
+
case 'filesystem:dialogs':
|
|
51
|
+
case 'filesystem-dialogs':
|
|
52
|
+
case 'filesystemdialogs':
|
|
53
|
+
case 'dialogs':
|
|
54
|
+
capabilities.filesystem.dialogs = enabled;
|
|
55
|
+
break;
|
|
56
|
+
case 'filesystem:drop':
|
|
57
|
+
case 'filesystem-drop':
|
|
58
|
+
case 'filesystemdrop':
|
|
59
|
+
case 'drop':
|
|
60
|
+
capabilities.filesystem.drop = enabled;
|
|
61
|
+
break;
|
|
62
|
+
case 'clipboard':
|
|
63
|
+
capabilities.clipboard = enabled;
|
|
64
|
+
break;
|
|
65
|
+
case 'notifications':
|
|
66
|
+
case 'notification':
|
|
67
|
+
capabilities.notifications = enabled;
|
|
68
|
+
break;
|
|
69
|
+
case 'compute-threads':
|
|
70
|
+
case 'computethreads':
|
|
71
|
+
case 'compute':
|
|
72
|
+
case 'threads':
|
|
73
|
+
capabilities.computeThreads = enabled;
|
|
74
|
+
break;
|
|
75
|
+
case 'full-system-access':
|
|
76
|
+
case 'fullsystemaccess':
|
|
77
|
+
capabilities.fullSystemAccess = enabled;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isCapabilityEnabled(capabilities, cap) {
|
|
85
|
+
switch (cap) {
|
|
86
|
+
case 'network':
|
|
87
|
+
return capabilities.network;
|
|
88
|
+
case 'sqlite':
|
|
89
|
+
return capabilities.sqlite;
|
|
90
|
+
case 'filesystem:xdg':
|
|
91
|
+
return capabilities.filesystem.xdg;
|
|
92
|
+
case 'filesystem:dialogs':
|
|
93
|
+
return capabilities.filesystem.dialogs;
|
|
94
|
+
case 'filesystem:drop':
|
|
95
|
+
return capabilities.filesystem.drop;
|
|
96
|
+
case 'clipboard':
|
|
97
|
+
return capabilities.clipboard;
|
|
98
|
+
case 'notifications':
|
|
99
|
+
return capabilities.notifications;
|
|
100
|
+
case 'compute-threads':
|
|
101
|
+
return capabilities.computeThreads;
|
|
102
|
+
default:
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const IMPORT_SPECIFIER_CAPS = new Map([
|
|
108
|
+
['HttpClient', 'network'],
|
|
109
|
+
['provideNativeHttp', 'network'],
|
|
110
|
+
['provideHttpClient', 'network'],
|
|
111
|
+
['NativeSqliteService', 'sqlite'],
|
|
112
|
+
['NativeFsService', 'filesystem:xdg'],
|
|
113
|
+
['NativeComputeService', 'compute-threads'],
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
const CALL_NAME_CAPS = new Map([
|
|
117
|
+
['fetch', 'network'],
|
|
118
|
+
['httpRequest', 'network'],
|
|
119
|
+
['httpBatch', 'network'],
|
|
120
|
+
['downloadFiles', 'network'],
|
|
121
|
+
['httpResource', 'network'],
|
|
122
|
+
['configureHttp', 'network'],
|
|
123
|
+
['sqliteExec', 'sqlite'],
|
|
124
|
+
['sqliteQuery', 'sqlite'],
|
|
125
|
+
['openSqlite', 'sqlite'],
|
|
126
|
+
['resolveXdgPath', 'filesystem:xdg'],
|
|
127
|
+
['fsResolvePath', 'filesystem:xdg'],
|
|
128
|
+
['fsReadText', 'filesystem:xdg'],
|
|
129
|
+
['fsWriteText', 'filesystem:xdg'],
|
|
130
|
+
['fsWatchFile', 'filesystem:xdg'],
|
|
131
|
+
['openFileDialog', 'filesystem:dialogs'],
|
|
132
|
+
['saveFileDialog', 'filesystem:dialogs'],
|
|
133
|
+
['getClipboard', 'clipboard'],
|
|
134
|
+
['setClipboard', 'clipboard'],
|
|
135
|
+
['readClipboard', 'clipboard'],
|
|
136
|
+
['writeClipboard', 'clipboard'],
|
|
137
|
+
['sendNotification', 'notifications'],
|
|
138
|
+
['computeFilter', 'compute-threads'],
|
|
139
|
+
['computeHash', 'compute-threads'],
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
function visitAst(node, visitor) {
|
|
143
|
+
if (!node || typeof node !== 'object') return;
|
|
144
|
+
if (Array.isArray(node)) {
|
|
145
|
+
for (const item of node) {
|
|
146
|
+
visitAst(item, visitor);
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (typeof node.type === 'string') {
|
|
151
|
+
visitor(node);
|
|
152
|
+
}
|
|
153
|
+
for (const key of Object.keys(node)) {
|
|
154
|
+
if (key === 'loc' || key === 'span' || key === 'start' || key === 'end') continue;
|
|
155
|
+
const val = node[key];
|
|
156
|
+
if (val && typeof val === 'object') {
|
|
157
|
+
visitAst(val, visitor);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function inspectTypeScriptAst(filename, code, addEvidence) {
|
|
163
|
+
const parsed = parseSync(filename, code);
|
|
164
|
+
visitAst(parsed.program, (node) => {
|
|
165
|
+
if (node.type === 'ImportDeclaration') {
|
|
166
|
+
const modName = node.source?.value;
|
|
167
|
+
if (
|
|
168
|
+
modName === '@ng-desktop/http' ||
|
|
169
|
+
modName === '@ng-native/http' ||
|
|
170
|
+
modName === '@angular/common/http'
|
|
171
|
+
) {
|
|
172
|
+
addEvidence('network', filename, `import from '${modName}'`);
|
|
173
|
+
}
|
|
174
|
+
for (const spec of node.specifiers || []) {
|
|
175
|
+
const imported = spec.imported?.name || spec.local?.name;
|
|
176
|
+
const cap = IMPORT_SPECIFIER_CAPS.get(imported);
|
|
177
|
+
if (cap) {
|
|
178
|
+
addEvidence(cap, filename, `import '${imported}'`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (node.type === 'CallExpression') {
|
|
185
|
+
if (node.callee?.type === 'Identifier') {
|
|
186
|
+
const cap = CALL_NAME_CAPS.get(node.callee.name);
|
|
187
|
+
if (cap) {
|
|
188
|
+
addEvidence(cap, filename, `call '${node.callee.name}()'`);
|
|
189
|
+
}
|
|
190
|
+
} else if (
|
|
191
|
+
node.callee?.type === 'MemberExpression' &&
|
|
192
|
+
node.callee.property?.type === 'Identifier'
|
|
193
|
+
) {
|
|
194
|
+
const method = node.callee.property.name;
|
|
195
|
+
const cap = method === 'notify' ? 'notifications' : CALL_NAME_CAPS.get(method);
|
|
196
|
+
if (cap) {
|
|
197
|
+
addEvidence(cap, filename, `call '.${method}()'`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (
|
|
204
|
+
node.type === 'NewExpression' &&
|
|
205
|
+
node.callee?.type === 'Identifier' &&
|
|
206
|
+
node.callee.name === 'WebSocket'
|
|
207
|
+
) {
|
|
208
|
+
addEvidence('network', filename, `new WebSocket()`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
213
|
+
if (node.value === 'file-drop' || node.value === 'ng-drop-target') {
|
|
214
|
+
addEvidence('filesystem:drop', filename, `literal '${node.value}'`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function collectProjectSourceFiles(rootDir, currentDir = rootDir, out = []) {
|
|
221
|
+
if (!existsSync(currentDir)) return out;
|
|
222
|
+
for (const entry of readdirSync(currentDir)) {
|
|
223
|
+
const fullPath = resolve(currentDir, entry);
|
|
224
|
+
const stat = statSync(fullPath);
|
|
225
|
+
if (stat.isDirectory()) {
|
|
226
|
+
collectProjectSourceFiles(rootDir, fullPath, out);
|
|
227
|
+
} else if (
|
|
228
|
+
(entry.endsWith('.ts') && !entry.endsWith('.spec.ts') && !entry.endsWith('.d.ts')) ||
|
|
229
|
+
entry.endsWith('.html')
|
|
230
|
+
) {
|
|
231
|
+
out.push({
|
|
232
|
+
file: relative(rootDir, fullPath),
|
|
233
|
+
content: readFileSync(fullPath, 'utf8'),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Statically analyzes source files using `oxc-parser` AST traversal and template attribute checks,
|
|
242
|
+
* applying optional `permissions` policy (`mode: 'auto' | 'strict'`, `allow`, `deny`).
|
|
243
|
+
*/
|
|
244
|
+
export function analyzeSourcePermissions(files, permissionsConfig = {}) {
|
|
245
|
+
const mode = permissionsConfig?.mode === 'strict' ? 'strict' : 'auto';
|
|
246
|
+
const allowList = Array.isArray(permissionsConfig?.allow) ? permissionsConfig.allow : [];
|
|
247
|
+
const denyList = Array.isArray(permissionsConfig?.deny) ? permissionsConfig.deny : [];
|
|
248
|
+
|
|
249
|
+
const evidence = [];
|
|
250
|
+
const seenKeys = new Set();
|
|
251
|
+
const addEvidence = (capability, file, reason) => {
|
|
252
|
+
const key = `${capability}::${file}::${reason}`;
|
|
253
|
+
if (seenKeys.has(key)) return;
|
|
254
|
+
seenKeys.add(key);
|
|
255
|
+
evidence.push({ capability, file, reason });
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
for (const item of files) {
|
|
259
|
+
if (item.file.endsWith('.ts') || item.file.endsWith('.mts') || item.file.endsWith('.js')) {
|
|
260
|
+
inspectTypeScriptAst(item.file, item.content, addEvidence);
|
|
261
|
+
} else if (item.file.endsWith('.html')) {
|
|
262
|
+
if (
|
|
263
|
+
item.content.includes('(file-drop)') ||
|
|
264
|
+
item.content.includes('dropTarget') ||
|
|
265
|
+
item.content.includes('ng-drop-target')
|
|
266
|
+
) {
|
|
267
|
+
addEvidence('filesystem:drop', item.file, 'template drop-target binding');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const capabilities = createEmptyCapabilities();
|
|
273
|
+
if (mode === 'auto') {
|
|
274
|
+
for (const item of evidence) {
|
|
275
|
+
applyCapabilityToken(capabilities, item.capability, true);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
for (const token of allowList) {
|
|
280
|
+
applyCapabilityToken(capabilities, token, true);
|
|
281
|
+
}
|
|
282
|
+
for (const token of denyList) {
|
|
283
|
+
applyCapabilityToken(capabilities, token, false);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const warnings = [];
|
|
287
|
+
if (mode === 'strict') {
|
|
288
|
+
for (const item of evidence) {
|
|
289
|
+
if (!isCapabilityEnabled(capabilities, item.capability) && !capabilities.fullSystemAccess) {
|
|
290
|
+
warnings.push(
|
|
291
|
+
`Detected '${item.capability}' usage in '${item.file}' (${item.reason}), but strict mode omits it unless listed in allow.`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
schemaVersion: 1,
|
|
299
|
+
mode,
|
|
300
|
+
capabilities,
|
|
301
|
+
evidence,
|
|
302
|
+
warnings,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Recursively collects application TypeScript/HTML sources under `sourceRoot` and computes the
|
|
308
|
+
* build-time least-privilege capability manifest.
|
|
309
|
+
*/
|
|
310
|
+
export function analyzeProjectPermissions(sourceRoot, permissionsConfig = {}) {
|
|
311
|
+
const files = collectProjectSourceFiles(sourceRoot);
|
|
312
|
+
return analyzeSourcePermissions(files, permissionsConfig);
|
|
313
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface EngineBinaryPackageMeta {
|
|
2
|
+
readonly pkgName: string;
|
|
3
|
+
readonly dirName: string;
|
|
4
|
+
readonly os: 'linux' | 'win32' | 'darwin';
|
|
5
|
+
readonly cpu: 'x64' | 'arm64';
|
|
6
|
+
readonly libc?: 'glibc';
|
|
7
|
+
readonly binaryName: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const ENGINE_BINARY_PACKAGES: Readonly<Record<string, EngineBinaryPackageMeta>>;
|
|
11
|
+
|
|
12
|
+
export type EngineBinarySource = 'env' | 'optional-package' | 'cargo-target' | 'cargo-fallback';
|
|
13
|
+
|
|
14
|
+
export interface ResolveEngineBinaryOptions {
|
|
15
|
+
env?: Record<string, string | undefined>;
|
|
16
|
+
platform?: NodeJS.Platform;
|
|
17
|
+
arch?: string;
|
|
18
|
+
cwd?: string;
|
|
19
|
+
workspaceRoot?: string;
|
|
20
|
+
resolvePkgPath?: (pkgName: string) => string | null | undefined;
|
|
21
|
+
fileExists?: (path: string) => boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface EngineBinaryResolution {
|
|
25
|
+
mode: 'binary' | 'cargo';
|
|
26
|
+
command: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
source: EngineBinarySource;
|
|
29
|
+
packageName: string | null;
|
|
30
|
+
targetKey: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resolveEngineBinaryPath(
|
|
34
|
+
options?: ResolveEngineBinaryOptions,
|
|
35
|
+
): EngineBinaryResolution;
|