@plaudit/webpack-extensions 2.72.0 → 2.73.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.
package/build/shared.d.ts CHANGED
@@ -129,7 +129,7 @@ export declare const scriptExtension: RegExp;
129
129
  export declare const scriptWithoutModuleExtension: RegExp;
130
130
  export declare const scriptWithModuleExtension: RegExp;
131
131
  export declare const styleExtension: RegExp;
132
- export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "" | "style" | "script";
132
+ export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "style" | "script" | "";
133
133
  export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
134
134
  export declare function isScriptModuleField(field: string): field is 'scriptModule' | 'viewScriptModule';
135
135
  export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
@@ -147,4 +147,6 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
147
147
  export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
148
148
  export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
149
149
  export declare function emitPHPWriterAsAsset(writer: PHPWriter, compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
150
+ export declare function dedent(text: TemplateStringsArray): string;
151
+ export declare function resolveLegacyBlockScriptsInFolder(folder: string): string[];
150
152
  export {};
package/build/shared.js CHANGED
@@ -25,7 +25,11 @@ exports.newWebpackErrorForFile = newWebpackErrorForFile;
25
25
  exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
26
26
  exports.getAssetsJson = getAssetsJson;
27
27
  exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
28
+ exports.dedent = dedent;
29
+ exports.resolveLegacyBlockScriptsInFolder = resolveLegacyBlockScriptsInFolder;
30
+ const node_fs_1 = __importDefault(require("node:fs"));
28
31
  const promises_1 = __importDefault(require("node:fs/promises"));
32
+ const node_path_1 = __importDefault(require("node:path"));
29
33
  const php_writer_1 = require("@plaudit/php-writer");
30
34
  const expressions_1 = require("@plaudit/php-writer/expressions");
31
35
  const webpack_1 = require("webpack");
@@ -183,3 +187,25 @@ function emitPHPWriterAsAsset(writer, compilation, file, assetInfo) {
183
187
  const contents = writer.toString() + "\n";
184
188
  compilation[file in compilation.assets ? 'updateAsset' : 'emitAsset'](file, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents), ...assetInfo });
185
189
  }
190
+ function dedent(text) {
191
+ const actualText = text.join("\n");
192
+ const firstLineIndent = actualText.split("\r?\n").find(line => line.length > 0)?.match(/^\s+/)?.[0];
193
+ if (!firstLineIndent) {
194
+ return actualText;
195
+ }
196
+ return actualText.replaceAll(new RegExp("^" + firstLineIndent, 'mg'), "").replace(/\n{2}$/, "\n");
197
+ }
198
+ function resolveLegacyBlockScriptsInFolder(folder) {
199
+ const blockScriptEntrypoints = [];
200
+ for (const blockDir of node_fs_1.default.readdirSync(folder)) {
201
+ const fullBlockDir = node_path_1.default.join(folder, blockDir);
202
+ const packageJSON = node_path_1.default.join(fullBlockDir, 'package.json');
203
+ if (node_fs_1.default.existsSync(packageJSON)) {
204
+ const main = JSON.parse(node_fs_1.default.readFileSync(packageJSON, 'utf8'))['main'];
205
+ if (main && node_fs_1.default.existsSync(node_path_1.default.join(fullBlockDir, main))) {
206
+ blockScriptEntrypoints.push(node_path_1.default.join(fullBlockDir, main));
207
+ }
208
+ }
209
+ }
210
+ return blockScriptEntrypoints;
211
+ }
@@ -22,24 +22,9 @@ const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin")
22
22
  const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
23
23
  const static_configs_1 = require("./plugins/static-configs");
24
24
  const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
25
- const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
26
25
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
27
26
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
28
27
  const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
29
- function resolveLegacyBlockScriptsInFolder(folder) {
30
- const blockScriptEntrypoints = [];
31
- for (const blockDir of node_fs_1.default.readdirSync(folder)) {
32
- const fullBlockDir = node_path_1.default.join(folder, blockDir);
33
- const packageJSON = node_path_1.default.join(fullBlockDir, 'package.json');
34
- if (node_fs_1.default.existsSync(packageJSON)) {
35
- const main = JSON.parse(node_fs_1.default.readFileSync(packageJSON, 'utf8'))['main'];
36
- if (main && node_fs_1.default.existsSync(node_path_1.default.join(fullBlockDir, main))) {
37
- blockScriptEntrypoints.push(node_path_1.default.join(fullBlockDir, main));
38
- }
39
- }
40
- }
41
- return blockScriptEntrypoints;
42
- }
43
28
  function testForDuplicatedEntryPaths(sources) {
44
29
  const seenPaths = (0, common_config_helpers_1.groupEntrypointsByAssetFile)(Array.isArray(sources)
45
30
  ? sources.map(s => typeof s === 'string' ? s : s[1].destination)
@@ -400,10 +385,16 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
400
385
  plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config));
401
386
  }
402
387
  plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
403
- const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
388
+ // We have to use constructor.name here the version desyncs can result in multiple equivalent versions kicking around
389
+ const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin.constructor.name === 'DependencyExtractionWebpackPlugin');
404
390
  if (dependencyExtractionPluginIndex === -1) {
405
- console.error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
406
- throw new Error();
391
+ console.error((0, shared_1.dedent) `
392
+ Unable to find the DependencyExtractionWebpackPlugin.
393
+ If this is your first time seeing this error, please run: pnpm up && pnpm dedupe && pnpm up
394
+ Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.
395
+ `);
396
+ console.error("Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.");
397
+ throw new Error("Cannot apply externals when they have been disabled via CLI flag. This will greatly increase bundle size and will likely cause the build to fail");
407
398
  }
408
399
  const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, assumeGlobalizedPlauditLibraries, true, externalize);
409
400
  plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
@@ -461,7 +452,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
461
452
  const { processingModules, scriptExtension } = commonConfig;
462
453
  const allSrcRoots = sources.map(([src, dest]) => {
463
454
  const srcRoots = (dest.withLegacyBlocksIn
464
- ? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
455
+ ? [...src.split(','), ...(0, shared_1.resolveLegacyBlockScriptsInFolder)(node_path_1.default.join(config.srcDir, dest.withLegacyBlocksIn))]
465
456
  : src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === shared_1.scriptWithModuleExtension.test(s));
466
457
  const srcRoot = srcRoots.length < 2 ? (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), src) : srcRoots.map(s => (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(process.cwd(), s));
467
458
  const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot, { throwIfNoEntry: false })?.isDirectory();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.72.0",
3
+ "version": "2.73.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
@@ -20,9 +20,9 @@
20
20
  }
21
21
  },
22
22
  "devDependencies": {
23
- "@plaudit/gutenberg-api-extensions": "^2.77.2",
23
+ "@plaudit/gutenberg-api-extensions": "^2.78.1",
24
24
  "@types/browser-sync-webpack-plugin": "^2.2.5",
25
- "@types/node": "^24.7.2",
25
+ "@types/node": "^24.9.2",
26
26
  "@types/postcss-functions": "^4.0.4",
27
27
  "@types/tapable": "^2.3.0",
28
28
  "@types/webpack": "^5.28.5",
@@ -34,14 +34,14 @@
34
34
  "webpack-bundle-analyzer": "^4.10.2"
35
35
  },
36
36
  "dependencies": {
37
- "@plaudit/php-writer": "^1.0.0",
37
+ "@plaudit/php-writer": "^1.2.3",
38
38
  "@plaudit/postcss-color-function": "^5.0.0",
39
39
  "@plaudit/postcss-legacy-shorthand": "^1.0.0",
40
40
  "@plaudit/postcss-silent-extend": "^3.0.0",
41
41
  "@plaudit/postcss-strip-units": "^3.0.0",
42
42
  "@plaudit/postcss-variables": "^1.1.0",
43
- "@wordpress/dependency-extraction-webpack-plugin": "^6.32.0",
44
- "@wordpress/scripts": "^30.25.0",
43
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.34.0",
44
+ "@wordpress/scripts": "^30.27.0",
45
45
  "autoprefixer": "^10.4.21",
46
46
  "browser-sync": "^3.0.4",
47
47
  "copy-webpack-plugin": "^10.2.4",