@plaudit/webpack-extensions 3.21.2 → 4.0.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.
Files changed (279) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/USER-GUIDE.md +2 -1
  3. package/dist/api/asset-information-emission.d.ts +74 -0
  4. package/dist/api/asset-information-emission.d.ts.map +1 -0
  5. package/dist/api/asset-information-emission.js +398 -0
  6. package/dist/api/asset-information-emission.js.map +1 -0
  7. package/dist/api/configuration.d.ts +102 -0
  8. package/dist/api/configuration.d.ts.map +1 -0
  9. package/dist/api/configuration.js +83 -0
  10. package/dist/api/configuration.js.map +1 -0
  11. package/dist/api/coordinatable-emitter.d.ts +27 -0
  12. package/dist/api/coordinatable-emitter.d.ts.map +1 -0
  13. package/dist/api/coordinatable-emitter.js +20 -0
  14. package/dist/api/coordinatable-emitter.js.map +1 -0
  15. package/dist/api/entries/dependencies.d.ts +69 -0
  16. package/dist/api/entries/dependencies.d.ts.map +1 -0
  17. package/dist/api/entries/dependencies.js +61 -0
  18. package/dist/api/entries/dependencies.js.map +1 -0
  19. package/dist/api/entries/flag-logic.d.ts +37 -0
  20. package/dist/api/entries/flag-logic.d.ts.map +1 -0
  21. package/dist/api/entries/flag-logic.js +110 -0
  22. package/dist/api/entries/flag-logic.js.map +1 -0
  23. package/dist/api/entries/identifiers.d.ts +84 -0
  24. package/dist/api/entries/identifiers.d.ts.map +1 -0
  25. package/dist/api/entries/identifiers.js +590 -0
  26. package/dist/api/entries/identifiers.js.map +1 -0
  27. package/dist/api/entries/index.d.ts +6 -0
  28. package/dist/api/entries/index.d.ts.map +1 -0
  29. package/dist/{plugins → api/entries}/index.js +6 -8
  30. package/dist/api/entries/index.js.map +1 -0
  31. package/dist/api/entries/locations.d.ts +135 -0
  32. package/dist/api/entries/locations.d.ts.map +1 -0
  33. package/dist/api/entries/locations.js +174 -0
  34. package/dist/api/entries/locations.js.map +1 -0
  35. package/dist/api/entries/manager.d.ts +12 -0
  36. package/dist/api/entries/manager.d.ts.map +1 -0
  37. package/dist/api/entries/manager.js +35 -0
  38. package/dist/api/entries/manager.js.map +1 -0
  39. package/dist/api/handle-derivation.d.ts +32 -0
  40. package/dist/api/handle-derivation.d.ts.map +1 -0
  41. package/dist/api/handle-derivation.js +77 -0
  42. package/dist/api/handle-derivation.js.map +1 -0
  43. package/dist/api/index.d.ts +7 -0
  44. package/dist/api/index.d.ts.map +1 -0
  45. package/dist/api/index.js +23 -0
  46. package/dist/api/index.js.map +1 -0
  47. package/dist/api/shared-types.d.ts +86 -0
  48. package/dist/api/shared-types.d.ts.map +1 -0
  49. package/dist/api/shared-types.js +3 -0
  50. package/dist/api/shared-types.js.map +1 -0
  51. package/dist/internal-utils/auto-registering-plugins-loader.d.ts +3 -0
  52. package/dist/internal-utils/auto-registering-plugins-loader.d.ts.map +1 -0
  53. package/dist/internal-utils/auto-registering-plugins-loader.js +42 -0
  54. package/dist/internal-utils/auto-registering-plugins-loader.js.map +1 -0
  55. package/dist/internal-utils/common-config-helpers.d.ts +14 -0
  56. package/dist/internal-utils/common-config-helpers.d.ts.map +1 -0
  57. package/dist/internal-utils/common-config-helpers.js +140 -0
  58. package/dist/internal-utils/common-config-helpers.js.map +1 -0
  59. package/dist/internal-utils/entrypoint-resolution-logic.d.ts +14 -0
  60. package/dist/internal-utils/entrypoint-resolution-logic.d.ts.map +1 -0
  61. package/dist/internal-utils/entrypoint-resolution-logic.js +223 -0
  62. package/dist/internal-utils/entrypoint-resolution-logic.js.map +1 -0
  63. package/dist/internal-utils/internal-pseudo-plugin.d.ts +6 -0
  64. package/dist/internal-utils/internal-pseudo-plugin.d.ts.map +1 -0
  65. package/dist/internal-utils/internal-pseudo-plugin.js +46 -0
  66. package/dist/internal-utils/internal-pseudo-plugin.js.map +1 -0
  67. package/dist/mocks/blocks.d.ts +32 -0
  68. package/dist/mocks/blocks.d.ts.map +1 -0
  69. package/dist/mocks/blocks.js +3 -0
  70. package/dist/mocks/blocks.js.map +1 -0
  71. package/dist/mocks/index.d.ts +2 -0
  72. package/dist/mocks/index.d.ts.map +1 -0
  73. package/dist/mocks/index.js +18 -0
  74. package/dist/mocks/index.js.map +1 -0
  75. package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +4 -10
  76. package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts.map +1 -0
  77. package/dist/plugins/AdditionalDependencyInjectorPlugin.js +48 -47
  78. package/dist/plugins/AdditionalDependencyInjectorPlugin.js.map +1 -0
  79. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +1 -0
  80. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts.map +1 -0
  81. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +1 -0
  82. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js.map +1 -0
  83. package/dist/plugins/PackageConfigSanityChecker.d.ts +1 -0
  84. package/dist/plugins/PackageConfigSanityChecker.d.ts.map +1 -0
  85. package/dist/plugins/PackageConfigSanityChecker.js +1 -0
  86. package/dist/plugins/PackageConfigSanityChecker.js.map +1 -0
  87. package/dist/plugins/RootCoordinatorPluginImpl.d.ts +56 -0
  88. package/dist/plugins/RootCoordinatorPluginImpl.d.ts.map +1 -0
  89. package/dist/plugins/RootCoordinatorPluginImpl.js +767 -0
  90. package/dist/plugins/RootCoordinatorPluginImpl.js.map +1 -0
  91. package/dist/plugins/VariablesJSMonitorPlugin.d.ts +2 -1
  92. package/dist/plugins/VariablesJSMonitorPlugin.d.ts.map +1 -0
  93. package/dist/plugins/VariablesJSMonitorPlugin.js +1 -0
  94. package/dist/plugins/VariablesJSMonitorPlugin.js.map +1 -0
  95. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts +25 -0
  96. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
  97. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js +458 -0
  98. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js.map +1 -0
  99. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts +29 -0
  100. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts.map +1 -0
  101. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js +290 -0
  102. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js.map +1 -0
  103. package/dist/plugins/blocks/register.d.ts +6 -0
  104. package/dist/plugins/blocks/register.d.ts.map +1 -0
  105. package/dist/plugins/blocks/register.js +14 -0
  106. package/dist/plugins/blocks/register.js.map +1 -0
  107. package/dist/plugins/blocks/registerEmitter.d.ts +4 -0
  108. package/dist/plugins/blocks/registerEmitter.d.ts.map +1 -0
  109. package/dist/plugins/blocks/registerEmitter.js +13 -0
  110. package/dist/plugins/blocks/registerEmitter.js.map +1 -0
  111. package/dist/plugins/blocks/registerProcessor.d.ts +4 -0
  112. package/dist/plugins/blocks/registerProcessor.d.ts.map +1 -0
  113. package/dist/plugins/blocks/registerProcessor.js +46 -0
  114. package/dist/plugins/blocks/registerProcessor.js.map +1 -0
  115. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +3 -2
  116. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts.map +1 -0
  117. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +2 -1
  118. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js.map +1 -0
  119. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts +14 -0
  120. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
  121. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js +191 -0
  122. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js.map +1 -0
  123. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts +14 -0
  124. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts.map +1 -0
  125. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js +102 -0
  126. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js.map +1 -0
  127. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts +25 -0
  128. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts.map +1 -0
  129. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js +229 -0
  130. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js.map +1 -0
  131. package/dist/plugins/extensions/register.d.ts +6 -0
  132. package/dist/plugins/extensions/register.d.ts.map +1 -0
  133. package/dist/plugins/extensions/register.js +14 -0
  134. package/dist/plugins/extensions/register.js.map +1 -0
  135. package/dist/plugins/extensions/registerEmitter.d.ts +4 -0
  136. package/dist/plugins/extensions/registerEmitter.d.ts.map +1 -0
  137. package/dist/plugins/extensions/registerEmitter.js +18 -0
  138. package/dist/plugins/extensions/registerEmitter.js.map +1 -0
  139. package/dist/plugins/extensions/registerProcessor.d.ts +4 -0
  140. package/dist/plugins/extensions/registerProcessor.d.ts.map +1 -0
  141. package/dist/plugins/extensions/registerProcessor.js +42 -0
  142. package/dist/plugins/extensions/registerProcessor.js.map +1 -0
  143. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts +18 -0
  144. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts.map +1 -0
  145. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js +203 -0
  146. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js.map +1 -0
  147. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts +13 -0
  148. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts.map +1 -0
  149. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js +51 -0
  150. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js.map +1 -0
  151. package/dist/plugins/plain/register.d.ts +6 -0
  152. package/dist/plugins/plain/register.d.ts.map +1 -0
  153. package/dist/plugins/plain/register.js +14 -0
  154. package/dist/plugins/plain/register.js.map +1 -0
  155. package/dist/plugins/plain/registerEmitter.d.ts +4 -0
  156. package/dist/plugins/plain/registerEmitter.d.ts.map +1 -0
  157. package/dist/plugins/plain/registerEmitter.js +21 -0
  158. package/dist/plugins/plain/registerEmitter.js.map +1 -0
  159. package/dist/plugins/plain/registerProcessor.d.ts +4 -0
  160. package/dist/plugins/plain/registerProcessor.d.ts.map +1 -0
  161. package/dist/plugins/plain/registerProcessor.js +34 -0
  162. package/dist/plugins/plain/registerProcessor.js.map +1 -0
  163. package/dist/plugins/register.d.ts +3 -0
  164. package/dist/plugins/register.d.ts.map +1 -0
  165. package/dist/plugins/register.js +17 -0
  166. package/dist/plugins/register.js.map +1 -0
  167. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts +20 -0
  168. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts.map +1 -0
  169. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js +56 -0
  170. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js.map +1 -0
  171. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts +13 -0
  172. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts.map +1 -0
  173. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js +105 -0
  174. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js.map +1 -0
  175. package/dist/plugins/special-assets/register.d.ts +6 -0
  176. package/dist/plugins/special-assets/register.d.ts.map +1 -0
  177. package/dist/plugins/special-assets/register.js +14 -0
  178. package/dist/plugins/special-assets/register.js.map +1 -0
  179. package/dist/plugins/special-assets/registerEmitter.d.ts +4 -0
  180. package/dist/plugins/special-assets/registerEmitter.d.ts.map +1 -0
  181. package/dist/plugins/special-assets/registerEmitter.js +15 -0
  182. package/dist/plugins/special-assets/registerEmitter.js.map +1 -0
  183. package/dist/plugins/special-assets/registerProcessor.d.ts +4 -0
  184. package/dist/plugins/special-assets/registerProcessor.d.ts.map +1 -0
  185. package/dist/plugins/special-assets/registerProcessor.js +15 -0
  186. package/dist/plugins/special-assets/registerProcessor.js.map +1 -0
  187. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts +22 -0
  188. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts.map +1 -0
  189. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js +95 -0
  190. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js.map +1 -0
  191. package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts +24 -0
  192. package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts.map +1 -0
  193. package/dist/plugins/{WPMLConfigBuilder.js → wpml-config/WPMLConfigBuilder.js} +123 -53
  194. package/dist/plugins/wpml-config/WPMLConfigBuilder.js.map +1 -0
  195. package/dist/plugins/wpml-config/register.d.ts +6 -0
  196. package/dist/plugins/wpml-config/register.d.ts.map +1 -0
  197. package/dist/plugins/wpml-config/register.js +25 -0
  198. package/dist/plugins/wpml-config/register.js.map +1 -0
  199. package/dist/shared.d.ts +10 -283
  200. package/dist/shared.d.ts.map +1 -0
  201. package/dist/shared.js +32 -405
  202. package/dist/shared.js.map +1 -0
  203. package/dist/utils/error-helpers.d.ts +7 -0
  204. package/dist/utils/error-helpers.d.ts.map +1 -0
  205. package/dist/utils/error-helpers.js +73 -0
  206. package/dist/utils/error-helpers.js.map +1 -0
  207. package/dist/utils/index.d.ts +6 -0
  208. package/dist/utils/index.d.ts.map +1 -0
  209. package/dist/utils/index.js +22 -0
  210. package/dist/utils/index.js.map +1 -0
  211. package/dist/utils/misc.d.ts +4 -0
  212. package/dist/utils/misc.d.ts.map +1 -0
  213. package/dist/utils/misc.js +18 -0
  214. package/dist/utils/misc.js.map +1 -0
  215. package/dist/utils/path-helpers.d.ts +16 -0
  216. package/dist/utils/path-helpers.d.ts.map +1 -0
  217. package/dist/utils/path-helpers.js +115 -0
  218. package/dist/utils/path-helpers.js.map +1 -0
  219. package/dist/utils/pseudo-semaphore.d.ts +1 -0
  220. package/dist/utils/pseudo-semaphore.d.ts.map +1 -0
  221. package/dist/utils/pseudo-semaphore.js +3 -5
  222. package/dist/utils/pseudo-semaphore.js.map +1 -0
  223. package/dist/utils/type-helpers.d.ts +27 -0
  224. package/dist/utils/type-helpers.d.ts.map +1 -0
  225. package/dist/utils/type-helpers.js +33 -0
  226. package/dist/utils/type-helpers.js.map +1 -0
  227. package/dist/utils/writer-utils.d.ts +8 -0
  228. package/dist/utils/writer-utils.d.ts.map +1 -0
  229. package/dist/utils/writer-utils.js +35 -0
  230. package/dist/utils/writer-utils.js.map +1 -0
  231. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +2 -1
  232. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts.map +1 -0
  233. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +5 -7
  234. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js.map +1 -0
  235. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +1 -0
  236. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts.map +1 -0
  237. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +1 -0
  238. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js.map +1 -0
  239. package/dist/wordpress-scripts-wrapper.d.ts +3 -2
  240. package/dist/wordpress-scripts-wrapper.d.ts.map +1 -0
  241. package/dist/wordpress-scripts-wrapper.js +137 -391
  242. package/dist/wordpress-scripts-wrapper.js.map +1 -0
  243. package/package.json +28 -50
  244. package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +0 -25
  245. package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.js +0 -86
  246. package/dist/plugins/AbstractBiPhasicGroupPlugin.d.ts +0 -31
  247. package/dist/plugins/AbstractBiPhasicGroupPlugin.js +0 -91
  248. package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +0 -47
  249. package/dist/plugins/EnhancedBlockJSONPlugin.js +0 -657
  250. package/dist/plugins/EnhancedDynamicEntryPlugin.d.ts +0 -8
  251. package/dist/plugins/EnhancedDynamicEntryPlugin.js +0 -14
  252. package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.d.ts +0 -20
  253. package/dist/plugins/ExtensionsConfigFileGeneratorPlugin.js +0 -191
  254. package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.d.ts +0 -9
  255. package/dist/plugins/ExtensionsConfigFileGeneratorPluginV1.js +0 -45
  256. package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.d.ts +0 -6
  257. package/dist/plugins/MixableBiPhasicGroupAndEntryPlugin.js +0 -13
  258. package/dist/plugins/MixableBiPhasicGroupPlugin.d.ts +0 -6
  259. package/dist/plugins/MixableBiPhasicGroupPlugin.js +0 -13
  260. package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +0 -26
  261. package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +0 -392
  262. package/dist/plugins/SpecialAssetHandlingPlugin.d.ts +0 -12
  263. package/dist/plugins/SpecialAssetHandlingPlugin.js +0 -134
  264. package/dist/plugins/UnifiedLoaderGenerator.d.ts +0 -21
  265. package/dist/plugins/UnifiedLoaderGenerator.js +0 -144
  266. package/dist/plugins/WPMLConfigBuilder.d.ts +0 -17
  267. package/dist/plugins/index.d.ts +0 -8
  268. package/dist/plugins/static-configs.d.ts +0 -3
  269. package/dist/plugins/static-configs.js +0 -44
  270. package/dist/utils/common-config-helpers.d.ts +0 -28
  271. package/dist/utils/common-config-helpers.js +0 -489
  272. package/dist/utils/css-writer.d.ts +0 -4
  273. package/dist/utils/css-writer.js +0 -46
  274. package/dist/utils/entrypoint-resolution-logic.d.ts +0 -13
  275. package/dist/utils/entrypoint-resolution-logic.js +0 -82
  276. package/dist/utils/location-encoding-filename-parser.d.ts +0 -30
  277. package/dist/utils/location-encoding-filename-parser.js +0 -120
  278. package/dist/utils/path-query-and-related-helpers.d.ts +0 -64
  279. package/dist/utils/path-query-and-related-helpers.js +0 -269
@@ -1,657 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnhancedBlockJSONPlugin = void 0;
4
- const node_crypto_1 = require("node:crypto");
5
- const promises_1 = require("node:fs/promises");
6
- const node_fs_1 = require("node:fs");
7
- const node_path_1 = require("node:path");
8
- const php_writer_1 = require("@plaudit/php-writer");
9
- const expressions_1 = require("@plaudit/php-writer/expressions");
10
- const webpack_1 = require("webpack");
11
- const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
12
- const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
13
- const shared_1 = require("../shared");
14
- const path_query_and_related_helpers_1 = require("../utils/path-query-and-related-helpers");
15
- const pseudo_semaphore_1 = require("../utils/pseudo-semaphore");
16
- class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
17
- config;
18
- dest;
19
- webpackRemoveEmptyScriptsPlugin;
20
- static semaphore = new pseudo_semaphore_1.PseudoSemaphore("Block JSON v3");
21
- constructor(config, dest, webpackRemoveEmptyScriptsPlugin, context, entry) {
22
- super(`block-json-${dest.destination}`, [EnhancedBlockJSONPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
- this.config = config;
24
- this.dest = dest;
25
- this.webpackRemoveEmptyScriptsPlugin = webpackRemoveEmptyScriptsPlugin;
26
- }
27
- async processAssets(compilation, parsedAssetJsonProvider) {
28
- const applicableBlockJsonFiles = {};
29
- const blockJsonOriginToOutputMapping = {};
30
- const staticallyLoadedEntrypoints = [];
31
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
32
- for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
33
- staticallyLoadedEntrypoints.push(...entrypoint.getEntrypointChunk().files);
34
- if ((0, node_path_1.basename)(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
35
- continue;
36
- }
37
- const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypoint.getEntrypointChunk())][0]?.originalSource();
38
- if (asset) {
39
- const epBlockJson = entrypoint.name + ".json";
40
- if (!applicableBlockJsonFiles[epBlockJson]) {
41
- const blockJsonText = EnhancedBlockJSONPlugin.extractAssetSource(compilation, epBlockJson) ?? await (0, promises_1.readFile)(srcPath, 'utf-8');
42
- if (!blockJsonText) {
43
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`Unable to extract the source for ${epBlockJson}`, srcPath));
44
- continue;
45
- }
46
- applicableBlockJsonFiles[epBlockJson] = { sourcePath: srcPath, workableBlockEntrypointsInfo: [], blockJsonText };
47
- }
48
- blockJsonOriginToOutputMapping[srcPath] = epBlockJson;
49
- }
50
- }
51
- for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
52
- if ((0, node_path_1.basename)(srcPath).toLowerCase() === "block.json" || 'purpose' in metadata) {
53
- continue;
54
- }
55
- const entrypointChunk = entrypoint.getEntrypointChunk();
56
- const epBlockJson = entrypointChunk.auxiliaryFiles.values().find(auxFile => (0, node_path_1.basename)(auxFile) === "block.json")
57
- ?? blockJsonOriginToOutputMapping[metadata.blockJsonOrigin];
58
- if (epBlockJson) {
59
- const assetData = parsedAssetJsonProvider(entrypoint, metadata)?.assetData;
60
- if (!assetData) {
61
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`assets.json did not contain information for ${srcPath}`, srcPath));
62
- continue;
63
- }
64
- const workableBlockEntrypointsInfo = entrypoint.getFiles()
65
- .filter(file => !this.webpackRemoveEmptyScriptsPlugin['trash'].includes(file))
66
- .map(file => [file, (0, shared_1.scriptOrStyleTest)(file, shared_1.scriptExtension)])
67
- .filter((item) => item[1] !== '')
68
- .map(([file, assetType]) => {
69
- const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, metadata.enqueuingFlags, this.dest.enqueuingFlags);
70
- const { scriptArgsObject, assetMeta } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
71
- if (assetMeta?.inlinedAsset !== undefined) {
72
- staticallyLoadedEntrypoints.push(file);
73
- }
74
- const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
75
- const outputPath = this.stripOffBlocksDestPrefix(file);
76
- if (wasOriginallyAStyleField !== (assetType === "style")) { // This means that the file is extracted
77
- const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
78
- return {
79
- ...metadata, outputPath, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
80
- entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject, ...assetMeta
81
- };
82
- }
83
- return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject, ...assetMeta };
84
- });
85
- if (applicableBlockJsonFiles[epBlockJson]) {
86
- applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
87
- }
88
- else {
89
- applicableBlockJsonFiles[epBlockJson] = { sourcePath: workableBlockEntrypointsInfo[0]?.blockJsonOrigin, workableBlockEntrypointsInfo };
90
- }
91
- }
92
- }
93
- EnhancedBlockJSONPlugin.semaphore.resolve(this.id, {
94
- collatableWorkableBlockInfo: applicableBlockJsonFiles, blocksDest: this.dest.destination,
95
- emittingWpmlXml: compilation.getAsset((0, node_path_1.join)(this.dest.destination, "wpml-config.xml")) !== undefined
96
- });
97
- const generateLoader = (writer) => {
98
- writer.require((0, node_path_1.join)(this.dest.destination, "blockdir-loader.php"), { dirRelative: true, once: true });
99
- };
100
- let action;
101
- const lazyLoader = this.dest.lazyLoader;
102
- if (lazyLoader) {
103
- try {
104
- action = writer => writer.function(new expressions_1.NamespacedReference(this.config.targetNamespace, lazyLoader, 'function'), [], generateLoader, { returnType: 'void' });
105
- }
106
- catch (e) {
107
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(["An error occurred while emitting a function for lazily loading blocks", { cause: e }], this.dest.destination));
108
- this.rejectSemaphores();
109
- return;
110
- }
111
- }
112
- else {
113
- action = writer => writer.withScope(generateLoader);
114
- }
115
- UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(applicableBlockJsonFiles).length ? {
116
- group: this.group,
117
- requiresBaseURI: false,
118
- staticallyLoadedEntrypoints,
119
- action
120
- } : undefined);
121
- }
122
- emitBlockLoaderFile(compilation, blockDirConfig) {
123
- if (this.config.useUnifiedLoader) {
124
- const { '__metadata': metadata, ...blockData } = blockDirConfig;
125
- const splitOutInlinedAssets = (handles, type) => {
126
- const registerableHandles = {};
127
- const inlinedAssets = [];
128
- for (const [handle, handleData] of Object.entries(handles)) {
129
- const { inlinedAsset, ...finalizedHandle } = handleData;
130
- if (inlinedAsset !== undefined) {
131
- finalizedHandle.src = false;
132
- inlinedAssets.push([handle, type, handleData]);
133
- }
134
- registerableHandles[handle] = finalizedHandle;
135
- }
136
- return [registerableHandles, inlinedAssets];
137
- };
138
- const [finalizedScriptHandles, inlinableScripts] = splitOutInlinedAssets(metadata.scriptHandles, 'script');
139
- const [finalizedStyleHandles, inlinableStyles] = splitOutInlinedAssets(metadata.styleHandles, 'style');
140
- const finalizedMetadata = Object.fromEntries(Object.entries(metadata)
141
- .map(([key, value]) => {
142
- if (key === 'scriptHandles') {
143
- return [key, []];
144
- }
145
- if (key === 'styleHandles') {
146
- return [key, []];
147
- }
148
- if (key === 'scriptModuleHandles') {
149
- return [key, []];
150
- }
151
- return [key, value];
152
- }));
153
- const writer = new php_writer_1.PHPWriter()
154
- .action("init", writer => {
155
- const baseUriVar = new expressions_1.Var("base_uri");
156
- writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
157
- this.callRegisterFunction('script', writer, baseUriVar, Object.entries(finalizedScriptHandles));
158
- this.callRegisterFunction('style', writer, baseUriVar, Object.entries(finalizedStyleHandles));
159
- this.callRegisterFunction('script_module', writer, baseUriVar, Object.entries(metadata.scriptModuleHandles));
160
- const entries = Object.entries(metadata.bindableBlockAttributes);
161
- const supportedAttributes = new expressions_1.Var("supported_block_attributes", "?array");
162
- if ((0, shared_1.arrayIsLength)(entries, 1)) {
163
- writer.filter(`block_bindings_supported_attributes_${entries[0][0]}`, writer => {
164
- const parameters = entries[0][1];
165
- if (parameters.length === 1) {
166
- writer.appendExpr(new expressions_1.Assignment(supportedAttributes, parameters[0], true));
167
- }
168
- else {
169
- writer.call("array_push", [supportedAttributes, ...parameters]);
170
- }
171
- writer.return(supportedAttributes);
172
- }, { functionArgParameters: [supportedAttributes] });
173
- }
174
- else if (entries.length > 1) {
175
- const compiledBindingSupportingAttributes = new expressions_1.Var("compiled_binding_supporting_attributes");
176
- writer.assign(compiledBindingSupportingAttributes, metadata.bindableBlockAttributes);
177
- const blockType = new expressions_1.Var("block_type", "?string");
178
- writer.filter(`block_bindings_supported_attributes`, writer => {
179
- writer
180
- .if(expressions_1.Op.binary(expressions_1.Expr.call("empty", [blockType]), " || ", expressions_1.Expr.call("empty", [new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType)])))
181
- .return(supportedAttributes)
182
- .endIf()
183
- .call("array_push", [supportedAttributes, new expressions_1.Op("...", new expressions_1.ArrayAccess(compiledBindingSupportingAttributes, blockType))])
184
- .return(supportedAttributes);
185
- }, { functionArgParameters: [supportedAttributes, blockType], useVars: [compiledBindingSupportingAttributes] });
186
- }
187
- writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [
188
- expressions_1.Constants.__DIR__, // string $dir
189
- new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")), // array $blockdirConfig
190
- expressions_1.Constants.__FILE__, // string $blockdirConfigFile
191
- new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(finalizedMetadata, false, "\t")), // array $metadata
192
- null // ?string $urlPrefix
193
- ]);
194
- for (const inlinableScript of inlinableScripts) {
195
- (0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableScript);
196
- }
197
- for (const inlinableStyle of inlinableStyles) {
198
- (0, shared_1.appendAddInlineAssetCall)(compilation, writer, ...inlinableStyle);
199
- }
200
- }, { accountForAlreadyDoing: this.config.includePostInitFallback });
201
- if (this.config.useBlockSupportsAsThemeJsonDefaults) {
202
- const copyableBlockSupports = [];
203
- for (const { name, supports } of Object.values(blockData)) {
204
- if (typeof name === 'string' && !!name && typeof supports === 'object' && !!supports && !Array.isArray(supports)) {
205
- const flagProps = EnhancedBlockJSONPlugin.pickOutFlagPropsFromBlockSupports(supports);
206
- if (flagProps) {
207
- copyableBlockSupports.push([name, flagProps]);
208
- }
209
- }
210
- }
211
- if (copyableBlockSupports.length > 0) {
212
- const themeJsonBlockSettings = new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)({
213
- version: 3,
214
- settings: {
215
- blocks: Object.fromEntries(copyableBlockSupports)
216
- }
217
- }, false, "\t"));
218
- const theme_json = new expressions_1.Var("theme_json");
219
- writer.filter('wp_theme_json_data_blocks', writer => {
220
- const updateCall = new expressions_1.Call(expressions_1.Literal.of("update_with", true), [themeJsonBlockSettings]);
221
- writer.appendExpr(new expressions_1.InstanceAccess(theme_json, [updateCall]), { return: true });
222
- }, { functionArgParameters: [theme_json] });
223
- }
224
- }
225
- (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, (0, node_path_1.join)(this.dest.destination, "blockdir-loader.php"));
226
- }
227
- else {
228
- compilation.emitAsset((0, node_path_1.join)(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockDirConfig, true)));
229
- }
230
- }
231
- /*
232
- * The block supports that have a boolean counterpart under theme.json's settings, as
233
- * `settings key -> {support prop: settings prop}`. This is an allow-list rather than an ignore-list
234
- * because most supports (align, alignWide, anchor, contentRole, inserter, interactivity, listView,
235
- * plaudit, ...) have no theme.json settings equivalent at all, and the ones that do don't always
236
- * share a name: typography's fontSize is settings.typography.customFontSize, and Gutenberg still
237
- * ships several of these under an __experimental prefix.
238
- */
239
- static THEME_JSON_FLAG_PROPS = {
240
- color: { background: 'background', link: 'link', text: 'text' },
241
- dimensions: { aspectRatio: 'aspectRatio', minHeight: 'minHeight' },
242
- spacing: { blockGap: 'blockGap', margin: 'margin', padding: 'padding' },
243
- typography: {
244
- fontSize: 'customFontSize',
245
- lineHeight: 'lineHeight',
246
- textAlign: 'textAlign',
247
- fontStyle: 'fontStyle', __experimentalFontStyle: 'fontStyle',
248
- fontWeight: 'fontWeight', __experimentalFontWeight: 'fontWeight',
249
- letterSpacing: 'letterSpacing', __experimentalLetterSpacing: 'letterSpacing',
250
- textDecoration: 'textDecoration', __experimentalTextDecoration: 'textDecoration',
251
- textTransform: 'textTransform', __experimentalTextTransform: 'textTransform',
252
- writingMode: 'writingMode', __experimentalWritingMode: 'writingMode'
253
- }
254
- };
255
- static pickOutFlagPropsFromBlockSupports(supports) {
256
- function isRecord(value) {
257
- return typeof value === 'object' && !!value && !Array.isArray(value);
258
- }
259
- let addedProp = false;
260
- const res = {};
261
- for (const [settingsKey, props] of Object.entries(EnhancedBlockJSONPlugin.THEME_JSON_FLAG_PROPS)) {
262
- const support = supports[settingsKey];
263
- if (!isRecord(support)) {
264
- continue;
265
- }
266
- const flags = {};
267
- for (const [supportProp, settingsProp] of Object.entries(props)) {
268
- // A sided support such as `"margin": ["top", "bottom"]` is still just "on" as far as theme.json is concerned
269
- if (support[supportProp]) {
270
- flags[settingsProp] = true;
271
- res[settingsKey] = flags;
272
- addedProp = true;
273
- }
274
- }
275
- }
276
- return addedProp ? res : undefined;
277
- }
278
- callRegisterFunction(type, writer, baseUriVar, handles) {
279
- for (const [name, { src, rest }] of handles) {
280
- writer.call(`wp_register_${type}`, [name, src === false ? false : expressions_1.Op.concat(baseUriVar, src), ...rest]);
281
- }
282
- }
283
- transformBlocks(compilation, collatedWorkableBlockInfo, emittingWpmlXml) {
284
- const handleData = Object.values(collatedWorkableBlockInfo)
285
- .flatMap(bi => bi.workableBlockEntrypointsInfo)
286
- .sort((a, b) => a.handle.localeCompare(b.handle) || a.entrypointField.localeCompare(b.entrypointField));
287
- const blockData = {};
288
- const bindableBlockAttributes = {};
289
- for (const [blockJsonAssetName, { sourcePath: blockJsonSourcePath, workableBlockEntrypointsInfo, blockJsonText }] of Object.entries(collatedWorkableBlockInfo)) {
290
- if (!blockJsonSourcePath) {
291
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have a source path`, blockJsonAssetName));
292
- continue;
293
- }
294
- if (!blockJsonText) {
295
- compilation.errors.push((0, shared_1.newWebpackErrorForFile)(`${blockJsonAssetName} does not have recorded text`, blockJsonAssetName));
296
- continue;
297
- }
298
- const sourceDir = (0, node_path_1.dirname)(blockJsonSourcePath);
299
- const outputDir = (0, node_path_1.join)(compilation.compiler.outputPath, (0, node_path_1.dirname)(blockJsonAssetName));
300
- const blockJson = JSON.parse(blockJsonText);
301
- const pathsNeedRemapping = !this.config.standaloneBlocks && blockJson["plaudit"] !== "simple";
302
- EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "setup", pathsNeedRemapping, sourceDir, outputDir, compilation, true);
303
- EnhancedBlockJSONPlugin.remapReferencedPHPFilesOnKey(blockJson, "variations", pathsNeedRemapping, sourceDir, outputDir, compilation, false);
304
- EnhancedBlockJSONPlugin.handleExperimentalBlockSupportsFlags(blockJson);
305
- const hashForVersion = EnhancedBlockJSONPlugin
306
- .hashThingForAsset([blockJsonText, ...workableBlockEntrypointsInfo.map(bi => bi.hash)].join("~"));
307
- if (blockJson["version"]) {
308
- blockJson["version"] = `${blockJson["version"]}-${hashForVersion}`;
309
- }
310
- else {
311
- blockJson["version"] = hashForVersion;
312
- }
313
- if (typeof blockJson["name"] === 'string' && typeof blockJson["attributes"] === 'object' && blockJson["attributes"]) {
314
- for (const [name, attr] of Object.entries(blockJson["attributes"])) {
315
- if (attr["supports-bindings"]) {
316
- delete attr["supports-bindings"];
317
- if (bindableBlockAttributes[blockJson["name"]] !== undefined) {
318
- bindableBlockAttributes[blockJson["name"]].push(name);
319
- }
320
- else {
321
- bindableBlockAttributes[blockJson["name"]] = [name];
322
- }
323
- }
324
- }
325
- }
326
- EnhancedBlockJSONPlugin.normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation);
327
- const blockDirName = (0, node_path_1.dirname)((0, node_path_1.relative)(this.dest.destination, blockJsonAssetName));
328
- blockData[blockDirName] = EnhancedBlockJSONPlugin
329
- .doFileOrHandleReplacements(compilation, Object.fromEntries(Object.entries(blockJson).filter(([k]) => k !== '$schema')), workableBlockEntrypointsInfo, epi => epi.handle);
330
- const emittableBlockJson = EnhancedBlockJSONPlugin.doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, epi => "file:./" + (0, node_path_1.relative)(blockDirName, epi.outputPath));
331
- compilation[blockJsonAssetName in compilation.assets ? 'updateAsset' : 'emitAsset'](blockJsonAssetName, new webpack_1.sources.RawSource(JSON.stringify(emittableBlockJson, undefined, " ")));
332
- }
333
- return {
334
- __metadata: {
335
- version: 3,
336
- "wpml-config": emittingWpmlXml,
337
- scriptHandles: Object.fromEntries(EnhancedBlockJSONPlugin
338
- .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && !(0, shared_1.isScriptModuleField)(hd.entrypointField)))),
339
- scriptModuleHandles: Object.fromEntries(EnhancedBlockJSONPlugin
340
- .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
341
- styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
342
- .map(hd => {
343
- if (hd.inlinedAsset === undefined) {
344
- return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], assetContents: hd.assetContents }];
345
- }
346
- return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset, assetContents: hd.assetContents }];
347
- })),
348
- bindableBlockAttributes
349
- },
350
- ...Object.fromEntries(Object.entries(blockData).sort((a, b) => a[0].localeCompare(b[0])))
351
- };
352
- }
353
- static extractAssetSource(compilation, assetName) {
354
- const assetSource = compilation.getAsset(assetName)?.source.source();
355
- return typeof assetSource === 'string' ? assetSource : assetSource?.toString('utf-8');
356
- }
357
- static convertToScriptHandles(handleData) {
358
- return handleData.map(hd => {
359
- const { assetContents, inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
360
- const { dependencies = [], module_dependencies = undefined } = originalValue !== undefined ? assetData : {};
361
- let scriptArgsObject;
362
- if (rawScriptArgsObject !== undefined) {
363
- const merged_module_dependencies = (0, shared_1.mergeModuleDependencyArrays)(rawScriptArgsObject.module_dependencies, module_dependencies);
364
- scriptArgsObject = merged_module_dependencies?.length ? { ...rawScriptArgsObject, module_dependencies: merged_module_dependencies } : { ...rawScriptArgsObject };
365
- }
366
- else {
367
- if (inlinedAsset !== undefined) {
368
- scriptArgsObject = inlinedAsset.position === 'before' ? { strategy: "defer" } : undefined;
369
- }
370
- else if (!entrypointField.startsWith("editor")) {
371
- scriptArgsObject = { strategy: "defer" };
372
- }
373
- else {
374
- scriptArgsObject = undefined;
375
- }
376
- if (module_dependencies?.length) {
377
- if (scriptArgsObject === undefined) {
378
- scriptArgsObject = { module_dependencies };
379
- }
380
- else {
381
- scriptArgsObject.module_dependencies = module_dependencies;
382
- }
383
- }
384
- }
385
- const rest = scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version];
386
- if (inlinedAsset) {
387
- return [handle, { src: outputPath, rest, inlinedAsset, assetContents }];
388
- }
389
- else {
390
- return [handle, { src: outputPath, rest, assetContents }];
391
- }
392
- });
393
- }
394
- static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
395
- for (const entrypointInfo of workableBlockEntrypointsInfo) {
396
- const fieldValue = blockJson[entrypointInfo.entrypointField];
397
- if (!fieldValue) {
398
- blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
399
- }
400
- else if (entrypointInfo.originalValue) {
401
- if (entrypointInfo.originalValue === fieldValue) {
402
- blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
403
- }
404
- else if (typeof fieldValue === 'string') {
405
- blockJson[entrypointInfo.entrypointField] = [fieldValue, getter(entrypointInfo)];
406
- }
407
- else if (Array.isArray(fieldValue)) {
408
- const replacementPos = fieldValue.indexOf(entrypointInfo.originalValue);
409
- if (replacementPos === -1) {
410
- compilation.warnings.push((0, shared_1.newWebpackErrorForFile)(`Unable to find ${entrypointInfo.originalValue} in ${entrypointInfo.entrypointField}`, entrypointInfo.blockJsonOrigin));
411
- blockJson[entrypointInfo.entrypointField] = fieldValue.concat(getter(entrypointInfo));
412
- }
413
- else {
414
- blockJson[entrypointInfo.entrypointField] = fieldValue.toSpliced(replacementPos, 1, getter(entrypointInfo));
415
- }
416
- }
417
- else {
418
- blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
419
- }
420
- }
421
- else {
422
- if (typeof fieldValue === 'string') {
423
- blockJson[entrypointInfo.entrypointField] = [fieldValue, getter(entrypointInfo)];
424
- }
425
- else if (Array.isArray(fieldValue)) {
426
- blockJson[entrypointInfo.entrypointField] = fieldValue.concat(getter(entrypointInfo));
427
- }
428
- else {
429
- blockJson[entrypointInfo.entrypointField] = getter(entrypointInfo);
430
- }
431
- }
432
- }
433
- return blockJson;
434
- }
435
- stripOffBlocksDestPrefix(file) {
436
- return this.dest.destination && file.startsWith(this.dest.destination + "/") ? file.substring(this.dest.destination.length + 1 /* we also need to drop the "/" */) : file;
437
- }
438
- static hashThingForAsset(thing) {
439
- return (0, node_crypto_1.createHash)('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
440
- }
441
- static stripFilePrefix(file) {
442
- return file.startsWith("file:./") ? file.substring(7) : file;
443
- }
444
- static findCommonAncestor(...paths) {
445
- return paths.map(p => (0, node_path_1.normalize)(p).split(node_path_1.sep)).reduce((prior, current) => {
446
- for (let i = 0, limit = Math.min(prior.length, current.length); i < limit; i++) {
447
- if (prior[i] !== current[i]) {
448
- return prior.slice(0, i);
449
- }
450
- }
451
- return current.length < prior.length ? current : prior;
452
- });
453
- }
454
- static findRelativeRouteBetween(path1, path2) {
455
- const commonAncestor = EnhancedBlockJSONPlugin.findCommonAncestor(path1, path2);
456
- return (".." + node_path_1.sep).repeat(path1.split(node_path_1.sep).length - commonAncestor.length) + (0, node_path_1.relative)(commonAncestor.join(node_path_1.sep), path2);
457
- }
458
- static remapReferencedPHPFilesOnKey(blockJson, key, pathsNeedRemapping, sourceDir, outputDir, compilation, inPlaudit) {
459
- const rawValue = (inPlaudit ? blockJson["plaudit"] : blockJson)?.[key];
460
- let rawFiles;
461
- let deleteOnEmpty = true;
462
- if (typeof rawValue === 'string') {
463
- rawFiles = [rawValue];
464
- }
465
- else if (Array.isArray(rawValue) && rawValue.length > 0) {
466
- const fileReferences = rawValue.filter((value) => typeof value === 'string' && value.startsWith("file:./"));
467
- if (fileReferences.length === rawValue.length) {
468
- rawFiles = fileReferences;
469
- }
470
- else {
471
- if (fileReferences.length !== 0) {
472
- compilation.warnings.push((0, shared_1.newWebpackErrorForFile)(`Encountered a block with a mixture of file-reference and non-file-reference elements in the "${inPlaudit ? 'plaudit.' : ''}${key}" property`, (0, node_path_1.join)(sourceDir, 'block.json')));
473
- rawFiles = fileReferences;
474
- }
475
- else {
476
- rawFiles = [`${key}.php`]; // We want to emit an error if both an appropriately-named file AND an incompatible value exist, so we still need to do the check
477
- }
478
- deleteOnEmpty = false;
479
- }
480
- }
481
- else {
482
- if (rawValue && (!Array.isArray(rawValue) || rawValue.length === 0)) {
483
- deleteOnEmpty = false;
484
- }
485
- rawFiles = [`${key}.php`];
486
- }
487
- const mappedFiles = pathsNeedRemapping
488
- ? rawFiles
489
- .map(p => (0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
490
- .filter(node_fs_1.existsSync)
491
- .map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
492
- : rawFiles
493
- .filter(p => (0, node_fs_1.existsSync)((0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
494
- if (mappedFiles.length === 0) {
495
- if (deleteOnEmpty && rawValue !== undefined) {
496
- delete (inPlaudit ? blockJson["plaudit"] : blockJson)[key];
497
- }
498
- }
499
- else {
500
- if (inPlaudit && typeof blockJson["plaudit"] !== 'object') {
501
- if (blockJson["plaudit"] === "native") {
502
- blockJson["plaudit"] = { type: "native" };
503
- }
504
- else {
505
- blockJson["plaudit"] = {};
506
- }
507
- }
508
- (inPlaudit ? blockJson["plaudit"] : blockJson)[key] = mappedFiles.length === 1 ? mappedFiles[0] : mappedFiles;
509
- }
510
- }
511
- static normalizeRenderTemplate(blockJson, pathsNeedRemapping, sourceDir, outputDir, compilation) {
512
- if (blockJson["acf"]) {
513
- if (blockJson["acf"]["renderTemplate"]) {
514
- blockJson["render_template"] = blockJson["acf"]["renderTemplate"];
515
- delete blockJson["acf"]["renderTemplate"];
516
- }
517
- else if (blockJson["acf"]["render_template"]) {
518
- blockJson["render_template"] = blockJson["acf"]["render_template"];
519
- delete blockJson["acf"]["render_template"];
520
- }
521
- }
522
- const blockName = blockJson["name"]?.toString() || "non-existent/block-name";
523
- let rawRenderTemplate = blockJson["render"] ?? blockJson["render_template"];
524
- rawRenderTemplate = (rawRenderTemplate
525
- ? (typeof rawRenderTemplate === 'string' ? [rawRenderTemplate] : rawRenderTemplate)
526
- : [`${blockName.substring(blockName.indexOf('/') + 1)}.php`, "template.php", "template.twig"]);
527
- const renderTemplate = pathsNeedRemapping
528
- ? rawRenderTemplate
529
- .map(p => (0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p))))
530
- .filter(node_fs_1.existsSync)
531
- .map(p => `file:./${EnhancedBlockJSONPlugin.findRelativeRouteBetween(outputDir, p)}`)
532
- : rawRenderTemplate
533
- .filter(p => (0, node_fs_1.existsSync)((0, node_path_1.normalize)((0, node_path_1.join)(sourceDir, EnhancedBlockJSONPlugin.stripFilePrefix(p)))));
534
- if (renderTemplate.length === 0) {
535
- delete blockJson["render_template"];
536
- delete blockJson["render"];
537
- }
538
- else {
539
- let validTemplateLocation, invalidTemplateLocation;
540
- if (blockJson["acf"] || (blockJson["plaudit"] && (blockJson["plaudit"] !== "native" && (typeof blockJson["plaudit"] !== 'object' || blockJson["plaudit"]?.["type"] !== "native")))) {
541
- // ACF-like blocks need to have the template stored in render_template.
542
- // Because we can statically detect ACF-like blocks, we can make the move here instead of at run-time.
543
- validTemplateLocation = "render_template";
544
- invalidTemplateLocation = "render";
545
- }
546
- else {
547
- validTemplateLocation = "render";
548
- invalidTemplateLocation = "render_template";
549
- }
550
- delete blockJson[invalidTemplateLocation];
551
- if (renderTemplate.length > 1) {
552
- compilation.warnings.push((0, shared_1.newWebpackErrorForFile)("Encountered a block with multiple possible render files. Please set the render key in block.json to the intended one", (0, node_path_1.join)(sourceDir, 'block.json')));
553
- blockJson[validTemplateLocation] = renderTemplate.find(p => p.endsWith(".php")) ?? renderTemplate[0];
554
- }
555
- else {
556
- blockJson[validTemplateLocation] = renderTemplate[0];
557
- }
558
- }
559
- }
560
- static knownExperimentalProperties = ['border', 'defaultControls', 'fontFamily', 'fontWeight', 'fontStyle', 'letterSpacing', 'textTransform', 'textDecoration']
561
- .map(prop => [prop, "__experimental" + prop.substring(0, 1).toUpperCase() + prop.substring(1)]);
562
- static handleExperimentalBlockSupportsFlags(blockSupports) {
563
- for (const [key, value] of Object.entries(blockSupports)) {
564
- if (typeof value === 'object' && !!value && !Array.isArray(value)) {
565
- EnhancedBlockJSONPlugin.handleExperimentalBlockSupportsFlags(value);
566
- }
567
- if (!key.startsWith("__experimental")) {
568
- continue;
569
- }
570
- const realKey = key.substring(14, 15).toLowerCase() + key.substring(15);
571
- if (!(realKey in blockSupports)) {
572
- blockSupports[realKey] = value;
573
- }
574
- }
575
- // This handles known currently-experimental properties
576
- for (const [eventualKey, experimentalKey] of EnhancedBlockJSONPlugin.knownExperimentalProperties) {
577
- if (eventualKey in blockSupports && !(experimentalKey in blockSupports)) {
578
- blockSupports[experimentalKey] = blockSupports[eventualKey];
579
- }
580
- }
581
- }
582
- attachUniquePhase(compilation) {
583
- compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
584
- const allSemaphoreData = (await EnhancedBlockJSONPlugin.semaphore.wait())
585
- .reduce((acc, cur) => {
586
- (acc[cur.blocksDest] ?? (acc[cur.blocksDest] = [])).push(cur);
587
- return acc;
588
- }, {});
589
- const semaphoreData = allSemaphoreData[this.dest.destination];
590
- if (semaphoreData === undefined) {
591
- compilation.errors.push(new Error(`Semaphore data missing for ${this.dest.destination}`));
592
- return;
593
- }
594
- const workableBlockInfo = semaphoreData.map(sd => sd.collatableWorkableBlockInfo)
595
- .reduce((acc, cur) => {
596
- for (const [k, v] of Object.entries(cur)) {
597
- if (acc[k]) {
598
- acc[k].workableBlockEntrypointsInfo.push(...v.workableBlockEntrypointsInfo);
599
- if (!acc[k].sourcePath && v.sourcePath) {
600
- acc[k].sourcePath = v.sourcePath;
601
- }
602
- }
603
- else {
604
- acc[k] = { ...v, workableBlockEntrypointsInfo: [...v.workableBlockEntrypointsInfo] };
605
- }
606
- acc[k].workableBlockEntrypointsInfo.sort((a, b) => {
607
- return a.handle.localeCompare(b.handle) || a.entrypointField.localeCompare(b.entrypointField);
608
- });
609
- }
610
- return acc;
611
- }, {});
612
- const blockData = this.transformBlocks(compilation, this.deduplicateEntrypointHandles(workableBlockInfo), semaphoreData.some(sd => sd.emittingWpmlXml));
613
- this.emitBlockLoaderFile(compilation, blockData);
614
- });
615
- }
616
- attachStandardPhase(compilation) {
617
- super.attachStandardPhase(compilation);
618
- compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER }, async () => {
619
- const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
620
- for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
621
- if ((0, node_path_1.basename)(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
622
- continue;
623
- }
624
- const entrypointChunk = entrypoint.getEntrypointChunk();
625
- for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
626
- if (!danglingBlockJsFile.endsWith("block.json")) {
627
- compilation.deleteAsset(danglingBlockJsFile);
628
- }
629
- }
630
- }
631
- });
632
- }
633
- deduplicateEntrypointHandles(workableBlockInfo) {
634
- const handleRecords = { scriptHandles: {}, scriptModuleHandles: {}, styleHandles: {} };
635
- for (const { workableBlockEntrypointsInfo } of Object.values(workableBlockInfo)) {
636
- for (const { handleGroup, handle, originalValue, outputPath } of workableBlockEntrypointsInfo) {
637
- if (originalValue !== undefined) {
638
- handleRecords[handleGroup][handle] = outputPath;
639
- }
640
- }
641
- }
642
- return Object.fromEntries(Object.entries(workableBlockInfo).map((e) => {
643
- const deduplicatedWorkableBlockEntrypointsInfo = e[1].workableBlockEntrypointsInfo.map(bei => {
644
- if (handleRecords[bei.handleGroup][bei.handle] === bei.outputPath) {
645
- return bei;
646
- }
647
- for (let count = 1, handle = `${bei.handle}_${count}`;; handle = `${bei.handle}_${++count}`) {
648
- if (!handleRecords[bei.handleGroup][handle] || handleRecords[bei.handleGroup][handle] === bei.outputPath) {
649
- return { ...bei, handle };
650
- }
651
- }
652
- });
653
- return [e[0], { ...e[1], workableBlockEntrypointsInfo: deduplicatedWorkableBlockEntrypointsInfo }];
654
- }));
655
- }
656
- }
657
- exports.EnhancedBlockJSONPlugin = EnhancedBlockJSONPlugin;