@plaudit/webpack-extensions 2.5.1 → 2.5.2

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.
@@ -96,7 +96,7 @@ function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts) {
96
96
  }
97
97
  entry[potentialKey] = entrypoint[1];
98
98
  }
99
- module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
99
+ function testForDuplicatedEntryPaths(config) {
100
100
  const seenPaths = groupEntrypointsByAssetFile(Array.isArray(config.src) ? config.src : Object.values(config.src).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
101
101
  let projectPrefix = undefined;
102
102
  let duplicatedPaths = "";
@@ -120,7 +120,8 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
120
120
  console.error(`Encountered multiple paths that produce the same effective bundle name:${duplicatedPaths}`);
121
121
  process.exit(1);
122
122
  }
123
- 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;
123
+ }
124
+ function disableDefaultURLProcessing(webpackConfig) {
124
125
  const cssLoader = require.resolve('css-loader');
125
126
  if (cssLoader && webpackConfig.module?.rules) {
126
127
  for (const rule of webpackConfig.module.rules) {
@@ -133,16 +134,11 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
133
134
  }
134
135
  }
135
136
  }
136
- let currentEntrypoint = '';
137
+ }
138
+ function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
137
139
  if (webpackConfig.module?.rules) {
138
140
  const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, (name) => {
139
- if (variables[name]) {
140
- return variables[name];
141
- }
142
- if (name === 'ENV') { // This is purely a backwards-compatibility issue.
143
- return currentEntrypoint.endsWith('public.pcss') ? 'PUBLIC' : (currentEntrypoint.endsWith('block-editor.pcss') ? 'EDITOR' : '');
144
- }
145
- return undefined;
141
+ return variables[name] ?? (name === 'ENV' ? '' : undefined);
146
142
  });
147
143
  for (const rule of webpackConfig.module.rules) {
148
144
  if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
@@ -164,10 +160,40 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
164
160
  }
165
161
  }
166
162
  }
163
+ }
164
+ function parseEntrypointsJSON(dir) {
165
+ const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
166
+ if (Array.isArray(entrypointsJSON)) {
167
+ return mapToRealEntrypoints(entrypointsJSON, dir);
168
+ }
169
+ else {
170
+ return Object.entries(entrypointsJSON).map(([name, config]) => {
171
+ if (typeof config === 'string') {
172
+ return [name, joinPossiblyAbsolutePaths(dir, config)];
173
+ }
174
+ else if (Array.isArray(config)) {
175
+ return [name, config.map(c => joinPossiblyAbsolutePaths(dir, c))];
176
+ }
177
+ else {
178
+ if (typeof config.import === 'string') {
179
+ config.import = joinPossiblyAbsolutePaths(dir, config.import);
180
+ }
181
+ else {
182
+ config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
183
+ }
184
+ return [name, config];
185
+ }
186
+ });
187
+ }
188
+ }
189
+ module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
190
+ 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
+ disableDefaultURLProcessing(webpackConfig);
193
+ injectPostcssConfigOverrides(webpackConfig, variables, verbose);
167
194
  let first = true;
168
195
  const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
169
196
  return sources.map(([src, dest]) => {
170
- currentEntrypoint = src;
171
197
  const srcRoots = typeof dest !== 'string' && dest.withLegacyBlocksIn
172
198
  ? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
173
199
  : src.split(',');
@@ -184,7 +210,10 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
184
210
  syntactic: true,
185
211
  }
186
212
  }
187
- }), new webpack_remove_empty_scripts_1.default({ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS, extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'] }));
213
+ }), new webpack_remove_empty_scripts_1.default({
214
+ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
215
+ extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
216
+ }));
188
217
  if (copyFiles) {
189
218
  plugins.push(new BlockJSONStyleRemappingPlugin_1.default(standaloneBlocks));
190
219
  }
@@ -224,29 +253,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
224
253
  }
225
254
  catch (e) {
226
255
  try {
227
- const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
228
- if (Array.isArray(entrypointsJSON)) {
229
- res.push(...mapToRealEntrypoints(entrypointsJSON, dir));
230
- }
231
- else {
232
- for (const [name, config] of Object.entries(entrypointsJSON)) {
233
- if (typeof config === 'string') {
234
- res.push([name, joinPossiblyAbsolutePaths(dir, config)]);
235
- }
236
- else if (Array.isArray(config)) {
237
- res.push([name, config.map(c => joinPossiblyAbsolutePaths(dir, c))]);
238
- }
239
- else {
240
- if (typeof config.import === 'string') {
241
- config.import = joinPossiblyAbsolutePaths(dir, config.import);
242
- }
243
- else {
244
- config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
245
- }
246
- res.push([name, config]);
247
- }
248
- }
249
- }
256
+ res.push(...parseEntrypointsJSON(dir));
250
257
  }
251
258
  catch (e) {
252
259
  // This just means that the directory doesn't contain any declared entrypoints.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",