@nx/webpack 0.0.0-pr-28229-afe192c → 0.0.0-pr-28453-54fa63c

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/index.js CHANGED
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "useLegacyNxPlugin", { enumerable: true, get: fun
13
13
  // Exported for backwards compatibility in case a plugin is using the old name.
14
14
  /** @deprecated Use `configurationGenerator` instead. */
15
15
  exports.webpackProjectGenerator = configuration_1.configurationGenerator;
16
- // TODO(v20): Remove this in favor of deep imports in order to load configs faster (150-200ms faster).
16
+ // TODO(v21): Remove this in favor of deep imports in order to load configs faster (150-200ms faster).
17
17
  /** @deprecated Use NxAppWebpackPlugin from `@nx/webpack/app-plugin` instead. */
18
18
  exports.NxWebpackPlugin = nx_app_webpack_plugin_1.NxAppWebpackPlugin;
19
19
  /** @deprecated Use NxTsconfigPathsWebpackPlugin from `@nx/webpack/tsconfig-paths-plugin` instead. */
package/migrations.json CHANGED
@@ -1,11 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "update-16-0-0-add-nx-packages": {
4
- "cli": "nx",
5
- "version": "16.0.0-beta.1",
6
- "description": "Replace @nrwl/webpack with @nx/webpack",
7
- "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
8
- },
9
3
  "update-17-2-1-webpack-config-setup": {
10
4
  "cli": "nx",
11
5
  "version": "17.2.1-beta.0",
@@ -20,24 +14,6 @@
20
14
  }
21
15
  },
22
16
  "packageJsonUpdates": {
23
- "16.3.0": {
24
- "version": "16.3.0-beta.8",
25
- "packages": {
26
- "@svgr/webpack": {
27
- "version": "^8.0.1",
28
- "alwaysAddToPackageJson": false
29
- }
30
- }
31
- },
32
- "16.4.1": {
33
- "version": "16.4.1-beta.0",
34
- "packages": {
35
- "webpack": {
36
- "version": "^5.80.0",
37
- "alwaysAddToPackageJson": false
38
- }
39
- }
40
- },
41
17
  "19.6.0": {
42
18
  "version": "19.6.0-beta.1",
43
19
  "packages": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "0.0.0-pr-28229-afe192c",
3
+ "version": "0.0.0-pr-28453-54fa63c",
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": {
@@ -69,8 +69,8 @@
69
69
  "webpack-dev-server": "^5.0.4",
70
70
  "webpack-node-externals": "^3.0.0",
71
71
  "webpack-subresource-integrity": "^5.1.0",
72
- "@nx/devkit": "0.0.0-pr-28229-afe192c",
73
- "@nx/js": "0.0.0-pr-28229-afe192c"
72
+ "@nx/devkit": "0.0.0-pr-28453-54fa63c",
73
+ "@nx/js": "0.0.0-pr-28453-54fa63c"
74
74
  },
75
75
  "publishConfig": {
76
76
  "access": "public"
@@ -47,7 +47,7 @@ export interface WebpackExecutorOptions {
47
47
  extractLicenses?: boolean;
48
48
  fileReplacements?: FileReplacement[];
49
49
  generatePackageJson?: boolean;
50
- // TODO(v20): Remove this option
50
+ // TODO(v21): Remove this option
51
51
  /** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
52
52
  isolatedConfig?: boolean;
53
53
  standardWebpackConfigFunction?: boolean;
@@ -7,10 +7,12 @@ const init_1 = require("../init/init");
7
7
  const has_plugin_1 = require("../../utils/has-plugin");
8
8
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
9
9
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
10
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
10
11
  function configurationGenerator(tree, options) {
11
12
  return configurationGeneratorInternal(tree, { addPlugin: false, ...options });
12
13
  }
13
14
  async function configurationGeneratorInternal(tree, options) {
15
+ (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'webpack', 'configuration');
14
16
  const tasks = [];
15
17
  const nxJson = (0, devkit_1.readNxJson)(tree);
16
18
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
@@ -4,12 +4,14 @@ exports.webpackInitGenerator = webpackInitGenerator;
4
4
  exports.webpackInitGeneratorInternal = webpackInitGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
8
  const plugin_1 = require("../../plugins/plugin");
8
9
  const versions_1 = require("../../utils/versions");
9
10
  function webpackInitGenerator(tree, schema) {
10
11
  return webpackInitGeneratorInternal(tree, { addPlugin: false, ...schema });
11
12
  }
12
13
  async function webpackInitGeneratorInternal(tree, schema) {
14
+ (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'webpack', 'init');
13
15
  const nxJson = (0, devkit_1.readNxJson)(tree);
14
16
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
15
17
  nxJson.useInferencePlugins !== false;
@@ -11,7 +11,7 @@ import type { Compiler, Configuration } from 'webpack';
11
11
  return config;
12
12
  }
13
13
  );
14
-
14
+
15
15
  Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
16
16
  Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
17
17
  The context options are created and passed to the legacy plugin function.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useLegacyNxPlugin = useLegacyNxPlugin;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const normalize_options_1 = require("../nx-webpack-plugin/lib/normalize-options");
6
+ const configuration_1 = require("nx/src/config/configuration");
6
7
  /**
7
8
  * This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
8
9
  * Initially the webpack config would be passed to the legacy plugin function and the options would be passed as a second argument.
@@ -13,7 +14,7 @@ const normalize_options_1 = require("../nx-webpack-plugin/lib/normalize-options"
13
14
  return config;
14
15
  }
15
16
  );
16
-
17
+
17
18
  Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
18
19
  Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
19
20
  The context options are created and passed to the legacy plugin function.
@@ -40,8 +41,10 @@ async function useLegacyNxPlugin(fn, executorOptions) {
40
41
  const context = {
41
42
  cwd: process.cwd(),
42
43
  isVerbose: process.env.NX_VERBOSE_LOGGING === 'true',
43
- root: project.data.root,
44
- projectGraph: (0, devkit_1.readCachedProjectGraph)(),
44
+ root: devkit_1.workspaceRoot,
45
+ projectGraph,
46
+ projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
47
+ nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
45
48
  target: project.data.targets[targetName],
46
49
  targetName: targetName,
47
50
  projectName: projectName,
@@ -5,6 +5,7 @@ exports.isNxWebpackComposablePlugin = isNxWebpackComposablePlugin;
5
5
  exports.composePlugins = composePlugins;
6
6
  exports.composePluginsSync = composePluginsSync;
7
7
  const devkit_1 = require("@nx/devkit");
8
+ const configuration_1 = require("nx/src/config/configuration");
8
9
  exports.nxWebpackComposablePlugin = 'nxWebpackComposablePlugin';
9
10
  function isNxWebpackComposablePlugin(a) {
10
11
  return a?.[exports.nxWebpackComposablePlugin] === true;
@@ -59,6 +60,8 @@ function ensureNxWebpackExecutionContext(ctx) {
59
60
  projectName,
60
61
  targetName,
61
62
  configurationName,
63
+ projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
64
+ nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
62
65
  cwd: process.cwd(),
63
66
  root: devkit_1.workspaceRoot,
64
67
  isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
@@ -13,29 +13,32 @@ const path_1 = require("path");
13
13
  */
14
14
  function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl, isRemoteGlobal = false) {
15
15
  const mappedRemotes = {};
16
- for (const remote of remotes) {
17
- if (Array.isArray(remote)) {
18
- mappedRemotes[remote[0]] = handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal);
16
+ for (const nxRemoteProjectName of remotes) {
17
+ if (Array.isArray(nxRemoteProjectName)) {
18
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName[0]);
19
+ mappedRemotes[mfRemoteName] = handleArrayRemote(nxRemoteProjectName, remoteEntryExt, isRemoteGlobal);
19
20
  }
20
- else if (typeof remote === 'string') {
21
- mappedRemotes[remote] = handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal);
21
+ else if (typeof nxRemoteProjectName === 'string') {
22
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
23
+ mappedRemotes[mfRemoteName] = handleStringRemote(nxRemoteProjectName, determineRemoteUrl, isRemoteGlobal);
22
24
  }
23
25
  }
24
26
  return mappedRemotes;
25
27
  }
26
28
  // Helper function to deal with remotes that are arrays
27
29
  function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
28
- const [remoteName, remoteLocation] = remote;
30
+ let [nxRemoteProjectName, remoteLocation] = remote;
31
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
29
32
  const remoteLocationExt = (0, path_1.extname)(remoteLocation);
30
33
  // If remote location already has .js or .mjs extension
31
- if (['.js', '.mjs'].includes(remoteLocationExt)) {
34
+ if (['.js', '.mjs', '.json'].includes(remoteLocationExt)) {
32
35
  return remoteLocation;
33
36
  }
34
37
  const baseRemote = remoteLocation.endsWith('/')
35
38
  ? remoteLocation.slice(0, -1)
36
39
  : remoteLocation;
37
40
  const globalPrefix = isRemoteGlobal
38
- ? `${remoteName.replace(/-/g, '_')}@`
41
+ ? `${normalizeRemoteName(nxRemoteProjectName)}@`
39
42
  : '';
40
43
  // if the remote is defined with anything other than http then we assume it's a promise based remote
41
44
  // In that case we should use what the user provides as the remote location
@@ -47,9 +50,11 @@ function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
47
50
  }
48
51
  }
49
52
  // Helper function to deal with remotes that are strings
50
- function handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal) {
51
- const globalPrefix = isRemoteGlobal ? `${remote.replace(/-/g, '_')}@` : '';
52
- return `${globalPrefix}${determineRemoteUrl(remote)}`;
53
+ function handleStringRemote(nxRemoteProjectName, determineRemoteUrl, isRemoteGlobal) {
54
+ const globalPrefix = isRemoteGlobal
55
+ ? `${normalizeRemoteName(nxRemoteProjectName)}@`
56
+ : '';
57
+ return `${globalPrefix}${determineRemoteUrl(nxRemoteProjectName)}`;
53
58
  }
54
59
  /**
55
60
  * Map remote names to a format that can be understood and used by Module
@@ -63,17 +68,22 @@ function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
63
68
  const mappedRemotes = {};
64
69
  for (const remote of remotes) {
65
70
  if (Array.isArray(remote)) {
66
- const [remoteName, remoteLocation] = remote;
71
+ let [nxRemoteProjectName, remoteLocation] = remote;
72
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
67
73
  const remoteLocationExt = (0, path_1.extname)(remoteLocation);
68
- mappedRemotes[remoteName] = `${remoteName}@${['.js', '.mjs'].includes(remoteLocationExt)
74
+ mappedRemotes[mfRemoteName] = `${mfRemoteName}@${['.js', '.mjs', '.json'].includes(remoteLocationExt)
69
75
  ? remoteLocation
70
76
  : `${remoteLocation.endsWith('/')
71
77
  ? remoteLocation.slice(0, -1)
72
78
  : remoteLocation}/remoteEntry.${remoteEntryExt}`}`;
73
79
  }
74
80
  else if (typeof remote === 'string') {
75
- mappedRemotes[remote] = `${remote}@${determineRemoteUrl(remote)}`;
81
+ const mfRemoteName = normalizeRemoteName(remote);
82
+ mappedRemotes[mfRemoteName] = `${mfRemoteName}@${determineRemoteUrl(remote)}`;
76
83
  }
77
84
  }
78
85
  return mappedRemotes;
79
86
  }
87
+ function normalizeRemoteName(remote) {
88
+ return remote.replace(/-/g, '_');
89
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readWebpackOptions = readWebpackOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const config_1 = require("../config");
6
+ const devkit_internals_1 = require("nx/src/devkit-internals");
6
7
  /**
7
8
  * Reads the webpack options from a give webpack configuration. The configuration can be:
8
9
  * 1. A standard config object
@@ -25,7 +26,14 @@ async function readWebpackOptions(webpackConfig) {
25
26
  outputPath: undefined,
26
27
  assets: undefined,
27
28
  },
28
- context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
29
+ context: {
30
+ root: devkit_1.workspaceRoot,
31
+ cwd: undefined,
32
+ isVerbose: false,
33
+ projectsConfigurations: null,
34
+ projectGraph: null,
35
+ nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
36
+ },
29
37
  });
30
38
  }
31
39
  else if (typeof webpackConfig === 'function') {
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function replacePackage(tree: Tree): Promise<void>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = replacePackage;
4
- const devkit_1 = require("@nx/devkit");
5
- const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- async function replacePackage(tree) {
7
- await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/webpack', '@nx/webpack');
8
- await (0, devkit_1.formatFiles)(tree);
9
- }