@nx/webpack 23.1.0 → 23.1.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.
@@ -89,6 +89,11 @@ async function* webpackExecutor(_options, context) {
89
89
  // Run build sequentially and bail when first one fails.
90
90
  (0, operators_1.mergeScan)((acc, config) => {
91
91
  if (!acc.hasErrors()) {
92
+ // Propagate watch mode from executor options to webpack config.
93
+ // Without this, NxAppWebpackPlugin-based configs run in single-run
94
+ // mode even when the executor is invoked with watch: true, causing
95
+ // @nx/js:node to restart the process after every build.
96
+ config.watch = options.watch ?? config.watch;
92
97
  return (0, run_webpack_1.runWebpack)(config).pipe((0, operators_1.tap)((stats) => {
93
98
  console.info(stats.toString(config.stats));
94
99
  }));
@@ -1,5 +1,4 @@
1
- import { type Tree } from '@nx/devkit';
2
- import { logger as devkitLogger } from 'nx/src/devkit-exports';
1
+ import { type Tree, logger as devkitLogger } from '@nx/devkit';
3
2
  interface Schema {
4
3
  project?: string;
5
4
  skipFormat?: boolean;
@@ -8,7 +8,6 @@ const tsquery_1 = require("@phenomnomnominal/tsquery");
8
8
  const plugin_1 = require("../../plugins/plugin");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const utils_1 = require("./utils");
11
- const devkit_exports_1 = require("nx/src/devkit-exports");
12
11
  async function convertToInferred(tree, options) {
13
12
  (0, versions_1.assertSupportedWebpackVersion)(tree);
14
13
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
@@ -90,12 +89,12 @@ function createCollectingLogger() {
90
89
  loggedMessages.forEach((messages, method) => {
91
90
  messages.forEach((message) => {
92
91
  if (!filter || filter(message)) {
93
- devkit_exports_1.logger[method](message);
92
+ devkit_1.logger[method](message);
94
93
  }
95
94
  });
96
95
  });
97
96
  };
98
- return new Proxy({ ...devkit_exports_1.logger, loggedMessages, flushLogs }, {
97
+ return new Proxy({ ...devkit_1.logger, loggedMessages, flushLogs }, {
99
98
  get(target, property) {
100
99
  const originalMethod = target[property];
101
100
  if (typeof originalMethod === 'function') {
@@ -150,6 +150,10 @@ function applyNxIndependentConfig(options, config) {
150
150
  })
151
151
  : new TerserPlugin({
152
152
  minify: TerserPlugin.swcMinify,
153
+ // terser-webpack-plugin 5.6+ forwards `extractComments` into swc's
154
+ // minify options, which rejects it as an unknown field. Disable it
155
+ // like the babel branch does above.
156
+ extractComments: false,
153
157
  // `terserOptions` options will be passed to `swc`
154
158
  terserOptions: {
155
159
  module: true,
@@ -13,6 +13,8 @@ export declare function getCommonLoadersForCssModules(options: NormalizedNxAppWe
13
13
  modules: {
14
14
  mode: string;
15
15
  getLocalIdent: typeof getCSSModuleLocalIdent;
16
+ namedExport: boolean;
17
+ exportLocalsConvention: string;
16
18
  };
17
19
  importLoaders: number;
18
20
  implementation?: undefined;
@@ -25,6 +25,11 @@ function getCommonLoadersForCssModules(options, includePaths) {
25
25
  modules: {
26
26
  mode: 'local',
27
27
  getLocalIdent: get_css_module_local_ident_1.getCSSModuleLocalIdent,
28
+ // css-loader 7 defaults namedExport to true, and to camel-case-only
29
+ // locals when it is off. Generated components import the default
30
+ // export and reference class names as authored, so pin both.
31
+ namedExport: false,
32
+ exportLocalsConvention: 'asIs',
28
33
  },
29
34
  importLoaders: 1,
30
35
  },
@@ -16,12 +16,24 @@ function resolveConditionalExport(target) {
16
16
  if (typeof target === 'string') {
17
17
  return target;
18
18
  }
19
+ // Fallback arrays: take the first non-empty target. Node resolves them in
20
+ // order on disk; for the allowlist any valid target marks the subpath.
21
+ if (Array.isArray(target)) {
22
+ for (const candidate of target) {
23
+ const resolved = resolveConditionalExport(candidate);
24
+ if (resolved) {
25
+ return resolved;
26
+ }
27
+ }
28
+ return null;
29
+ }
19
30
  if (typeof target === 'object' && target !== null) {
20
31
  // Priority order for conditions
21
32
  const conditions = ['development', 'import', 'require', 'default'];
22
33
  for (const condition of conditions) {
23
- if (target[condition] && typeof target[condition] === 'string') {
24
- return target[condition];
34
+ const resolved = resolveConditionalExport(target[condition]);
35
+ if (resolved) {
36
+ return resolved;
25
37
  }
26
38
  }
27
39
  }
@@ -6,8 +6,6 @@ const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
7
7
  const internal_2 = require("@nx/js/internal");
8
8
  const fs_1 = require("fs");
9
- const file_hasher_1 = require("nx/src/hasher/file-hasher");
10
- const cache_directory_1 = require("nx/src/utils/cache-directory");
11
9
  const path_1 = require("path");
12
10
  const read_webpack_options_1 = require("../utils/webpack/read-webpack-options");
13
11
  const resolve_user_defined_webpack_config_1 = require("../utils/webpack/resolve-user-defined-webpack-config");
@@ -22,8 +20,8 @@ const webpackConfigGlob = '**/webpack.config.{js,ts,mjs,cjs}';
22
20
  exports.createNodes = [
23
21
  webpackConfigGlob,
24
22
  async (configFilePaths, options, context) => {
25
- const optionsHash = (0, file_hasher_1.hashObject)(options);
26
- const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `webpack-${optionsHash}.hash`);
23
+ const optionsHash = (0, internal_1.hashObject)(options);
24
+ const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, `webpack-${optionsHash}.hash`);
27
25
  const targetsCache = new internal_1.PluginCache(cachePath);
28
26
  const normalizedOptions = normalizeOptions(options);
29
27
  const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
@@ -3,7 +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
+ const internal_1 = require("@nx/devkit/internal");
7
7
  /**
8
8
  * This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
9
9
  * Initially the webpack config would be passed to the legacy plugin function and the options would be passed as a second argument.
@@ -44,7 +44,7 @@ async function useLegacyNxPlugin(fn, executorOptions) {
44
44
  root: devkit_1.workspaceRoot,
45
45
  projectGraph,
46
46
  projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
47
- nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
47
+ nxJsonConfiguration: (0, internal_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
48
48
  target: project.data.targets[targetName],
49
49
  targetName: targetName,
50
50
  projectName: projectName,
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebpackNxBuildCoordinationPlugin = void 0;
4
4
  const child_process_1 = require("child_process");
5
- const client_1 = require("nx/src/daemon/client/client");
6
- const watch_1 = require("nx/src/command-line/watch/watch");
7
- const output_1 = require("nx/src/utils/output");
5
+ const internal_1 = require("@nx/devkit/internal");
6
+ const devkit_1 = require("@nx/devkit");
8
7
  class WebpackNxBuildCoordinationPlugin {
9
8
  constructor(buildCmd, skipInitialBuildOrOptions) {
10
9
  this.buildCmd = buildCmd;
@@ -17,11 +16,11 @@ class WebpackNxBuildCoordinationPlugin {
17
16
  this.buildChangedProjects();
18
17
  }
19
18
  if (!options?.skipWatchingDeps) {
20
- if ((0, client_1.isDaemonEnabled)()) {
19
+ if ((0, devkit_1.isDaemonEnabled)()) {
21
20
  this.startWatchingBuildableLibs();
22
21
  }
23
22
  else {
24
- output_1.output.warn({
23
+ devkit_1.output.warn({
25
24
  title: 'Nx Daemon is not enabled. Buildable libs will not be rebuilt on file changes.',
26
25
  });
27
26
  }
@@ -70,8 +69,8 @@ class WebpackNxBuildCoordinationPlugin {
70
69
  }
71
70
  }
72
71
  createFileWatcher() {
73
- const runner = new watch_1.BatchFunctionRunner(() => this.buildChangedProjects());
74
- return client_1.daemonClient.registerFileWatcher({
72
+ const runner = new internal_1.BatchFunctionRunner(() => this.buildChangedProjects());
73
+ return internal_1.daemonClient.registerFileWatcher({
75
74
  watchProjects: 'all',
76
75
  }, (err, { changedProjects, changedFiles }) => {
77
76
  if (err === 'reconnecting') {
@@ -83,13 +82,13 @@ class WebpackNxBuildCoordinationPlugin {
83
82
  return;
84
83
  }
85
84
  else if (err === 'closed') {
86
- output_1.output.error({
85
+ devkit_1.output.error({
87
86
  title: 'Failed to reconnect to daemon after multiple attempts',
88
87
  });
89
88
  process.exit(1);
90
89
  }
91
90
  else if (err) {
92
- output_1.output.error({
91
+ devkit_1.output.error({
93
92
  title: `Watch error: ${err?.message ?? 'Unknown'}`,
94
93
  });
95
94
  }
@@ -6,8 +6,8 @@ exports.composePlugins = composePlugins;
6
6
  exports.composePluginsSync = composePluginsSync;
7
7
  const devkit_1 = require("@nx/devkit");
8
8
  const internal_1 = require("@nx/js/internal");
9
- const configuration_1 = require("nx/src/config/configuration");
10
9
  const deprecation_1 = require("./deprecation");
10
+ const internal_2 = require("@nx/devkit/internal");
11
11
  exports.nxWebpackComposablePlugin = 'nxWebpackComposablePlugin';
12
12
  function isNxWebpackComposablePlugin(a) {
13
13
  return a?.[exports.nxWebpackComposablePlugin] === true;
@@ -78,7 +78,7 @@ function ensureNxWebpackExecutionContext(ctx) {
78
78
  targetName,
79
79
  configurationName,
80
80
  projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
81
- nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
81
+ nxJsonConfiguration: (0, internal_2.readNxJsonFromDisk)(devkit_1.workspaceRoot),
82
82
  cwd: process.cwd(),
83
83
  root: devkit_1.workspaceRoot,
84
84
  isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
@@ -6,7 +6,7 @@ exports.deleteOutputDir = deleteOutputDir;
6
6
  const tslib_1 = require("tslib");
7
7
  const path = tslib_1.__importStar(require("path"));
8
8
  const fs_1 = require("fs");
9
- const fileutils_1 = require("nx/src/utils/fileutils");
9
+ const internal_1 = require("@nx/devkit/internal");
10
10
  function findUp(names, from, stopOnNodeModules = false) {
11
11
  if (!Array.isArray(names)) {
12
12
  names = [names];
@@ -35,7 +35,7 @@ function findAllNodeModules(from, root) {
35
35
  let current = from;
36
36
  while (current && current !== root) {
37
37
  const potential = path.join(current, 'node_modules');
38
- if ((0, fileutils_1.directoryExists)(potential)) {
38
+ if ((0, internal_1.directoryExists)(potential)) {
39
39
  nodeModules.push(potential);
40
40
  }
41
41
  const next = path.dirname(current);
@@ -4,7 +4,6 @@ exports.PostcssCliResources = PostcssCliResources;
4
4
  const tslib_1 = require("tslib");
5
5
  const loader_utils_1 = require("loader-utils");
6
6
  const path = tslib_1.__importStar(require("path"));
7
- const url_1 = require("url");
8
7
  function wrapUrl(url) {
9
8
  let wrappedUrl;
10
9
  const hasSingleQuotes = url.indexOf("'") >= 0;
@@ -80,14 +79,19 @@ function PostcssCliResources(options) {
80
79
  // Separate URL query/hash from the file path before resolving
81
80
  const [, filePath, urlSuffix] = inputUrl.match(/^([^?#]*)(.*)$/);
82
81
  const resolvedPath = path.resolve(context, filePath.replace(/\\/g, '/'));
83
- const { pathname } = (0, url_1.pathToFileURL)(resolvedPath);
82
+ // Resolve a relative filesystem path, not a file:// URL pathname: on Windows the
83
+ // pathname is `/C:/...` (spaces as %20), which the resolver cannot find. Relative
84
+ // (not absolute) lets `resolve()`'s `./`-prefixed lookup succeed on the first try.
85
+ const resolveRequest = path
86
+ .relative(context, resolvedPath)
87
+ .replace(/\\/g, '/');
84
88
  let hash = '';
85
89
  let search = '';
86
90
  if (urlSuffix) {
87
91
  ({ hash, search } = new URL(`file:///dummy${urlSuffix}`));
88
92
  }
89
93
  const resolver = (file, base) => new Promise((resolve, reject) => {
90
- loader.resolve(base, decodeURI(file), (err, result) => {
94
+ loader.resolve(base, file, (err, result) => {
91
95
  if (err) {
92
96
  reject(err);
93
97
  return;
@@ -95,7 +99,7 @@ function PostcssCliResources(options) {
95
99
  resolve(result);
96
100
  });
97
101
  });
98
- const result = await resolve(pathname, context, resolver);
102
+ const result = await resolve(resolveRequest, context, resolver);
99
103
  return new Promise((resolve, reject) => {
100
104
  loader.fs.readFile(result, (err, content) => {
101
105
  if (err) {
@@ -3,7 +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
+ const internal_1 = require("@nx/devkit/internal");
7
7
  /**
8
8
  * Reads the webpack options from a give webpack configuration. The configuration can be:
9
9
  * 1. A standard config object
@@ -34,7 +34,7 @@ async function readWebpackOptions(webpackConfig) {
34
34
  isVerbose: false,
35
35
  projectsConfigurations: null,
36
36
  projectGraph: null,
37
- nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
37
+ nxJsonConfiguration: (0, internal_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
38
38
  },
39
39
  });
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "23.1.0",
3
+ "version": "23.1.2",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -86,7 +86,7 @@
86
86
  }
87
87
  },
88
88
  "dependencies": {
89
- "@babel/core": "^7.23.2",
89
+ "@babel/core": "^7.29.6",
90
90
  "@phenomnomnominal/tsquery": "~6.2.0",
91
91
  "ajv": "^8.0.0",
92
92
  "autoprefixer": "^10.4.9",
@@ -94,10 +94,10 @@
94
94
  "browserslist": "^4.26.0",
95
95
  "picocolors": "^1.1.0",
96
96
  "copy-webpack-plugin": "^14.0.0",
97
- "css-loader": "^6.4.0",
97
+ "css-loader": "^7.1.4",
98
98
  "css-minimizer-webpack-plugin": "^8.0.0",
99
99
  "fork-ts-checker-webpack-plugin": "9.1.0",
100
- "less": ">=4.1.3 <4.6.0",
100
+ "less": ">=4.1.3 <4.9.0",
101
101
  "less-loader": "^12.2.0",
102
102
  "license-webpack-plugin": "^4.0.2",
103
103
  "loader-utils": "^2.0.3",
@@ -118,8 +118,8 @@
118
118
  "tslib": "^2.3.0",
119
119
  "webpack-node-externals": "^3.0.0",
120
120
  "webpack-subresource-integrity": "^5.1.0",
121
- "@nx/devkit": "23.1.0",
122
- "@nx/js": "23.1.0"
121
+ "@nx/js": "23.1.2",
122
+ "@nx/devkit": "23.1.2"
123
123
  },
124
124
  "peerDependencies": {
125
125
  "webpack": "^5.0.0",
@@ -138,7 +138,7 @@
138
138
  }
139
139
  },
140
140
  "devDependencies": {
141
- "nx": "23.1.0"
141
+ "nx": "23.1.2"
142
142
  },
143
143
  "publishConfig": {
144
144
  "access": "public"