@plaudit/webpack-extensions 4.0.0-rc.1 → 4.1.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 (246) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/api/asset-information-emission.d.ts +74 -0
  3. package/dist/api/asset-information-emission.d.ts.map +1 -0
  4. package/dist/api/asset-information-emission.js +398 -0
  5. package/dist/api/asset-information-emission.js.map +1 -0
  6. package/dist/api/configuration.d.ts +102 -0
  7. package/dist/api/configuration.d.ts.map +1 -0
  8. package/dist/api/configuration.js +83 -0
  9. package/dist/api/configuration.js.map +1 -0
  10. package/dist/api/coordinatable-emitter.d.ts +27 -0
  11. package/dist/api/coordinatable-emitter.d.ts.map +1 -0
  12. package/dist/api/coordinatable-emitter.js +20 -0
  13. package/dist/api/coordinatable-emitter.js.map +1 -0
  14. package/dist/api/entries/dependencies.d.ts +69 -0
  15. package/dist/api/entries/dependencies.d.ts.map +1 -0
  16. package/dist/api/entries/dependencies.js +61 -0
  17. package/dist/api/entries/dependencies.js.map +1 -0
  18. package/dist/api/entries/flag-logic.d.ts +37 -0
  19. package/dist/api/entries/flag-logic.d.ts.map +1 -0
  20. package/dist/api/entries/flag-logic.js +110 -0
  21. package/dist/api/entries/flag-logic.js.map +1 -0
  22. package/dist/api/entries/identifiers.d.ts +84 -0
  23. package/dist/api/entries/identifiers.d.ts.map +1 -0
  24. package/dist/api/entries/identifiers.js +590 -0
  25. package/dist/api/entries/identifiers.js.map +1 -0
  26. package/dist/api/entries/index.d.ts +6 -0
  27. package/dist/api/entries/index.d.ts.map +1 -0
  28. package/dist/api/entries/index.js +22 -0
  29. package/dist/api/entries/index.js.map +1 -0
  30. package/dist/api/entries/locations.d.ts +135 -0
  31. package/dist/api/entries/locations.d.ts.map +1 -0
  32. package/dist/api/entries/locations.js +174 -0
  33. package/dist/api/entries/locations.js.map +1 -0
  34. package/dist/api/entries/manager.d.ts +12 -0
  35. package/dist/api/entries/manager.d.ts.map +1 -0
  36. package/dist/api/entries/manager.js +35 -0
  37. package/dist/api/entries/manager.js.map +1 -0
  38. package/dist/api/handle-derivation.d.ts +32 -0
  39. package/dist/api/handle-derivation.d.ts.map +1 -0
  40. package/dist/api/handle-derivation.js +77 -0
  41. package/dist/api/handle-derivation.js.map +1 -0
  42. package/dist/api/index.d.ts +7 -0
  43. package/dist/api/index.d.ts.map +1 -0
  44. package/dist/api/index.js +23 -0
  45. package/dist/api/index.js.map +1 -0
  46. package/dist/api/shared-types.d.ts +86 -0
  47. package/dist/api/shared-types.d.ts.map +1 -0
  48. package/dist/api/shared-types.js +3 -0
  49. package/dist/api/shared-types.js.map +1 -0
  50. package/dist/internal-utils/auto-registering-plugins-loader.d.ts +3 -0
  51. package/dist/internal-utils/auto-registering-plugins-loader.d.ts.map +1 -0
  52. package/dist/internal-utils/auto-registering-plugins-loader.js +42 -0
  53. package/dist/internal-utils/auto-registering-plugins-loader.js.map +1 -0
  54. package/dist/internal-utils/common-config-helpers.d.ts +14 -0
  55. package/dist/internal-utils/common-config-helpers.d.ts.map +1 -0
  56. package/dist/internal-utils/common-config-helpers.js +140 -0
  57. package/dist/internal-utils/common-config-helpers.js.map +1 -0
  58. package/dist/internal-utils/entrypoint-resolution-logic.d.ts +14 -0
  59. package/dist/internal-utils/entrypoint-resolution-logic.d.ts.map +1 -0
  60. package/dist/internal-utils/entrypoint-resolution-logic.js +223 -0
  61. package/dist/internal-utils/entrypoint-resolution-logic.js.map +1 -0
  62. package/dist/internal-utils/internal-pseudo-plugin.d.ts +6 -0
  63. package/dist/internal-utils/internal-pseudo-plugin.d.ts.map +1 -0
  64. package/dist/internal-utils/internal-pseudo-plugin.js +46 -0
  65. package/dist/internal-utils/internal-pseudo-plugin.js.map +1 -0
  66. package/dist/mocks/blocks.d.ts +32 -0
  67. package/dist/mocks/blocks.d.ts.map +1 -0
  68. package/dist/mocks/blocks.js +3 -0
  69. package/dist/mocks/blocks.js.map +1 -0
  70. package/dist/mocks/index.d.ts +2 -0
  71. package/dist/mocks/index.d.ts.map +1 -0
  72. package/dist/mocks/index.js +18 -0
  73. package/dist/mocks/index.js.map +1 -0
  74. package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts +5 -0
  75. package/dist/plugins/AdditionalDependencyInjectorPlugin.d.ts.map +1 -0
  76. package/dist/plugins/AdditionalDependencyInjectorPlugin.js +59 -0
  77. package/dist/plugins/AdditionalDependencyInjectorPlugin.js.map +1 -0
  78. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +5 -0
  79. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts.map +1 -0
  80. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js +16 -0
  81. package/dist/plugins/MiniCSSExtractPluginErrorCleaner.js.map +1 -0
  82. package/dist/plugins/PackageConfigSanityChecker.d.ts +5 -0
  83. package/dist/plugins/PackageConfigSanityChecker.d.ts.map +1 -0
  84. package/dist/plugins/PackageConfigSanityChecker.js +31 -0
  85. package/dist/plugins/PackageConfigSanityChecker.js.map +1 -0
  86. package/dist/plugins/RootCoordinatorPluginImpl.d.ts +56 -0
  87. package/dist/plugins/RootCoordinatorPluginImpl.d.ts.map +1 -0
  88. package/dist/plugins/RootCoordinatorPluginImpl.js +767 -0
  89. package/dist/plugins/RootCoordinatorPluginImpl.js.map +1 -0
  90. package/dist/plugins/VariablesJSMonitorPlugin.d.ts +8 -0
  91. package/dist/plugins/VariablesJSMonitorPlugin.d.ts.map +1 -0
  92. package/dist/plugins/VariablesJSMonitorPlugin.js +21 -0
  93. package/dist/plugins/VariablesJSMonitorPlugin.js.map +1 -0
  94. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts +25 -0
  95. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
  96. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js +458 -0
  97. package/dist/plugins/blocks/BlocksDirectoryLoaderEmitterPlugin.js.map +1 -0
  98. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts +29 -0
  99. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.d.ts.map +1 -0
  100. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js +290 -0
  101. package/dist/plugins/blocks/BlocksDirectoryProcessingPlugin.js.map +1 -0
  102. package/dist/plugins/blocks/register.d.ts +6 -0
  103. package/dist/plugins/blocks/register.d.ts.map +1 -0
  104. package/dist/plugins/blocks/register.js +14 -0
  105. package/dist/plugins/blocks/register.js.map +1 -0
  106. package/dist/plugins/blocks/registerEmitter.d.ts +4 -0
  107. package/dist/plugins/blocks/registerEmitter.d.ts.map +1 -0
  108. package/dist/plugins/blocks/registerEmitter.js +13 -0
  109. package/dist/plugins/blocks/registerEmitter.js.map +1 -0
  110. package/dist/plugins/blocks/registerProcessor.d.ts +4 -0
  111. package/dist/plugins/blocks/registerProcessor.d.ts.map +1 -0
  112. package/dist/plugins/blocks/registerProcessor.js +46 -0
  113. package/dist/plugins/blocks/registerProcessor.js.map +1 -0
  114. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +5 -0
  115. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts.map +1 -0
  116. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +148 -0
  117. package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js.map +1 -0
  118. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts +14 -0
  119. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.d.ts.map +1 -0
  120. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js +191 -0
  121. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPlugin.js.map +1 -0
  122. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts +14 -0
  123. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.d.ts.map +1 -0
  124. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js +102 -0
  125. package/dist/plugins/extensions/ExtensionsDirectoryLoaderEmitterPluginV1.js.map +1 -0
  126. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts +25 -0
  127. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.d.ts.map +1 -0
  128. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js +229 -0
  129. package/dist/plugins/extensions/ExtensionsDirectoryProcessingPlugin.js.map +1 -0
  130. package/dist/plugins/extensions/register.d.ts +6 -0
  131. package/dist/plugins/extensions/register.d.ts.map +1 -0
  132. package/dist/plugins/extensions/register.js +14 -0
  133. package/dist/plugins/extensions/register.js.map +1 -0
  134. package/dist/plugins/extensions/registerEmitter.d.ts +4 -0
  135. package/dist/plugins/extensions/registerEmitter.d.ts.map +1 -0
  136. package/dist/plugins/extensions/registerEmitter.js +18 -0
  137. package/dist/plugins/extensions/registerEmitter.js.map +1 -0
  138. package/dist/plugins/extensions/registerProcessor.d.ts +4 -0
  139. package/dist/plugins/extensions/registerProcessor.d.ts.map +1 -0
  140. package/dist/plugins/extensions/registerProcessor.js +42 -0
  141. package/dist/plugins/extensions/registerProcessor.js.map +1 -0
  142. package/dist/plugins/index.d.ts +11 -0
  143. package/dist/plugins/index.d.ts.map +1 -0
  144. package/dist/plugins/index.js +27 -0
  145. package/dist/plugins/index.js.map +1 -0
  146. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts +18 -0
  147. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.d.ts.map +1 -0
  148. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js +203 -0
  149. package/dist/plugins/plain/PlainEntrypointProcessingPlugin.js.map +1 -0
  150. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts +13 -0
  151. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.d.ts.map +1 -0
  152. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js +51 -0
  153. package/dist/plugins/plain/PlainEntrypointsConfigEmitterPlugin.js.map +1 -0
  154. package/dist/plugins/plain/register.d.ts +6 -0
  155. package/dist/plugins/plain/register.d.ts.map +1 -0
  156. package/dist/plugins/plain/register.js +14 -0
  157. package/dist/plugins/plain/register.js.map +1 -0
  158. package/dist/plugins/plain/registerEmitter.d.ts +4 -0
  159. package/dist/plugins/plain/registerEmitter.d.ts.map +1 -0
  160. package/dist/plugins/plain/registerEmitter.js +21 -0
  161. package/dist/plugins/plain/registerEmitter.js.map +1 -0
  162. package/dist/plugins/plain/registerProcessor.d.ts +4 -0
  163. package/dist/plugins/plain/registerProcessor.d.ts.map +1 -0
  164. package/dist/plugins/plain/registerProcessor.js +34 -0
  165. package/dist/plugins/plain/registerProcessor.js.map +1 -0
  166. package/dist/plugins/register.d.ts +3 -0
  167. package/dist/plugins/register.d.ts.map +1 -0
  168. package/dist/plugins/register.js +17 -0
  169. package/dist/plugins/register.js.map +1 -0
  170. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts +20 -0
  171. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.d.ts.map +1 -0
  172. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js +56 -0
  173. package/dist/plugins/special-assets/SpecialAssetsCollectorPlugin.js.map +1 -0
  174. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts +13 -0
  175. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.d.ts.map +1 -0
  176. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js +105 -0
  177. package/dist/plugins/special-assets/SpecialAssetsLoaderEmitterPlugin.js.map +1 -0
  178. package/dist/plugins/special-assets/register.d.ts +6 -0
  179. package/dist/plugins/special-assets/register.d.ts.map +1 -0
  180. package/dist/plugins/special-assets/register.js +14 -0
  181. package/dist/plugins/special-assets/register.js.map +1 -0
  182. package/dist/plugins/special-assets/registerEmitter.d.ts +4 -0
  183. package/dist/plugins/special-assets/registerEmitter.d.ts.map +1 -0
  184. package/dist/plugins/special-assets/registerEmitter.js +15 -0
  185. package/dist/plugins/special-assets/registerEmitter.js.map +1 -0
  186. package/dist/plugins/special-assets/registerProcessor.d.ts +4 -0
  187. package/dist/plugins/special-assets/registerProcessor.d.ts.map +1 -0
  188. package/dist/plugins/special-assets/registerProcessor.js +15 -0
  189. package/dist/plugins/special-assets/registerProcessor.js.map +1 -0
  190. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts +22 -0
  191. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.d.ts.map +1 -0
  192. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js +95 -0
  193. package/dist/plugins/unified-loader/UnifiedLoaderGenerator.js.map +1 -0
  194. package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts +24 -0
  195. package/dist/plugins/wpml-config/WPMLConfigBuilder.d.ts.map +1 -0
  196. package/dist/plugins/wpml-config/WPMLConfigBuilder.js +542 -0
  197. package/dist/plugins/wpml-config/WPMLConfigBuilder.js.map +1 -0
  198. package/dist/plugins/wpml-config/register.d.ts +6 -0
  199. package/dist/plugins/wpml-config/register.d.ts.map +1 -0
  200. package/dist/plugins/wpml-config/register.js +25 -0
  201. package/dist/plugins/wpml-config/register.js.map +1 -0
  202. package/dist/shared.d.ts +38 -0
  203. package/dist/shared.d.ts.map +1 -0
  204. package/dist/shared.js +163 -0
  205. package/dist/shared.js.map +1 -0
  206. package/dist/utils/error-helpers.d.ts +7 -0
  207. package/dist/utils/error-helpers.d.ts.map +1 -0
  208. package/dist/utils/error-helpers.js +73 -0
  209. package/dist/utils/error-helpers.js.map +1 -0
  210. package/dist/utils/index.d.ts +6 -0
  211. package/dist/utils/index.d.ts.map +1 -0
  212. package/dist/utils/index.js +22 -0
  213. package/dist/utils/index.js.map +1 -0
  214. package/dist/utils/misc.d.ts +4 -0
  215. package/dist/utils/misc.d.ts.map +1 -0
  216. package/dist/utils/misc.js +18 -0
  217. package/dist/utils/misc.js.map +1 -0
  218. package/dist/utils/path-helpers.d.ts +16 -0
  219. package/dist/utils/path-helpers.d.ts.map +1 -0
  220. package/dist/utils/path-helpers.js +115 -0
  221. package/dist/utils/path-helpers.js.map +1 -0
  222. package/dist/utils/pseudo-semaphore.d.ts +15 -0
  223. package/dist/utils/pseudo-semaphore.d.ts.map +1 -0
  224. package/dist/utils/pseudo-semaphore.js +77 -0
  225. package/dist/utils/pseudo-semaphore.js.map +1 -0
  226. package/dist/utils/type-helpers.d.ts +27 -0
  227. package/dist/utils/type-helpers.d.ts.map +1 -0
  228. package/dist/utils/type-helpers.js +33 -0
  229. package/dist/utils/type-helpers.js.map +1 -0
  230. package/dist/utils/writer-utils.d.ts +8 -0
  231. package/dist/utils/writer-utils.d.ts.map +1 -0
  232. package/dist/utils/writer-utils.js +35 -0
  233. package/dist/utils/writer-utils.js.map +1 -0
  234. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +73 -0
  235. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts.map +1 -0
  236. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +516 -0
  237. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js.map +1 -0
  238. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +57 -0
  239. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts.map +1 -0
  240. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +156 -0
  241. package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js.map +1 -0
  242. package/dist/wordpress-scripts-wrapper.d.ts +5 -0
  243. package/dist/wordpress-scripts-wrapper.d.ts.map +1 -0
  244. package/dist/wordpress-scripts-wrapper.js +444 -0
  245. package/dist/wordpress-scripts-wrapper.js.map +1 -0
  246. package/package.json +7 -3
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultRequestToExternal = defaultRequestToExternal;
4
+ exports.defaultRequestToExternalModule = defaultRequestToExternalModule;
5
+ exports.defaultRequestToHandle = defaultRequestToHandle;
6
+ exports.camelCaseDash = camelCaseDash;
7
+ exports.isConcatenatedModule = isConcatenatedModule;
8
+ exports.isEntrypoint = isEntrypoint;
9
+ const WORDPRESS_NAMESPACE = '@wordpress/';
10
+ const BUNDLED_PACKAGES = [
11
+ '@wordpress/admin-ui',
12
+ '@wordpress/dataviews',
13
+ '@wordpress/dataviews/wp',
14
+ '@wordpress/fields',
15
+ '@wordpress/global-styles-engine',
16
+ '@wordpress/global-styles-ui',
17
+ '@wordpress/grid',
18
+ '@wordpress/icons',
19
+ '@wordpress/interface',
20
+ '@wordpress/kebab-case',
21
+ '@wordpress/react-inert-value',
22
+ '@wordpress/style-runtime',
23
+ '@wordpress/sync',
24
+ '@wordpress/ui',
25
+ '@wordpress/undo-manager',
26
+ '@wordpress/views',
27
+ ];
28
+ /**
29
+ * Default request to global transformation
30
+ *
31
+ * Transform @wordpress dependencies:
32
+ * - request `@wordpress/api-fetch` becomes `[ 'wp', 'apiFetch' ]`
33
+ * - request `@wordpress/i18n` becomes `[ 'wp', 'i18n' ]`
34
+ *
35
+ * @param {string} request Module request (the module name in `import from`) to be transformed
36
+ * @return {string|string[]|undefined} The resulting external definition. Return `undefined`
37
+ * to ignore the request. Return `string|string[]` to map the request to an external.
38
+ */
39
+ function defaultRequestToExternal(request) {
40
+ switch (request) {
41
+ case 'moment':
42
+ return request;
43
+ case '@babel/runtime/regenerator':
44
+ return 'regeneratorRuntime';
45
+ case 'lodash':
46
+ case 'lodash-es':
47
+ return 'lodash';
48
+ case 'jquery':
49
+ return 'jQuery';
50
+ case 'react':
51
+ return 'React';
52
+ case 'react-dom':
53
+ case 'react-dom/client':
54
+ return 'ReactDOM';
55
+ case 'react/jsx-runtime':
56
+ case 'react/jsx-dev-runtime':
57
+ return 'ReactJSXRuntime';
58
+ }
59
+ if (request.includes('react-refresh/runtime')) {
60
+ return 'ReactRefreshRuntime';
61
+ }
62
+ if (BUNDLED_PACKAGES.includes(request)) {
63
+ return undefined;
64
+ }
65
+ if (request.startsWith(WORDPRESS_NAMESPACE)) {
66
+ return [
67
+ 'wp',
68
+ camelCaseDash(request.substring(WORDPRESS_NAMESPACE.length)),
69
+ ];
70
+ }
71
+ return undefined;
72
+ }
73
+ /**
74
+ * Default request to external module transformation
75
+ *
76
+ * Currently only @wordpress/interactivity and `@wordpress/interactivity-router`
77
+ * are supported.
78
+ *
79
+ * Do not use the boolean shorthand here, it's only handled for the
80
+ * `requestToExternalModule` option.
81
+ *
82
+ * @param {string} request Module request (the module name in `import from`) to be transformed
83
+ * @return {string|undefined} The resulting external definition.
84
+ * - Return `undefined` to ignore the request (do not externalize).
85
+ * - Return `string` to map the request to an external.
86
+ * - Return `Error` to emit an error.
87
+ */
88
+ function defaultRequestToExternalModule(request) {
89
+ if (request === '@wordpress/interactivity') {
90
+ // This is a special case. Interactivity does not support dynamic imports at
91
+ // this time. We add the external "module" type to indicate that webpack
92
+ // should externalize this as a module (instead of our default `import()`
93
+ // external type) which forces @wordpress/interactivity imports to be
94
+ // hoisted to static imports.
95
+ return `module ${request}`;
96
+ }
97
+ switch (request) {
98
+ case '@wordpress/interactivity-router':
99
+ case '@wordpress/a11y':
100
+ return `import ${request}`;
101
+ }
102
+ const isWordPressScript = Boolean(defaultRequestToExternal(request));
103
+ if (isWordPressScript) {
104
+ throw new Error(`Attempted to use WordPress script in a module: ${request}, which is not supported yet.`);
105
+ }
106
+ return undefined;
107
+ }
108
+ /**
109
+ * Default request to WordPress script handle transformation
110
+ *
111
+ * Transform @wordpress dependencies:
112
+ * - request `@wordpress/i18n` becomes `wp-i18n`
113
+ * - request `@wordpress/escape-html` becomes `wp-escape-html`
114
+ *
115
+ * @param {string} request Module request (the module name in `import from`) to be transformed
116
+ * @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
117
+ * to use the same name as the module.
118
+ */
119
+ function defaultRequestToHandle(request) {
120
+ switch (request) {
121
+ case '@babel/runtime/regenerator':
122
+ return 'regenerator-runtime';
123
+ case 'lodash-es':
124
+ return 'lodash';
125
+ case 'react-dom/client':
126
+ return 'react-dom';
127
+ case 'react/jsx-runtime':
128
+ return 'react-jsx-runtime';
129
+ }
130
+ if (request.includes('react-refresh/runtime')) {
131
+ return 'wp-react-refresh-runtime';
132
+ }
133
+ if (request.startsWith(WORDPRESS_NAMESPACE)) {
134
+ return 'wp-' + request.substring(WORDPRESS_NAMESPACE.length);
135
+ }
136
+ return undefined;
137
+ }
138
+ /**
139
+ * Given a string, returns a new string with dash separators converted to
140
+ * camelCase equivalent. This is not as aggressive as `_.camelCase` in
141
+ * converting to uppercase, where Lodash will also capitalize letters
142
+ * following numbers.
143
+ *
144
+ * @param {string} string Input dash-delimited string.
145
+ * @return {string} Camel-cased string.
146
+ */
147
+ function camelCaseDash(string) {
148
+ return string.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
149
+ }
150
+ function isConcatenatedModule(module) {
151
+ return 'modules' in module && Array.isArray(module.modules);
152
+ }
153
+ function isEntrypoint(group) {
154
+ return !!group && group.constructor.name === 'Entrypoint';
155
+ }
156
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/wordpress-ports/dependency-extraction-webpack-plugin/util.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+ import type { Configuration } from "webpack";
2
+ import { type PlauditWordpressWebpackConfig } from "./api";
3
+ export = _default;
4
+ declare function _default(config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration): Promise<Configuration[]>;
5
+ //# sourceMappingURL=wordpress-scripts-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wordpress-scripts-wrapper.d.ts","sourceRoot":"","sources":["../src/wordpress-scripts-wrapper.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAW,aAAa,EAAC,MAAM,SAAS,CAAC;AAGrD,OAAO,EAIN,KAAK,6BAA6B,EASlC,MAAM,OAAO,CAAC;;0BAsWC,MAAM,EAAE,6BAA6B,EAAE,aAAa,GAAE,aAAa,EAAE,GAAC,aAAmE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC"}
@@ -0,0 +1,444 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
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"));
15
+ const AdditionalDependencyInjectorPlugin_1 = require("./plugins/AdditionalDependencyInjectorPlugin");
16
+ const dependency_extraction_webpack_plugin_config_builder_1 = require("./plugins/dependency-extraction-webpack-plugin-config-builder");
17
+ const MiniCSSExtractPluginErrorCleaner_1 = require("./plugins/MiniCSSExtractPluginErrorCleaner");
18
+ const PackageConfigSanityChecker_1 = require("./plugins/PackageConfigSanityChecker");
19
+ const RootCoordinatorPluginImpl_1 = require("./plugins/RootCoordinatorPluginImpl");
20
+ const register_1 = require("./plugins/register");
21
+ const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin");
22
+ const shared_1 = require("./shared");
23
+ const utils_1 = require("./utils");
24
+ function testForDuplicatedEntryPaths(sources) {
25
+ const seenPaths = (0, utils_1.groupEntrypointsByAssetName)(Array.isArray(sources)
26
+ ? sources.map(s => typeof s === 'string' ? s : s[1].destination)
27
+ : Object.values(sources).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
28
+ let projectPrefix;
29
+ let duplicatedPaths = "";
30
+ for (const sameNamePaths of Object.values(seenPaths)) {
31
+ if ((0, utils_1.arrayHasAtLeastLength)(sameNamePaths, 2)) {
32
+ if (projectPrefix === undefined) {
33
+ for (let p = process.cwd(); p.length > 1; p = (0, node_path_1.dirname)(p)) {
34
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(p, "docker-compose.yml"))) {
35
+ projectPrefix = new RegExp(`^${p}`);
36
+ break;
37
+ }
38
+ }
39
+ if (projectPrefix === undefined) {
40
+ projectPrefix = /^/;
41
+ }
42
+ }
43
+ duplicatedPaths += `\n* ${(0, node_path_1.dirname)(sameNamePaths[0]).replace(projectPrefix, '')}/[${sameNamePaths.map(p => (0, node_path_1.basename)(p)).join(', ')}]`;
44
+ }
45
+ }
46
+ if (duplicatedPaths.length !== 0) {
47
+ console.error(`Encountered multiple paths that produce the same effective bundle name:${duplicatedPaths}`);
48
+ process.exit(1);
49
+ }
50
+ }
51
+ function buildVerifiedConfig(config) {
52
+ const baseDir = process.cwd();
53
+ config = (0, shared_1.applyStandards)(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
+ }
60
+ let outputDir = config.outputDir ?? "";
61
+ if ((0, shared_1.shouldWriteDistDev)({ outputDir, useUnifiedLoader, omitDistDev })) {
62
+ outputDir += "-dev";
63
+ }
64
+ let srcPrefixes;
65
+ const trailingSlashedSrcDir = srcDir && !srcDir.endsWith("/") ? srcDir + "/" : srcDir;
66
+ if (config.srcPrefixes === undefined) {
67
+ srcPrefixes = srcDir ? [trailingSlashedSrcDir] : ["src/"];
68
+ }
69
+ else {
70
+ srcPrefixes = (srcDir && !config.srcPrefixes.includes(trailingSlashedSrcDir) ? [...config.srcPrefixes, trailingSlashedSrcDir] : config.srcPrefixes);
71
+ }
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");
78
+ }
79
+ // Only the lazyLoader emitters read this, so an absence of package metadata is not worth failing a build
80
+ // over: php-writer treats an empty namespace as "emit no namespace", which is what we did before 3.10.0
81
+ const targetNamespace = config.targetNamespace || deriveDefaultHandlePrefixFromComposerJsonOrThemeName(utils_1.camelCaseForPHPLabels, true) || "";
82
+ let variablesFilePath;
83
+ const currentVariables = rawVariables ?? {};
84
+ if (!rawVariables) {
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];
86
+ }
87
+ let extensionsVersion = config.extensionsVersion ?? 1;
88
+ if (extensionsVersion === 2) {
89
+ extensionsVersion = 3; // Version 3 is a backwards-compatible upgrade of version 2, so we can automatically upgrade everything
90
+ }
91
+ const cfg = {
92
+ currentVariables, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries,
93
+ useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix,
94
+ useUnifiedLoader, includePostInitFallback, omitDistDev, onlyRunPostCSSOnPCSS, targetNamespace, useBlockSupportsAsThemeJsonDefaults,
95
+ pluginConfig
96
+ };
97
+ // Destination -> source map
98
+ const allocatedDestinations = {};
99
+ const { staticEntrypoints, dynamicEntrypoints } = (0, entrypoint_resolution_logic_1.resolveAllConfigLevelEntrypoints)(cfg, config.src, baseDir, allocatedDestinations, srcPrefixes);
100
+ const partiallyVerifiedSources = [...staticEntrypoints, ...dynamicEntrypoints];
101
+ const dynamicEffectiveDestinationsWithExpectedNaiveDuplicates = partiallyVerifiedSources
102
+ .filter(entry => !entry[1].staticallyDeclaredDestination)
103
+ .map(entry => entry[1].effectiveDestination)
104
+ .reduce((a, dest) => {
105
+ a[dest] = (a[dest] !== undefined); // If it's undefined, then this is the first instance, otherwise, it's not the first instance and, therefore, is expected to be a duplicate
106
+ return a;
107
+ }, {});
108
+ const sources = partiallyVerifiedSources
109
+ .map(entry => finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpectedNaiveDuplicates, allocatedDestinations));
110
+ testForDuplicatedEntryPaths(sources);
111
+ return cfg.outputDir ? { cfg, sources } : withDerivedOutputDir(cfg, sources);
112
+ }
113
+ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpectedNaiveDuplicates, allocatedDestinations) {
114
+ if (entry[1].staticallyDeclaredDestination) {
115
+ return entry;
116
+ }
117
+ const extension = (0, node_path_1.extname)(entry[1].destination);
118
+ const filename = dynamicEffectiveDestinationsWithExpectedNaiveDuplicates[entry[1].effectiveDestination]
119
+ ? entry[1].effectiveDestination + (extension === '.css' ? "_style" : "_script")
120
+ : entry[1].effectiveDestination;
121
+ let count = 0, derivedDestination = filename + extension;
122
+ while (derivedDestination in allocatedDestinations && allocatedDestinations[derivedDestination] !== entry[0]) {
123
+ derivedDestination = `${filename}_${++count}${extension}`; // We don't want to add deduplication indexes unless absolutely necessary
124
+ }
125
+ entry[1].additionalDependencies?.sort();
126
+ allocatedDestinations[derivedDestination] = entry[0];
127
+ return [entry[0], { ...entry[1], destination: derivedDestination }];
128
+ }
129
+ /**
130
+ * TODO: WTF is the bot on about here?
131
+ * Derives a prefix from whichever piece of package metadata sits next to the config. Returns undefined
132
+ * when there is nothing to derive from at all — a caller that cannot proceed without one says so itself,
133
+ * because the ones that can (see `targetNamespace`) would otherwise fail builds that never needed it. A
134
+ * file that *is* present but unusable still throws, since that is a misconfiguration rather than an absence.
135
+ */
136
+ function deriveDefaultHandlePrefixFromComposerJsonOrThemeName(stringTransformer, keepPlauditSep = false) {
137
+ let composerJson;
138
+ try {
139
+ composerJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(process.cwd(), "composer.json"), 'utf-8'));
140
+ }
141
+ catch {
142
+ // Then composer.json doesn't exist
143
+ return deriveDefaultHandlePrefixFromThemeName(stringTransformer);
144
+ }
145
+ if (typeof composerJson !== 'object' || typeof composerJson.name !== 'string' || !composerJson.name) {
146
+ throw new ReferenceError("targetHandlePrefix was not set and the adjacent composer.json file does not have a valid name in it");
147
+ }
148
+ return stringTransformer(keepPlauditSep ? composerJson.name.replace(/plaudit\/plaudit-/, 'plaudit/') : composerJson.name.replace(/plaudit\/plaudit/, 'plaudit'));
149
+ }
150
+ function deriveDefaultHandlePrefixFromThemeName(stringTransformer) {
151
+ const styleFilePath = (0, node_path_1.join)(process.cwd(), "style.css");
152
+ if (!(0, node_fs_1.existsSync)(styleFilePath)) {
153
+ // Then there is no package metadata to derive anything from
154
+ return undefined;
155
+ }
156
+ const styleFileContents = (0, node_fs_1.readFileSync)(styleFilePath, 'utf-8');
157
+ const themeName = /^\W*Theme\s*Name:\s*(.+)$/im.exec(styleFileContents)?.[1]?.trim();
158
+ if (!themeName) {
159
+ throw new ReferenceError("targetHandlePrefix was not set and the adjacent style.css file does not have a valid name in it");
160
+ }
161
+ return stringTransformer(themeName);
162
+ }
163
+ function withDerivedOutputDir(cfg, sources) {
164
+ const destinations = sources.map(([_, { destination }]) => destination.split(/[/\\]/g));
165
+ if (!(0, utils_1.arrayHasAtLeastLength)(destinations, 2)) {
166
+ return { cfg, sources };
167
+ }
168
+ const commonParent = destinations[0][0];
169
+ for (const destination of destinations) {
170
+ if (destination[0] !== commonParent) {
171
+ return { cfg, sources };
172
+ }
173
+ }
174
+ return {
175
+ cfg: { ...cfg, outputDir: commonParent },
176
+ sources: sources.map(([src, dest]) => {
177
+ return [src, { ...dest, destination: dest.destination.substring(commonParent.length + 1) }];
178
+ })
179
+ };
180
+ }
181
+ let forkTsCheckerInstalled = false;
182
+ function isTypeScriptSourceFile(file) {
183
+ return /\.[cm]?tsx?$/i.test(file.split('?')[0] ?? '');
184
+ }
185
+ const prefixes = ['c', 'm', ''];
186
+ const suffixes = ['x', ''];
187
+ const tsExtensions = prefixes.map(prefix => prefix + "ts").flatMap(name => suffixes.map(suffix => name + suffix));
188
+ function handleDisablingTSCheckerIfNecessary(srcRoot, scriptExtension, plugins) {
189
+ if (process.env["NO_TS_CHECKER"] === "true" || forkTsCheckerInstalled) {
190
+ return;
191
+ }
192
+ const include = [];
193
+ for (const sr of (Array.isArray(srcRoot) ? srcRoot : [srcRoot])) {
194
+ if ((0, node_path_1.extname)(sr).length === 0) {
195
+ include.push(...tsExtensions.map(tsExt => (0, node_path_1.join)(sr, "**", `*.${tsExt}`)));
196
+ }
197
+ else if ((0, api_1.scriptOrStyleTest)(sr, scriptExtension) === "script") {
198
+ include.push(sr);
199
+ }
200
+ }
201
+ if (include.length === 0) {
202
+ return;
203
+ }
204
+ forkTsCheckerInstalled = true;
205
+ let logTsStatus = true;
206
+ plugins.push({
207
+ apply(compiler) {
208
+ compiler.hooks.watchRun.tap('PlauditForkTsCheckerCssQuiet', watchingCompiler => {
209
+ const changed = [
210
+ ...(watchingCompiler.modifiedFiles ?? []),
211
+ ...(watchingCompiler.removedFiles ?? [])
212
+ ];
213
+ logTsStatus = changed.length === 0 || changed.some(isTypeScriptSourceFile);
214
+ });
215
+ }
216
+ });
217
+ plugins.push(new fork_ts_checker_webpack_plugin_1.default({
218
+ async: true,
219
+ logger: {
220
+ log(message) {
221
+ if (!logTsStatus) {
222
+ return;
223
+ }
224
+ console.log(message);
225
+ },
226
+ error(message) {
227
+ console.error(message);
228
+ }
229
+ },
230
+ typescript: {
231
+ diagnosticOptions: {
232
+ semantic: true,
233
+ syntactic: true,
234
+ },
235
+ configOverwrite: {
236
+ include,
237
+ compilerOptions: {
238
+ skipLibCheck: true
239
+ }
240
+ }
241
+ },
242
+ issue: {
243
+ exclude(issue) {
244
+ return issue.code === 'TS18003';
245
+ }
246
+ }
247
+ }));
248
+ }
249
+ function buildCommonPluginConfig(coordinator, webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize) {
250
+ const plugins = webpackConfig.plugins?.filter(v => !!v)
251
+ .filter(plugin => plugin.constructor.name !== 'RtlCssPlugin')
252
+ .filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
253
+ .map(plugin => {
254
+ if (plugin.constructor.name === 'MiniCssExtractPlugin') {
255
+ return new plugin.constructor({
256
+ filename(pd) {
257
+ const name = pd.chunk?.name?.replaceAll(/__[a-zA-Z0-9]+__/g, ""); // This removes the prefix that the cache group adds
258
+ return name ? `${name}.css` : "[name].css";
259
+ }
260
+ });
261
+ }
262
+ return plugin;
263
+ })
264
+ ?? [];
265
+ plugins.unshift(new PackageConfigSanityChecker_1.PackageConfigSanityChecker(), coordinator);
266
+ if (bundleAnalyzer) {
267
+ plugins.unshift(new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static', openAnalyzer: bundleAnalyzer !== 'no-auto-open' }));
268
+ }
269
+ plugins.push(new webpack_remove_empty_scripts_1.default({
270
+ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
271
+ extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'],
272
+ ignore: /block\.json/
273
+ }), new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
274
+ plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
275
+ // We have to use constructor.name here the version desyncs can result in multiple equivalent versions kicking around
276
+ const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin.constructor.name === 'DependencyExtractionWebpackPlugin');
277
+ if (dependencyExtractionPluginIndex === -1) {
278
+ console.error((0, shared_1.dedent) `
279
+ Unable to find the DependencyExtractionWebpackPlugin.
280
+ If this is your first time seeing this error, please run: pnpm up && pnpm dedupe && pnpm up
281
+ Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.
282
+ `);
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.");
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");
285
+ }
286
+ plugins[dependencyExtractionPluginIndex] = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(config.externals, assumeGlobalizedPlauditLibraries, externalize);
287
+ try {
288
+ const { PlauditDevPlugin } = require("@plaudit/dev-webpack-plugin");
289
+ plugins.push(new PlauditDevPlugin(config));
290
+ }
291
+ catch { }
292
+ return {
293
+ plugins
294
+ };
295
+ }
296
+ async function commonConfigProcessingPrep(wrapperManager, config, webpackConfig, hasAnyNonModuleBuilds) {
297
+ const processingModules = webpackConfig.output?.module ?? false;
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);
300
+ let currentVariables = config.currentVariables;
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);
305
+ return {
306
+ entrypointFields, fixedRules, processingModules, scriptExtension,
307
+ updateCurrentVariables: (value) => {
308
+ return currentVariables = value;
309
+ }
310
+ };
311
+ }
312
+ function destToKey(dest) {
313
+ const externalize = typeof dest.externalize === 'object' && dest.externalize !== undefined
314
+ ? (Array.isArray(dest.externalize) ? dest.externalize.join("_") : (dest.externalize ? Object.entries(dest.externalize).flat().sort().join() : "undefined"))
315
+ : dest.externalize?.toString() ?? "undefined";
316
+ return [dest.assumeGlobalizedPlauditLibraries, dest.bundleAnalyzer, externalize].join("~");
317
+ }
318
+ async function processIndividualWebpackConfig(wrapperManager, coordinator, config, webpackConfig, sources, canClean, hasAnyNonModuleBuilds) {
319
+ if (webpackConfig.output?.module) {
320
+ // This ensures that module files are emitted as module files
321
+ webpackConfig = {
322
+ name: "base:modules",
323
+ ...webpackConfig,
324
+ output: {
325
+ ...webpackConfig.output,
326
+ filename: '[name].mjs',
327
+ chunkFilename: '[name].mjs?ver=[chunkhash]',
328
+ }
329
+ };
330
+ }
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 = {};
337
+ const allSrcRoots = sources.map(([src, dest]) => {
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
+ }
351
+ const srcIsDirectory = !Array.isArray(srcRoot) && (0, node_fs_1.lstatSync)(srcRoot, { throwIfNoEntry: false })?.isDirectory();
352
+ if (srcIsDirectory === undefined) {
353
+ return undefined;
354
+ }
355
+ return { srcRoots, src, dest, srcRoot, srcIsDirectory };
356
+ }).filter(a => a !== undefined);
357
+ const groupedSrcRoots = {};
358
+ for (const entry of allSrcRoots) {
359
+ const key = destToKey(entry.dest);
360
+ (groupedSrcRoots[key] ?? (groupedSrcRoots[key] = [])).push(entry);
361
+ }
362
+ const batches = Object.values(groupedSrcRoots).filter(utils_1.hasAtLeastOneItem);
363
+ return Promise.all(batches.map(async (currentBatch) => {
364
+ const { bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize } = currentBatch[0].dest;
365
+ const { plugins } = buildCommonPluginConfig(coordinator, webpackConfig, config, bundleAnalyzer, assumeGlobalizedPlauditLibraries, externalize);
366
+ if (!processingModules || !hasAnyNonModuleBuilds) {
367
+ handleDisablingTSCheckerIfNecessary(currentBatch.flatMap(a => a.srcRoots), scriptExtension, plugins);
368
+ }
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);
379
+ }
380
+ (0, utils_1.emitError)(`Encountered an unsupported source type: ${item.dest.sourceType}. The supported source types are ${supportedSourceTypes}`);
381
+ continue;
382
+ }
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);
387
+ continue;
388
+ }
389
+ if (Array.isArray(destinationHandler.plugin)) {
390
+ plugins.push(...destinationHandler.plugin);
391
+ }
392
+ else if (destinationHandler.plugin !== undefined) {
393
+ plugins.push(destinationHandler.plugin);
394
+ }
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
+ }
411
+ }
412
+ }
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
+ }));
417
+ }
418
+ module.exports = async (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) => {
419
+ const { cfg, sources } = buildVerifiedConfig(config);
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)) {
431
+ webpackConfig = webpackConfig[0];
432
+ }
433
+ if (Array.isArray(webpackConfig)) {
434
+ const hasNonModuleCompiler = webpackConfig.some(cfg => !cfg.output?.module);
435
+ return finalizer((await Promise.all(webpackConfig.toSorted((a, b) => {
436
+ if (a.output?.module) {
437
+ return b.output?.module ? 0 : -1;
438
+ }
439
+ return b.output?.module ? 1 : 0;
440
+ }).map(wpCfg => processIndividualWebpackConfig(wrapperManager, coordinator, cfg, wpCfg, sources, false, hasNonModuleCompiler)))).flat());
441
+ }
442
+ return finalizer(await processIndividualWebpackConfig(wrapperManager, coordinator, cfg, webpackConfig, sources, true, false));
443
+ };
444
+ //# sourceMappingURL=wordpress-scripts-wrapper.js.map