@nx/angular-rspack-compiler 19.0.0-alpha.30

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/code-pushup.config.ts +13 -0
  4. package/dist/compilation/augments.d.ts +41 -0
  5. package/dist/compilation/augments.d.ts.map +1 -0
  6. package/dist/compilation/augments.js +100 -0
  7. package/dist/compilation/build-and-analyze.d.ts +4 -0
  8. package/dist/compilation/build-and-analyze.d.ts.map +1 -0
  9. package/dist/compilation/build-and-analyze.js +14 -0
  10. package/dist/compilation/index.d.ts +5 -0
  11. package/dist/compilation/index.d.ts.map +1 -0
  12. package/dist/compilation/index.js +7 -0
  13. package/dist/compilation/setup-compilation.d.ts +22 -0
  14. package/dist/compilation/setup-compilation.d.ts.map +1 -0
  15. package/dist/compilation/setup-compilation.js +88 -0
  16. package/dist/compilation/setup-with-paralell-compilation.d.ts +5 -0
  17. package/dist/compilation/setup-with-paralell-compilation.d.ts.map +1 -0
  18. package/dist/compilation/setup-with-paralell-compilation.js +29 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +6 -0
  22. package/dist/models/compiler-plugin-options.d.ts +15 -0
  23. package/dist/models/compiler-plugin-options.d.ts.map +1 -0
  24. package/dist/models/compiler-plugin-options.js +2 -0
  25. package/dist/models/file-replacement.d.ts +5 -0
  26. package/dist/models/file-replacement.d.ts.map +1 -0
  27. package/dist/models/file-replacement.js +2 -0
  28. package/dist/models/index.d.ts +35 -0
  29. package/dist/models/index.d.ts.map +1 -0
  30. package/dist/models/index.js +19 -0
  31. package/dist/models/inline-style-language.d.ts +2 -0
  32. package/dist/models/inline-style-language.d.ts.map +1 -0
  33. package/dist/models/inline-style-language.js +2 -0
  34. package/dist/models/style-preprocessor-options.d.ts +34 -0
  35. package/dist/models/style-preprocessor-options.d.ts.map +1 -0
  36. package/dist/models/style-preprocessor-options.js +2 -0
  37. package/dist/utils/component-resolvers.d.ts +39 -0
  38. package/dist/utils/component-resolvers.d.ts.map +1 -0
  39. package/dist/utils/component-resolvers.js +98 -0
  40. package/dist/utils/constants.d.ts +2 -0
  41. package/dist/utils/constants.d.ts.map +1 -0
  42. package/dist/utils/constants.js +4 -0
  43. package/dist/utils/index.d.ts +5 -0
  44. package/dist/utils/index.d.ts.map +1 -0
  45. package/dist/utils/index.js +9 -0
  46. package/dist/utils/load-compiler-cli.d.ts +2 -0
  47. package/dist/utils/load-compiler-cli.d.ts.map +1 -0
  48. package/dist/utils/load-compiler-cli.js +10 -0
  49. package/dist/utils/regex-filters.d.ts +5 -0
  50. package/dist/utils/regex-filters.d.ts.map +1 -0
  51. package/dist/utils/regex-filters.js +10 -0
  52. package/dist/utils/source-file-cache.d.ts +18 -0
  53. package/dist/utils/source-file-cache.d.ts.map +1 -0
  54. package/dist/utils/source-file-cache.js +40 -0
  55. package/dist/utils/targets-from-browsers.d.ts +9 -0
  56. package/dist/utils/targets-from-browsers.d.ts.map +1 -0
  57. package/dist/utils/targets-from-browsers.js +52 -0
  58. package/dist/utils/utils.d.ts +9 -0
  59. package/dist/utils/utils.d.ts.map +1 -0
  60. package/dist/utils/utils.js +43 -0
  61. package/eslint.next.config.js +22 -0
  62. package/package.json +67 -0
  63. package/patch/patch-angular-build.js +28 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Colum Ferry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ <div style="text-align: center;">
2
+
3
+ <img src="http://github.com/nrwl/angular-rspack/raw/main/rsbuild-plugin-angular.png" alt="Rsbuild Plugin Angular" />
4
+
5
+ </div>
6
+
7
+ # @nx/angular-rspack-compiler
8
+
9
+ ## Compilation Utilities for Angular with Rspack and Rsbuild
10
+
11
+ This library provides utilities for compiling Angular applications with Rspack and Rsbuild.
@@ -0,0 +1,13 @@
1
+ import { CoreConfig } from '@code-pushup/models';
2
+ import { mergeConfigs } from '@code-pushup/utils';
3
+ import {
4
+ baseConfig,
5
+ coverageCoreConfig,
6
+ eslintConfig,
7
+ } from '../../tools/reports/code-pushup.preset.config';
8
+
9
+ export default mergeConfigs(
10
+ baseConfig as CoreConfig,
11
+ await eslintConfig(),
12
+ await coverageCoreConfig()
13
+ );
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2022 Brandon Roberts
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ import * as ts from 'typescript';
26
+ import { InlineStyleLanguage } from '../models';
27
+ /**
28
+ *
29
+ * @param host
30
+ * @param transform
31
+ * @param options
32
+ */
33
+ export declare function augmentHostWithResources(host: ts.CompilerHost, transform: (code: string, id: string, options?: {
34
+ ssr?: boolean;
35
+ }) => string | null, options?: {} & {
36
+ inlineStylesExtension?: InlineStyleLanguage;
37
+ isProd?: boolean;
38
+ }): void;
39
+ export declare function augmentProgramWithVersioning(program: ts.Program): void;
40
+ export declare function augmentHostWithCaching(host: ts.CompilerHost, cache: Map<string, ts.SourceFile>): void;
41
+ //# sourceMappingURL=augments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augments.d.ts","sourceRoot":"","sources":["../../src/compilation/augments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,EAAE,CAAC,YAAY,EACrB,SAAS,EAAE,CACT,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,KACxB,MAAM,GAAG,IAAI,EAClB,OAAO,GAAE,EAAE,GAAG;IACZ,qBAAqB,CAAC,EAAE,mBAAmB,CAAC;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAC;CACb,QA+CP;AAGD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,IAAI,CActE;AAGD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,EAAE,CAAC,YAAY,EACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAChC,IAAI,CA4BN"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2022 Brandon Roberts
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.augmentHostWithResources = augmentHostWithResources;
28
+ exports.augmentProgramWithVersioning = augmentProgramWithVersioning;
29
+ exports.augmentHostWithCaching = augmentHostWithCaching;
30
+ const path_1 = require("path");
31
+ const node_crypto_1 = require("node:crypto");
32
+ /**
33
+ *
34
+ * @param host
35
+ * @param transform
36
+ * @param options
37
+ */
38
+ function augmentHostWithResources(host, transform, options = {}) {
39
+ const resourceHost = host;
40
+ resourceHost.readResource = async function (fileName) {
41
+ const filePath = (0, path_1.normalize)(fileName);
42
+ const content = this.readFile(filePath);
43
+ if (content === undefined) {
44
+ throw new Error('Unable to locate component resource: ' + fileName);
45
+ }
46
+ return content;
47
+ };
48
+ resourceHost.transformResource = async function (data, context) {
49
+ // Only style resources are supported currently
50
+ if (context.type !== 'style') {
51
+ return null;
52
+ }
53
+ if (options.inlineStylesExtension) {
54
+ // Resource file only exists for external stylesheets
55
+ const filename = context.resourceFile ??
56
+ `${context.containingFile.replace(/\.ts$/, () => {
57
+ return `.${options?.inlineStylesExtension}`;
58
+ })}`;
59
+ if (options.inlineStylesExtension === 'css') {
60
+ return { content: data || '' };
61
+ }
62
+ let stylesheetResult;
63
+ try {
64
+ stylesheetResult = transform(data, `${filename}?direct`);
65
+ }
66
+ catch (e) {
67
+ console.error(`${e}`);
68
+ }
69
+ return { content: stylesheetResult || '' };
70
+ }
71
+ return null;
72
+ };
73
+ }
74
+ // @TODO check if it is used or dead code
75
+ function augmentProgramWithVersioning(program) {
76
+ const baseGetSourceFiles = program.getSourceFiles;
77
+ program.getSourceFiles = function (...parameters) {
78
+ const files = baseGetSourceFiles(...parameters);
79
+ for (const file of files) {
80
+ if (file.version === undefined) {
81
+ file.version = (0, node_crypto_1.createHash)('sha256').update(file.text).digest('hex');
82
+ }
83
+ }
84
+ return files;
85
+ };
86
+ }
87
+ // @TODO check if it is used or dead code
88
+ function augmentHostWithCaching(host, cache) {
89
+ const baseGetSourceFile = host.getSourceFile;
90
+ host.getSourceFile = function (fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) {
91
+ if (!shouldCreateNewSourceFile && cache.has(fileName)) {
92
+ return cache.get(fileName);
93
+ }
94
+ const file = baseGetSourceFile.call(host, fileName, languageVersion, onError, true, ...parameters);
95
+ if (file) {
96
+ cache.set(fileName, file);
97
+ }
98
+ return file;
99
+ };
100
+ }
@@ -0,0 +1,4 @@
1
+ import { ParallelCompilation } from '@angular/build/src/tools/angular/compilation/parallel-compilation';
2
+ import { JavaScriptTransformer } from '@angular/build/src/tools/esbuild/javascript-transformer';
3
+ export declare function buildAndAnalyzeWithParallelCompilation(parallelCompilation: ParallelCompilation, typescriptFileCache: Map<string, string | Uint8Array>, javascriptTransformer: JavaScriptTransformer): Promise<void>;
4
+ //# sourceMappingURL=build-and-analyze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-and-analyze.d.ts","sourceRoot":"","sources":["../../src/compilation/build-and-analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,yDAAyD,CAAC;AAGhG,wBAAsB,sCAAsC,CAC1D,mBAAmB,EAAE,mBAAmB,EACxC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,EACrD,qBAAqB,EAAE,qBAAqB,iBAgB7C"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAndAnalyzeWithParallelCompilation = buildAndAnalyzeWithParallelCompilation;
4
+ const path_1 = require("path");
5
+ async function buildAndAnalyzeWithParallelCompilation(parallelCompilation, typescriptFileCache, javascriptTransformer) {
6
+ for (const { filename, contents, } of await parallelCompilation.emitAffectedFiles()) {
7
+ const normalizedFilename = (0, path_1.normalize)(filename.replace(/^[A-Z]:/, ''));
8
+ await javascriptTransformer
9
+ .transformData(normalizedFilename, contents, true, false)
10
+ .then((contents) => {
11
+ typescriptFileCache.set(normalizedFilename, Buffer.from(contents).toString());
12
+ });
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ export * from './augments';
2
+ export * from './build-and-analyze';
3
+ export * from './setup-compilation';
4
+ export * from './setup-with-paralell-compilation';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compilation/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./augments"), exports);
5
+ tslib_1.__exportStar(require("./build-and-analyze"), exports);
6
+ tslib_1.__exportStar(require("./setup-compilation"), exports);
7
+ tslib_1.__exportStar(require("./setup-with-paralell-compilation"), exports);
@@ -0,0 +1,22 @@
1
+ import { RsbuildConfig } from '@rsbuild/core';
2
+ import * as ts from 'typescript';
3
+ import { InlineStyleLanguage, FileReplacement } from '../models';
4
+ import { ComponentStylesheetBundler } from '@angular/build/src/tools/esbuild/angular/component-stylesheets';
5
+ export interface SetupCompilationOptions {
6
+ root: string;
7
+ tsConfig: string;
8
+ aot: boolean;
9
+ inlineStyleLanguage: InlineStyleLanguage;
10
+ fileReplacements: Array<FileReplacement>;
11
+ useTsProjectReferences?: boolean;
12
+ hasServer?: boolean;
13
+ }
14
+ export declare const DEFAULT_NG_COMPILER_OPTIONS: ts.CompilerOptions;
15
+ export declare function setupCompilation(config: Pick<RsbuildConfig, 'mode' | 'source'>, options: SetupCompilationOptions): Promise<{
16
+ rootNames: string[];
17
+ compilerOptions: import("@angular/compiler-cli").AngularCompilerOptions;
18
+ host: ts.CompilerHost;
19
+ componentStylesheetBundler: ComponentStylesheetBundler;
20
+ }>;
21
+ export declare function styleTransform(componentStylesheetBundler: ComponentStylesheetBundler): (styles: string, containingFile: string, stylesheetFile?: string) => Promise<any>;
22
+ //# sourceMappingURL=setup-compilation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-compilation.d.ts","sourceRoot":"","sources":["../../src/compilation/setup-compilation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAI5G,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACzC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAAC,eAc5C,CAAC;AAEF,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,CAAC,EAC9C,OAAO,EAAE,uBAAuB;;;;;GA0DjC;AAED,wBAAgB,cAAc,CAC5B,0BAA0B,EAAE,0BAA0B,YAG5C,MAAM,kBACE,MAAM,mBACL,MAAM,kBAwB1B"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_NG_COMPILER_OPTIONS = void 0;
4
+ exports.setupCompilation = setupCompilation;
5
+ exports.styleTransform = styleTransform;
6
+ const tslib_1 = require("tslib");
7
+ const ts = tslib_1.__importStar(require("typescript"));
8
+ const sass_embedded_1 = require("sass-embedded");
9
+ const augments_1 = require("./augments");
10
+ const utils_1 = require("../utils");
11
+ const component_stylesheets_1 = require("@angular/build/src/tools/esbuild/angular/component-stylesheets");
12
+ const targets_from_browsers_1 = require("../utils/targets-from-browsers");
13
+ const private_1 = require("@angular/build/private");
14
+ exports.DEFAULT_NG_COMPILER_OPTIONS = {
15
+ suppressOutputPathCheck: true,
16
+ outDir: undefined,
17
+ sourceMap: true,
18
+ declaration: false,
19
+ declarationMap: false,
20
+ allowEmptyCodegenFiles: false,
21
+ annotationsAs: 'decorators',
22
+ enableResourceInlining: false,
23
+ noEmitOnError: false,
24
+ mapRoot: undefined,
25
+ sourceRoot: undefined,
26
+ supportTestBed: false,
27
+ supportJitMode: false,
28
+ };
29
+ async function setupCompilation(config, options) {
30
+ const isProd = config.mode === 'production';
31
+ const { readConfiguration } = await (0, utils_1.loadCompilerCli)();
32
+ const { options: tsCompilerOptions, rootNames } = readConfiguration(config.source?.tsconfigPath ?? options.tsConfig, {
33
+ ...exports.DEFAULT_NG_COMPILER_OPTIONS,
34
+ ...(options.useTsProjectReferences
35
+ ? {
36
+ sourceMap: false,
37
+ inlineSources: false,
38
+ isolatedModules: true,
39
+ }
40
+ : {}),
41
+ });
42
+ const compilerOptions = tsCompilerOptions;
43
+ const host = ts.createIncrementalCompilerHost(compilerOptions);
44
+ const componentStylesheetBundler = new component_stylesheets_1.ComponentStylesheetBundler({
45
+ workspaceRoot: options.root,
46
+ optimization: config.mode === 'production',
47
+ cacheOptions: { path: '', basePath: '', enabled: false },
48
+ inlineFonts: false,
49
+ outputNames: {
50
+ bundles: config.mode === 'production' ? '[name]-[hash]' : '[name]',
51
+ media: `media/${config.mode === 'production' ? '[name]-[hash]' : '[name]'}`,
52
+ },
53
+ sourcemap: false,
54
+ target: (0, targets_from_browsers_1.transformSupportedBrowsersToTargets)((0, private_1.getSupportedBrowsers)(options.root, {
55
+ warn: (message) => console.warn(message),
56
+ })),
57
+ }, options.inlineStyleLanguage, false);
58
+ if (options.aot) {
59
+ (0, augments_1.augmentHostWithResources)(host, (code) => (0, sass_embedded_1.compileString)(code).css, {
60
+ inlineStylesExtension: options.inlineStyleLanguage,
61
+ isProd,
62
+ });
63
+ }
64
+ return {
65
+ rootNames,
66
+ compilerOptions,
67
+ host,
68
+ componentStylesheetBundler,
69
+ };
70
+ }
71
+ function styleTransform(componentStylesheetBundler) {
72
+ return async (styles, containingFile, stylesheetFile) => {
73
+ try {
74
+ let stylesheetResult;
75
+ if (stylesheetFile) {
76
+ stylesheetResult = await componentStylesheetBundler.bundleFile(stylesheetFile);
77
+ }
78
+ else {
79
+ stylesheetResult = await componentStylesheetBundler.bundleInline(styles, containingFile, containingFile.endsWith('.html') ? 'css' : undefined);
80
+ }
81
+ return stylesheetResult.contents;
82
+ }
83
+ catch (e) {
84
+ console.error('Failed to compile styles. Continuing execution ignoring failing stylesheet...', e);
85
+ return '';
86
+ }
87
+ };
88
+ }
@@ -0,0 +1,5 @@
1
+ import type { RsbuildConfig } from '@rsbuild/core';
2
+ import { ParallelCompilation } from '@angular/build/src/tools/angular/compilation/parallel-compilation';
3
+ import { SetupCompilationOptions } from './setup-compilation';
4
+ export declare function setupCompilationWithParallelCompilation(config: Pick<RsbuildConfig, 'source'>, options: SetupCompilationOptions): Promise<ParallelCompilation>;
5
+ //# sourceMappingURL=setup-with-paralell-compilation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-with-paralell-compilation.d.ts","sourceRoot":"","sources":["../../src/compilation/setup-with-paralell-compilation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AAExG,OAAO,EAGL,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,wBAAsB,uCAAuC,CAC3D,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,EACrC,OAAO,EAAE,uBAAuB,gCAgCjC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupCompilationWithParallelCompilation = setupCompilationWithParallelCompilation;
4
+ const parallel_compilation_1 = require("@angular/build/src/tools/angular/compilation/parallel-compilation");
5
+ const core_1 = require("@swc/core");
6
+ const setup_compilation_1 = require("./setup-compilation");
7
+ async function setupCompilationWithParallelCompilation(config, options) {
8
+ const { rootNames, compilerOptions, componentStylesheetBundler } = await (0, setup_compilation_1.setupCompilation)(config, options);
9
+ const parallelCompilation = new parallel_compilation_1.ParallelCompilation(!options.aot, options.hasServer === false);
10
+ const fileReplacements = options.fileReplacements.reduce((r, f) => {
11
+ r[f.replace] = f.with;
12
+ return r;
13
+ }, {});
14
+ try {
15
+ await parallelCompilation.initialize(config.source?.tsconfigPath ?? options.tsConfig, {
16
+ ...compilerOptions,
17
+ fileReplacements,
18
+ modifiedFiles: new Set(rootNames),
19
+ transformStylesheet: (0, setup_compilation_1.styleTransform)(componentStylesheetBundler),
20
+ processWebWorker(workerFile) {
21
+ return (0, core_1.transformFileSync)(workerFile).code;
22
+ },
23
+ }, () => compilerOptions);
24
+ }
25
+ catch (e) {
26
+ console.error('Failed to initialize Angular Compilation', e);
27
+ }
28
+ return parallelCompilation;
29
+ }
@@ -0,0 +1,4 @@
1
+ export * from './compilation';
2
+ export * from './models';
3
+ export * from './utils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./compilation"), exports);
5
+ tslib_1.__exportStar(require("./models"), exports);
6
+ tslib_1.__exportStar(require("./utils"), exports);
@@ -0,0 +1,15 @@
1
+ import { SourceFileCache } from '../utils/source-file-cache';
2
+ export interface CompilerPluginOptions {
3
+ sourcemap: boolean;
4
+ tsconfig: string;
5
+ aot?: boolean;
6
+ /** Skip TypeScript compilation setup. This is useful to re-use the TypeScript compilation from another plugin. */
7
+ noopTypeScriptCompilation?: boolean;
8
+ advancedOptimizations?: boolean;
9
+ thirdPartySourcemaps?: boolean;
10
+ fileReplacements?: Record<string, string>;
11
+ sourceFileCache?: SourceFileCache;
12
+ incremental: boolean;
13
+ useTsProjectReferences?: boolean;
14
+ }
15
+ //# sourceMappingURL=compiler-plugin-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler-plugin-options.d.ts","sourceRoot":"","sources":["../../src/models/compiler-plugin-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,kHAAkH;IAClH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface FileReplacement {
2
+ replace: string;
3
+ with: string;
4
+ }
5
+ //# sourceMappingURL=file-replacement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-replacement.d.ts","sourceRoot":"","sources":["../../src/models/file-replacement.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ import { JavaScriptTransformer } from '@angular/build/src/tools/esbuild/javascript-transformer';
2
+ import { ParallelCompilation } from '@angular/build/src/tools/angular/compilation/parallel-compilation';
3
+ export { ParallelCompilation, JavaScriptTransformer };
4
+ export * from './inline-style-language';
5
+ export * from './file-replacement';
6
+ export * from './style-preprocessor-options';
7
+ export declare enum DiagnosticModes {
8
+ None = 0,
9
+ Option = 1,
10
+ Syntactic = 2,
11
+ Semantic = 4,
12
+ All = 7
13
+ }
14
+ export interface Location {
15
+ file: string;
16
+ namespace: string;
17
+ line: number;
18
+ column: number;
19
+ length: number;
20
+ lineText: string;
21
+ suggestion: string;
22
+ }
23
+ export interface PartialNote {
24
+ text?: string;
25
+ location?: Partial<Location> | null;
26
+ }
27
+ export interface PartialMessage {
28
+ id?: string;
29
+ pluginName?: string;
30
+ text?: string;
31
+ location?: Partial<Location> | null;
32
+ notes?: PartialNote[];
33
+ detail?: never;
34
+ }
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yDAAyD,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAC;AAEtD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAE7C,oBAAY,eAAe;IACzB,IAAI,IAAI;IACR,MAAM,IAAS;IACf,SAAS,IAAS;IAClB,QAAQ,IAAS;IACjB,GAAG,IAAgC;CACpC;AACD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;CACrC;AACD,MAAM,WAAW,cAAc;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiagnosticModes = exports.JavaScriptTransformer = exports.ParallelCompilation = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const javascript_transformer_1 = require("@angular/build/src/tools/esbuild/javascript-transformer");
6
+ Object.defineProperty(exports, "JavaScriptTransformer", { enumerable: true, get: function () { return javascript_transformer_1.JavaScriptTransformer; } });
7
+ const parallel_compilation_1 = require("@angular/build/src/tools/angular/compilation/parallel-compilation");
8
+ Object.defineProperty(exports, "ParallelCompilation", { enumerable: true, get: function () { return parallel_compilation_1.ParallelCompilation; } });
9
+ tslib_1.__exportStar(require("./inline-style-language"), exports);
10
+ tslib_1.__exportStar(require("./file-replacement"), exports);
11
+ tslib_1.__exportStar(require("./style-preprocessor-options"), exports);
12
+ var DiagnosticModes;
13
+ (function (DiagnosticModes) {
14
+ DiagnosticModes[DiagnosticModes["None"] = 0] = "None";
15
+ DiagnosticModes[DiagnosticModes["Option"] = 1] = "Option";
16
+ DiagnosticModes[DiagnosticModes["Syntactic"] = 2] = "Syntactic";
17
+ DiagnosticModes[DiagnosticModes["Semantic"] = 4] = "Semantic";
18
+ DiagnosticModes[DiagnosticModes["All"] = 7] = "All";
19
+ })(DiagnosticModes || (exports.DiagnosticModes = DiagnosticModes = {}));
@@ -0,0 +1,2 @@
1
+ export type InlineStyleLanguage = 'css' | 'scss' | 'sass' | 'less';
2
+ //# sourceMappingURL=inline-style-language.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-style-language.d.ts","sourceRoot":"","sources":["../../src/models/inline-style-language.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ import { DeprecationOrId } from 'sass-embedded';
2
+ export interface StylePreprocessorOptions {
3
+ /**
4
+ * Paths to include. Paths will be resolved to workspace root.
5
+ */
6
+ includePaths?: string[];
7
+ /**
8
+ * Options to pass to the sass preprocessor.
9
+ */
10
+ sass?: Sass;
11
+ }
12
+ /**
13
+ * Options to pass to the sass preprocessor.
14
+ */
15
+ export interface Sass {
16
+ /**
17
+ * A set of deprecations to treat as fatal. If a deprecation warning of any provided type is
18
+ * encountered during compilation, the compiler will error instead. If a Version is
19
+ * provided, then all deprecations that were active in that compiler version will be treated
20
+ * as fatal.
21
+ */
22
+ fatalDeprecations?: DeprecationOrId[];
23
+ /**
24
+ * A set of future deprecations to opt into early. Future deprecations passed here will be
25
+ * treated as active by the compiler, emitting warnings as necessary.
26
+ */
27
+ futureDeprecations?: DeprecationOrId[];
28
+ /**
29
+ * A set of active deprecations to ignore. If a deprecation warning of any provided type is
30
+ * encountered during compilation, the compiler will ignore it instead.
31
+ */
32
+ silenceDeprecations?: DeprecationOrId[];
33
+ }
34
+ //# sourceMappingURL=style-preprocessor-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style-preprocessor-options.d.ts","sourceRoot":"","sources":["../../src/models/style-preprocessor-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC;IACtC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;IACvC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,eAAe,EAAE,CAAC;CACzC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @license
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2022 Brandon Roberts
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ export declare class StyleUrlsResolver {
26
+ private readonly styleUrlsCache;
27
+ resolve(code: string, id: string): string[];
28
+ }
29
+ export declare function getStyleUrls(code: string): (string | undefined)[];
30
+ export declare function getTemplateUrls(code: string): string[];
31
+ export interface TemplateUrlsCacheEntry {
32
+ code: string;
33
+ templateUrlPaths: string[];
34
+ }
35
+ export declare class TemplateUrlsResolver {
36
+ private readonly templateUrlsCache;
37
+ resolve(code: string, id: string): string[];
38
+ }
39
+ //# sourceMappingURL=component-resolvers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-resolvers.d.ts","sourceRoot":"","sources":["../../src/utils/component-resolvers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAYH,qBAAa,iBAAiB;IAK5B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0C;IAEzE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CA8B5C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,0BASxC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,YAO3C;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAG9B;IAEJ,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CAc5C"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2022 Brandon Roberts
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.TemplateUrlsResolver = exports.StyleUrlsResolver = void 0;
28
+ exports.getStyleUrls = getStyleUrls;
29
+ exports.getTemplateUrls = getTemplateUrls;
30
+ const node_path_1 = require("node:path");
31
+ const ts_morph_1 = require("ts-morph");
32
+ const path_1 = require("path");
33
+ const utils_1 = require("./utils");
34
+ class StyleUrlsResolver {
35
+ constructor() {
36
+ // These resolvers may be called multiple times during the same
37
+ // compilation for the same files. Caching is required because these
38
+ // resolvers use synchronous system calls to the filesystem, which can
39
+ // degrade performance when running compilations for multiple files.
40
+ this.styleUrlsCache = new Map();
41
+ }
42
+ resolve(code, id) {
43
+ // Given the code is the following:
44
+ // @Component({
45
+ // styleUrls: [
46
+ // './app.component.scss'
47
+ // ]
48
+ // })
49
+ // The `matchedStyleUrls` would result in: `styleUrls: [\n './app.component.scss'\n ]`.
50
+ const matchedStyleUrls = getStyleUrls(code)
51
+ // for type narrowing
52
+ .filter((v) => v !== undefined);
53
+ const entry = this.styleUrlsCache.get(id);
54
+ // We're using `matchedStyleUrls` as a key because the code may be changing continuously,
55
+ // resulting in the resolver being called multiple times. While the code changes, the
56
+ // `styleUrls` may remain constant, which means we should always return the previously
57
+ // resolved style URLs.
58
+ if (entry &&
59
+ entry.matchedStyleUrls.join(',') === matchedStyleUrls.join(',')) {
60
+ return entry.styleUrls;
61
+ }
62
+ const styleUrls = matchedStyleUrls.map((styleUrlPath) => {
63
+ return `${styleUrlPath}|${(0, path_1.normalize)((0, node_path_1.resolve)((0, node_path_1.dirname)(id), styleUrlPath))}`;
64
+ });
65
+ this.styleUrlsCache.set(id, { styleUrls, matchedStyleUrls });
66
+ return styleUrls;
67
+ }
68
+ }
69
+ exports.StyleUrlsResolver = StyleUrlsResolver;
70
+ function getStyleUrls(code) {
71
+ const project = new ts_morph_1.Project({ useInMemoryFileSystem: true });
72
+ const sourceFile = project.createSourceFile('cmp.ts', code);
73
+ const properties = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
74
+ const styleUrl = (0, utils_1.getTextByProperty)('styleUrl', properties);
75
+ const styleUrls = (0, utils_1.getAllTextByProperty)('styleUrls', properties);
76
+ return [...styleUrls, ...styleUrl];
77
+ }
78
+ function getTemplateUrls(code) {
79
+ const project = new ts_morph_1.Project({ useInMemoryFileSystem: true });
80
+ const sourceFile = project.createSourceFile('cmp.ts', code);
81
+ const properties = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment);
82
+ return (0, utils_1.getTextByProperty)('templateUrl', properties);
83
+ }
84
+ class TemplateUrlsResolver {
85
+ constructor() {
86
+ this.templateUrlsCache = new Map();
87
+ }
88
+ resolve(code, id) {
89
+ const entry = this.templateUrlsCache.get(id);
90
+ if (entry?.code === code) {
91
+ return entry.templateUrlPaths;
92
+ }
93
+ const templateUrlPaths = getTemplateUrls(code).map((url) => `${url}|${(0, path_1.normalize)((0, node_path_1.resolve)((0, node_path_1.dirname)(id), url).replace(/\\/g, '/'))}`);
94
+ this.templateUrlsCache.set(id, { code, templateUrlPaths });
95
+ return templateUrlPaths;
96
+ }
97
+ }
98
+ exports.TemplateUrlsResolver = TemplateUrlsResolver;
@@ -0,0 +1,2 @@
1
+ export declare const ENV_NG_BUILD_MAX_WORKERS = "NG_BUILD_MAX_WORKERS";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,yBAAyB,CAAC"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENV_NG_BUILD_MAX_WORKERS = void 0;
4
+ exports.ENV_NG_BUILD_MAX_WORKERS = 'NG_BUILD_MAX_WORKERS';
@@ -0,0 +1,5 @@
1
+ export * from './regex-filters';
2
+ export * from './component-resolvers';
3
+ export * from './load-compiler-cli';
4
+ export { maxWorkers } from './utils';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maxWorkers = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./regex-filters"), exports);
6
+ tslib_1.__exportStar(require("./component-resolvers"), exports);
7
+ tslib_1.__exportStar(require("./load-compiler-cli"), exports);
8
+ var utils_1 = require("./utils");
9
+ Object.defineProperty(exports, "maxWorkers", { enumerable: true, get: function () { return utils_1.maxWorkers; } });
@@ -0,0 +1,2 @@
1
+ export declare function loadCompilerCli(): Promise<typeof import('@angular/compiler-cli')>;
2
+ //# sourceMappingURL=load-compiler-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-compiler-cli.d.ts","sourceRoot":"","sources":["../../src/utils/load-compiler-cli.ts"],"names":[],"mappings":"AACA,wBAAgB,eAAe,IAAI,OAAO,CACxC,cAAc,uBAAuB,CAAC,CACvC,CAOA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadCompilerCli = loadCompilerCli;
4
+ let load;
5
+ function loadCompilerCli() {
6
+ load ?? (load = new Function('', `return import('@angular/compiler-cli');`));
7
+ return load().catch((e) => {
8
+ throw new Error(`Failed to load Angular Compiler CLI: ${e.message ?? e.toString()}`);
9
+ });
10
+ }
@@ -0,0 +1,5 @@
1
+ export declare const TS_ALL_EXT_REGEX: RegExp;
2
+ export declare const JS_ALL_EXT_REGEX: RegExp;
3
+ export declare const JS_EXT_REGEX: RegExp;
4
+ export declare function isStandardJsFile(filename: string): boolean;
5
+ //# sourceMappingURL=regex-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex-filters.d.ts","sourceRoot":"","sources":["../../src/utils/regex-filters.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAAwB,CAAC;AACtD,eAAO,MAAM,gBAAgB,QAAwB,CAAC;AACtD,eAAO,MAAM,YAAY,QAAe,CAAC;AAEzC,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,WAEhD"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JS_EXT_REGEX = exports.JS_ALL_EXT_REGEX = exports.TS_ALL_EXT_REGEX = void 0;
4
+ exports.isStandardJsFile = isStandardJsFile;
5
+ exports.TS_ALL_EXT_REGEX = /\.[cm]?(ts)[^x]?\??/;
6
+ exports.JS_ALL_EXT_REGEX = /\.[cm]?(js)[^x]?\??/;
7
+ exports.JS_EXT_REGEX = /\.[cm]?js$/;
8
+ function isStandardJsFile(filename) {
9
+ return exports.JS_EXT_REGEX.test(filename);
10
+ }
@@ -0,0 +1,18 @@
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.io/license
7
+ */
8
+ import type ts from 'typescript';
9
+ export declare class SourceFileCache extends Map<string, ts.SourceFile> {
10
+ readonly persistentCachePath?: string | undefined;
11
+ readonly modifiedFiles: Set<string>;
12
+ readonly babelFileCache: Map<string, Uint8Array>;
13
+ readonly typeScriptFileCache: Map<string, string | Uint8Array>;
14
+ referencedFiles?: readonly string[];
15
+ constructor(persistentCachePath?: string | undefined);
16
+ invalidate(files: Iterable<string>): void;
17
+ }
18
+ //# sourceMappingURL=source-file-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-file-cache.d.ts","sourceRoot":"","sources":["../../src/utils/source-file-cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAKjC,qBAAa,eAAgB,SAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC;IAOjD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM;IANjD,QAAQ,CAAC,aAAa,cAAqB;IAC3C,QAAQ,CAAC,cAAc,0BAAiC;IACxD,QAAQ,CAAC,mBAAmB,mCAA0C;IAEtE,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;gBAEf,mBAAmB,CAAC,EAAE,MAAM,YAAA;IAIjD,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;CAiB1C"}
@@ -0,0 +1,40 @@
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.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SourceFileCache = void 0;
11
+ const tslib_1 = require("tslib");
12
+ const path = tslib_1.__importStar(require("node:path"));
13
+ const node_url_1 = require("node:url");
14
+ const utils_1 = require("./utils");
15
+ const WINDOWS_SEP_REGEXP = new RegExp(`\\${path.win32.sep}`, 'g');
16
+ class SourceFileCache extends Map {
17
+ constructor(persistentCachePath) {
18
+ super();
19
+ this.persistentCachePath = persistentCachePath;
20
+ this.modifiedFiles = new Set();
21
+ this.babelFileCache = new Map();
22
+ this.typeScriptFileCache = new Map();
23
+ }
24
+ invalidate(files) {
25
+ if (files !== this.modifiedFiles) {
26
+ this.modifiedFiles.clear();
27
+ }
28
+ for (let file of files) {
29
+ this.babelFileCache.delete(file);
30
+ this.typeScriptFileCache.delete((0, node_url_1.pathToFileURL)(file).href);
31
+ // Normalize separators to allow matching TypeScript Host paths
32
+ if ((0, utils_1.isUsingWindows)()) {
33
+ file = file.replace(WINDOWS_SEP_REGEXP, path.posix.sep);
34
+ }
35
+ this.delete(file);
36
+ this.modifiedFiles.add(file);
37
+ }
38
+ }
39
+ }
40
+ exports.SourceFileCache = SourceFileCache;
@@ -0,0 +1,9 @@
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 declare function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[];
9
+ //# sourceMappingURL=targets-from-browsers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"targets-from-browsers.d.ts","sourceRoot":"","sources":["../../src/utils/targets-from-browsers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,mCAAmC,CACjD,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,EAAE,CA+CV"}
@@ -0,0 +1,52 @@
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.transformSupportedBrowsersToTargets = transformSupportedBrowsersToTargets;
11
+ function transformSupportedBrowsersToTargets(supportedBrowsers) {
12
+ const transformed = [];
13
+ // https://esbuild.github.io/api/#target
14
+ const esBuildSupportedBrowsers = new Set([
15
+ 'chrome',
16
+ 'edge',
17
+ 'firefox',
18
+ 'ie',
19
+ 'ios',
20
+ 'node',
21
+ 'opera',
22
+ 'safari',
23
+ ]);
24
+ for (const browser of supportedBrowsers) {
25
+ let [browserName, version] = browser.toLowerCase().split(' ');
26
+ if (version == null) {
27
+ throw new Error(`Invalid browser version in: ${browser}`);
28
+ }
29
+ // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
30
+ if (browserName === 'ios_saf') {
31
+ browserName = 'ios';
32
+ }
33
+ // browserslist uses ranges `15.2-15.3` versions but only the lowest is required
34
+ // to perform minimum supported feature checks. esbuild also expects a single version.
35
+ [version] = version.split('-');
36
+ if (esBuildSupportedBrowsers.has(browserName)) {
37
+ if (browserName === 'safari' && version === 'tp') {
38
+ // esbuild only supports numeric versions so `TP` is converted to a high number (999) since
39
+ // a Technology Preview (TP) of Safari is assumed to support all currently known features.
40
+ version = '999';
41
+ }
42
+ else if (!version.includes('.')) {
43
+ // A lone major version is considered by esbuild to include all minor versions. However,
44
+ // browserslist does not and is also inconsistent in its `.0` version naming. For example,
45
+ // Safari 15.0 is named `safari 15` but Safari 16.0 is named `safari 16.0`.
46
+ version += '.0';
47
+ }
48
+ transformed.push(browserName + version);
49
+ }
50
+ }
51
+ return transformed;
52
+ }
@@ -0,0 +1,9 @@
1
+ import { PropertyAssignment } from 'ts-morph';
2
+ export declare const isUsingWindows: () => boolean;
3
+ export declare function getTextByProperty(name: string, properties: PropertyAssignment[]): string[];
4
+ export declare function getAllTextByProperty(name: string, properties: PropertyAssignment[]): (string | undefined)[];
5
+ export declare function normalizeQuotes(str?: string): string | undefined;
6
+ export declare function isPresent(variable: string | undefined): variable is string;
7
+ export declare function parseMaxWorkers(value: string | undefined): number | null;
8
+ export declare const maxWorkers: () => number;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGtE,eAAO,MAAM,cAAc,eAA+B,CAAC;AAE3D,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,kBAAkB,EAAE,YAMjC;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,kBAAkB,EAAE,0BAQjC;AAED,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,sBAE3C;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,IAAI,MAAM,CAE1E;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIxE;AAED,eAAO,MAAM,UAAU,cAKtB,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maxWorkers = exports.isUsingWindows = void 0;
4
+ exports.getTextByProperty = getTextByProperty;
5
+ exports.getAllTextByProperty = getAllTextByProperty;
6
+ exports.normalizeQuotes = normalizeQuotes;
7
+ exports.isPresent = isPresent;
8
+ exports.parseMaxWorkers = parseMaxWorkers;
9
+ const node_os_1 = require("node:os");
10
+ const constants_1 = require("./constants");
11
+ const isUsingWindows = () => (0, node_os_1.platform)() === 'win32';
12
+ exports.isUsingWindows = isUsingWindows;
13
+ function getTextByProperty(name, properties) {
14
+ return properties
15
+ .filter((property) => property.getName() === name)
16
+ .map((property) => normalizeQuotes(property.getInitializer()?.getText()))
17
+ .filter((url) => url !== undefined);
18
+ }
19
+ function getAllTextByProperty(name, properties) {
20
+ return properties
21
+ .filter((property) => property.getName() === name)
22
+ .map((property) => property.getInitializer())
23
+ .flatMap((array) => array.getElements().map((el) => normalizeQuotes(el.getText())));
24
+ }
25
+ function normalizeQuotes(str) {
26
+ return str ? str.replace(/['"`]/g, '') : str;
27
+ }
28
+ function isPresent(variable) {
29
+ return typeof variable === 'string' && variable.trim() !== '';
30
+ }
31
+ function parseMaxWorkers(value) {
32
+ if (!isPresent(value))
33
+ return null;
34
+ const parsed = Number(value);
35
+ return Number.isNaN(parsed) || parsed <= 0 ? null : parsed; // Ensure valid positive number
36
+ }
37
+ const maxWorkers = () => {
38
+ const parsedWorkers = parseMaxWorkers(process.env[constants_1.ENV_NG_BUILD_MAX_WORKERS]);
39
+ return parsedWorkers !== null
40
+ ? parsedWorkers
41
+ : Math.min(4, Math.max((0, node_os_1.availableParallelism)() - 1, 1));
42
+ };
43
+ exports.maxWorkers = maxWorkers;
@@ -0,0 +1,22 @@
1
+ const baseConfig = require('../../eslint.config.js');
2
+
3
+ module.exports = [
4
+ ...baseConfig,
5
+ {
6
+ files: ['**/*.json'],
7
+ rules: {
8
+ '@nx/dependency-checks': [
9
+ 'error',
10
+ {
11
+ ignoredFiles: [
12
+ '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
+ '{projectRoot}/vite.config.{js,ts,mjs,mts}',
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ languageOptions: {
19
+ parser: require('jsonc-eslint-parser'),
20
+ },
21
+ },
22
+ ];
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@nx/angular-rspack-compiler",
3
+ "private": false,
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Compilation utilities for Angular with Rspack and Rsbuild.",
8
+ "author": "Colum Ferry",
9
+ "license": "MIT",
10
+ "bugs": {
11
+ "url": "https://github.com/nrwl/angular-rspack/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/nrwl/angular-rspack.git",
16
+ "directory": "packages/angular-rspack-compiler"
17
+ },
18
+ "keywords": [
19
+ "angular",
20
+ "rspack",
21
+ "rsbuild",
22
+ "compiler"
23
+ ],
24
+ "version": "19.0.0-alpha.30",
25
+ "type": "commonjs",
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "typings": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
34
+ },
35
+ "dependencies": {
36
+ "sass-embedded": "^1.79.3",
37
+ "ts-morph": "^24.0.0",
38
+ "tslib": "^2.3.0",
39
+ "typescript": "5.6.3"
40
+ },
41
+ "devDependencies": {
42
+ "@ng-rspack/testing-setup": "0.0.1"
43
+ },
44
+ "peerDependencies": {
45
+ "@angular/compiler-cli": ">=18.0.0 <20.0.0",
46
+ "@rsbuild/core": ">=1.0.5 <2.0.0",
47
+ "@angular/build": ">=18.0.0 <20.0.0",
48
+ "@swc/core": ">=1.5.0 <1.11.0"
49
+ },
50
+ "nx": {
51
+ "sourceRoot": "packages/angular-rspack-compiler/src",
52
+ "projectType": "library",
53
+ "name": "angular-rspack-compiler",
54
+ "targets": {
55
+ "code-pushup": {},
56
+ "integration-test": {
57
+ "configName": "vitest.integration.config.mts"
58
+ },
59
+ "unit-test": {
60
+ "configName": "vitest.unit.config.mts"
61
+ }
62
+ }
63
+ },
64
+ "scripts": {
65
+ "postinstall": "node ./patch/patch-angular-build.js"
66
+ }
67
+ }
@@ -0,0 +1,28 @@
1
+ const { readFileSync, writeFileSync } = require('fs');
2
+
3
+ function main() {
4
+ const angularBuildPackageJson = require.resolve(
5
+ '@angular/build/package.json'
6
+ );
7
+ const fileContentsJson = JSON.parse(
8
+ readFileSync(angularBuildPackageJson, 'utf8')
9
+ );
10
+ fileContentsJson.exports['./src/tools/esbuild/javascript-transformer'] =
11
+ './src/tools/esbuild/javascript-transformer.js';
12
+ fileContentsJson.exports[
13
+ './src/tools/esbuild/angular/file-reference-tracker'
14
+ ] = './src/tools/esbuild/angular/file-reference-tracker.js';
15
+ fileContentsJson.exports[
16
+ './src/tools/angular/compilation/parallel-compilation'
17
+ ] = './src/tools/angular/compilation/parallel-compilation.js';
18
+ fileContentsJson.exports[
19
+ './src/tools/esbuild/angular/component-stylesheets'
20
+ ] = './src/tools/esbuild/angular/component-stylesheets.js';
21
+
22
+ writeFileSync(
23
+ angularBuildPackageJson,
24
+ JSON.stringify(fileContentsJson, null, 2)
25
+ );
26
+ }
27
+
28
+ main();