@nx/react 18.0.3 → 18.0.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 (42) hide show
  1. package/package.json +6 -6
  2. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +10 -0
  3. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +49 -27
  4. package/src/generators/application/application.js +2 -1
  5. package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +1 -1
  6. package/src/generators/application/lib/add-e2e.js +2 -2
  7. package/src/generators/application/lib/add-project.d.ts +0 -1
  8. package/src/generators/application/lib/add-project.js +5 -10
  9. package/src/generators/application/lib/add-routing.d.ts +1 -1
  10. package/src/generators/application/lib/add-routing.js +4 -8
  11. package/src/generators/application/lib/create-application-files.js +3 -3
  12. package/src/generators/application/lib/update-jest-config.js +2 -1
  13. package/src/generators/federate-module/schema.json +2 -1
  14. package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +33 -0
  15. package/src/generators/host/host.js +5 -1
  16. package/src/generators/host/lib/add-module-federation-files.d.ts +1 -1
  17. package/src/generators/host/lib/add-module-federation-files.js +3 -2
  18. package/src/generators/host/lib/update-module-federation-e2e-project.js +7 -5
  19. package/src/generators/host/schema.json +3 -2
  20. package/src/generators/library/lib/add-rollup-build-target.js +1 -1
  21. package/src/generators/library/lib/update-app-routes.js +1 -1
  22. package/src/generators/library/library.js +4 -3
  23. package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +1 -1
  24. package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
  25. package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  26. package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
  27. package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -1
  28. package/src/generators/remote/lib/update-host-with-remote.js +10 -1
  29. package/src/generators/remote/remote.js +8 -2
  30. package/src/generators/remote/schema.json +3 -2
  31. package/src/rules/update-module-federation-project.d.ts +1 -0
  32. package/src/rules/update-module-federation-project.js +5 -4
  33. package/src/utils/maybe-js.d.ts +3 -0
  34. package/src/generators/library/lib/maybe-js.d.ts +0 -2
  35. /package/src/generators/host/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
  36. /package/src/generators/host/files/{common → common-ts}/src/app/__fileName__.tsx__tmpl__ +0 -0
  37. /package/src/generators/host/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
  38. /package/src/generators/remote/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
  39. /package/src/generators/remote/files/{module-federation/src/remote-entry.ts__tmpl__ → common/src/remote-entry.js__tmpl__} +0 -0
  40. /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
  41. /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__ +0 -0
  42. /package/src/{generators/library/lib → utils}/maybe-js.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "18.0.3",
3
+ "version": "18.0.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": {
@@ -36,11 +36,11 @@
36
36
  "chalk": "^4.1.0",
37
37
  "minimatch": "9.0.3",
38
38
  "tslib": "^2.3.0",
39
- "@nx/devkit": "18.0.3",
40
- "@nx/js": "18.0.3",
41
- "@nx/eslint": "18.0.3",
42
- "@nx/web": "18.0.3",
43
- "@nrwl/react": "18.0.3"
39
+ "@nx/devkit": "18.0.5",
40
+ "@nx/js": "18.0.5",
41
+ "@nx/eslint": "18.0.5",
42
+ "@nx/web": "18.0.5",
43
+ "@nrwl/react": "18.0.5"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
@@ -8,6 +8,16 @@ type ModuleFederationDevServerOptions = WebDevServerOptions & {
8
8
  parallel?: number;
9
9
  staticRemotesPort?: number;
10
10
  };
11
+ type StaticRemoteConfig = {
12
+ basePath: string;
13
+ outputPath: string;
14
+ urlSegment: string;
15
+ };
16
+ type StaticRemotesConfig = {
17
+ remotes: string[];
18
+ config: Record<string, StaticRemoteConfig> | undefined;
19
+ };
20
+ export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
11
21
  export default function moduleFederationDevServer(options: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncIterableIterator<{
12
22
  success: boolean;
13
23
  baseUrl?: string;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStaticRemotesConfig = void 0;
3
4
  const devkit_1 = require("@nx/devkit");
4
5
  const dev_server_impl_1 = require("@nx/webpack/src/executors/dev-server/dev-server.impl");
5
6
  const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
@@ -16,26 +17,24 @@ function getBuildOptions(buildTarget, context) {
16
17
  ...buildOptions,
17
18
  };
18
19
  }
19
- function startStaticRemotesFileServer(remotes, context, options) {
20
+ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
20
21
  let shouldMoveToCommonLocation = false;
21
22
  let commonOutputDirectory;
22
- for (const app of remotes.staticRemotes) {
23
- const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
24
- const directoryOfOutputPath = (0, path_1.dirname)(outputPath);
23
+ for (const app of staticRemotesConfig.remotes) {
24
+ const remoteBasePath = staticRemotesConfig.config[app].basePath;
25
25
  if (!commonOutputDirectory) {
26
- commonOutputDirectory = directoryOfOutputPath;
26
+ commonOutputDirectory = remoteBasePath;
27
27
  }
28
- else if (commonOutputDirectory !== directoryOfOutputPath ||
29
- !outputPath.endsWith(app)) {
28
+ else if (commonOutputDirectory !== remoteBasePath) {
30
29
  shouldMoveToCommonLocation = true;
30
+ break;
31
31
  }
32
32
  }
33
33
  if (shouldMoveToCommonLocation) {
34
34
  commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
35
- for (const app of remotes.staticRemotes) {
36
- const outputPath = context.projectGraph.nodes[app].data.targets['build'].options
37
- .outputPath;
38
- (0, fs_1.cpSync)(outputPath, (0, path_1.join)(commonOutputDirectory, app), {
35
+ for (const app of staticRemotesConfig.remotes) {
36
+ const remoteConfig = staticRemotesConfig.config[app];
37
+ (0, fs_1.cpSync)(remoteConfig.outputPath, (0, path_1.join)(commonOutputDirectory, remoteConfig.urlSegment), {
39
38
  force: true,
40
39
  recursive: true,
41
40
  });
@@ -56,7 +55,7 @@ function startStaticRemotesFileServer(remotes, context, options) {
56
55
  }, context);
57
56
  return staticRemotesIter;
58
57
  }
59
- async function startDevRemotes(remotes, context) {
58
+ async function startDevRemotes(remotes, context, options) {
60
59
  const devRemoteIters = [];
61
60
  for (const app of remotes.devRemotes) {
62
61
  const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets['serve'];
@@ -67,6 +66,10 @@ async function startDevRemotes(remotes, context) {
67
66
  configuration: context.configurationName,
68
67
  }, {
69
68
  watch: true,
69
+ ...(options.host ? { host: options.host } : {}),
70
+ ...(options.ssl ? { ssl: options.ssl } : {}),
71
+ ...(options.sslCert ? { sslCert: options.sslCert } : {}),
72
+ ...(options.sslKey ? { sslKey: options.sslKey } : {}),
70
73
  ...(isUsingModuleFederationDevServerExecutor
71
74
  ? { isInitialHost: false }
72
75
  : {}),
@@ -74,21 +77,21 @@ async function startDevRemotes(remotes, context) {
74
77
  }
75
78
  return devRemoteIters;
76
79
  }
77
- async function buildStaticRemotes(remotes, nxBin, context, options) {
78
- if (!remotes.staticRemotes.length) {
80
+ async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options) {
81
+ if (!staticRemotesConfig.remotes.length) {
79
82
  return;
80
83
  }
81
- devkit_1.logger.info(`NX Building ${remotes.staticRemotes.length} static remotes...`);
84
+ devkit_1.logger.info(`NX Building ${staticRemotesConfig.remotes.length} static remotes...`);
82
85
  const mappedLocationOfRemotes = {};
83
- for (const app of remotes.staticRemotes) {
84
- mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${app}`;
86
+ for (const app of staticRemotesConfig.remotes) {
87
+ mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[app].urlSegment}`;
85
88
  }
86
89
  process.env.NX_MF_DEV_SERVER_STATIC_REMOTES = JSON.stringify(mappedLocationOfRemotes);
87
90
  await new Promise((res) => {
88
91
  const staticProcess = (0, child_process_1.fork)(nxBin, [
89
92
  'run-many',
90
93
  `--target=build`,
91
- `--projects=${remotes.staticRemotes.join(',')}`,
94
+ `--projects=${staticRemotesConfig.remotes.join(',')}`,
92
95
  ...(context.configurationName
93
96
  ? [`--configuration=${context.configurationName}`]
94
97
  : []),
@@ -102,7 +105,7 @@ async function buildStaticRemotes(remotes, nxBin, context, options) {
102
105
  const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
103
106
  if (stdoutString.includes('Successfully ran target build')) {
104
107
  staticProcess.stdout.removeAllListeners('data');
105
- devkit_1.logger.info(`NX Built ${remotes.staticRemotes.length} static remotes`);
108
+ devkit_1.logger.info(`NX Built ${staticRemotesConfig.remotes.length} static remotes`);
106
109
  res();
107
110
  }
108
111
  });
@@ -116,6 +119,20 @@ async function buildStaticRemotes(remotes, nxBin, context, options) {
116
119
  process.on('exit', () => staticProcess.kill('SIGTERM'));
117
120
  });
118
121
  }
122
+ function parseStaticRemotesConfig(staticRemotes, context) {
123
+ if (!staticRemotes?.length) {
124
+ return { remotes: [], config: undefined };
125
+ }
126
+ const config = {};
127
+ for (const app of staticRemotes) {
128
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
129
+ const basePath = (0, path_1.dirname)(outputPath);
130
+ const urlSegment = (0, path_1.basename)(outputPath);
131
+ config[app] = { basePath, outputPath, urlSegment };
132
+ }
133
+ return { remotes: staticRemotes, config };
134
+ }
135
+ exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
119
136
  async function* moduleFederationDevServer(options, context) {
120
137
  const initialStaticRemotesPorts = options.staticRemotesPort;
121
138
  options.staticRemotesPort ??= options.port + 1;
@@ -152,10 +169,11 @@ async function* moduleFederationDevServer(options, context) {
152
169
  }
153
170
  }, options.staticRemotesPort);
154
171
  }
155
- await buildStaticRemotes(remotes, nxBin, context, options);
156
- const devRemoteIters = await startDevRemotes(remotes, context);
172
+ const staticRemotesConfig = parseStaticRemotesConfig(remotes.staticRemotes, context);
173
+ await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
174
+ const devRemoteIters = await startDevRemotes(remotes, context, options);
157
175
  const staticRemotesIter = remotes.staticRemotes.length > 0
158
- ? startStaticRemotesFileServer(remotes, context, options)
176
+ ? startStaticRemotesFileServer(staticRemotesConfig, context, options)
159
177
  : undefined;
160
178
  return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
161
179
  if (!options.isInitialHost) {
@@ -167,19 +185,23 @@ async function* moduleFederationDevServer(options, context) {
167
185
  return;
168
186
  }
169
187
  try {
188
+ const host = options.host ?? 'localhost';
189
+ const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
170
190
  const portsToWaitFor = staticRemotesIter
171
191
  ? [options.staticRemotesPort, ...remotes.remotePorts]
172
192
  : [...remotes.remotePorts];
173
193
  await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
174
194
  retries: 480,
175
195
  retryDelay: 2500,
176
- host: 'localhost',
196
+ host: host,
177
197
  })));
178
- devkit_1.logger.info(`NX All remotes started, server ready at http://localhost:${options.port}`);
179
- next({ success: true, baseUrl: `http://localhost:${options.port}` });
198
+ devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
199
+ next({ success: true, baseUrl: baseUrl });
180
200
  }
181
- catch {
182
- throw new Error(`Timed out waiting for remote to start. Check above for any errors.`);
201
+ catch (err) {
202
+ throw new Error(`Failed to start remotes. Check above for any errors.`, {
203
+ cause: err,
204
+ });
183
205
  }
184
206
  finally {
185
207
  done();
@@ -14,6 +14,7 @@ const devkit_1 = require("@nx/devkit");
14
14
  const init_1 = require("../init/init");
15
15
  const eslint_1 = require("@nx/eslint");
16
16
  const versions_1 = require("../../utils/versions");
17
+ const maybe_js_1 = require("../../utils/maybe-js");
17
18
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
18
19
  const create_ts_config_1 = require("../../utils/create-ts-config");
19
20
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
@@ -131,7 +132,7 @@ async function applicationGeneratorInternal(host, schema) {
131
132
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
132
133
  const rspackTask = await configurationGenerator(host, {
133
134
  project: options.projectName,
134
- main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, add_project_1.maybeJs)(options, `src/main.tsx`)),
135
+ main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
135
136
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
136
137
  target: 'web',
137
138
  newProject: true,
@@ -735,7 +735,7 @@ export function NxWelcome({ title }: { title: string }) {
735
735
  You can activate distributed tasks executions and caching by
736
736
  running:
737
737
  </p>
738
- <pre>nx connect-to-nx-cloud</pre>
738
+ <pre>nx connect</pre>
739
739
  <a
740
740
  href="https://nx.app/?utm_source=nx-project"
741
741
  target="_blank"
@@ -34,7 +34,7 @@ async function addE2e(tree, options) {
34
34
  bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
35
35
  skipFormat: true,
36
36
  devServerTarget: `${options.projectName}:serve`,
37
- baseUrl: 'http://localhost:4200',
37
+ baseUrl: `http://localhost:${options.devServerPort ?? 4200}`,
38
38
  jsx: true,
39
39
  rootProject: options.rootProject,
40
40
  webServerCommands: hasNxBuildPlugin
@@ -66,7 +66,7 @@ async function addE2e(tree, options) {
66
66
  linter: options.linter,
67
67
  setParserOptionsProject: options.setParserOptionsProject,
68
68
  webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
69
- webServerAddress: 'http://localhost:4200',
69
+ webServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
70
70
  rootProject: options.rootProject,
71
71
  addPlugin: options.addPlugin,
72
72
  });
@@ -1,4 +1,3 @@
1
1
  import { NormalizedSchema } from '../schema';
2
2
  import { Tree } from '@nx/devkit';
3
3
  export declare function addProject(host: Tree, options: NormalizedSchema): void;
4
- export declare function maybeJs(options: NormalizedSchema, path: string): string;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeJs = exports.addProject = void 0;
3
+ exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
6
+ const maybe_js_1 = require("../../../utils/maybe-js");
6
7
  function addProject(host, options) {
7
8
  const project = {
8
9
  root: options.appProjectRoot,
@@ -24,12 +25,6 @@ function addProject(host, options) {
24
25
  });
25
26
  }
26
27
  exports.addProject = addProject;
27
- function maybeJs(options, path) {
28
- return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
29
- ? path.replace(/\.tsx?$/, '.js')
30
- : path;
31
- }
32
- exports.maybeJs = maybeJs;
33
28
  function createBuildTarget(options) {
34
29
  return {
35
30
  executor: '@nx/webpack:webpack',
@@ -42,7 +37,7 @@ function createBuildTarget(options) {
42
37
  : options.projectName),
43
38
  index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
44
39
  baseHref: '/',
45
- main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/main.tsx`)),
40
+ main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
46
41
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
47
42
  assets: [
48
43
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
@@ -66,8 +61,8 @@ function createBuildTarget(options) {
66
61
  production: {
67
62
  fileReplacements: [
68
63
  {
69
- replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.ts`)),
70
- with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.prod.ts`)),
64
+ replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.ts`)),
65
+ with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.prod.ts`)),
71
66
  },
72
67
  ],
73
68
  optimization: true,
@@ -1,3 +1,3 @@
1
- import { NormalizedSchema } from '../schema';
2
1
  import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
3
  export declare function addRouting(host: Tree, options: NormalizedSchema): import("@nx/devkit").GeneratorCallback;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addRouting = void 0;
4
- const ast_utils_1 = require("../../../utils/ast-utils");
5
- const versions_1 = require("../../../utils/versions");
6
4
  const devkit_1 = require("@nx/devkit");
7
5
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ const ast_utils_1 = require("../../../utils/ast-utils");
7
+ const versions_1 = require("../../../utils/versions");
8
+ const maybe_js_1 = require("../../../utils/maybe-js");
8
9
  let tsModule;
9
10
  function addRouting(host, options) {
10
11
  if (!options.routing) {
@@ -13,7 +14,7 @@ function addRouting(host, options) {
13
14
  if (!tsModule) {
14
15
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
15
16
  }
16
- const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/app/${options.fileName}.tsx`));
17
+ const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/app/${options.fileName}.tsx`));
17
18
  const appFileContent = host.read(appPath, 'utf-8');
18
19
  const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
19
20
  const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
@@ -24,8 +25,3 @@ function addRouting(host, options) {
24
25
  return () => { };
25
26
  }
26
27
  exports.addRouting = addRouting;
27
- function maybeJs(options, path) {
28
- return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
29
- ? path.replace(/\.tsx?$/, '.js')
30
- : path;
31
- }
@@ -6,9 +6,9 @@ const js_1 = require("@nx/js");
6
6
  const path_1 = require("path");
7
7
  const create_ts_config_1 = require("../../../utils/create-ts-config");
8
8
  const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
9
- const get_app_tests_1 = require("./get-app-tests");
10
- const add_project_1 = require("./add-project");
9
+ const maybe_js_1 = require("../../../utils/maybe-js");
11
10
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
11
+ const get_app_tests_1 = require("./get-app-tests");
12
12
  function createApplicationFiles(host, options) {
13
13
  let styleSolutionSpecificAppFiles;
14
14
  if (options.styledModule && options.style !== 'styled-jsx') {
@@ -128,7 +128,7 @@ function createNxWebpackPluginOptions(options) {
128
128
  : options.projectName),
129
129
  index: './src/index.html',
130
130
  baseHref: '/',
131
- main: (0, add_project_1.maybeJs)(options, `./src/main.tsx`),
131
+ main: (0, maybe_js_1.maybeJs)(options, `./src/main.tsx`),
132
132
  tsConfig: './tsconfig.app.json',
133
133
  assets: ['./src/favicon.ico', './src/assets'],
134
134
  styles: options.styledModule || !options.hasStyles
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateSpecConfig = void 0;
4
+ const maybe_js_1 = require("../../../utils/maybe-js");
4
5
  const jest_utils_1 = require("../../../utils/jest-utils");
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  function updateSpecConfig(host, options) {
@@ -21,7 +22,7 @@ function updateSpecConfig(host, options) {
21
22
  if (options.unitTestRunner !== 'jest') {
22
23
  return;
23
24
  }
24
- const configPath = `${options.appProjectRoot}/jest.config.${options.js ? 'js' : 'ts'}`;
25
+ const configPath = (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/jest.config.ts`);
25
26
  const originalContent = host.read(configPath, 'utf-8');
26
27
  const content = (0, jest_utils_1.updateJestConfigContent)(originalContent);
27
28
  host.write(configPath, content);
@@ -69,7 +69,8 @@
69
69
  "e2eTestRunner": {
70
70
  "type": "string",
71
71
  "enum": ["cypress", "playwright", "none"],
72
- "description": "Test runner to use for end to end (e2e) tests.",
72
+ "description": "Test runner to use for end to end (E2E) tests.",
73
+ "x-prompt": "Which E2E test runner would you like to use?",
73
74
  "default": "cypress"
74
75
  },
75
76
  "host": {
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ <% if (!minimal) { %>
3
+ import NxWelcome from "./nx-welcome";
4
+ <% } %>
5
+ import { Link, Route, Routes } from 'react-router-dom';
6
+
7
+ <% if (remotes.length > 0) { %>
8
+ <% remotes.forEach(function(r) { %>
9
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
10
+ <% }); %>
11
+ <% } %>
12
+ export function App() {
13
+ return (
14
+ <React.Suspense fallback={null}>
15
+ <ul>
16
+ <li><Link to="/">Home</Link></li>
17
+ <% remotes.forEach(function(r) { %>
18
+ <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
19
+ <% }); %>
20
+ </ul>
21
+ <Routes>
22
+ <% if (!minimal) { %>
23
+ <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
24
+ <% } %>
25
+ <% remotes.forEach(function(r) { %>
26
+ <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
27
+ <% }); %>
28
+ </Routes>
29
+ </React.Suspense>
30
+ );
31
+ }
32
+
33
+ export default App;
@@ -23,7 +23,10 @@ async function hostGeneratorInternal(host, schema) {
23
23
  const tasks = [];
24
24
  const options = {
25
25
  ...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:host')),
26
- typescriptConfiguration: schema.typescriptConfiguration ?? true,
26
+ js: schema.js ?? false,
27
+ typescriptConfiguration: schema.js
28
+ ? false
29
+ : schema.typescriptConfiguration ?? true,
27
30
  dynamic: schema.dynamic ?? false,
28
31
  // TODO(colum): remove when MF works with Crystal
29
32
  addPlugin: false,
@@ -55,6 +58,7 @@ async function hostGeneratorInternal(host, schema) {
55
58
  skipFormat: true,
56
59
  projectNameAndRootFormat: options.projectNameAndRootFormat,
57
60
  typescriptConfiguration: options.typescriptConfiguration,
61
+ js: options.js,
58
62
  dynamic: options.dynamic,
59
63
  host: options.name,
60
64
  });
@@ -1,5 +1,5 @@
1
- import { NormalizedSchema } from '../schema';
2
1
  import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
3
  export declare function addModuleFederationFiles(host: Tree, options: NormalizedSchema, defaultRemoteManifest: {
4
4
  name: string;
5
5
  port: number;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addModuleFederationFiles = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const maybe_js_1 = require("../../../utils/maybe-js");
5
6
  function addModuleFederationFiles(host, options, defaultRemoteManifest) {
6
7
  const templateVariables = {
7
8
  ...(0, devkit_1.names)(options.name),
@@ -20,8 +21,8 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
20
21
  // Module federation requires bootstrap code to be dynamically imported.
21
22
  // Renaming original entry file so we can use `import(./bootstrap)` in
22
23
  // new entry file.
23
- host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/main.tsx'), (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/bootstrap.tsx'));
24
- (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/common`), options.appProjectRoot, templateVariables);
24
+ host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
25
+ (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/${options.js ? 'common' : 'common-ts'}`), options.appProjectRoot, templateVariables);
25
26
  const pathToModuleFederationFiles = options.typescriptConfiguration
26
27
  ? 'module-federation-ts'
27
28
  : 'module-federation';
@@ -5,11 +5,13 @@ const devkit_1 = require("@nx/devkit");
5
5
  function updateModuleFederationE2eProject(host, options) {
6
6
  try {
7
7
  let projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.e2eProjectName);
8
- projectConfig.targets.e2e.options = {
9
- ...projectConfig.targets.e2e.options,
10
- baseUrl: `http://localhost:${options.devServerPort}`,
11
- };
12
- (0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
8
+ if (projectConfig.targets.e2e.executor !== '@nx/playwright:playwright') {
9
+ projectConfig.targets.e2e.options = {
10
+ ...projectConfig.targets.e2e.options,
11
+ baseUrl: `http://localhost:${options.devServerPort}`,
12
+ };
13
+ (0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
14
+ }
13
15
  }
14
16
  catch {
15
17
  // nothing
@@ -100,7 +100,8 @@
100
100
  "e2eTestRunner": {
101
101
  "type": "string",
102
102
  "enum": ["cypress", "playwright", "none"],
103
- "description": "Test runner to use for end to end (e2e) tests.",
103
+ "description": "Test runner to use for end to end (E2E) tests.",
104
+ "x-prompt": "Which E2E test runner would you like to use?",
104
105
  "default": "cypress"
105
106
  },
106
107
  "tags": {
@@ -170,7 +171,7 @@
170
171
  },
171
172
  "typescriptConfiguration": {
172
173
  "type": "boolean",
173
- "description": "Whether the module federation configuration and webpack configuration files should use TS.",
174
+ "description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
174
175
  "default": true
175
176
  }
176
177
  },
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addRollupBuildTarget = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const maybe_js_1 = require("./maybe-js");
5
+ const maybe_js_1 = require("../../../utils/maybe-js");
6
6
  const versions_1 = require("../../../utils/versions");
7
7
  async function addRollupBuildTarget(host, options) {
8
8
  const tasks = [];
@@ -4,7 +4,7 @@ exports.updateAppRoutes = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const ast_utils_1 = require("../../../utils/ast-utils");
6
6
  const ast_utils_2 = require("../../../utils/ast-utils");
7
- const maybe_js_1 = require("./maybe-js");
7
+ const maybe_js_1 = require("../../../utils/maybe-js");
8
8
  const versions_1 = require("../../../utils/versions");
9
9
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
10
10
  let tsModule;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
+ const path_1 = require("path");
4
5
  const devkit_1 = require("@nx/devkit");
5
6
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
7
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
6
8
  const js_1 = require("@nx/js");
7
9
  const versions_1 = require("../../utils/versions");
10
+ const maybe_js_1 = require("../../utils/maybe-js");
8
11
  const component_1 = require("../component/component");
9
12
  const init_1 = require("../init/init");
10
13
  const jest_utils_1 = require("../../utils/jest-utils");
@@ -16,8 +19,6 @@ const create_files_1 = require("./lib/create-files");
16
19
  const create_ts_config_1 = require("../../utils/create-ts-config");
17
20
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
18
21
  const set_defaults_1 = require("./lib/set-defaults");
19
- const path_1 = require("path");
20
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
21
22
  async function libraryGenerator(host, schema) {
22
23
  return await libraryGeneratorInternal(host, {
23
24
  addPlugin: false,
@@ -177,7 +178,7 @@ async function libraryGeneratorInternal(host, schema) {
177
178
  (0, create_ts_config_1.extractTsConfigBase)(host);
178
179
  if (!options.skipTsConfig) {
179
180
  (0, js_1.addTsConfigPath)(host, options.importPath, [
180
- (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
181
+ (0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
181
182
  ]);
182
183
  }
183
184
  if (!options.skipFormat) {
@@ -4,6 +4,6 @@ module.exports = {
4
4
  library: { type: 'var', name: '<%= projectName %>'},
5
5
  <% } %>
6
6
  exposes: {
7
- './Module': './src/remote-entry.ts',
7
+ './Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
8
8
  },
9
9
  };
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
2
  name: '<%= projectName %>',
3
3
  exposes: {
4
- './Module': '<%= appProjectRoot %>/src/remote-entry.ts',
4
+ './Module': '<%= appProjectRoot %>/src/remote-entry.<%= js ? 'js' : 'ts' %>',
5
5
  },
6
6
  };
@@ -3,7 +3,7 @@ import {ModuleFederationConfig} from '@nx/webpack';
3
3
  const config: ModuleFederationConfig = {
4
4
  name: '<%= projectName %>',
5
5
  exposes: {
6
- './Module': '<%= appProjectRoot %>/src/remote-entry.ts',
6
+ './Module': '<%= appProjectRoot %>/src/remote-entry.<%= js ? 'js' : 'ts' %>',
7
7
  },
8
8
  };
9
9
 
@@ -6,7 +6,7 @@ const config: ModuleFederationConfig = {
6
6
  library: { type: 'var', name: '<%= projectName %>'},
7
7
  <% } %>
8
8
  exposes: {
9
- './Module': './src/remote-entry.ts',
9
+ './Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
10
10
  },
11
11
  };
12
12
 
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupTspathForRemote = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
+ const maybe_js_1 = require("../../../utils/maybe-js");
6
7
  function setupTspathForRemote(tree, options) {
7
8
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.name);
8
- const exportPath = `./src/remote-entry.ts`;
9
+ const exportPath = (0, maybe_js_1.maybeJs)(options, './src/remote-entry.ts');
9
10
  const exportName = 'Module';
10
11
  (0, js_1.addTsConfigPath)(tree, `${options.name}/${exportName}`, [
11
12
  (0, devkit_1.joinPathFragments)(project.root, exportPath),
@@ -46,7 +46,16 @@ function updateHostWithRemote(host, hostName, remoteName) {
46
46
  }
47
47
  exports.updateHostWithRemote = updateHostWithRemote;
48
48
  function findAppComponentPath(host, sourceRoot) {
49
- const locations = ['app/app.tsx', 'app/App.tsx', 'app.tsx', 'App.tsx'];
49
+ const locations = [
50
+ 'app/app.tsx',
51
+ 'app/App.tsx',
52
+ 'app/app.js',
53
+ 'app/App.js',
54
+ 'app.tsx',
55
+ 'App.tsx',
56
+ 'app.js',
57
+ 'App.js',
58
+ ];
50
59
  for (const loc of locations) {
51
60
  if (host.exists((0, devkit_1.joinPathFragments)(sourceRoot, loc))) {
52
61
  return (0, devkit_1.joinPathFragments)(sourceRoot, loc);
@@ -12,12 +12,14 @@ const setup_ssr_for_remote_1 = require("./lib/setup-ssr-for-remote");
12
12
  const setup_tspath_for_remote_1 = require("./lib/setup-tspath-for-remote");
13
13
  const add_remote_to_dynamic_host_1 = require("./lib/add-remote-to-dynamic-host");
14
14
  const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
15
+ const maybe_js_1 = require("../../utils/maybe-js");
15
16
  function addModuleFederationFiles(host, options) {
16
17
  const templateVariables = {
17
18
  ...(0, devkit_1.names)(options.name),
18
19
  ...options,
19
20
  tmpl: '',
20
21
  };
22
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js ? 'common' : 'common-ts'}`), options.appProjectRoot, templateVariables);
21
23
  const pathToModuleFederationFiles = options.typescriptConfiguration
22
24
  ? 'module-federation-ts'
23
25
  : 'module-federation';
@@ -45,7 +47,11 @@ async function remoteGeneratorInternal(host, schema) {
45
47
  const tasks = [];
46
48
  const options = {
47
49
  ...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:remote')),
48
- typescriptConfiguration: schema.typescriptConfiguration ?? false,
50
+ // when js is set to true, we want to use the js configuration
51
+ js: schema.js ?? false,
52
+ typescriptConfiguration: schema.js
53
+ ? false
54
+ : schema.typescriptConfiguration ?? true,
49
55
  dynamic: schema.dynamic ?? false,
50
56
  // TODO(colum): remove when MF works with Crystal
51
57
  addPlugin: false,
@@ -63,7 +69,7 @@ async function remoteGeneratorInternal(host, schema) {
63
69
  // Module federation requires bootstrap code to be dynamically imported.
64
70
  // Renaming original entry file so we can use `import(./bootstrap)` in
65
71
  // new entry file.
66
- host.rename((0, path_1.join)(options.appProjectRoot, 'src/main.tsx'), (0, path_1.join)(options.appProjectRoot, 'src/bootstrap.tsx'));
72
+ host.rename((0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
67
73
  addModuleFederationFiles(host, options);
68
74
  (0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
69
75
  (0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
@@ -106,7 +106,8 @@
106
106
  "e2eTestRunner": {
107
107
  "type": "string",
108
108
  "enum": ["cypress", "playwright", "none"],
109
- "description": "Test runner to use for end to end (e2e) tests.",
109
+ "description": "Test runner to use for end to end (E2E) tests.",
110
+ "x-prompt": "Which E2E test runner would you like to use?",
110
111
  "default": "cypress"
111
112
  },
112
113
  "tags": {
@@ -169,7 +170,7 @@
169
170
  },
170
171
  "typescriptConfiguration": {
171
172
  "type": "boolean",
172
- "description": "Whether the module federation configuration and webpack configuration files should use TS.",
173
+ "description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
173
174
  "default": true
174
175
  }
175
176
  },
@@ -1,5 +1,6 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  export declare function updateModuleFederationProject(host: Tree, options: {
3
+ js?: boolean;
3
4
  projectName: string;
4
5
  appProjectRoot: string;
5
6
  devServerPort?: number;
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateModuleFederationProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../utils/versions");
6
+ const maybe_js_1 = require("../utils/maybe-js");
6
7
  function updateModuleFederationProject(host, options) {
7
8
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
8
9
  projectConfig.targets.build.options = {
9
10
  ...projectConfig.targets.build.options,
10
- main: `${options.appProjectRoot}/src/main.ts`,
11
- webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration ? 'ts' : 'js'}`,
11
+ main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
12
+ webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
12
13
  };
13
14
  projectConfig.targets.build.configurations.production = {
14
15
  ...projectConfig.targets.build.configurations.production,
15
- webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration ? 'ts' : 'js'}`,
16
+ webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
16
17
  };
17
18
  // If host should be configured to use dynamic federation
18
19
  if (options.dynamic) {
19
- const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
20
+ const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
20
21
  if (host.exists(pathToProdWebpackConfig)) {
21
22
  host.delete(pathToProdWebpackConfig);
22
23
  }
@@ -0,0 +1,3 @@
1
+ export declare function maybeJs(options: {
2
+ js?: boolean;
3
+ }, path: string): string;
@@ -1,2 +0,0 @@
1
- import { NormalizedSchema } from '../schema';
2
- export declare function maybeJs(options: NormalizedSchema, path: string): string;