@plaudit/webpack-extensions 2.30.2 → 2.31.1

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.
@@ -6,6 +6,13 @@ interface AdvancedOutputConfig {
6
6
  additionalDependencies?: string[];
7
7
  directoryLayout?: 'blocks' | 'extensions';
8
8
  }
9
+ type IndividualExternalDepConfig = string | {
10
+ import: string;
11
+ handle: string;
12
+ };
13
+ type Externals = {
14
+ [dep: string]: IndividualExternalDepConfig;
15
+ };
9
16
  type PlauditWordpressWebpackConfig = {
10
17
  standaloneBlocks?: boolean;
11
18
  variables?: Record<string, any>;
@@ -15,12 +22,7 @@ type PlauditWordpressWebpackConfig = {
15
22
  postcss?: {
16
23
  functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions['functions'];
17
24
  };
18
- externals?: {
19
- [dep: string]: string | {
20
- import: string;
21
- handle: string;
22
- };
23
- };
25
+ externals?: Externals;
24
26
  };
25
27
  declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
26
28
  export = _default;
@@ -232,6 +232,48 @@ function parseEntrypointsJSON(dir) {
232
232
  });
233
233
  }
234
234
  }
235
+ function makeDependencyExtractionPlugin(externals) {
236
+ const exactExternals = {};
237
+ const suffixExternals = [];
238
+ for (const [key, value] of Object.entries(externals)) {
239
+ if (key.startsWith("*/")) {
240
+ suffixExternals.push([key.substring(1), typeof value === 'string' ? { import: value, handle: key.substring(2) } : value]);
241
+ }
242
+ else {
243
+ exactExternals[key] = value;
244
+ }
245
+ }
246
+ const resolvePossibleExternal = (request) => {
247
+ if (request in exactExternals) {
248
+ return exactExternals[request];
249
+ }
250
+ for (const [key, value] of suffixExternals) {
251
+ if (request.endsWith(key)) {
252
+ return value;
253
+ }
254
+ }
255
+ return undefined;
256
+ };
257
+ return new dependency_extraction_webpack_plugin_1.default({
258
+ requestToExternal(request) {
259
+ const possibleExternal = resolvePossibleExternal(request);
260
+ if (typeof possibleExternal === 'string') {
261
+ return possibleExternal;
262
+ }
263
+ else if (possibleExternal !== undefined) {
264
+ return possibleExternal['import'];
265
+ }
266
+ return undefined;
267
+ },
268
+ requestToHandle(request) {
269
+ const possibleExternal = resolvePossibleExternal(request);
270
+ if (possibleExternal !== undefined && typeof possibleExternal !== 'string') {
271
+ return possibleExternal.handle;
272
+ }
273
+ return undefined;
274
+ }
275
+ });
276
+ }
235
277
  function processIndividualWebpackConfig(config, webpackConfig, sources) {
236
278
  let scriptExtension; // This is only used in non-block contexts. It might not actually be necessary, but it is good to have
237
279
  let entrypointFields;
@@ -313,29 +355,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
313
355
  console.error("Cannot apply externals when they have been disabled via CLI flag.");
314
356
  }
315
357
  else {
316
- plugins[pluginIndex] = new dependency_extraction_webpack_plugin_1.default({
317
- requestToExternal(request) {
318
- const possibleExternal = externals[request];
319
- if (typeof possibleExternal === 'string') {
320
- return possibleExternal;
321
- }
322
- else if (possibleExternal !== undefined) {
323
- return possibleExternal['import'];
324
- }
325
- else {
326
- return undefined;
327
- }
328
- },
329
- requestToHandle(request) {
330
- const possibleExternal = externals[request];
331
- if (possibleExternal !== undefined && typeof possibleExternal !== 'string') {
332
- return typeof possibleExternal.handle;
333
- }
334
- else {
335
- return request;
336
- }
337
- }
338
- });
358
+ plugins[pluginIndex] = makeDependencyExtractionPlugin(externals);
339
359
  }
340
360
  }
341
361
  if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.30.2",
3
+ "version": "2.31.1",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",
@@ -36,6 +36,7 @@
36
36
  "@plaudit/postcss-silent-extend": "^3.0.0",
37
37
  "@plaudit/postcss-strip-units": "^3.0.0",
38
38
  "@plaudit/postcss-variables": "^1.0.0",
39
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.7.0",
39
40
  "@wordpress/scripts": "^28.3.0",
40
41
  "autoprefixer": "^10.4.19",
41
42
  "browser-sync": "^3.0.2",