@nx/webpack 21.2.1 → 21.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "21.2.1",
3
+ "version": "21.2.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.1",
70
- "@nx/js": "21.2.1"
69
+ "@nx/devkit": "21.2.3",
70
+ "@nx/js": "21.2.3"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webpackExecutor = webpackExecutor;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
6
+ const js_1 = require("@nx/js");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
+ const path_1 = require("path");
6
9
  const rxjs_1 = require("rxjs");
7
10
  const operators_1 = require("rxjs/operators");
8
- const path_1 = require("path");
9
- const run_webpack_1 = require("./lib/run-webpack");
11
+ const config_1 = require("../../utils/config");
10
12
  const fs_1 = require("../../utils/fs");
11
13
  const resolve_user_defined_webpack_config_1 = require("../../utils/webpack/resolve-user-defined-webpack-config");
12
14
  const normalize_options_1 = require("./lib/normalize-options");
13
- const config_1 = require("../../utils/config");
14
- const js_1 = require("@nx/js");
15
+ const run_webpack_1 = require("./lib/run-webpack");
15
16
  async function getWebpackConfigs(options, context) {
16
17
  let userDefinedWebpackConfig = null;
17
18
  if (options.webpackConfig) {
@@ -49,7 +50,7 @@ async function* webpackExecutor(_options, context) {
49
50
  // Default to production build.
50
51
  process.env['NODE_ENV'] ||= 'production';
51
52
  const metadata = context.projectsConfigurations.projects[context.projectName];
52
- const sourceRoot = metadata.sourceRoot;
53
+ const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(metadata);
53
54
  const options = (0, normalize_options_1.normalizeOptions)(_options, context.root, metadata.root, sourceRoot);
54
55
  const isScriptOptimizeOn = typeof options.optimization === 'boolean'
55
56
  ? options.optimization
@@ -71,8 +71,28 @@ function applyNxIndependentConfig(options, config) {
71
71
  options.sourceMap === true ? 'source-map' : options.sourceMap;
72
72
  config.output = {
73
73
  ...config.output,
74
- libraryTarget: config.output?.libraryTarget ??
75
- (options.target === 'node' ? 'commonjs' : undefined),
74
+ libraryTarget: (() => {
75
+ const existingOutputConfig = config.output;
76
+ const existingLibraryTarget = existingOutputConfig?.libraryTarget;
77
+ const existingLibraryType = typeof existingOutputConfig?.library === 'object' &&
78
+ 'type' in existingOutputConfig?.library
79
+ ? existingOutputConfig?.library?.type
80
+ : undefined;
81
+ // If user is using modern library.type, don't set the deprecated libraryTarget
82
+ if (existingLibraryType !== undefined) {
83
+ return undefined;
84
+ }
85
+ // If user has set libraryTarget explicitly, use it
86
+ if (existingLibraryTarget !== undefined) {
87
+ return existingLibraryTarget;
88
+ }
89
+ // Set defaults based on target when user hasn't configured anything
90
+ if (options.target === 'node')
91
+ return 'commonjs';
92
+ if (options.target === 'async-node')
93
+ return 'commonjs-module';
94
+ return undefined;
95
+ })(),
76
96
  path: config.output?.path ??
77
97
  (options.outputPath
78
98
  ? // If path is relative, it is relative from project root (aka cwd).
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = normalizeOptions;
4
4
  exports.normalizeAssets = normalizeAssets;
5
5
  exports.normalizeFileReplacements = normalizeFileReplacements;
6
- const path_1 = require("path");
7
- const fs_1 = require("fs");
8
6
  const devkit_1 = require("@nx/devkit");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
9
10
  function normalizeOptions(options) {
10
11
  const combinedPluginAndMaybeExecutorOptions = {};
11
12
  const isProd = process.env.NODE_ENV === 'production';
@@ -48,10 +49,7 @@ function normalizeOptions(options) {
48
49
  // executor options take precedence (especially for overriding with CLI args)
49
50
  originalTargetOptions);
50
51
  }
51
- const sourceRoot = projectNode.data.sourceRoot ??
52
- ((0, fs_1.existsSync)((0, path_1.join)(devkit_1.workspaceRoot, projectNode.data.root, 'src'))
53
- ? (0, path_1.join)(projectNode.data.root, 'src')
54
- : projectNode.data.root);
52
+ const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data);
55
53
  if (!combinedPluginAndMaybeExecutorOptions.main) {
56
54
  throw new Error(`Missing "main" option for the entry file. Set this option in your Nx webpack plugin.`);
57
55
  }
@@ -5,6 +5,7 @@ exports.isNxWebpackComposablePlugin = isNxWebpackComposablePlugin;
5
5
  exports.composePlugins = composePlugins;
6
6
  exports.composePluginsSync = composePluginsSync;
7
7
  const devkit_1 = require("@nx/devkit");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
9
  const configuration_1 = require("nx/src/config/configuration");
9
10
  exports.nxWebpackComposablePlugin = 'nxWebpackComposablePlugin';
10
11
  function isNxWebpackComposablePlugin(a) {
@@ -49,7 +50,7 @@ function ensureNxWebpackExecutionContext(ctx) {
49
50
  ctx.options ??= {
50
51
  root: devkit_1.workspaceRoot,
51
52
  projectRoot: projectNode.data.root,
52
- sourceRoot: projectNode.data.sourceRoot ?? projectNode.data.root,
53
+ sourceRoot: (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data),
53
54
  // These aren't actually needed since NxWebpackPlugin and withNx both support them being undefined.
54
55
  assets: undefined,
55
56
  outputPath: undefined,