@plaudit/webpack-extensions 2.6.0 → 2.7.0

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.
@@ -0,0 +1,6 @@
1
+ import type { Compiler, WebpackPluginInstance } from "webpack";
2
+ export default class VariablesJSMonitorPlugin implements WebpackPluginInstance {
3
+ private readonly variablesFilePath;
4
+ constructor(variablesFilePath: string);
5
+ apply(compiler: Compiler): void;
6
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class VariablesJSMonitorPlugin {
4
+ variablesFilePath;
5
+ constructor(variablesFilePath) {
6
+ this.variablesFilePath = variablesFilePath;
7
+ }
8
+ apply(compiler) {
9
+ compiler.hooks.make.tap('VariablesJSMonitorPlugin', compilation => {
10
+ if (!compilation.fileDependencies.has(this.variablesFilePath)) {
11
+ compilation.fileDependencies.add(this.variablesFilePath);
12
+ }
13
+ });
14
+ }
15
+ }
16
+ exports.default = VariablesJSMonitorPlugin;
@@ -9,6 +9,7 @@ interface PlauditWordpressWebpackConfig {
9
9
  variables?: Record<string, any>;
10
10
  verbose?: boolean;
11
11
  src: string[] | Record<string, string | AdvancedOutputConfig>;
12
+ stats?: Configuration['stats'];
12
13
  }
13
14
  declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration) => Configuration[];
14
15
  export = _default;
@@ -11,6 +11,7 @@ const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webp
11
11
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
12
12
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
13
13
  const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
14
+ const VariablesJSMonitorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/VariablesJSMonitorPlugin"));
14
15
  function joinPossiblyAbsolutePaths(...paths) {
15
16
  return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
16
17
  }
@@ -138,7 +139,7 @@ function disableDefaultURLProcessing(webpackConfig) {
138
139
  function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
139
140
  if (webpackConfig.module?.rules) {
140
141
  const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, (name) => {
141
- return variables[name] ?? (name === 'ENV' ? '' : undefined);
142
+ return variables(name) ?? (name === 'ENV' ? '' : undefined);
142
143
  });
143
144
  for (const rule of webpackConfig.module.rules) {
144
145
  if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
@@ -188,9 +189,14 @@ function parseEntrypointsJSON(dir) {
188
189
  }
189
190
  module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
190
191
  testForDuplicatedEntryPaths(config);
191
- const { standaloneBlocks = false, variables = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p)).map(p => require(p))[0] ?? {}, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
192
+ const { standaloneBlocks = false, variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
193
+ let variablesFilePath = undefined;
194
+ let currentVariables = rawVariables ?? {};
195
+ if (!rawVariables) {
196
+ variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p))[0];
197
+ }
192
198
  disableDefaultURLProcessing(webpackConfig);
193
- injectPostcssConfigOverrides(webpackConfig, variables, verbose);
199
+ injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
194
200
  let first = true;
195
201
  const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
196
202
  return sources.map(([src, dest]) => {
@@ -214,6 +220,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
214
220
  stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
215
221
  extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
216
222
  }));
223
+ if (variablesFilePath) {
224
+ plugins.push(new VariablesJSMonitorPlugin_1.default(variablesFilePath));
225
+ }
217
226
  if (copyFiles) {
218
227
  plugins.push(new BlockJSONStyleRemappingPlugin_1.default(standaloneBlocks));
219
228
  }
@@ -281,9 +290,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
281
290
  }
282
291
  else {
283
292
  const baseDest = node_path_1.default.basename(destPath);
284
- entry = {
293
+ entry = () => ({
285
294
  [baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
286
- };
295
+ });
287
296
  }
288
297
  return {
289
298
  ...webpackConfig,
@@ -293,6 +302,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
293
302
  ...webpackConfig.output,
294
303
  path: joinPossiblyAbsolutePaths(process.cwd(), srcIsDirectory ? destPath : node_path_1.default.dirname(destPath))
295
304
  },
305
+ stats: config.stats ?? 'errors-warnings',
296
306
  plugins: copyFiles
297
307
  ? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
298
308
  ? new copy_webpack_plugin_1.default({ patterns: [{ from: standaloneBlocks ? '**/(block.json|*.(php|twig|svg))' : '**/(block.json|*.(asset\.php|svg))',
@@ -301,7 +311,13 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
301
311
  : (srcIsDirectory
302
312
  ? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
303
313
  : plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
304
- entry
314
+ entry() {
315
+ if (variablesFilePath) {
316
+ delete require.cache[require.resolve(variablesFilePath)];
317
+ currentVariables = require(variablesFilePath);
318
+ }
319
+ return entry();
320
+ }
305
321
  };
306
322
  });
307
323
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",
@@ -14,9 +14,9 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/browser-sync-webpack-plugin": "^2.2.2",
17
- "@types/node": "^20.3.2",
18
- "@types/tapable": "^2.2.3",
19
- "@types/webpack": "^5.28.1",
17
+ "@types/node": "^20.5.3",
18
+ "@types/tapable": "^2.2.4",
19
+ "@types/webpack": "^5.28.2",
20
20
  "@types/webpack-sources": "^3.2.0",
21
21
  "postcss-load-config": "^4.0.1",
22
22
  "postcss-loader": "^7.3.3",
@@ -28,18 +28,19 @@
28
28
  "@plaudit/postcss-silent-extend": "^3.0.0",
29
29
  "@plaudit/postcss-strip-units": "^3.0.0",
30
30
  "@plaudit/postcss-variables": "^1.0.0",
31
- "@wordpress/scripts": "^26.7.0",
32
- "autoprefixer": "^10.4.14",
31
+ "@wordpress/scripts": "^26.11.0",
32
+ "autoprefixer": "^10.4.15",
33
33
  "browser-sync": "^2.29.3",
34
34
  "browser-sync-webpack-plugin": "^2.3.0",
35
35
  "clean-webpack-plugin": "^4.0.0",
36
36
  "copy-webpack-plugin": "^11.0.0",
37
37
  "cssnano": "^6.0.1",
38
- "eslint": "^8.43.0",
39
- "eslint-plugin-jsdoc": "^43.1.1",
38
+ "eslint": "^8.47.0",
39
+ "eslint-plugin-jsdoc": "^46.5.0",
40
40
  "fork-ts-checker-webpack-plugin": "^8.0.0",
41
- "postcss": "^8.4.25",
41
+ "postcss": "^8.4.28",
42
42
  "postcss-calc": "^9.0.1",
43
+ "postcss-discard-comments": "^6.0.0",
43
44
  "postcss-fallback": "^0.1.0",
44
45
  "postcss-functions": "^4.0.2",
45
46
  "postcss-import": "^15.1.0",
@@ -57,10 +58,7 @@
57
58
  "postcss-url": "^10.1.3",
58
59
  "react": "^18.2.0",
59
60
  "react-dom": "^18.2.0",
60
- "webpack": "^5.88.1",
61
+ "webpack": "^5.88.2",
61
62
  "webpack-remove-empty-scripts": "^1.0.3"
62
- },
63
- "resolutions": {
64
- "eslint-plugin-jsdoc": "^43.1.1"
65
63
  }
66
64
  }