@nx/rspack 21.2.0-beta.2 → 21.2.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,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": "21.2.0-beta.2",
4
+ "version": "21.2.0-beta.3",
5
5
  "type": "commonjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,10 +24,10 @@
24
24
  "generators": "./generators.json",
25
25
  "executors": "./executors.json",
26
26
  "dependencies": {
27
- "@nx/js": "21.2.0-beta.2",
28
- "@nx/devkit": "21.2.0-beta.2",
29
- "@nx/web": "21.2.0-beta.2",
30
- "@nx/module-federation": "21.2.0-beta.2",
27
+ "@nx/js": "21.2.0-beta.3",
28
+ "@nx/devkit": "21.2.0-beta.3",
29
+ "@nx/web": "21.2.0-beta.3",
30
+ "@nx/module-federation": "21.2.0-beta.3",
31
31
  "@phenomnomnominal/tsquery": "~5.0.1",
32
32
  "@rspack/core": "^1.3.8",
33
33
  "@rspack/dev-server": "^1.1.1",
@@ -18,7 +18,7 @@ async function* runExecutor(options, context) {
18
18
  if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
19
19
  normalizedOptions.mode = process.env.NODE_ENV;
20
20
  }
21
- if (normalizedOptions.typeCheck) {
21
+ if (!normalizedOptions.skipTypeChecking) {
22
22
  await executeTypeCheck(normalizedOptions, context);
23
23
  }
24
24
  // Mimic --clean from webpack.
@@ -19,6 +19,12 @@ const IGNORED_RSPACK_WARNINGS = [
19
19
  /could not find any license/i,
20
20
  ];
21
21
  const extensions = ['...', '.ts', '.tsx', '.mjs', '.js', '.jsx'];
22
+ const extensionAlias = {
23
+ '.js': ['.ts', '.tsx', '.js', '.jsx'],
24
+ '.mjs': ['.mts', '.mjs'],
25
+ '.cjs': ['.cts', '.cjs'],
26
+ '.jsx': ['.tsx', '.jsx'],
27
+ };
22
28
  const mainFields = ['module', 'main'];
23
29
  function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
24
30
  // Defaults that was applied from executor schema previously.
@@ -306,6 +312,10 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
306
312
  config.resolve = {
307
313
  ...config.resolve,
308
314
  extensions: [...(config?.resolve?.extensions ?? []), ...extensions],
315
+ extensionAlias: {
316
+ ...(config.resolve?.extensionAlias ?? {}),
317
+ ...extensionAlias,
318
+ },
309
319
  alias: {
310
320
  ...(config.resolve?.alias ?? {}),
311
321
  ...(options.fileReplacements?.reduce((aliases, replacement) => ({
@@ -1,4 +1,5 @@
1
1
  import { type ProjectGraph } from '@nx/devkit';
2
+ export declare function createAllowlistFromExports(packageName: string, exports: Record<string, any> | string | undefined): (string | RegExp)[];
2
3
  /**
3
4
  * Get all non-buildable libraries in the project graph for a given project.
4
5
  * This function retrieves all direct and transitive dependencies of a project,
@@ -7,4 +8,4 @@ import { type ProjectGraph } from '@nx/devkit';
7
8
  * @param projectName The project name to get dependencies for
8
9
  * @returns A list of all non-buildable libraries that the project depends on, including transitive dependencies.
9
10
  */
10
- export declare function getNonBuildableLibs(graph: ProjectGraph, projectName: string): string[];
11
+ export declare function getNonBuildableLibs(graph: ProjectGraph, projectName: string): (string | RegExp)[];
@@ -1,8 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAllowlistFromExports = createAllowlistFromExports;
3
4
  exports.getNonBuildableLibs = getNonBuildableLibs;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const path_1 = require("path");
4
7
  const get_transitive_deps_1 = require("./get-transitive-deps");
5
8
  const is_lib_buildable_1 = require("./is-lib-buildable");
9
+ function escapePackageName(packageName) {
10
+ return packageName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
11
+ }
12
+ function escapeRegexAndConvertWildcard(pattern) {
13
+ return pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*');
14
+ }
15
+ function resolveConditionalExport(target) {
16
+ if (typeof target === 'string') {
17
+ return target;
18
+ }
19
+ if (typeof target === 'object' && target !== null) {
20
+ // Priority order for conditions
21
+ const conditions = ['development', 'import', 'require', 'default'];
22
+ for (const condition of conditions) {
23
+ if (target[condition] && typeof target[condition] === 'string') {
24
+ return target[condition];
25
+ }
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ function createAllowlistFromExports(packageName, exports) {
31
+ if (!exports) {
32
+ return [packageName];
33
+ }
34
+ const allowlist = [];
35
+ allowlist.push(packageName);
36
+ if (typeof exports === 'string') {
37
+ return allowlist;
38
+ }
39
+ if (typeof exports === 'object') {
40
+ for (const [exportPath, target] of Object.entries(exports)) {
41
+ if (typeof exportPath !== 'string')
42
+ continue;
43
+ const resolvedTarget = resolveConditionalExport(target);
44
+ if (!resolvedTarget)
45
+ continue;
46
+ if (exportPath === '.') {
47
+ continue;
48
+ }
49
+ else if (exportPath.startsWith('./')) {
50
+ const subpath = exportPath.slice(2);
51
+ if (subpath.includes('*')) {
52
+ const regexPattern = escapeRegexAndConvertWildcard(subpath);
53
+ allowlist.push(new RegExp(`^${escapePackageName(packageName)}/${regexPattern}$`));
54
+ }
55
+ else {
56
+ allowlist.push(`${packageName}/${subpath}`);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return allowlist;
62
+ }
6
63
  /**
7
64
  * Get all non-buildable libraries in the project graph for a given project.
8
65
  * This function retrieves all direct and transitive dependencies of a project,
@@ -24,11 +81,32 @@ function getNonBuildableLibs(graph, projectName) {
24
81
  return false;
25
82
  return !(0, is_lib_buildable_1.isBuildableLibrary)(node);
26
83
  });
27
- // Add direct non-buildable dependencies
84
+ // Add direct non-buildable dependencies with expanded export patterns
28
85
  for (const dep of directNonBuildable) {
29
- const packageName = graph.nodes?.[dep.target]?.data?.metadata?.js?.packageName;
86
+ const node = graph.nodes?.[dep.target];
87
+ const packageName = node?.data?.metadata?.js?.packageName;
30
88
  if (packageName) {
31
- allNonBuildable.add(packageName);
89
+ // Get exports from project metadata first (most reliable)
90
+ const packageExports = node?.data?.metadata?.js?.packageExports;
91
+ if (packageExports) {
92
+ // Use metadata exports if available
93
+ const allowlistPatterns = createAllowlistFromExports(packageName, packageExports);
94
+ allowlistPatterns.forEach((pattern) => allNonBuildable.add(pattern));
95
+ }
96
+ else {
97
+ // Fallback: try to read package.json directly
98
+ try {
99
+ const projectRoot = node.data.root;
100
+ const packageJsonPath = (0, path_1.join)(projectRoot, 'package.json');
101
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
102
+ const allowlistPatterns = createAllowlistFromExports(packageName, packageJson.exports);
103
+ allowlistPatterns.forEach((pattern) => allNonBuildable.add(pattern));
104
+ }
105
+ catch (error) {
106
+ // Final fallback: just add base package name
107
+ allNonBuildable.add(packageName);
108
+ }
109
+ }
32
110
  }
33
111
  // Get all transitive non-buildable dependencies App -> library1 -> library2
34
112
  const transitiveDeps = (0, get_transitive_deps_1.getAllTransitiveDeps)(graph, dep.target);
@@ -52,6 +52,34 @@ function normalizeOptions(options) {
52
52
  if (!combinedPluginAndMaybeExecutorOptions.main) {
53
53
  throw new Error(`Missing "main" option for the entry file. Set this option in your Nx rspack plugin.`);
54
54
  }
55
+ // Normalize typeCheck and skipTypeChecking options
56
+ let normalizedTypeCheck;
57
+ let normalizedSkipTypeChecking;
58
+ if (combinedPluginAndMaybeExecutorOptions.typeCheck !== undefined &&
59
+ combinedPluginAndMaybeExecutorOptions.skipTypeChecking !== undefined) {
60
+ // Both options are provided - use typeCheck as the source of truth
61
+ normalizedTypeCheck = combinedPluginAndMaybeExecutorOptions.typeCheck;
62
+ normalizedSkipTypeChecking =
63
+ !combinedPluginAndMaybeExecutorOptions.typeCheck;
64
+ }
65
+ else if (combinedPluginAndMaybeExecutorOptions.typeCheck !== undefined) {
66
+ // Only typeCheck is provided
67
+ normalizedTypeCheck = combinedPluginAndMaybeExecutorOptions.typeCheck;
68
+ normalizedSkipTypeChecking =
69
+ !combinedPluginAndMaybeExecutorOptions.typeCheck;
70
+ }
71
+ else if (combinedPluginAndMaybeExecutorOptions.skipTypeChecking !== undefined) {
72
+ // Only skipTypeChecking is provided
73
+ normalizedSkipTypeChecking =
74
+ combinedPluginAndMaybeExecutorOptions.skipTypeChecking;
75
+ normalizedTypeCheck =
76
+ !combinedPluginAndMaybeExecutorOptions.skipTypeChecking;
77
+ }
78
+ else {
79
+ // Neither option is provided - use defaults
80
+ normalizedTypeCheck = true;
81
+ normalizedSkipTypeChecking = false;
82
+ }
55
83
  return {
56
84
  ...combinedPluginAndMaybeExecutorOptions,
57
85
  assets: combinedPluginAndMaybeExecutorOptions.assets
@@ -81,12 +109,14 @@ function normalizeOptions(options) {
81
109
  sassImplementation: combinedPluginAndMaybeExecutorOptions.sassImplementation ??
82
110
  'sass-embedded',
83
111
  scripts: combinedPluginAndMaybeExecutorOptions.scripts ?? [],
112
+ skipTypeChecking: normalizedSkipTypeChecking,
84
113
  sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
85
114
  sourceRoot,
86
115
  styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
87
116
  subresourceIntegrity: combinedPluginAndMaybeExecutorOptions.subresourceIntegrity ?? false,
88
117
  target: combinedPluginAndMaybeExecutorOptions.target ?? 'web',
89
118
  targetName,
119
+ typeCheck: normalizedTypeCheck,
90
120
  vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,
91
121
  };
92
122
  }
@@ -16,9 +16,8 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
16
16
  async function readRspackOptions(rspackConfig) {
17
17
  const configs = [];
18
18
  const resolveConfig = async (config) => {
19
- let resolvedConfig;
20
19
  if ((0, config_1.isNxRspackComposablePlugin)(config)) {
21
- resolvedConfig = await config({}, {
20
+ return await config({}, {
22
21
  // These values are only used during build-time, so passing stubs here just to read out
23
22
  // the returned config object.
24
23
  options: {