@nx/react 20.2.0-beta.5 → 20.2.0-beta.7

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 (23) hide show
  1. package/package.json +6 -6
  2. package/src/executors/module-federation-dev-server/lib/index.d.ts +2 -0
  3. package/src/executors/module-federation-dev-server/lib/index.js +5 -0
  4. package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +4 -0
  5. package/src/executors/module-federation-dev-server/lib/normalize-options.js +19 -0
  6. package/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +5 -0
  7. package/src/executors/module-federation-dev-server/lib/start-remotes.js +33 -0
  8. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -1
  9. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -108
  10. package/src/executors/module-federation-dev-server/schema.d.ts +9 -7
  11. package/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +2 -0
  12. package/src/executors/module-federation-ssr-dev-server/lib/index.js +5 -0
  13. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +4 -0
  14. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +23 -0
  15. package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +5 -0
  16. package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +34 -0
  17. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +1 -17
  18. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -151
  19. package/src/executors/module-federation-ssr-dev-server/schema.d.ts +29 -0
  20. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +2 -2
  21. package/src/generators/library/library.js +6 -0
  22. package/src/utils/build-static.remotes.d.ts +0 -4
  23. package/src/utils/build-static.remotes.js +0 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "20.2.0-beta.5",
3
+ "version": "20.2.0-beta.7",
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, Vitest, Playwright, 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": {
@@ -38,11 +38,11 @@
38
38
  "minimatch": "9.0.3",
39
39
  "picocolors": "^1.1.0",
40
40
  "tslib": "^2.3.0",
41
- "@nx/devkit": "20.2.0-beta.5",
42
- "@nx/js": "20.2.0-beta.5",
43
- "@nx/eslint": "20.2.0-beta.5",
44
- "@nx/web": "20.2.0-beta.5",
45
- "@nx/module-federation": "20.2.0-beta.5",
41
+ "@nx/devkit": "20.2.0-beta.7",
42
+ "@nx/js": "20.2.0-beta.7",
43
+ "@nx/eslint": "20.2.0-beta.7",
44
+ "@nx/web": "20.2.0-beta.7",
45
+ "@nx/module-federation": "20.2.0-beta.7",
46
46
  "express": "^4.19.2",
47
47
  "http-proxy-middleware": "^3.0.3"
48
48
  },
@@ -0,0 +1,2 @@
1
+ export * from './normalize-options';
2
+ export * from './start-remotes';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./normalize-options"), exports);
5
+ tslib_1.__exportStar(require("./start-remotes"), exports);
@@ -0,0 +1,4 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { ModuleFederationDevServerOptions, NormalizedModuleFederationDevServerOptions } from '../schema';
3
+ export declare function getBuildOptions(buildTarget: string, context: ExecutorContext): any;
4
+ export declare function normalizeOptions(options: ModuleFederationDevServerOptions): NormalizedModuleFederationDevServerOptions;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBuildOptions = getBuildOptions;
4
+ exports.normalizeOptions = normalizeOptions;
5
+ const devkit_1 = require("@nx/devkit");
6
+ function getBuildOptions(buildTarget, context) {
7
+ const target = (0, devkit_1.parseTargetString)(buildTarget, context);
8
+ const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
9
+ return {
10
+ ...buildOptions,
11
+ };
12
+ }
13
+ function normalizeOptions(options) {
14
+ return {
15
+ ...options,
16
+ devRemotes: options.devRemotes ?? [],
17
+ verbose: options.verbose ?? false,
18
+ };
19
+ }
@@ -0,0 +1,5 @@
1
+ import { ExecutorContext, ProjectConfiguration } from '@nx/devkit';
2
+ import { NormalizedModuleFederationDevServerOptions } from '../schema';
3
+ export declare function startRemotes(remotes: string[], workspaceProjects: Record<string, ProjectConfiguration>, options: Pick<NormalizedModuleFederationDevServerOptions, 'devRemotes' | 'host' | 'ssl' | 'sslCert' | 'sslKey' | 'verbose'>, context: ExecutorContext, target?: 'serve' | 'serve-static'): Promise<AsyncIterable<{
4
+ success: boolean;
5
+ }>[]>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startRemotes = startRemotes;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function startRemotes(remotes, workspaceProjects, options, context, target = 'serve') {
6
+ const remoteIters = [];
7
+ for (const app of remotes) {
8
+ const remoteProjectServeTarget = workspaceProjects[app].targets[target];
9
+ const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
10
+ const configurationOverride = options.devRemotes?.find((r) => typeof r !== 'string' && r.remoteName === app)?.configuration;
11
+ const defaultOverrides = {
12
+ ...(options.host ? { host: options.host } : {}),
13
+ ...(options.ssl ? { ssl: options.ssl } : {}),
14
+ ...(options.sslCert ? { sslCert: options.sslCert } : {}),
15
+ ...(options.sslKey ? { sslKey: options.sslKey } : {}),
16
+ };
17
+ const overrides = target === 'serve'
18
+ ? {
19
+ watch: true,
20
+ ...(isUsingModuleFederationDevServerExecutor
21
+ ? { isInitialHost: false }
22
+ : {}),
23
+ ...defaultOverrides,
24
+ }
25
+ : { ...defaultOverrides };
26
+ remoteIters.push(await (0, devkit_1.runExecutor)({
27
+ project: app,
28
+ target,
29
+ configuration: configurationOverride ?? context.configurationName,
30
+ }, overrides, context));
31
+ }
32
+ return remoteIters;
33
+ }
@@ -1,6 +1,6 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
2
  import { ModuleFederationDevServerOptions } from './schema';
3
- export default function moduleFederationDevServer(options: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncIterableIterator<{
3
+ export default function moduleFederationDevServer(schema: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncIterableIterator<{
4
4
  success: boolean;
5
5
  baseUrl?: string;
6
6
  }>;
@@ -4,94 +4,14 @@ exports.default = moduleFederationDevServer;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const dev_server_impl_1 = require("@nx/webpack/src/executors/dev-server/dev-server.impl");
6
6
  const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
7
- const utils_1 = require("@nx/module-federation/src/utils");
7
+ const utils_1 = require("@nx/module-federation/src/executors/utils");
8
8
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
9
9
  const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
10
10
  const fs_1 = require("fs");
11
11
  const path_1 = require("path");
12
- const build_static_remotes_1 = require("../../utils/build-static.remotes");
13
- function getBuildOptions(buildTarget, context) {
14
- const target = (0, devkit_1.parseTargetString)(buildTarget, context);
15
- const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
16
- return {
17
- ...buildOptions,
18
- };
19
- }
20
- function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
21
- if (!staticRemotesConfig.remotes ||
22
- staticRemotesConfig.remotes.length === 0) {
23
- return;
24
- }
25
- let shouldMoveToCommonLocation = false;
26
- let commonOutputDirectory;
27
- for (const app of staticRemotesConfig.remotes) {
28
- const remoteBasePath = staticRemotesConfig.config[app].basePath;
29
- if (!commonOutputDirectory) {
30
- commonOutputDirectory = remoteBasePath;
31
- }
32
- else if (commonOutputDirectory !== remoteBasePath) {
33
- shouldMoveToCommonLocation = true;
34
- break;
35
- }
36
- }
37
- if (shouldMoveToCommonLocation) {
38
- commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
39
- for (const app of staticRemotesConfig.remotes) {
40
- const remoteConfig = staticRemotesConfig.config[app];
41
- (0, fs_1.cpSync)(remoteConfig.outputPath, (0, path_1.join)(commonOutputDirectory, remoteConfig.urlSegment), {
42
- force: true,
43
- recursive: true,
44
- });
45
- }
46
- }
47
- const staticRemotesIter = (0, file_server_impl_1.default)({
48
- cors: true,
49
- watch: false,
50
- staticFilePath: commonOutputDirectory,
51
- parallel: false,
52
- spa: false,
53
- withDeps: false,
54
- host: options.host,
55
- port: options.staticRemotesPort,
56
- ssl: options.ssl,
57
- sslCert: options.sslCert,
58
- sslKey: options.sslKey,
59
- cacheSeconds: -1,
60
- }, context);
61
- return staticRemotesIter;
62
- }
63
- async function startRemotes(remotes, context, options, target = 'serve') {
64
- const remoteIters = [];
65
- for (const app of remotes) {
66
- const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
67
- const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
68
- const configurationOverride = options.devRemotes?.find((r) => typeof r !== 'string' && r.remoteName === app)?.configuration;
69
- const defaultOverrides = {
70
- ...(options.host ? { host: options.host } : {}),
71
- ...(options.ssl ? { ssl: options.ssl } : {}),
72
- ...(options.sslCert ? { sslCert: options.sslCert } : {}),
73
- ...(options.sslKey ? { sslKey: options.sslKey } : {}),
74
- };
75
- const overrides = target === 'serve'
76
- ? {
77
- watch: true,
78
- ...(isUsingModuleFederationDevServerExecutor
79
- ? { isInitialHost: false }
80
- : {}),
81
- ...defaultOverrides,
82
- }
83
- : { ...defaultOverrides };
84
- remoteIters.push(await (0, devkit_1.runExecutor)({
85
- project: app,
86
- target,
87
- configuration: configurationOverride ?? context.configurationName,
88
- }, overrides, context));
89
- }
90
- return remoteIters;
91
- }
92
- async function* moduleFederationDevServer(options, context) {
93
- // Force Node to resolve to look for the nx binary that is inside node_modules
94
- const nxBin = require.resolve('nx/bin/nx');
12
+ const lib_1 = require("./lib");
13
+ async function* moduleFederationDevServer(schema, context) {
14
+ const options = (0, lib_1.normalizeOptions)(schema);
95
15
  const currIter = options.static
96
16
  ? (0, file_server_impl_1.default)({
97
17
  ...options,
@@ -103,7 +23,7 @@ async function* moduleFederationDevServer(options, context) {
103
23
  }, context)
104
24
  : (0, dev_server_impl_1.default)(options, context);
105
25
  const p = context.projectsConfigurations.projects[context.projectName];
106
- const buildOptions = getBuildOptions(options.buildTarget, context);
26
+ const buildOptions = (0, lib_1.getBuildOptions)(options.buildTarget, context);
107
27
  let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
108
28
  if (options.pathToManifestFile) {
109
29
  const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
@@ -118,29 +38,7 @@ async function* moduleFederationDevServer(options, context) {
118
38
  if (!options.isInitialHost) {
119
39
  return yield* currIter;
120
40
  }
121
- const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
122
- const remoteNames = options.devRemotes?.map((r) => typeof r === 'string' ? r : r.remoteName);
123
- const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
124
- projectName: context.projectName,
125
- projectGraph: context.projectGraph,
126
- root: context.root,
127
- }, pathToManifestFile);
128
- options.staticRemotesPort ??= remotes.staticRemotePort;
129
- // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
130
- process.env.NX_MF_DEV_REMOTES = JSON.stringify([
131
- ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []).map((r) => r.replace(/-/g, '_')),
132
- p.name.replace(/-/g, '_'),
133
- ]);
134
- const staticRemotesConfig = (0, utils_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
135
- const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
136
- const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
137
- const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
138
- (0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
139
- ? {
140
- pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert),
141
- pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey),
142
- }
143
- : undefined);
41
+ const { staticRemotesIter, devRemoteIters, remotes } = await (0, utils_1.startRemoteIterators)(options, context, lib_1.startRemotes, pathToManifestFile, 'react');
144
42
  return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
145
43
  if (!options.isInitialHost) {
146
44
  done();
@@ -1,17 +1,19 @@
1
1
  import { WebDevServerOptions } from '@nx/webpack';
2
+ import { DevRemoteDefinition } from '@nx/module-federation/src/executors/utils';
2
3
 
3
4
  export type ModuleFederationDevServerOptions = WebDevServerOptions & {
4
- devRemotes?: (
5
- | string
6
- | {
7
- remoteName: string;
8
- configuration: string;
9
- }
10
- )[];
5
+ devRemotes?: DevRemoteDefinition[];
11
6
  skipRemotes?: string[];
12
7
  static?: boolean;
13
8
  isInitialHost?: boolean;
14
9
  parallel?: number;
15
10
  staticRemotesPort?: number;
16
11
  pathToManifestFile?: string;
12
+ verbose?: boolean;
17
13
  };
14
+
15
+ export type NormalizedModuleFederationDevServerOptions =
16
+ ModuleFederationDevServerOptions & {
17
+ devRemotes: DevRemoteDefinition[];
18
+ verbose: boolean;
19
+ };
@@ -0,0 +1,2 @@
1
+ export * from './normalize-options';
2
+ export * from './start-remotes';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./normalize-options"), exports);
5
+ tslib_1.__exportStar(require("./start-remotes"), exports);
@@ -0,0 +1,4 @@
1
+ import { ModuleFederationSsrDevServerOptions, NormalizedModuleFederationSsrDevServerOptions } from '../schema';
2
+ import { ExecutorContext } from '@nx/devkit';
3
+ export declare function normalizeOptions(options: ModuleFederationSsrDevServerOptions): NormalizedModuleFederationSsrDevServerOptions;
4
+ export declare function getBuildOptions(buildTarget: string, context: ExecutorContext): any;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = normalizeOptions;
4
+ exports.getBuildOptions = getBuildOptions;
5
+ const path_1 = require("path");
6
+ const devkit_1 = require("@nx/devkit");
7
+ function normalizeOptions(options) {
8
+ return {
9
+ ...options,
10
+ devRemotes: options.devRemotes ?? [],
11
+ verbose: options.verbose ?? false,
12
+ ssl: options.ssl ?? false,
13
+ sslCert: options.sslCert ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert) : undefined,
14
+ sslKey: options.sslKey ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey) : undefined,
15
+ };
16
+ }
17
+ function getBuildOptions(buildTarget, context) {
18
+ const target = (0, devkit_1.parseTargetString)(buildTarget, context);
19
+ const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
20
+ return {
21
+ ...buildOptions,
22
+ };
23
+ }
@@ -0,0 +1,5 @@
1
+ import { ModuleFederationSsrDevServerOptions } from '../schema';
2
+ import { ExecutorContext, ProjectConfiguration } from '@nx/devkit';
3
+ export declare function startRemotes(remotes: string[], workspaceProjects: Record<string, ProjectConfiguration>, options: Partial<Pick<ModuleFederationSsrDevServerOptions, 'devRemotes' | 'host' | 'ssl' | 'sslCert' | 'sslKey' | 'verbose'>>, context: ExecutorContext): Promise<AsyncIterable<{
4
+ success: boolean;
5
+ }>[]>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startRemotes = startRemotes;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function startRemotes(remotes, workspaceProjects, options, context) {
6
+ const remoteIters = [];
7
+ const target = 'serve';
8
+ for (const app of remotes) {
9
+ const remoteProjectServeTarget = workspaceProjects[app].targets[target];
10
+ const isUsingModuleFederationSsrDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-ssr-dev-server');
11
+ const configurationOverride = options.devRemotes?.find((remote) => typeof remote !== 'string' && remote.remoteName === app)?.configuration;
12
+ {
13
+ const defaultOverrides = {
14
+ ...(options.host ? { host: options.host } : {}),
15
+ ...(options.ssl ? { ssl: options.ssl } : {}),
16
+ ...(options.sslCert ? { sslCert: options.sslCert } : {}),
17
+ ...(options.sslKey ? { sslKey: options.sslKey } : {}),
18
+ };
19
+ const overrides = {
20
+ watch: true,
21
+ ...defaultOverrides,
22
+ ...(isUsingModuleFederationSsrDevServerExecutor
23
+ ? { isInitialHost: false }
24
+ : {}),
25
+ };
26
+ remoteIters.push(await (0, devkit_1.runExecutor)({
27
+ project: app,
28
+ target,
29
+ configuration: configurationOverride ?? context.configurationName,
30
+ }, overrides, context));
31
+ }
32
+ }
33
+ return remoteIters;
34
+ }
@@ -1,19 +1,3 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import { WebSsrDevServerOptions } from '@nx/webpack/src/executors/ssr-dev-server/schema';
3
- type ModuleFederationSsrDevServerOptions = WebSsrDevServerOptions & {
4
- devRemotes?: (string | {
5
- remoteName: string;
6
- configuration: string;
7
- })[];
8
- skipRemotes?: string[];
9
- host: string;
10
- pathToManifestFile?: string;
11
- staticRemotesPort?: number;
12
- parallel?: number;
13
- ssl?: boolean;
14
- sslKey?: string;
15
- sslCert?: string;
16
- isInitialHost?: boolean;
17
- };
2
+ import { ModuleFederationSsrDevServerOptions } from './schema';
18
3
  export default function moduleFederationSsrDevServer(ssrDevServerOptions: ModuleFederationSsrDevServerOptions, context: ExecutorContext): AsyncGenerator<any, any, any>;
19
- export {};
@@ -4,141 +4,16 @@ exports.default = moduleFederationSsrDevServer;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const ssr_dev_server_impl_1 = require("@nx/webpack/src/executors/ssr-dev-server/ssr-dev-server.impl");
6
6
  const path_1 = require("path");
7
- const utils_1 = require("@nx/module-federation/src/utils");
7
+ const utils_1 = require("@nx/module-federation/src/executors/utils");
8
8
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
9
- const child_process_1 = require("child_process");
10
9
  const fs_1 = require("fs");
11
- const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
12
- const cache_directory_1 = require("nx/src/utils/cache-directory");
13
10
  const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
14
- function normalizeOptions(options) {
15
- return {
16
- ...options,
17
- ssl: options.ssl ?? false,
18
- sslCert: options.sslCert ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert) : undefined,
19
- sslKey: options.sslKey ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey) : undefined,
20
- };
21
- }
22
- function getBuildOptions(buildTarget, context) {
23
- const target = (0, devkit_1.parseTargetString)(buildTarget, context);
24
- const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
25
- return {
26
- ...buildOptions,
27
- };
28
- }
29
- async function* startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, options) {
30
- if (ssrStaticRemotesConfig.remotes.length === 0) {
31
- yield { success: true };
32
- return;
33
- }
34
- // The directories are usually generated with /browser and /server suffixes so we need to copy them to a common directory
35
- const commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
36
- for (const app of ssrStaticRemotesConfig.remotes) {
37
- const remoteConfig = ssrStaticRemotesConfig.config[app];
38
- (0, fs_1.cpSync)(remoteConfig.outputPath, (0, path_1.join)(commonOutputDirectory, remoteConfig.urlSegment), {
39
- force: true,
40
- recursive: true,
41
- });
42
- }
43
- const staticRemotesIter = (0, file_server_impl_1.default)({
44
- cors: true,
45
- watch: false,
46
- staticFilePath: commonOutputDirectory,
47
- parallel: false,
48
- spa: false,
49
- withDeps: false,
50
- host: options.host,
51
- port: options.staticRemotesPort,
52
- ssl: options.ssl,
53
- sslCert: options.sslCert,
54
- sslKey: options.sslKey,
55
- cacheSeconds: -1,
56
- }, context);
57
- yield* staticRemotesIter;
58
- }
59
- async function startRemotes(remotes, context, options) {
60
- const remoteIters = [];
61
- const target = 'serve';
62
- for (const app of remotes) {
63
- const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
64
- const isUsingModuleFederationSsrDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-ssr-dev-server');
65
- const configurationOverride = options.devRemotes?.find((remote) => typeof remote !== 'string' && remote.remoteName === app)?.configuration;
66
- {
67
- const defaultOverrides = {
68
- ...(options.host ? { host: options.host } : {}),
69
- ...(options.ssl ? { ssl: options.ssl } : {}),
70
- ...(options.sslCert ? { sslCert: options.sslCert } : {}),
71
- ...(options.sslKey ? { sslKey: options.sslKey } : {}),
72
- };
73
- const overrides = {
74
- watch: true,
75
- ...defaultOverrides,
76
- ...(isUsingModuleFederationSsrDevServerExecutor
77
- ? { isInitialHost: false }
78
- : {}),
79
- };
80
- remoteIters.push(await (0, devkit_1.runExecutor)({
81
- project: app,
82
- target,
83
- configuration: configurationOverride ?? context.configurationName,
84
- }, overrides, context));
85
- }
86
- }
87
- return remoteIters;
88
- }
89
- async function buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options) {
90
- if (!staticRemotesConfig.remotes.length) {
91
- return;
92
- }
93
- devkit_1.logger.info(`Nx is building ${staticRemotesConfig.remotes.length} static remotes...`);
94
- const mapLocationOfRemotes = {};
95
- for (const remoteApp of staticRemotesConfig.remotes) {
96
- mapLocationOfRemotes[remoteApp] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[remoteApp].urlSegment}`;
97
- }
98
- await new Promise((resolve) => {
99
- const childProcess = (0, child_process_1.fork)(nxBin, [
100
- 'run-many',
101
- '--target=server',
102
- '--projects',
103
- staticRemotesConfig.remotes.join(','),
104
- ...(context.configurationName
105
- ? [`--configuration=${context.configurationName}`]
106
- : []),
107
- ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
108
- ], {
109
- cwd: context.root,
110
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
111
- });
112
- // Add a listener to the child process to capture the build log
113
- const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
114
- const remoteBuildLogStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
115
- childProcess.stdout.on('data', (data) => {
116
- const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
117
- const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
118
- remoteBuildLogStream.write(stdoutString);
119
- // in addition to writing into the stdout stream, also show error directly in console
120
- // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
121
- if (stdoutString.includes('ERROR in')) {
122
- devkit_1.logger.log(stdoutString);
123
- }
124
- if (stdoutString.includes('Successfully ran target server')) {
125
- childProcess.stdout.removeAllListeners('data');
126
- devkit_1.logger.info(`Nx Built ${staticRemotesConfig.remotes.length} static remotes.`);
127
- resolve();
128
- }
129
- });
130
- process.on('SIGTERM', () => childProcess.kill('SIGTERM'));
131
- process.on('exit', () => childProcess.kill('SIGTERM'));
132
- });
133
- return mapLocationOfRemotes;
134
- }
11
+ const lib_1 = require("./lib");
135
12
  async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
136
- const options = normalizeOptions(ssrDevServerOptions);
137
- // Force Node to resolve to look for the nx binary that is inside node_modules
138
- const nxBin = require.resolve('nx/bin/nx');
13
+ const options = (0, lib_1.normalizeOptions)(ssrDevServerOptions);
139
14
  let iter = (0, ssr_dev_server_impl_1.default)(options, context);
140
15
  const projectConfig = context.projectsConfigurations.projects[context.projectName];
141
- const buildOptions = getBuildOptions(options.browserTarget, context);
16
+ const buildOptions = (0, lib_1.getBuildOptions)(options.browserTarget, context);
142
17
  let pathToManifestFile = (0, path_1.join)(context.root, projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
143
18
  if (options.pathToManifestFile) {
144
19
  const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
@@ -153,28 +28,7 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
153
28
  if (!options.isInitialHost) {
154
29
  return yield* iter;
155
30
  }
156
- const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, projectConfig.root, 'react');
157
- const remoteNames = options.devRemotes?.map((remote) => typeof remote === 'string' ? remote : remote.remoteName);
158
- const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
159
- projectName: context.projectName,
160
- projectGraph: context.projectGraph,
161
- root: context.root,
162
- }, pathToManifestFile);
163
- options.staticRemotesPort ??= remotes.staticRemotePort;
164
- process.env.NX_MF_DEV_REMOTES = JSON.stringify([
165
- ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []).map((r) => r.replace(/-/g, '_')),
166
- projectConfig.name.replace(/-/g, '_'),
167
- ]);
168
- const staticRemotesConfig = (0, utils_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
169
- const mappedLocationsOfStaticRemotes = await buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options);
170
- const devRemoteIters = await startRemotes(remotes.devRemotes, context, options);
171
- const staticRemotesIter = startSsrStaticRemotesFileServer(staticRemotesConfig, context, options);
172
- (0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
173
- ? {
174
- pathToCert: options.sslCert,
175
- pathToKey: options.sslKey,
176
- }
177
- : undefined);
31
+ const { staticRemotesIter, devRemoteIters, remotes } = await (0, utils_1.startRemoteIterators)(options, context, lib_1.startRemotes, pathToManifestFile, 'react', true);
178
32
  const combined = (0, async_iterable_1.combineAsyncIterables)(staticRemotesIter, ...devRemoteIters);
179
33
  let refs = 1 + (devRemoteIters?.length ?? 0);
180
34
  for await (const result of combined) {
@@ -0,0 +1,29 @@
1
+ import { WebSsrDevServerOptions } from '@nx/webpack/src/executors/ssr-dev-server/schema';
2
+ import { DevRemoteDefinition } from '@nx/module-federation/src/executors/utils';
3
+
4
+ export type ModuleFederationSsrDevServerOptions = WebSsrDevServerOptions & {
5
+ devRemotes?: (
6
+ | string
7
+ | {
8
+ remoteName: string;
9
+ configuration: string;
10
+ }
11
+ )[];
12
+
13
+ skipRemotes?: string[];
14
+ host: string;
15
+ pathToManifestFile?: string;
16
+ staticRemotesPort?: number;
17
+ parallel?: number;
18
+ ssl?: boolean;
19
+ sslKey?: string;
20
+ sslCert?: string;
21
+ isInitialHost?: boolean;
22
+ verbose?: boolean;
23
+ };
24
+
25
+ export type NormalizedModuleFederationSsrDevServerOptions =
26
+ ModuleFederationSsrDevServerOptions & {
27
+ devRemotes: DevRemoteDefinition[];
28
+ verbose: boolean;
29
+ };
@@ -6,7 +6,7 @@ const path_1 = require("path");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const fs_1 = require("fs");
8
8
  const utils_1 = require("@nx/module-federation/src/utils");
9
- const build_static_remotes_1 = require("../../utils/build-static.remotes");
9
+ const utils_2 = require("@nx/module-federation/src/executors/utils");
10
10
  const child_process_1 = require("child_process");
11
11
  const process = require("node:process");
12
12
  const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
@@ -171,7 +171,7 @@ async function* moduleFederationStaticServer(schema, context) {
171
171
  }, options.pathToManifestFile);
172
172
  const staticRemotesConfig = (0, utils_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
173
173
  options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
174
- const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
174
+ const mappedLocationsOfStaticRemotes = await (0, utils_2.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
175
175
  // Build the host
176
176
  const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
177
177
  const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
@@ -21,6 +21,7 @@ const create_ts_config_1 = require("../../utils/create-ts-config");
21
21
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
22
22
  const set_defaults_1 = require("./lib/set-defaults");
23
23
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
24
+ const plugin_1 = require("@nx/js/src/utils/typescript/plugin");
24
25
  async function libraryGenerator(host, schema) {
25
26
  return await libraryGeneratorInternal(host, {
26
27
  addPlugin: false,
@@ -114,6 +115,11 @@ async function libraryGeneratorInternal(host, schema) {
114
115
  const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, options);
115
116
  tasks.push(rollupTask);
116
117
  }
118
+ else if (options.bundler === 'none' && options.addPlugin) {
119
+ const nxJson = (0, devkit_1.readNxJson)(host);
120
+ (0, plugin_1.ensureProjectIsExcludedFromPluginRegistrations)(nxJson, options.projectRoot);
121
+ (0, devkit_1.updateNxJson)(host, nxJson);
122
+ }
117
123
  // Set up test target
118
124
  if (options.unitTestRunner === 'jest') {
119
125
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
@@ -1,4 +0,0 @@
1
- import { StaticRemotesConfig } from '@nx/module-federation/src/utils';
2
- import { ExecutorContext } from '@nx/devkit';
3
- import { ModuleFederationDevServerOptions } from '../executors/module-federation-dev-server/schema';
4
- export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildStaticRemotes = buildStaticRemotes;
4
- const logger_1 = require("nx/src/utils/logger");
5
- const node_child_process_1 = require("node:child_process");
6
- const path_1 = require("path");
7
- const cache_directory_1 = require("nx/src/utils/cache-directory");
8
- const fs_1 = require("fs");
9
- async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options) {
10
- if (!staticRemotesConfig.remotes.length) {
11
- return;
12
- }
13
- logger_1.logger.info(`NX Building ${staticRemotesConfig.remotes.length} static remotes...`);
14
- const mappedLocationOfRemotes = {};
15
- for (const app of staticRemotesConfig.remotes) {
16
- mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[app].urlSegment}`;
17
- }
18
- await new Promise((res, rej) => {
19
- const staticProcess = (0, node_child_process_1.fork)(nxBin, [
20
- 'run-many',
21
- `--target=build`,
22
- `--projects=${staticRemotesConfig.remotes.join(',')}`,
23
- ...(context.configurationName
24
- ? [`--configuration=${context.configurationName}`]
25
- : []),
26
- ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
27
- ], {
28
- cwd: context.root,
29
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
30
- });
31
- // File to debug build failures e.g. 2024-01-01T00_00_0_0Z-build.log'
32
- const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
33
- const stdoutStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
34
- staticProcess.stdout.on('data', (data) => {
35
- const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
36
- const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
37
- stdoutStream.write(stdoutString);
38
- // in addition to writing into the stdout stream, also show error directly in console
39
- // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
40
- if (stdoutString.includes('ERROR in')) {
41
- logger_1.logger.log(stdoutString);
42
- }
43
- if (stdoutString.includes('Successfully ran target build')) {
44
- staticProcess.stdout.removeAllListeners('data');
45
- logger_1.logger.info(`NX Built ${staticRemotesConfig.remotes.length} static remotes`);
46
- res();
47
- }
48
- });
49
- staticProcess.stderr.on('data', (data) => logger_1.logger.info(data.toString()));
50
- staticProcess.once('exit', (code) => {
51
- stdoutStream.end();
52
- staticProcess.stdout.removeAllListeners('data');
53
- staticProcess.stderr.removeAllListeners('data');
54
- if (code !== 0) {
55
- rej(`Remote failed to start. A complete log can be found in: ${remoteBuildLogFile}`);
56
- }
57
- else {
58
- res();
59
- }
60
- });
61
- process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
62
- process.on('exit', () => staticProcess.kill('SIGTERM'));
63
- });
64
- return mappedLocationOfRemotes;
65
- }