@nx/angular-rspack 21.2.0 → 21.4.0-beta.9

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 (31) hide show
  1. package/LICENSE +18 -17
  2. package/README.md +66 -13
  3. package/README.md__tpl__ +50 -0
  4. package/dist/lib/config/create-config.d.ts.map +1 -1
  5. package/dist/lib/models/angular-rspack-plugin-options.d.ts +1 -0
  6. package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -1
  7. package/dist/lib/models/i18n.js +3 -1
  8. package/dist/lib/models/normalize-options.d.ts.map +1 -1
  9. package/dist/lib/models/normalize-options.js +4 -0
  10. package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -1
  11. package/dist/lib/plugins/angular-rspack-plugin.js +53 -53
  12. package/dist/lib/plugins/angular-ssr-dev-server.js +25 -22
  13. package/dist/lib/plugins/any-component-style-budget-checker-plugin.js +0 -1
  14. package/dist/lib/plugins/client/ssr-reload-client.js +0 -1
  15. package/dist/lib/plugins/i18n-inline-plugin.d.ts.map +1 -1
  16. package/dist/lib/plugins/i18n-inline-plugin.js +132 -125
  17. package/dist/lib/plugins/index-html-plugin.js +0 -2
  18. package/dist/lib/plugins/ng-rspack.js +0 -3
  19. package/dist/lib/plugins/prerender-plugin.d.ts.map +1 -1
  20. package/dist/lib/plugins/prerender-plugin.js +159 -162
  21. package/dist/lib/plugins/server/ssr-reload-server.js +8 -5
  22. package/dist/lib/plugins/stats-json-plugin.js +0 -1
  23. package/dist/lib/plugins/tools/render-worker.d.ts.map +1 -1
  24. package/dist/lib/plugins/tools/render-worker.js +3 -1
  25. package/dist/lib/plugins/tools/routes-extractor-worker.d.ts +1 -1
  26. package/dist/lib/plugins/tools/routes-extractor-worker.d.ts.map +1 -1
  27. package/dist/lib/plugins/tools/routes-extractor-worker.js +3 -1
  28. package/dist/lib/utils/spinner.js +7 -6
  29. package/dist/lib/utils/stats.d.ts.map +1 -1
  30. package/dist/lib/utils/stats.js +2 -1
  31. package/package.json +45 -16
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var _I18nInlinePlugin_instances, _I18nInlinePlugin_pluginOptions, _I18nInlinePlugin_i18n, _I18nInlinePlugin_localizeToolsModule, _I18nInlinePlugin_outputPaths, _I18nInlinePlugin_checkAssetHasBeenProcessed, _I18nInlinePlugin_loadLocalizeTools, _I18nInlinePlugin_createI18nPlugins, _I18nInlinePlugin_assertIsError, _I18nInlinePlugin_transformWithBabel;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.I18nInlinePlugin = void 0;
4
5
  const tslib_1 = require("tslib");
@@ -10,18 +11,19 @@ const i18n_1 = require("../utils/i18n");
10
11
  const misc_helpers_1 = require("../utils/misc-helpers");
11
12
  const PLUGIN_NAME = 'I18nInlinePlugin';
12
13
  class I18nInlinePlugin {
13
- #pluginOptions;
14
- #i18n;
15
- /**
16
- * Cached instance of the `@angular/localize/tools` module.
17
- * This is used to remove the need to repeatedly import the module per file translation.
18
- */
19
- #localizeToolsModule;
20
- #outputPaths;
21
14
  constructor(pluginOptions, i18nOptions) {
22
- this.#pluginOptions = pluginOptions;
23
- this.#i18n = i18nOptions;
24
- this.#outputPaths = new Set((0, i18n_1.getLocaleOutputPaths)(i18nOptions).values());
15
+ _I18nInlinePlugin_instances.add(this);
16
+ _I18nInlinePlugin_pluginOptions.set(this, void 0);
17
+ _I18nInlinePlugin_i18n.set(this, void 0);
18
+ /**
19
+ * Cached instance of the `@angular/localize/tools` module.
20
+ * This is used to remove the need to repeatedly import the module per file translation.
21
+ */
22
+ _I18nInlinePlugin_localizeToolsModule.set(this, void 0);
23
+ _I18nInlinePlugin_outputPaths.set(this, void 0);
24
+ tslib_1.__classPrivateFieldSet(this, _I18nInlinePlugin_pluginOptions, pluginOptions, "f");
25
+ tslib_1.__classPrivateFieldSet(this, _I18nInlinePlugin_i18n, i18nOptions, "f");
26
+ tslib_1.__classPrivateFieldSet(this, _I18nInlinePlugin_outputPaths, new Set((0, i18n_1.getLocaleOutputPaths)(i18nOptions).values()), "f");
25
27
  }
26
28
  apply(compiler) {
27
29
  compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => {
@@ -41,19 +43,25 @@ class I18nInlinePlugin {
41
43
  }
42
44
  // Map of locales to Map of files to output
43
45
  const filesToOutput = new Map();
44
- for (const localeKey of this.#i18n.inlineLocales) {
45
- const locale = this.#i18n.locales[localeKey];
46
+ for (const localeKey of tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_i18n, "f").inlineLocales) {
47
+ const locale = tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_i18n, "f").locales[localeKey];
46
48
  const localeFiles = new Map();
47
49
  for (const [filename, { text, map }] of filesToInline.entries()) {
48
- if (this.#checkAssetHasBeenProcessed(filename)) {
50
+ if (tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_checkAssetHasBeenProcessed).call(this, filename)) {
49
51
  continue;
50
52
  }
51
- const result = await this.#transformWithBabel(text, map, filename, localeKey, locale.translation, this.#pluginOptions.advancedOptimizations);
52
- localeFiles.set(filename, { text: result.code, map: result.map });
53
+ const result = await tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_transformWithBabel).call(this, text, map, filename, localeKey, locale.translation, tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_pluginOptions, "f").advancedOptimizations);
54
+ const sourceMap = result.map
55
+ ? new core_2.sources.SourceMapSource(result.code, filename, result.map)
56
+ : undefined;
57
+ localeFiles.set(filename, {
58
+ text: result.code,
59
+ map: sourceMap ? sourceMap.map() : undefined,
60
+ });
53
61
  // TODO: Add support for diagnostics
54
62
  }
55
63
  for (const [filename, source] of additionalFiles.entries()) {
56
- if (this.#checkAssetHasBeenProcessed(filename)) {
64
+ if (tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_checkAssetHasBeenProcessed).call(this, filename)) {
57
65
  continue;
58
66
  }
59
67
  localeFiles.set(filename, {
@@ -67,7 +75,7 @@ class I18nInlinePlugin {
67
75
  for (const [filename, { text, map }] of files.entries()) {
68
76
  const localeFileName = `${localeSubPath}/${filename}`;
69
77
  const asset = compilation.getAsset(filename);
70
- const assetInfo = asset?.info;
78
+ const assetInfo = asset ? asset.info : undefined;
71
79
  if (map) {
72
80
  compilation.emitAsset(localeFileName, new core_2.sources.SourceMapSource(text, localeFileName, map), (newAssetInfo) => ({ ...assetInfo, ...newAssetInfo }));
73
81
  }
@@ -80,115 +88,114 @@ class I18nInlinePlugin {
80
88
  callback();
81
89
  });
82
90
  }
83
- #checkAssetHasBeenProcessed(filename) {
84
- return this.#outputPaths.has(filename.split('/')[0]);
85
- }
86
- /**
87
- * Attempts to load the `@angular/localize/tools` module containing the functionality to
88
- * perform the file translations.
89
- * This module must be dynamically loaded as it is an ESM module and this file is CommonJS.
90
- */
91
- async #loadLocalizeTools() {
92
- // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
93
- // Once TypeScript provides support for keeping the dynamic import this workaround can be
94
- // changed to a direct dynamic import.
95
- this.#localizeToolsModule ??= await (0, misc_helpers_1.loadEsmModule)('@angular/localize/tools');
96
- }
97
- /**
98
- * Creates the needed Babel plugins to inline a given locale and translation for a JavaScript file.
99
- * @param locale A string containing the locale specifier to use.
100
- * @param translation A object record containing locale specific messages to use.
101
- * @returns An array of Babel plugins.
102
- */
103
- async #createI18nPlugins(locale, translation) {
104
- await this.#loadLocalizeTools();
105
- const { Diagnostics, makeEs2015TranslatePlugin } =
106
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
107
- this.#localizeToolsModule;
108
- const plugins = [];
109
- const diagnostics = new Diagnostics();
110
- plugins.push(makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
111
- missingTranslation: translation === undefined
112
- ? 'ignore'
113
- : this.#pluginOptions.i18nMissingTranslation,
114
- }));
115
- // Create a plugin to replace the locale specifier constant inject by the build system with the actual specifier
116
- plugins.push({
117
- visitor: {
118
- StringLiteral(path) {
119
- if (path.node.value === '___NG_LOCALE_INSERT___') {
120
- path.replaceWith(core_1.types.stringLiteral(locale));
121
- }
122
- },
91
+ }
92
+ exports.I18nInlinePlugin = I18nInlinePlugin;
93
+ _I18nInlinePlugin_pluginOptions = new WeakMap(), _I18nInlinePlugin_i18n = new WeakMap(), _I18nInlinePlugin_localizeToolsModule = new WeakMap(), _I18nInlinePlugin_outputPaths = new WeakMap(), _I18nInlinePlugin_instances = new WeakSet(), _I18nInlinePlugin_checkAssetHasBeenProcessed = function _I18nInlinePlugin_checkAssetHasBeenProcessed(filename) {
94
+ return tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_outputPaths, "f").has(filename.split('/')[0]);
95
+ }, _I18nInlinePlugin_loadLocalizeTools =
96
+ /**
97
+ * Attempts to load the `@angular/localize/tools` module containing the functionality to
98
+ * perform the file translations.
99
+ * This module must be dynamically loaded as it is an ESM module and this file is CommonJS.
100
+ */
101
+ async function _I18nInlinePlugin_loadLocalizeTools() {
102
+ // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
103
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
104
+ // changed to a direct dynamic import.
105
+ tslib_1.__classPrivateFieldSet(this, _I18nInlinePlugin_localizeToolsModule, tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_localizeToolsModule, "f") ?? await (0, misc_helpers_1.loadEsmModule)('@angular/localize/tools'), "f");
106
+ }, _I18nInlinePlugin_createI18nPlugins =
107
+ /**
108
+ * Creates the needed Babel plugins to inline a given locale and translation for a JavaScript file.
109
+ * @param locale A string containing the locale specifier to use.
110
+ * @param translation A object record containing locale specific messages to use.
111
+ * @returns An array of Babel plugins.
112
+ */
113
+ async function _I18nInlinePlugin_createI18nPlugins(locale, translation) {
114
+ await tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_loadLocalizeTools).call(this);
115
+ const { Diagnostics, makeEs2015TranslatePlugin } =
116
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
117
+ tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_localizeToolsModule, "f");
118
+ const plugins = [];
119
+ const diagnostics = new Diagnostics();
120
+ plugins.push(makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
121
+ missingTranslation: translation === undefined
122
+ ? 'ignore'
123
+ : tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_pluginOptions, "f").i18nMissingTranslation,
124
+ }));
125
+ // Create a plugin to replace the locale specifier constant inject by the build system with the actual specifier
126
+ plugins.push({
127
+ visitor: {
128
+ StringLiteral(path) {
129
+ if (path.node.value === '___NG_LOCALE_INSERT___') {
130
+ path.replaceWith(core_1.types.stringLiteral(locale));
131
+ }
123
132
  },
133
+ },
134
+ });
135
+ return { diagnostics, plugins };
136
+ }, _I18nInlinePlugin_assertIsError = function _I18nInlinePlugin_assertIsError(value) {
137
+ const isError = value instanceof Error ||
138
+ // The following is needing to identify errors coming from RxJs.
139
+ (typeof value === 'object' &&
140
+ value &&
141
+ 'name' in value &&
142
+ 'message' in value);
143
+ (0, node_assert_1.default)(isError, 'catch clause variable is not an Error instance');
144
+ }, _I18nInlinePlugin_transformWithBabel =
145
+ /**
146
+ * Transforms a JavaScript file using Babel to inline the request locale and translation.
147
+ * @param code A string containing the JavaScript code to transform.
148
+ * @param map A sourcemap object for the provided JavaScript code.
149
+ * @param filename The filename of the JavaScript file to transform.
150
+ * @param locale The locale to inline.
151
+ * @param translation The translation to inline.
152
+ * @param shouldOptimize Whether to optimize the transformed code.
153
+ * @returns An object containing the code, map, and diagnostics from the transformation.
154
+ */
155
+ async function _I18nInlinePlugin_transformWithBabel(code, map, filename, locale, translation, shouldOptimize) {
156
+ let ast;
157
+ try {
158
+ ast = (0, core_1.parseSync)(code, {
159
+ babelrc: false,
160
+ configFile: false,
161
+ sourceType: 'unambiguous',
162
+ filename,
124
163
  });
125
- return { diagnostics, plugins };
126
164
  }
127
- #assertIsError(value) {
128
- const isError = value instanceof Error ||
129
- // The following is needing to identify errors coming from RxJs.
130
- (typeof value === 'object' &&
131
- value &&
132
- 'name' in value &&
133
- 'message' in value);
134
- (0, node_assert_1.default)(isError, 'catch clause variable is not an Error instance');
165
+ catch (error) {
166
+ tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_assertIsError).call(this, error);
167
+ // Make the error more readable.
168
+ // Same errors will contain the full content of the file as the error message
169
+ // Which makes it hard to find the actual error message.
170
+ const index = error.message.indexOf(')\n');
171
+ const msg = index !== -1 ? error.message.slice(0, index + 1) : error.message;
172
+ throw new Error(`${msg}\nAn error occurred inlining file "${filename}"`);
135
173
  }
136
- /**
137
- * Transforms a JavaScript file using Babel to inline the request locale and translation.
138
- * @param code A string containing the JavaScript code to transform.
139
- * @param map A sourcemap object for the provided JavaScript code.
140
- * @param filename The filename of the JavaScript file to transform.
141
- * @param locale The locale to inline.
142
- * @param translation The translation to inline.
143
- * @param shouldOptimize Whether to optimize the transformed code.
144
- * @returns An object containing the code, map, and diagnostics from the transformation.
145
- */
146
- async #transformWithBabel(code, map, filename, locale, translation, shouldOptimize) {
147
- let ast;
148
- try {
149
- ast = (0, core_1.parseSync)(code, {
150
- babelrc: false,
151
- configFile: false,
152
- sourceType: 'unambiguous',
153
- filename,
154
- });
155
- }
156
- catch (error) {
157
- this.#assertIsError(error);
158
- // Make the error more readable.
159
- // Same errors will contain the full content of the file as the error message
160
- // Which makes it hard to find the actual error message.
161
- const index = error.message.indexOf(')\n');
162
- const msg = index !== -1 ? error.message.slice(0, index + 1) : error.message;
163
- throw new Error(`${msg}\nAn error occurred inlining file "${filename}"`);
164
- }
165
- if (!ast) {
166
- throw new Error(`Unknown error occurred inlining file "${filename}"`);
167
- }
168
- const { diagnostics, plugins } = await this.#createI18nPlugins(locale, translation);
169
- const transformResult = await (0, core_1.transformFromAstAsync)(ast, code, {
170
- filename,
171
- // false is a valid value but not included in the type definition
172
- inputSourceMap: false,
173
- sourceMaps: !!map,
174
- compact: shouldOptimize,
175
- configFile: false,
176
- babelrc: false,
177
- browserslistConfigFile: false,
178
- plugins,
179
- });
180
- if (!transformResult || !transformResult.code) {
181
- throw new Error(`Unknown error occurred processing bundle for "${filename}".`);
182
- }
183
- let outputMap;
184
- if (map && transformResult.map) {
185
- outputMap = (0, remapping_1.default)([transformResult.map, map], () => null);
186
- }
187
- return {
188
- code: transformResult.code,
189
- map: outputMap && JSON.stringify(outputMap),
190
- diagnostics,
191
- };
174
+ if (!ast) {
175
+ throw new Error(`Unknown error occurred inlining file "${filename}"`);
192
176
  }
193
- }
194
- exports.I18nInlinePlugin = I18nInlinePlugin;
177
+ const { diagnostics, plugins } = await tslib_1.__classPrivateFieldGet(this, _I18nInlinePlugin_instances, "m", _I18nInlinePlugin_createI18nPlugins).call(this, locale, translation);
178
+ const transformResult = await (0, core_1.transformFromAstAsync)(ast, code, {
179
+ filename,
180
+ // false is a valid value but not included in the type definition
181
+ inputSourceMap: false,
182
+ sourceMaps: !!map,
183
+ compact: shouldOptimize,
184
+ configFile: false,
185
+ babelrc: false,
186
+ browserslistConfigFile: false,
187
+ plugins,
188
+ });
189
+ if (!transformResult || !transformResult.code) {
190
+ throw new Error(`Unknown error occurred processing bundle for "${filename}".`);
191
+ }
192
+ let outputMap;
193
+ if (map && transformResult.map) {
194
+ outputMap = (0, remapping_1.default)([transformResult.map, map], () => null);
195
+ }
196
+ return {
197
+ code: transformResult.code,
198
+ map: outputMap && JSON.stringify(outputMap),
199
+ diagnostics,
200
+ };
201
+ };
@@ -12,8 +12,6 @@ const url_join_1 = require("../utils/url-join");
12
12
  const get_index_output_file_1 = require("../utils/index-file/get-index-output-file");
13
13
  const PLUGIN_NAME = 'IndexHtmlPlugin';
14
14
  class IndexHtmlPlugin extends private_1.IndexHtmlGenerator {
15
- options;
16
- _compilation;
17
15
  get compilation() {
18
16
  if (this._compilation) {
19
17
  return this._compilation;
@@ -12,9 +12,6 @@ const rxjs_esm_resolution_1 = require("./rxjs-esm-resolution");
12
12
  const progress_plugin_1 = require("./progress-plugin");
13
13
  const misc_helpers_1 = require("../utils/misc-helpers");
14
14
  class NgRspackPlugin {
15
- pluginOptions;
16
- isPlatformServer;
17
- i18n;
18
15
  constructor(pluginOptions, extraOptions) {
19
16
  this.pluginOptions = pluginOptions;
20
17
  this.i18n = extraOptions.i18nOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"prerender-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/prerender-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOhF,OAAO,EACL,KAAK,WAAW,EAEhB,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAenB,qBAAa,eAAgB,YAAW,oBAAoB;;gBAKxD,OAAO,EAAE,oCAAoC,EAC7C,WAAW,CAAC,EAAE,WAAW;IAM3B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA2QzB"}
1
+ {"version":3,"file":"prerender-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/prerender-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOhF,OAAO,EACL,KAAK,WAAW,EAEhB,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAenB,qBAAa,eAAgB,YAAW,oBAAoB;;gBAKxD,OAAO,EAAE,oCAAoC,EAC7C,WAAW,CAAC,EAAE,WAAW;IAM3B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAwQzB"}