@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
@@ -3,38 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  const node_fs_1 = require("node:fs");
6
- const promises_1 = require("node:fs/promises");
7
6
  const node_path_1 = require("node:path");
8
- const shared_1 = require("./shared");
9
- const entrypoint_resolution_logic_1 = require("./utils/entrypoint-resolution-logic");
10
- const common_config_helpers_1 = require("./utils/common-config-helpers");
11
- const path_query_and_related_helpers_1 = require("./utils/path-query-and-related-helpers");
7
+ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
8
+ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
9
+ const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
10
+ const api_1 = require("./api");
11
+ const auto_registering_plugins_loader_1 = require("./internal-utils/auto-registering-plugins-loader");
12
+ const common_config_helpers_1 = require("./internal-utils/common-config-helpers");
13
+ const entrypoint_resolution_logic_1 = require("./internal-utils/entrypoint-resolution-logic");
14
+ const internal_pseudo_plugin_1 = __importDefault(require("./internal-utils/internal-pseudo-plugin"));
12
15
  const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
13
16
  const dependency_extraction_webpack_plugin_config_builder_1 = require("./plugins/dependency-extraction-webpack-plugin-config-builder");
14
- const EnhancedDynamicEntryPlugin_1 = require("./plugins/EnhancedDynamicEntryPlugin");
15
- const ExtensionsConfigFileGeneratorPlugin_1 = require("./plugins/ExtensionsConfigFileGeneratorPlugin");
16
- const ExtensionsConfigFileGeneratorPluginV1_1 = require("./plugins/ExtensionsConfigFileGeneratorPluginV1");
17
17
  const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
18
18
  const PackageConfigSanityChecker_1 = require("./plugins/PackageConfigSanityChecker");
19
- const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./plugins/PlainEntrypointsConfigFileGeneratorPlugin");
20
- const EnhancedBlockJSONPlugin_1 = require("./plugins/EnhancedBlockJSONPlugin");
21
- const SpecialAssetHandlingPlugin_1 = require("./plugins/SpecialAssetHandlingPlugin");
19
+ const RootCoordinatorPluginImpl_1 = require("./plugins/RootCoordinatorPluginImpl");
20
+ const register_1 = require("./plugins/register");
22
21
  const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin");
23
- const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
24
- const static_configs_1 = require("./plugins/static-configs");
25
- const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
26
- const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
27
- const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
28
- const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
29
- const location_encoding_filename_parser_1 = require("./utils/location-encoding-filename-parser");
22
+ const shared_1 = require("./shared");
23
+ const utils_1 = require("./utils");
30
24
  function testForDuplicatedEntryPaths(sources) {
31
- const seenPaths = (0, common_config_helpers_1.groupEntrypointsByAssetFile)(Array.isArray(sources)
25
+ const seenPaths = (0, utils_1.groupEntrypointsByAssetName)(Array.isArray(sources)
32
26
  ? sources.map(s => typeof s === 'string' ? s : s[1].destination)
33
27
  : Object.values(sources).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
34
- let projectPrefix = undefined;
28
+ let projectPrefix;
35
29
  let duplicatedPaths = "";
36
- for (const sameNamePaths of seenPaths.values()) {
37
- if (sameNamePaths.length > 1) {
30
+ for (const sameNamePaths of Object.values(seenPaths)) {
31
+ if ((0, utils_1.arrayHasAtLeastLength)(sameNamePaths, 2)) {
38
32
  if (projectPrefix === undefined) {
39
33
  for (let p = process.cwd(); p.length > 1; p = (0, node_path_1.dirname)(p)) {
40
34
  if ((0, node_fs_1.existsSync)((0, node_path_1.join)(p, "docker-compose.yml"))) {
@@ -54,99 +48,15 @@ function testForDuplicatedEntryPaths(sources) {
54
48
  process.exit(1);
55
49
  }
56
50
  }
57
- function replaceDefaultURLProcessing(useWebpackResourceFiltering) {
58
- return (rules) => {
59
- const cssLoader = require.resolve('css-loader');
60
- if (cssLoader) {
61
- return rules.map(rule => {
62
- if (rule && typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
63
- return {
64
- ...rule,
65
- use: rule.use.map(useElement => {
66
- if (useElement && typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
67
- return {
68
- ...useElement,
69
- options: {
70
- ...useElement.options,
71
- url: {
72
- filter(url) {
73
- return (useWebpackResourceFiltering || !url.startsWith("/"))
74
- && !!url.match(/\.(woff2?|eot|ttf|otf|png|jpe?g|svg|webp|avif|gif|bmp)[^.]*?(\?.*)?/i);
75
- }
76
- }
77
- }
78
- };
79
- }
80
- return useElement;
81
- })
82
- };
83
- }
84
- return rule;
85
- });
86
- }
87
- return rules;
88
- };
89
- }
90
- function injectPostcssConfigOverrides(rules, config, variables, postcssFunctionsConfig) {
91
- const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(name => variables(name) ?? (name === 'ENV' ? '' : undefined), postcssFunctionsConfig);
92
- return rules.map(rule => {
93
- if (rule && typeof rule === 'object') {
94
- if (Array.isArray(rule.use)) {
95
- for (const useItem of rule.use) {
96
- if (useItem && typeof useItem === 'object' && typeof useItem.options === 'object') {
97
- if (useItem.options["sourceMap"] === false) {
98
- useItem.options["sourceMap"] = true;
99
- }
100
- if (useItem.loader?.includes('postcss-loader')) {
101
- if (useItem.options["postcssOptions"]) {
102
- useItem.options["postcssOptions"] = { ...useItem.options["postcssOptions"], ...postcssConfig, sourceMap: true, config: false };
103
- }
104
- else {
105
- useItem.options["postcssOptions"] = { ...postcssConfig, sourceMap: true, config: false };
106
- }
107
- }
108
- }
109
- }
110
- if (rule.test instanceof RegExp) {
111
- if (rule.test.test("index.ts") || rule.test.test("index.mts")) { // Then this is the JavaScript and TypeScript rule
112
- rule.test = /\.m?[jt]sx?$/; // This hacks in support for mjs and mts files
113
- }
114
- if (config.onlyRunPostCSSOnPCSS && rule.test.test("test.css") && !rule.test.test("test.pcss")) {
115
- // We remove PostCSS processing from the .css file handling pipeline
116
- rule.use = rule.use.filter(useItem => !useItem || typeof useItem !== 'object' || !useItem.loader?.includes('postcss-loader'));
117
- }
118
- }
119
- }
120
- if (rule.type === "asset/inline" && rule.test instanceof RegExp && rule.issuer instanceof RegExp && rule.test.test("test.svg") && rule.issuer.test("test.pcss")) {
121
- const { type: originalType, ...commonRuleParams } = rule;
122
- return {
123
- ...commonRuleParams,
124
- oneOf: [
125
- { type: originalType, resourceQuery: /string|inline/i },
126
- { type: "asset/resource", generator: { filename: "images/[name].[hash:8][ext]" } }
127
- ]
128
- };
129
- }
130
- }
131
- return rule;
132
- });
133
- }
134
- function injectSupportForInliningSVGsAsStrings(rules) {
135
- const svgRLoader = require.resolve('@svgr/webpack');
136
- return rules.map(rule => {
137
- if (rule && typeof rule === 'object' && "use" in rule && Array.isArray(rule.use) && (rule.use.includes('@svgr/webpack') || rule.use.includes(svgRLoader))) {
138
- const { test, issuer, ...reactSpecific } = rule;
139
- return { test, issuer, oneOf: [
140
- { type: 'asset/source', resourceQuery: /string/ }, // *.svg?string
141
- reactSpecific
142
- ] };
143
- }
144
- return rule;
145
- });
146
- }
147
51
  function buildVerifiedConfig(config) {
52
+ const baseDir = process.cwd();
148
53
  config = (0, shared_1.applyStandards)(config);
149
- const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false, onlyRunPostCSSOnPCSS = false, useBlockSupportsAsThemeJsonDefaults = true, } = config;
54
+ const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', externals, assumeGlobalizedPlauditLibraries = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false, onlyRunPostCSSOnPCSS = false, useBlockSupportsAsThemeJsonDefaults = true, pluginConfig = {}, } = config;
55
+ // This is present to handle the postcss config being in the legacy location
56
+ if ('postcss' in config) {
57
+ (0, utils_1.emitWarning)("Found the postcss config object at the root of the config object. Please move it to be a child of pluginConfig");
58
+ pluginConfig['postcss'] = config.postcss;
59
+ }
150
60
  let outputDir = config.outputDir ?? "";
151
61
  if ((0, shared_1.shouldWriteDistDev)({ outputDir, useUnifiedLoader, omitDistDev })) {
152
62
  outputDir += "-dev";
@@ -159,87 +69,35 @@ function buildVerifiedConfig(config) {
159
69
  else {
160
70
  srcPrefixes = (srcDir && !config.srcPrefixes.includes(trailingSlashedSrcDir) ? [...config.srcPrefixes, trailingSlashedSrcDir] : config.srcPrefixes);
161
71
  }
162
- let targetHandlePrefix = config.targetHandlePrefix ?? config.plainEntrypointsHandlePrefix ?? "";
163
- if (plainEntrypointsVersion > 1) {
164
- if (!targetHandlePrefix) {
165
- targetHandlePrefix = deriveDefaultHandlePrefixFromComposerJsonOrThemeName(shared_1.kebabCase) ?? "";
166
- if (!targetHandlePrefix) {
167
- throw new Error("Plain Entrypoints V2 and higher require either 'targetHandlePrefix' to be set or an adjacent composer.json or style.css file to be present");
168
- }
169
- }
170
- if (!outputDir) {
171
- throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
172
- }
72
+ const targetHandlePrefix = config.targetHandlePrefix ?? config.plainEntrypointsHandlePrefix ?? deriveDefaultHandlePrefixFromComposerJsonOrThemeName(utils_1.kebabCase) ?? "";
73
+ if (!targetHandlePrefix) {
74
+ throw new Error("'targetHandlePrefix' must be set or the webpack.config.js file must have an adjacent composer.json or style.css file");
75
+ }
76
+ if (plainEntrypointsVersion > 1 && !outputDir) {
77
+ throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
173
78
  }
174
79
  // Only the lazyLoader emitters read this, so an absence of package metadata is not worth failing a build
175
80
  // over: php-writer treats an empty namespace as "emit no namespace", which is what we did before 3.10.0
176
- const targetNamespace = config.targetNamespace || deriveDefaultHandlePrefixFromComposerJsonOrThemeName(shared_1.camelCaseForPHPLabels, true) || "";
177
- const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(config);
178
- const rawSources = [...staticEntrypoints, ...dynamicEntrypoints];
179
- let variablesFilePath = undefined;
81
+ const targetNamespace = config.targetNamespace || deriveDefaultHandlePrefixFromComposerJsonOrThemeName(utils_1.camelCaseForPHPLabels, true) || "";
82
+ let variablesFilePath;
180
83
  const currentVariables = rawVariables ?? {};
181
84
  if (!rawVariables) {
182
- variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => (0, node_path_1.join)(process.cwd(), p)).filter(p => (0, node_fs_1.existsSync)(p))[0];
85
+ variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => (0, node_path_1.join)(baseDir, p)).filter(p => (0, node_fs_1.existsSync)(p))[0];
183
86
  }
184
87
  let extensionsVersion = config.extensionsVersion ?? 1;
185
88
  if (extensionsVersion === 2) {
186
89
  extensionsVersion = 3; // Version 3 is a backwards-compatible upgrade of version 2, so we can automatically upgrade everything
187
90
  }
188
91
  const cfg = {
189
- currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries,
92
+ currentVariables, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries,
190
93
  useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix,
191
- useUnifiedLoader, includePostInitFallback, omitDistDev, onlyRunPostCSSOnPCSS, targetNamespace, useBlockSupportsAsThemeJsonDefaults
94
+ useUnifiedLoader, includePostInitFallback, omitDistDev, onlyRunPostCSSOnPCSS, targetNamespace, useBlockSupportsAsThemeJsonDefaults,
95
+ pluginConfig
192
96
  };
193
97
  // Destination -> source map
194
98
  const allocatedDestinations = {};
195
- const partiallyVerifiedSources = rawSources.map(([src, config]) => {
196
- const { destination, additionalDependencies = [], assumeGlobalizedPlauditLibraries = cfg.assumeGlobalizedPlauditLibraries, bundleAnalyzer = false, directoryLayout, externalize, withLegacyBlocksIn = false, lazyLoader, pathQueryParameters: rawPathQueryParameters, enqueuingFlags: rawEnqueuingFlags, locations: rawSourceLocations, } = config;
197
- // This guards against a crash later on down the line due to trying to run a spread on a boolean
198
- if (externalize && typeof externalize !== 'string' && typeof externalize !== 'object') {
199
- throw new TypeError(`externalize must be a string, an array or an object, but "${src}" set externalize to a ${typeof externalize}`);
200
- }
201
- const { flags: queryEnqueuingFlags, remainder: pathQueryParameters, handle: pathQueryHandle } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(rawPathQueryParameters, src, 'path query parameters');
202
- const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(src, rawEnqueuingFlags, queryEnqueuingFlags);
203
- const normalizedParts = { additionalDependencies, assumeGlobalizedPlauditLibraries, bundleAnalyzer, directoryLayout, externalize, withLegacyBlocksIn, lazyLoader };
204
- let locations;
205
- if (pathQueryHandle === undefined) {
206
- locations = typeof rawSourceLocations === 'string' || typeof rawSourceLocations === 'function' || (rawSourceLocations !== undefined && 'niceName' in rawSourceLocations)
207
- ? { handle: rawSourceLocations } : rawSourceLocations ?? {};
208
- }
209
- else {
210
- const rawSourceHandle = typeof rawSourceLocations === 'string' || typeof rawSourceLocations === 'function' || (rawSourceLocations !== undefined && 'niceName' in rawSourceLocations)
211
- ? rawSourceLocations : rawSourceLocations?.handle;
212
- if (rawSourceHandle === undefined) {
213
- locations = { handle: pathQueryHandle };
214
- }
215
- else if (typeof rawSourceHandle === 'string') {
216
- if (rawSourceHandle !== pathQueryHandle) {
217
- throw new ReferenceError(`Encountered mismatched handles "${rawSourceHandle}" and "${pathQueryHandle}" when preparing "${src}"`);
218
- }
219
- locations = { handle: pathQueryHandle };
220
- }
221
- else {
222
- throw new ReferenceError(`Encountered a function handle and a path query handle when preparing "${src}"`);
223
- }
224
- // This is just a means of merging the new handle into the rawSourceLocations config without mutating the base config
225
- if (rawSourceLocations !== undefined && typeof rawSourceLocations !== 'function' && typeof rawSourceLocations !== 'string') {
226
- locations = { ...rawSourceLocations, ...locations };
227
- }
228
- }
229
- if (typeof locations.registerScriptArgs === 'string' && !['lazy', 'eager', 'inline'].includes(locations.registerScriptArgs)) {
230
- throw new ReferenceError("The only supported string values for registerScriptArgs are 'lazy', 'eager', and 'inline'");
231
- }
232
- if (destination !== undefined) {
233
- const effectiveDestination = toEffectiveWebpackDestination(destination);
234
- allocatedDestinations[effectiveDestination] = src; // We need to pre-populate the allocatedDestinations map with statically declared destinations
235
- return [src, { ...normalizedParts, locations, destination, effectiveDestination, staticallyDeclaredDestination: true, pathQueryParameters, enqueuingFlags }];
236
- }
237
- else {
238
- const naiveDestination = deriveNaiveDestinationFromUnverifiedSourceEntry(src, destination, srcPrefixes);
239
- const effectiveDestination = toEffectiveWebpackDestination(naiveDestination);
240
- return [src, { ...normalizedParts, locations, destination: naiveDestination, effectiveDestination, staticallyDeclaredDestination: false, pathQueryParameters, enqueuingFlags }];
241
- }
242
- });
99
+ const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(cfg, config.src, baseDir, allocatedDestinations, srcPrefixes);
100
+ const partiallyVerifiedSources = [...staticEntrypoints, ...dynamicEntrypoints];
243
101
  const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
244
102
  .filter(entry => !entry[1].staticallyDeclaredDestination)
245
103
  .map(entry => entry[1].effectiveDestination)
@@ -252,33 +110,6 @@ function buildVerifiedConfig(config) {
252
110
  testForDuplicatedEntryPaths(sources);
253
111
  return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
254
112
  }
255
- function toEffectiveWebpackDestination(destination) {
256
- const pathParts = (0, node_path_1.parse)(destination);
257
- return (0, node_path_1.join)(pathParts.dir, pathParts.name);
258
- }
259
- function deriveNaiveDestinationFromUnverifiedSourceEntry(src, destination, srcPrefixes) {
260
- if (destination !== undefined) {
261
- return destination;
262
- }
263
- const commaIndex = src.indexOf(',');
264
- const primarySource = stripSrcPrefix(commaIndex > -1 ? src.substring(0, commaIndex).trim() : src, srcPrefixes);
265
- const scriptParts = shared_1.scriptExtension.exec(primarySource);
266
- if (scriptParts !== null) {
267
- return `${scriptParts.groups['filename']}.js`; // filename is always defined here
268
- }
269
- const styleParts = shared_1.styleExtension.exec(primarySource);
270
- if (styleParts !== null) {
271
- return `${styleParts.groups['filename']}.css`; // filename is always defined here
272
- }
273
- return primarySource;
274
- }
275
- function stripSrcPrefix(src, srcPrefixes) {
276
- const prefix = srcPrefixes.find(sp => src.startsWith(sp));
277
- if (!prefix) {
278
- return src;
279
- }
280
- return src[prefix.length] === '/' ? src.substring(prefix.length + 1) : src.substring(prefix.length);
281
- }
282
113
  function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpectedNaiveDuplicates, allocatedDestinations) {
283
114
  if (entry[1].staticallyDeclaredDestination) {
284
115
  return entry;
@@ -330,8 +161,8 @@ function deriveDefaultHandlePrefixFromThemeName(stringTransformer) {
330
161
  return stringTransformer(themeName);
331
162
  }
332
163
  function withDerivedOutputDir(cfg, sources) {
333
- const destinations = sources.map(([_, { destination }]) => destination.split(/[\/\\]/g));
334
- if (destinations.length < 2) {
164
+ const destinations = sources.map(([_, { destination }]) => destination.split(/[/\\]/g));
165
+ if (!(0, utils_1.arrayHasAtLeastLength)(destinations, 2)) {
335
166
  return { cfg, sources };
336
167
  }
337
168
  const commonParent = destinations[0][0];
@@ -363,7 +194,7 @@ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins)
363
194
  if ((0, node_path_1.extname)(sr).length === 0) {
364
195
  include.push(...tsExtensions.map(tsExt => (0, node_path_1.join)(sr, "**", `*.${tsExt}`)));
365
196
  }
366
- else if ((0, shared_1.scriptOrStyleTest)(sr, scriptExtension) === "script") {
197
+ else if ((0, api_1.scriptOrStyleTest)(sr, scriptExtension) === "script") {
367
198
  include.push(sr);
368
199
  }
369
200
  }
@@ -415,7 +246,7 @@ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins)
415
246
  }
416
247
  }));
417
248
  }
418
- function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize) {
249
+ function buildCommonPluginConfig(coordinator, webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize) {
419
250
  const plugins = webpackConfig.plugins?.filter(v => !!v)
420
251
  .filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
421
252
  .filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
@@ -431,19 +262,15 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
431
262
  return plugin;
432
263
  })
433
264
  ?? [];
434
- plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
265
+ plugins.unshift(new PackageConfigSanityChecker_1.PackageConfigSanityChecker(), coordinator);
435
266
  if (bundleAnalyzer) {
436
- plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static', openAnalyzer: bundleAnalyzer !== 'no-auto-open' }));
267
+ plugins.unshift(new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static', openAnalyzer: bundleAnalyzer !== 'no-auto-open' }));
437
268
  }
438
- const removeEmptyScriptsPlugin = new webpack_remove_empty_scripts_1.default({
269
+ plugins.push(new webpack_remove_empty_scripts_1.default({
439
270
  stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
440
271
  extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'],
441
272
  ignore: /block\.json/
442
- });
443
- plugins.push(removeEmptyScriptsPlugin, new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
444
- if (config.useWebpackResourceFiltering) {
445
- plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config));
446
- }
273
+ }), new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
447
274
  plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
448
275
  // We have to use constructor.name here the version desyncs can result in multiple equivalent versions kicking around
449
276
  const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin.constructor.name === 'DependencyExtractionWebpackPlugin');
@@ -456,51 +283,30 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
456
283
  console.error("Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.");
457
284
  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");
458
285
  }
459
- const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries, externalize);
460
- plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin;
286
+ plugins[dependencyExtractionPluginIndex] = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries, externalize);
461
287
  try {
462
288
  const { PlauditDevPlugin } = require("@plaudit/dev-webpack-plugin");
463
289
  plugins.push(new PlauditDevPlugin(config));
464
290
  }
465
291
  catch { }
466
292
  return {
467
- plugins, removeEmptyScriptsPlugin,
468
- makeAdditionalDependencyInjectorPlugin(referencePlugin) {
469
- return new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin(webpackConfig.output?.module, builtDependencyExtractionWebpackPlugin.addExternalizedDep, referencePlugin);
470
- }
293
+ plugins
471
294
  };
472
295
  }
473
- function commonConfigProcessingPrep(config, webpackConfig) {
474
- let scriptExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
475
- let entrypointFields;
296
+ async function commonConfigProcessingPrep(wrapperManager, config, webpackConfig, hasAnyNonModuleBuilds) {
476
297
  const processingModules = webpackConfig.output?.module ?? false;
477
- if (processingModules) {
478
- scriptExtension = shared_1.scriptWithModuleExtension;
479
- entrypointFields = ["viewScriptModule"];
480
- }
481
- else {
482
- scriptExtension = shared_1.scriptWithoutModuleExtension;
483
- entrypointFields = ["editorStyle", "viewStyle", "style", "editorScript", "viewScript", "script"];
484
- }
298
+ const scriptExtension = processingModules ? api_1.scriptWithModuleExtension : api_1.scriptWithoutModuleExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
299
+ const entrypointFields = (0, api_1.getLoadableEntrypointFields)(processingModules);
485
300
  let currentVariables = config.currentVariables;
486
- const fixedRules = [
487
- replaceDefaultURLProcessing(config.useWebpackResourceFiltering),
488
- (rules) => {
489
- return injectPostcssConfigOverrides(rules, config, name => currentVariables[name], config.postcss.functions ?? (() => ({})));
490
- },
491
- injectSupportForInliningSVGsAsStrings
492
- ].reduce((r, a) => a(r), webpackConfig.module?.rules ?? []);
493
- fixedRules.push({
494
- test: /wpml-config\.xml$/i,
495
- type: 'asset/resource',
496
- generator: {
497
- filename: '[name][ext]',
498
- emit: false
499
- }
500
- });
301
+ const getVariableValue = (name) => currentVariables[name];
302
+ const draftRules = utils_1.nonFreezingImmer.createDraft(webpackConfig.module?.rules ?? []);
303
+ await wrapperManager.hooks.webpackConfig.rules.promise(draftRules, { config, hasAnyNonModuleBuilds, webpackConfig, getVariableValue, entrypointFields, scriptExtension });
304
+ const fixedRules = utils_1.nonFreezingImmer.finishDraft(draftRules);
501
305
  return {
502
306
  entrypointFields, fixedRules, processingModules, scriptExtension,
503
- updateCurrentVariables: (value) => currentVariables = value
307
+ updateCurrentVariables: (value) => {
308
+ return currentVariables = value;
309
+ }
504
310
  };
505
311
  }
506
312
  function destToKey(dest) {
@@ -509,10 +315,11 @@ function destToKey(dest) {
509
315
  : dest.externalize?.toString() ?? "undefined";
510
316
  return [dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize].join("~");
511
317
  }
512
- function processIndividualWebpackConfig(config, webpackConfig, sources, canClean, preferNonModuleTsChecker) {
318
+ async function processIndividualWebpackConfig(wrapperManager, coordinator, config, webpackConfig, sources, canClean, hasAnyNonModuleBuilds) {
513
319
  if (webpackConfig.output?.module) {
514
320
  // This ensures that module files are emitted as module files
515
321
  webpackConfig = {
322
+ name: "base:modules",
516
323
  ...webpackConfig,
517
324
  output: {
518
325
  ...webpackConfig.output,
@@ -521,13 +328,26 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
521
328
  }
522
329
  };
523
330
  }
524
- const commonConfig = commonConfigProcessingPrep(config, webpackConfig);
525
- const { processingModules, scriptExtension } = commonConfig;
331
+ else if (!webpackConfig.name) {
332
+ webpackConfig = { name: "base:non-modules", ...webpackConfig };
333
+ }
334
+ const commonConfig = await commonConfigProcessingPrep(wrapperManager, config, webpackConfig, hasAnyNonModuleBuilds);
335
+ const { entrypointFields, processingModules, scriptExtension } = commonConfig;
336
+ const legacyBlocksResources = {};
526
337
  const allSrcRoots = sources.map(([src, dest]) => {
527
- const srcRoots = (dest.withLegacyBlocksIn
528
- ? [...src.split(','), ...(0, shared_1.resolveLegacyBlockScriptsInFolder)((0, node_path_1.join)(config.srcDir, dest.withLegacyBlocksIn))]
529
- : src.split(',')).filter(s => s.endsWith(".json") || !s.substring(s.lastIndexOf('/')).includes('.') || processingModules === shared_1.scriptWithModuleExtension.test(s));
530
- 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));
338
+ let srcRoots, legacyBlocksAssets;
339
+ if (dest.withLegacyBlocksIn !== false) {
340
+ legacyBlocksAssets = (0, shared_1.resolveLegacyBlockScriptsInFolder)((0, utils_1.joinPossiblyAbsolutePaths)(process.cwd(), config.srcDir, dest.withLegacyBlocksIn));
341
+ srcRoots = [...src.split(','), ...legacyBlocksAssets];
342
+ }
343
+ else {
344
+ legacyBlocksAssets = [];
345
+ srcRoots = src.split(',');
346
+ }
347
+ const srcRoot = srcRoots.length < 2 ? (0, utils_1.joinPossiblyAbsolutePaths)(process.cwd(), src) : srcRoots.map(s => (0, utils_1.joinPossiblyAbsolutePaths)(process.cwd(), s));
348
+ for (const legacyBlocksAsset of legacyBlocksAssets) {
349
+ legacyBlocksResources[legacyBlocksAsset] = srcRoot;
350
+ }
531
351
  const srcIsDirectory = !Array.isArray(srcRoot) && (0, node_fs_1.lstatSync)(srcRoot, { throwIfNoEntry: false })?.isDirectory();
532
352
  if (srcIsDirectory === undefined) {
533
353
  return undefined;
@@ -539,160 +359,86 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
539
359
  const key = destToKey(entry.dest);
540
360
  (groupedSrcRoots[key] ?? (groupedSrcRoots[key] = [])).push(entry);
541
361
  }
542
- const batches = Object.values(groupedSrcRoots).filter(shared_1.hasAtLeastOneItem);
543
- return batches.map(currentBatch => {
362
+ const batches = Object.values(groupedSrcRoots).filter(utils_1.hasAtLeastOneItem);
363
+ return Promise.all(batches.map(async (currentBatch) => {
544
364
  const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize } = currentBatch[0].dest;
545
- const { plugins, removeEmptyScriptsPlugin, makeAdditionalDependencyInjectorPlugin } = buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize);
546
- if (!processingModules || !preferNonModuleTsChecker) {
365
+ const { plugins } = buildCommonPluginConfig(coordinator, webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize);
366
+ if (!processingModules || !hasAnyNonModuleBuilds) {
547
367
  handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
548
368
  }
549
- const applicableExtensionTest = (name) => {
550
- return commonConfig.scriptExtension.test(name) || (!processingModules && shared_1.styleExtension.test(name));
551
- };
552
- const contextPath = webpackConfig.context ?? process.cwd();
553
- for (const { dest, src, srcIsDirectory, srcRoot } of currentBatch) {
554
- let plugin;
555
- const sourceType = (0, shared_1.determineCurrentSourceType)(dest, srcIsDirectory);
556
- if (sourceType === "blocks" /* SourceType.blocks */) {
557
- if (!srcIsDirectory) {
558
- continue;
559
- }
560
- plugin = new EnhancedBlockJSONPlugin_1.EnhancedBlockJSONPlugin(config, dest, removeEmptyScriptsPlugin, contextPath, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest));
561
- plugins.push(plugin);
562
- if (!processingModules) {
563
- plugins.push(new WPMLConfigBuilder_1.WPMLConfigBuilderPlugin(dest.destination, plugin));
564
- }
565
- }
566
- else if (sourceType === "extensions" /* SourceType.extensions */) {
567
- if (!srcIsDirectory) {
568
- continue;
569
- }
570
- const entry = async () => {
571
- const rawEntrypoints = [];
572
- for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
573
- if ((0, shared_1.shouldBeSkipped)(dirent.name)) {
574
- continue;
575
- }
576
- if (dirent.isFile()) {
577
- if (applicableExtensionTest(dirent.name)) {
578
- const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
579
- const extensionId = (0, node_path_1.parse)(dirent.name).name;
580
- rawEntrypoints.push([(0, node_path_1.join)(dest.destination, (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc))), {
581
- import: [absoluteSrc],
582
- plauditMetadata: { dest, absoluteSrc, extensionId }
583
- }]);
584
- }
585
- }
586
- else if (dirent.isDirectory()) {
587
- rawEntrypoints.push(...await walkExtensionsTree((0, node_path_1.join)(srcRoot, dirent.name), dest, applicableExtensionTest, [dirent.name]));
588
- }
589
- }
590
- return Object.fromEntries(rawEntrypoints);
591
- };
592
- plugin = config.extensionsVersion > 1
593
- ? new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(config, srcRoot, dest, contextPath, entry)
594
- : new ExtensionsConfigFileGeneratorPluginV1_1.ExtensionsConfigFileGeneratorPluginV1(dest.destination, contextPath, entry);
595
- plugins.push(plugin);
596
- }
597
- else if (sourceType === "plain" /* SourceType.plain */) {
598
- const absoluteSrc = typeof srcRoot === 'string' ? srcRoot : srcRoot[0];
599
- if (!srcIsDirectory && !applicableExtensionTest(absoluteSrc)) {
600
- continue;
601
- }
602
- const baseDest = stripExtension(dest.destination);
603
- if (config.plainEntrypointsVersion > 1) {
604
- const entry = srcIsDirectory // This being true implies that srcRoot is not an array
605
- ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
606
- : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } });
607
- plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest, config.useUnifiedLoader, contextPath, entry);
608
- }
609
- else {
610
- if (srcIsDirectory) {
611
- console.error("Using directory mode with legacy plain entrypoint handling is not supported");
612
- continue;
613
- }
614
- plugin = new EnhancedDynamicEntryPlugin_1.EnhancedDynamicEntryPlugin(contextPath, () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } }));
369
+ const batchProcessor = new api_1.IndividualBatchProcessor(plugins, canClean, hasAnyNonModuleBuilds, entrypointFields, scriptExtension);
370
+ const configLevelProps = { config, hasAnyNonModuleBuilds, webpackConfig };
371
+ await wrapperManager.hooks.batch.promise(batchProcessor, configLevelProps);
372
+ await batchProcessor.hooks.beforeBatch.promise();
373
+ for (const item of currentBatch) {
374
+ if (item.dest.sourceType && !wrapperManager.supportedSourceTypes.has(item.dest.sourceType)) {
375
+ let supportedSourceTypes = wrapperManager.supportedSourceTypes.values().map(st => "'" + st + "'").toArray().join(", ");
376
+ if (wrapperManager.supportedSourceTypes.size > 2) {
377
+ const splitIndex = supportedSourceTypes.lastIndexOf("', '") + 2;
378
+ supportedSourceTypes = supportedSourceTypes.substring(0, splitIndex) + " and" + supportedSourceTypes.substring(splitIndex);
615
379
  }
616
- plugins.push(plugin);
617
- }
618
- else {
619
- console.error("Unrecognized sourceType");
380
+ (0, utils_1.emitError)(`Encountered an unsupported source type: ${item.dest.sourceType}. The supported source types are ${supportedSourceTypes}`);
620
381
  continue;
621
382
  }
622
- plugins.push(makeAdditionalDependencyInjectorPlugin(plugin));
623
- const canCopyFiles = srcIsDirectory && src !== dest.destination;
624
- if (canCopyFiles) {
625
- plugins.push(new copy_webpack_plugin_1.default({
626
- patterns: [{
627
- from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset\.php|svg)', //TODO: I'm pretty sure that the dots need proper escaping
628
- to: dest.destination,
629
- context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */, noErrorOnMissing: true
630
- }]
631
- }));
632
- }
633
- }
634
- plugins.push(new UnifiedLoaderGenerator_1.UnifiedLoaderGenerator(config));
635
- return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, externalize, plugins, canClean && batches.length < 2);
636
- }).filter(cfg => cfg !== undefined);
637
- }
638
- async function walkExtensionsTree(srcRoot, dest, applicableExtensionTest, parents) {
639
- const res = [];
640
- for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
641
- if ((0, shared_1.shouldBeSkipped)(dirent.name)) {
642
- continue;
643
- }
644
- if (dirent.isFile()) {
645
- if (!applicableExtensionTest(dirent.name)) {
383
+ await batchProcessor.hooks.beforeDestinationHandler.promise(item);
384
+ const destinationHandler = batchProcessor.hooks.destinationHandler.call(item);
385
+ if (destinationHandler === undefined) {
386
+ await batchProcessor.hooks.afterDestinationHandler.promise(item, destinationHandler);
646
387
  continue;
647
388
  }
648
- const parsedFilename = (0, location_encoding_filename_parser_1.parseLocationEncodingFilename)(dirent.name);
649
- if (parsedFilename === undefined) {
650
- continue;
389
+ if (Array.isArray(destinationHandler.plugin)) {
390
+ plugins.push(...destinationHandler.plugin);
651
391
  }
652
- const absoluteSrc = (0, common_config_helpers_1.joinPossiblyAbsolutePaths)(srcRoot, dirent.name);
653
- let destFile;
654
- if (Object.keys(parsedFilename.locations).length === 1) {
655
- if (parsedFilename.locations.clientView) {
656
- destFile = `view-${parsedFilename.type}`;
657
- }
658
- else if (parsedFilename.locations.clientEditor) {
659
- destFile = `editor-${parsedFilename.type}`;
660
- }
661
- else {
662
- destFile = (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc));
663
- }
392
+ else if (destinationHandler.plugin !== undefined) {
393
+ plugins.push(destinationHandler.plugin);
664
394
  }
665
- else {
666
- destFile = (0, node_path_1.basename)(absoluteSrc, (0, node_path_1.extname)(absoluteSrc));
395
+ plugins.push(...wrapperManager.emitterPlugins
396
+ .flatMap(cb => cb(configLevelProps, item, destinationHandler))
397
+ .filter(p => p !== undefined));
398
+ await batchProcessor.hooks.afterDestinationHandler.promise(item, destinationHandler);
399
+ const { dest, src, srcIsDirectory, srcRoot } = item;
400
+ if (destinationHandler.supportsAssetCopying ?? true) {
401
+ if (srcIsDirectory && src !== dest.destination) {
402
+ plugins.push(new copy_webpack_plugin_1.default({
403
+ patterns: [{
404
+ from: config.standaloneBlocks ? '**/*.(php|twig|svg)' : '**/*.(asset.php|svg)',
405
+ to: dest.destination,
406
+ context: srcRoot /* canCopyFiles can only be true if srcRoot is a string, so this is safe */,
407
+ noErrorOnMissing: true,
408
+ }]
409
+ }));
410
+ }
667
411
  }
668
- const extensionId = parents.join("-") + "-" + destFile;
669
- res.push([(0, node_path_1.join)(dest.destination, ...parents, destFile), {
670
- import: [absoluteSrc],
671
- plauditMetadata: { dest, absoluteSrc, extensionId }
672
- }]);
673
- }
674
- else if (dirent.isDirectory()) {
675
- res.push(...await walkExtensionsTree((0, node_path_1.join)(srcRoot, dirent.name), dest, applicableExtensionTest, [...parents, dirent.name]));
676
412
  }
677
- }
678
- return res;
679
- }
680
- function stripExtension(filepath) {
681
- return (0, node_path_1.join)((0, node_path_1.dirname)(filepath), (0, node_path_1.basename)(filepath, (0, node_path_1.extname)(filepath)));
413
+ plugins.push(new AdditionalDependencyInjectorPlugin_1.AdditionalDependencyInjectorPlugin());
414
+ await batchProcessor.hooks.afterBatch.promise(plugins);
415
+ return (0, common_config_helpers_1.commonMakeWebpackConfig)(wrapperManager, config, commonConfig, webpackConfig, externalize, plugins, canClean && batches.length < 2, hasAnyNonModuleBuilds);
416
+ }));
682
417
  }
683
- module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
418
+ module.exports = async (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) => {
684
419
  const { cfg, sources } = buildVerifiedConfig(config);
685
- if (Array.isArray(webpackConfig) && (0, shared_1.arrayIsLength)(webpackConfig, 1)) {
420
+ const { coordinator, finalizer } = RootCoordinatorPluginImpl_1.RootCoordinatorPluginImpl.make();
421
+ const wrapperManager = new api_1.WrapperManager(coordinator, cfg);
422
+ await (0, register_1.registerBuiltins)(wrapperManager);
423
+ await (0, auto_registering_plugins_loader_1.registerAutoLoadingPlugins)(wrapperManager);
424
+ if (config.wrapperPlugins) {
425
+ for (const plugin of config.wrapperPlugins) {
426
+ await plugin.register(wrapperManager);
427
+ }
428
+ }
429
+ await internal_pseudo_plugin_1.default.register(wrapperManager);
430
+ if (Array.isArray(webpackConfig) && (0, utils_1.arrayIsLength)(webpackConfig, 1)) {
686
431
  webpackConfig = webpackConfig[0];
687
432
  }
688
433
  if (Array.isArray(webpackConfig)) {
689
434
  const hasNonModuleCompiler = webpackConfig.some(cfg => !cfg.output?.module);
690
- return webpackConfig.toSorted((a, b) => {
435
+ return finalizer((await Promise.all(webpackConfig.toSorted((a, b) => {
691
436
  if (a.output?.module) {
692
437
  return b.output?.module ? 0 : -1;
693
438
  }
694
439
  return b.output?.module ? 1 : 0;
695
- }).flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources, false, hasNonModuleCompiler));
440
+ }).map(wpCfg => processIndividualWebpackConfig(wrapperManager, coordinator, cfg, wpCfg, sources, false, hasNonModuleCompiler)))).flat());
696
441
  }
697
- return processIndividualWebpackConfig(cfg, webpackConfig, sources, true, false);
442
+ return finalizer(await processIndividualWebpackConfig(wrapperManager, coordinator, cfg, webpackConfig, sources, true, false));
698
443
  };
444
+ //# sourceMappingURL=wordpress-scripts-wrapper.js.map