@nx/angular-rspack 20.8.2 → 20.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/lib/config/config-utils/browser-config.d.ts +4 -0
  2. package/dist/lib/config/config-utils/browser-config.d.ts.map +1 -0
  3. package/dist/lib/config/config-utils/browser-config.js +68 -0
  4. package/dist/lib/config/config-utils/common-config.d.ts +3 -0
  5. package/dist/lib/config/config-utils/common-config.d.ts.map +1 -0
  6. package/dist/lib/config/config-utils/common-config.js +111 -0
  7. package/dist/lib/config/config-utils/dev-server-config-utils.d.ts +4 -0
  8. package/dist/lib/config/config-utils/dev-server-config-utils.d.ts.map +1 -0
  9. package/dist/lib/config/config-utils/dev-server-config-utils.js +255 -0
  10. package/dist/lib/config/{entry-points.d.ts → config-utils/entry-points.d.ts} +1 -1
  11. package/dist/lib/config/config-utils/entry-points.d.ts.map +1 -0
  12. package/dist/lib/config/config-utils/helpers.d.ts +13 -0
  13. package/dist/lib/config/config-utils/helpers.d.ts.map +1 -0
  14. package/dist/lib/config/{helpers.js → config-utils/helpers.js} +33 -0
  15. package/dist/lib/config/config-utils/optimization-config.d.ts +5 -0
  16. package/dist/lib/config/config-utils/optimization-config.d.ts.map +1 -0
  17. package/dist/lib/config/config-utils/optimization-config.js +67 -0
  18. package/dist/lib/config/config-utils/server-config.d.ts +4 -0
  19. package/dist/lib/config/config-utils/server-config.d.ts.map +1 -0
  20. package/dist/lib/config/config-utils/server-config.js +87 -0
  21. package/dist/lib/config/config-utils/sourcemap-utils.d.ts +7 -0
  22. package/dist/lib/config/config-utils/sourcemap-utils.d.ts.map +1 -0
  23. package/dist/lib/config/config-utils/sourcemap-utils.js +48 -0
  24. package/dist/lib/config/config-utils/style-config-utils.d.ts +7 -0
  25. package/dist/lib/config/config-utils/style-config-utils.d.ts.map +1 -0
  26. package/dist/lib/config/config-utils/style-config-utils.js +353 -0
  27. package/dist/lib/config/config-utils/user-defined-config-helpers.d.ts +78 -0
  28. package/dist/lib/config/config-utils/user-defined-config-helpers.d.ts.map +1 -0
  29. package/dist/lib/config/config-utils/user-defined-config-helpers.js +23 -0
  30. package/dist/lib/config/create-config.d.ts +2 -75
  31. package/dist/lib/config/create-config.d.ts.map +1 -1
  32. package/dist/lib/config/create-config.js +17 -473
  33. package/dist/lib/index.d.ts +4 -0
  34. package/dist/lib/index.d.ts.map +1 -1
  35. package/dist/lib/index.js +9 -0
  36. package/dist/lib/models/angular-rspack-plugin-options.d.ts +41 -4
  37. package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -1
  38. package/dist/lib/models/normalize-options.d.ts.map +1 -1
  39. package/dist/lib/models/normalize-options.js +53 -54
  40. package/dist/lib/models/unsupported-options.d.ts +0 -7
  41. package/dist/lib/models/unsupported-options.d.ts.map +1 -1
  42. package/dist/lib/models/unsupported-options.js +0 -4
  43. package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -1
  44. package/dist/lib/plugins/angular-rspack-plugin.js +0 -7
  45. package/dist/lib/plugins/angular-ssr-dev-server.d.ts +2 -2
  46. package/dist/lib/plugins/angular-ssr-dev-server.d.ts.map +1 -1
  47. package/dist/lib/plugins/angular-ssr-dev-server.js +19 -9
  48. package/dist/lib/plugins/index-html-plugin.d.ts.map +1 -1
  49. package/dist/lib/plugins/index-html-plugin.js +2 -7
  50. package/dist/lib/plugins/loaders/platform-server-exports.loader.d.ts +5 -0
  51. package/dist/lib/plugins/loaders/platform-server-exports.loader.d.ts.map +1 -0
  52. package/dist/lib/plugins/loaders/platform-server-exports.loader.js +18 -0
  53. package/dist/lib/plugins/ng-rspack.d.ts.map +1 -1
  54. package/dist/lib/plugins/ng-rspack.js +3 -3
  55. package/dist/lib/plugins/prerender-plugin.d.ts +8 -0
  56. package/dist/lib/plugins/prerender-plugin.d.ts.map +1 -0
  57. package/dist/lib/plugins/prerender-plugin.js +154 -0
  58. package/dist/lib/plugins/tools/render-worker.d.ts +31 -0
  59. package/dist/lib/plugins/tools/render-worker.d.ts.map +1 -0
  60. package/dist/lib/plugins/tools/render-worker.js +103 -0
  61. package/dist/lib/plugins/tools/routes-extractor-worker.d.ts +21 -0
  62. package/dist/lib/plugins/tools/routes-extractor-worker.d.ts.map +1 -0
  63. package/dist/lib/plugins/tools/routes-extractor-worker.js +46 -0
  64. package/dist/lib/plugins/tools/worker-pool.d.ts +13 -0
  65. package/dist/lib/plugins/tools/worker-pool.d.ts.map +1 -0
  66. package/dist/lib/plugins/tools/worker-pool.js +26 -0
  67. package/dist/lib/utils/index-file/add-body-script.d.ts +2 -0
  68. package/dist/lib/utils/index-file/add-body-script.d.ts.map +1 -0
  69. package/dist/lib/utils/index-file/add-body-script.js +15 -0
  70. package/dist/lib/utils/index-file/get-index-output-file.d.ts +3 -0
  71. package/dist/lib/utils/index-file/get-index-output-file.d.ts.map +1 -0
  72. package/dist/lib/utils/index-file/get-index-output-file.js +10 -0
  73. package/dist/lib/utils/max-workers.d.ts +2 -0
  74. package/dist/lib/utils/max-workers.d.ts.map +1 -0
  75. package/dist/lib/utils/max-workers.js +21 -0
  76. package/dist/lib/utils/postcss-cli-resources.d.ts +22 -0
  77. package/dist/lib/utils/postcss-cli-resources.d.ts.map +1 -0
  78. package/dist/lib/utils/postcss-cli-resources.js +158 -0
  79. package/dist/lib/utils/postcss-configuration.d.ts +18 -0
  80. package/dist/lib/utils/postcss-configuration.d.ts.map +1 -0
  81. package/dist/lib/utils/postcss-configuration.js +89 -0
  82. package/package.json +19 -5
  83. package/dist/lib/config/dev-server-config-utils.d.ts +0 -4
  84. package/dist/lib/config/dev-server-config-utils.d.ts.map +0 -1
  85. package/dist/lib/config/dev-server-config-utils.js +0 -107
  86. package/dist/lib/config/entry-points.d.ts.map +0 -1
  87. package/dist/lib/config/helpers.d.ts +0 -14
  88. package/dist/lib/config/helpers.d.ts.map +0 -1
  89. package/dist/lib/config/style-config-utils.d.ts +0 -22
  90. package/dist/lib/config/style-config-utils.d.ts.map +0 -1
  91. package/dist/lib/config/style-config-utils.js +0 -202
  92. package/dist/lib/utils/tailwind.d.ts +0 -2
  93. package/dist/lib/utils/tailwind.d.ts.map +0 -1
  94. package/dist/lib/utils/tailwind.js +0 -31
  95. /package/dist/lib/config/{entry-points.js → config-utils/entry-points.js} +0 -0
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrerenderPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const private_1 = require("@angular/build/private");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const fs_1 = require("fs");
8
+ const promises_1 = require("fs/promises");
9
+ const path_1 = require("path");
10
+ const assert_1 = tslib_1.__importDefault(require("assert"));
11
+ const get_index_output_file_1 = require("../utils/index-file/get-index-output-file");
12
+ const worker_pool_1 = require("./tools/worker-pool");
13
+ const max_workers_1 = require("../utils/max-workers");
14
+ const i18n_1 = require("../utils/i18n");
15
+ const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
16
+ const misc_helpers_1 = require("../utils/misc-helpers");
17
+ class RoutesSet extends Set {
18
+ add(value) {
19
+ return super.add(value.charAt(0) === '/' ? value.slice(1) : value);
20
+ }
21
+ }
22
+ class PrerenderPlugin {
23
+ #_options;
24
+ #i18n;
25
+ constructor(options, i18nOptions) {
26
+ this.#_options = options;
27
+ this.#i18n = i18nOptions;
28
+ }
29
+ apply(compiler) {
30
+ compiler.hooks.afterEmit.tapAsync('Angular Rspack', async (compilation, callback) => {
31
+ await this.#renderUniversal(compilation);
32
+ callback();
33
+ });
34
+ }
35
+ async #renderUniversal(compilation) {
36
+ // Users can specify a different base html file e.g. "src/home.html"
37
+ const indexFile = (0, get_index_output_file_1.getIndexOutputFile)(this.#_options.index);
38
+ const zonePackage = require.resolve('zone.js', {
39
+ paths: [devkit_1.workspaceRoot],
40
+ });
41
+ const worker = new worker_pool_1.WorkerPool({
42
+ filename: require.resolve('./tools/render-worker'),
43
+ maxThreads: (0, max_workers_1.maxWorkers)(),
44
+ workerData: {
45
+ zonePackage,
46
+ },
47
+ recordTiming: false,
48
+ });
49
+ let routes;
50
+ try {
51
+ const outputPaths = this.#i18n
52
+ ? (0, i18n_1.ensureOutputPaths)(this.#_options.outputPath.browser, this.#i18n)
53
+ : new Map([['', this.#_options.outputPath.browser]]);
54
+ const localeOutputPaths = this.#i18n
55
+ ? (0, i18n_1.getLocaleOutputPaths)(this.#i18n)
56
+ : new Map();
57
+ for (const [locale, outputPath] of outputPaths.entries()) {
58
+ const normalizedOutputPath = (0, path_1.join)(this.#_options.outputPath.browser, outputPath);
59
+ const serverBundlePath = locale
60
+ ? (0, path_1.join)(this.#_options.outputPath.server, localeOutputPaths.get(locale), 'server.js')
61
+ : (0, path_1.join)(this.#_options.outputPath.server, 'server.js');
62
+ if (!(0, fs_1.existsSync)(serverBundlePath)) {
63
+ throw new Error(`Could not find the main bundle: ${serverBundlePath}`);
64
+ }
65
+ routes ??= await this.#getRoutes(indexFile, normalizedOutputPath, serverBundlePath, devkit_1.workspaceRoot);
66
+ try {
67
+ const results = (await Promise.all(routes.map((route) => {
68
+ const options = {
69
+ indexFile,
70
+ deployUrl: this.#_options.deployUrl || '',
71
+ inlineCriticalCss:
72
+ // TODO: Enable below when styles optimization is enabled
73
+ // !!normalizedStylesOptimization.inlineCritical,
74
+ true,
75
+ minifyCss:
76
+ // TODO: Enable below when styles optimization is enabled
77
+ // !!normalizedStylesOptimization.minify,
78
+ true,
79
+ outputPath: normalizedOutputPath,
80
+ route,
81
+ serverBundlePath,
82
+ };
83
+ return worker.run(options);
84
+ })));
85
+ for (const { errors, warnings } of results) {
86
+ errors?.forEach((e) => (0, rspack_diagnostics_1.addError)(compilation, e));
87
+ warnings?.forEach((e) => (0, rspack_diagnostics_1.addWarning)(compilation, e));
88
+ }
89
+ }
90
+ catch (error) {
91
+ (0, misc_helpers_1.assertIsError)(error);
92
+ (0, rspack_diagnostics_1.addError)(compilation, error.message);
93
+ }
94
+ if (this.#_options.serviceWorker && this.#_options.ngswConfigPath) {
95
+ try {
96
+ await (0, private_1.augmentAppWithServiceWorker)(this.#_options.root, devkit_1.workspaceRoot, outputPath, this.#_options.baseHref || '/', this.#_options.ngswConfigPath);
97
+ }
98
+ catch (error) {
99
+ (0, misc_helpers_1.assertIsError)(error);
100
+ (0, rspack_diagnostics_1.addError)(compilation, error.message);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ finally {
106
+ void worker.destroy();
107
+ }
108
+ }
109
+ async #getRoutes(indexFile, outputPath, serverBundlePath, workspaceRoot) {
110
+ const { routes: extraRoutes = [], routesFile, discoverRoutes, } = this.#normalizePrerenderOptions();
111
+ const routes = new RoutesSet(extraRoutes);
112
+ if (routesFile) {
113
+ const routesFromFile = (await (0, promises_1.readFile)((0, path_1.join)(workspaceRoot, routesFile), 'utf8')).split(/\r?\n/);
114
+ for (const route of routesFromFile) {
115
+ routes.add(route);
116
+ }
117
+ }
118
+ if (discoverRoutes) {
119
+ const renderWorker = new worker_pool_1.WorkerPool({
120
+ filename: require.resolve('./tools/routes-extractor-worker'),
121
+ maxThreads: (0, max_workers_1.maxWorkers)(),
122
+ workerData: {
123
+ indexFile,
124
+ outputPath,
125
+ serverBundlePath,
126
+ zonePackage: require.resolve('zone.js', { paths: [workspaceRoot] }),
127
+ },
128
+ recordTiming: false,
129
+ });
130
+ const extractedRoutes = await renderWorker
131
+ .run({})
132
+ .finally(() => void renderWorker.destroy());
133
+ for (const route of extractedRoutes) {
134
+ routes.add(route);
135
+ }
136
+ }
137
+ if (routes.size === 0) {
138
+ throw new Error('Could not find any routes to prerender.');
139
+ }
140
+ return [...routes];
141
+ }
142
+ #normalizePrerenderOptions() {
143
+ (0, assert_1.default)(this.#_options.prerender, 'Prerendering is not enabled.');
144
+ if (typeof this.#_options.prerender === 'boolean') {
145
+ return {
146
+ routes: [],
147
+ routesFile: undefined,
148
+ discoverRoutes: true,
149
+ };
150
+ }
151
+ return this.#_options.prerender;
152
+ }
153
+ }
154
+ exports.PrerenderPlugin = PrerenderPlugin;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ export interface RenderOptions {
9
+ indexFile: string;
10
+ deployUrl: string;
11
+ inlineCriticalCss: boolean;
12
+ minifyCss: boolean;
13
+ outputPath: string;
14
+ serverBundlePath: string;
15
+ route: string;
16
+ }
17
+ export interface RenderResult {
18
+ errors?: string[];
19
+ warnings?: string[];
20
+ }
21
+ /**
22
+ * Renders each route in routes and writes them to <outputPath>/<route>/index.html.
23
+ */
24
+ declare function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }: RenderOptions): Promise<RenderResult>;
25
+ /**
26
+ * The default export will be the promise returned by the initialize function.
27
+ * This is awaited by piscina prior to using the Worker.
28
+ */
29
+ declare const _default: Promise<typeof render>;
30
+ export default _default;
31
+ //# sourceMappingURL=render-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-worker.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/tools/render-worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AA2BD;;GAEG;AACH,iBAAe,MAAM,CAAC,EACpB,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,iBAAiB,GAClB,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAmGvC;AAqBD;;;GAGG;;AACH,wBAA4B"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const tslib_1 = require("tslib");
11
+ const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
12
+ const fs = tslib_1.__importStar(require("node:fs"));
13
+ const path = tslib_1.__importStar(require("node:path"));
14
+ const node_worker_threads_1 = require("node:worker_threads");
15
+ /**
16
+ * The fully resolved path to the zone.js package that will be loaded during worker initialization.
17
+ * This is passed as workerData when setting up the worker via the `piscina` package.
18
+ */
19
+ const { zonePackage } = node_worker_threads_1.workerData;
20
+ /**
21
+ * Renders each route in routes and writes them to <outputPath>/<route>/index.html.
22
+ */
23
+ async function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }) {
24
+ const result = {};
25
+ const browserIndexOutputPath = path.join(outputPath, indexFile);
26
+ const outputFolderPath = path.join(outputPath, route);
27
+ const outputIndexPath = path.join(outputFolderPath, 'index.html');
28
+ const { ɵSERVER_CONTEXT, AppServerModule, renderModule, renderApplication, default: bootstrapAppFn, } = (await Promise.resolve(`${serverBundlePath}`).then(s => tslib_1.__importStar(require(s))));
29
+ (0, node_assert_1.default)(ɵSERVER_CONTEXT, `ɵSERVER_CONTEXT was not exported from: ${serverBundlePath}.`);
30
+ const indexBaseName = fs.existsSync(path.join(outputPath, 'index.original.html'))
31
+ ? 'index.original.html'
32
+ : indexFile;
33
+ const browserIndexInputPath = path.join(outputPath, indexBaseName);
34
+ const document = await fs.promises.readFile(browserIndexInputPath, 'utf8');
35
+ const platformProviders = [
36
+ {
37
+ provide: ɵSERVER_CONTEXT,
38
+ useValue: 'ssg',
39
+ },
40
+ ];
41
+ let html;
42
+ // Render platform server module
43
+ if (isBootstrapFn(bootstrapAppFn)) {
44
+ (0, node_assert_1.default)(renderApplication, `renderApplication was not exported from: ${serverBundlePath}.`);
45
+ html = await renderApplication(bootstrapAppFn, {
46
+ document,
47
+ url: route,
48
+ platformProviders,
49
+ });
50
+ }
51
+ else {
52
+ (0, node_assert_1.default)(renderModule, `renderModule was not exported from: ${serverBundlePath}.`);
53
+ const moduleClass = bootstrapAppFn || AppServerModule;
54
+ (0, node_assert_1.default)(moduleClass, `Neither an AppServerModule nor a bootstrapping function was exported from: ${serverBundlePath}.`);
55
+ html = await renderModule(moduleClass, {
56
+ document,
57
+ url: route,
58
+ extraProviders: platformProviders,
59
+ });
60
+ }
61
+ if (inlineCriticalCss) {
62
+ const { InlineCriticalCssProcessor } = await Promise.resolve().then(() => tslib_1.__importStar(require('@angular/build/private')));
63
+ const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
64
+ deployUrl: deployUrl,
65
+ minify: minifyCss,
66
+ });
67
+ const { content, warnings, errors } = await inlineCriticalCssProcessor.process(html, {
68
+ outputPath,
69
+ });
70
+ result.errors = errors;
71
+ result.warnings = warnings;
72
+ html = content;
73
+ }
74
+ // This case happens when we are prerendering "/".
75
+ if (browserIndexOutputPath === outputIndexPath) {
76
+ const browserIndexOutputPathOriginal = path.join(outputPath, 'index.original.html');
77
+ fs.renameSync(browserIndexOutputPath, browserIndexOutputPathOriginal);
78
+ }
79
+ fs.mkdirSync(outputFolderPath, { recursive: true });
80
+ fs.writeFileSync(outputIndexPath, html);
81
+ return result;
82
+ }
83
+ function isBootstrapFn(value) {
84
+ // We can differentiate between a module and a bootstrap function by reading compiler-generated `ɵmod` static property:
85
+ return typeof value === 'function' && !('ɵmod' in value);
86
+ }
87
+ /**
88
+ * Initializes the worker when it is first created by loading the Zone.js package
89
+ * into the worker instance.
90
+ *
91
+ * @returns A promise resolving to the render function of the worker.
92
+ */
93
+ async function initialize() {
94
+ // Setup Zone.js
95
+ await Promise.resolve(`${zonePackage}`).then(s => tslib_1.__importStar(require(s)));
96
+ // Return the render function for use
97
+ return render;
98
+ }
99
+ /**
100
+ * The default export will be the promise returned by the initialize function.
101
+ * This is awaited by piscina prior to using the Worker.
102
+ */
103
+ exports.default = initialize();
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ export interface RoutesExtractorWorkerData {
9
+ zonePackage: string;
10
+ indexFile: string;
11
+ outputPath: string;
12
+ serverBundlePath: string;
13
+ }
14
+ declare function extract(): Promise<string[]>;
15
+ /**
16
+ * The default export will be the promise returned by the initialize function.
17
+ * This is awaited by piscina prior to using the Worker.
18
+ */
19
+ declare const _default: Promise<typeof extract>;
20
+ export default _default;
21
+ //# sourceMappingURL=routes-extractor-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-extractor-worker.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/tools/routes-extractor-worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAgBD,iBAAe,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CA8B1C;AAeD;;;GAGG;;AACH,wBAA4B"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const tslib_1 = require("tslib");
11
+ const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
12
+ const fs = tslib_1.__importStar(require("node:fs"));
13
+ const path = tslib_1.__importStar(require("node:path"));
14
+ const node_worker_threads_1 = require("node:worker_threads");
15
+ const { zonePackage, serverBundlePath, outputPath, indexFile } = node_worker_threads_1.workerData;
16
+ async function extract() {
17
+ const { AppServerModule, ɵgetRoutesFromAngularRouterConfig: getRoutesFromAngularRouterConfig, default: bootstrapAppFn, } = (await Promise.resolve(`${serverBundlePath}`).then(s => tslib_1.__importStar(require(s))));
18
+ const browserIndexInputPath = path.join(outputPath, indexFile);
19
+ const document = await fs.promises.readFile(browserIndexInputPath, 'utf8');
20
+ const bootstrapAppFnOrModule = bootstrapAppFn || AppServerModule;
21
+ (0, node_assert_1.default)(bootstrapAppFnOrModule, `The file "${serverBundlePath}" does not have a default export for an AppServerModule or a bootstrapping function.`);
22
+ const routes = [];
23
+ const { routes: extractRoutes } = await getRoutesFromAngularRouterConfig(bootstrapAppFnOrModule, document, new URL('http://localhost'));
24
+ for (const { route, redirectTo } of extractRoutes) {
25
+ if (redirectTo === undefined && !/[:*]/.test(route)) {
26
+ routes.push(route);
27
+ }
28
+ }
29
+ return routes;
30
+ }
31
+ /**
32
+ * Initializes the worker when it is first created by loading the Zone.js package
33
+ * into the worker instance.
34
+ *
35
+ * @returns A promise resolving to the extract function of the worker.
36
+ */
37
+ async function initialize() {
38
+ // Setup Zone.js
39
+ await Promise.resolve(`${zonePackage}`).then(s => tslib_1.__importStar(require(s)));
40
+ return extract;
41
+ }
42
+ /**
43
+ * The default export will be the promise returned by the initialize function.
44
+ * This is awaited by piscina prior to using the Worker.
45
+ */
46
+ exports.default = initialize();
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Piscina } from 'piscina';
9
+ export type WorkerPoolOptions = ConstructorParameters<typeof Piscina>[0];
10
+ export declare class WorkerPool extends Piscina {
11
+ constructor(options: WorkerPoolOptions);
12
+ }
13
+ //# sourceMappingURL=worker-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-pool.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/tools/worker-pool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE,qBAAa,UAAW,SAAQ,OAAO;gBACzB,OAAO,EAAE,iBAAiB;CAavC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.WorkerPool = void 0;
11
+ const piscina_1 = require("piscina");
12
+ class WorkerPool extends piscina_1.Piscina {
13
+ constructor(options) {
14
+ const piscinaOptions = {
15
+ minThreads: 1,
16
+ idleTimeout: 1000,
17
+ // Web containers do not support transferable objects with receiveOnMessagePort which
18
+ // is used when the Atomics based wait loop is enable.
19
+ useAtomics: !process.versions.webcontainer,
20
+ recordTiming: false,
21
+ ...options,
22
+ };
23
+ super(piscinaOptions);
24
+ }
25
+ }
26
+ exports.WorkerPool = WorkerPool;
@@ -0,0 +1,2 @@
1
+ export declare function addBodyScript(html: string, bodyScriptContents: string): Promise<string>;
2
+ //# sourceMappingURL=add-body-script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-body-script.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index-file/add-body-script.ts"],"names":[],"mappings":"AAEA,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,MAAM,CAAC,CAcjB"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addBodyScript = addBodyScript;
4
+ const html_rewriting_stream_1 = require("./html-rewriting-stream");
5
+ async function addBodyScript(html, bodyScriptContents) {
6
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
7
+ const bodyScript = `<script type="text/javascript">${bodyScriptContents}</script>`;
8
+ rewriter.on('startTag', (tag) => {
9
+ rewriter.emitStartTag(tag);
10
+ if (tag.tagName === 'body') {
11
+ rewriter.emitRaw(bodyScript);
12
+ }
13
+ });
14
+ return transformedContent();
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { IndexExpandedDefinition } from '../../models';
2
+ export declare function getIndexOutputFile(index: IndexExpandedDefinition): string;
3
+ //# sourceMappingURL=get-index-output-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-index-output-file.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index-file/get-index-output-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG5D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAMzE"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIndexOutputFile = getIndexOutputFile;
4
+ const node_path_1 = require("node:path");
5
+ function getIndexOutputFile(index) {
6
+ if (typeof index === 'string') {
7
+ return (0, node_path_1.basename)(index);
8
+ }
9
+ return index.output || 'index.html';
10
+ }
@@ -0,0 +1,2 @@
1
+ export declare const maxWorkers: () => number;
2
+ //# sourceMappingURL=max-workers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max-workers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/max-workers.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,UAAU,cAKtB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maxWorkers = void 0;
4
+ const node_os_1 = require("node:os");
5
+ const ENV_NG_BUILD_MAX_WORKERS = 'NG_BUILD_MAX_WORKERS';
6
+ function isPresent(variable) {
7
+ return typeof variable === 'string' && variable.trim() !== '';
8
+ }
9
+ function parseMaxWorkers(value) {
10
+ if (!isPresent(value))
11
+ return null;
12
+ const parsed = Number(value);
13
+ return Number.isNaN(parsed) || parsed <= 0 ? null : parsed; // Ensure valid positive number
14
+ }
15
+ const maxWorkers = () => {
16
+ const parsedWorkers = parseMaxWorkers(process.env[ENV_NG_BUILD_MAX_WORKERS]);
17
+ return parsedWorkers !== null
18
+ ? parsedWorkers
19
+ : Math.min(4, Math.max((0, node_os_1.availableParallelism)() - 1, 1));
20
+ };
21
+ exports.maxWorkers = maxWorkers;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import type { Plugin } from 'postcss';
9
+ export interface PostcssCliResourcesOptions {
10
+ baseHref?: string;
11
+ deployUrl?: string;
12
+ resourcesOutputPath?: string;
13
+ rebaseRootRelative?: boolean;
14
+ /** CSS is extracted to a `.css` or is embedded in a `.js` file. */
15
+ extracted?: boolean;
16
+ filename: (resourcePath: string) => string;
17
+ loader: import('@rspack/core').LoaderContext<unknown>;
18
+ emitFile: boolean;
19
+ }
20
+ export declare const postcss = true;
21
+ export default function (options?: PostcssCliResourcesOptions): Plugin;
22
+ //# sourceMappingURL=postcss-cli-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcss-cli-resources.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/postcss-cli-resources.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,SAAS,CAAC;AAgBnD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,MAAM,EAAE,OAAO,cAAc,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACtD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAcD,eAAO,MAAM,OAAO,OAAO,CAAC;AAE5B,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM,CAuKrE"}