@nx/webpack 16.8.0-beta.3 → 16.8.0-beta.5

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostcssCliResources = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const loader_utils_1 = require("loader-utils");
6
5
  const path = require("path");
7
6
  const url = require("node:url");
@@ -16,21 +15,19 @@ function wrapUrl(url) {
16
15
  }
17
16
  return `url(${wrappedUrl})`;
18
17
  }
19
- function resolve(file, base, resolver) {
20
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
- try {
22
- return yield resolver(`./${file}`, base);
23
- }
24
- catch (_a) {
25
- return resolver(file, base);
26
- }
27
- });
18
+ async function resolve(file, base, resolver) {
19
+ try {
20
+ return await resolver(`./${file}`, base);
21
+ }
22
+ catch {
23
+ return resolver(file, base);
24
+ }
28
25
  }
29
26
  module.exports.postcss = true;
30
27
  function PostcssCliResources(options) {
31
28
  const { deployUrl = '', baseHref = '', resourcesOutputPath = '', rebaseRootRelative = false, filename, loader, } = options;
32
29
  const dedupeSlashes = (url) => url.replace(/\/\/+/g, '/');
33
- const process = (inputUrl, context, resourceCache) => tslib_1.__awaiter(this, void 0, void 0, function* () {
30
+ const process = async (inputUrl, context, resourceCache) => {
34
31
  // If root-relative, absolute or protocol relative url, leave as is
35
32
  if (/^((?:\w+:)?\/\/|data:|chrome:|#)/.test(inputUrl)) {
36
33
  return inputUrl;
@@ -80,7 +77,7 @@ function PostcssCliResources(options) {
80
77
  resolve(result);
81
78
  });
82
79
  });
83
- const result = yield resolve(pathname, context, resolver);
80
+ const result = await resolve(pathname, context, resolver);
84
81
  return new Promise((resolve, reject) => {
85
82
  loader.fs.readFile(result, (err, content) => {
86
83
  if (err) {
@@ -105,7 +102,7 @@ function PostcssCliResources(options) {
105
102
  resolve(outputUrl);
106
103
  });
107
104
  });
108
- });
105
+ };
109
106
  return {
110
107
  postcssPlugin: 'postcss-cli-resources',
111
108
  Once(root) {
@@ -123,7 +120,7 @@ function PostcssCliResources(options) {
123
120
  return;
124
121
  }
125
122
  const resourceCache = new Map();
126
- return Promise.all(urlDeclarations.map((decl) => tslib_1.__awaiter(this, void 0, void 0, function* () {
123
+ return Promise.all(urlDeclarations.map(async (decl) => {
127
124
  const value = decl.value;
128
125
  const urlRegex = /url\(\s*(?:"([^"]+)"|'([^']+)'|(.+?))\s*\)/g;
129
126
  const segments = [];
@@ -138,7 +135,7 @@ function PostcssCliResources(options) {
138
135
  const originalUrl = match[1] || match[2] || match[3];
139
136
  let processedUrl;
140
137
  try {
141
- processedUrl = yield process(originalUrl, context, resourceCache);
138
+ processedUrl = await process(originalUrl, context, resourceCache);
142
139
  }
143
140
  catch (err) {
144
141
  loader.emitError(decl.error(err.message, { word: originalUrl }));
@@ -162,7 +159,7 @@ function PostcssCliResources(options) {
162
159
  if (modified) {
163
160
  decl.value = segments.join('');
164
161
  }
165
- })));
162
+ }));
166
163
  },
167
164
  };
168
165
  }
@@ -21,13 +21,12 @@ class ScriptsWebpackPlugin {
21
21
  this.options = options;
22
22
  }
23
23
  shouldSkip(compilation, scripts) {
24
- var _a;
25
24
  if (this._lastBuildTime == undefined) {
26
25
  this._lastBuildTime = Date.now();
27
26
  return false;
28
27
  }
29
28
  for (let i = 0; i < scripts.length; i++) {
30
- const scriptTime = (_a = compilation.fileTimestamps) === null || _a === void 0 ? void 0 : _a.get(scripts[i]);
29
+ const scriptTime = compilation.fileTimestamps?.get(scripts[i]);
31
30
  if (!scriptTime || scriptTime > this._lastBuildTime) {
32
31
  this._lastBuildTime = Date.now();
33
32
  return false;
@@ -57,11 +57,10 @@ const processed = new Set();
57
57
  */
58
58
  function withNx(pluginOptions) {
59
59
  return function configure(config, { options, context, }) {
60
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
61
60
  if (processed.has(config))
62
61
  return config;
63
62
  const plugins = [];
64
- if (!(pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.skipTypeChecking)) {
63
+ if (!pluginOptions?.skipTypeChecking) {
65
64
  plugins.push(new ForkTsCheckerWebpackPlugin({
66
65
  typescript: {
67
66
  configFile: options.tsConfig,
@@ -131,9 +130,14 @@ function withNx(pluginOptions) {
131
130
  const chunkFilename = options.outputHashing
132
131
  ? `[name]${hashFormat.chunk}.js`
133
132
  : '[name].js';
134
- const updated = Object.assign(Object.assign({}, config), { context: context
133
+ const updated = {
134
+ ...config,
135
+ context: context
135
136
  ? path.join(context.root, options.projectRoot)
136
- : undefined, target: options.target, node: false, mode:
137
+ : undefined,
138
+ target: options.target,
139
+ node: false,
140
+ mode:
137
141
  // When the target is Node avoid any optimizations, such as replacing `process.env.NODE_ENV` with build time value.
138
142
  options.target === 'node'
139
143
  ? 'none'
@@ -148,27 +152,55 @@ function withNx(pluginOptions) {
148
152
  process.env.NODE_ENV === 'development' ||
149
153
  process.env.NODE_ENV === 'production'
150
154
  ? process.env.NODE_ENV
151
- : 'none', devtool: options.sourceMap === 'hidden'
155
+ : 'none',
156
+ devtool: options.sourceMap === 'hidden'
152
157
  ? 'hidden-source-map'
153
158
  : options.sourceMap
154
159
  ? 'source-map'
155
- : false, entry, output: Object.assign(Object.assign({}, config.output), { libraryTarget: options.target === 'node' ? 'commonjs' : undefined, path: options.outputPath, filename,
156
- chunkFilename, hashFunction: 'xxhash64',
160
+ : false,
161
+ entry,
162
+ output: {
163
+ ...config.output,
164
+ libraryTarget: options.target === 'node' ? 'commonjs' : undefined,
165
+ path: options.outputPath,
166
+ filename,
167
+ chunkFilename,
168
+ hashFunction: 'xxhash64',
157
169
  // Disabled for performance
158
- pathinfo: false,
170
+ pathinfo: false,
159
171
  // Use CJS for Node since it has the widest support.
160
- scriptType: options.target === 'node' ? undefined : 'module' }), watch: options.watch, watchOptions: {
172
+ scriptType: options.target === 'node' ? undefined : 'module',
173
+ },
174
+ watch: options.watch,
175
+ watchOptions: {
161
176
  poll: options.poll,
162
- }, profile: options.statsJson, resolve: Object.assign(Object.assign({}, config.resolve), { extensions: [...extensions, ...((_b = (_a = config === null || config === void 0 ? void 0 : config.resolve) === null || _a === void 0 ? void 0 : _a.extensions) !== null && _b !== void 0 ? _b : [])], alias: options.fileReplacements.reduce((aliases, replacement) => (Object.assign(Object.assign({}, aliases), { [replacement.replace]: replacement.with })), {}), plugins: [
163
- ...((_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.plugins) !== null && _d !== void 0 ? _d : []),
177
+ },
178
+ profile: options.statsJson,
179
+ resolve: {
180
+ ...config.resolve,
181
+ extensions: [...extensions, ...(config?.resolve?.extensions ?? [])],
182
+ alias: options.fileReplacements.reduce((aliases, replacement) => ({
183
+ ...aliases,
184
+ [replacement.replace]: replacement.with,
185
+ }), {}),
186
+ plugins: [
187
+ ...(config.resolve?.plugins ?? []),
164
188
  new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
165
189
  configFile: options.tsConfig,
166
- extensions: [...extensions, ...((_f = (_e = config === null || config === void 0 ? void 0 : config.resolve) === null || _e === void 0 ? void 0 : _e.extensions) !== null && _f !== void 0 ? _f : [])],
190
+ extensions: [...extensions, ...(config?.resolve?.extensions ?? [])],
167
191
  mainFields,
168
192
  }),
169
- ], mainFields }), externals, optimization: Object.assign(Object.assign({}, config.optimization), { sideEffects: true, minimize: typeof options.optimization === 'object'
193
+ ],
194
+ mainFields,
195
+ },
196
+ externals,
197
+ optimization: {
198
+ ...config.optimization,
199
+ sideEffects: true,
200
+ minimize: typeof options.optimization === 'object'
170
201
  ? !!options.optimization.scripts
171
- : !!options.optimization, minimizer: [
202
+ : !!options.optimization,
203
+ minimizer: [
172
204
  options.compiler !== 'swc'
173
205
  ? new TerserPlugin({
174
206
  parallel: true,
@@ -191,12 +223,24 @@ function withNx(pluginOptions) {
191
223
  mangle: false,
192
224
  },
193
225
  }),
194
- ], runtimeChunk: false, concatenateModules: true }), performance: Object.assign(Object.assign({}, config.performance), { hints: false }), experiments: Object.assign(Object.assign({}, config.experiments), { cacheUnaffected: true }), ignoreWarnings: [
226
+ ],
227
+ runtimeChunk: false,
228
+ concatenateModules: true,
229
+ },
230
+ performance: {
231
+ ...config.performance,
232
+ hints: false,
233
+ },
234
+ experiments: { ...config.experiments, cacheUnaffected: true },
235
+ ignoreWarnings: [
195
236
  (x) => IGNORED_WEBPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
196
- ], module: Object.assign(Object.assign({}, config.module), {
237
+ ],
238
+ module: {
239
+ ...config.module,
197
240
  // Enabled for performance
198
- unsafeCache: true, rules: [
199
- ...((_h = (_g = config === null || config === void 0 ? void 0 : config.module) === null || _g === void 0 ? void 0 : _g.rules) !== null && _h !== void 0 ? _h : []),
241
+ unsafeCache: true,
242
+ rules: [
243
+ ...(config?.module?.rules ?? []),
200
244
  options.sourceMap && {
201
245
  test: /\.js$/,
202
246
  enforce: 'pre',
@@ -220,7 +264,10 @@ function withNx(pluginOptions) {
220
264
  type: 'javascript/auto',
221
265
  },
222
266
  createLoaderFromCompiler(options),
223
- ].filter((r) => !!r) }), plugins: ((_j = config.plugins) !== null && _j !== void 0 ? _j : []).concat(plugins), stats: {
267
+ ].filter((r) => !!r),
268
+ },
269
+ plugins: (config.plugins ?? []).concat(plugins),
270
+ stats: {
224
271
  hash: true,
225
272
  timings: false,
226
273
  cached: false,
@@ -239,14 +286,14 @@ function withNx(pluginOptions) {
239
286
  errorDetails: !!options.verbose,
240
287
  moduleTrace: !!options.verbose,
241
288
  usedExports: !!options.verbose,
242
- } });
289
+ },
290
+ };
243
291
  processed.add(updated);
244
292
  return updated;
245
293
  };
246
294
  }
247
295
  exports.withNx = withNx;
248
296
  function createLoaderFromCompiler(options) {
249
- var _a;
250
297
  switch (options.compiler) {
251
298
  case 'swc':
252
299
  return {
@@ -299,7 +346,7 @@ function createLoaderFromCompiler(options) {
299
346
  emitDecoratorMetadata: tsConfig.options.emitDecoratorMetadata,
300
347
  isModern: true,
301
348
  isTest: process.env.NX_CYPRESS_COMPONENT_TEST === 'true',
302
- envName: (_a = process.env.BABEL_ENV) !== null && _a !== void 0 ? _a : process.env.NODE_ENV,
349
+ envName: process.env.BABEL_ENV ?? process.env.NODE_ENV,
303
350
  cacheDirectory: true,
304
351
  cacheCompression: false,
305
352
  },
@@ -24,10 +24,12 @@ const processed = new Set();
24
24
  */
25
25
  function withWeb(pluginOptions = {}) {
26
26
  return function configure(config, { options: executorOptions, context }) {
27
- var _a, _b, _c;
28
27
  if (processed.has(config))
29
28
  return config;
30
- const mergedOptions = Object.assign(Object.assign({}, executorOptions), pluginOptions);
29
+ const mergedOptions = {
30
+ ...executorOptions,
31
+ ...pluginOptions,
32
+ };
31
33
  const plugins = [];
32
34
  const stylesOptimization = typeof mergedOptions.optimization === 'object'
33
35
  ? mergedOptions.optimization.styles
@@ -66,7 +68,7 @@ function withWeb(pluginOptions = {}) {
66
68
  // Determine hashing format.
67
69
  const hashFormat = (0, hash_format_1.getOutputHashFormat)(mergedOptions.outputHashing);
68
70
  const includePaths = [];
69
- if (((_b = (_a = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths) === null || _b === void 0 ? void 0 : _b.length) > 0) {
71
+ if (mergedOptions?.stylePreprocessorOptions?.includePaths?.length > 0) {
70
72
  mergedOptions.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(mergedOptions.root, includePath)));
71
73
  }
72
74
  let lessPathOptions = {};
@@ -180,7 +182,10 @@ function withWeb(pluginOptions = {}) {
180
182
  loader: require.resolve('less-loader'),
181
183
  options: {
182
184
  sourceMap: !!mergedOptions.sourceMap,
183
- lessOptions: Object.assign({ javascriptEnabled: true }, lessPathOptions),
185
+ lessOptions: {
186
+ javascriptEnabled: true,
187
+ ...lessPathOptions,
188
+ },
184
189
  },
185
190
  },
186
191
  ],
@@ -237,7 +242,10 @@ function withWeb(pluginOptions = {}) {
237
242
  loader: require.resolve('less-loader'),
238
243
  options: {
239
244
  sourceMap: !!mergedOptions.sourceMap,
240
- lessOptions: Object.assign({ javascriptEnabled: true }, lessPathOptions),
245
+ lessOptions: {
246
+ javascriptEnabled: true,
247
+ ...lessPathOptions,
248
+ },
241
249
  },
242
250
  },
243
251
  ],
@@ -270,9 +278,12 @@ function withWeb(pluginOptions = {}) {
270
278
  new MiniCssExtractPlugin({
271
279
  filename: `[name]${hashFormat.extract}.css`,
272
280
  }));
273
- config.output = Object.assign(Object.assign({}, config.output), { crossOriginLoading: mergedOptions.subresourceIntegrity
281
+ config.output = {
282
+ ...config.output,
283
+ crossOriginLoading: mergedOptions.subresourceIntegrity
274
284
  ? 'anonymous'
275
- : false });
285
+ : false,
286
+ };
276
287
  // In case users customize their webpack config with unsupported entry.
277
288
  if (typeof config.entry === 'function')
278
289
  throw new Error('Entry function is not supported. Use an object.');
@@ -280,8 +291,14 @@ function withWeb(pluginOptions = {}) {
280
291
  throw new Error('Entry string is not supported. Use an object.');
281
292
  if (Array.isArray(config.entry))
282
293
  throw new Error('Entry array is not supported. Use an object.');
283
- config.entry = Object.assign(Object.assign({}, config.entry), entry);
284
- config.optimization = Object.assign(Object.assign({}, config.optimization), { minimizer: [...config.optimization.minimizer, ...minimizer], emitOnErrors: false, moduleIds: 'deterministic', runtimeChunk: mergedOptions.runtimeChunk ? 'single' : false, splitChunks: {
294
+ config.entry = { ...config.entry, ...entry };
295
+ config.optimization = {
296
+ ...config.optimization,
297
+ minimizer: [...config.optimization.minimizer, ...minimizer],
298
+ emitOnErrors: false,
299
+ moduleIds: 'deterministic',
300
+ runtimeChunk: mergedOptions.runtimeChunk ? 'single' : false,
301
+ splitChunks: {
285
302
  maxAsyncRequests: Infinity,
286
303
  cacheGroups: {
287
304
  default: !!mergedOptions.commonChunk && {
@@ -304,11 +321,14 @@ function withWeb(pluginOptions = {}) {
304
321
  test: /[\\/]node_modules[\\/]/,
305
322
  },
306
323
  },
307
- } });
324
+ },
325
+ };
308
326
  config.plugins.push(...plugins);
309
327
  config.resolve.mainFields = ['browser', 'module', 'main'];
310
- config.module = Object.assign(Object.assign({}, config.module), { rules: [
311
- ...((_c = config.module.rules) !== null && _c !== void 0 ? _c : []),
328
+ config.module = {
329
+ ...config.module,
330
+ rules: [
331
+ ...(config.module.rules ?? []),
312
332
  // Images: Inline small images, and emit a separate file otherwise.
313
333
  {
314
334
  test: /\.(avif|bmp|gif|ico|jpe?g|png|webp)$/,
@@ -344,7 +364,8 @@ function withWeb(pluginOptions = {}) {
344
364
  },
345
365
  },
346
366
  ...rules,
347
- ] });
367
+ ],
368
+ };
348
369
  processed.add(config);
349
370
  return config;
350
371
  };