@nx/webpack 19.5.0 → 19.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "19.5.0",
3
+ "version": "19.5.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
6
6
  "repository": {
@@ -33,6 +33,7 @@
33
33
  "@babel/core": "^7.23.2",
34
34
  "@phenomnomnominal/tsquery": "~5.0.1",
35
35
  "@module-federation/sdk": "^0.2.3",
36
+ "@module-federation/enhanced": "^0.2.3",
36
37
  "ajv": "^8.12.0",
37
38
  "autoprefixer": "^10.4.9",
38
39
  "babel-loader": "^9.1.2",
@@ -41,7 +42,9 @@
41
42
  "copy-webpack-plugin": "^10.2.4",
42
43
  "css-loader": "^6.4.0",
43
44
  "css-minimizer-webpack-plugin": "^5.0.0",
45
+ "express": "^4.19.2",
44
46
  "fork-ts-checker-webpack-plugin": "7.2.13",
47
+ "http-proxy-middleware": "^3.0.0",
45
48
  "less": "4.1.3",
46
49
  "less-loader": "11.1.0",
47
50
  "license-webpack-plugin": "^4.0.2",
@@ -66,9 +69,9 @@
66
69
  "webpack-dev-server": "^4.9.3",
67
70
  "webpack-node-externals": "^3.0.0",
68
71
  "webpack-subresource-integrity": "^5.1.0",
69
- "@nx/devkit": "19.5.0",
70
- "@nx/js": "19.5.0",
71
- "@nrwl/webpack": "19.5.0"
72
+ "@nx/devkit": "19.5.2",
73
+ "@nx/js": "19.5.2",
74
+ "@nrwl/webpack": "19.5.2"
72
75
  },
73
76
  "publishConfig": {
74
77
  "access": "public"
@@ -10,6 +10,7 @@ export declare function getRemotes(devRemotes: string[], skipRemotes: string[],
10
10
  devRemotes: any[];
11
11
  dynamicRemotes: any[];
12
12
  remotePorts: any[];
13
+ staticRemotePort: number;
13
14
  };
14
15
  export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
15
16
  export {};
@@ -57,14 +57,19 @@ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile
57
57
  ? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
58
58
  : (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
59
59
  const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
60
- const devServeRemotes = [...knownRemotes, ...dynamicRemotes].filter((r) => devServeApps.has(r));
60
+ const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
61
61
  const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
62
62
  const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
63
+ const staticRemotePort = Math.max(...[
64
+ ...remotePorts,
65
+ ...staticRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port),
66
+ ]) + 1;
63
67
  return {
64
68
  staticRemotes,
65
69
  devRemotes: devServeRemotes,
66
70
  dynamicRemotes: staticDynamicRemotes,
67
71
  remotePorts,
72
+ staticRemotePort,
68
73
  };
69
74
  }
70
75
  function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
@@ -33,6 +33,12 @@ export interface ModuleFederationConfig {
33
33
  exposes?: Record<string, string>;
34
34
  shared?: SharedFunction;
35
35
  additionalShared?: AdditionalSharedConfig;
36
+ /**
37
+ * `nxRuntimeLibraryControlPlugin` is a runtime module federation plugin to ensure
38
+ * that shared libraries are resolved from a remote with live reload capabilities.
39
+ * If you run into any issues with loading shared libraries, try disabling this option.
40
+ */
41
+ disableNxRuntimeLibraryControlPlugin?: boolean;
36
42
  }
37
43
  export type NxModuleFederationConfigOverride = Omit<moduleFederationPlugin.ModuleFederationPluginOptions, 'exposes' | 'remotes' | 'name' | 'library' | 'shared' | 'filename' | 'remoteType'>;
38
44
  export type WorkspaceLibrarySecondaryEntryPoint = {
@@ -0,0 +1,12 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ export type StaticRemoteConfig = {
3
+ basePath: string;
4
+ outputPath: string;
5
+ urlSegment: string;
6
+ port: number;
7
+ };
8
+ export type StaticRemotesConfig = {
9
+ remotes: string[];
10
+ config: Record<string, StaticRemoteConfig> | undefined;
11
+ };
12
+ export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
4
+ const path_1 = require("path");
5
+ function parseStaticRemotesConfig(staticRemotes, context) {
6
+ if (!staticRemotes?.length) {
7
+ return { remotes: [], config: undefined };
8
+ }
9
+ const config = {};
10
+ for (const app of staticRemotes) {
11
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
12
+ const basePath = (0, path_1.dirname)(outputPath);
13
+ const urlSegment = (0, path_1.basename)(outputPath);
14
+ const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
15
+ config[app] = { basePath, outputPath, urlSegment, port };
16
+ }
17
+ return { remotes: staticRemotes, config };
18
+ }
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const nxRuntimeLibraryControlPlugin: () => FederationRuntimePlugin;
3
+ export default nxRuntimeLibraryControlPlugin;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const runtimeStore = {
4
+ sharedPackagesFromDev: {},
5
+ };
6
+ if (process.env.NX_MF_DEV_REMOTES) {
7
+ // process.env.NX_MF_DEV_REMOTES is replaced by an array value via DefinePlugin, even though the original value is a stringified array.
8
+ runtimeStore.devRemotes = process.env
9
+ .NX_MF_DEV_REMOTES;
10
+ }
11
+ const nxRuntimeLibraryControlPlugin = function () {
12
+ return {
13
+ name: 'nx-runtime-library-control-plugin',
14
+ beforeInit(args) {
15
+ runtimeStore.name = args.options.name;
16
+ return args;
17
+ },
18
+ resolveShare: (args) => {
19
+ const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
20
+ const originalResolver = args.resolver;
21
+ args.resolver = function () {
22
+ if (!runtimeStore.sharedPackagesFromDev[pkgName]) {
23
+ if (!GlobalFederation.__INSTANCES__) {
24
+ return originalResolver();
25
+ }
26
+ else if (!runtimeStore.devRemotes) {
27
+ return originalResolver();
28
+ }
29
+ const devRemoteInstanceToUse = GlobalFederation.__INSTANCES__.find((instance) => instance.options.shared[pkgName] &&
30
+ runtimeStore.devRemotes.find((dr) => instance.name === dr));
31
+ if (!devRemoteInstanceToUse) {
32
+ return originalResolver();
33
+ }
34
+ runtimeStore.sharedPackagesFromDev[pkgName] =
35
+ devRemoteInstanceToUse.name;
36
+ }
37
+ const remoteInstanceName = runtimeStore.sharedPackagesFromDev[pkgName];
38
+ const remoteInstance = GlobalFederation.__INSTANCES__.find((instance) => instance.name === remoteInstanceName);
39
+ try {
40
+ const remotePkgInfo = remoteInstance.options.shared[pkgName].find((shared) => shared.from === remoteInstanceName);
41
+ remotePkgInfo.useIn.push(runtimeStore.name);
42
+ remotePkgInfo.useIn = Array.from(new Set(remotePkgInfo.useIn));
43
+ shareScopeMap[scope][pkgName][version] = remotePkgInfo;
44
+ return remotePkgInfo;
45
+ }
46
+ catch {
47
+ return originalResolver();
48
+ }
49
+ };
50
+ return args;
51
+ },
52
+ };
53
+ };
54
+ exports.default = nxRuntimeLibraryControlPlugin;
@@ -0,0 +1,2 @@
1
+ import { StaticRemotesConfig } from './parse-static-remotes-config';
2
+ export declare function startRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startRemoteProxies = startRemoteProxies;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes) {
6
+ const { createProxyMiddleware } = require('http-proxy-middleware');
7
+ const express = require('express');
8
+ devkit_1.logger.info(`NX Starting static remotes proxies...`);
9
+ for (const app of staticRemotesConfig.remotes) {
10
+ const expressProxy = express();
11
+ expressProxy.use(createProxyMiddleware({
12
+ target: mappedLocationsOfRemotes[app],
13
+ changeOrigin: true,
14
+ }));
15
+ const proxyServer = expressProxy.listen(staticRemotesConfig.config[app].port);
16
+ process.on('SIGTERM', () => proxyServer.close());
17
+ process.on('exit', () => proxyServer.close());
18
+ }
19
+ devkit_1.logger.info(`NX Static remotes proxies started successfully`);
20
+ }