@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
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getModuleFederationConfig = exports.getFunctionDeterminateRemoteUrl = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const module_federation_1 = require("@nx/devkit/src/utils/module-federation");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const project_graph_1 = require("nx/src/project-graph/project-graph");
@@ -9,50 +8,50 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
9
8
  const target = isServer ? 'serve-server' : 'serve';
10
9
  const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
11
10
  return function (remote) {
12
- var _a, _b, _c, _d, _e;
13
11
  const remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
14
- const serveTarget = (_a = remoteConfiguration === null || remoteConfiguration === void 0 ? void 0 : remoteConfiguration.targets) === null || _a === void 0 ? void 0 : _a[target];
12
+ const serveTarget = remoteConfiguration?.targets?.[target];
15
13
  if (!serveTarget) {
16
14
  throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
17
15
  You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
18
16
  }
19
- const host = (_c = (_b = serveTarget.options) === null || _b === void 0 ? void 0 : _b.host) !== null && _c !== void 0 ? _c : `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
20
- const port = (_e = (_d = serveTarget.options) === null || _d === void 0 ? void 0 : _d.port) !== null && _e !== void 0 ? _e : 4201;
17
+ const host = serveTarget.options?.host ??
18
+ `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
19
+ const port = serveTarget.options?.port ?? 4201;
21
20
  return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
22
21
  };
23
22
  }
24
23
  exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
25
- function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
26
- var _a;
27
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
- let projectGraph;
29
- try {
30
- projectGraph = (0, devkit_1.readCachedProjectGraph)();
31
- }
32
- catch (e) {
33
- projectGraph = yield (0, devkit_1.createProjectGraphAsync)();
34
- }
35
- const project = (_a = projectGraph.nodes[mfConfig.name]) === null || _a === void 0 ? void 0 : _a.data;
36
- if (!project) {
37
- throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
38
- }
39
- const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
40
- if (mfConfig.shared) {
41
- dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
42
- dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
43
- }
44
- const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
45
- const npmPackages = (0, module_federation_1.sharePackages)(dependencies.npmPackages);
46
- const sharedDependencies = Object.assign(Object.assign({}, sharedLibraries.getLibraries()), npmPackages);
47
- (0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
48
- (0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
49
- const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
50
- const determineRemoteUrlFn = options.determineRemoteUrl ||
51
- getFunctionDeterminateRemoteUrl(options.isServer);
52
- const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
53
- ? {}
54
- : mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFn);
55
- return { sharedLibraries, sharedDependencies, mappedRemotes };
56
- });
24
+ async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
25
+ let projectGraph;
26
+ try {
27
+ projectGraph = (0, devkit_1.readCachedProjectGraph)();
28
+ }
29
+ catch (e) {
30
+ projectGraph = await (0, devkit_1.createProjectGraphAsync)();
31
+ }
32
+ const project = projectGraph.nodes[mfConfig.name]?.data;
33
+ if (!project) {
34
+ throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
35
+ }
36
+ const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
37
+ if (mfConfig.shared) {
38
+ dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
39
+ dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
40
+ }
41
+ const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
42
+ const npmPackages = (0, module_federation_1.sharePackages)(dependencies.npmPackages);
43
+ const sharedDependencies = {
44
+ ...sharedLibraries.getLibraries(),
45
+ ...npmPackages,
46
+ };
47
+ (0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
48
+ (0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
49
+ const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
50
+ const determineRemoteUrlFn = options.determineRemoteUrl ||
51
+ getFunctionDeterminateRemoteUrl(options.isServer);
52
+ const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
53
+ ? {}
54
+ : mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFn);
55
+ return { sharedLibraries, sharedDependencies, mappedRemotes };
57
56
  }
58
57
  exports.getModuleFederationConfig = getModuleFederationConfig;
@@ -1,32 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withModuleFederationForSSR = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const utils_1 = require("./utils");
6
- function withModuleFederationForSSR(options) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const { sharedLibraries, sharedDependencies, mappedRemotes } = yield (0, utils_1.getModuleFederationConfig)(options, {
9
- isServer: true,
10
- });
11
- return (config) => {
12
- config.target = false;
13
- config.output.uniqueName = options.name;
14
- config.optimization = {
15
- runtimeChunk: false,
16
- };
17
- config.plugins.push(new (require('@module-federation/node').UniversalFederationPlugin)({
18
- name: options.name,
19
- filename: 'remoteEntry.js',
20
- exposes: options.exposes,
21
- remotes: mappedRemotes,
22
- shared: Object.assign({}, sharedDependencies),
23
- library: {
24
- type: 'commonjs-module',
25
- },
26
- isServer: true,
27
- }, {}), sharedLibraries.getReplacementPlugin());
28
- return config;
29
- };
5
+ async function withModuleFederationForSSR(options) {
6
+ const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
7
+ isServer: true,
30
8
  });
9
+ return (config) => {
10
+ config.target = false;
11
+ config.output.uniqueName = options.name;
12
+ config.optimization = {
13
+ runtimeChunk: false,
14
+ };
15
+ config.plugins.push(new (require('@module-federation/node').UniversalFederationPlugin)({
16
+ name: options.name,
17
+ filename: 'remoteEntry.js',
18
+ exposes: options.exposes,
19
+ remotes: mappedRemotes,
20
+ shared: {
21
+ ...sharedDependencies,
22
+ },
23
+ library: {
24
+ type: 'commonjs-module',
25
+ },
26
+ isServer: true,
27
+ }, {}), sharedLibraries.getReplacementPlugin());
28
+ return config;
29
+ };
31
30
  }
32
31
  exports.withModuleFederationForSSR = withModuleFederationForSSR;
@@ -1,34 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withModuleFederation = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const utils_1 = require("./utils");
6
5
  const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
7
6
  /**
8
7
  * @param {ModuleFederationConfig} options
9
8
  * @return {Promise<AsyncNxWebpackPlugin>}
10
9
  */
11
- function withModuleFederation(options) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- const { sharedDependencies, sharedLibraries, mappedRemotes } = yield (0, utils_1.getModuleFederationConfig)(options);
14
- return (config, ctx) => {
15
- var _a;
16
- config.output.uniqueName = options.name;
17
- config.output.publicPath = 'auto';
18
- config.optimization = {
19
- runtimeChunk: false,
20
- };
21
- config.experiments = Object.assign(Object.assign({}, config.experiments), { outputModule: true });
22
- config.plugins.push(new ModuleFederationPlugin({
23
- name: options.name,
24
- library: (_a = options.library) !== null && _a !== void 0 ? _a : { type: 'module' },
25
- filename: 'remoteEntry.js',
26
- exposes: options.exposes,
27
- remotes: mappedRemotes,
28
- shared: Object.assign({}, sharedDependencies),
29
- }), sharedLibraries.getReplacementPlugin());
30
- return config;
10
+ async function withModuleFederation(options) {
11
+ const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
12
+ return (config, ctx) => {
13
+ config.output.uniqueName = options.name;
14
+ config.output.publicPath = 'auto';
15
+ config.optimization = {
16
+ runtimeChunk: false,
31
17
  };
32
- });
18
+ config.experiments = {
19
+ ...config.experiments,
20
+ outputModule: true,
21
+ };
22
+ config.plugins.push(new ModuleFederationPlugin({
23
+ name: options.name,
24
+ library: options.library ?? { type: 'module' },
25
+ filename: 'remoteEntry.js',
26
+ exposes: options.exposes,
27
+ remotes: mappedRemotes,
28
+ shared: {
29
+ ...sharedDependencies,
30
+ },
31
+ }), sharedLibraries.getReplacementPlugin());
32
+ return config;
33
+ };
33
34
  }
34
35
  exports.withModuleFederation = withModuleFederation;
@@ -5,8 +5,15 @@ const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../utils/versions");
6
6
  function updateModuleFederationProject(host, options) {
7
7
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
8
- projectConfig.targets.build.options = Object.assign(Object.assign({}, projectConfig.targets.build.options), { main: `${options.appProjectRoot}/src/main.ts`, webpackConfig: `${options.appProjectRoot}/webpack.config.js` });
9
- projectConfig.targets.build.configurations.production = Object.assign(Object.assign({}, projectConfig.targets.build.configurations.production), { webpackConfig: `${options.appProjectRoot}/webpack.config.prod.js` });
8
+ projectConfig.targets.build.options = {
9
+ ...projectConfig.targets.build.options,
10
+ main: `${options.appProjectRoot}/src/main.ts`,
11
+ webpackConfig: `${options.appProjectRoot}/webpack.config.js`,
12
+ };
13
+ projectConfig.targets.build.configurations.production = {
14
+ ...projectConfig.targets.build.configurations.production,
15
+ webpackConfig: `${options.appProjectRoot}/webpack.config.prod.js`,
16
+ };
10
17
  projectConfig.targets.serve.executor =
11
18
  '@nx/react:module-federation-dev-server';
12
19
  projectConfig.targets.serve.options.port = options.devServerPort;
@@ -107,7 +107,7 @@ function findExportDeclarationsForJsx(source) {
107
107
  ...(0, js_1.findNodes)(node, tsModule.SyntaxKind.ExportSpecifier),
108
108
  ];
109
109
  });
110
- const componentNames = componentNamesNodes === null || componentNamesNodes === void 0 ? void 0 : componentNamesNodes.map((node) => node.getText());
110
+ const componentNames = componentNamesNodes?.map((node) => node.getText());
111
111
  const all = [...variables, ...variableStatements, ...fns, ...cls];
112
112
  let foundExport;
113
113
  let foundJSX;
@@ -116,27 +116,25 @@ function findExportDeclarationsForJsx(source) {
116
116
  tsModule.SyntaxKind.JsxSelfClosingElement,
117
117
  tsModule.SyntaxKind.JsxOpeningElement,
118
118
  ]);
119
- return foundJSX === null || foundJSX === void 0 ? void 0 : foundJSX.length;
119
+ return foundJSX?.length;
120
120
  });
121
121
  const exported = nodesContainingJSX.filter((x) => {
122
- var _a, _b, _c;
123
122
  foundExport = (0, js_1.findNodes)(x, tsModule.SyntaxKind.ExportKeyword);
124
123
  if (x.kind === tsModule.SyntaxKind.VariableStatement) {
125
- const nameNode = (_a = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)) === null || _a === void 0 ? void 0 : _a[0];
126
- return (((_b = nameNode === null || nameNode === void 0 ? void 0 : nameNode.name) === null || _b === void 0 ? void 0 : _b.kind) === tsModule.SyntaxKind.Identifier ||
127
- (foundExport === null || foundExport === void 0 ? void 0 : foundExport.length) ||
128
- (componentNames === null || componentNames === void 0 ? void 0 : componentNames.includes((_c = nameNode === null || nameNode === void 0 ? void 0 : nameNode.name) === null || _c === void 0 ? void 0 : _c.getText())));
124
+ const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
125
+ return (nameNode?.name?.kind === tsModule.SyntaxKind.Identifier ||
126
+ foundExport?.length ||
127
+ componentNames?.includes(nameNode?.name?.getText()));
129
128
  }
130
129
  else {
131
130
  return ((x.name.kind === tsModule.SyntaxKind.Identifier &&
132
- (foundExport === null || foundExport === void 0 ? void 0 : foundExport.length)) ||
133
- (componentNames === null || componentNames === void 0 ? void 0 : componentNames.includes(x.name.getText())));
131
+ foundExport?.length) ||
132
+ componentNames?.includes(x.name.getText()));
134
133
  }
135
134
  });
136
135
  const exportedDeclarations = exported.map((x) => {
137
- var _a;
138
136
  if (x.kind === tsModule.SyntaxKind.VariableStatement) {
139
- const nameNode = (_a = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)) === null || _a === void 0 ? void 0 : _a[0];
137
+ const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
140
138
  return nameNode;
141
139
  }
142
140
  return x;
@@ -473,14 +471,13 @@ function getComponentNode(sourceFile) {
473
471
  }
474
472
  exports.getComponentNode = getComponentNode;
475
473
  function getComponentPropsInterface(sourceFile, cmpDeclaration) {
476
- var _a, _b, _c, _d;
477
474
  if (!tsModule) {
478
475
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
479
476
  }
480
477
  let propsTypeName = null;
481
478
  if (tsModule.isFunctionDeclaration(cmpDeclaration)) {
482
479
  const propsParam = cmpDeclaration.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
483
- if ((_a = propsParam === null || propsParam === void 0 ? void 0 : propsParam.type) === null || _a === void 0 ? void 0 : _a['typeName']) {
480
+ if (propsParam?.type?.['typeName']) {
484
481
  propsTypeName = propsParam.type.typeName.text;
485
482
  }
486
483
  }
@@ -489,7 +486,7 @@ function getComponentPropsInterface(sourceFile, cmpDeclaration) {
489
486
  const arrowFn = cmpDeclaration
490
487
  .initializer;
491
488
  const propsParam = arrowFn.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
492
- if ((_b = propsParam === null || propsParam === void 0 ? void 0 : propsParam.type) === null || _b === void 0 ? void 0 : _b['typeName']) {
489
+ if (propsParam?.type?.['typeName']) {
493
490
  propsTypeName = propsParam.type.typeName.text;
494
491
  }
495
492
  }
@@ -505,7 +502,7 @@ function getComponentPropsInterface(sourceFile, cmpDeclaration) {
505
502
  x.expression.name.text;
506
503
  return name === 'Component' || name === 'PureComponent';
507
504
  });
508
- if ((_d = (_c = propsTypeExpression === null || propsTypeExpression === void 0 ? void 0 : propsTypeExpression.typeArguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d['typeName']) {
505
+ if (propsTypeExpression?.typeArguments?.[0]?.['typeName']) {
509
506
  propsTypeName = propsTypeExpression.typeArguments[0].typeName.getText();
510
507
  }
511
508
  }
@@ -32,7 +32,10 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
32
32
  // inline tsconfig.base.json into the project
33
33
  if (options.rootProject) {
34
34
  json.compileOnSave = false;
35
- json.compilerOptions = Object.assign(Object.assign({}, shared.tsConfigBaseOptions), json.compilerOptions);
35
+ json.compilerOptions = {
36
+ ...shared.tsConfigBaseOptions,
37
+ ...json.compilerOptions,
38
+ };
36
39
  json.exclude = ['node_modules', 'tmp'];
37
40
  }
38
41
  else {
@@ -42,9 +45,8 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
42
45
  const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
43
46
  if (options.bundler === 'vite' && host.exists(tsconfigProjectPath)) {
44
47
  (0, json_1.updateJson)(host, tsconfigProjectPath, (json) => {
45
- var _a, _b;
46
- (_a = json.compilerOptions) !== null && _a !== void 0 ? _a : (json.compilerOptions = {});
47
- const types = new Set((_b = json.compilerOptions.types) !== null && _b !== void 0 ? _b : []);
48
+ json.compilerOptions ??= {};
49
+ const types = new Set(json.compilerOptions.types ?? []);
48
50
  types.add('node');
49
51
  types.add('vite/client');
50
52
  json.compilerOptions.types = Array.from(types);
@@ -1,31 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isComponent = exports.getBundlerFromTarget = exports.addCTTargetWithBuildTarget = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
7
6
  const ast_utils_1 = require("./ast-utils");
8
7
  let tsModule;
9
8
  const allowedFileExt = new RegExp(/\.[jt]sx?/);
10
9
  const isSpecFile = new RegExp(/(spec|test)\./);
11
- function addCTTargetWithBuildTarget(tree, options) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- let found = { target: options.buildTarget, config: undefined };
14
- // Specifically undefined as a workaround for Remix to pass an empty string as the buildTarget
15
- if (options.buildTarget === undefined) {
16
- const { findBuildConfig } = yield Promise.resolve().then(() => require('@nx/cypress/src/utils/find-target-options'));
17
- found = yield findBuildConfig(tree, {
18
- project: options.project,
19
- buildTarget: options.buildTarget,
20
- validExecutorNames: options.validExecutorNames,
21
- });
22
- assertValidConfig(found === null || found === void 0 ? void 0 : found.config);
23
- }
24
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
25
- projectConfig.targets['component-test'].options = Object.assign(Object.assign({}, projectConfig.targets['component-test'].options), { devServerTarget: found.target, skipServe: true });
26
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
27
- return found;
28
- });
10
+ async function addCTTargetWithBuildTarget(tree, options) {
11
+ let found = { target: options.buildTarget, config: undefined };
12
+ // Specifically undefined as a workaround for Remix to pass an empty string as the buildTarget
13
+ if (options.buildTarget === undefined) {
14
+ const { findBuildConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/find-target-options'));
15
+ found = await findBuildConfig(tree, {
16
+ project: options.project,
17
+ buildTarget: options.buildTarget,
18
+ validExecutorNames: options.validExecutorNames,
19
+ });
20
+ assertValidConfig(found?.config);
21
+ }
22
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
23
+ projectConfig.targets['component-test'].options = {
24
+ ...projectConfig.targets['component-test'].options,
25
+ devServerTarget: found.target,
26
+ skipServe: true,
27
+ };
28
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
29
+ return found;
29
30
  }
30
31
  exports.addCTTargetWithBuildTarget = addCTTargetWithBuildTarget;
31
32
  function assertValidConfig(config) {
@@ -33,22 +34,19 @@ function assertValidConfig(config) {
33
34
  throw new Error('Unable to find a valid build configuration. Try passing in a target for an app. --build-target=<project>:<target>[:<configuration>]');
34
35
  }
35
36
  }
36
- function getBundlerFromTarget(found, tree) {
37
- var _a, _b, _c;
38
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
- if (found.target && ((_a = found.config) === null || _a === void 0 ? void 0 : _a.executor)) {
40
- return found.config.executor === '@nrwl/vite:build' ||
41
- found.config.executor === '@nx/vite:build'
42
- ? 'vite'
43
- : 'webpack';
44
- }
45
- const { target, project } = (0, devkit_1.parseTargetString)(found.target, yield (0, devkit_1.createProjectGraphAsync)());
46
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
47
- const executor = (_c = (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _b === void 0 ? void 0 : _b[target]) === null || _c === void 0 ? void 0 : _c.executor;
48
- return executor === '@nrwl/vite:build' || executor === '@nx/vite:build'
37
+ async function getBundlerFromTarget(found, tree) {
38
+ if (found.target && found.config?.executor) {
39
+ return found.config.executor === '@nrwl/vite:build' ||
40
+ found.config.executor === '@nx/vite:build'
49
41
  ? 'vite'
50
42
  : 'webpack';
51
- });
43
+ }
44
+ const { target, project } = (0, devkit_1.parseTargetString)(found.target, await (0, devkit_1.createProjectGraphAsync)());
45
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
46
+ const executor = projectConfig?.targets?.[target]?.executor;
47
+ return executor === '@nrwl/vite:build' || executor === '@nx/vite:build'
48
+ ? 'vite'
49
+ : 'webpack';
52
50
  }
53
51
  exports.getBundlerFromTarget = getBundlerFromTarget;
54
52
  function isComponent(tree, filePath) {
package/src/utils/lint.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extendReactEslintJson = exports.extraEslintDependencies = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const versions_1 = require("./versions");
6
5
  exports.extraEslintDependencies = {
7
6
  dependencies: {},
@@ -16,7 +15,10 @@ exports.extraEslintDependencies = {
16
15
  * @deprecated Use `addExtendsToLintConfig` from `@nx/linter` instead.
17
16
  */
18
17
  const extendReactEslintJson = (json) => {
19
- const { extends: pluginExtends } = json, config = tslib_1.__rest(json, ["extends"]);
20
- return Object.assign({ extends: ['plugin:@nx/react', ...(pluginExtends || [])] }, config);
18
+ const { extends: pluginExtends, ...config } = json;
19
+ return {
20
+ extends: ['plugin:@nx/react', ...(pluginExtends || [])],
21
+ ...config,
22
+ };
21
23
  };
22
24
  exports.extendReactEslintJson = extendReactEslintJson;
@@ -1,35 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLib = exports.createApp = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const application_1 = require("../generators/application/application");
7
6
  const linter_1 = require("@nx/linter");
8
- function createApp(tree, appName) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- yield (0, application_1.default)(tree, {
11
- e2eTestRunner: 'none',
12
- linter: linter_1.Linter.EsLint,
13
- skipFormat: true,
14
- style: 'css',
15
- unitTestRunner: 'none',
16
- name: appName,
17
- projectNameAndRootFormat: 'as-provided',
18
- });
7
+ async function createApp(tree, appName) {
8
+ await (0, application_1.default)(tree, {
9
+ e2eTestRunner: 'none',
10
+ linter: linter_1.Linter.EsLint,
11
+ skipFormat: true,
12
+ style: 'css',
13
+ unitTestRunner: 'none',
14
+ name: appName,
15
+ projectNameAndRootFormat: 'as-provided',
19
16
  });
20
17
  }
21
18
  exports.createApp = createApp;
22
- function createLib(tree, libName) {
23
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
- const { fileName } = (0, devkit_1.names)(libName);
25
- tree.write(`/${fileName}/src/index.ts`, `import React from 'react';\n`);
26
- (0, devkit_1.addProjectConfiguration)(tree, fileName, {
27
- tags: [],
28
- root: `${fileName}`,
29
- projectType: 'library',
30
- sourceRoot: `${fileName}/src`,
31
- targets: {},
32
- });
19
+ async function createLib(tree, libName) {
20
+ const { fileName } = (0, devkit_1.names)(libName);
21
+ tree.write(`/${fileName}/src/index.ts`, `import React from 'react';\n`);
22
+ (0, devkit_1.addProjectConfiguration)(tree, fileName, {
23
+ tags: [],
24
+ root: `${fileName}`,
25
+ projectType: 'library',
26
+ sourceRoot: `${fileName}/src`,
27
+ targets: {},
33
28
  });
34
29
  }
35
30
  exports.createLib = createLib;