@nx/rspack 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.
@@ -1,5 +1,5 @@
1
+ import { ExecutorContext } from '@nx/devkit';
1
2
  import { StaticRemotesConfig } from '@nx/module-federation/internal';
2
- import { ExecutorContext } from 'nx/src/config/misc-interfaces';
3
3
  import { ModuleFederationDevServerOptions } from '../module-federation-dev-server/schema';
4
4
  import { ModuleFederationStaticServerSchema } from './schema';
5
5
  export declare function startProxies(staticRemotesConfig: StaticRemotesConfig, hostServeOptions: ModuleFederationDevServerOptions, mappedLocationOfHost: string, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
@@ -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
  const assert_supported_rspack_version_1 = require("../../utils/assert-supported-rspack-version");
13
12
  async function convertToInferred(tree, options) {
14
13
  (0, assert_supported_rspack_version_1.assertSupportedRspackVersion)(tree);
@@ -97,12 +96,12 @@ function createCollectingLogger() {
97
96
  loggedMessages.forEach((messages, method) => {
98
97
  messages.forEach((message) => {
99
98
  if (!filter || filter(message)) {
100
- devkit_exports_1.logger[method](message);
99
+ devkit_1.logger[method](message);
101
100
  }
102
101
  });
103
102
  });
104
103
  };
105
- return new Proxy({ ...devkit_exports_1.logger, loggedMessages, flushLogs }, {
104
+ return new Proxy({ ...devkit_1.logger, loggedMessages, flushLogs }, {
106
105
  get(target, property) {
107
106
  const originalMethod = target[property];
108
107
  if (typeof originalMethod === 'function') {
@@ -6,9 +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
- const package_manager_1 = require("nx/src/utils/package-manager");
12
9
  const path_1 = require("path");
13
10
  const read_rspack_options_1 = require("../utils/read-rspack-options");
14
11
  const resolve_user_defined_rspack_config_1 = require("../utils/resolve-user-defined-rspack-config");
@@ -20,12 +17,12 @@ const rspackConfigGlob = '**/rspack.config.{js,ts,mjs,mts,cjs,cts}';
20
17
  exports.createNodes = [
21
18
  rspackConfigGlob,
22
19
  async (configFilePaths, options, context) => {
23
- const optionsHash = (0, file_hasher_1.hashObject)(options);
24
- const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rspack-${optionsHash}.hash`);
20
+ const optionsHash = (0, internal_1.hashObject)(options);
21
+ const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, `rspack-${optionsHash}.hash`);
25
22
  const targetsCache = new internal_1.PluginCache(cachePath);
26
23
  const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
27
24
  const packageManager = (0, devkit_1.detectPackageManager)(context.workspaceRoot);
28
- const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
25
+ const pmc = (0, devkit_1.getPackageManagerCommand)(packageManager);
29
26
  const lockFileName = (0, js_1.getLockFileName)(packageManager);
30
27
  try {
31
28
  return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache, isTsSolutionSetup, pmc, lockFileName), configFilePaths, options, context);
@@ -52,12 +49,12 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
52
49
  packageJson = (0, devkit_1.readJsonFile)((0, path_1.join)(context.workspaceRoot, projectRoot, 'package.json'));
53
50
  }
54
51
  const normalizedOptions = normalizeOptions(options);
55
- const lockFileHash = (0, file_hasher_1.hashFile)((0, path_1.join)(context.workspaceRoot, lockFileName)) ?? '';
56
- const nodeHash = (0, file_hasher_1.hashArray)([
57
- (0, file_hasher_1.hashFile)((0, path_1.join)(context.workspaceRoot, configFilePath)),
52
+ const lockFileHash = (0, internal_1.hashFile)((0, path_1.join)(context.workspaceRoot, lockFileName)) ?? '';
53
+ const nodeHash = (0, devkit_1.hashArray)([
54
+ (0, internal_1.hashFile)((0, path_1.join)(context.workspaceRoot, configFilePath)),
58
55
  lockFileHash,
59
- (0, file_hasher_1.hashObject)({ ...options, isTsSolutionSetup }),
60
- (0, file_hasher_1.hashObject)(packageJson),
56
+ (0, internal_1.hashObject)({ ...options, isTsSolutionSetup }),
57
+ (0, internal_1.hashObject)(packageJson),
61
58
  ]);
62
59
  // We do not want to alter how the hash is calculated, so appending the config file path to the hash
63
60
  // to prevent vite/vitest files overwriting the target cache created by the other
@@ -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("../utils/plugins/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 rspack 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,
@@ -6,6 +6,7 @@ const path = tslib_1.__importStar(require("path"));
6
6
  const license_webpack_plugin_1 = require("license-webpack-plugin");
7
7
  const js_1 = require("@nx/js");
8
8
  const version_utils_1 = require("../../utils/version-utils");
9
+ const load_rspack_core_1 = require("../../utils/load-rspack-core");
9
10
  const stats_json_plugin_1 = require("./plugins/stats-json-plugin");
10
11
  const generate_package_json_plugin_1 = require("./plugins/generate-package-json-plugin");
11
12
  const hash_format_1 = require("./hash-format");
@@ -36,10 +37,8 @@ function applyBaseConfig(options, config = {}, { useNormalizedEntry, compiler, }
36
37
  options.progress ??= true;
37
38
  options.outputHashing ??= 'all';
38
39
  // Lazy-require avoids loading @rspack/core (pure ESM in v2) at module
39
- // parse time, so Jest can still load this file.
40
- const rspackCore = compiler
41
- ? compiler.rspack
42
- : require('@rspack/core');
40
+ // parse time, so Jest can still load this file. See load-rspack-core.ts.
41
+ const rspackCore = (0, load_rspack_core_1.loadRspackCore)(compiler);
43
42
  applyNxIndependentConfig(options, config, rspackCore);
44
43
  // Some of the options only work during actual tasks, not when reading the rspack config during CreateNodes.
45
44
  if (global.NX_GRAPH_CREATION)
@@ -8,15 +8,15 @@ const hash_format_1 = require("./hash-format");
8
8
  const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
9
9
  const stylesheet_loaders_1 = require("./loaders/stylesheet-loaders");
10
10
  const normalize_entry_1 = require("./normalize-entry");
11
+ const load_rspack_core_1 = require("../../utils/load-rspack-core");
11
12
  function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, } = {}) {
12
13
  if (global.NX_GRAPH_CREATION)
13
14
  return;
14
15
  // Prefer compiler.rspack when available; otherwise lazy-require
15
16
  // @rspack/core (works on Node 22.12+ via require(esm), and keeps the
16
17
  // file Jest-loadable since the require is inside the function body).
17
- const rspackCore = compiler
18
- ? compiler.rspack
19
- : require('@rspack/core');
18
+ // See load-rspack-core.ts.
19
+ const rspackCore = (0, load_rspack_core_1.loadRspackCore)(compiler);
20
20
  const { CssExtractRspackPlugin, DefinePlugin, EnvironmentPlugin, HtmlRspackPlugin, LightningCssMinimizerRspackPlugin, } = rspackCore;
21
21
  const cssExtractLoader = CssExtractRspackPlugin.loader;
22
22
  // Defaults that was applied from executor schema previously.
@@ -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
  }
@@ -12,6 +12,8 @@ export declare function getCommonLoadersForCssModules(options: any, includePaths
12
12
  modules: {
13
13
  mode: string;
14
14
  getLocalIdent: typeof getCSSModuleLocalIdent;
15
+ namedExport: boolean;
16
+ exportLocalsConvention: string;
15
17
  };
16
18
  importLoaders: number;
17
19
  implementation?: undefined;
@@ -24,6 +24,11 @@ function getCommonLoadersForCssModules(options, includePaths, cssExtractLoader)
24
24
  modules: {
25
25
  mode: 'local',
26
26
  getLocalIdent: get_css_module_local_ident_1.getCSSModuleLocalIdent,
27
+ // css-loader 7 defaults namedExport to true, and to camel-case-only
28
+ // locals when it is off. Generated components import the default
29
+ // export and reference class names as authored, so pin both.
30
+ namedExport: false,
31
+ exportLocalsConvention: 'asIs',
27
32
  },
28
33
  importLoaders: 1,
29
34
  },
@@ -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) {
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RspackNxBuildCoordinationPlugin = 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 RspackNxBuildCoordinationPlugin {
9
8
  constructor(buildCmd, skipInitialBuild) {
10
9
  this.buildCmd = buildCmd;
@@ -13,11 +12,11 @@ class RspackNxBuildCoordinationPlugin {
13
12
  if (!skipInitialBuild) {
14
13
  this.buildChangedProjects();
15
14
  }
16
- if ((0, client_1.isDaemonEnabled)()) {
15
+ if ((0, devkit_1.isDaemonEnabled)()) {
17
16
  this.startWatchingBuildableLibs();
18
17
  }
19
18
  else {
20
- output_1.output.warn({
19
+ devkit_1.output.warn({
21
20
  title: 'Nx Daemon is not enabled. Buildable libs will not be rebuilt on file changes.',
22
21
  });
23
22
  }
@@ -65,8 +64,8 @@ class RspackNxBuildCoordinationPlugin {
65
64
  }
66
65
  }
67
66
  createFileWatcher() {
68
- const runner = new watch_1.BatchFunctionRunner(() => this.buildChangedProjects());
69
- return client_1.daemonClient.registerFileWatcher({
67
+ const runner = new internal_1.BatchFunctionRunner(() => this.buildChangedProjects());
68
+ return internal_1.daemonClient.registerFileWatcher({
70
69
  watchProjects: 'all',
71
70
  }, (err, { changedProjects, changedFiles }) => {
72
71
  if (err === 'reconnecting') {
@@ -78,13 +77,13 @@ class RspackNxBuildCoordinationPlugin {
78
77
  return;
79
78
  }
80
79
  else if (err === 'closed') {
81
- output_1.output.error({
80
+ devkit_1.output.error({
82
81
  title: 'Failed to reconnect to daemon after multiple attempts',
83
82
  });
84
83
  process.exit(1);
85
84
  }
86
85
  else if (err) {
87
- output_1.output.error({
86
+ devkit_1.output.error({
88
87
  title: `Watch error: ${err?.message ?? 'Unknown'}`,
89
88
  });
90
89
  }
@@ -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.nxRspackComposablePlugin = 'nxRspackComposablePlugin';
12
12
  function isNxRspackComposablePlugin(a) {
13
13
  return a?.[exports.nxRspackComposablePlugin] === true;
@@ -80,7 +80,7 @@ function ensureNxRspackExecutionContext(ctx) {
80
80
  targetName,
81
81
  configurationName,
82
82
  projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
83
- nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
83
+ nxJsonConfiguration: (0, internal_2.readNxJsonFromDisk)(devkit_1.workspaceRoot),
84
84
  cwd: process.cwd(),
85
85
  root: devkit_1.workspaceRoot,
86
86
  isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
@@ -1,5 +1,5 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import { type Compiler, type MultiCompiler } from '@rspack/core';
2
+ import type { Compiler, MultiCompiler } from '@rspack/core';
3
3
  import { NormalizedRspackExecutorSchema } from '../executors/rspack/schema';
4
4
  export declare function createCompiler(options: NormalizedRspackExecutorSchema & {
5
5
  devServer?: any;
@@ -2,14 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCompiler = createCompiler;
4
4
  exports.isMultiCompiler = isMultiCompiler;
5
- const core_1 = require("@rspack/core");
6
5
  const config_1 = require("../executors/rspack/lib/config");
6
+ const load_rspack_core_1 = require("./load-rspack-core");
7
7
  async function createCompiler(options, context) {
8
8
  const config = await (0, config_1.getRspackConfigs)(options, context);
9
9
  if (!options.standardRspackConfigFunction) {
10
10
  validateConfig(config);
11
11
  }
12
- return (0, core_1.rspack)(config);
12
+ // Lazy-loaded to avoid resolving @rspack/core (pure ESM) before a build runs; see load-rspack-core.ts.
13
+ const { rspack } = (0, load_rspack_core_1.loadRspackCore)();
14
+ return rspack(config);
13
15
  }
14
16
  function isMultiCompiler(compiler) {
15
17
  return 'compilers' in compiler;
@@ -0,0 +1,2 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ export declare function loadRspackCore(compiler?: Pick<Compiler, 'rspack'>): typeof import('@rspack/core');
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadRspackCore = loadRspackCore;
4
+ // @rspack/core v2 is pure ESM; lazy-require avoids resolving it before a Compiler exists.
5
+ function loadRspackCore(compiler) {
6
+ // Reuse the compiler's already-resolved module to avoid ending up with a second, possibly different copy.
7
+ return compiler
8
+ ? compiler.rspack
9
+ : require('@rspack/core');
10
+ }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readRspackOptions = readRspackOptions;
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 Rspack options from a give Rspack configuration. The configuration can be:
9
9
  * 1. A single standard config object
@@ -36,7 +36,7 @@ async function readRspackOptions(rspackConfig) {
36
36
  root: devkit_1.workspaceRoot,
37
37
  cwd: undefined,
38
38
  isVerbose: false,
39
- nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
39
+ nxJsonConfiguration: (0, internal_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
40
40
  projectGraph: null,
41
41
  projectsConfigurations: null,
42
42
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/rspack",
3
3
  "description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
4
- "version": "23.1.0",
4
+ "version": "23.1.2",
5
5
  "type": "commonjs",
6
6
  "files": [
7
7
  "dist",
@@ -130,10 +130,10 @@
130
130
  "@phenomnomnominal/tsquery": "~6.2.0",
131
131
  "autoprefixer": "^10.4.9",
132
132
  "browserslist": "^4.26.0",
133
- "css-loader": "^6.4.0",
133
+ "css-loader": "^7.1.4",
134
134
  "enquirer": "~2.3.6",
135
135
  "express": "^4.21.2",
136
- "http-proxy-middleware": "^3.0.5",
136
+ "http-proxy-middleware": "^3.0.7",
137
137
  "less-loader": "^12.2.0",
138
138
  "license-webpack-plugin": "^4.0.2",
139
139
  "loader-utils": "^2.0.3",
@@ -152,14 +152,14 @@
152
152
  "tslib": "^2.3.0",
153
153
  "webpack": "5.105.2",
154
154
  "webpack-node-externals": "^3.0.0",
155
- "@nx/devkit": "23.1.0",
156
- "@nx/js": "23.1.0",
157
- "@nx/module-federation": "23.1.0",
158
- "@nx/web": "23.1.0"
155
+ "@nx/devkit": "23.1.2",
156
+ "@nx/module-federation": "23.1.2",
157
+ "@nx/web": "23.1.2",
158
+ "@nx/js": "23.1.2"
159
159
  },
160
160
  "devDependencies": {
161
- "nx": "23.1.0",
162
- "@nx/nest": "23.1.0"
161
+ "nx": "23.1.2",
162
+ "@nx/nest": "23.1.2"
163
163
  },
164
164
  "peerDependencies": {
165
165
  "@rspack/cli": "^1.0.0 || ^2.0.0",