@nx/webpack 21.2.0-beta.1 → 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/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # Nx: Smart Repos · Fast Builds
24
24
 
25
- Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
25
+ An AI-first build platform that connects everything from your editor to CI. Helping you deliver fast, without breaking things.
26
26
 
27
27
  This package is a [Webpack plugin for Nx](https://nx.dev/nx-api/webpack).
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "21.2.0-beta.1",
3
+ "version": "21.2.0-beta.3",
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.1",
70
- "@nx/js": "21.2.0-beta.1"
69
+ "@nx/devkit": "21.2.0-beta.3",
70
+ "@nx/js": "21.2.0-beta.3"
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'];
@@ -281,27 +283,11 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
281
283
  const modulesDir = `${options.root}/node_modules`;
282
284
  const graph = options.projectGraph;
283
285
  const projectName = options.projectName;
284
- const deps = graph?.dependencies?.[projectName] ?? [];
285
286
  // Collect non-buildable TS project references so that they are bundled
286
287
  // in the final output. This is needed for projects that are not buildable
287
- // but are referenced by buildable projects. This is needed for the new TS
288
- // solution setup.
288
+ // but are referenced by buildable projects.
289
289
  const nonBuildableWorkspaceLibs = isUsingTsSolution
290
- ? deps
291
- .filter((dep) => {
292
- const node = graph.nodes?.[dep.target];
293
- if (!node || node.type !== 'lib')
294
- return false;
295
- const hasBuildTarget = 'build' in (node.data?.targets ?? {});
296
- if (hasBuildTarget) {
297
- return false;
298
- }
299
- // If there is no build target we check the package exports to see if they reference
300
- // source files
301
- return !(0, utils_1.isBuildableLibrary)(node);
302
- })
303
- .map((dep) => graph.nodes?.[dep.target]?.data?.metadata?.js?.packageName)
304
- .filter((name) => !!name)
290
+ ? (0, utils_1.getNonBuildableLibs)(graph, projectName)
305
291
  : [];
306
292
  externals.push(nodeExternals({ modulesDir, allowlist: nonBuildableWorkspaceLibs }));
307
293
  }
@@ -1,7 +1,26 @@
1
- import { type ProjectGraphProjectNode } from '@nx/devkit';
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
5
6
  * @returns boolean
6
7
  */
7
8
  export declare function isBuildableLibrary(node: ProjectGraphProjectNode): boolean;
9
+ /**
10
+ * Get all transitive dependencies of a target that are non-buildable libraries.
11
+ * This function traverses the project graph to find all dependencies of a given target,
12
+ * @param graph Graph of the project
13
+ * @param targetName The project name to get dependencies for
14
+ * @param visited Set to keep track of visited nodes to prevent infinite loops in circular dependencies
15
+ * @returns string[] - List of all transitive dependencies that are non-buildable libraries
16
+ */
17
+ export declare function getAllTransitiveDeps(graph: ProjectGraph, targetName: string, visited?: Set<string>): string[];
18
+ /**
19
+ * Get all non-buildable libraries in the project graph for a given project.
20
+ * This function retrieves all direct and transitive dependencies of a project,
21
+ * filtering out only those that are libraries and not buildable.
22
+ * @param graph Project graph
23
+ * @param projectName The project name to get dependencies for
24
+ * @returns A list of all non-buildable libraries that the project depends on, including transitive dependencies.
25
+ */
26
+ export declare function getNonBuildableLibs(graph: ProjectGraph, projectName: string): (string | RegExp)[];
@@ -1,6 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAllowlistFromExports = createAllowlistFromExports;
3
4
  exports.isBuildableLibrary = isBuildableLibrary;
5
+ exports.getAllTransitiveDeps = getAllTransitiveDeps;
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
+ }
4
63
  function isSourceFile(path) {
5
64
  return ['.ts', '.tsx', '.mts', '.cts'].some((ext) => path.endsWith(ext));
6
65
  }
@@ -46,3 +105,97 @@ function isBuildableLibrary(node) {
46
105
  packageMain !== '' &&
47
106
  !isSourceFile(packageMain));
48
107
  }
108
+ /**
109
+ * Get all transitive dependencies of a target that are non-buildable libraries.
110
+ * This function traverses the project graph to find all dependencies of a given target,
111
+ * @param graph Graph of the project
112
+ * @param targetName The project name to get dependencies for
113
+ * @param visited Set to keep track of visited nodes to prevent infinite loops in circular dependencies
114
+ * @returns string[] - List of all transitive dependencies that are non-buildable libraries
115
+ */
116
+ function getAllTransitiveDeps(graph, targetName, visited = new Set()) {
117
+ if (visited.has(targetName)) {
118
+ return [];
119
+ }
120
+ visited.add(targetName);
121
+ const node = graph.nodes?.[targetName];
122
+ if (!node) {
123
+ return [];
124
+ }
125
+ // Get direct dependencies of this target
126
+ const directDeps = graph.dependencies?.[targetName] || [];
127
+ const transitiveDeps = [];
128
+ for (const dep of directDeps) {
129
+ const depNode = graph.nodes?.[dep.target];
130
+ // Only consider library dependencies
131
+ if (!depNode || depNode.type !== 'lib') {
132
+ continue;
133
+ }
134
+ // Check if this dependency is non-buildable
135
+ const hasBuildTarget = 'build' in (depNode.data?.targets ?? {});
136
+ const isBuildable = hasBuildTarget || isBuildableLibrary(depNode);
137
+ if (!isBuildable) {
138
+ const packageName = depNode.data?.metadata?.js?.packageName;
139
+ if (packageName) {
140
+ transitiveDeps.push(packageName);
141
+ }
142
+ const nestedDeps = getAllTransitiveDeps(graph, dep.target, visited);
143
+ transitiveDeps.push(...nestedDeps);
144
+ }
145
+ }
146
+ return transitiveDeps;
147
+ }
148
+ /**
149
+ * Get all non-buildable libraries in the project graph for a given project.
150
+ * This function retrieves all direct and transitive dependencies of a project,
151
+ * filtering out only those that are libraries and not buildable.
152
+ * @param graph Project graph
153
+ * @param projectName The project name to get dependencies for
154
+ * @returns A list of all non-buildable libraries that the project depends on, including transitive dependencies.
155
+ */
156
+ function getNonBuildableLibs(graph, projectName) {
157
+ const deps = graph?.dependencies?.[projectName] ?? [];
158
+ const allNonBuildable = new Set();
159
+ // First, find all direct non-buildable deps and add them App -> library
160
+ const directNonBuildable = deps.filter((dep) => {
161
+ const node = graph.nodes?.[dep.target];
162
+ if (!node || node.type !== 'lib')
163
+ return false;
164
+ const hasBuildTarget = 'build' in (node.data?.targets ?? {});
165
+ if (hasBuildTarget)
166
+ return false;
167
+ return !isBuildableLibrary(node);
168
+ });
169
+ // Add direct non-buildable dependencies with expanded export patterns
170
+ for (const dep of directNonBuildable) {
171
+ const node = graph.nodes?.[dep.target];
172
+ const packageName = node?.data?.metadata?.js?.packageName;
173
+ if (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
+ }
195
+ }
196
+ // Get all transitive non-buildable dependencies App -> library1 -> library2
197
+ const transitiveDeps = getAllTransitiveDeps(graph, dep.target);
198
+ transitiveDeps.forEach((pkg) => allNonBuildable.add(pkg));
199
+ }
200
+ return Array.from(allNonBuildable);
201
+ }