@nx/webpack 16.9.0-beta.1 → 16.9.0-beta.3

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": "16.9.0-beta.1",
3
+ "version": "16.9.0-beta.3",
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": {
@@ -30,9 +30,9 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/core": "^7.22.9",
33
- "@nrwl/webpack": "16.9.0-beta.1",
34
- "@nx/devkit": "16.9.0-beta.1",
35
- "@nx/js": "16.9.0-beta.1",
33
+ "@nrwl/webpack": "16.9.0-beta.3",
34
+ "@nx/devkit": "16.9.0-beta.3",
35
+ "@nx/js": "16.9.0-beta.3",
36
36
  "autoprefixer": "^10.4.9",
37
37
  "babel-loader": "^9.1.2",
38
38
  "browserslist": "^4.21.4",
@@ -70,5 +70,5 @@
70
70
  "access": "public"
71
71
  },
72
72
  "type": "commonjs",
73
- "gitHead": "5056d6cefb2949ba865019e8b71e633fba28c091"
73
+ "gitHead": "d5692528c089a75c76b21d2d1235d8cc5dbb1d26"
74
74
  }
@@ -47,7 +47,7 @@ async function* devServerExecutor(serveOptions, context) {
47
47
  }
48
48
  exports.devServerExecutor = devServerExecutor;
49
49
  function getBuildOptions(options, context) {
50
- const target = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
50
+ const target = (0, devkit_1.parseTargetString)(options.buildTarget, context);
51
51
  const overrides = {
52
52
  watch: false,
53
53
  };
@@ -7,7 +7,7 @@ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
7
  const wait_until_server_is_listening_1 = require("./lib/wait-until-server-is-listening");
8
8
  async function* ssrDevServerExecutor(options, context) {
9
9
  const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
10
- const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context.projectGraph);
10
+ const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context);
11
11
  const browserOptions = (0, devkit_1.readTargetOptions)(browserTarget, context);
12
12
  const serverOptions = (0, devkit_1.readTargetOptions)(serverTarget, context);
13
13
  const runBrowser = await (0, devkit_1.runExecutor)(browserTarget, { ...browserOptions, ...options.browserTargetOptions }, context);
@@ -10,7 +10,7 @@ export type WorkspaceLibrary = {
10
10
  };
11
11
  export type SharedWorkspaceLibraryConfig = {
12
12
  getAliases: () => Record<string, string>;
13
- getLibraries: (eager?: boolean) => Record<string, SharedLibraryConfig>;
13
+ getLibraries: (projectRoot: string, eager?: boolean) => Record<string, SharedLibraryConfig>;
14
14
  getReplacementPlugin: () => NormalModuleReplacementPlugin;
15
15
  };
16
16
  export type Remotes = string[] | [remoteName: string, remoteUrl: string][];
@@ -7,7 +7,7 @@ import { Remotes } from './models';
7
7
  * @param remoteEntryExt - The file extension of the remoteEntry file
8
8
  * @param determineRemoteUrl - The function used to lookup the URL of the served remote
9
9
  */
10
- export declare function mapRemotes(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
10
+ export declare function mapRemotes(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string, isRemoteGlobal?: boolean): Record<string, string>;
11
11
  /**
12
12
  * Map remote names to a format that can be understood and used by Module
13
13
  * Federation.
@@ -10,25 +10,40 @@ const path_1 = require("path");
10
10
  * @param remoteEntryExt - The file extension of the remoteEntry file
11
11
  * @param determineRemoteUrl - The function used to lookup the URL of the served remote
12
12
  */
13
- function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl) {
13
+ function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl, isRemoteGlobal = false) {
14
14
  const mappedRemotes = {};
15
15
  for (const remote of remotes) {
16
16
  if (Array.isArray(remote)) {
17
- const [remoteName, remoteLocation] = remote;
18
- const remoteLocationExt = (0, path_1.extname)(remoteLocation);
19
- mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt)
20
- ? remoteLocation
21
- : `${remoteLocation.endsWith('/')
22
- ? remoteLocation.slice(0, -1)
23
- : remoteLocation}/remoteEntry.${remoteEntryExt}`;
17
+ mappedRemotes[remote[0]] = handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal);
24
18
  }
25
19
  else if (typeof remote === 'string') {
26
- mappedRemotes[remote] = determineRemoteUrl(remote);
20
+ mappedRemotes[remote] = handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal);
27
21
  }
28
22
  }
29
23
  return mappedRemotes;
30
24
  }
31
25
  exports.mapRemotes = mapRemotes;
26
+ // Helper function to deal with remotes that are arrays
27
+ function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
28
+ const [remoteName, remoteLocation] = remote;
29
+ const remoteLocationExt = (0, path_1.extname)(remoteLocation);
30
+ // If remote location already has .js or .mjs extension
31
+ if (['.js', '.mjs'].includes(remoteLocationExt)) {
32
+ return remoteLocation;
33
+ }
34
+ const baseRemote = remoteLocation.endsWith('/')
35
+ ? remoteLocation.slice(0, -1)
36
+ : remoteLocation;
37
+ const globalPrefix = isRemoteGlobal
38
+ ? `${remoteName.replace(/-/g, '_')}@`
39
+ : '';
40
+ return `${globalPrefix}${baseRemote}/remoteEntry.${remoteEntryExt}`;
41
+ }
42
+ // Helper function to deal with remotes that are strings
43
+ function handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal) {
44
+ const globalPrefix = isRemoteGlobal ? `${remote.replace(/-/g, '_')}@` : '';
45
+ return `${globalPrefix}${determineRemoteUrl(remote)}`;
46
+ }
32
47
  /**
33
48
  * Map remote names to a format that can be understood and used by Module
34
49
  * Federation.
@@ -5,10 +5,10 @@ import { type ProjectGraph } from '@nx/devkit';
5
5
  * Build an object of functions to be used with the ModuleFederationPlugin to
6
6
  * share Nx Workspace Libraries between Hosts and Remotes.
7
7
  *
8
- * @param libraries - The Nx Workspace Libraries to share
8
+ * @param workspaceLibs - The Nx Workspace Libraries to share
9
9
  * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
10
10
  */
11
- export declare function shareWorkspaceLibraries(libraries: WorkspaceLibrary[], tsConfigPath?: string): SharedWorkspaceLibraryConfig;
11
+ export declare function shareWorkspaceLibraries(workspaceLibs: WorkspaceLibrary[], tsConfigPath?: string): SharedWorkspaceLibraryConfig;
12
12
  /**
13
13
  * Build the Module Federation Share Config for a specific package and the
14
14
  * specified version of that package.
@@ -6,15 +6,16 @@ const package_json_1 = require("./package-json");
6
6
  const typescript_1 = require("./typescript");
7
7
  const secondary_entry_points_1 = require("./secondary-entry-points");
8
8
  const devkit_1 = require("@nx/devkit");
9
+ const fs_1 = require("fs");
9
10
  /**
10
11
  * Build an object of functions to be used with the ModuleFederationPlugin to
11
12
  * share Nx Workspace Libraries between Hosts and Remotes.
12
13
  *
13
- * @param libraries - The Nx Workspace Libraries to share
14
+ * @param workspaceLibs - The Nx Workspace Libraries to share
14
15
  * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
15
16
  */
16
- function shareWorkspaceLibraries(libraries, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
17
- if (!libraries) {
17
+ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
18
+ if (!workspaceLibs) {
18
19
  return getEmptySharedLibrariesConfig();
19
20
  }
20
21
  const tsconfigPathAliases = (0, typescript_1.readTsPathMappings)(tsConfigPath);
@@ -23,7 +24,7 @@ function shareWorkspaceLibraries(libraries, tsConfigPath = process.env.NX_TSCONF
23
24
  }
24
25
  const pathMappings = [];
25
26
  for (const [key, paths] of Object.entries(tsconfigPathAliases)) {
26
- const library = libraries.find((lib) => lib.importKey === key);
27
+ const library = workspaceLibs.find((lib) => lib.importKey === key);
27
28
  if (!library) {
28
29
  continue;
29
30
  }
@@ -41,10 +42,41 @@ function shareWorkspaceLibraries(libraries, tsConfigPath = process.env.NX_TSCONF
41
42
  const webpack = require('webpack');
42
43
  return {
43
44
  getAliases: () => pathMappings.reduce((aliases, library) => ({ ...aliases, [library.name]: library.path }), {}),
44
- getLibraries: (eager) => pathMappings.reduce((libraries, library) => ({
45
- ...libraries,
46
- [library.name]: { requiredVersion: false, eager },
47
- }), {}),
45
+ getLibraries: (projectRoot, eager) => {
46
+ let pkgJson = null;
47
+ if (projectRoot &&
48
+ (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'))) {
49
+ pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
50
+ }
51
+ return pathMappings.reduce((libraries, library) => {
52
+ // Check to see if the library version is declared in the app's package.json
53
+ let version = pkgJson?.dependencies?.[library.name];
54
+ if (!version && workspaceLibs.length > 0) {
55
+ const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
56
+ const libPackageJsonPath = workspaceLib
57
+ ? (0, path_1.join)(workspaceLib.root, 'package.json')
58
+ : null;
59
+ if (libPackageJsonPath && (0, fs_1.existsSync)(libPackageJsonPath)) {
60
+ pkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
61
+ if (pkgJson) {
62
+ version = pkgJson.version;
63
+ }
64
+ }
65
+ }
66
+ return {
67
+ ...libraries,
68
+ [library.name]: {
69
+ ...(version
70
+ ? {
71
+ requiredVersion: version,
72
+ singleton: true,
73
+ }
74
+ : { requiredVersion: false }),
75
+ eager,
76
+ },
77
+ };
78
+ }, {});
79
+ },
48
80
  getReplacementPlugin: () => new webpack.NormalModuleReplacementPlugin(/./, (req) => {
49
81
  if (!req.request.startsWith('.')) {
50
82
  return;
@@ -225,6 +225,7 @@ function withNx(pluginOptions) {
225
225
  minify: TerserPlugin.swcMinify,
226
226
  // `terserOptions` options will be passed to `swc`
227
227
  terserOptions: {
228
+ module: true,
228
229
  mangle: false,
229
230
  },
230
231
  }),