@nx/webpack 21.2.0-beta.2 → 21.2.0-beta.4

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": "21.2.0-beta.2",
3
+ "version": "21.2.0-beta.4",
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": {
@@ -66,8 +66,8 @@
66
66
  "webpack-dev-server": "^5.2.1",
67
67
  "webpack-node-externals": "^3.0.0",
68
68
  "webpack-subresource-integrity": "^5.1.0",
69
- "@nx/devkit": "21.2.0-beta.2",
70
- "@nx/js": "21.2.0-beta.2"
69
+ "@nx/devkit": "21.2.0-beta.4",
70
+ "@nx/js": "21.2.0-beta.4"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -21,8 +21,10 @@ const IGNORED_WEBPACK_WARNINGS = [
21
21
  /could not find any license/i,
22
22
  ];
23
23
  const extensionAlias = {
24
- '.js': ['.ts', '.js'],
24
+ '.js': ['.ts', '.tsx', '.js', '.jsx'],
25
25
  '.mjs': ['.mts', '.mjs'],
26
+ '.cjs': ['.cts', '.cjs'],
27
+ '.jsx': ['.tsx', '.jsx'],
26
28
  };
27
29
  const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
28
30
  const mainFields = ['module', 'main'];
@@ -1,4 +1,5 @@
1
1
  import type { ProjectGraph, ProjectGraphProjectNode } from '@nx/devkit';
2
+ export declare function createAllowlistFromExports(packageName: string, exports: Record<string, any> | string | undefined): (string | RegExp)[];
2
3
  /**
3
4
  * Check if the library is buildable.
4
5
  * @param node from the project graph
@@ -22,4 +23,4 @@ export declare function getAllTransitiveDeps(graph: ProjectGraph, targetName: st
22
23
  * @param projectName The project name to get dependencies for
23
24
  * @returns A list of all non-buildable libraries that the project depends on, including transitive dependencies.
24
25
  */
25
- export declare function getNonBuildableLibs(graph: ProjectGraph, projectName: string): string[];
26
+ 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.isBuildableLibrary = isBuildableLibrary;
4
5
  exports.getAllTransitiveDeps = getAllTransitiveDeps;
5
6
  exports.getNonBuildableLibs = getNonBuildableLibs;
7
+ const devkit_1 = require("@nx/devkit");
8
+ const path_1 = require("path");
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
  function isSourceFile(path) {
7
64
  return ['.ts', '.tsx', '.mts', '.cts'].some((ext) => path.endsWith(ext));
8
65
  }
@@ -109,11 +166,32 @@ function getNonBuildableLibs(graph, projectName) {
109
166
  return false;
110
167
  return !isBuildableLibrary(node);
111
168
  });
112
- // Add direct non-buildable dependencies
169
+ // Add direct non-buildable dependencies with expanded export patterns
113
170
  for (const dep of directNonBuildable) {
114
- const packageName = graph.nodes?.[dep.target]?.data?.metadata?.js?.packageName;
171
+ const node = graph.nodes?.[dep.target];
172
+ const packageName = node?.data?.metadata?.js?.packageName;
115
173
  if (packageName) {
116
- allNonBuildable.add(packageName);
174
+ // Get exports from project metadata first (most reliable)
175
+ const packageExports = node?.data?.metadata?.js?.packageExports;
176
+ if (packageExports) {
177
+ // Use metadata exports if available
178
+ const allowlistPatterns = createAllowlistFromExports(packageName, packageExports);
179
+ allowlistPatterns.forEach((pattern) => allNonBuildable.add(pattern));
180
+ }
181
+ else {
182
+ // Fallback: try to read package.json directly
183
+ try {
184
+ const projectRoot = node.data.root;
185
+ const packageJsonPath = (0, path_1.join)(projectRoot, 'package.json');
186
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
187
+ const allowlistPatterns = createAllowlistFromExports(packageName, packageJson.exports);
188
+ allowlistPatterns.forEach((pattern) => allNonBuildable.add(pattern));
189
+ }
190
+ catch (error) {
191
+ // Final fallback: just add base package name
192
+ allNonBuildable.add(packageName);
193
+ }
194
+ }
117
195
  }
118
196
  // Get all transitive non-buildable dependencies App -> library1 -> library2
119
197
  const transitiveDeps = getAllTransitiveDeps(graph, dep.target);