@nx/webpack 17.0.0-beta.8 → 17.0.0-rc.0

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": "17.0.0-beta.8",
3
+ "version": "17.0.0-rc.0",
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": {
@@ -60,9 +60,9 @@
60
60
  "webpack-dev-server": "^4.9.3",
61
61
  "webpack-node-externals": "^3.0.0",
62
62
  "webpack-subresource-integrity": "^5.1.0",
63
- "@nx/devkit": "17.0.0-beta.8",
64
- "@nx/js": "17.0.0-beta.8",
65
- "@nrwl/webpack": "17.0.0-beta.8"
63
+ "@nx/devkit": "17.0.0-rc.0",
64
+ "@nx/js": "17.0.0-rc.0",
65
+ "@nrwl/webpack": "17.0.0-rc.0"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"
@@ -0,0 +1,14 @@
1
+ import { type ProjectGraph } from '@nx/devkit';
2
+ import { ModuleFederationConfig } from './models/index';
3
+ interface ModuleFederationExecutorContext {
4
+ projectName: string;
5
+ projectGraph: ProjectGraph;
6
+ root: string;
7
+ }
8
+ export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
9
+ staticRemotes: string[];
10
+ devRemotes: string[];
11
+ remotePorts: any[];
12
+ };
13
+ export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
14
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModuleFederationConfig = exports.getRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const internal_1 = require("@nx/js/src/internal");
6
+ const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
7
+ const chalk = require("chalk");
8
+ const path_1 = require("path");
9
+ const fs_1 = require("fs");
10
+ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
11
+ const remotes = [];
12
+ if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
13
+ const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
14
+ if (moduleFederationManifestJson) {
15
+ // This should have shape of
16
+ // {
17
+ // "remoteName": "remoteLocation",
18
+ // }
19
+ const parsedManifest = JSON.parse(moduleFederationManifestJson);
20
+ if (Object.keys(parsedManifest).every((key) => typeof key === 'string' && typeof parsedManifest[key] === 'string')) {
21
+ remotes.push(Object.keys(parsedManifest));
22
+ }
23
+ }
24
+ }
25
+ const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
26
+ remotes.push(...staticRemotes);
27
+ return remotes;
28
+ }
29
+ function collectRemoteProjects(remote, collected, context) {
30
+ const remoteProject = context.projectGraph.nodes[remote]?.data;
31
+ if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
32
+ return;
33
+ }
34
+ collected.add(remote);
35
+ const remoteProjectRoot = remoteProject.root;
36
+ const remoteProjectTsConfig = remoteProject.targets['build'].options.tsConfig;
37
+ const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
38
+ const remoteProjectRemotes = extractRemoteProjectsFromConfig(remoteProjectConfig);
39
+ remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
40
+ }
41
+ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
42
+ const collectedRemotes = new Set();
43
+ const remotes = extractRemoteProjectsFromConfig(config, pathToManifestFile);
44
+ remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
45
+ const remotesToSkip = new Set((0, find_matching_projects_1.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
46
+ if (remotesToSkip.size > 0) {
47
+ devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
48
+ }
49
+ const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
50
+ devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk.bold(context.projectName)} with ${knownRemotes.length} remotes`);
51
+ const devServeApps = new Set(!devRemotes
52
+ ? []
53
+ : Array.isArray(devRemotes)
54
+ ? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
55
+ : (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
56
+ const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
57
+ const devServeRemotes = knownRemotes.filter((r) => devServeApps.has(r));
58
+ const remotePorts = knownRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
59
+ return {
60
+ staticRemotes,
61
+ devRemotes: devServeRemotes,
62
+ remotePorts,
63
+ };
64
+ }
65
+ exports.getRemotes = getRemotes;
66
+ function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
67
+ const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
68
+ const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
69
+ let moduleFederationConfigPath = moduleFederationConfigPathJS;
70
+ // create a no-op so this can be called with issue
71
+ const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
72
+ ? tsconfigPath
73
+ : (0, path_1.join)(workspaceRoot, tsconfigPath);
74
+ let cleanupTranspiler = () => { };
75
+ if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
76
+ cleanupTranspiler = (0, internal_1.registerTsProject)(fullTSconfigPath);
77
+ moduleFederationConfigPath = moduleFederationConfigPathTS;
78
+ }
79
+ try {
80
+ const config = require(moduleFederationConfigPath);
81
+ cleanupTranspiler();
82
+ return config.default || config;
83
+ }
84
+ catch {
85
+ throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/${pluginName}:host"?\nSee: https://nx.dev/concepts/more-concepts/faster-builds-with-module-federation`);
86
+ }
87
+ }
88
+ exports.getModuleFederationConfig = getModuleFederationConfig;
@@ -3,3 +3,4 @@ export * from './dependencies';
3
3
  export * from './package-json';
4
4
  export * from './remotes';
5
5
  export * from './models';
6
+ export * from './get-remotes-for-host';
@@ -6,3 +6,4 @@ tslib_1.__exportStar(require("./dependencies"), exports);
6
6
  tslib_1.__exportStar(require("./package-json"), exports);
7
7
  tslib_1.__exportStar(require("./remotes"), exports);
8
8
  tslib_1.__exportStar(require("./models"), exports);
9
+ tslib_1.__exportStar(require("./get-remotes-for-host"), exports);