@nx/react 16.8.0-beta.3 → 16.8.0-beta.5

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 (76) hide show
  1. package/babel.js +2 -3
  2. package/package.json +7 -7
  3. package/plugins/bundle-rollup.js +9 -3
  4. package/plugins/component-testing/index.js +57 -37
  5. package/plugins/jest.js +4 -6
  6. package/plugins/storybook/index.js +46 -17
  7. package/plugins/with-react.js +5 -9
  8. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +101 -103
  9. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +67 -72
  10. package/src/generators/application/application.js +124 -124
  11. package/src/generators/application/lib/add-e2e.js +41 -37
  12. package/src/generators/application/lib/add-jest.js +13 -8
  13. package/src/generators/application/lib/add-project.js +4 -3
  14. package/src/generators/application/lib/create-application-files.js +8 -1
  15. package/src/generators/application/lib/find-free-port.js +1 -2
  16. package/src/generators/application/lib/normalize-options.js +49 -47
  17. package/src/generators/application/lib/set-defaults.js +25 -5
  18. package/src/generators/component/component.js +68 -64
  19. package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -9
  20. package/src/generators/component-story/component-story.js +8 -9
  21. package/src/generators/component-test/component-test.js +15 -18
  22. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -26
  23. package/src/generators/cypress-component-configuration/lib/add-files.js +38 -42
  24. package/src/generators/hook/hook.js +59 -58
  25. package/src/generators/host/host.js +54 -53
  26. package/src/generators/host/lib/add-module-federation-files.js +11 -3
  27. package/src/generators/host/lib/normalize-remote.js +8 -11
  28. package/src/generators/host/lib/setup-ssr-for-host.js +21 -15
  29. package/src/generators/host/lib/update-module-federation-e2e-project.js +5 -2
  30. package/src/generators/init/init.js +30 -20
  31. package/src/generators/library/lib/add-linting.js +24 -27
  32. package/src/generators/library/lib/add-rollup-build-target.js +42 -46
  33. package/src/generators/library/lib/create-files.js +7 -1
  34. package/src/generators/library/lib/normalize-options.js +53 -50
  35. package/src/generators/library/lib/set-defaults.js +12 -4
  36. package/src/generators/library/library.js +122 -111
  37. package/src/generators/redux/redux.js +25 -16
  38. package/src/generators/remote/lib/setup-ssr-for-remote.js +25 -23
  39. package/src/generators/remote/remote.js +44 -39
  40. package/src/generators/setup-ssr/setup-ssr.js +134 -132
  41. package/src/generators/setup-tailwind/lib/update-project.js +3 -5
  42. package/src/generators/setup-tailwind/setup-tailwind.js +23 -26
  43. package/src/generators/stories/stories.js +79 -88
  44. package/src/generators/storybook-configuration/configuration.js +40 -47
  45. package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +2 -5
  46. package/src/migrations/update-12-0-0/update-emotion-setup.js +50 -55
  47. package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +14 -18
  48. package/src/migrations/update-12-8-0/update-12-8-0.js +3 -6
  49. package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +23 -26
  50. package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
  51. package/src/migrations/update-13-0-0/webpack5-changes-utils.js +30 -34
  52. package/src/migrations/update-13-10-0/update-13-10-0.js +15 -18
  53. package/src/migrations/update-14-0-0/add-default-development-configurations.js +26 -31
  54. package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +12 -16
  55. package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +13 -17
  56. package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +24 -27
  57. package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -2
  58. package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +3 -4
  59. package/src/migrations/update-15-3-0/update-rollup-executor.js +1 -2
  60. package/src/migrations/update-15-6-3/webpack-config-setup.js +56 -60
  61. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  62. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +3 -6
  63. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +3 -6
  64. package/src/migrations/update-16-7-0/add-babel-core.js +8 -11
  65. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +36 -41
  66. package/src/module-federation/ast-utils.js +1 -1
  67. package/src/module-federation/load-config.js +1 -1
  68. package/src/module-federation/utils.js +36 -37
  69. package/src/module-federation/with-module-federation-ssr.js +24 -25
  70. package/src/module-federation/with-module-federation.js +23 -22
  71. package/src/rules/update-module-federation-project.js +9 -2
  72. package/src/utils/ast-utils.js +12 -15
  73. package/src/utils/create-ts-config.js +6 -4
  74. package/src/utils/ct-utils.js +31 -33
  75. package/src/utils/lint.js +5 -3
  76. package/src/utils/testing-generators.js +18 -22
@@ -1,39 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.update = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
- function update(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const projects = (0, devkit_1.getProjects)(tree);
9
- projects.forEach((config, name) => {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
11
- var _l, _m, _o, _p, _q, _r;
12
- let shouldUpdate = false;
13
- if (((_b = (_a = config.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) === '@nrwl/web:webpack') {
14
- shouldUpdate = true;
15
- (_c = (_l = config.targets.build).defaultConfiguration) !== null && _c !== void 0 ? _c : (_l.defaultConfiguration = 'production');
16
- (_d = (_m = config.targets.build).configurations) !== null && _d !== void 0 ? _d : (_m.configurations = {});
17
- (_e = (_o = config.targets.build.configurations).development) !== null && _e !== void 0 ? _e : (_o.development = {
18
- extractLicenses: false,
19
- optimization: false,
20
- sourceMap: true,
21
- vendorChunk: true,
22
- });
23
- }
24
- if (((_g = (_f = config.targets) === null || _f === void 0 ? void 0 : _f.serve) === null || _g === void 0 ? void 0 : _g.executor) === '@nrwl/web:dev-server') {
25
- shouldUpdate = true;
26
- (_h = (_p = config.targets.serve).defaultConfiguration) !== null && _h !== void 0 ? _h : (_p.defaultConfiguration = 'development');
27
- (_j = (_q = config.targets.serve).configurations) !== null && _j !== void 0 ? _j : (_q.configurations = {});
28
- (_k = (_r = config.targets.serve.configurations).development) !== null && _k !== void 0 ? _k : (_r.development = {
29
- buildTarget: `${name}:build:development`,
30
- });
31
- }
32
- if (shouldUpdate)
33
- (0, devkit_1.updateProjectConfiguration)(tree, name, config);
34
- });
35
- yield (0, devkit_1.formatFiles)(tree);
5
+ async function update(tree) {
6
+ const projects = (0, devkit_1.getProjects)(tree);
7
+ projects.forEach((config, name) => {
8
+ let shouldUpdate = false;
9
+ if (config.targets?.build?.executor === '@nrwl/web:webpack') {
10
+ shouldUpdate = true;
11
+ config.targets.build.defaultConfiguration ??= 'production';
12
+ config.targets.build.configurations ??= {};
13
+ config.targets.build.configurations.development ??= {
14
+ extractLicenses: false,
15
+ optimization: false,
16
+ sourceMap: true,
17
+ vendorChunk: true,
18
+ };
19
+ }
20
+ if (config.targets?.serve?.executor === '@nrwl/web:dev-server') {
21
+ shouldUpdate = true;
22
+ config.targets.serve.defaultConfiguration ??= 'development';
23
+ config.targets.serve.configurations ??= {};
24
+ config.targets.serve.configurations.development ??= {
25
+ buildTarget: `${name}:build:development`,
26
+ };
27
+ }
28
+ if (shouldUpdate)
29
+ (0, devkit_1.updateProjectConfiguration)(tree, name, config);
36
30
  });
31
+ await (0, devkit_1.formatFiles)(tree);
37
32
  }
38
33
  exports.update = update;
39
34
  exports.default = update;
@@ -1,26 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.update = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
- function update(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const projects = (0, devkit_1.getProjects)(tree);
9
- projects.forEach((config) => {
10
- var _a, _b;
11
- if (((_b = (_a = config.targets) === null || _a === void 0 ? void 0 : _a.test) === null || _b === void 0 ? void 0 : _b.executor) !== '@nrwl/jest:jest')
5
+ async function update(tree) {
6
+ const projects = (0, devkit_1.getProjects)(tree);
7
+ projects.forEach((config) => {
8
+ if (config.targets?.test?.executor !== '@nrwl/jest:jest')
9
+ return;
10
+ (0, devkit_1.visitNotIgnoredFiles)(tree, config.sourceRoot, (file) => {
11
+ if (!file.endsWith('.spec.ts'))
12
12
  return;
13
- (0, devkit_1.visitNotIgnoredFiles)(tree, config.sourceRoot, (file) => {
14
- if (!file.endsWith('.spec.ts'))
15
- return;
16
- const content = tree.read(file).toString();
17
- if (content.includes('@testing-library/react-hooks')) {
18
- tree.write(file, content.replace(/@testing-library\/react-hooks/g, '@testing-library/react'));
19
- }
20
- });
13
+ const content = tree.read(file).toString();
14
+ if (content.includes('@testing-library/react-hooks')) {
15
+ tree.write(file, content.replace(/@testing-library\/react-hooks/g, '@testing-library/react'));
16
+ }
21
17
  });
22
- (0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@testing-library/react-hooks'], ['@testing-library/react-hooks']);
23
18
  });
19
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@testing-library/react-hooks'], ['@testing-library/react-hooks']);
24
20
  }
25
21
  exports.update = update;
26
22
  exports.default = update;
@@ -1,27 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.migrateReactDomRender = exports.update = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const js_1 = require("@nx/js");
7
6
  const ts = require("typescript");
8
- function update(tree) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const projects = (0, devkit_1.getProjects)(tree);
11
- projects.forEach((config, name) => {
12
- var _a, _b;
13
- const isReactProject = ((_b = (_a = config.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) === '@nrwl/web:webpack' &&
14
- /main\.(t|j)sx?$/.test(config.targets.build.options.main);
15
- if (isReactProject) {
16
- const sourcePath = config.targets.build.options.main;
17
- const sourceCode = tree.read(sourcePath).toString();
18
- const source = ts.createSourceFile(sourcePath, sourceCode, ts.ScriptTarget.Latest, true);
19
- const result = (0, devkit_1.applyChangesToString)(sourceCode, migrateReactDomRender(sourcePath, source));
20
- tree.write(sourcePath, result);
21
- }
22
- });
23
- yield (0, devkit_1.formatFiles)(tree);
7
+ async function update(tree) {
8
+ const projects = (0, devkit_1.getProjects)(tree);
9
+ projects.forEach((config, name) => {
10
+ const isReactProject = config.targets?.build?.executor === '@nrwl/web:webpack' &&
11
+ /main\.(t|j)sx?$/.test(config.targets.build.options.main);
12
+ if (isReactProject) {
13
+ const sourcePath = config.targets.build.options.main;
14
+ const sourceCode = tree.read(sourcePath).toString();
15
+ const source = ts.createSourceFile(sourcePath, sourceCode, ts.ScriptTarget.Latest, true);
16
+ const result = (0, devkit_1.applyChangesToString)(sourceCode, migrateReactDomRender(sourcePath, source));
17
+ tree.write(sourcePath, result);
18
+ }
24
19
  });
20
+ await (0, devkit_1.formatFiles)(tree);
25
21
  }
26
22
  exports.update = update;
27
23
  function migrateReactDomRender(sourcePath, source) {
@@ -1,36 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateExternalEmotionJsxRuntime = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
7
- function updateExternalEmotionJsxRuntime(tree) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/web:rollup', (options, projectName, targetName, configurationName) => {
10
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
11
- const config = configurationName
12
- ? projectConfiguration.targets[targetName].configurations[configurationName]
13
- : projectConfiguration.targets[targetName].options;
14
- if (config.external && config.external.length > 0) {
15
- const hasEmotionStyledBase = config.external.includes('@emotion/styled/base');
16
- const hasReactJsxRuntime = config.external.includes('react/jsx-runtime');
17
- if (hasEmotionStyledBase && hasReactJsxRuntime) {
18
- // Replace 'react/jsx-runtime' with '@emotion/react/jsx-runtime'
19
- config.external.forEach((value, index) => {
20
- if (value === 'react/jsx-runtime') {
21
- config.external.splice(index, 1, '@emotion/react/jsx-runtime');
22
- }
23
- });
24
- // Remove '@emotion/styled/base'
25
- config.external.forEach((value, index) => {
26
- if (value === '@emotion/styled/base') {
27
- config.external.splice(index, 1);
28
- }
29
- });
30
- }
31
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
6
+ async function updateExternalEmotionJsxRuntime(tree) {
7
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/web:rollup', (options, projectName, targetName, configurationName) => {
8
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
9
+ const config = configurationName
10
+ ? projectConfiguration.targets[targetName].configurations[configurationName]
11
+ : projectConfiguration.targets[targetName].options;
12
+ if (config.external && config.external.length > 0) {
13
+ const hasEmotionStyledBase = config.external.includes('@emotion/styled/base');
14
+ const hasReactJsxRuntime = config.external.includes('react/jsx-runtime');
15
+ if (hasEmotionStyledBase && hasReactJsxRuntime) {
16
+ // Replace 'react/jsx-runtime' with '@emotion/react/jsx-runtime'
17
+ config.external.forEach((value, index) => {
18
+ if (value === 'react/jsx-runtime') {
19
+ config.external.splice(index, 1, '@emotion/react/jsx-runtime');
20
+ }
21
+ });
22
+ // Remove '@emotion/styled/base'
23
+ config.external.forEach((value, index) => {
24
+ if (value === '@emotion/styled/base') {
25
+ config.external.splice(index, 1);
26
+ }
27
+ });
32
28
  }
33
- });
29
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
30
+ }
34
31
  });
35
32
  }
36
33
  exports.updateExternalEmotionJsxRuntime = updateExternalEmotionJsxRuntime;
@@ -19,7 +19,6 @@ function addBabelJestPresetTransformerOption(tree) {
19
19
  }
20
20
  exports.addBabelJestPresetTransformerOption = addBabelJestPresetTransformerOption;
21
21
  function isReactProject(tree, projectConfig) {
22
- var _a, _b;
23
22
  const knownInvalidExecutors = [
24
23
  '@nrwl/next:build',
25
24
  '@nrwl/angular',
@@ -30,7 +29,7 @@ function isReactProject(tree, projectConfig) {
30
29
  'nx:run-commands',
31
30
  '@nrwl/node:webpack',
32
31
  ];
33
- if (knownInvalidExecutors.includes((_b = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) ||
32
+ if (knownInvalidExecutors.includes(projectConfig?.targets?.build?.executor) ||
34
33
  tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'next.config.js'))) {
35
34
  return false;
36
35
  }
@@ -4,13 +4,12 @@ exports.installWebpackRollupDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../../utils/versions");
6
6
  function installWebpackRollupDependencies(tree) {
7
- var _a, _b, _c, _d, _e, _f;
8
7
  const projects = (0, devkit_1.getProjects)(tree);
9
8
  let shouldInstall = false;
10
9
  for (const [, project] of projects) {
11
- if (((_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) === '@nrwl/webpack:webpack' ||
12
- ((_d = (_c = project.targets) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.executor) === '@nrwl/rollup:rollup' ||
13
- ((_f = (_e = project.targets) === null || _e === void 0 ? void 0 : _e.build) === null || _f === void 0 ? void 0 : _f.executor) === '@nrwl/web:rollup') {
10
+ if (project.targets?.build?.executor === '@nrwl/webpack:webpack' ||
11
+ project.targets?.build?.executor === '@nrwl/rollup:rollup' ||
12
+ project.targets?.build?.executor === '@nrwl/web:rollup') {
14
13
  shouldInstall = true;
15
14
  break;
16
15
  }
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateRollupExecutor = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  function updateRollupExecutor(tree) {
6
- var _a, _b;
7
6
  const projects = (0, devkit_1.getProjects)(tree);
8
7
  for (const [name, project] of projects) {
9
- if (((_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) === '@nrwl/web:rollup') {
8
+ if (project.targets?.build?.executor === '@nrwl/web:rollup') {
10
9
  project.targets.build.executor = '@nrwl/rollup:rollup';
11
10
  (0, devkit_1.updateProjectConfiguration)(tree, name, project);
12
11
  }
@@ -1,50 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const path_1 = require("path");
7
- function default_1(tree) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- // Since projects can have multiple configurations, we need to know if the default options
10
- // need to be migrated or not. If so then the subsequent configurations with `webpackConfig` also need to be.
11
- const defaultOptionsUpdated = new Set();
12
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', (options, projectName, targetName, configurationName) => {
13
- var _a;
14
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
15
- const defaultOptions = projectConfiguration.targets[targetName].options;
16
- const defaultWasUpdated = defaultOptionsUpdated.has(projectName);
17
- // If default was not updated (for different configurations), we don't do anything
18
- // If isolatedConfig is set, we don't need to do anything
19
- // If it is NOT React, we don't need to do anything
20
- if (!defaultWasUpdated &&
21
- ((defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions['isolatedConfig']) ||
22
- !(((_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions['main']) === null || _a === void 0 ? void 0 : _a.match(/main\.(t|j)sx$/)) ||
23
- (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions['webpackConfig']) === '@nrwl/react/plugins/webpack'))) {
24
- return;
6
+ async function default_1(tree) {
7
+ // Since projects can have multiple configurations, we need to know if the default options
8
+ // need to be migrated or not. If so then the subsequent configurations with `webpackConfig` also need to be.
9
+ const defaultOptionsUpdated = new Set();
10
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', (options, projectName, targetName, configurationName) => {
11
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
12
+ const defaultOptions = projectConfiguration.targets[targetName].options;
13
+ const defaultWasUpdated = defaultOptionsUpdated.has(projectName);
14
+ // If default was not updated (for different configurations), we don't do anything
15
+ // If isolatedConfig is set, we don't need to do anything
16
+ // If it is NOT React, we don't need to do anything
17
+ if (!defaultWasUpdated &&
18
+ (defaultOptions?.['isolatedConfig'] ||
19
+ !(defaultOptions?.['main']?.match(/main\.(t|j)sx$/) ||
20
+ defaultOptions?.['webpackConfig'] === '@nrwl/react/plugins/webpack'))) {
21
+ return;
22
+ }
23
+ defaultOptionsUpdated.add(projectName);
24
+ // If this is not the default options (e.g. for development, production, or something custom),
25
+ // then skip it unless it specifically configures a webpackConfig file
26
+ if (configurationName && !options?.webpackConfig) {
27
+ return;
28
+ }
29
+ // If webpackConfig is set, update it with the new options
30
+ // If webpackConfig is not set, we need to create a new
31
+ // webpack.config.js file and set the path to it in the
32
+ // executor options
33
+ if (options?.['webpackConfig'] &&
34
+ options['webpackConfig'] !== '@nrwl/react/plugins/webpack') {
35
+ let oldName = options['webpackConfig'];
36
+ if (options['webpackConfig'].endsWith('.js')) {
37
+ oldName = options['webpackConfig'].replace('.js', '.old.js');
25
38
  }
26
- defaultOptionsUpdated.add(projectName);
27
- // If this is not the default options (e.g. for development, production, or something custom),
28
- // then skip it unless it specifically configures a webpackConfig file
29
- if (configurationName && !(options === null || options === void 0 ? void 0 : options.webpackConfig)) {
30
- return;
39
+ if (options['webpackConfig'].endsWith('.ts')) {
40
+ oldName = options['webpackConfig'].replace('.ts', '.old.ts');
31
41
  }
32
- // If webpackConfig is set, update it with the new options
33
- // If webpackConfig is not set, we need to create a new
34
- // webpack.config.js file and set the path to it in the
35
- // executor options
36
- if ((options === null || options === void 0 ? void 0 : options['webpackConfig']) &&
37
- options['webpackConfig'] !== '@nrwl/react/plugins/webpack') {
38
- let oldName = options['webpackConfig'];
39
- if (options['webpackConfig'].endsWith('.js')) {
40
- oldName = options['webpackConfig'].replace('.js', '.old.js');
41
- }
42
- if (options['webpackConfig'].endsWith('.ts')) {
43
- oldName = options['webpackConfig'].replace('.ts', '.old.ts');
44
- }
45
- renameFile(tree, options['webpackConfig'], oldName);
46
- const justTheFileName = (0, path_1.basename)(oldName);
47
- tree.write(options['webpackConfig'], `
42
+ renameFile(tree, options['webpackConfig'], oldName);
43
+ const justTheFileName = (0, path_1.basename)(oldName);
44
+ tree.write(options['webpackConfig'], `
48
45
  const { composePlugins, withNx } = require('@nrwl/webpack');
49
46
  const { withReact } = require('@nrwl/react');
50
47
 
@@ -53,30 +50,30 @@ function default_1(tree) {
53
50
  // Note: This was added by an Nx migration.
54
51
  // You should consider inlining the logic into this file.
55
52
  // For more information on webpack config and Nx see:
56
- // https://nx.dev/packages/webpack/documents/webpack-config-setup
53
+ // https://nx.dev/recipes/webpack/webpack-config-setup
57
54
  return require('./${justTheFileName}')(config, context);
58
55
  });
59
56
  `);
60
- options['isolatedConfig'] = true;
61
- projectConfiguration.targets[targetName][configurationName !== null && configurationName !== void 0 ? configurationName : 'options'] = options;
62
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
63
- devkit_1.logger.info(`
57
+ options['isolatedConfig'] = true;
58
+ projectConfiguration.targets[targetName][configurationName ?? 'options'] = options;
59
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
60
+ devkit_1.logger.info(`
64
61
  ${options['webpackConfig']} has been renamed to ${oldName} and a new ${options['webpackConfig']}
65
62
  has been created for your project ${projectName}.
66
63
  You should consider inlining the logic from ${oldName} into ${options['webpackConfig']}.
67
64
  You can read our guide on how to do this here:
68
65
 
69
- https://nx.dev/packages/webpack/documents/webpack-config-setup
66
+ https://nx.dev/recipes/webpack/webpack-config-setup
70
67
  `);
68
+ }
69
+ else {
70
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
71
+ if (!options) {
72
+ options = {};
71
73
  }
72
- else {
73
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
74
- if (!options) {
75
- options = {};
76
- }
77
- options['webpackConfig'] = `${projectConfiguration.root}/webpack.config.js`;
78
- options['isolatedConfig'] = true;
79
- tree.write(options['webpackConfig'], `
74
+ options['webpackConfig'] = `${projectConfiguration.root}/webpack.config.js`;
75
+ options['isolatedConfig'] = true;
76
+ tree.write(options['webpackConfig'], `
80
77
  const { composePlugins, withNx } = require('@nrwl/webpack');
81
78
  const { withReact } = require('@nrwl/react');
82
79
 
@@ -85,16 +82,15 @@ function default_1(tree) {
85
82
  // Update the webpack config as needed here.
86
83
  // e.g. config.plugins.push(new MyPlugin())
87
84
  // For more information on webpack config and Nx see:
88
- // https://nx.dev/packages/webpack/documents/webpack-config-setup
85
+ // https://nx.dev/recipes/webpack/webpack-config-setup
89
86
  return config;
90
87
  });
91
88
  `);
92
- projectConfiguration.targets[targetName].options = options;
93
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
94
- }
95
- });
96
- yield (0, devkit_1.formatFiles)(tree);
89
+ projectConfiguration.targets[targetName].options = options;
90
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
91
+ }
97
92
  });
93
+ await (0, devkit_1.formatFiles)(tree);
98
94
  }
99
95
  exports.default = default_1;
100
96
  function renameFile(tree, from, to) {
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- function replacePackage(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- yield (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/react', '@nx/react');
9
- yield (0, devkit_1.formatFiles)(tree);
10
- });
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/react', '@nx/react');
7
+ await (0, devkit_1.formatFiles)(tree);
11
8
  }
12
9
  exports.default = replacePackage;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
- function removePackage(tree) {
6
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
7
- (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['react-test-renderer']);
8
- yield (0, devkit_1.formatFiles)(tree);
9
- });
4
+ async function removePackage(tree) {
5
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['react-test-renderer']);
6
+ await (0, devkit_1.formatFiles)(tree);
10
7
  }
11
8
  exports.default = removePackage;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
- function removePackage(tree) {
6
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
7
- (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['react-test-renderer']);
8
- yield (0, devkit_1.formatFiles)(tree);
9
- });
4
+ async function removePackage(tree) {
5
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['react-test-renderer']);
6
+ await (0, devkit_1.formatFiles)(tree);
10
7
  }
11
8
  exports.default = removePackage;
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const versions_1 = require("../../utils/versions");
6
- function addBabelCore(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
9
- if (packageJson === null || packageJson === void 0 ? void 0 : packageJson.devDependencies['@babel/preset-react']) {
10
- (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
11
- '@babel/core': versions_1.babelCoreVersion,
12
- });
13
- yield (0, devkit_1.formatFiles)(tree);
14
- }
15
- });
5
+ async function addBabelCore(tree) {
6
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
7
+ if (packageJson?.devDependencies['@babel/preset-react']) {
8
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
9
+ '@babel/core': versions_1.babelCoreVersion,
10
+ });
11
+ await (0, devkit_1.formatFiles)(tree);
12
+ }
16
13
  }
17
14
  exports.default = addBabelCore;
@@ -1,47 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
- function addTypings(tree) {
6
- var _a, _b;
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const projects = (0, devkit_1.getProjects)(tree);
9
- const buildExecutors = [
10
- '@nx/webpack:webpack',
11
- '@nx/vite:build',
12
- '@nx/rspack:rspack',
13
- ];
14
- const relatedTsConfigs = [
15
- 'tsconfig.app.json',
16
- 'tsconfig.lib.json',
17
- 'tsconfig.spec.json',
18
- ];
19
- const typesToAdd = [
20
- '@nx/react/typings/cssmodule.d.ts',
21
- '@nx/react/typings/image.d.ts',
22
- ];
23
- for (const [, config] of projects) {
24
- if (buildExecutors.includes((_b = (_a = config === null || config === void 0 ? void 0 : config.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor)) {
25
- const rootPath = config.root;
26
- relatedTsConfigs.forEach((tsConfig) => {
27
- const tsConfigPath = (0, devkit_1.joinPathFragments)(rootPath, tsConfig);
28
- if (tree.exists(tsConfigPath)) {
29
- (0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
30
- var _a;
31
- const compilerOptions = json.compilerOptions || {};
32
- compilerOptions.types = [
33
- ...new Set([...(compilerOptions.types || []), ...typesToAdd]),
34
- ];
35
- if (((_a = json.files) === null || _a === void 0 ? void 0 : _a.length) > 0) {
36
- json.files = json.files.filter((file) => !['cssmodule.d.ts', 'image.d.ts'].includes(file));
37
- }
38
- return Object.assign(Object.assign({}, json), { compilerOptions });
39
- });
40
- }
41
- });
42
- }
4
+ async function addTypings(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ const buildExecutors = [
7
+ '@nx/webpack:webpack',
8
+ '@nx/vite:build',
9
+ '@nx/rspack:rspack',
10
+ ];
11
+ const relatedTsConfigs = [
12
+ 'tsconfig.app.json',
13
+ 'tsconfig.lib.json',
14
+ 'tsconfig.spec.json',
15
+ ];
16
+ const typesToAdd = [
17
+ '@nx/react/typings/cssmodule.d.ts',
18
+ '@nx/react/typings/image.d.ts',
19
+ ];
20
+ for (const [, config] of projects) {
21
+ if (buildExecutors.includes(config?.targets?.build?.executor)) {
22
+ const rootPath = config.root;
23
+ relatedTsConfigs.forEach((tsConfig) => {
24
+ const tsConfigPath = (0, devkit_1.joinPathFragments)(rootPath, tsConfig);
25
+ if (tree.exists(tsConfigPath)) {
26
+ (0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
27
+ const compilerOptions = json.compilerOptions || {};
28
+ compilerOptions.types = [
29
+ ...new Set([...(compilerOptions.types || []), ...typesToAdd]),
30
+ ];
31
+ if (json.files?.length > 0) {
32
+ json.files = json.files.filter((file) => !['cssmodule.d.ts', 'image.d.ts'].includes(file));
33
+ }
34
+ return { ...json, compilerOptions };
35
+ });
36
+ }
37
+ });
43
38
  }
44
- yield (0, devkit_1.formatFiles)(tree);
45
- });
39
+ }
40
+ await (0, devkit_1.formatFiles)(tree);
46
41
  }
47
42
  exports.default = addTypings;
@@ -40,7 +40,7 @@ function addRemoteToConfig(source, app) {
40
40
  pae.name.getText() === 'exports');
41
41
  }
42
42
  });
43
- if ((exportExpression === null || exportExpression === void 0 ? void 0 : exportExpression.right.kind) === tsModule.SyntaxKind.ObjectLiteralExpression) {
43
+ if (exportExpression?.right.kind === tsModule.SyntaxKind.ObjectLiteralExpression) {
44
44
  const ole = exportExpression.right;
45
45
  return [
46
46
  {
@@ -8,7 +8,7 @@ function loadModuleFederationConfigFromContext(context) {
8
8
  try {
9
9
  return require(moduleFederationConfigPath);
10
10
  }
11
- catch (_a) {
11
+ catch {
12
12
  // TODO(jack): Add a link to guide
13
13
  throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/react:host"?`);
14
14
  }