@nx/react 16.8.0-beta.4 → 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 +53 -57
  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 -23
package/babel.js CHANGED
@@ -7,7 +7,7 @@ module.exports = function (api, options) {
7
7
  /**
8
8
  * pagesDir is set when being transpiled by Next.js
9
9
  */
10
- const isNextJs = api.caller((caller) => caller === null || caller === void 0 ? void 0 : caller.pagesDir);
10
+ const isNextJs = api.caller((caller) => caller?.pagesDir);
11
11
  const presets = [[require.resolve('@nx/js/babel'), options]];
12
12
  /**
13
13
  * Next.js already includes the preset-react, and including it
@@ -34,9 +34,8 @@ module.exports = function (api, options) {
34
34
  };
35
35
  };
36
36
  function getReactPresetOptions({ presetOptions, env }) {
37
- var _a;
38
37
  const reactPresetOptions = {
39
- runtime: (_a = presetOptions.runtime) !== null && _a !== void 0 ? _a : 'automatic',
38
+ runtime: presetOptions.runtime ?? 'automatic',
40
39
  development: env !== 'production',
41
40
  };
42
41
  // JSX spread is transformed into object spread in `@babel/plugin-transform-react-jsx`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "16.8.0-beta.4",
3
+ "version": "16.8.0-beta.5",
4
4
  "private": false,
5
5
  "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -31,11 +31,11 @@
31
31
  "migrations": "./migrations.json"
32
32
  },
33
33
  "dependencies": {
34
- "@nrwl/react": "16.8.0-beta.4",
35
- "@nx/devkit": "16.8.0-beta.4",
36
- "@nx/js": "16.8.0-beta.4",
37
- "@nx/linter": "16.8.0-beta.4",
38
- "@nx/web": "16.8.0-beta.4",
34
+ "@nrwl/react": "16.8.0-beta.5",
35
+ "@nx/devkit": "16.8.0-beta.5",
36
+ "@nx/js": "16.8.0-beta.5",
37
+ "@nx/linter": "16.8.0-beta.5",
38
+ "@nx/web": "16.8.0-beta.5",
39
39
  "@phenomnomnominal/tsquery": "~5.0.1",
40
40
  "@svgr/webpack": "^8.0.1",
41
41
  "chalk": "^4.1.0",
@@ -47,5 +47,5 @@
47
47
  "access": "public"
48
48
  },
49
49
  "type": "commonjs",
50
- "gitHead": "c9aad2dc8c2b34531cf61549bff872e68c481e4e"
50
+ "gitHead": "ad2d1e8a55b2d1b358bb5e7483343d9757ff2c53"
51
51
  }
@@ -10,11 +10,17 @@ function getRollupOptions(options) {
10
10
  };
11
11
  if (Array.isArray(options.output)) {
12
12
  options.output.forEach((o) => {
13
- o.globals = Object.assign(Object.assign({}, o.globals), extraGlobals);
13
+ o.globals = { ...o.globals, ...extraGlobals };
14
14
  });
15
15
  }
16
16
  else {
17
- options.output = Object.assign(Object.assign({}, options.output), { globals: Object.assign(Object.assign({}, options.output.globals), extraGlobals) });
17
+ options.output = {
18
+ ...options.output,
19
+ globals: {
20
+ ...options.output.globals,
21
+ ...extraGlobals,
22
+ },
23
+ };
18
24
  }
19
25
  // React buildable libs support SVGR, but not for React Native.
20
26
  // If imports fail, ignore it.
@@ -33,7 +39,7 @@ function getRollupOptions(options) {
33
39
  ...options.plugins,
34
40
  ];
35
41
  }
36
- catch (_a) {
42
+ catch {
37
43
  // Ignored for React Native
38
44
  }
39
45
  return options;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxComponentTestingPreset = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const ct_helpers_1 = require("@nx/cypress/src/utils/ct-helpers");
@@ -32,11 +31,16 @@ function nxComponentTestingPreset(pathToConfig, options) {
32
31
  const basePresetSettings = (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig, {
33
32
  testingType: 'component',
34
33
  });
35
- if ((options === null || options === void 0 ? void 0 : options.bundler) === 'vite') {
36
- return Object.assign(Object.assign({}, basePresetSettings), { specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}', devServer: Object.assign(Object.assign({}, { framework: 'react', bundler: 'vite' }), { viteConfig: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
34
+ if (options?.bundler === 'vite') {
35
+ return {
36
+ ...basePresetSettings,
37
+ specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}',
38
+ devServer: {
39
+ ...{ framework: 'react', bundler: 'vite' },
40
+ viteConfig: async () => {
37
41
  const viteConfigPath = findViteConfig(normalizedProjectRootPath);
38
- const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } = yield Function('return import("vite")')();
39
- const resolved = yield loadConfigFromFile({
42
+ const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } = await Function('return import("vite")')();
43
+ const resolved = await loadConfigFromFile({
40
44
  mode: 'watch',
41
45
  command: 'serve',
42
46
  }, viteConfigPath);
@@ -51,13 +55,15 @@ function nxComponentTestingPreset(pathToConfig, options) {
51
55
  },
52
56
  },
53
57
  });
54
- }) }) });
58
+ },
59
+ },
60
+ };
55
61
  }
56
62
  let webpackConfig;
57
63
  try {
58
64
  const graph = (0, devkit_1.readCachedProjectGraph)();
59
65
  const { targets: ctTargets, name: ctProjectName } = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
60
- const ctTargetName = (options === null || options === void 0 ? void 0 : options.ctTargetName) || 'component-test';
66
+ const ctTargetName = options?.ctTargetName || 'component-test';
61
67
  const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
62
68
  const ctExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
63
69
  const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
@@ -81,40 +87,49 @@ function nxComponentTestingPreset(pathToConfig, options) {
81
87
  compiler: 'babel',
82
88
  });
83
89
  }
84
- return Object.assign(Object.assign({}, basePresetSettings), { specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}', devServer: Object.assign(Object.assign({}, { framework: 'react', bundler: 'webpack' }), { webpackConfig }) });
90
+ return {
91
+ ...basePresetSettings,
92
+ specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}',
93
+ devServer: {
94
+ // cypress uses string union type,
95
+ // need to use const to prevent typing to string
96
+ // but don't want to use as const on webpackConfig
97
+ // so it is still user modifiable
98
+ ...{ framework: 'react', bundler: 'webpack' },
99
+ webpackConfig,
100
+ },
101
+ };
85
102
  }
86
103
  exports.nxComponentTestingPreset = nxComponentTestingPreset;
87
104
  /**
88
105
  * apply the schema.json defaults from the @nx/web:webpack executor to the target options
89
106
  */
90
107
  function withSchemaDefaults(target, context) {
91
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
92
108
  const options = (0, devkit_1.readTargetOptions)(target, context);
93
- (_a = options.compiler) !== null && _a !== void 0 ? _a : (options.compiler = 'babel');
94
- (_b = options.deleteOutputPath) !== null && _b !== void 0 ? _b : (options.deleteOutputPath = true);
95
- (_c = options.vendorChunk) !== null && _c !== void 0 ? _c : (options.vendorChunk = true);
96
- (_d = options.commonChunk) !== null && _d !== void 0 ? _d : (options.commonChunk = true);
97
- (_e = options.runtimeChunk) !== null && _e !== void 0 ? _e : (options.runtimeChunk = true);
98
- (_f = options.sourceMap) !== null && _f !== void 0 ? _f : (options.sourceMap = true);
99
- (_g = options.assets) !== null && _g !== void 0 ? _g : (options.assets = []);
100
- (_h = options.scripts) !== null && _h !== void 0 ? _h : (options.scripts = []);
101
- (_j = options.styles) !== null && _j !== void 0 ? _j : (options.styles = []);
102
- (_k = options.budgets) !== null && _k !== void 0 ? _k : (options.budgets = []);
103
- (_l = options.namedChunks) !== null && _l !== void 0 ? _l : (options.namedChunks = true);
104
- (_m = options.outputHashing) !== null && _m !== void 0 ? _m : (options.outputHashing = 'none');
105
- (_o = options.extractCss) !== null && _o !== void 0 ? _o : (options.extractCss = true);
106
- (_p = options.memoryLimit) !== null && _p !== void 0 ? _p : (options.memoryLimit = 2048);
107
- (_q = options.maxWorkers) !== null && _q !== void 0 ? _q : (options.maxWorkers = 2);
108
- (_r = options.fileReplacements) !== null && _r !== void 0 ? _r : (options.fileReplacements = []);
109
- (_s = options.buildLibsFromSource) !== null && _s !== void 0 ? _s : (options.buildLibsFromSource = true);
110
- (_t = options.generateIndexHtml) !== null && _t !== void 0 ? _t : (options.generateIndexHtml = true);
109
+ options.compiler ??= 'babel';
110
+ options.deleteOutputPath ??= true;
111
+ options.vendorChunk ??= true;
112
+ options.commonChunk ??= true;
113
+ options.runtimeChunk ??= true;
114
+ options.sourceMap ??= true;
115
+ options.assets ??= [];
116
+ options.scripts ??= [];
117
+ options.styles ??= [];
118
+ options.budgets ??= [];
119
+ options.namedChunks ??= true;
120
+ options.outputHashing ??= 'none';
121
+ options.extractCss ??= true;
122
+ options.memoryLimit ??= 2048;
123
+ options.maxWorkers ??= 2;
124
+ options.fileReplacements ??= [];
125
+ options.buildLibsFromSource ??= true;
126
+ options.generateIndexHtml ??= true;
111
127
  return options;
112
128
  }
113
129
  function buildTargetWebpack(graph, buildTarget, componentTestingProjectName) {
114
- var _a, _b;
115
130
  const parsed = (0, devkit_1.parseTargetString)(buildTarget, graph);
116
- const buildableProjectConfig = (_a = graph.nodes[parsed.project]) === null || _a === void 0 ? void 0 : _a.data;
117
- const ctProjectConfig = (_b = graph.nodes[componentTestingProjectName]) === null || _b === void 0 ? void 0 : _b.data;
131
+ const buildableProjectConfig = graph.nodes[parsed.project]?.data;
132
+ const ctProjectConfig = graph.nodes[componentTestingProjectName]?.data;
118
133
  if (!buildableProjectConfig || !ctProjectConfig) {
119
134
  throw new Error((0, devkit_1.stripIndents) `Unable to load project configs from graph.
120
135
  Using build target '${buildTarget}'
@@ -131,23 +146,28 @@ function buildTargetWebpack(graph, buildTarget, componentTestingProjectName) {
131
146
  if (options.webpackConfig) {
132
147
  customWebpack = resolveCustomWebpackConfig(options.webpackConfig, options.tsConfig);
133
148
  }
134
- return () => tslib_1.__awaiter(this, void 0, void 0, function* () {
135
- customWebpack = yield customWebpack;
149
+ return async () => {
150
+ customWebpack = await customWebpack;
136
151
  // TODO(jack): Once webpackConfig is always set in @nx/webpack:webpack, we no longer need this default.
137
- const defaultWebpack = getWebpackConfig(context, Object.assign(Object.assign({}, options), {
152
+ const defaultWebpack = getWebpackConfig(context, {
153
+ ...options,
138
154
  // cypress will generate its own index.html from component-index.html
139
- generateIndexHtml: false,
155
+ generateIndexHtml: false,
140
156
  // causes issues with buildable libraries with ENOENT: no such file or directory, scandir error
141
- extractLicenses: false, root: devkit_1.workspaceRoot, projectRoot: ctProjectConfig.root, sourceRoot: ctProjectConfig.sourceRoot }));
157
+ extractLicenses: false,
158
+ root: devkit_1.workspaceRoot,
159
+ projectRoot: ctProjectConfig.root,
160
+ sourceRoot: ctProjectConfig.sourceRoot,
161
+ });
142
162
  if (customWebpack) {
143
- return yield customWebpack(defaultWebpack, {
163
+ return await customWebpack(defaultWebpack, {
144
164
  options,
145
165
  context,
146
166
  configuration: parsed.configuration,
147
167
  });
148
168
  }
149
169
  return defaultWebpack;
150
- });
170
+ };
151
171
  }
152
172
  function findViteConfig(projectRootFullPath) {
153
173
  const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
package/plugins/jest.js CHANGED
@@ -5,7 +5,6 @@ const devkit_1 = require("@nx/devkit");
5
5
  const JS_SOURCE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
6
6
  module.exports = {
7
7
  process(src, filename, options) {
8
- var _a, _b;
9
8
  const assetFilename = JSON.stringify(path.basename(filename));
10
9
  if (filename.match(/\.svg$/)) {
11
10
  // Based on how SVGR generates a component name:
@@ -32,7 +31,7 @@ module.exports = {
32
31
  };
33
32
  }
34
33
  if (JS_SOURCE_EXTENSIONS.includes(path.extname(filename))) {
35
- const transformer = getJsTransform((_b = (_a = options.config) === null || _a === void 0 ? void 0 : _a.transform) !== null && _b !== void 0 ? _b : []);
34
+ const transformer = getJsTransform(options.config?.transform ?? []);
36
35
  if (transformer)
37
36
  return transformer.process(src, filename, options);
38
37
  }
@@ -43,19 +42,18 @@ module.exports = {
43
42
  },
44
43
  };
45
44
  function getJsTransform(transformers) {
46
- var _a;
47
45
  try {
48
- if ((_a = transformers === null || transformers === void 0 ? void 0 : transformers[1]) === null || _a === void 0 ? void 0 : _a.includes('@swc/jest')) {
46
+ if (transformers?.[1]?.includes('@swc/jest')) {
49
47
  return require('@swc/jest').createTransformer();
50
48
  }
51
49
  }
52
- catch (_b) {
50
+ catch {
53
51
  // ignored
54
52
  }
55
53
  try {
56
54
  return require('babel-jest').default.createTransformer();
57
55
  }
58
- catch (_c) {
56
+ catch {
59
57
  // ignored
60
58
  }
61
59
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webpack = exports.core = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const config_1 = require("@nx/webpack/src/utils/config");
7
6
  const path_1 = require("path");
@@ -43,9 +42,12 @@ function getClientEnvironment(mode) {
43
42
  };
44
43
  return { stringified };
45
44
  }
46
- const core = (prev, options) => (Object.assign(Object.assign({}, prev), { disableWebpackDefaults: true }));
45
+ const core = (prev, options) => ({
46
+ ...prev,
47
+ disableWebpackDefaults: true,
48
+ });
47
49
  exports.core = core;
48
- const getProjectData = (storybookOptions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
50
+ const getProjectData = async (storybookOptions) => {
49
51
  const fallbackData = {
50
52
  workspaceRoot: storybookOptions.configDir,
51
53
  projectRoot: '',
@@ -54,7 +56,7 @@ const getProjectData = (storybookOptions) => tslib_1.__awaiter(void 0, void 0, v
54
56
  // Edge-case: not running from Nx
55
57
  if (!process.env.NX_WORKSPACE_ROOT)
56
58
  return fallbackData;
57
- const projectGraph = yield (0, devkit_1.createProjectGraphAsync)();
59
+ const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
58
60
  const projectNode = projectGraph.nodes[process.env.NX_TASK_TARGET_PROJECT];
59
61
  return projectNode
60
62
  ? {
@@ -65,16 +67,15 @@ const getProjectData = (storybookOptions) => tslib_1.__awaiter(void 0, void 0, v
65
67
  }
66
68
  : // Edge-case: missing project node
67
69
  fallbackData;
68
- });
70
+ };
69
71
  const fixBabelConfigurationIfNeeded = (webpackConfig, projectData) => {
70
72
  if (!projectData.projectNode)
71
73
  return;
72
74
  const isUsingBabelUpwardRootMode = Object.keys(projectData.projectNode.data.targets).find((k) => {
73
- var _a;
74
75
  const targetConfig = projectData.projectNode.data.targets[k];
75
76
  return ((targetConfig.executor === '@nx/webpack:webpack' ||
76
77
  targetConfig.executor === '@nrwl/webpack:webpack') &&
77
- ((_a = targetConfig.options) === null || _a === void 0 ? void 0 : _a.babelUpwardRootMode));
78
+ targetConfig.options?.babelUpwardRootMode);
78
79
  });
79
80
  if (isUsingBabelUpwardRootMode)
80
81
  return;
@@ -106,22 +107,33 @@ const fixBabelConfigurationIfNeeded = (webpackConfig, projectData) => {
106
107
  babelRuleItem.options.configFile = babelrcPath;
107
108
  }
108
109
  };
109
- const webpack = (storybookWebpackConfig = {}, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
110
- var _a, _b, _c, _d, _e, _f;
110
+ const webpack = async (storybookWebpackConfig = {}, options) => {
111
111
  devkit_1.logger.info('=> Loading Nx React Storybook Addon from "@nx/react/plugins/storybook"');
112
112
  // In case anyone is missing dep and did not run migrations.
113
113
  // See: https://github.com/nrwl/nx/issues/14455
114
114
  try {
115
115
  require.resolve('@nx/webpack');
116
116
  }
117
- catch (_g) {
117
+ catch {
118
118
  throw new Error(`'@nx/webpack' package is not installed. Install it and try again.`);
119
119
  }
120
120
  const { withNx, withWeb } = require('@nx/webpack');
121
- const projectData = yield getProjectData(options);
121
+ const projectData = await getProjectData(options);
122
122
  const tsconfigPath = (0, path_1.join)(projectData.projectRoot, 'tsconfig.storybook.json');
123
123
  fixBabelConfigurationIfNeeded(storybookWebpackConfig, projectData);
124
- const builderOptions = Object.assign(Object.assign({}, options), { root: projectData.workspaceRoot, projectRoot: projectData.projectRoot, sourceRoot: projectData.sourceRoot, fileReplacements: [], sourceMap: true, styles: (_a = options.styles) !== null && _a !== void 0 ? _a : [], optimization: {}, tsConfig: tsconfigPath, extractCss: storybookWebpackConfig.mode === 'production', target: 'web' });
124
+ const builderOptions = {
125
+ ...options,
126
+ root: projectData.workspaceRoot,
127
+ projectRoot: projectData.projectRoot,
128
+ sourceRoot: projectData.sourceRoot,
129
+ fileReplacements: [],
130
+ sourceMap: true,
131
+ styles: options.styles ?? [],
132
+ optimization: {},
133
+ tsConfig: tsconfigPath,
134
+ extractCss: storybookWebpackConfig.mode === 'production',
135
+ target: 'web',
136
+ };
125
137
  // ESM build for modern browsers.
126
138
  let baseWebpackConfig = {};
127
139
  const configure = (0, config_1.composePluginsSync)(withNx({ skipTypeChecking: true }), withWeb(), (0, with_react_1.withReact)());
@@ -129,13 +141,30 @@ const webpack = (storybookWebpackConfig = {}, options) => tslib_1.__awaiter(void
129
141
  options: builderOptions,
130
142
  context: { root: devkit_1.workspaceRoot }, // The context is not used here.
131
143
  });
132
- return Object.assign(Object.assign({}, storybookWebpackConfig), { module: Object.assign(Object.assign({}, storybookWebpackConfig.module), { rules: [
144
+ return {
145
+ ...storybookWebpackConfig,
146
+ module: {
147
+ ...storybookWebpackConfig.module,
148
+ rules: [
133
149
  ...storybookWebpackConfig.module.rules,
134
150
  ...finalConfig.module.rules,
135
- ] }), resolve: Object.assign(Object.assign({}, storybookWebpackConfig.resolve), { fallback: Object.assign(Object.assign({}, (_b = storybookWebpackConfig.resolve) === null || _b === void 0 ? void 0 : _b.fallback), {
151
+ ],
152
+ },
153
+ resolve: {
154
+ ...storybookWebpackConfig.resolve,
155
+ fallback: {
156
+ ...storybookWebpackConfig.resolve?.fallback,
136
157
  // Next.js and other React frameworks may have server-code that uses these modules.
137
158
  // They are not meant for client-side components so skip the fallbacks.
138
- assert: false, path: false, util: false }), plugins: (0, merge_plugins_1.mergePlugins)(...((_c = storybookWebpackConfig.resolve.plugins) !== null && _c !== void 0 ? _c : []), ...((_d = finalConfig.resolve
139
- .plugins) !== null && _d !== void 0 ? _d : [])) }), plugins: (0, merge_plugins_1.mergePlugins)(new webpack_1.DefinePlugin(getClientEnvironment(storybookWebpackConfig.mode).stringified), ...((_e = storybookWebpackConfig.plugins) !== null && _e !== void 0 ? _e : []), ...((_f = finalConfig.plugins) !== null && _f !== void 0 ? _f : [])) });
140
- });
159
+ assert: false,
160
+ path: false,
161
+ util: false,
162
+ },
163
+ plugins: (0, merge_plugins_1.mergePlugins)(...(storybookWebpackConfig.resolve.plugins ??
164
+ []), ...(finalConfig.resolve
165
+ .plugins ?? [])),
166
+ },
167
+ plugins: (0, merge_plugins_1.mergePlugins)(new webpack_1.DefinePlugin(getClientEnvironment(storybookWebpackConfig.mode).stringified), ...(storybookWebpackConfig.plugins ?? []), ...(finalConfig.plugins ?? [])),
168
+ };
169
+ };
141
170
  exports.webpack = webpack;
@@ -3,15 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withReact = void 0;
4
4
  const processed = new Set();
5
5
  function addHotReload(config) {
6
- var _a;
7
- if (config.mode === 'development' && ((_a = config['devServer']) === null || _a === void 0 ? void 0 : _a.hot)) {
6
+ if (config.mode === 'development' && config['devServer']?.hot) {
8
7
  // add `react-refresh/babel` to babel loader plugin
9
- const babelLoader = config.module.rules.find((rule) => {
10
- var _a;
11
- return rule &&
12
- typeof rule !== 'string' &&
13
- ((_a = rule.loader) === null || _a === void 0 ? void 0 : _a.toString().includes('babel-loader'));
14
- });
8
+ const babelLoader = config.module.rules.find((rule) => rule &&
9
+ typeof rule !== 'string' &&
10
+ rule.loader?.toString().includes('babel-loader'));
15
11
  if (babelLoader && typeof babelLoader !== 'string') {
16
12
  babelLoader.options['plugins'] = [
17
13
  ...(babelLoader.options['plugins'] || []),
@@ -47,7 +43,7 @@ function withReact(pluginOptions = {}) {
47
43
  // Apply web config for CSS, JSX, index.html handling, etc.
48
44
  config = withWeb(pluginOptions)(config, context);
49
45
  addHotReload(config);
50
- if ((pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.svgr) !== false) {
46
+ if (pluginOptions?.svgr !== false) {
51
47
  removeSvgLoaderIfPresent(config);
52
48
  config.module.rules.push({
53
49
  test: /\.svg$/,