@nx/react 16.10.0 → 17.0.0-beta.2

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 (42) hide show
  1. package/generators.json +14 -0
  2. package/migrations.json +0 -698
  3. package/package.json +6 -6
  4. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +1 -1
  5. package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +8 -0
  6. package/src/generators/federate-module/federate-module.d.ts +5 -0
  7. package/src/generators/federate-module/federate-module.js +58 -0
  8. package/src/generators/federate-module/lib/utils.d.ts +23 -0
  9. package/src/generators/federate-module/lib/utils.js +97 -0
  10. package/src/generators/federate-module/schema.d.ts +12 -0
  11. package/src/generators/federate-module/schema.json +116 -0
  12. package/src/generators/remote/remote.js +1 -1
  13. package/src/generators/setup-ssr/setup-ssr.js +4 -1
  14. package/src/generators/storybook-configuration/configuration.js +1 -1
  15. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +32 -17
  16. package/src/module-federation/with-module-federation.js +1 -2
  17. package/src/migrations/update-12-0-0/remove-react-redux-types-package.d.ts +0 -3
  18. package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +0 -9
  19. package/src/migrations/update-12-0-0/update-emotion-setup.d.ts +0 -3
  20. package/src/migrations/update-12-0-0/update-emotion-setup.js +0 -61
  21. package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.d.ts +0 -3
  22. package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +0 -22
  23. package/src/migrations/update-12-8-0/update-12-8-0.d.ts +0 -3
  24. package/src/migrations/update-12-8-0/update-12-8-0.js +0 -11
  25. package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.d.ts +0 -3
  26. package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +0 -34
  27. package/src/migrations/update-13-0-0/update-emotion-setup.d.ts +0 -3
  28. package/src/migrations/update-13-0-0/update-emotion-setup.js +0 -35
  29. package/src/migrations/update-13-0-0/webpack5-changes-utils.d.ts +0 -11
  30. package/src/migrations/update-13-0-0/webpack5-changes-utils.js +0 -264
  31. package/src/migrations/update-13-10-0/update-13-10-0.d.ts +0 -3
  32. package/src/migrations/update-13-10-0/update-13-10-0.js +0 -25
  33. package/src/migrations/update-14-0-0/add-default-development-configurations.d.ts +0 -3
  34. package/src/migrations/update-14-0-0/add-default-development-configurations.js +0 -34
  35. package/src/migrations/update-14-0-0/replace-testing-library-react-hook.d.ts +0 -3
  36. package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +0 -22
  37. package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.d.ts +0 -5
  38. package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +0 -64
  39. package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.d.ts +0 -3
  40. package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +0 -34
  41. package/src/migrations/update-14-6-0/add-preset-jest-config.d.ts +0 -3
  42. package/src/migrations/update-14-6-0/add-preset-jest-config.js +0 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "16.10.0",
3
+ "version": "17.0.0-beta.2",
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": {
@@ -37,11 +37,11 @@
37
37
  "file-loader": "^6.2.0",
38
38
  "minimatch": "3.0.5",
39
39
  "tslib": "^2.3.0",
40
- "@nx/devkit": "16.10.0",
41
- "@nx/js": "16.10.0",
42
- "@nx/linter": "16.10.0",
43
- "@nx/web": "16.10.0",
44
- "@nrwl/react": "16.10.0"
40
+ "@nx/devkit": "17.0.0-beta.2",
41
+ "@nx/js": "17.0.0-beta.2",
42
+ "@nx/linter": "17.0.0-beta.2",
43
+ "@nx/web": "17.0.0-beta.2",
44
+ "@nrwl/react": "17.0.0-beta.2"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -24,7 +24,7 @@ function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot) {
24
24
  // create a no-op so this can be called with issue
25
25
  let cleanupTranspiler = () => { };
26
26
  if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
27
- cleanupTranspiler = (0, internal_1.registerTsProject)(moduleFederationConfigPathTS, tsconfigPath);
27
+ cleanupTranspiler = (0, internal_1.registerTsProject)((0, path_1.join)(workspaceRoot, tsconfigPath));
28
28
  moduleFederationConfigPath = moduleFederationConfigPathTS;
29
29
  }
30
30
  try {
@@ -14,6 +14,14 @@ export function App() {
14
14
  return (
15
15
  <div>
16
16
  <style jsx>{`/** your style here **/`}</style>
17
+ <% if (!minimal) { %>
18
+ <NxWelcome title="<%= projectName %>"/>
19
+ <% } else { %>
20
+ <h1>
21
+ <span> Hello there, </span>
22
+ Welcome <%= projectName %> 👋
23
+ </h1>
24
+ <% } %>
17
25
  </div>
18
26
  );
19
27
 
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function federateModuleGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export default federateModuleGenerator;
5
+ export declare const federateModuleSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.federateModuleSchematic = exports.federateModuleGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const remote_1 = require("../remote/remote");
6
+ const utils_1 = require("./lib/utils");
7
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
+ const js_1 = require("@nx/js");
9
+ async function federateModuleGenerator(tree, schema) {
10
+ const tasks = [];
11
+ // Check remote exists
12
+ const remote = (0, utils_1.checkRemoteExists)(tree, schema.remote);
13
+ const { projectName, projectRoot: remoteRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
14
+ name: schema.remote,
15
+ projectType: 'application',
16
+ projectNameAndRootFormat: schema.projectNameAndRootFormat,
17
+ callingGenerator: '@nx/react:federate-module',
18
+ });
19
+ if (!remote) {
20
+ // create remote
21
+ const remoteGenerator = await (0, remote_1.remoteGeneratorInternal)(tree, {
22
+ name: schema.remote,
23
+ e2eTestRunner: schema.e2eTestRunner,
24
+ skipFormat: schema.skipFormat,
25
+ linter: schema.linter,
26
+ style: schema.style,
27
+ unitTestRunner: schema.unitTestRunner,
28
+ host: schema.host,
29
+ projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
30
+ });
31
+ tasks.push(remoteGenerator);
32
+ }
33
+ const projectRoot = remote ? remote.root : remoteRoot;
34
+ const remoteName = remote ? remote.name : projectName;
35
+ // add path to exposes property
36
+ (0, utils_1.addPathToExposes)(tree, projectRoot, schema.name, schema.path);
37
+ // Add new path to tsconfig
38
+ const rootJSON = (0, devkit_1.readJson)(tree, (0, js_1.getRootTsConfigPathInTree)(tree));
39
+ if (!rootJSON?.compilerOptions?.paths[`${remoteName}/${schema.name}`]) {
40
+ (0, js_1.addTsConfigPath)(tree, `${remoteName}/${schema.name}`, [schema.path]);
41
+ }
42
+ if (!schema.skipFormat) {
43
+ await (0, devkit_1.formatFiles)(tree);
44
+ }
45
+ devkit_1.logger.info(`✅️ Updated module federation config.
46
+ Now you can use the module from your host app like this:
47
+
48
+ Static import:
49
+ import { MyComponent } from '${schema.name}/${remoteName}';
50
+
51
+ Dynamic import:
52
+ import('${schema.name}/${remoteName}').then((m) => m.${remoteName});
53
+ `);
54
+ return (0, devkit_1.runTasksInSerial)(...tasks);
55
+ }
56
+ exports.federateModuleGenerator = federateModuleGenerator;
57
+ exports.default = federateModuleGenerator;
58
+ exports.federateModuleSchematic = (0, devkit_1.convertNxGenerator)(federateModuleGenerator);
@@ -0,0 +1,23 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { SourceFile, ObjectLiteralExpression, PropertyAssignment } from 'typescript';
3
+ /**
4
+ * Adds a Module Federation path to the exposes property of the module federation config
5
+ * The assumption here is made the we will only update a TypeScript Module Federation file namely 'module-federation.config.js'
6
+ * @param tree Tree for the workspace
7
+ * @param projectPath Project path relative to the workspace
8
+ * @param moduleName The name of the module to expose
9
+ * @param modulePath The path to the module to expose (e.g. './src/my-lib/my-lib.ts')
10
+ */
11
+ export declare function addPathToExposes(tree: Tree, projectPath: string, moduleName: string, modulePath: string): void;
12
+ /**
13
+ * @param tree The workspace tree
14
+ * @param remoteName The name of the remote to check
15
+ * @returns Remote ProjectConfig if it exists, false otherwise
16
+ */
17
+ export declare function checkRemoteExists(tree: Tree, remoteName: string): false | import("@nx/devkit").ProjectConfiguration;
18
+ export declare function getRemote(tree: Tree, remoteName: string): import("@nx/devkit").ProjectConfiguration;
19
+ export declare function findExposes(sourceFile: SourceFile): ObjectLiteralExpression;
20
+ export declare function createObjectEntry(moduleName: string, modulePath: string): PropertyAssignment;
21
+ export declare function updateExposesPropertyinAST(source: SourceFile, exposesObject: ObjectLiteralExpression, newEntry: PropertyAssignment): SourceFile;
22
+ export declare function writeToConfig(tree: Tree, filename: string, source: SourceFile, updatedSourceFile: SourceFile): void;
23
+ export declare function updateExposesProperty(tree: Tree, filename: string, moduleName: string, modulePath: string): void;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateExposesProperty = exports.writeToConfig = exports.updateExposesPropertyinAST = exports.createObjectEntry = exports.findExposes = exports.getRemote = exports.checkRemoteExists = exports.addPathToExposes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ let tsModule;
7
+ if (!tsModule) {
8
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
9
+ }
10
+ /**
11
+ * Adds a Module Federation path to the exposes property of the module federation config
12
+ * The assumption here is made the we will only update a TypeScript Module Federation file namely 'module-federation.config.js'
13
+ * @param tree Tree for the workspace
14
+ * @param projectPath Project path relative to the workspace
15
+ * @param moduleName The name of the module to expose
16
+ * @param modulePath The path to the module to expose (e.g. './src/my-lib/my-lib.ts')
17
+ */
18
+ function addPathToExposes(tree, projectPath, moduleName, modulePath) {
19
+ const moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(projectPath, 'module-federation.config.js');
20
+ updateExposesProperty(tree, moduleFederationConfigPath, moduleName, modulePath);
21
+ }
22
+ exports.addPathToExposes = addPathToExposes;
23
+ /**
24
+ * @param tree The workspace tree
25
+ * @param remoteName The name of the remote to check
26
+ * @returns Remote ProjectConfig if it exists, false otherwise
27
+ */
28
+ function checkRemoteExists(tree, remoteName) {
29
+ const remote = getRemote(tree, remoteName);
30
+ if (!remote)
31
+ return false;
32
+ const hasModuleFederationConfig = tree.exists((0, devkit_1.joinPathFragments)(remote.root, 'module-federation.config.js'));
33
+ return hasModuleFederationConfig ? remote : false;
34
+ }
35
+ exports.checkRemoteExists = checkRemoteExists;
36
+ function getRemote(tree, remoteName) {
37
+ const projects = (0, devkit_1.getProjects)(tree);
38
+ const remote = projects.get(remoteName);
39
+ return remote;
40
+ }
41
+ exports.getRemote = getRemote;
42
+ // Check if the exposes property exists in the AST
43
+ function findExposes(sourceFile) {
44
+ let exposesObject = null;
45
+ const visit = (node) => {
46
+ if (tsModule.isPropertyAssignment(node) &&
47
+ tsModule.isIdentifier(node.name) &&
48
+ node.name.text === 'exposes' &&
49
+ tsModule.isObjectLiteralExpression(node.initializer)) {
50
+ exposesObject = node.initializer;
51
+ }
52
+ else {
53
+ tsModule.forEachChild(node, visit);
54
+ }
55
+ };
56
+ tsModule.forEachChild(sourceFile, visit);
57
+ return exposesObject;
58
+ }
59
+ exports.findExposes = findExposes;
60
+ // Create a new property assignment
61
+ function createObjectEntry(moduleName, modulePath) {
62
+ return tsModule.factory.createPropertyAssignment(tsModule.factory.createStringLiteral(`./${moduleName}`, true), tsModule.factory.createStringLiteral(modulePath, true));
63
+ }
64
+ exports.createObjectEntry = createObjectEntry;
65
+ // Update the exposes property in the AST
66
+ function updateExposesPropertyinAST(source, exposesObject, newEntry) {
67
+ const updatedExposes = tsModule.factory.updateObjectLiteralExpression(exposesObject, [...exposesObject.properties, newEntry]);
68
+ const transform = (context) => {
69
+ const visit = (node) => {
70
+ // Comparing nodes indirectly to ensure type compatibility. You must ensure that the nodes are identical.
71
+ return tsModule.isObjectLiteralExpression(node) && node === exposesObject
72
+ ? updatedExposes
73
+ : tsModule.visitEachChild(node, visit, context);
74
+ };
75
+ return (node) => tsModule.visitNode(node, visit);
76
+ };
77
+ return tsModule.transform(source, [transform]).transformed[0];
78
+ }
79
+ exports.updateExposesPropertyinAST = updateExposesPropertyinAST;
80
+ // Write the updated AST to the file (module-federation.config.js)
81
+ function writeToConfig(tree, filename, source, updatedSourceFile) {
82
+ const printer = tsModule.createPrinter();
83
+ const update = printer.printNode(tsModule.EmitHint.Unspecified, updatedSourceFile, source);
84
+ tree.write(filename, update);
85
+ }
86
+ exports.writeToConfig = writeToConfig;
87
+ function updateExposesProperty(tree, filename, moduleName, modulePath) {
88
+ const fileContent = tree.read(filename).toString();
89
+ const source = tsModule.createSourceFile(filename, fileContent, tsModule.ScriptTarget.ES2015, true);
90
+ const exposesObject = findExposes(source);
91
+ if (!exposesObject)
92
+ return;
93
+ const newEntry = createObjectEntry(moduleName, modulePath);
94
+ const updatedSourceFile = updateExposesPropertyinAST(source, exposesObject, newEntry);
95
+ writeToConfig(tree, filename, source, updatedSourceFile);
96
+ }
97
+ exports.updateExposesProperty = updateExposesProperty;
@@ -0,0 +1,12 @@
1
+ export interface Schema {
2
+ name: string;
3
+ path: string;
4
+ remote: string;
5
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
6
+ e2eTestRunner?: 'cypress' | 'none';
7
+ host?: string;
8
+ linter?: Linter;
9
+ skipFormat?: boolean;
10
+ style?: SupportedStyles;
11
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
12
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxReactFederateModule",
5
+ "title": "Federate Module",
6
+ "description": "Create a federated module, which can be loaded by a remote host.",
7
+ "examples": [
8
+ {
9
+ "command": "nx g federate-module MyModule --path=./src/component/my-cmp.ts --remote=my-remote-app",
10
+ "description": "Create a federated module from my-remote-app, that exposes my-cmp from ./src/component/my-cmp.ts as MyModule."
11
+ }
12
+ ],
13
+ "type": "object",
14
+ "properties": {
15
+ "name": {
16
+ "description": "The name of the module.",
17
+ "type": "string",
18
+ "$default": {
19
+ "$source": "argv",
20
+ "index": 0
21
+ },
22
+ "x-prompt": "What name would you like to use for the module?",
23
+ "pattern": "^[a-zA-Z][^:]*$",
24
+ "x-priority": "important"
25
+ },
26
+ "path": {
27
+ "type": "string",
28
+ "description": "The path to locate the federated module.",
29
+ "x-prompt": "What is the path to the module to be federated?"
30
+ },
31
+ "remote": {
32
+ "type": "string",
33
+ "description": "The name of the remote.",
34
+ "x-prompt": "What is/should the remote be named?"
35
+ },
36
+ "projectNameAndRootFormat": {
37
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
38
+ "type": "string",
39
+ "enum": ["as-provided", "derived"]
40
+ },
41
+ "style": {
42
+ "description": "The file extension to be used for style files.",
43
+ "type": "string",
44
+ "default": "css",
45
+ "alias": "s",
46
+ "x-prompt": {
47
+ "message": "Which stylesheet format would you like to use?",
48
+ "type": "list",
49
+ "items": [
50
+ {
51
+ "value": "css",
52
+ "label": "CSS"
53
+ },
54
+ {
55
+ "value": "scss",
56
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
57
+ },
58
+ {
59
+ "value": "less",
60
+ "label": "LESS [ http://lesscss.org ]"
61
+ },
62
+ {
63
+ "value": "styled-components",
64
+ "label": "styled-components [ https://styled-components.com ]"
65
+ },
66
+ {
67
+ "value": "@emotion/styled",
68
+ "label": "emotion [ https://emotion.sh ]"
69
+ },
70
+ {
71
+ "value": "styled-jsx",
72
+ "label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
73
+ },
74
+ {
75
+ "value": "styl",
76
+ "label": "DEPRECATD: Stylus(.styl) [ http://stylus-lang.com ]"
77
+ },
78
+ {
79
+ "value": "none",
80
+ "label": "None"
81
+ }
82
+ ]
83
+ }
84
+ },
85
+ "linter": {
86
+ "description": "The tool to use for running lint checks.",
87
+ "type": "string",
88
+ "enum": ["eslint"],
89
+ "default": "eslint"
90
+ },
91
+ "skipFormat": {
92
+ "description": "Skip formatting files.",
93
+ "type": "boolean",
94
+ "default": false,
95
+ "x-priority": "internal"
96
+ },
97
+ "unitTestRunner": {
98
+ "type": "string",
99
+ "enum": ["jest", "none"],
100
+ "description": "Test runner to use for unit tests.",
101
+ "default": "jest"
102
+ },
103
+ "e2eTestRunner": {
104
+ "type": "string",
105
+ "enum": ["cypress", "none"],
106
+ "description": "Test runner to use for end to end (e2e) tests.",
107
+ "default": "cypress"
108
+ },
109
+ "host": {
110
+ "type": "string",
111
+ "description": "The host / shell application for this remote."
112
+ }
113
+ },
114
+ "required": ["name", "path", "remote"],
115
+ "additionalProperties": false
116
+ }
@@ -43,7 +43,7 @@ async function remoteGeneratorInternal(host, schema) {
43
43
  const tasks = [];
44
44
  const options = {
45
45
  ...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:remote')),
46
- typescriptConfiguration: schema.typescriptConfiguration ?? true,
46
+ typescriptConfiguration: schema.typescriptConfiguration ?? false,
47
47
  };
48
48
  const initAppTask = await (0, application_1.default)(host, {
49
49
  ...options,
@@ -124,12 +124,15 @@ async function setupSsrGenerator(tree, options) {
124
124
  (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
125
125
  const nxJson = (0, devkit_1.readNxJson)(tree);
126
126
  if (nxJson.tasksRunnerOptions?.default &&
127
- !nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('server')) {
127
+ !nxJson.tasksRunnerOptions?.default.options.cacheableOperations.includes('server')) {
128
128
  nxJson.tasksRunnerOptions.default.options.cacheableOperations = [
129
129
  ...nxJson.tasksRunnerOptions.default.options.cacheableOperations,
130
130
  'server',
131
131
  ];
132
132
  }
133
+ nxJson.targetDefaults ??= {};
134
+ nxJson.targetDefaults['server'] ??= {};
135
+ nxJson.targetDefaults.server.cache = true;
133
136
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
134
137
  tmpl: '',
135
138
  extraInclude: options.extraInclude?.length > 0
@@ -5,7 +5,7 @@ const stories_1 = require("../stories/stories");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const versions_1 = require("../../utils/versions");
7
7
  async function generateStories(host, schema) {
8
- // TODO(v18): remove Cypress
8
+ // TODO(katerina): Nx 18 -> remove Cypress
9
9
  (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
10
10
  const { getE2eProjectName } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/project-name'));
11
11
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, schema.name);
@@ -8,6 +8,11 @@ async function addTypings(tree) {
8
8
  '@nx/vite:build',
9
9
  '@nx/rspack:rspack',
10
10
  ];
11
+ const serveExecutors = [
12
+ '@nx/webpack:dev-server',
13
+ '@nx/vite:dev-server',
14
+ '@nx/rspack:dev-server',
15
+ ];
11
16
  const relatedTsConfigs = [
12
17
  'tsconfig.app.json',
13
18
  'tsconfig.lib.json',
@@ -18,24 +23,34 @@ async function addTypings(tree) {
18
23
  '@nx/react/typings/image.d.ts',
19
24
  ];
20
25
  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
- });
26
+ if (!buildExecutors.includes(config?.targets?.build?.executor)) {
27
+ continue;
28
+ }
29
+ if (config?.targets?.serve?.executor &&
30
+ !serveExecutors.includes(config?.targets?.serve?.executor)) {
31
+ continue;
32
+ }
33
+ const rootPath = config.root;
34
+ const projectTsConfigPath = (0, devkit_1.joinPathFragments)(rootPath, 'tsconfig.json');
35
+ const projectTsConfig = (0, devkit_1.readJson)(tree, projectTsConfigPath);
36
+ if (projectTsConfig.compilerOptions?.jsx !== 'react-jsx') {
37
+ continue;
38
38
  }
39
+ relatedTsConfigs.forEach((tsConfig) => {
40
+ const tsConfigPath = (0, devkit_1.joinPathFragments)(rootPath, tsConfig);
41
+ if (tree.exists(tsConfigPath)) {
42
+ (0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
43
+ const compilerOptions = json.compilerOptions || {};
44
+ compilerOptions.types = [
45
+ ...new Set([...(compilerOptions.types || []), ...typesToAdd]),
46
+ ];
47
+ if (json.files?.length > 0) {
48
+ json.files = json.files.filter((file) => !['cssmodule.d.ts', 'image.d.ts'].includes(file));
49
+ }
50
+ return { ...json, compilerOptions };
51
+ });
52
+ }
53
+ });
39
54
  }
40
55
  await (0, devkit_1.formatFiles)(tree);
41
56
  }
@@ -14,14 +14,13 @@ async function withModuleFederation(options) {
14
14
  config.output.publicPath = 'auto';
15
15
  if (options.library?.type === 'var') {
16
16
  config.output.scriptType = 'text/javascript';
17
- config.experiments.outputModule = false;
18
17
  }
19
18
  config.optimization = {
20
19
  runtimeChunk: false,
21
20
  };
22
21
  config.experiments = {
23
22
  ...config.experiments,
24
- outputModule: true,
23
+ outputModule: !(options.library?.type === 'var'),
25
24
  };
26
25
  config.plugins.push(new ModuleFederationPlugin({
27
26
  name: options.name,
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function removeReactReduxTypesFromPackageJson(host: Tree): Promise<import("@nx/devkit").GeneratorCallback>;
3
- export default removeReactReduxTypesFromPackageJson;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeReactReduxTypesFromPackageJson = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- async function removeReactReduxTypesFromPackageJson(host) {
6
- return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@types/react-redux'], ['@types/react-redux']);
7
- }
8
- exports.removeReactReduxTypesFromPackageJson = removeReactReduxTypesFromPackageJson;
9
- exports.default = removeReactReduxTypesFromPackageJson;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function updateEmotionSetup(host: Tree): Promise<void>;
3
- export default updateEmotionSetup;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateEmotionSetup = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- async function updateEmotionSetup(host) {
6
- const projects = (0, devkit_1.getProjects)(host);
7
- projects.forEach((p) => {
8
- const babelrcPath = `${p.root}/.babelrc`;
9
- const oldPreset = '@emotion/babel-preset-css-prop';
10
- const newPlugin = '@emotion/babel-plugin';
11
- if (host.exists(babelrcPath)) {
12
- (0, devkit_1.updateJson)(host, babelrcPath, (json) => {
13
- if (!json.presets)
14
- return json;
15
- let emotionPresetIdx = -1;
16
- let emotionOptions = null;
17
- for (const [idx, preset] of json.presets.entries()) {
18
- if (Array.isArray(preset)) {
19
- if (!preset[0].includes(oldPreset))
20
- continue;
21
- emotionOptions = preset[1];
22
- emotionPresetIdx = idx;
23
- break;
24
- }
25
- else {
26
- if (!preset.includes(oldPreset))
27
- continue;
28
- emotionPresetIdx = idx;
29
- break;
30
- }
31
- }
32
- if (emotionPresetIdx !== -1) {
33
- // Remove preset
34
- json.presets.splice(emotionPresetIdx, 1);
35
- // Add new plugin
36
- json.plugins ??= [];
37
- json.plugins.push(emotionOptions ? [newPlugin, emotionOptions] : newPlugin);
38
- return json;
39
- }
40
- else {
41
- return json;
42
- }
43
- });
44
- }
45
- });
46
- (0, devkit_1.updateJson)(host, 'package.json', (json) => {
47
- if (json.devDependencies?.['@emotion/babel-preset-css-prop']) {
48
- delete json.devDependencies['@emotion/babel-preset-css-prop'];
49
- json.devDependencies['@emotion/babel-plugin'] = '11.2.0';
50
- }
51
- // Just in case someone moved it to `dependencies`
52
- else if (json.dependencies?.['@emotion/babel-preset-css-prop']) {
53
- delete json.dependencies['@emotion/babel-preset-css-prop'];
54
- json.dependencies['@emotion/babel-plugin'] = '11.2.0';
55
- }
56
- return json;
57
- });
58
- await (0, devkit_1.formatFiles)(host);
59
- }
60
- exports.updateEmotionSetup = updateEmotionSetup;
61
- exports.default = updateEmotionSetup;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function useReactJsxInTsconfig(host: Tree): Promise<void>;
3
- export default useReactJsxInTsconfig;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useReactJsxInTsconfig = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- async function useReactJsxInTsconfig(host) {
6
- const projects = (0, devkit_1.getProjects)(host);
7
- projects.forEach((p) => {
8
- const tsConfigPath = `${p.root}/tsconfig.json`;
9
- if (host.exists(tsConfigPath)) {
10
- (0, devkit_1.updateJson)(host, tsConfigPath, (json) => {
11
- if (json.compilerOptions?.jsx === 'react') {
12
- // JSX is handled by babel
13
- json.compilerOptions.jsx = 'react-jsx';
14
- }
15
- return json;
16
- });
17
- }
18
- });
19
- await (0, devkit_1.formatFiles)(host);
20
- }
21
- exports.useReactJsxInTsconfig = useReactJsxInTsconfig;
22
- exports.default = useReactJsxInTsconfig;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function removeReactReduxTypesFromPackageJson(host: Tree): Promise<import("@nx/devkit").GeneratorCallback>;
3
- export default removeReactReduxTypesFromPackageJson;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeReactReduxTypesFromPackageJson = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- async function removeReactReduxTypesFromPackageJson(host) {
6
- return (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
7
- '@testing-library/react-hooks': '^7.0.1',
8
- });
9
- }
10
- exports.removeReactReduxTypesFromPackageJson = removeReactReduxTypesFromPackageJson;
11
- exports.default = removeReactReduxTypesFromPackageJson;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function migrateStorybookToWebPack5(tree: Tree): Promise<void>;
3
- export default migrateStorybookToWebPack5;