@nx/angular 21.0.0-beta.1 → 21.0.0-beta.11

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 (117) hide show
  1. package/fesm2022/nx-angular.mjs +0 -352
  2. package/fesm2022/nx-angular.mjs.map +1 -1
  3. package/generators.json +7 -2
  4. package/index.d.ts +1 -1
  5. package/migrations.json +199 -69
  6. package/ng-package.json +1 -1
  7. package/package.json +11 -14
  8. package/src/builders/dev-server/dev-server.impl.js +2 -3
  9. package/src/builders/dev-server/lib/normalize-options.js +1 -0
  10. package/src/builders/dev-server/schema.d.ts +4 -0
  11. package/src/builders/dev-server/schema.json +10 -4
  12. package/src/builders/webpack-browser/schema.d.ts +1 -4
  13. package/src/builders/webpack-browser/schema.json +5 -0
  14. package/src/builders/webpack-browser/webpack-browser.impl.js +5 -5
  15. package/src/executors/delegate-build/delegate-build.impl.d.ts +1 -3
  16. package/src/executors/delegate-build/delegate-build.impl.js +0 -3
  17. package/src/executors/module-federation-dev-server/schema.d.ts +3 -0
  18. package/src/executors/module-federation-dev-server/schema.json +2 -1
  19. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
  20. package/src/executors/package/package.impl.js +1 -4
  21. package/src/generators/add-linting/add-linting.js +2 -17
  22. package/src/generators/add-linting/lib/create-eslint-configuration.d.ts +2 -2
  23. package/src/generators/add-linting/lib/create-eslint-configuration.js +2 -2
  24. package/src/generators/add-linting/schema.d.ts +1 -0
  25. package/src/generators/application/application.js +20 -1
  26. package/src/generators/application/files/rspack-ssr/server.ts__tmpl__ +72 -0
  27. package/src/generators/application/lib/add-e2e.js +2 -9
  28. package/src/generators/application/lib/add-linting.js +2 -2
  29. package/src/generators/application/lib/add-serve-static-target.js +1 -0
  30. package/src/generators/application/lib/add-unit-test-runner.js +2 -0
  31. package/src/generators/application/lib/create-project.js +1 -0
  32. package/src/generators/application/lib/normalize-options.d.ts +1 -1
  33. package/src/generators/application/lib/normalize-options.js +10 -4
  34. package/src/generators/application/schema.d.ts +2 -2
  35. package/src/generators/application/schema.json +1 -7
  36. package/src/generators/component-test/component-test.js +1 -1
  37. package/src/generators/convert-to-rspack/convert-to-rspack.d.ts +4 -0
  38. package/src/generators/convert-to-rspack/convert-to-rspack.js +329 -0
  39. package/src/generators/convert-to-rspack/lib/create-config.d.ts +2 -0
  40. package/src/generators/convert-to-rspack/lib/create-config.js +45 -0
  41. package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.d.ts +6 -0
  42. package/src/generators/convert-to-rspack/lib/get-custom-webpack-config.js +77 -0
  43. package/src/generators/convert-to-rspack/lib/update-tsconfig.d.ts +2 -0
  44. package/src/generators/convert-to-rspack/lib/update-tsconfig.js +26 -0
  45. package/src/generators/convert-to-rspack/lib/validate-supported-executor.d.ts +2 -0
  46. package/src/generators/convert-to-rspack/lib/validate-supported-executor.js +14 -0
  47. package/src/generators/convert-to-rspack/schema.d.ts +5 -0
  48. package/src/generators/convert-to-rspack/schema.json +30 -0
  49. package/src/generators/host/host.js +1 -1
  50. package/src/generators/host/schema.d.ts +0 -1
  51. package/src/generators/host/schema.json +0 -6
  52. package/src/generators/library/lib/add-project.d.ts +1 -1
  53. package/src/generators/library/lib/add-project.js +7 -1
  54. package/src/generators/library/lib/normalize-options.js +3 -4
  55. package/src/generators/library/lib/normalized-schema.d.ts +0 -1
  56. package/src/generators/library/library.js +6 -3
  57. package/src/generators/library/schema.d.ts +0 -1
  58. package/src/generators/library/schema.json +0 -6
  59. package/src/generators/move/move.d.ts +3 -0
  60. package/src/generators/move/move.js +3 -0
  61. package/src/generators/ng-add/migrators/projects/e2e.migrator.js +4 -4
  62. package/src/generators/ngrx/ngrx.d.ts +3 -0
  63. package/src/generators/ngrx/ngrx.js +3 -0
  64. package/src/generators/ngrx/schema.json +1 -1
  65. package/src/generators/ngrx-feature-store/schema.d.ts +1 -1
  66. package/src/generators/remote/remote.js +1 -1
  67. package/src/generators/remote/schema.d.ts +0 -1
  68. package/src/generators/remote/schema.json +0 -6
  69. package/src/generators/setup-mf/lib/setup-serve-target.js +1 -0
  70. package/src/generators/setup-ssr/files/v19+/application-builder/ngmodule-src/app/__rootModuleFileName__ +2 -2
  71. package/src/generators/setup-ssr/files/v19+/application-builder/server/__serverFileName__ +1 -1
  72. package/src/generators/setup-ssr/files/v19+/application-builder/standalone-src/app/app.config.server.ts__tpl__ +2 -2
  73. package/src/generators/setup-ssr/files/v19+/application-builder-common-engine/server/__serverFileName__ +2 -0
  74. package/src/generators/setup-ssr/lib/generate-files.js +12 -1
  75. package/src/generators/setup-ssr/lib/update-project-config.js +1 -0
  76. package/src/generators/stories/stories.js +2 -2
  77. package/src/generators/utils/add-jest.d.ts +1 -0
  78. package/src/generators/utils/add-jest.js +2 -2
  79. package/src/generators/utils/add-vitest.d.ts +1 -0
  80. package/src/generators/utils/add-vitest.js +1 -1
  81. package/src/generators/utils/ensure-angular-dependencies.js +0 -1
  82. package/src/generators/utils/testing.js +1 -2
  83. package/src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store.js +4 -4
  84. package/src/migrations/update-19-6-0/turn-off-dts-by-default.js +2 -2
  85. package/src/migrations/{update-16-1-0 → update-20-5-0}/update-angular-cli.d.ts +1 -1
  86. package/src/migrations/{update-16-1-0 → update-20-5-0}/update-angular-cli.js +1 -1
  87. package/src/migrations/{update-16-1-0/remove-ngcc-invocation.d.ts → update-21-0-0/change-data-persistence-operators-imports-to-ngrx-router-store-data-persistence.d.ts} +1 -1
  88. package/src/migrations/update-21-0-0/change-data-persistence-operators-imports-to-ngrx-router-store-data-persistence.js +122 -0
  89. package/src/migrations/update-21-0-0/set-continuous-option.d.ts +3 -0
  90. package/src/migrations/update-21-0-0/set-continuous-option.js +29 -0
  91. package/src/plugins/plugin.js +2 -0
  92. package/src/utils/backward-compatible-versions.js +2 -0
  93. package/src/utils/nx-devkit/ast-utils.d.ts +0 -8
  94. package/src/utils/nx-devkit/ast-utils.js +7 -12
  95. package/src/utils/versions.d.ts +7 -6
  96. package/src/utils/versions.js +8 -7
  97. package/fesm2022/nx-angular-testing.mjs +0 -45
  98. package/fesm2022/nx-angular-testing.mjs.map +0 -1
  99. package/src/migrations/update-16-0-0/remove-karma-defaults.d.ts +0 -2
  100. package/src/migrations/update-16-0-0/remove-karma-defaults.js +0 -52
  101. package/src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option.d.ts +0 -2
  102. package/src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option.js +0 -40
  103. package/src/migrations/update-16-0-0/remove-protractor-defaults.d.ts +0 -2
  104. package/src/migrations/update-16-0-0/remove-protractor-defaults.js +0 -52
  105. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  106. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  107. package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.d.ts +0 -2
  108. package/src/migrations/update-16-1-0/extract-standalone-config-from-bootstrap.js +0 -127
  109. package/src/migrations/update-16-1-0/remove-ngcc-invocation.js +0 -22
  110. package/src/migrations/update-16-1-0/remove-render-module-platform-server-exports.d.ts +0 -2
  111. package/src/migrations/update-16-1-0/remove-render-module-platform-server-exports.js +0 -62
  112. package/src/migrations/update-16-1-0/update-server-executor-config.d.ts +0 -2
  113. package/src/migrations/update-16-1-0/update-server-executor-config.js +0 -26
  114. package/src/runtime/nx/data-persistence.d.ts +0 -276
  115. package/testing/index.d.ts +0 -1
  116. package/testing/ng-package.json +0 -6
  117. package/testing/src/testing-utils.d.ts +0 -33
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToRspack = convertToRspack;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ const create_config_1 = require("./lib/create-config");
7
+ const get_custom_webpack_config_1 = require("./lib/get-custom-webpack-config");
8
+ const update_tsconfig_1 = require("./lib/update-tsconfig");
9
+ const validate_supported_executor_1 = require("./lib/validate-supported-executor");
10
+ const posix_1 = require("path/posix");
11
+ const path_1 = require("path");
12
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
13
+ const enquirer_1 = require("enquirer");
14
+ const SUPPORTED_EXECUTORS = [
15
+ '@angular-devkit/build-angular:browser',
16
+ '@angular-devkit/build-angular:dev-server',
17
+ '@angular-devkit/build-angular:server',
18
+ '@nx/angular:webpack-browser',
19
+ '@nx/angular:webpack-server',
20
+ '@nx/angular:dev-server',
21
+ '@nx/angular:module-federation-dev-server',
22
+ ];
23
+ const RENAMED_OPTIONS = {
24
+ main: 'browser',
25
+ ngswConfigPath: 'serviceWorker',
26
+ };
27
+ const DEFAULT_PORT = 4200;
28
+ const REMOVED_OPTIONS = [
29
+ 'buildOptimizer',
30
+ 'buildTarget',
31
+ 'browserTarget',
32
+ 'publicHost',
33
+ ];
34
+ function normalizeFromProjectRoot(tree, path, projectRoot) {
35
+ if (projectRoot === '.') {
36
+ if (!path.startsWith('./')) {
37
+ return `./${path}`;
38
+ }
39
+ else {
40
+ return path;
41
+ }
42
+ }
43
+ else if (path.startsWith(projectRoot)) {
44
+ return path.replace(projectRoot, '.');
45
+ }
46
+ else if (!path.startsWith('./')) {
47
+ if (tree.exists(path)) {
48
+ const pathWithWorkspaceRoot = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, path);
49
+ const projectRootWithWorkspaceRoot = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot);
50
+ return (0, path_1.relative)(projectRootWithWorkspaceRoot, pathWithWorkspaceRoot);
51
+ }
52
+ return `./${path}`;
53
+ }
54
+ return path;
55
+ }
56
+ const defaultNormalizer = (tree, path, root) => normalizeFromProjectRoot(tree, path, root);
57
+ const PATH_NORMALIZER = {
58
+ index: (tree, path, root) => {
59
+ if (typeof path === 'string') {
60
+ return normalizeFromProjectRoot(tree, path, root);
61
+ }
62
+ return {
63
+ input: normalizeFromProjectRoot(tree, path.input, root),
64
+ output: path.output ?? 'index.html',
65
+ };
66
+ },
67
+ indexHtmlTransformer: defaultNormalizer,
68
+ main: defaultNormalizer,
69
+ server: defaultNormalizer,
70
+ tsConfig: defaultNormalizer,
71
+ outputPath: (tree, path, root) => {
72
+ const relativePathFromWorkspaceRoot = (0, path_1.relative)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, root), devkit_1.workspaceRoot);
73
+ return (0, devkit_1.joinPathFragments)(relativePathFromWorkspaceRoot, path);
74
+ },
75
+ proxyConfig: defaultNormalizer,
76
+ polyfills: (tree, paths, root) => {
77
+ const normalizedPaths = [];
78
+ const normalizeFn = (path) => {
79
+ try {
80
+ const resolvedPath = require.resolve(path, {
81
+ paths: [(0, posix_1.join)(devkit_1.workspaceRoot, 'node_modules')],
82
+ });
83
+ normalizedPaths.push(path);
84
+ }
85
+ catch {
86
+ normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
87
+ }
88
+ };
89
+ if (typeof paths === 'string') {
90
+ normalizeFn(paths);
91
+ }
92
+ else {
93
+ for (const path of paths) {
94
+ normalizeFn(path);
95
+ }
96
+ }
97
+ return normalizedPaths;
98
+ },
99
+ styles: (tree, paths, root) => {
100
+ const normalizedPaths = [];
101
+ for (const path of paths) {
102
+ if (typeof path === 'string') {
103
+ normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
104
+ }
105
+ else {
106
+ normalizedPaths.push({
107
+ input: normalizeFromProjectRoot(tree, path.input, root),
108
+ bundleName: path.bundleName,
109
+ inject: path.inject ?? true,
110
+ });
111
+ }
112
+ }
113
+ return normalizedPaths;
114
+ },
115
+ scripts: (tree, paths, root) => {
116
+ const normalizedPaths = [];
117
+ for (const path of paths) {
118
+ if (typeof path === 'string') {
119
+ normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
120
+ }
121
+ else {
122
+ normalizedPaths.push({
123
+ input: normalizeFromProjectRoot(tree, path.input, root),
124
+ bundleName: path.bundleName,
125
+ inject: path.inject ?? true,
126
+ });
127
+ }
128
+ }
129
+ return normalizedPaths;
130
+ },
131
+ assets: (tree, paths, root) => {
132
+ const normalizedPaths = [];
133
+ for (const path of paths) {
134
+ if (typeof path === 'string') {
135
+ normalizedPaths.push(normalizeFromProjectRoot(tree, path, root));
136
+ }
137
+ else {
138
+ normalizedPaths.push({
139
+ ...path,
140
+ input: normalizeFromProjectRoot(tree, path.input, root),
141
+ });
142
+ }
143
+ }
144
+ return normalizedPaths;
145
+ },
146
+ fileReplacements: (tree, paths, root) => {
147
+ const normalizedPaths = [];
148
+ for (const path of paths) {
149
+ normalizedPaths.push({
150
+ replace: normalizeFromProjectRoot(tree, 'src' in path ? path.src : path.replace, root),
151
+ with: normalizeFromProjectRoot(tree, 'replaceWith' in path ? path.replaceWith : path.with, root),
152
+ });
153
+ }
154
+ return normalizedPaths;
155
+ },
156
+ };
157
+ function handleBuildTargetOptions(tree, options, newConfigurationOptions, root) {
158
+ let customWebpackConfigPath;
159
+ if (!options || Object.keys(options).length === 0) {
160
+ return customWebpackConfigPath;
161
+ }
162
+ if (options.customWebpackConfig) {
163
+ customWebpackConfigPath = options.customWebpackConfig.path;
164
+ delete options.customWebpackConfig;
165
+ }
166
+ if (options.outputs) {
167
+ // handled by the Rspack inference plugin
168
+ delete options.outputs;
169
+ }
170
+ for (const [key, value] of Object.entries(options)) {
171
+ let optionName = key;
172
+ let optionValue = key in PATH_NORMALIZER ? PATH_NORMALIZER[key](tree, value, root) : value;
173
+ if (REMOVED_OPTIONS.includes(key)) {
174
+ continue;
175
+ }
176
+ if (key in RENAMED_OPTIONS) {
177
+ optionName = RENAMED_OPTIONS[key];
178
+ }
179
+ newConfigurationOptions[optionName] = optionValue;
180
+ }
181
+ if (typeof newConfigurationOptions.polyfills === 'string') {
182
+ newConfigurationOptions.polyfills = [newConfigurationOptions.polyfills];
183
+ }
184
+ let outputPath = newConfigurationOptions.outputPath;
185
+ if (typeof outputPath === 'string') {
186
+ if (!/\/browser\/?$/.test(outputPath)) {
187
+ console.warn(`The output location of the browser build has been updated from "${outputPath}" to ` +
188
+ `"${(0, posix_1.join)(outputPath, 'browser')}". ` +
189
+ 'You might need to adjust your deployment pipeline or, as an alternative, ' +
190
+ 'set outputPath.browser to "" in order to maintain the previous functionality.');
191
+ }
192
+ else {
193
+ outputPath = outputPath.replace(/\/browser\/?$/, '');
194
+ }
195
+ newConfigurationOptions['outputPath'] = {
196
+ base: outputPath,
197
+ };
198
+ if (typeof newConfigurationOptions.resourcesOutputPath === 'string') {
199
+ const media = newConfigurationOptions.resourcesOutputPath.replaceAll('/', '');
200
+ if (media && media !== 'media') {
201
+ newConfigurationOptions['outputPath'] = {
202
+ base: outputPath,
203
+ media,
204
+ };
205
+ }
206
+ }
207
+ }
208
+ return customWebpackConfigPath;
209
+ }
210
+ function handleDevServerTargetOptions(tree, options, newConfigurationOptions, root) {
211
+ for (const [key, value] of Object.entries(options)) {
212
+ let optionName = key;
213
+ let optionValue = key in PATH_NORMALIZER ? PATH_NORMALIZER[key](tree, value, root) : value;
214
+ if (REMOVED_OPTIONS.includes(key)) {
215
+ continue;
216
+ }
217
+ if (key in RENAMED_OPTIONS) {
218
+ optionName = RENAMED_OPTIONS[key];
219
+ }
220
+ newConfigurationOptions[optionName] = optionValue;
221
+ }
222
+ }
223
+ async function getProjectToConvert(tree) {
224
+ const projects = new Set();
225
+ for (const executor of SUPPORTED_EXECUTORS) {
226
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, executor, (_, project) => {
227
+ projects.add(project);
228
+ });
229
+ }
230
+ const { project } = await (0, enquirer_1.prompt)({
231
+ type: 'select',
232
+ name: 'project',
233
+ message: 'Which project would you like to convert to rspack?',
234
+ choices: Array.from(projects),
235
+ });
236
+ return project;
237
+ }
238
+ async function convertToRspack(tree, schema) {
239
+ let { project: projectName } = schema;
240
+ if (!projectName) {
241
+ projectName = await getProjectToConvert(tree);
242
+ }
243
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
244
+ const tasks = [];
245
+ const createConfigOptions = {
246
+ root: project.root,
247
+ };
248
+ const configurationOptions = {};
249
+ const buildTargetNames = [];
250
+ const serveTargetNames = [];
251
+ let customWebpackConfigPath;
252
+ (0, validate_supported_executor_1.validateSupportedBuildExecutor)(Object.values(project.targets));
253
+ let projectServePort = DEFAULT_PORT;
254
+ for (const [targetName, target] of Object.entries(project.targets)) {
255
+ if (target.executor === '@angular-devkit/build-angular:browser' ||
256
+ target.executor === '@nx/angular:webpack-browser') {
257
+ customWebpackConfigPath = handleBuildTargetOptions(tree, target.options, createConfigOptions, project.root);
258
+ if (target.configurations) {
259
+ for (const [configurationName, configuration] of Object.entries(target.configurations)) {
260
+ configurationOptions[configurationName] = {};
261
+ handleBuildTargetOptions(tree, configuration, configurationOptions[configurationName], project.root);
262
+ }
263
+ }
264
+ buildTargetNames.push(targetName);
265
+ }
266
+ else if (target.executor === '@angular-devkit/build-angular:server' ||
267
+ target.executor === '@nx/angular:webpack-server') {
268
+ createConfigOptions.ssr ??= {};
269
+ createConfigOptions.ssr.entry ??= normalizeFromProjectRoot(tree, target.options.main, project.root);
270
+ createConfigOptions.server = './src/main.server.ts';
271
+ buildTargetNames.push(targetName);
272
+ }
273
+ else if (target.executor === '@angular-devkit/build-angular:dev-server' ||
274
+ target.executor === '@nx/angular:dev-server' ||
275
+ target.executor === '@nx/angular:module-federation-dev-server') {
276
+ createConfigOptions.devServer = {};
277
+ if (target.options) {
278
+ handleDevServerTargetOptions(tree, target.options, createConfigOptions.devServer, project.root);
279
+ if (target.options.port !== DEFAULT_PORT) {
280
+ projectServePort = target.options.port;
281
+ }
282
+ }
283
+ if (target.configurations) {
284
+ for (const [configurationName, configuration] of Object.entries(target.configurations)) {
285
+ configurationOptions[configurationName] ??= {};
286
+ configurationOptions[configurationName].devServer ??= {};
287
+ handleDevServerTargetOptions(tree, configuration, configurationOptions[configurationName].devServer, project.root);
288
+ }
289
+ }
290
+ serveTargetNames.push(targetName);
291
+ }
292
+ }
293
+ const customWebpackConfigInfo = customWebpackConfigPath
294
+ ? await (0, get_custom_webpack_config_1.getCustomWebpackConfig)(tree, project.root, customWebpackConfigPath)
295
+ : undefined;
296
+ (0, create_config_1.createConfig)(tree, createConfigOptions, configurationOptions, customWebpackConfigInfo?.normalizedPathToCustomWebpackConfig, customWebpackConfigInfo?.isWebpackConfigFunction);
297
+ (0, update_tsconfig_1.updateTsconfig)(tree, project.root);
298
+ for (const targetName of [...buildTargetNames, ...serveTargetNames]) {
299
+ delete project.targets[targetName];
300
+ }
301
+ if (projectServePort !== DEFAULT_PORT) {
302
+ project.targets.serve ??= {};
303
+ project.targets.serve.options ??= {};
304
+ project.targets.serve.options.port = projectServePort;
305
+ }
306
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
307
+ const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
308
+ await rspackInitGenerator(tree, {
309
+ addPlugin: true,
310
+ });
311
+ // This is needed to prevent a circular execution of the build target
312
+ const rootPkgJson = (0, devkit_1.readJson)(tree, 'package.json');
313
+ if (rootPkgJson.scripts?.build === 'nx build') {
314
+ delete rootPkgJson.scripts.build;
315
+ (0, devkit_1.writeJson)(tree, 'package.json', rootPkgJson);
316
+ }
317
+ if (!schema.skipInstall) {
318
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
319
+ '@nx/angular-rspack': versions_1.angularRspackVersion,
320
+ 'ts-node': versions_1.tsNodeVersion,
321
+ });
322
+ tasks.push(installTask);
323
+ }
324
+ if (!schema.skipFormat) {
325
+ await (0, devkit_1.formatFiles)(tree);
326
+ }
327
+ return (0, devkit_1.runTasksInSerial)(...tasks);
328
+ }
329
+ exports.default = convertToRspack;
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function createConfig(tree: Tree, opts: Record<string, any>, configurationOptions?: Record<string, Record<string, any>>, existingWebpackConfigPath?: string, isExistingWebpackConfigFunction?: boolean): void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfig = createConfig;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function createConfig(tree, opts, configurationOptions = {}, existingWebpackConfigPath, isExistingWebpackConfigFunction) {
6
+ const { root, ...createConfigOptions } = opts;
7
+ const hasConfigurations = Object.keys(configurationOptions).length > 0;
8
+ const expandedConfigurationOptions = hasConfigurations
9
+ ? Object.entries(configurationOptions)
10
+ .map(([configurationName, configurationOptions]) => {
11
+ return `
12
+ "${configurationName}": {
13
+ options: {
14
+ ${JSON.stringify(configurationOptions, undefined, 2).slice(1, -1)}
15
+ }
16
+ }`;
17
+ })
18
+ .join(',\n')
19
+ : '';
20
+ const createConfigContents = `createConfig({
21
+ options: {
22
+ root: __dirname,
23
+ ${JSON.stringify(createConfigOptions, undefined, 2).slice(1, -1)}
24
+ }
25
+ }${hasConfigurations ? `, {${expandedConfigurationOptions}}` : ''});`;
26
+ const configContents = `
27
+ import { createConfig }from '@nx/angular-rspack';
28
+ ${existingWebpackConfigPath
29
+ ? `import baseWebpackConfig from '${existingWebpackConfigPath}';
30
+ ${isExistingWebpackConfigFunction
31
+ ? ''
32
+ : `import webpackMerge from 'webpack-merge';`}`
33
+ : ''}
34
+
35
+ ${existingWebpackConfigPath
36
+ ? `export default async () => {
37
+ const baseConfig = await ${createConfigContents}
38
+ ${isExistingWebpackConfigFunction
39
+ ? `const oldConfig = await baseWebpackConfig;
40
+ const browserConfig = baseConfig[0];
41
+ return oldConfig(browserConfig);`
42
+ : 'return webpackMerge(baseConfig[0], baseWebpackConfig);'}};`
43
+ : `export default ${createConfigContents}`}`;
44
+ tree.write((0, devkit_1.joinPathFragments)(root, 'rspack.config.ts'), configContents);
45
+ }
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function getCustomWebpackConfig(tree: Tree, projectRoot: string, pathToCustomWebpackConfig: string): Promise<{
3
+ isWebpackConfigFunction: boolean;
4
+ normalizedPathToCustomWebpackConfig: string;
5
+ }>;
6
+ export declare function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents: string): string;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCustomWebpackConfig = getCustomWebpackConfig;
4
+ exports.convertWebpackConfigToUseNxModuleFederationPlugin = convertWebpackConfigToUseNxModuleFederationPlugin;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
7
+ const path_1 = require("path");
8
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
9
+ const FILE_EXTENSION_REGEX = /\.[^.]+$/;
10
+ async function getCustomWebpackConfig(tree, projectRoot, pathToCustomWebpackConfig) {
11
+ const webpackConfigContents = tree.read(pathToCustomWebpackConfig, 'utf-8');
12
+ if (webpackConfigContents.includes('@nx/module-federation/angular') &&
13
+ webpackConfigContents.includes('withModuleFederation')) {
14
+ tree.write(pathToCustomWebpackConfig, convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents));
15
+ return {
16
+ isWebpackConfigFunction: false,
17
+ normalizedPathToCustomWebpackConfig: `./${(0, path_1.relative)(projectRoot, pathToCustomWebpackConfig).replace(FILE_EXTENSION_REGEX, '')}`,
18
+ };
19
+ }
20
+ const configFile = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(tree.root, pathToCustomWebpackConfig));
21
+ const webpackConfig = 'default' in configFile ? configFile.default : configFile;
22
+ return {
23
+ isWebpackConfigFunction: typeof webpackConfig === 'function',
24
+ normalizedPathToCustomWebpackConfig: `./${(0, path_1.relative)(projectRoot, pathToCustomWebpackConfig).replace(FILE_EXTENSION_REGEX, '')}`,
25
+ };
26
+ }
27
+ function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents) {
28
+ let newWebpackConfigContents = webpackConfigContents;
29
+ let ast = tsquery_1.tsquery.ast(webpackConfigContents);
30
+ const withModuleFederationImportNodes = (0, tsquery_1.tsquery)(ast, 'ImportDeclaration:has(StringLiteral[value=@nx/module-federation/angular])');
31
+ if (withModuleFederationImportNodes.length > 0) {
32
+ const withModuleFederationImportNode = withModuleFederationImportNodes[0];
33
+ newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationImportNode.getStart())}import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack';${webpackConfigContents.slice(withModuleFederationImportNode.getEnd())}`;
34
+ ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
35
+ const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExportAssignment:has(CallExpression > Identifier[name=withModuleFederation])');
36
+ if (exportedWithModuleFederationNodes.length > 0) {
37
+ const exportedWithModuleFederationNode = exportedWithModuleFederationNodes[0];
38
+ newWebpackConfigContents = `${newWebpackConfigContents.slice(0, exportedWithModuleFederationNode.getStart())}${newWebpackConfigContents.slice(exportedWithModuleFederationNode.getEnd())}
39
+ export default {
40
+ plugins: [
41
+ new NxModuleFederationPlugin({ config }, {
42
+ dts: false,
43
+ }),
44
+ new NxModuleFederationDevServerPlugin({ config }),
45
+ ]
46
+ }
47
+ `;
48
+ }
49
+ else {
50
+ devkit_1.logger.warn("Could not find 'export default withModuleFederation' in the webpack config file. Skipping conversion.");
51
+ }
52
+ }
53
+ const withModuleFederationRequireNodes = (0, tsquery_1.tsquery)(ast, 'VariableStatement:has(CallExpression > Identifier[name=withModuleFederation], StringLiteral[value=@nx/module-federation/angular])');
54
+ if (withModuleFederationRequireNodes.length > 0) {
55
+ const withModuleFederationRequireNode = withModuleFederationRequireNodes[0];
56
+ newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationRequireNode.getStart())}const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');${webpackConfigContents.slice(withModuleFederationRequireNode.getEnd())}`;
57
+ ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
58
+ const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExpressionStatement:has(BinaryExpression > PropertyAccessExpression:has(Identifier[name=module], Identifier[name=exports]), CallExpression:has(Identifier[name=withModuleFederation]))');
59
+ if (exportedWithModuleFederationNodes.length > 0) {
60
+ const exportedWithModuleFederationNode = exportedWithModuleFederationNodes[0];
61
+ newWebpackConfigContents = `${newWebpackConfigContents.slice(0, exportedWithModuleFederationNode.getStart())}${newWebpackConfigContents.slice(exportedWithModuleFederationNode.getEnd())}
62
+ module.exports = {
63
+ plugins: [
64
+ new NxModuleFederationPlugin({ config }, {
65
+ dts: false,
66
+ }),
67
+ new NxModuleFederationDevServerPlugin({ config }),
68
+ ]
69
+ }
70
+ `;
71
+ }
72
+ else {
73
+ devkit_1.logger.warn("Could not find 'module.exports = withModuleFederation' in the webpack config file. Skipping conversion.");
74
+ }
75
+ }
76
+ return newWebpackConfigContents;
77
+ }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function updateTsconfig(tree: Tree, projectRoot: string): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTsconfig = updateTsconfig;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ function updateTsconfig(tree, projectRoot) {
7
+ const tsconfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json');
8
+ const tsconfig = (0, devkit_1.readJson)(tree, tsconfigPath);
9
+ tsconfig['ts-node'] ??= {};
10
+ tsconfig['ts-node'].compilerOptions ??= {};
11
+ tsconfig['ts-node'].compilerOptions.module = 'CommonJS';
12
+ tsconfig['ts-node'].compilerOptions.moduleResolution = 'Node10';
13
+ if (tsconfig.compilerOptions?.customConditions) {
14
+ tsconfig['ts-node'].compilerOptions.customConditions = null;
15
+ }
16
+ else {
17
+ const rootTsconfigFile = (0, js_1.getRootTsConfigFileName)(tree);
18
+ if (rootTsconfigFile) {
19
+ const rootTsconfigJson = (0, devkit_1.readJson)(tree, rootTsconfigFile);
20
+ if (rootTsconfigJson.compilerOptions?.customConditions) {
21
+ tsconfig['ts-node'].compilerOptions.customConditions = null;
22
+ }
23
+ }
24
+ }
25
+ (0, devkit_1.writeJson)(tree, tsconfigPath, tsconfig);
26
+ }
@@ -0,0 +1,2 @@
1
+ import { TargetConfiguration } from '@nx/devkit';
2
+ export declare function validateSupportedBuildExecutor(targets: TargetConfiguration[]): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSupportedBuildExecutor = validateSupportedBuildExecutor;
4
+ const SUPPORTED_BUILD_EXECUTORS = [
5
+ '@angular-devkit/build-angular:browser',
6
+ '@nx/angular:webpack-browser',
7
+ ];
8
+ function validateSupportedBuildExecutor(targets) {
9
+ const executorsUsedByProject = targets.map((target) => target.executor);
10
+ if (!executorsUsedByProject.some((executor) => SUPPORTED_BUILD_EXECUTORS.includes(executor))) {
11
+ throw new Error('The project does not use a supported build executor. Please use one of the following executors: ' +
12
+ SUPPORTED_BUILD_EXECUTORS.join(', '));
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ export interface ConvertToRspackSchema {
2
+ project: string;
3
+ skipFormat?: boolean;
4
+ skipInstall?: boolean;
5
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "GeneratorNxApp",
4
+ "title": "Creates an Angular application.",
5
+ "description": "Creates an Angular application.",
6
+ "type": "object",
7
+ "cli": "nx",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "aliases": ["name", "projectName"],
12
+ "description": "Project for which to convert to rspack.",
13
+ "$default": {
14
+ "$source": "argv",
15
+ "index": 0
16
+ },
17
+ "x-priority": "important"
18
+ },
19
+ "skipFormat": {
20
+ "description": "Skip formatting files.",
21
+ "type": "boolean",
22
+ "default": false
23
+ },
24
+ "skipInstall": {
25
+ "description": "Skip installing dependencies.",
26
+ "type": "boolean",
27
+ "default": false
28
+ }
29
+ }
30
+ }
@@ -39,7 +39,7 @@ async function host(tree, schema) {
39
39
  }
40
40
  });
41
41
  }
42
- await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'application');
42
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
43
43
  const { projectName: hostProjectName, projectRoot: appRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
44
44
  name: options.name,
45
45
  projectType: 'application',
@@ -20,7 +20,6 @@ export interface Schema {
20
20
  e2eTestRunner?: E2eTestRunner;
21
21
  backendProject?: string;
22
22
  strict?: boolean;
23
- standaloneConfig?: boolean;
24
23
  inlineStyle?: boolean;
25
24
  inlineTemplate?: boolean;
26
25
  viewEncapsulation?: 'Emulated' | 'Native' | 'None';
@@ -144,12 +144,6 @@
144
144
  "description": "Create an application with stricter type checking and build optimization options.",
145
145
  "default": true
146
146
  },
147
- "standaloneConfig": {
148
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
149
- "type": "boolean",
150
- "default": true,
151
- "x-deprecated": "Nx only supports standaloneConfig"
152
- },
153
147
  "setParserOptionsProject": {
154
148
  "type": "boolean",
155
149
  "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
@@ -1,4 +1,4 @@
1
1
  import type { Tree } from '@nx/devkit';
2
2
  import type { AngularProjectConfiguration } from '../../../utils/types';
3
3
  import type { NormalizedSchema } from './normalized-schema';
4
- export declare function addProject(tree: Tree, libraryOptions: NormalizedSchema['libraryOptions']): AngularProjectConfiguration;
4
+ export declare function addProject(tree: Tree, libraryOptions: NormalizedSchema['libraryOptions']): Promise<AngularProjectConfiguration>;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = addProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
- function addProject(tree, libraryOptions) {
6
+ const add_release_config_1 = require("@nx/js/src/generators/library/utils/add-release-config");
7
+ const use_legacy_versioning_1 = require("nx/src/command-line/release/config/use-legacy-versioning");
8
+ async function addProject(tree, libraryOptions) {
7
9
  const project = {
8
10
  name: libraryOptions.name,
9
11
  root: libraryOptions.projectRoot,
@@ -34,6 +36,10 @@ function addProject(tree, libraryOptions) {
34
36
  },
35
37
  defaultConfiguration: 'production',
36
38
  };
39
+ if (libraryOptions.publishable) {
40
+ const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
41
+ await (0, add_release_config_1.addReleaseConfigForNonTsSolution)((0, use_legacy_versioning_1.shouldUseLegacyVersioning)(nxJson.release), tree, libraryOptions.name, project);
42
+ }
37
43
  }
38
44
  (0, devkit_1.addProjectConfiguration)(tree, libraryOptions.name, project);
39
45
  return project;
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
- const eslint_1 = require("@nx/eslint");
7
6
  const test_runners_1 = require("../../../utils/test-runners");
8
7
  async function normalizeOptions(host, schema) {
9
8
  schema.standalone = schema.standalone ?? true;
10
9
  // Create a schema with populated default values
11
10
  const options = {
12
11
  buildable: false,
13
- linter: eslint_1.Linter.EsLint,
12
+ linter: 'eslint',
14
13
  publishable: false,
15
14
  simpleName: false,
16
15
  skipFormat: false,
@@ -22,7 +21,7 @@ async function normalizeOptions(host, schema) {
22
21
  skipModule: schema.skipModule || schema.standalone,
23
22
  ...schema,
24
23
  };
25
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
24
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
26
25
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
27
26
  name: options.name,
28
27
  projectType: 'library',
@@ -40,7 +39,7 @@ async function normalizeOptions(host, schema) {
40
39
  const ngCliSchematicLibRoot = projectName;
41
40
  const allNormalizedOptions = {
42
41
  ...options,
43
- linter: options.linter ?? eslint_1.Linter.EsLint,
42
+ linter: options.linter ?? 'eslint',
44
43
  unitTestRunner: options.unitTestRunner ?? test_runners_1.UnitTestRunner.Jest,
45
44
  prefix: options.prefix ?? 'lib',
46
45
  name: projectName,
@@ -12,7 +12,6 @@ export interface NormalizedSchema {
12
12
  buildable?: boolean;
13
13
  publishable?: boolean;
14
14
  importPath?: string;
15
- standaloneConfig?: boolean;
16
15
  spec?: boolean;
17
16
  commonModule?: boolean;
18
17
  routing?: boolean;