@nx/angular-rspack 20.7.0 → 20.8.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 (65) hide show
  1. package/dist/lib/config/create-config.d.ts +75 -2
  2. package/dist/lib/config/create-config.d.ts.map +1 -1
  3. package/dist/lib/config/create-config.js +166 -138
  4. package/dist/lib/config/dev-server-config-utils.d.ts.map +1 -1
  5. package/dist/lib/config/dev-server-config-utils.js +3 -7
  6. package/dist/lib/config/entry-points.d.ts +9 -0
  7. package/dist/lib/config/entry-points.d.ts.map +1 -0
  8. package/dist/lib/config/entry-points.js +36 -0
  9. package/dist/lib/config/i18n/create-i18n-options.d.ts +1 -1
  10. package/dist/lib/config/i18n/create-i18n-options.d.ts.map +1 -1
  11. package/dist/lib/config/i18n/create-i18n-options.js +8 -6
  12. package/dist/lib/config/style-config-utils.d.ts +12 -306
  13. package/dist/lib/config/style-config-utils.d.ts.map +1 -1
  14. package/dist/lib/config/style-config-utils.js +180 -93
  15. package/dist/lib/models/angular-rspack-plugin-options.d.ts +39 -1
  16. package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -1
  17. package/dist/lib/models/normalize-options.d.ts +2 -2
  18. package/dist/lib/models/normalize-options.d.ts.map +1 -1
  19. package/dist/lib/models/normalize-options.js +68 -119
  20. package/dist/lib/models/unsupported-options.d.ts +0 -6
  21. package/dist/lib/models/unsupported-options.d.ts.map +1 -1
  22. package/dist/lib/models/unsupported-options.js +0 -6
  23. package/dist/lib/plugins/angular-rspack-plugin.d.ts +2 -2
  24. package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -1
  25. package/dist/lib/plugins/angular-rspack-plugin.js +33 -26
  26. package/dist/lib/plugins/i18n-inline-plugin.d.ts +2 -2
  27. package/dist/lib/plugins/i18n-inline-plugin.d.ts.map +1 -1
  28. package/dist/lib/plugins/i18n-inline-plugin.js +24 -58
  29. package/dist/lib/plugins/index-html-plugin.d.ts +21 -0
  30. package/dist/lib/plugins/index-html-plugin.d.ts.map +1 -0
  31. package/dist/lib/plugins/index-html-plugin.js +114 -0
  32. package/dist/lib/plugins/ng-rspack.d.ts +8 -4
  33. package/dist/lib/plugins/ng-rspack.d.ts.map +1 -1
  34. package/dist/lib/plugins/ng-rspack.js +41 -39
  35. package/dist/lib/utils/find-project-for-path.d.ts +1 -1
  36. package/dist/lib/utils/find-project-for-path.d.ts.map +1 -1
  37. package/dist/lib/utils/find-project-for-path.js +2 -4
  38. package/dist/lib/utils/get-locale-base-href.d.ts +3 -0
  39. package/dist/lib/utils/get-locale-base-href.d.ts.map +1 -0
  40. package/dist/lib/utils/get-locale-base-href.js +17 -0
  41. package/dist/lib/utils/graph.d.ts +3 -0
  42. package/dist/lib/utils/graph.d.ts.map +1 -0
  43. package/dist/lib/utils/graph.js +25 -0
  44. package/dist/lib/utils/i18n.d.ts +4 -0
  45. package/dist/lib/utils/i18n.d.ts.map +1 -0
  46. package/dist/lib/utils/i18n.js +25 -0
  47. package/dist/lib/utils/index-file/add-event-dispatch-contract.d.ts +9 -0
  48. package/dist/lib/utils/index-file/add-event-dispatch-contract.d.ts.map +1 -0
  49. package/dist/lib/utils/index-file/add-event-dispatch-contract.js +27 -0
  50. package/dist/lib/utils/index-file/html-rewriting-stream.d.ts +16 -0
  51. package/dist/lib/utils/index-file/html-rewriting-stream.d.ts.map +1 -0
  52. package/dist/lib/utils/index-file/html-rewriting-stream.js +27 -0
  53. package/dist/lib/utils/misc-helpers.d.ts +6 -0
  54. package/dist/lib/utils/misc-helpers.d.ts.map +1 -0
  55. package/dist/lib/utils/misc-helpers.js +30 -0
  56. package/dist/lib/utils/rspack-diagnostics.d.ts +4 -0
  57. package/dist/lib/utils/rspack-diagnostics.d.ts.map +1 -0
  58. package/dist/lib/utils/rspack-diagnostics.js +10 -0
  59. package/dist/lib/utils/tailwind.d.ts +2 -0
  60. package/dist/lib/utils/tailwind.d.ts.map +1 -0
  61. package/dist/lib/utils/tailwind.js +31 -0
  62. package/dist/lib/utils/url-join.d.ts +9 -0
  63. package/dist/lib/utils/url-join.d.ts.map +1 -0
  64. package/dist/lib/utils/url-join.js +17 -0
  65. package/package.json +23 -6
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.I18nInlinePlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const core_1 = require("@rspack/core");
6
- const core_2 = require("@babel/core");
7
5
  const remapping_1 = tslib_1.__importDefault(require("@ampproject/remapping"));
6
+ const core_1 = require("@babel/core");
7
+ const core_2 = require("@rspack/core");
8
8
  const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
9
+ const i18n_1 = require("../utils/i18n");
10
+ const misc_helpers_1 = require("../utils/misc-helpers");
9
11
  const PLUGIN_NAME = 'I18nInlinePlugin';
10
12
  class I18nInlinePlugin {
11
13
  #pluginOptions;
@@ -15,9 +17,11 @@ class I18nInlinePlugin {
15
17
  * This is used to remove the need to repeatedly import the module per file translation.
16
18
  */
17
19
  #localizeToolsModule;
20
+ #outputPaths;
18
21
  constructor(pluginOptions, i18nOptions) {
19
22
  this.#pluginOptions = pluginOptions;
20
23
  this.#i18n = i18nOptions;
24
+ this.#outputPaths = new Set((0, i18n_1.getLocaleOutputPaths)(i18nOptions).values());
21
25
  }
22
26
  apply(compiler) {
23
27
  compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
@@ -41,11 +45,17 @@ class I18nInlinePlugin {
41
45
  const locale = this.#i18n.locales[localeKey];
42
46
  const localeFiles = new Map();
43
47
  for (const [filename, { text, map }] of filesToInline.entries()) {
48
+ if (this.#checkAssetHasBeenProcessed(filename)) {
49
+ continue;
50
+ }
44
51
  const result = await this.#transformWithBabel(text, map, filename, localeKey, locale.translation, this.#pluginOptions.advancedOptimizations);
45
52
  localeFiles.set(filename, { text: result.code, map: result.map });
46
53
  // TODO: Add support for diagnostics
47
54
  }
48
55
  for (const [filename, source] of additionalFiles.entries()) {
56
+ if (this.#checkAssetHasBeenProcessed(filename)) {
57
+ continue;
58
+ }
49
59
  localeFiles.set(filename, {
50
60
  text: source.source(),
51
61
  map: source.map(),
@@ -56,20 +66,10 @@ class I18nInlinePlugin {
56
66
  for (const [localeSubPath, files] of filesToOutput.entries()) {
57
67
  for (const [filename, { text, map }] of files.entries()) {
58
68
  const localeFileName = `${localeSubPath}/${filename}`;
59
- if (localeFileName.endsWith('index.html')) {
60
- // update the baseHref for the locale and set the lang attribute
61
- const html = typeof text === 'string' ? text : text.toString();
62
- const updatedHtml = await this.#updateBaseHrefAndLang(html, localeSubPath);
63
- compilation.emitAsset(localeFileName, new core_1.sources.RawSource(updatedHtml));
64
- if (compilation.getAsset(filename)) {
65
- compilation.deleteAsset(filename);
66
- }
67
- continue;
68
- }
69
69
  if (map) {
70
- compilation.emitAsset(localeFileName, new core_1.sources.SourceMapSource(text, localeFileName, map));
70
+ compilation.emitAsset(localeFileName, new core_2.sources.SourceMapSource(text, localeFileName, map));
71
71
  }
72
- compilation.emitAsset(localeFileName, new core_1.sources.RawSource(text));
72
+ compilation.emitAsset(localeFileName, new core_2.sources.RawSource(text));
73
73
  if (compilation.getAsset(filename)) {
74
74
  compilation.deleteAsset(filename);
75
75
  }
@@ -78,14 +78,8 @@ class I18nInlinePlugin {
78
78
  callback();
79
79
  });
80
80
  }
81
- async #updateBaseHrefAndLang(html, localeSubPath) {
82
- // TODO: add support for diagnostics
83
- const dir = localeSubPath
84
- ? await this.#getLanguageDirection(localeSubPath, [])
85
- : undefined;
86
- html = html.replace(/<base href="([^"]+)">/g, `<base href="/${localeSubPath}$1">`);
87
- html = html.replace(/<html lang="([^"]+)">/g, `<html lang="${localeSubPath}"${dir ? ` dir="${dir}"` : ''}>`);
88
- return html;
81
+ #checkAssetHasBeenProcessed(filename) {
82
+ return this.#outputPaths.has(filename.split('/')[0]);
89
83
  }
90
84
  /**
91
85
  * Attempts to load the `@angular/localize/tools` module containing the functionality to
@@ -96,8 +90,7 @@ class I18nInlinePlugin {
96
90
  // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
97
91
  // Once TypeScript provides support for keeping the dynamic import this workaround can be
98
92
  // changed to a direct dynamic import.
99
- this.#localizeToolsModule ??=
100
- await this.#loadEsmModule('@angular/localize/tools');
93
+ this.#localizeToolsModule ??= await (0, misc_helpers_1.loadEsmModule)('@angular/localize/tools');
101
94
  }
102
95
  /**
103
96
  * Creates the needed Babel plugins to inline a given locale and translation for a JavaScript file.
@@ -122,17 +115,13 @@ class I18nInlinePlugin {
122
115
  visitor: {
123
116
  StringLiteral(path) {
124
117
  if (path.node.value === '___NG_LOCALE_INSERT___') {
125
- path.replaceWith(core_2.types.stringLiteral(locale));
118
+ path.replaceWith(core_1.types.stringLiteral(locale));
126
119
  }
127
120
  },
128
121
  },
129
122
  });
130
123
  return { diagnostics, plugins };
131
124
  }
132
- #loadEsmModule(modulePath) {
133
- const load = new Function('modulePath', `return import(modulePath);`);
134
- return load(modulePath);
135
- }
136
125
  #assertIsError(value) {
137
126
  const isError = value instanceof Error ||
138
127
  // The following is needing to identify errors coming from RxJs.
@@ -146,13 +135,16 @@ class I18nInlinePlugin {
146
135
  * Transforms a JavaScript file using Babel to inline the request locale and translation.
147
136
  * @param code A string containing the JavaScript code to transform.
148
137
  * @param map A sourcemap object for the provided JavaScript code.
149
- * @param options The inline request options to use.
138
+ * @param filename The filename of the JavaScript file to transform.
139
+ * @param locale The locale to inline.
140
+ * @param translation The translation to inline.
141
+ * @param shouldOptimize Whether to optimize the transformed code.
150
142
  * @returns An object containing the code, map, and diagnostics from the transformation.
151
143
  */
152
144
  async #transformWithBabel(code, map, filename, locale, translation, shouldOptimize) {
153
145
  let ast;
154
146
  try {
155
- ast = (0, core_2.parseSync)(code, {
147
+ ast = (0, core_1.parseSync)(code, {
156
148
  babelrc: false,
157
149
  configFile: false,
158
150
  sourceType: 'unambiguous',
@@ -172,7 +164,7 @@ class I18nInlinePlugin {
172
164
  throw new Error(`Unknown error occurred inlining file "${filename}"`);
173
165
  }
174
166
  const { diagnostics, plugins } = await this.#createI18nPlugins(locale, translation);
175
- const transformResult = await (0, core_2.transformFromAstAsync)(ast, code, {
167
+ const transformResult = await (0, core_1.transformFromAstAsync)(ast, code, {
176
168
  filename,
177
169
  // false is a valid value but not included in the type definition
178
170
  inputSourceMap: false,
@@ -196,31 +188,5 @@ class I18nInlinePlugin {
196
188
  diagnostics,
197
189
  };
198
190
  }
199
- async #getLanguageDirection(locale, warnings) {
200
- const dir = await this.#getLanguageDirectionFromLocales(locale);
201
- if (!dir) {
202
- warnings.push(`Locale data for '${locale}' cannot be found. 'dir' attribute will not be set for this locale.`);
203
- }
204
- return dir;
205
- }
206
- async #getLanguageDirectionFromLocales(locale) {
207
- try {
208
- const localeData = (await this.#loadEsmModule(`@angular/common/locales/${locale}`)).default;
209
- const dir = localeData[localeData.length - 2];
210
- return this.#isString(dir) ? dir : undefined;
211
- }
212
- catch {
213
- // In some cases certain locales might map to files which are named only with language id.
214
- // Example: `en-US` -> `en`.
215
- const [languageId] = locale.split('-', 1);
216
- if (languageId !== locale) {
217
- return this.#getLanguageDirectionFromLocales(languageId);
218
- }
219
- }
220
- return undefined;
221
- }
222
- #isString(value) {
223
- return typeof value === 'string';
224
- }
225
191
  }
226
192
  exports.I18nInlinePlugin = I18nInlinePlugin;
@@ -0,0 +1,21 @@
1
+ import { IndexHtmlGenerator, type IndexHtmlGeneratorOptions } from '@angular/build/private';
2
+ import { Compilation, RspackPluginInstance, type Compiler } from '@rspack/core';
3
+ import type { I18nOptions, IndexExpandedDefinition } from '../models';
4
+ export interface IndexHtmlPluginOptions extends IndexHtmlGeneratorOptions {
5
+ baseHref: string | undefined;
6
+ i18n: I18nOptions;
7
+ index: IndexExpandedDefinition;
8
+ isSsr: boolean;
9
+ outputPath: string;
10
+ }
11
+ export declare class IndexHtmlPlugin extends IndexHtmlGenerator implements RspackPluginInstance {
12
+ readonly options: IndexHtmlPluginOptions;
13
+ private _compilation;
14
+ get compilation(): Compilation;
15
+ constructor(options: IndexHtmlPluginOptions);
16
+ apply(compiler: Compiler): void;
17
+ readAsset(path: string): Promise<string>;
18
+ protected readIndex(path: string): Promise<string>;
19
+ getLocaleBaseHref(locale: string): string | undefined;
20
+ }
21
+ //# sourceMappingURL=index-html-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-html-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/index-html-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,KAAK,yBAAyB,EAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAOtE,MAAM,WAAW,sBAAuB,SAAQ,yBAAyB;IACvE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,qBAAa,eACX,SAAQ,kBACR,YAAW,oBAAoB;aAWD,OAAO,EAAE,sBAAsB;IAT7D,OAAO,CAAC,YAAY,CAA0B;IAC9C,IAAI,WAAW,IAAI,WAAW,CAM7B;gBAE6B,OAAO,EAAE,sBAAsB;IAI7D,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAoET,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAM9B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBjE,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAgBtD"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IndexHtmlPlugin = void 0;
4
+ const private_1 = require("@angular/build/private");
5
+ const core_1 = require("@rspack/core");
6
+ const node_path_1 = require("node:path");
7
+ const add_event_dispatch_contract_1 = require("../utils/index-file/add-event-dispatch-contract");
8
+ const misc_helpers_1 = require("../utils/misc-helpers");
9
+ const i18n_1 = require("../utils/i18n");
10
+ const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
11
+ const url_join_1 = require("../utils/url-join");
12
+ const PLUGIN_NAME = 'IndexHtmlPlugin';
13
+ class IndexHtmlPlugin extends private_1.IndexHtmlGenerator {
14
+ options;
15
+ _compilation;
16
+ get compilation() {
17
+ if (this._compilation) {
18
+ return this._compilation;
19
+ }
20
+ throw new Error('compilation is undefined.');
21
+ }
22
+ constructor(options) {
23
+ super(options);
24
+ this.options = options;
25
+ }
26
+ apply(compiler) {
27
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
28
+ this._compilation = compilation;
29
+ compilation.hooks.processAssets.tapPromise({
30
+ name: PLUGIN_NAME,
31
+ stage: core_1.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
32
+ }, async () => {
33
+ const files = [];
34
+ try {
35
+ for (const chunk of compilation.chunks) {
36
+ for (const file of chunk.files) {
37
+ // https://github.com/web-infra-dev/rspack/blob/a2e1e21c7e1ed0f34e476ec270e3c5460c4a1a36/packages/rspack/src/config/defaults.ts#L606
38
+ if (file.endsWith('.hot-update.js') ||
39
+ file.endsWith('.hot-update.mjs')) {
40
+ continue;
41
+ }
42
+ files.push({
43
+ name: chunk.name,
44
+ file,
45
+ extension: (0, node_path_1.extname)(file),
46
+ });
47
+ }
48
+ }
49
+ const outputPaths = (0, i18n_1.ensureOutputPaths)(this.options.outputPath, this.options.i18n);
50
+ for (const [locale, outputPath] of outputPaths.entries()) {
51
+ const { csrContent, warnings, errors } = await this.process({
52
+ files,
53
+ outputPath,
54
+ baseHref: this.getLocaleBaseHref(locale) ?? this.options.baseHref,
55
+ lang: locale || undefined,
56
+ });
57
+ let html = csrContent;
58
+ if (this.options.isSsr) {
59
+ html = await (0, add_event_dispatch_contract_1.addEventDispatchContract)(csrContent);
60
+ }
61
+ const { RawSource } = compiler.rspack.sources;
62
+ compilation.emitAsset((0, node_path_1.join)(outputPath, getIndexOutputFile(this.options.index)), new RawSource(html));
63
+ warnings.forEach((msg) => (0, rspack_diagnostics_1.addWarning)(compilation, msg));
64
+ errors.forEach((msg) => (0, rspack_diagnostics_1.addError)(compilation, msg));
65
+ }
66
+ }
67
+ catch (error) {
68
+ (0, misc_helpers_1.assertIsError)(error);
69
+ (0, rspack_diagnostics_1.addError)(compilation, error.message);
70
+ }
71
+ });
72
+ });
73
+ }
74
+ async readAsset(path) {
75
+ const data = this.compilation.assets[(0, node_path_1.basename)(path)].source();
76
+ return typeof data === 'string' ? data : data.toString();
77
+ }
78
+ async readIndex(path) {
79
+ return new Promise((resolve, reject) => {
80
+ if (!this.compilation.inputFileSystem) {
81
+ super.readIndex(path).then(resolve).catch(reject);
82
+ return;
83
+ }
84
+ this.compilation.inputFileSystem.readFile(path, (err, data) => {
85
+ if (err) {
86
+ reject(err);
87
+ return;
88
+ }
89
+ this.compilation.fileDependencies.add(path);
90
+ resolve(data?.toString() ?? '');
91
+ });
92
+ });
93
+ }
94
+ getLocaleBaseHref(locale) {
95
+ if (this.options.i18n.flatOutput) {
96
+ return undefined;
97
+ }
98
+ const localeData = this.options.i18n.locales[locale];
99
+ if (!localeData) {
100
+ return undefined;
101
+ }
102
+ const baseHrefSuffix = localeData.baseHref ?? localeData.subPath + '/';
103
+ return baseHrefSuffix !== ''
104
+ ? (0, url_join_1.urlJoin)(this.options.baseHref || '', baseHrefSuffix)
105
+ : undefined;
106
+ }
107
+ }
108
+ exports.IndexHtmlPlugin = IndexHtmlPlugin;
109
+ function getIndexOutputFile(index) {
110
+ if (typeof index === 'string') {
111
+ return (0, node_path_1.basename)(index);
112
+ }
113
+ return index.output || 'index.html';
114
+ }
@@ -1,9 +1,13 @@
1
1
  import { Compiler, RspackPluginInstance } from '@rspack/core';
2
- import { I18nOptions, NormalizedAngularRspackPluginOptions } from '../models';
2
+ import type { I18nOptions, NormalizedAngularRspackPluginOptions } from '../models';
3
3
  export declare class NgRspackPlugin implements RspackPluginInstance {
4
- pluginOptions: NormalizedAngularRspackPluginOptions;
5
- i18n: I18nOptions | undefined;
6
- constructor(options: NormalizedAngularRspackPluginOptions, i18nOptions?: I18nOptions);
4
+ readonly pluginOptions: NormalizedAngularRspackPluginOptions;
5
+ readonly isPlatformServer: boolean;
6
+ readonly i18n: I18nOptions;
7
+ constructor(pluginOptions: NormalizedAngularRspackPluginOptions, extraOptions: {
8
+ platform: 'browser' | 'server';
9
+ i18nOptions: I18nOptions;
10
+ });
7
11
  apply(compiler: Compiler): void;
8
12
  }
9
13
  //# sourceMappingURL=ng-rspack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ng-rspack.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/ng-rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAMR,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAKtB,OAAO,EACL,WAAW,EACX,oCAAoC,EAErC,MAAM,WAAW,CAAC;AAGnB,qBAAa,cAAe,YAAW,oBAAoB;IACzD,aAAa,EAAE,oCAAoC,CAAC;IACpD,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;gBAG5B,OAAO,EAAE,oCAAoC,EAC7C,WAAW,CAAC,EAAE,WAAW;IAM3B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA+GzB"}
1
+ {"version":3,"file":"ng-rspack.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/ng-rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIR,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EACV,WAAW,EACX,oCAAoC,EAErC,MAAM,WAAW,CAAC;AAOnB,qBAAa,cAAe,YAAW,oBAAoB;IACzD,QAAQ,CAAC,aAAa,EAAE,oCAAoC,CAAC;IAC7D,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;gBAGzB,aAAa,EAAE,oCAAoC,EACnD,YAAY,EAAE;QACZ,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC/B,WAAW,EAAE,WAAW,CAAC;KAC1B;IAOH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAoHzB"}
@@ -3,51 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NgRspackPlugin = void 0;
4
4
  const core_1 = require("@rspack/core");
5
5
  const node_path_1 = require("node:path");
6
- const rxjs_esm_resolution_1 = require("./rxjs-esm-resolution");
6
+ const entry_points_1 = require("../config/entry-points");
7
7
  const angular_rspack_plugin_1 = require("./angular-rspack-plugin");
8
- const i18n_inline_plugin_1 = require("./i18n-inline-plugin");
9
8
  const angular_ssr_dev_server_1 = require("./angular-ssr-dev-server");
9
+ const i18n_inline_plugin_1 = require("./i18n-inline-plugin");
10
+ const index_html_plugin_1 = require("./index-html-plugin");
11
+ const rxjs_esm_resolution_1 = require("./rxjs-esm-resolution");
10
12
  class NgRspackPlugin {
11
13
  pluginOptions;
14
+ isPlatformServer;
12
15
  i18n;
13
- constructor(options, i18nOptions) {
14
- this.pluginOptions = options;
15
- this.i18n = i18nOptions;
16
+ constructor(pluginOptions, extraOptions) {
17
+ this.pluginOptions = pluginOptions;
18
+ this.i18n = extraOptions.i18nOptions;
19
+ this.isPlatformServer = extraOptions.platform === 'server';
16
20
  }
17
21
  apply(compiler) {
18
22
  const root = this.pluginOptions.root;
19
- const isProduction = process.env['NODE_ENV'] === 'production';
20
23
  const isDevServer = process.env['WEBPACK_SERVE'];
21
- const polyfills = this.pluginOptions.polyfills ?? [];
22
- if (polyfills.length > 0) {
23
- compiler.hooks.entryOption.tap('NgRspackPlugin', (context, entry) => {
24
- const keys = Object.keys(entry);
25
- for (const key of keys) {
26
- if (key === 'styles') {
27
- continue;
28
- }
29
- const entryValue = entry[key];
30
- entryValue.import = [...polyfills, ...entryValue.import];
31
- }
32
- });
33
- }
34
- if (!this.pluginOptions.hasServer) {
35
- const scripts = this.pluginOptions.globalScripts ?? [];
36
- for (const script of scripts) {
37
- for (const file of script.files) {
38
- new core_1.EntryPlugin(compiler.context, file, {
39
- name: isProduction ? script.name : undefined,
40
- }).apply(compiler);
41
- }
42
- }
43
- if (this.pluginOptions.index) {
44
- new core_1.HtmlRspackPlugin({
45
- minify: false,
46
- inject: 'body',
47
- scriptLoading: 'module',
48
- template: this.pluginOptions.index.input,
49
- }).apply(compiler);
50
- }
24
+ if (!this.isPlatformServer) {
51
25
  if (this.pluginOptions.ssr &&
52
26
  typeof this.pluginOptions.ssr === 'object' &&
53
27
  this.pluginOptions.ssr.entry !== undefined) {
@@ -58,9 +32,10 @@ class NgRspackPlugin {
58
32
  new core_1.ProgressPlugin().apply(compiler);
59
33
  }
60
34
  new core_1.DefinePlugin({
61
- ngDevMode: isProduction ? 'false' : {},
35
+ // TODO: Replace with ...(this.pluginOptions.optimization.scripts ? { 'ngDevMode': 'false' } : undefined) when Optimization is implemented
36
+ ...(this.pluginOptions.optimization ? { ngDevMode: 'false' } : {}),
62
37
  ngJitMode: this.pluginOptions.aot ? undefined : 'true',
63
- ngServerMode: this.pluginOptions.hasServer,
38
+ ngServerMode: this.isPlatformServer,
64
39
  ...(this.pluginOptions.define ?? {}),
65
40
  }).apply(compiler);
66
41
  if (this.pluginOptions.assets) {
@@ -104,11 +79,38 @@ class NgRspackPlugin {
104
79
  skipChildCompilers: true,
105
80
  }).apply(compiler);
106
81
  }
107
- if (this.i18n?.shouldInline) {
82
+ if (this.i18n.shouldInline) {
108
83
  new i18n_inline_plugin_1.I18nInlinePlugin(this.pluginOptions, this.i18n).apply(compiler);
109
84
  }
110
85
  new rxjs_esm_resolution_1.RxjsEsmResolutionPlugin().apply(compiler);
111
86
  new angular_rspack_plugin_1.AngularRspackPlugin(this.pluginOptions, this.i18n).apply(compiler);
87
+ if (!this.isPlatformServer && this.pluginOptions.index) {
88
+ // @TODO: remove this once we properly support optimization granular options
89
+ const optimize = this.pluginOptions.optimization !== false;
90
+ new index_html_plugin_1.IndexHtmlPlugin({
91
+ indexPath: this.pluginOptions.index.input,
92
+ index: this.pluginOptions.index,
93
+ baseHref: this.pluginOptions.baseHref,
94
+ outputPath: this.pluginOptions.outputPath.browser,
95
+ entrypoints: (0, entry_points_1.getEntryPoints)(this.pluginOptions.globalStyles, this.pluginOptions.globalScripts, this.pluginOptions.devServer?.hmr),
96
+ i18n: this.i18n,
97
+ optimization: {
98
+ fonts: { inline: optimize },
99
+ scripts: optimize,
100
+ styles: {
101
+ inlineCritical: optimize,
102
+ minify: optimize,
103
+ removeSpecialComments: optimize,
104
+ },
105
+ },
106
+ isSsr: !!(this.pluginOptions.ssr ||
107
+ this.pluginOptions.prerender ||
108
+ this.pluginOptions.appShell),
109
+ deployUrl: this.pluginOptions.deployUrl,
110
+ crossOrigin: this.pluginOptions.crossOrigin,
111
+ sri: this.pluginOptions.subresourceIntegrity,
112
+ }).apply(compiler);
113
+ }
112
114
  }
113
115
  }
114
116
  exports.NgRspackPlugin = NgRspackPlugin;
@@ -1,4 +1,4 @@
1
- import { ProjectGraphProjectNode } from '@nx/devkit';
1
+ import type { ProjectGraphProjectNode } from '@nx/devkit';
2
2
  type ProjectRootMappings = Map<string, string>;
3
3
  /**
4
4
  * This creates a map of project roots to project names to easily look up the project of a file
@@ -1 +1 @@
1
- {"version":3,"file":"find-project-for-path.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/find-project-for-path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAiB,MAAM,YAAY,CAAC;AAGpE,KAAK,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC7C,mBAAmB,CAQrB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,mBAAmB,GAClC,MAAM,GAAG,SAAS,CAkBpB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAGhD"}
1
+ {"version":3,"file":"find-project-for-path.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/find-project-for-path.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAG1D,KAAK,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC7C,mBAAmB,CAQrB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,mBAAmB,GAClC,MAAM,GAAG,SAAS,CAkBpB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAGhD"}
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProjectRootMappings = createProjectRootMappings;
4
4
  exports.findProjectForPath = findProjectForPath;
5
5
  exports.normalizeProjectRoot = normalizeProjectRoot;
6
- // TODO: Remove this once migrated to Nx
7
- const devkit_1 = require("@nx/devkit");
8
6
  const node_path_1 = require("node:path");
9
7
  /**
10
8
  * This creates a map of project roots to project names to easily look up the project of a file
@@ -29,8 +27,8 @@ function findProjectForPath(filePath, projectRootMap) {
29
27
  * Windows may pass Win-style file paths
30
28
  * Ensure filePath is in UNIX-style
31
29
  */
32
- let currentPath = (0, devkit_1.normalizePath)(filePath);
33
- for (; currentPath != (0, node_path_1.dirname)(currentPath); currentPath = (0, node_path_1.dirname)(currentPath)) {
30
+ let currentPath = node_path_1.posix.normalize(filePath);
31
+ for (; currentPath != node_path_1.posix.dirname(currentPath); currentPath = node_path_1.posix.dirname(currentPath)) {
34
32
  const p = projectRootMap.get(currentPath);
35
33
  if (p) {
36
34
  return p;
@@ -0,0 +1,3 @@
1
+ import { I18nOptions } from '../models';
2
+ export declare function getLocaleBaseHref(i18n: I18nOptions, locale: string, baseHref?: string): string | undefined;
3
+ //# sourceMappingURL=get-locale-base-href.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-locale-base-href.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/get-locale-base-href.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAepB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocaleBaseHref = getLocaleBaseHref;
4
+ const url_join_1 = require("./url-join");
5
+ function getLocaleBaseHref(i18n, locale, baseHref) {
6
+ if (i18n.flatOutput) {
7
+ return undefined;
8
+ }
9
+ const localeData = i18n.locales[locale];
10
+ if (!localeData) {
11
+ return undefined;
12
+ }
13
+ const baseHrefSuffix = localeData.baseHref ?? localeData.subPath + '/';
14
+ return baseHrefSuffix !== ''
15
+ ? (0, url_join_1.urlJoin)(baseHref || '', baseHrefSuffix)
16
+ : undefined;
17
+ }
@@ -0,0 +1,3 @@
1
+ import { type ProjectGraph } from '@nx/devkit';
2
+ export declare function retrieveOrCreateProjectGraph(): Promise<ProjectGraph | null>;
3
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAEpB,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAoBjF"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveOrCreateProjectGraph = retrieveOrCreateProjectGraph;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function retrieveOrCreateProjectGraph() {
6
+ let projectGraph = null;
7
+ try {
8
+ projectGraph = (0, devkit_1.readCachedProjectGraph)();
9
+ }
10
+ catch {
11
+ // ignore
12
+ }
13
+ try {
14
+ if (!projectGraph) {
15
+ projectGraph = await (0, devkit_1.createProjectGraphAsync)({
16
+ exitOnError: false,
17
+ resetDaemonClient: true,
18
+ });
19
+ }
20
+ }
21
+ catch {
22
+ // ignore
23
+ }
24
+ return projectGraph;
25
+ }
@@ -0,0 +1,4 @@
1
+ import type { I18nOptions } from '../models';
2
+ export declare function ensureOutputPaths(baseOutputPath: string, i18n: I18nOptions): Map<string, string>;
3
+ export declare function getLocaleOutputPaths(i18n: I18nOptions): Map<string, string>;
4
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/i18n.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,WAAW,GAChB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAWrB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAS3E"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureOutputPaths = ensureOutputPaths;
4
+ exports.getLocaleOutputPaths = getLocaleOutputPaths;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ function ensureOutputPaths(baseOutputPath, i18n) {
8
+ const outputPaths = getLocaleOutputPaths(i18n);
9
+ for (const [, outputPath] of outputPaths) {
10
+ const fullPath = (0, node_path_1.join)(baseOutputPath, outputPath);
11
+ if (!(0, node_fs_1.existsSync)(fullPath)) {
12
+ (0, node_fs_1.mkdirSync)(fullPath, { recursive: true });
13
+ }
14
+ }
15
+ return outputPaths;
16
+ }
17
+ function getLocaleOutputPaths(i18n) {
18
+ const outputPaths = i18n.shouldInline
19
+ ? [...i18n.inlineLocales].map((l) => [
20
+ l,
21
+ i18n.flatOutput ? '' : i18n.locales[l].subPath,
22
+ ])
23
+ : [['', '']];
24
+ return new Map(outputPaths);
25
+ }
@@ -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 addEventDispatchContract(html: string): Promise<string>;
9
+ //# sourceMappingURL=add-event-dispatch-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-event-dispatch-contract.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index-file/add-event-dispatch-contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoB5E"}
@@ -0,0 +1,27 @@
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.addEventDispatchContract = addEventDispatchContract;
11
+ const promises_1 = require("node:fs/promises");
12
+ const html_rewriting_stream_1 = require("./html-rewriting-stream");
13
+ let jsActionContractScript;
14
+ async function addEventDispatchContract(html) {
15
+ const { rewriter, transformedContent } = await (0, html_rewriting_stream_1.htmlRewritingStream)(html);
16
+ jsActionContractScript ??=
17
+ '<script type="text/javascript" id="ng-event-dispatch-contract">' +
18
+ (await (0, promises_1.readFile)(require.resolve('@angular/core/event-dispatch-contract.min.js'), 'utf-8')) +
19
+ '</script>';
20
+ rewriter.on('startTag', (tag) => {
21
+ rewriter.emitStartTag(tag);
22
+ if (tag.tagName === 'body') {
23
+ rewriter.emitRaw(jsActionContractScript);
24
+ }
25
+ });
26
+ return transformedContent();
27
+ }
@@ -0,0 +1,16 @@
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 { RewritingStream } from 'parse5-html-rewriting-stream';
9
+ export type StartTag = Parameters<RewritingStream['emitStartTag']>[0];
10
+ export type EndTag = Parameters<RewritingStream['emitEndTag']>[0];
11
+ export type { RewritingStream };
12
+ export declare function htmlRewritingStream(content: string): Promise<{
13
+ rewriter: RewritingStream;
14
+ transformedContent: () => Promise<string>;
15
+ }>;
16
+ //# sourceMappingURL=html-rewriting-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-rewriting-stream.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index-file/html-rewriting-stream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAIpE,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAClE,QAAQ,EAAE,eAAe,CAAC;IAC1B,kBAAkB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C,CAAC,CAkBD"}