@plaudit/webpack-extensions 2.76.0 → 2.76.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.
@@ -13,7 +13,7 @@ type CollatedWorkableBlockInfo = Record<string, {
13
13
  workableBlockEntrypointsInfo: WorkableBlockEntrypointInfo[];
14
14
  blockJsonText?: string;
15
15
  }>;
16
- export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
16
+ export declare class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
17
17
  private readonly dest;
18
18
  private readonly webpackRemoveEmptyScriptsPlugin;
19
19
  private static readonly semaphore;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PlainEntrypointsStyleBlockJSONPlugin = void 0;
6
+ exports.EnhancedBlockJSONPlugin = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
8
  const promises_1 = __importDefault(require("node:fs/promises"));
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
@@ -15,12 +15,12 @@ const expressions_1 = require("@plaudit/php-writer/expressions");
15
15
  const shared_1 = require("../shared");
16
16
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
17
17
  const webpack_1 = require("webpack");
18
- class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
18
+ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
19
19
  dest;
20
20
  webpackRemoveEmptyScriptsPlugin;
21
21
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Block JSON v3");
22
22
  constructor(config, dest, webpackRemoveEmptyScriptsPlugin, context, entry) {
23
- super(config, `block-json-${dest.destination}`, [PlainEntrypointsStyleBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
+ super(config, `block-json-${dest.destination}`, [EnhancedBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
24
24
  this.dest = dest;
25
25
  this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
26
26
  }
@@ -37,7 +37,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
37
37
  //TODO: Can we guarantee that entrypoint.name is always non-null?
38
38
  const epBlockJson = entrypoint.name + ".json";
39
39
  if (!applicableBlockJsonFiles[epBlockJson]) {
40
- const blockJsonText = PlainEntrypointsStyleBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
40
+ const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson)
41
41
  ?? await promises_1.default.readFile(srcPath, 'utf-8');
42
42
  if (!blockJsonText) {
43
43
  compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
@@ -85,7 +85,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
85
85
  }
86
86
  }
87
87
  }
88
- PlainEntrypointsStyleBlockJSONPlugin.semaphore.resolve(this.id, {
88
+ EnhancedBlockJSONPlugin.semaphore.resolve(this.id, {
89
89
  collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
90
90
  emittingWpmlXml: compilation.getAsset(node_path_1.default.join(this.dest.destination, "wpml-config.xml")) !== undefined
91
91
  });
@@ -146,9 +146,9 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
146
146
  const outputDir = node_path_1.default.join(compilation.compiler.outputPath, node_path_1.default.dirname(blockJsonAssetName));
147
147
  const blockJson = JSON.parse(blockJsonText);
148
148
  const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
149
- PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
150
- PlainEntrypointsStyleBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
151
- const hashForVersion = PlainEntrypointsStyleBlockJSONPlugin
149
+ EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
150
+ EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
151
+ const hashForVersion = EnhancedBlockJSONPlugin
152
152
  .hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
153
153
  if (blockJson["version"]) {
154
154
  blockJson["version"] = `${blockJson["version"]}-${hashForVersion}`;
@@ -156,20 +156,20 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
156
156
  else {
157
157
  blockJson["version"] = hashForVersion;
158
158
  }
159
- PlainEntrypointsStyleBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
159
+ EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
160
160
  const blockDirName = node_path_1.default.dirname(node_path_1.default.relative(this.dest.destination, blockJsonAssetName));
161
- blockData[blockDirName] = PlainEntrypointsStyleBlockJSONPlugin
161
+ blockData[blockDirName] = EnhancedBlockJSONPlugin
162
162
  .doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
163
- compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(PlainEntrypointsStyleBlockJSONPlugin
163
+ compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(EnhancedBlockJSONPlugin
164
164
  .doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, epi => "file:./" + node_path_1.default.relative(blockDirName, epi.outputPath)), undefined, " ")));
165
165
  }
166
166
  return {
167
167
  __metadata: {
168
168
  version: 3,
169
169
  "wpml-config": emittingWpmlXml,
170
- scriptHandles: Object.fromEntries(PlainEntrypointsStyleBlockJSONPlugin
170
+ scriptHandles: Object.fromEntries(EnhancedBlockJSONPlugin
171
171
  .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && !(0, shared_1.isScriptModuleField)(hd.entrypointField)))),
172
- scriptModuleHandles: Object.fromEntries(PlainEntrypointsStyleBlockJSONPlugin
172
+ scriptModuleHandles: Object.fromEntries(EnhancedBlockJSONPlugin
173
173
  .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
174
174
  styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
175
175
  .map(hd => {
@@ -250,7 +250,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
250
250
  });
251
251
  }
252
252
  static findRelativeRouteBetween(path1, path2) {
253
- const commonAncestor = PlainEntrypointsStyleBlockJSONPlugin.findCommonAncestor(path1, path2);
253
+ const commonAncestor = EnhancedBlockJSONPlugin.findCommonAncestor(path1, path2);
254
254
  const route = Array(path1.split(node_path_1.default.sep).length - commonAncestor.length).fill("..");
255
255
  route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
256
256
  return route.join(node_path_1.default.sep);
@@ -286,11 +286,11 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
286
286
  }
287
287
  const mappedFiles = pathsNeedRemapping
288
288
  ? rawFiles
289
- .map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, PlainEntrypointsStyleBlockJSONPlugin.stripFilePrefix(p))))
289
+ .map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
290
290
  .filter(p => node_fs_1.default.existsSync(p))
291
- .map(p => `file:./${PlainEntrypointsStyleBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
291
+ .map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
292
292
  : rawFiles
293
- .filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, PlainEntrypointsStyleBlockJSONPlugin.stripFilePrefix(p)))));
293
+ .filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
294
294
  if (mappedFiles.length === 0) {
295
295
  if (deleteOnEmpty && rawValue !== undefined) {
296
296
  delete (inPlaudit ? blockJson["plaudit"] : blockJson)[key];
@@ -326,11 +326,11 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
326
326
  : [`${blockName.substring(blockName.indexOf('/') + 1)}.php`, "template.php", "template.twig"]);
327
327
  const renderTemplate = pathsNeedRemapping
328
328
  ? rawRenderTemplate
329
- .map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, PlainEntrypointsStyleBlockJSONPlugin.stripFilePrefix(p))))
329
+ .map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
330
330
  .filter(p => node_fs_1.default.existsSync(p))
331
- .map(p => `file:./${PlainEntrypointsStyleBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
331
+ .map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
332
332
  : rawRenderTemplate
333
- .filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, PlainEntrypointsStyleBlockJSONPlugin.stripFilePrefix(p)))));
333
+ .filter(p => node_fs_1.default.existsSync(node_path_1.default.normalize(node_path_1.default.join(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
334
334
  if (renderTemplate.length === 0) {
335
335
  delete blockJson["render_template"];
336
336
  delete blockJson["render"];
@@ -359,7 +359,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
359
359
  }
360
360
  attachUniquePhase(compilation) {
361
361
  compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
362
- const allSemaphoreData = (await PlainEntrypointsStyleBlockJSONPlugin.semaphore.wait())
362
+ const allSemaphoreData = (await EnhancedBlockJSONPlugin.semaphore.wait())
363
363
  .reduce((acc, cur) => {
364
364
  (acc[cur.blocksDest] ?? (acc[cur.blocksDest] = [])).push(cur);
365
365
  return acc;
@@ -432,4 +432,4 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
432
432
  }));
433
433
  }
434
434
  }
435
- exports.PlainEntrypointsStyleBlockJSONPlugin = PlainEntrypointsStyleBlockJSONPlugin;
435
+ exports.EnhancedBlockJSONPlugin = EnhancedBlockJSONPlugin;
@@ -1,7 +1,9 @@
1
+ import { Compilation } from "webpack";
1
2
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
2
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
4
+ import { ParsedAssetJsonProvider } from "../shared";
3
5
  export declare class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin {
4
6
  constructor(config: VerifiedPlauditWordpressWebpackConfig, context: string, entry: EntryProvider);
5
7
  protected attachUniquePhase(): void;
6
- protected processAssets(): void;
8
+ protected processAssets(compilation: Compilation, parsedAssetJsonProvider: ParsedAssetJsonProvider): void;
7
9
  }
@@ -7,6 +7,8 @@ class EnhancedDynamicEntryPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.A
7
7
  super(config, `enhanced-dynamic-entries`, [], context, entry);
8
8
  }
9
9
  attachUniquePhase() { }
10
- processAssets() { }
10
+ processAssets(compilation, parsedAssetJsonProvider) {
11
+ this.extractRelevantAssetData(compilation, parsedAssetJsonProvider);
12
+ }
11
13
  }
12
14
  exports.EnhancedDynamicEntryPlugin = EnhancedDynamicEntryPlugin;
@@ -48,12 +48,13 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
48
48
  });
49
49
  const staticallyLoadedEntrypoints = new Set(groupedLoaderInfo.flatMap(lig => lig.staticallyLoadedEntrypoints));
50
50
  for (const [file, assetData] of Object.entries((0, shared_1.getAssetsJson)(compilation))) {
51
- if (staticallyLoadedEntrypoints.has(file)) {
51
+ if (staticallyLoadedEntrypoints.has(file) || staticallyLoadedEntrypoints.has(file.replace(/\.css$/, '.js')) || staticallyLoadedEntrypoints.has(file.replace(/\.js$/, '.css'))) {
52
52
  continue;
53
53
  }
54
54
  const parsedPath = node_path_1.default.parse(file);
55
55
  const contents = `<?php return ${(0, php_writer_1.json2php)(assetData)};\n`;
56
- compilation.emitAsset(node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php", new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
56
+ const assetName = node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php";
57
+ compilation[assetName in compilation.assets ? 'updateAsset' : 'emitAsset'](assetName, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
57
58
  }
58
59
  if (this.config.useUnifiedLoader) {
59
60
  compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
@@ -16,7 +16,7 @@ const ExtensionsConfigFileGeneratorPluginV1_1 = require("./plugins/ExtensionsCon
16
16
  const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
17
17
  const PackageConfigSanityChecker_1 = require("./plugins/PackageConfigSanityChecker");
18
18
  const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./plugins/PlainEntrypointsConfigFileGeneratorPlugin");
19
- const PlainEntrypointsStyleBlockJSONPlugin_1 = require("./plugins/PlainEntrypointsStyleBlockJSONPlugin");
19
+ const EnhancedBlockJSONPlugin_1 = require("./plugins/EnhancedBlockJSONPlugin");
20
20
  const SpecialAssetHandlingPlugin_1 = require("./plugins/SpecialAssetHandlingPlugin");
21
21
  const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin");
22
22
  const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
@@ -479,7 +479,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
479
479
  if (!srcIsDirectory) {
480
480
  continue;
481
481
  }
482
- plugin = new PlainEntrypointsStyleBlockJSONPlugin_1.PlainEntrypointsStyleBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
482
+ plugin = new EnhancedBlockJSONPlugin_1.EnhancedBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
483
483
  plugins.push(plugin);
484
484
  if (config.processTranslationConfigs && !processingModules) {
485
485
  plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.76.0",
3
+ "version": "2.76.2",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"