@ng-desktop/builders 0.3.0 → 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.
- package/bin/ng-desktop.mjs +9 -0
- package/builders.json +7 -2
- package/fesm2022/application-builder.d.mts +62 -0
- package/fesm2022/application-builder.mjs +58 -0
- package/fesm2022/ast-metadata-extractor.mjs +51 -11
- package/fesm2022/build-bundle.d.mts +9 -0
- package/fesm2022/build-bundle.mjs +172 -25
- package/fesm2022/builder.d.ts +0 -1
- package/fesm2022/builder.js +0 -1
- package/fesm2022/dev-server-builder.d.mts +26 -0
- package/fesm2022/dev-server-builder.mjs +24 -0
- package/fesm2022/hmr-client.d.mts +5 -0
- package/fesm2022/hmr-client.mjs +7 -0
- package/fesm2022/index.d.ts +6 -4
- package/fesm2022/index.js +5 -3
- package/fesm2022/permission-analyzer.mjs +20 -0
- package/fesm2022/server-compiler.d.mts +29 -0
- package/fesm2022/server-compiler.mjs +236 -0
- package/fesm2022/style-compiler.d.mts +12 -0
- package/fesm2022/style-compiler.mjs +166 -5
- package/fesm2022/template-compiler.mjs +83 -1
- package/fesm2022/workspace-resolver.mjs +1 -1
- package/package.json +8 -7
- package/schema/native-builder-schema.json +18 -0
- package/schematics/ng-add/index.mjs +2 -2
- package/fesm2022/builder.d.ts.map +0 -1
- package/fesm2022/builder.js.map +0 -1
- package/fesm2022/index.d.ts.map +0 -1
- package/fesm2022/index.js.map +0 -1
package/bin/ng-desktop.mjs
CHANGED
|
@@ -106,6 +106,15 @@ function launchHostEngine(ws, engineArgs, { preferReleaseCargo = false, envExtra
|
|
|
106
106
|
cwd: ws.workspaceRoot,
|
|
107
107
|
env: { ...process.env, ...envExtra },
|
|
108
108
|
});
|
|
109
|
+
if (run.error?.code === 'ENOENT') {
|
|
110
|
+
process.stderr.write(
|
|
111
|
+
resolvedEngine.mode === 'cargo'
|
|
112
|
+
? `[ng-desktop] Native engine not found for ${resolvedEngine.targetKey}. ` +
|
|
113
|
+
`Install '${resolvedEngine.packageName ?? '@ng-desktop/engine-*'}' (no 'cargo' available), ` +
|
|
114
|
+
`or set NG_DESKTOP_ENGINE_BIN to the engine binary.\n`
|
|
115
|
+
: `[ng-desktop] Could not execute engine binary '${resolvedEngine.command}'.\n`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
109
118
|
process.exitCode = run.status ?? 1;
|
|
110
119
|
}
|
|
111
120
|
|
package/builders.json
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
"$schema": "../../node_modules/@angular-devkit/architect/src/builders-schema.json",
|
|
3
3
|
"builders": {
|
|
4
4
|
"application": {
|
|
5
|
-
"implementation": "./fesm2022/
|
|
5
|
+
"implementation": "./fesm2022/application-builder.mjs",
|
|
6
6
|
"schema": "./schema/native-builder-schema.json",
|
|
7
|
-
"description": "Compile Angular templates
|
|
7
|
+
"description": "Compile Angular templates, Ivy bundles, Analog server routes, and least-privilege manifests for native desktop targets."
|
|
8
|
+
},
|
|
9
|
+
"dev-server": {
|
|
10
|
+
"implementation": "./fesm2022/dev-server-builder.mjs",
|
|
11
|
+
"schema": "./schema/native-builder-schema.json",
|
|
12
|
+
"description": "Run incremental native watch builds and push live frontend/server HMR updates to the running desktop window."
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HmrDeltaSummary } from './build-bundle.mjs';
|
|
2
|
+
|
|
3
|
+
export const ARCHITECT_BUILDER_SYMBOL: unique symbol;
|
|
4
|
+
export const ARCHITECT_VERSION_SYMBOL: unique symbol;
|
|
5
|
+
|
|
6
|
+
export interface ArchitectBuilderContextLike {
|
|
7
|
+
workspaceRoot?: string;
|
|
8
|
+
target?: { project?: string; target?: string };
|
|
9
|
+
logger?: { info?: (msg: string) => void; error?: (msg: string) => void };
|
|
10
|
+
addTeardown?: (teardown: () => void | Promise<void>) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NativeApplicationBuilderOptions {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
configPath?: string;
|
|
16
|
+
projectName?: string;
|
|
17
|
+
version?: string;
|
|
18
|
+
rebuildIcons?: boolean;
|
|
19
|
+
os?: string;
|
|
20
|
+
arch?: string;
|
|
21
|
+
cpu?: string;
|
|
22
|
+
targetPlatform?: string;
|
|
23
|
+
jsEngine?: string;
|
|
24
|
+
outputPath?: string;
|
|
25
|
+
main?: string;
|
|
26
|
+
permissions?: { mode?: 'auto' | 'strict'; allow?: string[]; deny?: string[] };
|
|
27
|
+
packageFormats?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NativeApplicationBuilderOutput {
|
|
31
|
+
success: boolean;
|
|
32
|
+
projectName: string;
|
|
33
|
+
version: string;
|
|
34
|
+
bundleFile: string;
|
|
35
|
+
entryBundleFile?: string;
|
|
36
|
+
serverBundleFile?: string;
|
|
37
|
+
permissionsFile: string;
|
|
38
|
+
runtimeConfigFile: string;
|
|
39
|
+
hmrDelta: HmrDeltaSummary;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ArchitectBuilderObject<TOpt, TOut> {
|
|
43
|
+
handler: unknown;
|
|
44
|
+
run: (options?: TOpt, context?: ArchitectBuilderContextLike) => Promise<TOut>;
|
|
45
|
+
[key: symbol]: unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createArchitectBuilder<TOpt, TOut>(
|
|
49
|
+
handlerFn: (options?: TOpt, context?: ArchitectBuilderContextLike) => Promise<TOut>,
|
|
50
|
+
): ArchitectBuilderObject<TOpt, TOut>;
|
|
51
|
+
|
|
52
|
+
export function runNativeApplicationBuilder(
|
|
53
|
+
options?: NativeApplicationBuilderOptions,
|
|
54
|
+
context?: ArchitectBuilderContextLike,
|
|
55
|
+
): Promise<NativeApplicationBuilderOutput>;
|
|
56
|
+
|
|
57
|
+
export const applicationBuilder: ArchitectBuilderObject<
|
|
58
|
+
NativeApplicationBuilderOptions,
|
|
59
|
+
NativeApplicationBuilderOutput
|
|
60
|
+
>;
|
|
61
|
+
|
|
62
|
+
export default applicationBuilder;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { compileBundle } from './build-bundle.mjs';
|
|
3
|
+
|
|
4
|
+
export const ARCHITECT_BUILDER_SYMBOL = Symbol.for('@angular-devkit/architect:builder');
|
|
5
|
+
export const ARCHITECT_VERSION_SYMBOL = Symbol.for('@angular-devkit/architect:builder-version');
|
|
6
|
+
|
|
7
|
+
export function createArchitectBuilder(handlerFn) {
|
|
8
|
+
let builderObj = null;
|
|
9
|
+
try {
|
|
10
|
+
const req = createRequire(import.meta.url);
|
|
11
|
+
const architect = req('@angular-devkit/architect');
|
|
12
|
+
if (typeof architect?.createBuilder === 'function') {
|
|
13
|
+
builderObj = architect.createBuilder(handlerFn);
|
|
14
|
+
}
|
|
15
|
+
} catch {
|
|
16
|
+
// Fallback below if @angular-devkit/architect is not installed in minimal environments
|
|
17
|
+
}
|
|
18
|
+
if (!builderObj) {
|
|
19
|
+
builderObj = {
|
|
20
|
+
handler: handlerFn,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
builderObj[ARCHITECT_BUILDER_SYMBOL] = true;
|
|
24
|
+
builderObj[ARCHITECT_VERSION_SYMBOL] = builderObj[ARCHITECT_VERSION_SYMBOL] ?? '0.4.0';
|
|
25
|
+
builderObj.run = handlerFn;
|
|
26
|
+
return builderObj;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function runNativeApplicationBuilder(options = {}, context = {}) {
|
|
30
|
+
const workspaceRoot = context?.workspaceRoot || options?.cwd || process.cwd();
|
|
31
|
+
const projectName = context?.target?.project || options?.projectName;
|
|
32
|
+
const compiled = compileBundle({
|
|
33
|
+
cwd: workspaceRoot,
|
|
34
|
+
configPath: options?.configPath,
|
|
35
|
+
projectName,
|
|
36
|
+
version: options?.version,
|
|
37
|
+
rebuildIcons: options?.rebuildIcons ?? true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
context?.logger?.info?.(
|
|
41
|
+
`[NgDesktop Architect] Built ${compiled.projectName} v${compiled.version} -> ${compiled.bundleFile}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
projectName: compiled.projectName,
|
|
47
|
+
version: compiled.version,
|
|
48
|
+
bundleFile: compiled.bundleFile,
|
|
49
|
+
...(compiled.entryBundleFile ? { entryBundleFile: compiled.entryBundleFile } : {}),
|
|
50
|
+
...(compiled.serverBundleFile ? { serverBundleFile: compiled.serverBundleFile } : {}),
|
|
51
|
+
permissionsFile: compiled.permissionsFile,
|
|
52
|
+
runtimeConfigFile: compiled.runtimeConfigFile,
|
|
53
|
+
hmrDelta: compiled.hmrDelta,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const applicationBuilder = createArchitectBuilder(runNativeApplicationBuilder);
|
|
58
|
+
export default applicationBuilder;
|
|
@@ -104,12 +104,27 @@ function evaluateDerivedExpression(node, state) {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
function
|
|
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) {
|
|
108
119
|
const component = {
|
|
109
120
|
selector: 'app-root',
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
template: null,
|
|
122
|
+
templateUrl: isRootApp ? './app.html' : null,
|
|
123
|
+
styleUrl: isRootApp ? './app.css' : null,
|
|
124
|
+
styleUrls: [],
|
|
125
|
+
styles: [],
|
|
112
126
|
imports: [],
|
|
127
|
+
hasComponentDecorator: false,
|
|
113
128
|
};
|
|
114
129
|
|
|
115
130
|
for (const dec of decorators) {
|
|
@@ -122,6 +137,7 @@ function extractDecoratorMetadata(decorators = []) {
|
|
|
122
137
|
continue;
|
|
123
138
|
}
|
|
124
139
|
|
|
140
|
+
component.hasComponentDecorator = true;
|
|
125
141
|
const arg = expr.arguments?.[0];
|
|
126
142
|
if (arg?.type !== 'ObjectExpression') continue;
|
|
127
143
|
|
|
@@ -135,12 +151,27 @@ function extractDecoratorMetadata(decorators = []) {
|
|
|
135
151
|
continue;
|
|
136
152
|
}
|
|
137
153
|
|
|
138
|
-
|
|
139
|
-
|
|
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;
|
|
140
170
|
|
|
141
|
-
if (prop.key.name === 'selector') component.selector =
|
|
142
|
-
if (prop.key.name === '
|
|
143
|
-
if (prop.key.name === '
|
|
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;
|
|
144
175
|
}
|
|
145
176
|
}
|
|
146
177
|
|
|
@@ -228,11 +259,17 @@ export function extractComponentMetadata(tsSource, filename = 'app.ts') {
|
|
|
228
259
|
const resources = {};
|
|
229
260
|
const methods = {};
|
|
230
261
|
const relativeImports = {};
|
|
262
|
+
const isRootApp =
|
|
263
|
+
filename === 'app.ts' || filename.endsWith('/app.ts') || filename.endsWith('\\app.ts');
|
|
231
264
|
let component = {
|
|
232
265
|
selector: 'app-root',
|
|
233
|
-
|
|
234
|
-
|
|
266
|
+
template: null,
|
|
267
|
+
templateUrl: isRootApp ? './app.html' : null,
|
|
268
|
+
styleUrl: isRootApp ? './app.css' : null,
|
|
269
|
+
styleUrls: [],
|
|
270
|
+
styles: [],
|
|
235
271
|
imports: [],
|
|
272
|
+
hasComponentDecorator: false,
|
|
236
273
|
};
|
|
237
274
|
|
|
238
275
|
for (const stmt of parsed.program.body || []) {
|
|
@@ -252,7 +289,10 @@ export function extractComponentMetadata(tsSource, filename = 'app.ts') {
|
|
|
252
289
|
|
|
253
290
|
if (decl?.type !== 'ClassDeclaration') continue;
|
|
254
291
|
|
|
255
|
-
|
|
292
|
+
const extractedDec = extractDecoratorMetadata(decl.decorators, isRootApp);
|
|
293
|
+
if (extractedDec.hasComponentDecorator) {
|
|
294
|
+
component = extractedDec;
|
|
295
|
+
}
|
|
256
296
|
|
|
257
297
|
for (const member of decl.body?.body || []) {
|
|
258
298
|
if (member.type === 'PropertyDefinition' && member.key?.type === 'Identifier') {
|
|
@@ -11,15 +11,24 @@ export interface CompileBundleOptions {
|
|
|
11
11
|
version?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface HmrDeltaSummary {
|
|
15
|
+
ngbChanged: boolean;
|
|
16
|
+
appBundleChanged: boolean;
|
|
17
|
+
serverBundleChanged: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
export interface CompileBundleResult {
|
|
15
21
|
projectName: string;
|
|
16
22
|
version: string;
|
|
17
23
|
sourceRoot: string;
|
|
18
24
|
bundleFile: string;
|
|
25
|
+
entryBundleFile?: string;
|
|
26
|
+
serverBundleFile?: string;
|
|
19
27
|
permissionsFile: string;
|
|
20
28
|
runtimeConfigFile: string;
|
|
21
29
|
permissions: PermissionAnalysisManifest;
|
|
22
30
|
socketPath: string;
|
|
31
|
+
hmrDelta: HmrDeltaSummary;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
export function emitNgbBundle(
|
|
@@ -10,14 +10,29 @@ import {
|
|
|
10
10
|
import { dirname, relative, resolve } from 'node:path';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { extractComponentMetadata } from './ast-metadata-extractor.mjs';
|
|
13
|
-
import { pushHmrReload } from './hmr-client.mjs';
|
|
13
|
+
import { pushHmrReload, pushHmrServerReload } from './hmr-client.mjs';
|
|
14
14
|
import { buildMultiResolutionIcons } from './icon-compiler.mjs';
|
|
15
15
|
import { analyzeProjectPermissions } from './permission-analyzer.mjs';
|
|
16
|
-
import {
|
|
16
|
+
import { compileServerBundle, discoverServerRoutes, runEsbuildBuild } from './server-compiler.mjs';
|
|
17
|
+
import {
|
|
18
|
+
emitStyleInstruction,
|
|
19
|
+
formatStyleRuleExtensions,
|
|
20
|
+
parseStylesCss,
|
|
21
|
+
} from './style-compiler.mjs';
|
|
17
22
|
import { parseTemplateHtml } from './template-compiler.mjs';
|
|
18
23
|
import { resolveWorkspaceProject } from './workspace-resolver.mjs';
|
|
19
24
|
|
|
20
|
-
export {
|
|
25
|
+
export {
|
|
26
|
+
compileServerBundle,
|
|
27
|
+
discoverServerRoutes,
|
|
28
|
+
extractComponentMetadata,
|
|
29
|
+
parseStylesCss,
|
|
30
|
+
parseTemplateHtml,
|
|
31
|
+
pushHmrReload,
|
|
32
|
+
pushHmrServerReload,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const lastEmittedByOutDir = new Map();
|
|
21
36
|
|
|
22
37
|
function extractCliFlagValue(argv, flag) {
|
|
23
38
|
const prefix = `${flag}=`;
|
|
@@ -148,6 +163,85 @@ export function emitNgbBundle(
|
|
|
148
163
|
return lines.join('\n') + '\n';
|
|
149
164
|
}
|
|
150
165
|
|
|
166
|
+
function emitAppJsBundleIfPresent(outDir, projectName, allStyleRules, iconMeta) {
|
|
167
|
+
const browserDir = resolve(outDir, 'browser');
|
|
168
|
+
if (!existsSync(browserDir)) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const entries = readdirSync(browserDir);
|
|
172
|
+
const mainFile =
|
|
173
|
+
entries.find((f) => f === 'main.js') ?? entries.find((f) => /^main-.*\.js$/.test(f));
|
|
174
|
+
if (!mainFile) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const polyfillsFile =
|
|
178
|
+
entries.find((f) => f === 'polyfills.js') ?? entries.find((f) => /^polyfills-.*\.js$/.test(f));
|
|
179
|
+
|
|
180
|
+
const preamble = [
|
|
181
|
+
`globalThis.__NG_NATIVE_APP_ID__ = ${JSON.stringify(projectName)};`,
|
|
182
|
+
iconMeta
|
|
183
|
+
? `globalThis.__NG_DESKTOP_ICON__ = ${JSON.stringify(iconMeta)};`
|
|
184
|
+
: 'delete globalThis.__NG_DESKTOP_ICON__;',
|
|
185
|
+
];
|
|
186
|
+
for (const rule of allStyleRules) {
|
|
187
|
+
const extras = formatStyleRuleExtensions(rule);
|
|
188
|
+
preamble.push(
|
|
189
|
+
`globalThis.__NG_NATIVE__?.registerStyle(${JSON.stringify(rule.className)}, ${JSON.stringify(rule.background)}, ${JSON.stringify(rule.color)}, ${Number(rule.padding) || 0}, ${Number(rule.spacing) || 0}, ${JSON.stringify(extras)});`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const entryLines = [];
|
|
194
|
+
if (polyfillsFile) {
|
|
195
|
+
entryLines.push(`import ${JSON.stringify(`./${polyfillsFile}`)};`);
|
|
196
|
+
}
|
|
197
|
+
entryLines.push(`import ${JSON.stringify(`./${mainFile}`)};`);
|
|
198
|
+
|
|
199
|
+
const bundled = runEsbuildBuild({
|
|
200
|
+
workspaceRoot: outDir,
|
|
201
|
+
resolveDir: browserDir,
|
|
202
|
+
entrySource: entryLines.join('\n'),
|
|
203
|
+
loader: 'js',
|
|
204
|
+
define: { __NG_DESKTOP_PROD_BUNDLE__: 'true' },
|
|
205
|
+
minifySyntax: true,
|
|
206
|
+
banner: { js: preamble.join('\n') },
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const entryBundleFile = resolve(outDir, 'app.bundle.js');
|
|
210
|
+
writeFileSync(entryBundleFile, bundled, 'utf8');
|
|
211
|
+
return entryBundleFile;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function collectComponentStyleRules(compMeta, baseDir) {
|
|
215
|
+
const rules = [];
|
|
216
|
+
const stylePaths = [];
|
|
217
|
+
if (compMeta.styleUrl) {
|
|
218
|
+
stylePaths.push(compMeta.styleUrl);
|
|
219
|
+
}
|
|
220
|
+
if (Array.isArray(compMeta.styleUrls)) {
|
|
221
|
+
stylePaths.push(...compMeta.styleUrls);
|
|
222
|
+
}
|
|
223
|
+
for (const relCss of stylePaths) {
|
|
224
|
+
const absCss = resolve(baseDir, relCss);
|
|
225
|
+
if (existsSync(absCss)) {
|
|
226
|
+
rules.push(...parseStylesCss(readFileSync(absCss, 'utf8'), relCss));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (Array.isArray(compMeta.styles)) {
|
|
230
|
+
for (const inlineCss of compMeta.styles) {
|
|
231
|
+
rules.push(...parseStylesCss(inlineCss, `${compMeta.selector}.inline.css`));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return rules;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function dedupeStyleRules(rules) {
|
|
238
|
+
const byClass = new Map();
|
|
239
|
+
for (const rule of rules) {
|
|
240
|
+
byClass.set(rule.className, rule);
|
|
241
|
+
}
|
|
242
|
+
return [...byClass.values()];
|
|
243
|
+
}
|
|
244
|
+
|
|
151
245
|
export function compileBundle({
|
|
152
246
|
rebuildIcons = true,
|
|
153
247
|
cwd,
|
|
@@ -169,9 +263,16 @@ export function compileBundle({
|
|
|
169
263
|
const sourceRootAbs = resolve(rootDir, workspace.sourceRoot);
|
|
170
264
|
const appDir = resolve(sourceRootAbs, 'app');
|
|
171
265
|
const tsSource = readFileSync(resolve(appDir, 'app.ts'), 'utf8');
|
|
172
|
-
const { state, numericSignals, methods, component } = extractComponentMetadata(
|
|
173
|
-
|
|
174
|
-
|
|
266
|
+
const { state, numericSignals, methods, component } = extractComponentMetadata(
|
|
267
|
+
tsSource,
|
|
268
|
+
'app.ts',
|
|
269
|
+
);
|
|
270
|
+
const htmlSource =
|
|
271
|
+
typeof component.template === 'string'
|
|
272
|
+
? component.template
|
|
273
|
+
: component.templateUrl && existsSync(resolve(appDir, component.templateUrl))
|
|
274
|
+
? readFileSync(resolve(appDir, component.templateUrl), 'utf8')
|
|
275
|
+
: '';
|
|
175
276
|
const indexHtmlPath = resolve(sourceRootAbs, 'index.html');
|
|
176
277
|
const indexHtml = existsSync(indexHtmlPath) ? readFileSync(indexHtmlPath, 'utf8') : '';
|
|
177
278
|
|
|
@@ -182,29 +283,31 @@ export function compileBundle({
|
|
|
182
283
|
const iconAbsPath = resolve(rootDir, iconRelPath);
|
|
183
284
|
|
|
184
285
|
const componentRegistry = {};
|
|
185
|
-
const
|
|
286
|
+
const collectedRules = [...collectComponentStyleRules(component, appDir)];
|
|
186
287
|
|
|
187
288
|
const candidateFiles = collectComponentTsFiles(appDir, appDir);
|
|
188
289
|
for (const file of candidateFiles) {
|
|
189
290
|
const filePath = resolve(appDir, file);
|
|
190
291
|
if (existsSync(filePath)) {
|
|
191
292
|
const ts = readFileSync(filePath, 'utf8');
|
|
192
|
-
const meta = extractComponentMetadata(ts, file);
|
|
193
293
|
if (!ts.includes('@Component')) continue;
|
|
294
|
+
const meta = extractComponentMetadata(ts, file);
|
|
295
|
+
if (!meta.component.hasComponentDecorator) continue;
|
|
194
296
|
const compDir = dirname(filePath);
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
297
|
+
const templateHtml =
|
|
298
|
+
typeof meta.component.template === 'string'
|
|
299
|
+
? meta.component.template
|
|
300
|
+
: meta.component.templateUrl && existsSync(resolve(compDir, meta.component.templateUrl))
|
|
301
|
+
? readFileSync(resolve(compDir, meta.component.templateUrl), 'utf8')
|
|
302
|
+
: '';
|
|
303
|
+
collectedRules.push(...collectComponentStyleRules(meta.component, compDir));
|
|
202
304
|
componentRegistry[meta.component.selector] = {
|
|
203
305
|
templateHtml,
|
|
204
|
-
templateUrl: meta.component.templateUrl
|
|
306
|
+
templateUrl: meta.component.templateUrl || `${meta.component.selector}.html`,
|
|
205
307
|
};
|
|
206
308
|
}
|
|
207
309
|
}
|
|
310
|
+
const allStyleRules = dedupeStyleRules(collectedRules);
|
|
208
311
|
|
|
209
312
|
const templateAst = parseTemplateHtml(
|
|
210
313
|
htmlSource,
|
|
@@ -237,6 +340,14 @@ export function compileBundle({
|
|
|
237
340
|
const bundleFile = resolve(outDir, 'main.ngb');
|
|
238
341
|
writeFileSync(bundleFile, bundle, 'utf8');
|
|
239
342
|
|
|
343
|
+
const entryBundleFile = emitAppJsBundleIfPresent(outDir, projectName, allStyleRules, iconMeta);
|
|
344
|
+
const serverBundleFile = compileServerBundle({
|
|
345
|
+
workspaceRoot: rootDir,
|
|
346
|
+
sourceRootAbs,
|
|
347
|
+
outDir,
|
|
348
|
+
projectName,
|
|
349
|
+
});
|
|
350
|
+
|
|
240
351
|
const permissions = analyzeProjectPermissions(sourceRootAbs, nativeOptions.permissions);
|
|
241
352
|
const permissionsFile = resolve(outDir, 'permissions.manifest.json');
|
|
242
353
|
writeFileSync(permissionsFile, JSON.stringify(permissions, null, 2) + '\n', 'utf8');
|
|
@@ -249,26 +360,59 @@ export function compileBundle({
|
|
|
249
360
|
targetPlatform: nativeOptions.targetPlatform || 'linux-gtk4',
|
|
250
361
|
outputPath: resolvedOutputPath,
|
|
251
362
|
iconSearchDir: `${resolvedOutputPath}/icons`,
|
|
363
|
+
...(entryBundleFile ? { entryBundle: 'app.bundle.js' } : {}),
|
|
364
|
+
...(serverBundleFile ? { serverBundle: 'server.bundle.js' } : {}),
|
|
252
365
|
permissions,
|
|
253
366
|
};
|
|
254
367
|
const runtimeConfigFile = resolve(outDir, 'ng-desktop.runtime.json');
|
|
255
368
|
writeFileSync(runtimeConfigFile, JSON.stringify(runtimeConfig, null, 2) + '\n', 'utf8');
|
|
256
369
|
|
|
257
|
-
const standaloneFallback = resolve(rootDir, 'src/standalone_pokedex.ngb');
|
|
258
|
-
if (projectName === 'ng-linux-counter' && existsSync(standaloneFallback)) {
|
|
259
|
-
writeFileSync(standaloneFallback, bundle, 'utf8');
|
|
260
|
-
}
|
|
261
370
|
console.log(
|
|
262
371
|
`[Angular Native Compiler] Compiled ${projectName} v${resolvedVersion} (${workspace.workspaceKind}) -> ${bundleFile}`,
|
|
263
372
|
);
|
|
373
|
+
if (entryBundleFile) {
|
|
374
|
+
console.log(`[Angular Native Compiler] Bundled Ivy JS runtime entry -> ${entryBundleFile}`);
|
|
375
|
+
}
|
|
376
|
+
if (serverBundleFile) {
|
|
377
|
+
console.log(`[Angular Native Compiler] Bundled Analog server routes -> ${serverBundleFile}`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const prevEmitted = lastEmittedByOutDir.get(outDir);
|
|
381
|
+
const appBundleContent = entryBundleFile ? readFileSync(entryBundleFile, 'utf8') : null;
|
|
382
|
+
const serverBundleContent = serverBundleFile ? readFileSync(serverBundleFile, 'utf8') : null;
|
|
383
|
+
const hmrDelta = {
|
|
384
|
+
ngbChanged: !prevEmitted || prevEmitted.ngb !== bundle,
|
|
385
|
+
appBundleChanged: Boolean(
|
|
386
|
+
appBundleContent && (!prevEmitted || prevEmitted.appBundle !== appBundleContent),
|
|
387
|
+
),
|
|
388
|
+
serverBundleChanged: Boolean(
|
|
389
|
+
serverBundleContent && (!prevEmitted || prevEmitted.serverBundle !== serverBundleContent),
|
|
390
|
+
),
|
|
391
|
+
};
|
|
392
|
+
lastEmittedByOutDir.set(outDir, {
|
|
393
|
+
ngb: bundle,
|
|
394
|
+
appBundle: appBundleContent,
|
|
395
|
+
serverBundle: serverBundleContent,
|
|
396
|
+
});
|
|
264
397
|
|
|
265
398
|
const socketPath = resolve(outDir, 'hmr.sock');
|
|
266
399
|
if (existsSync(socketPath)) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
400
|
+
if (hmrDelta.ngbChanged) {
|
|
401
|
+
pushHmrReload(socketPath, bundle).then((res) => {
|
|
402
|
+
if (res.connected && res.response?.status === 'ok') {
|
|
403
|
+
console.log(`[Angular Native HMR] Pushed live bundle update over IPC -> ${socketPath}`);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
if (hmrDelta.serverBundleChanged && serverBundleContent) {
|
|
408
|
+
pushHmrServerReload(socketPath, serverBundleContent).then((res) => {
|
|
409
|
+
if (res.connected && res.response?.status === 'ok') {
|
|
410
|
+
console.log(
|
|
411
|
+
`[Angular Native HMR] Pushed live server route reload over IPC -> ${socketPath}`,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
272
416
|
}
|
|
273
417
|
|
|
274
418
|
return {
|
|
@@ -276,10 +420,13 @@ export function compileBundle({
|
|
|
276
420
|
version: resolvedVersion,
|
|
277
421
|
sourceRoot: sourceRootAbs,
|
|
278
422
|
bundleFile,
|
|
423
|
+
...(entryBundleFile ? { entryBundleFile } : {}),
|
|
424
|
+
...(serverBundleFile ? { serverBundleFile } : {}),
|
|
279
425
|
permissionsFile,
|
|
280
426
|
runtimeConfigFile,
|
|
281
427
|
permissions,
|
|
282
428
|
socketPath,
|
|
429
|
+
hmrDelta,
|
|
283
430
|
};
|
|
284
431
|
}
|
|
285
432
|
|
package/fesm2022/builder.d.ts
CHANGED
|
@@ -64,4 +64,3 @@ export declare function createNativeTargetConfig(options: NativeBuilderOptions):
|
|
|
64
64
|
* `.ngb` bundle path, and target distribution artifacts.
|
|
65
65
|
*/
|
|
66
66
|
export declare function executeNativeBuilder(projectName: string, options: NativeBuilderOptions): NativeBuilderResult;
|
|
67
|
-
//# sourceMappingURL=builder.d.ts.map
|
package/fesm2022/builder.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArchitectBuilderContextLike,
|
|
3
|
+
ArchitectBuilderObject,
|
|
4
|
+
NativeApplicationBuilderOptions,
|
|
5
|
+
NativeApplicationBuilderOutput,
|
|
6
|
+
} from './application-builder.mjs';
|
|
7
|
+
|
|
8
|
+
export interface NativeDevServerBuilderOptions extends NativeApplicationBuilderOptions {
|
|
9
|
+
watch?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface NativeDevServerBuilderOutput extends NativeApplicationBuilderOutput {
|
|
13
|
+
watching: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function runNativeDevServerBuilder(
|
|
17
|
+
options?: NativeDevServerBuilderOptions,
|
|
18
|
+
context?: ArchitectBuilderContextLike,
|
|
19
|
+
): Promise<NativeDevServerBuilderOutput>;
|
|
20
|
+
|
|
21
|
+
export const devServerBuilder: ArchitectBuilderObject<
|
|
22
|
+
NativeDevServerBuilderOptions,
|
|
23
|
+
NativeDevServerBuilderOutput
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
export default devServerBuilder;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createArchitectBuilder, runNativeApplicationBuilder } from './application-builder.mjs';
|
|
2
|
+
import { watchBundle } from './build-bundle.mjs';
|
|
3
|
+
|
|
4
|
+
export async function runNativeDevServerBuilder(options = {}, context = {}) {
|
|
5
|
+
const initial = await runNativeApplicationBuilder(options, context);
|
|
6
|
+
const watching = Boolean(options?.watch);
|
|
7
|
+
if (watching) {
|
|
8
|
+
const workspaceRoot = context?.workspaceRoot || options?.cwd || process.cwd();
|
|
9
|
+
const watcher = watchBundle({
|
|
10
|
+
cwd: workspaceRoot,
|
|
11
|
+
configPath: options?.configPath,
|
|
12
|
+
projectName: initial.projectName,
|
|
13
|
+
version: options?.version,
|
|
14
|
+
});
|
|
15
|
+
context?.addTeardown?.(() => watcher.close());
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...initial,
|
|
19
|
+
watching,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const devServerBuilder = createArchitectBuilder(runNativeDevServerBuilder);
|
|
24
|
+
export default devServerBuilder;
|
|
@@ -14,6 +14,11 @@ export function sendHmrMessage(
|
|
|
14
14
|
|
|
15
15
|
export function pushHmrReload(socketPath: string, bundleScript: string): Promise<HmrClientResult>;
|
|
16
16
|
|
|
17
|
+
export function pushHmrServerReload(
|
|
18
|
+
socketPath: string,
|
|
19
|
+
serverBundleCode: string,
|
|
20
|
+
): Promise<HmrClientResult>;
|
|
21
|
+
|
|
17
22
|
export function pushHmrEval(socketPath: string, jsCode: string): Promise<HmrClientResult>;
|
|
18
23
|
|
|
19
24
|
export function pingHmr(socketPath: string): Promise<HmrClientResult>;
|
package/fesm2022/hmr-client.mjs
CHANGED
|
@@ -62,6 +62,13 @@ export async function pushHmrReload(socketPath, bundleScript) {
|
|
|
62
62
|
return sendHmrMessage(socketPath, { type: 'reload', script: bundleScript });
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Pushes a newly compiled `server.bundle.js` to hot-reload the isolated backend worker.
|
|
67
|
+
*/
|
|
68
|
+
export async function pushHmrServerReload(socketPath, serverBundleCode) {
|
|
69
|
+
return sendHmrMessage(socketPath, { type: 'reload_server', bundle: serverBundleCode });
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
/**
|
|
66
73
|
* Evaluates arbitrary JavaScript inside the active runtime of the running desktop window.
|
|
67
74
|
*/
|