@nx/webpack 0.0.0-pr-30516-4c8bfff → 0.0.0-pr-30457-d91a68c

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/migrations.json CHANGED
@@ -44,6 +44,19 @@
44
44
  "alwaysAddToPackageJson": false
45
45
  }
46
46
  }
47
+ },
48
+ "20.7.1": {
49
+ "version": "20.7.1-beta.0",
50
+ "packages": {
51
+ "webpack": {
52
+ "version": "^5.98.0",
53
+ "alwaysAddToPackageJson": false
54
+ },
55
+ "webpack-dev-server": {
56
+ "version": "^5.2.1",
57
+ "alwaysAddToPackageJson": false
58
+ }
59
+ }
47
60
  }
48
61
  }
49
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "0.0.0-pr-30516-4c8bfff",
3
+ "version": "0.0.0-pr-30457-d91a68c",
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": {
@@ -62,12 +62,12 @@
62
62
  "ts-loader": "^9.3.1",
63
63
  "tsconfig-paths-webpack-plugin": "4.0.0",
64
64
  "tslib": "^2.3.0",
65
- "webpack": "^5.80.0",
66
- "webpack-dev-server": "^5.0.4",
65
+ "webpack": "^5.98.0",
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": "0.0.0-pr-30516-4c8bfff",
70
- "@nx/js": "0.0.0-pr-30516-4c8bfff"
69
+ "@nx/devkit": "0.0.0-pr-30457-d91a68c",
70
+ "@nx/js": "0.0.0-pr-30457-d91a68c"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -156,7 +156,10 @@ function extractDevServerOptions(options, context) {
156
156
  return devServerOptions;
157
157
  }
158
158
  function applyDefaults(options, buildOptions) {
159
- if (options.port === undefined) {
159
+ if (!options) {
160
+ options = {};
161
+ }
162
+ if (options?.port === undefined) {
160
163
  options.port = 4200;
161
164
  }
162
165
  options.headers = { 'Access-Control-Allow-Origin': '*' };
@@ -15,10 +15,15 @@ const compiler_loaders_1 = require("./compiler-loaders");
15
15
  const TerserPlugin = require("terser-webpack-plugin");
16
16
  const nodeExternals = require("webpack-node-externals");
17
17
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
18
+ const utils_1 = require("./utils");
18
19
  const IGNORED_WEBPACK_WARNINGS = [
19
20
  /The comment file/i,
20
21
  /could not find any license/i,
21
22
  ];
23
+ const extensionAlias = {
24
+ '.js': ['.ts', '.js'],
25
+ '.mjs': ['.mts', '.mjs'],
26
+ };
22
27
  const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
23
28
  const mainFields = ['module', 'main'];
24
29
  function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
@@ -183,8 +188,11 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
183
188
  if (options.useTsconfigPaths) {
184
189
  plugins.push(new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ ...options, tsConfig }));
185
190
  }
186
- // New TS Solution already has a typecheck target
187
- if (!options?.skipTypeChecking && !isUsingTsSolution) {
191
+ // New TS Solution already has a typecheck target but allow it to run during serve
192
+ if ((!options?.skipTypeChecking && !isUsingTsSolution) ||
193
+ (isUsingTsSolution &&
194
+ options?.skipTypeChecking === false &&
195
+ process.env['WEBPACK_SERVE'])) {
188
196
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
189
197
  plugins.push(new ForkTsCheckerWebpackPlugin({
190
198
  typescript: {
@@ -271,7 +279,31 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
271
279
  const externals = [];
272
280
  if (options.target === 'node' && options.externalDependencies === 'all') {
273
281
  const modulesDir = `${options.root}/node_modules`;
274
- externals.push(nodeExternals({ modulesDir }));
282
+ const graph = options.projectGraph;
283
+ const projectName = options.projectName;
284
+ const deps = graph?.dependencies?.[projectName] ?? [];
285
+ // Collect non-buildable TS project references so that they are bundled
286
+ // 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.
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)
305
+ : [];
306
+ externals.push(nodeExternals({ modulesDir, allowlist: nonBuildableWorkspaceLibs }));
275
307
  }
276
308
  else if (Array.isArray(options.externalDependencies)) {
277
309
  externals.push(function (ctx, callback) {
@@ -286,6 +318,10 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
286
318
  config.resolve = {
287
319
  ...config.resolve,
288
320
  extensions: [...(config?.resolve?.extensions ?? []), ...extensions],
321
+ extensionAlias: {
322
+ ...(config.resolve?.extensionAlias ?? {}),
323
+ ...extensionAlias,
324
+ },
289
325
  alias: {
290
326
  ...(config.resolve?.alias ?? {}),
291
327
  ...(options.fileReplacements?.reduce((aliases, replacement) => ({
@@ -34,7 +34,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
34
34
  sri: options.subresourceIntegrity,
35
35
  outputPath: path.basename(options.index),
36
36
  indexPath: path.join(options.root, options.index),
37
- baseHref: options.baseHref,
37
+ baseHref: options.baseHref !== false ? options.baseHref : undefined,
38
38
  deployUrl: options.deployUrl,
39
39
  scripts: options.scripts,
40
40
  styles: options.styles,
@@ -24,6 +24,8 @@ export declare function createLoaderFromCompiler(options: NormalizedNxAppWebpack
24
24
  tsx: boolean;
25
25
  };
26
26
  transform: {
27
+ legacyDecorator: boolean;
28
+ decoratorMetadata: boolean;
27
29
  react: {
28
30
  runtime: string;
29
31
  };
@@ -18,6 +18,8 @@ function createLoaderFromCompiler(options) {
18
18
  tsx: true,
19
19
  },
20
20
  transform: {
21
+ legacyDecorator: true,
22
+ decoratorMetadata: true,
21
23
  react: {
22
24
  runtime: 'automatic',
23
25
  },
@@ -98,7 +98,7 @@ function postcssOptionsCreator(options, { includePaths, forCssModules = false, }
98
98
  ? []
99
99
  : [
100
100
  (0, postcss_cli_resources_1.PostcssCliResources)({
101
- baseHref: options.baseHref,
101
+ baseHref: options.baseHref ? options.baseHref : undefined,
102
102
  deployUrl: options.deployUrl,
103
103
  loader,
104
104
  filename: `[name]${hashFormat.file}.[ext]`,
@@ -0,0 +1,7 @@
1
+ import { type ProjectGraphProjectNode } from '@nx/devkit';
2
+ /**
3
+ * Check if the library is buildable.
4
+ * @param node from the project graph
5
+ * @returns boolean
6
+ */
7
+ export declare function isBuildableLibrary(node: ProjectGraphProjectNode): boolean;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBuildableLibrary = isBuildableLibrary;
4
+ function isSourceFile(path) {
5
+ return ['.ts', '.tsx', '.mts', '.cts'].some((ext) => path.endsWith(ext));
6
+ }
7
+ function isBuildableExportMap(packageExports) {
8
+ if (!packageExports || Object.keys(packageExports).length === 0) {
9
+ return false; // exports = {} → not buildable
10
+ }
11
+ const isCompiledExport = (value) => {
12
+ if (typeof value === 'string') {
13
+ return !isSourceFile(value);
14
+ }
15
+ if (typeof value === 'object' && value !== null) {
16
+ return Object.entries(value).some(([key, subValue]) => {
17
+ if (key === 'types' ||
18
+ key === 'development' ||
19
+ key === './package.json')
20
+ return false;
21
+ return typeof subValue === 'string' && !isSourceFile(subValue);
22
+ });
23
+ }
24
+ return false;
25
+ };
26
+ if (packageExports['.']) {
27
+ return isCompiledExport(packageExports['.']);
28
+ }
29
+ return Object.entries(packageExports).some(([key, value]) => key !== '.' && isCompiledExport(value));
30
+ }
31
+ /**
32
+ * Check if the library is buildable.
33
+ * @param node from the project graph
34
+ * @returns boolean
35
+ */
36
+ function isBuildableLibrary(node) {
37
+ if (!node.data.metadata?.js) {
38
+ return false;
39
+ }
40
+ const { packageExports, packageMain } = node.data.metadata.js;
41
+ // if we have exports only check this else fallback to packageMain
42
+ if (packageExports) {
43
+ return isBuildableExportMap(packageExports);
44
+ }
45
+ return (typeof packageMain === 'string' &&
46
+ packageMain !== '' &&
47
+ !isSourceFile(packageMain));
48
+ }
@@ -57,7 +57,7 @@ export interface NxAppWebpackPluginOptions {
57
57
  /**
58
58
  * Set <base href> for the resulting index.html.
59
59
  */
60
- baseHref?: string;
60
+ baseHref?: string | false;
61
61
  /**
62
62
  * Build the libraries from source. Default is `true`.
63
63
  */
@@ -73,6 +73,7 @@ export interface NxAppWebpackPluginOptions {
73
73
  crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
74
74
  /**
75
75
  * Delete the output path before building.
76
+ * @deprecated Use the `output.clean` option in Webpack. https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder
76
77
  */
77
78
  deleteOutputPath?: boolean;
78
79
  /**
@@ -29,6 +29,10 @@ class NxAppWebpackPlugin {
29
29
  if (typeof target === 'string') {
30
30
  this.options.target = target;
31
31
  }
32
+ // Prefer `clean` option from Webpack config over our own.
33
+ if (typeof compiler.options.output?.clean !== 'undefined') {
34
+ this.options.deleteOutputPath = false;
35
+ }
32
36
  (0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
33
37
  useNormalizedEntry: true,
34
38
  });