@ngrs/build 0.0.0-stage → 0.2.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/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # `@ngrs/build`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Drop-in 1:1 Rust-native replacement for `@angular/build` (`application`, `browser-esbuild`, `browser`, `dev-server`, `unit-test` with Vitest + `happy-dom`, and `extract-i18n`), powered by `@ngrs/compiler` and Vite 8 Rolldown.
4
+
5
+ ## Quick Setup (1 Command)
6
+
7
+ ```bash
8
+ ng add @ngrs/build
9
+ ```
10
+
11
+ Then use standard Angular CLI or `ngrs` commands as usual:
12
+
13
+ ```bash
14
+ ng build
15
+ ng serve
16
+ ng test
17
+ # or directly via ngrs CLI:
18
+ npx ngrs build
19
+ npx ngrs serve
20
+ npx ngrs test
21
+ ```
@@ -0,0 +1,604 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import {
7
+ buildApplication,
8
+ createConsoleLogger,
9
+ createWorkspaceBuilderContext,
10
+ executeExtractI18nBuilder,
11
+ executeUnitTestBuilder,
12
+ initWorkspaceWithNgrsBuild,
13
+ loadWorkspace,
14
+ normalizeApplicationOptions,
15
+ normalizeDevServerOptions,
16
+ resolveProjectName,
17
+ resolveTargetOptions,
18
+ startDevServer,
19
+ } from '../src/index.mjs';
20
+
21
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
22
+ const pkgJson = JSON.parse(
23
+ fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'),
24
+ );
25
+
26
+ const HELP_TEXT = `\
27
+ ngrs-build v${pkgJson.version} — Rust-native Angular Application Builder & Vite Dev-Server
28
+
29
+ USAGE:
30
+ ng add @ngrs/build [--project <name>]
31
+ ngrs init [project] [--dry-run]
32
+ ngrs build [project] [options]
33
+ ngrs serve [project] [options]
34
+ ngrs test [project] [options]
35
+ ngrs-build init [project] [--dry-run]
36
+ ngrs-build build [project] [options]
37
+ ngrs-build serve [project] [options]
38
+ ngrs-build test [project] [options]
39
+ ngrs-build extract-i18n [project] [options]
40
+
41
+ BUILD OPTIONS:
42
+ -c, --configuration <name> Angular workspace configuration(s) (default: "production")
43
+ --output-path <dir> Override output directory path
44
+ --base-href <url> Base URL for the application being built
45
+ --deploy-url <url> URL where files will be deployed
46
+ --source-map / --no-source-map Emit script & style source maps
47
+ --optimization / --no-optimization
48
+ Enable/disable bundle minification & optimizations
49
+ --output-hashing <mode> Output filename hashing: none | all | media | bundles
50
+ --aot / --no-aot Build using Ahead-of-Time compilation (default: true)
51
+ --delete-output-path / --no-delete-output-path
52
+ Delete output path before building (default: true)
53
+ --named-chunks Use file name for lazy loaded chunks
54
+ --subresource-integrity Enable Subresource Integrity (SRI) hashes in index.html
55
+ --stats-json Write bundle stats.json to output directory
56
+ -w, --watch Rebuild when files change
57
+ --poll <ms> Enable polling file watcher with interval in milliseconds
58
+ --verbose Enable verbose build logging
59
+
60
+ SERVE OPTIONS:
61
+ -c, --configuration <name> Angular serve/build configuration (default: "development")
62
+ --build-target <target> Build target in "project:target[:configuration]" format
63
+ --browser-target <target> Legacy alias for --build-target
64
+ -p, --port <port> Port to listen on (default: 4200, or $PORT)
65
+ --host <host> Host to listen on (default: "localhost")
66
+ -o, --open Open the application URL in default browser
67
+ --ssl Serve using HTTPS
68
+ --ssl-key <path> SSL private key path
69
+ --ssl-cert <path> SSL certificate path
70
+ --proxy-config <path> Proxy configuration file (.json, .js, .mjs, .cjs)
71
+ --hmr / --no-hmr Enable/disable Angular Hot Module Replacement (default: true)
72
+ --live-reload / --no-live-reload
73
+ Enable/disable live page reload on change (default: true)
74
+ --serve-path <path> URL pathname where the application will be served
75
+ --allowed-hosts <hosts> Comma-separated allowed hosts (or "true" for all)
76
+ --poll <ms> Enable polling file watcher with interval in milliseconds
77
+ --verbose Enable verbose server logging
78
+
79
+ GENERAL OPTIONS:
80
+ -h, --help Show this help message
81
+ -v, -V, --version Show version number
82
+ `;
83
+
84
+ function splitFlag(arg) {
85
+ if (!arg.startsWith('--')) return null;
86
+ const eq = arg.indexOf('=');
87
+ if (eq === -1) return { flag: arg, value: undefined };
88
+ return { flag: arg.slice(0, eq), value: arg.slice(eq + 1) };
89
+ }
90
+
91
+ function parseBooleanInline(val, defaultIfOmitted = true) {
92
+ if (val === undefined) return defaultIfOmitted;
93
+ const lower = val.trim().toLowerCase();
94
+ if (lower === 'false' || lower === '0' || lower === 'no') return false;
95
+ return true;
96
+ }
97
+
98
+ function parseCliArgs(argv) {
99
+ let command = null;
100
+ let project = undefined;
101
+ let configuration = undefined;
102
+ let help = false;
103
+ let version = false;
104
+ const overrides = {};
105
+
106
+ let i = 0;
107
+ if (argv[0] && !argv[0].startsWith('-')) {
108
+ if (
109
+ argv[0] === 'build' ||
110
+ argv[0] === 'b' ||
111
+ argv[0] === 'serve' ||
112
+ argv[0] === 's' ||
113
+ argv[0] === 'dev' ||
114
+ argv[0] === 'extract-i18n' ||
115
+ argv[0] === 'xi18n' ||
116
+ argv[0] === 'test' ||
117
+ argv[0] === 't' ||
118
+ argv[0] === 'init'
119
+ ) {
120
+ command =
121
+ argv[0] === 'b'
122
+ ? 'build'
123
+ : argv[0] === 's' || argv[0] === 'dev'
124
+ ? 'serve'
125
+ : argv[0] === 't'
126
+ ? 'test'
127
+ : argv[0] === 'xi18n'
128
+ ? 'extract-i18n'
129
+ : argv[0];
130
+ i = 1;
131
+ }
132
+ }
133
+
134
+ const takeValue = (inlineVal) => {
135
+ if (inlineVal !== undefined) return inlineVal;
136
+ if (i + 1 >= argv.length) {
137
+ throw new Error(`Missing value for option "${argv[i]}".`);
138
+ }
139
+ i += 1;
140
+ return argv[i];
141
+ };
142
+
143
+ while (i < argv.length) {
144
+ const raw = argv[i];
145
+ if (raw === '-h' || raw === '--help') {
146
+ help = true;
147
+ i += 1;
148
+ continue;
149
+ }
150
+ if (raw === '-v' || raw === '-V' || raw === '--version') {
151
+ version = true;
152
+ i += 1;
153
+ continue;
154
+ }
155
+ if (raw === '-c') {
156
+ configuration = takeValue(undefined);
157
+ i += 1;
158
+ continue;
159
+ }
160
+ if (raw === '-w') {
161
+ overrides.watch = true;
162
+ i += 1;
163
+ continue;
164
+ }
165
+ if (raw === '-o') {
166
+ overrides.open = true;
167
+ i += 1;
168
+ continue;
169
+ }
170
+ if (raw === '-p' && command === 'serve') {
171
+ overrides.port = Number(takeValue(undefined));
172
+ i += 1;
173
+ continue;
174
+ }
175
+
176
+ const long = splitFlag(raw);
177
+ if (long) {
178
+ switch (long.flag) {
179
+ case '--configuration':
180
+ configuration = takeValue(long.value);
181
+ break;
182
+ case '--prod':
183
+ configuration = 'production';
184
+ break;
185
+ case '--output-path':
186
+ case '--outputPath':
187
+ overrides.outputPath = takeValue(long.value);
188
+ break;
189
+ case '--base-href':
190
+ case '--baseHref':
191
+ overrides.baseHref = takeValue(long.value);
192
+ break;
193
+ case '--deploy-url':
194
+ case '--deployUrl':
195
+ overrides.deployUrl = takeValue(long.value);
196
+ break;
197
+ case '--source-map':
198
+ case '--sourceMap':
199
+ overrides.sourceMap = parseBooleanInline(long.value, true);
200
+ break;
201
+ case '--no-source-map':
202
+ overrides.sourceMap = false;
203
+ break;
204
+ case '--optimization':
205
+ overrides.optimization = parseBooleanInline(long.value, true);
206
+ break;
207
+ case '--no-optimization':
208
+ overrides.optimization = false;
209
+ break;
210
+ case '--output-hashing':
211
+ case '--outputHashing':
212
+ overrides.outputHashing = takeValue(long.value);
213
+ break;
214
+ case '--aot':
215
+ overrides.aot = parseBooleanInline(long.value, true);
216
+ break;
217
+ case '--no-aot':
218
+ overrides.aot = false;
219
+ break;
220
+ case '--delete-output-path':
221
+ case '--deleteOutputPath':
222
+ overrides.deleteOutputPath = parseBooleanInline(long.value, true);
223
+ break;
224
+ case '--no-delete-output-path':
225
+ overrides.deleteOutputPath = false;
226
+ break;
227
+ case '--named-chunks':
228
+ case '--namedChunks':
229
+ overrides.namedChunks = parseBooleanInline(long.value, true);
230
+ break;
231
+ case '--subresource-integrity':
232
+ case '--subresourceIntegrity':
233
+ overrides.subresourceIntegrity = parseBooleanInline(long.value, true);
234
+ break;
235
+ case '--stats-json':
236
+ case '--statsJson':
237
+ overrides.statsJson = parseBooleanInline(long.value, true);
238
+ break;
239
+ case '--watch':
240
+ overrides.watch = parseBooleanInline(long.value, true);
241
+ break;
242
+ case '--no-watch':
243
+ overrides.watch = false;
244
+ break;
245
+ case '--poll':
246
+ overrides.poll = Number(takeValue(long.value));
247
+ break;
248
+ case '--verbose':
249
+ overrides.verbose = parseBooleanInline(long.value, true);
250
+ break;
251
+ case '--progress':
252
+ overrides.progress = parseBooleanInline(long.value, true);
253
+ break;
254
+ case '--no-progress':
255
+ overrides.progress = false;
256
+ break;
257
+ case '--color':
258
+ case '--colors':
259
+ overrides.colors = parseBooleanInline(long.value, true);
260
+ break;
261
+ case '--no-color':
262
+ case '--no-colors':
263
+ overrides.colors = false;
264
+ break;
265
+ case '--project':
266
+ project = takeValue(long.value);
267
+ break;
268
+ case '--dry-run':
269
+ overrides.dryRun = parseBooleanInline(long.value, true);
270
+ break;
271
+ case '--coverage':
272
+ case '--code-coverage':
273
+ overrides.coverage = parseBooleanInline(long.value, true);
274
+ break;
275
+ case '--no-coverage':
276
+ overrides.coverage = false;
277
+ break;
278
+ case '--filter':
279
+ overrides.filter = takeValue(long.value);
280
+ break;
281
+ case '--include': {
282
+ const val = takeValue(long.value);
283
+ overrides.include = [...(overrides.include || []), val];
284
+ break;
285
+ }
286
+ case '--exclude': {
287
+ const val = takeValue(long.value);
288
+ overrides.exclude = [...(overrides.exclude || []), val];
289
+ break;
290
+ }
291
+ case '--reporters': {
292
+ const val = takeValue(long.value);
293
+ overrides.reporters = val.split(',').map((s) => s.trim()).filter(Boolean);
294
+ break;
295
+ }
296
+ case '--list-tests':
297
+ case '--listTests':
298
+ overrides.listTests = parseBooleanInline(long.value, true);
299
+ break;
300
+ case '--headless':
301
+ overrides.headless = parseBooleanInline(long.value, true);
302
+ break;
303
+ case '--no-headless':
304
+ overrides.headless = false;
305
+ break;
306
+ case '--environment':
307
+ overrides.environment = takeValue(long.value);
308
+ break;
309
+ case '--port':
310
+ overrides.port = Number(takeValue(long.value));
311
+ break;
312
+ case '--host':
313
+ overrides.host = takeValue(long.value);
314
+ break;
315
+ case '--open':
316
+ overrides.open = parseBooleanInline(long.value, true);
317
+ break;
318
+ case '--ssl':
319
+ overrides.ssl = parseBooleanInline(long.value, true);
320
+ break;
321
+ case '--no-ssl':
322
+ overrides.ssl = false;
323
+ break;
324
+ case '--ssl-key':
325
+ case '--sslKey':
326
+ overrides.sslKey = takeValue(long.value);
327
+ break;
328
+ case '--ssl-cert':
329
+ case '--sslCert':
330
+ overrides.sslCert = takeValue(long.value);
331
+ break;
332
+ case '--proxy-config':
333
+ case '--proxyConfig':
334
+ overrides.proxyConfig = takeValue(long.value);
335
+ break;
336
+ case '--hmr':
337
+ overrides.hmr = parseBooleanInline(long.value, true);
338
+ break;
339
+ case '--no-hmr':
340
+ overrides.hmr = false;
341
+ break;
342
+ case '--live-reload':
343
+ case '--liveReload':
344
+ overrides.liveReload = parseBooleanInline(long.value, true);
345
+ break;
346
+ case '--no-live-reload':
347
+ overrides.liveReload = false;
348
+ break;
349
+ case '--serve-path':
350
+ case '--servePath':
351
+ overrides.servePath = takeValue(long.value);
352
+ break;
353
+ case '--build-target':
354
+ case '--buildTarget':
355
+ overrides.buildTarget = takeValue(long.value);
356
+ break;
357
+ case '--browser-target':
358
+ case '--browserTarget':
359
+ overrides.browserTarget = takeValue(long.value);
360
+ break;
361
+ case '--allowed-hosts':
362
+ case '--allowedHosts': {
363
+ const val = takeValue(long.value);
364
+ overrides.allowedHosts =
365
+ val === 'true'
366
+ ? true
367
+ : val
368
+ .split(',')
369
+ .map((s) => s.trim())
370
+ .filter(Boolean);
371
+ break;
372
+ }
373
+ case '--format':
374
+ overrides.format = takeValue(long.value);
375
+ break;
376
+ case '--out-file':
377
+ case '--outFile':
378
+ overrides.outFile = takeValue(long.value);
379
+ break;
380
+ default:
381
+ throw new Error(`Unknown CLI option "${raw}". Run with --help for usage.`);
382
+ }
383
+ i += 1;
384
+ continue;
385
+ }
386
+
387
+ if (!raw.startsWith('-') && project === undefined) {
388
+ project = raw;
389
+ i += 1;
390
+ continue;
391
+ }
392
+
393
+ throw new Error(`Unexpected argument "${raw}". Run with --help for usage.`);
394
+ }
395
+
396
+ return {
397
+ command: command || 'build',
398
+ project,
399
+ configuration,
400
+ help,
401
+ version,
402
+ overrides,
403
+ };
404
+ }
405
+
406
+ async function main() {
407
+ const parsed = parseCliArgs(process.argv.slice(2));
408
+
409
+ if (parsed.help) {
410
+ process.stdout.write(HELP_TEXT);
411
+ return 0;
412
+ }
413
+ if (parsed.version) {
414
+ process.stdout.write(`${pkgJson.version}\n`);
415
+ return 0;
416
+ }
417
+
418
+ const logger = createConsoleLogger(Boolean(parsed.overrides.verbose));
419
+
420
+ if (parsed.command === 'init') {
421
+ await initWorkspaceWithNgrsBuild({
422
+ workspaceRoot: process.cwd(),
423
+ project: parsed.project,
424
+ dryRun: Boolean(parsed.overrides.dryRun),
425
+ logger,
426
+ });
427
+ return 0;
428
+ }
429
+
430
+ const loaded = await loadWorkspace(process.cwd());
431
+ const projectName = resolveProjectName(loaded.workspace, parsed.project);
432
+
433
+ if (parsed.command === 'build') {
434
+ const targetSpec = {
435
+ project: projectName,
436
+ target: 'build',
437
+ ...(parsed.configuration ? { configuration: parsed.configuration } : {}),
438
+ };
439
+ const resolvedBuildOpts = {
440
+ ...resolveTargetOptions(loaded.workspace, targetSpec, 'production'),
441
+ ...parsed.overrides,
442
+ };
443
+
444
+ const context = createWorkspaceBuilderContext({
445
+ workspaceRoot: loaded.workspaceRoot,
446
+ workspace: loaded.workspace,
447
+ target: targetSpec,
448
+ builderName: '@ngrs/build:application',
449
+ logger,
450
+ });
451
+
452
+ let lastSuccess = true;
453
+ for await (const output of buildApplication(resolvedBuildOpts, context)) {
454
+ lastSuccess = Boolean(output?.success);
455
+ if (!resolvedBuildOpts.watch) {
456
+ break;
457
+ }
458
+ }
459
+ await context.runTeardowns();
460
+ return lastSuccess ? 0 : 1;
461
+ }
462
+
463
+ if (parsed.command === 'serve') {
464
+ const projectObj = loaded.workspace.projects[projectName] || {};
465
+ const targets = projectObj.architect || projectObj.targets || {};
466
+
467
+ let rawServeOpts = {};
468
+ if (targets.serve) {
469
+ const serveTargetSpec = {
470
+ project: projectName,
471
+ target: 'serve',
472
+ ...(parsed.configuration ? { configuration: parsed.configuration } : {}),
473
+ };
474
+ // If `-c <cfg>` was passed and exists on `serve.configurations`, use it; otherwise if it
475
+ // only exists on `build.configurations`, forward it via `buildTarget`!
476
+ const serveConfigs = targets.serve.configurations || {};
477
+ if (parsed.configuration && !serveConfigs[parsed.configuration]) {
478
+ rawServeOpts = {
479
+ ...resolveTargetOptions(
480
+ loaded.workspace,
481
+ { project: projectName, target: 'serve' },
482
+ 'development',
483
+ ),
484
+ buildTarget: `${projectName}:build:${parsed.configuration}`,
485
+ };
486
+ } else {
487
+ rawServeOpts = resolveTargetOptions(
488
+ loaded.workspace,
489
+ serveTargetSpec,
490
+ 'development',
491
+ );
492
+ }
493
+ } else if (parsed.configuration) {
494
+ rawServeOpts = {
495
+ buildTarget: `${projectName}:build:${parsed.configuration}`,
496
+ };
497
+ }
498
+
499
+ const mergedServeOpts = {
500
+ ...rawServeOpts,
501
+ ...parsed.overrides,
502
+ };
503
+
504
+ const normalizedServe = normalizeDevServerOptions(
505
+ mergedServeOpts,
506
+ loaded.workspace,
507
+ projectName,
508
+ loaded.workspaceRoot,
509
+ );
510
+
511
+ const devBuildRaw = {
512
+ optimization: false,
513
+ sourceMap: true,
514
+ outputHashing: 'none',
515
+ ...normalizedServe.buildTargetOptions,
516
+ };
517
+ const targetProjectMeta =
518
+ loaded.workspace.projects[normalizedServe.buildTarget.project] || projectObj;
519
+ const normalizedApp = normalizeApplicationOptions(
520
+ devBuildRaw,
521
+ targetProjectMeta,
522
+ loaded.workspaceRoot,
523
+ normalizedServe.buildTarget.project,
524
+ );
525
+
526
+ const started = await startDevServer(normalizedServe, normalizedApp, logger);
527
+
528
+ const shutdown = async () => {
529
+ await started.server.close();
530
+ process.exit(0);
531
+ };
532
+ process.once('SIGINT', shutdown);
533
+ process.once('SIGTERM', shutdown);
534
+
535
+ await new Promise((resolve) => {
536
+ started.server.httpServer?.once('close', resolve);
537
+ });
538
+ return 0;
539
+ }
540
+
541
+ if (parsed.command === 'test') {
542
+ const targetSpec = {
543
+ project: projectName,
544
+ target: 'test',
545
+ ...(parsed.configuration ? { configuration: parsed.configuration } : {}),
546
+ };
547
+ let resolvedTestOpts = {};
548
+ try {
549
+ resolvedTestOpts = resolveTargetOptions(loaded.workspace, targetSpec);
550
+ } catch {
551
+ resolvedTestOpts = {};
552
+ }
553
+ const mergedTestOpts = {
554
+ ...resolvedTestOpts,
555
+ ...parsed.overrides,
556
+ };
557
+
558
+ const context = createWorkspaceBuilderContext({
559
+ workspaceRoot: loaded.workspaceRoot,
560
+ workspace: loaded.workspace,
561
+ target: targetSpec,
562
+ builderName: '@ngrs/build:unit-test',
563
+ logger,
564
+ });
565
+
566
+ let lastSuccess = true;
567
+ for await (const output of executeUnitTestBuilder(mergedTestOpts, context)) {
568
+ lastSuccess = Boolean(output?.success);
569
+ if (!mergedTestOpts.watch) {
570
+ break;
571
+ }
572
+ }
573
+ await context.runTeardowns();
574
+ return lastSuccess ? 0 : 1;
575
+ }
576
+
577
+ if (parsed.command === 'extract-i18n') {
578
+ const context = createWorkspaceBuilderContext({
579
+ workspaceRoot: loaded.workspaceRoot,
580
+ workspace: loaded.workspace,
581
+ target: {
582
+ project: projectName,
583
+ target: 'extract-i18n',
584
+ ...(parsed.configuration ? { configuration: parsed.configuration } : {}),
585
+ },
586
+ builderName: '@ngrs/build:extract-i18n',
587
+ logger,
588
+ });
589
+ const out = await executeExtractI18nBuilder(parsed.overrides, context);
590
+ return out.success ? 0 : 1;
591
+ }
592
+
593
+ throw new Error(`Unsupported command "${parsed.command}".`);
594
+ }
595
+
596
+ main().then(
597
+ (code) => {
598
+ process.exitCode = code;
599
+ },
600
+ (err) => {
601
+ console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
602
+ process.exit(1);
603
+ },
604
+ );