@plaudit/webpack-extensions 2.94.0 → 2.95.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.
package/CHANGELOG.md CHANGED
@@ -60,6 +60,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
60
60
  - Legacy PostCSS features that have been integrated into modern CSS
61
61
  - `@extends` support
62
62
 
63
+ ## [2.95.0] - 2026-08-04
64
+ ### Added
65
+ - Logic so that files and directories with names equal to "example" or "examples" or that include "example" as a name segment are skipped
66
+ - This is done to allow us to include example files
67
+ - Updated the user guide with this information
68
+
69
+ ## [2.94.1] - 2026-07-20
70
+ ### Fixed
71
+ - A bug that caused all styles bound for editor use to be emitted as inline CSS
72
+
63
73
  ## [2.94.0] - 2026-07-17
64
74
  ### Changed
65
75
  - The `add_editor_style()` enqueue path to use `block_editor_settings_all` to avoid a litany of bugs courtesy of WordPress's high-quality code
package/USER-GUIDE.md CHANGED
@@ -104,7 +104,7 @@ However, if you need to do something unusual or just want to know what everythin
104
104
  - Any time that `dist` is referenced in a path, it should be replaced with the value of `outputDir` in your WebPack file
105
105
  - As with `src`, the value of `outputDir` *should be* `dist`; however, this might not be the case in some inherited or older code
106
106
  - Keys in the `src` *object* are all assumed to be paths relative to `srcDir` if it is specified or the folder in which the `webpack.config.js` file is located if it is not specified
107
- - Paths in values in the `src` *object* are all assumed to be paths relative to `outputDir` if it is specified or the folder in which the `webpack.config.js` file is located if it is not specified
107
+ - Paths in *values* in the `src` object are all assumed to be paths relative to `outputDir` if it is specified or the folder in which the `webpack.config.js` file is located if it is not specified
108
108
  - All file names are informational placeholders. They can be whatever you want provided that they are web-safe (basically, don't do things like calling the email address block "✉️" and you'll be fine)
109
109
 
110
110
  ### Examples
@@ -117,6 +117,10 @@ However, if you need to do something unusual or just want to know what everythin
117
117
  - All folder and file names should be in kebab-case
118
118
  - Assets *should not* be in the root of the `src` folder. Assets that aren't block- or extension-bound should be in the `site` folder (or in a folder named after where they'll be used like, `admin` or `map-page`)
119
119
 
120
+ ### Enforced Naming Conventions
121
+ - Directory and file names that start with a "~" are interpreted as "backup code" and are, therefore, not built.
122
+ - File and directory names that are equal to "example" or "examples", or have "example" as a name segment (see [Location-Encoding Filenames](#location-encoding-filenames) for details on what a name-segment is) are treated as example code and are also not built
123
+
120
124
  ### Blocks
121
125
  - Block folder names *should* match the local portion of their name (ex: `plaudit-query-loop-maps/address-wrapper` should be stored in `address-wrapper`)
122
126
 
@@ -354,16 +358,17 @@ Notes on how to read the following table:
354
358
  - `(-|=)` means "this can be either a dash or an equal sign"
355
359
  - Pipe-separated items in parentheses means "any one of these items can go here"
356
360
 
357
- | Name | Token | Usage |
358
- |--------------------|-------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
359
- | Enqueuing Location | `(enqueuing-location)[(-\|=)priority]` | This is a special section that is actually a collection of values. See the [Enqueuing Location](#enqueuing-location) section for more details |
360
- | Type Override | `script`, `style`, `script-module` | Can be used to override the detected of the asset. Must be the first token in the filename; if used directly, it is shorthand for `both-(Type Override)` |
361
- | Inline | `inline[(-\|=)position]`, `strategy(-\|=)inline[-position]` | Indicates that the script should be inlined. `position` can be either `before` or `after` |
362
- | Strategy | `lazy\|eager`, `strategy(-\|=)(lazy\|eager\|defer\|async)` | Controls the loading strategy. Lazy and eager have shorthand while the remaining values must be prefixed with `strategy` |
363
- | Fetch Priority | `fetchpriority(-\|=)(low\|high\|auto)` | Controls the fetchpriority property; `auto` is the default |
364
- | In Footer | `in-footer`, `in_footer` | Sets the `in_footer` value to `true`; incompatible with `in-header` |
365
- | In Header | `in-header`, `in_header` | Sets the `in_footer` value to `false`; incompatible with `in-footer` |
366
- | Extension | `([ps]?c\|sa)ss`, `m?[jt]sx?` | This determines the type unless it is overridden. This **MUST** be the last token in the name (it is the file extension) |
361
+ | Name | Token | Usage |
362
+ |---------------------|-------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
363
+ | Enqueuing Location | `(enqueuing-location)[(-\|=)priority]` | This is a special section that is actually a collection of values. See the [Enqueuing Location](#enqueuing-location) section for more details |
364
+ | Type Override | `script`, `style`, `script-module` | Can be used to override the detected of the asset. Must be the first token in the filename; if used directly, it is shorthand for `both-(Type Override)` |
365
+ | Inline | `inline[(-\|=)position]`, `strategy(-\|=)inline[-position]` | Indicates that the script should be inlined. `position` can be either `before` or `after` |
366
+ | Strategy | `lazy\|eager`, `strategy(-\|=)(lazy\|eager\|defer\|async)` | Controls the loading strategy. Lazy and eager have shorthand while the remaining values must be prefixed with `strategy` |
367
+ | Fetch Priority | `fetchpriority(-\|=)(low\|high\|auto)` | Controls the fetchpriority property; `auto` is the default |
368
+ | In Footer | `in-footer`, `in_footer` | Sets the `in_footer` value to `true`; incompatible with `in-header` |
369
+ | In Header | `in-header`, `in_header` | Sets the `in_footer` value to `false`; incompatible with `in-footer` |
370
+ | Extension | `([ps]?c\|sa)ss`, `m?[jt]sx?` | This determines the type unless it is overridden. This **MUST** be the last token in the name (it is the file extension) |
371
+ | Example Code Marker | `example` | This informs the build system that the file contains example code and, therefore, should not be build |
367
372
 
368
373
  ### Enqueuing Location
369
374
  If this is the first token, it can be suffixed with `-script`, `-style`, or `-script-module` to override the type.
@@ -1,15 +1,17 @@
1
1
  import { Compilation } from "webpack";
2
2
  import type WebpackRemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts";
3
3
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
4
- import { BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, InlinedAsset, ParsedAssetJsonProvider, ParsedAssetsJson, ScriptArgsObject, VerifiedAdvancedOutputConfig } from "../shared";
4
+ import { AssetMetaSegment, BlockEntrypointInfo, FileSegmentBlockEntrypointInfo, ParsedAssetJsonProvider, ParsedAssetsJson, ScriptArgsObject, VerifiedAdvancedOutputConfig } from "../shared";
5
5
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
6
6
  type WorkableBlockEntrypointInfo = Omit<FileSegmentBlockEntrypointInfo, 'originalValue' | 'pathQueryParameters'> & Partial<Pick<FileSegmentBlockEntrypointInfo, 'originalValue'>> & {
7
7
  outputPath: string;
8
8
  assetData: ParsedAssetsJson[string];
9
9
  hash: string;
10
10
  scriptArgsObject: ScriptArgsObject | undefined;
11
- inlinedAsset: InlinedAsset | undefined;
12
- };
11
+ } & (AssetMetaSegment | {
12
+ inlinedAsset?: undefined;
13
+ assetContents?: string;
14
+ });
13
15
  type CollatedWorkableBlockInfo = Record<string, {
14
16
  sourcePath?: string;
15
17
  workableBlockEntrypointsInfo: WorkableBlockEntrypointInfo[];
@@ -65,8 +65,8 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
65
65
  .filter((item) => item[1] !== '')
66
66
  .map(([file, assetType]) => {
67
67
  const enqueuingFlags = (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, metadata.enqueuingFlags, this.dest.enqueuingFlags);
68
- const { scriptArgsObject, inlinedAsset } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
69
- if (inlinedAsset !== undefined) {
68
+ const { scriptArgsObject, assetMeta } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, enqueuingFlags);
69
+ if (assetMeta?.inlinedAsset !== undefined) {
70
70
  staticallyLoadedEntrypoints.push(file);
71
71
  }
72
72
  const wasOriginallyAStyleField = (0, shared_1.isStyleField)(metadata.entrypointField);
@@ -75,10 +75,10 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
75
75
  const entrypointField = (0, shared_1.convertEntrypointFieldForAssetType)(metadata.entrypointField, assetType);
76
76
  return {
77
77
  ...metadata, outputPath, assetData, originalValue: undefined, hash: entrypointChunk.hash ?? "",
78
- entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject, inlinedAsset
78
+ entrypointField, handleGroup: (0, shared_1.getHandleGroup)(entrypointField), scriptArgsObject, ...assetMeta
79
79
  };
80
80
  }
81
- return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject, inlinedAsset };
81
+ return { ...metadata, outputPath, assetData, hash: entrypointChunk.hash ?? "", scriptArgsObject, ...assetMeta };
82
82
  });
83
83
  if (applicableBlockJsonFiles[epBlockJson]) {
84
84
  applicableBlockJsonFiles[epBlockJson].workableBlockEntrypointsInfo.push(...workableBlockEntrypointsInfo);
@@ -127,7 +127,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
127
127
  const { inlinedAsset, ...finalizedHandle } = handleData;
128
128
  if (inlinedAsset !== undefined) {
129
129
  finalizedHandle.src = false;
130
- inlinedAssets.push([handle, type, inlinedAsset, handleData, handleData.src]);
130
+ inlinedAssets.push([handle, type, handleData]);
131
131
  }
132
132
  registerableHandles[handle] = finalizedHandle;
133
133
  }
@@ -327,7 +327,10 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
327
327
  .convertToScriptHandles(handleData.filter(hd => !(0, shared_1.isStyleField)(hd.entrypointField) && (0, shared_1.isScriptModuleField)(hd.entrypointField)))),
328
328
  styleHandles: Object.fromEntries(handleData.filter(hd => (0, shared_1.isStyleField)(hd.entrypointField))
329
329
  .map(hd => {
330
- return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset }];
330
+ if (hd.inlinedAsset === undefined) {
331
+ return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], assetContents: hd.assetContents }];
332
+ }
333
+ return [hd.handle, { src: hd.outputPath, rest: [hd.originalValue !== undefined ? hd.assetData.dependencies : [], hd.assetData.version], inlinedAsset: hd.inlinedAsset, assetContents: hd.assetContents }];
331
334
  })),
332
335
  bindableBlockAttributes
333
336
  },
@@ -340,7 +343,7 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
340
343
  }
341
344
  static convertToScriptHandles(handleData) {
342
345
  return handleData.map(hd => {
343
- const { inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
346
+ const { assetContents, inlinedAsset, originalValue, outputPath, entrypointField, scriptArgsObject: rawScriptArgsObject, assetData, handle } = hd;
344
347
  const { dependencies = [], module_dependencies = undefined } = originalValue !== undefined ? assetData : {};
345
348
  let scriptArgsObject;
346
349
  if (rawScriptArgsObject !== undefined) {
@@ -366,7 +369,13 @@ class EnhancedBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.Abst
366
369
  }
367
370
  }
368
371
  }
369
- return [handle, { src: outputPath, rest: scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version], inlinedAsset }];
372
+ const rest = scriptArgsObject !== undefined ? [dependencies, assetData.version, scriptArgsObject] : [dependencies, assetData.version];
373
+ if (inlinedAsset) {
374
+ return [handle, { src: outputPath, rest, inlinedAsset, assetContents }];
375
+ }
376
+ else {
377
+ return [handle, { src: outputPath, rest, assetContents }];
378
+ }
370
379
  });
371
380
  }
372
381
  static doFileOrHandleReplacements(compilation, blockJson, workableBlockEntrypointsInfo, getter) {
@@ -52,7 +52,7 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
52
52
  compilation.contextDependencies.add(srcRoot);
53
53
  }
54
54
  for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
55
- if (dirent.name.startsWith("~")) {
55
+ if ((0, shared_1.shouldBeSkipped)(dirent.name)) {
56
56
  continue;
57
57
  }
58
58
  if (dirent.isFile()) {
@@ -78,13 +78,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
78
78
  writer.action("init", writer => {
79
79
  writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
80
80
  for (const { handle, type, data } of prioritizedHandleList) {
81
- const { inlinedAsset, rest, src } = data;
82
- const emittedSrc = inlinedAsset === undefined
83
- ? expressions_1.Op.concat(baseUriVar, (0, node_path_1.relative)(emitDir, src))
84
- : false;
85
- writer.call(`wp_register_${type}`, [handle, emittedSrc, ...rest]);
86
- if (inlinedAsset !== undefined) {
87
- (0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
81
+ if (data.inlinedAsset !== undefined) {
82
+ writer.call(`wp_register_${type}`, [handle, false, ...data.rest]);
83
+ (0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, data);
84
+ }
85
+ else {
86
+ writer.call(`wp_register_${type}`, [handle, expressions_1.Op.concat(baseUriVar, (0, node_path_1.relative)(emitDir, data.src)), ...data.rest]);
88
87
  }
89
88
  }
90
89
  }, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
@@ -93,10 +92,9 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
93
92
  writer.action("init", writer => {
94
93
  writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
95
94
  for (const { handle, type, data } of prioritizedHandleList) {
96
- const { inlinedAsset, rest, src } = data;
97
- writer.call(`wp_register_${type}`, [handle, false, ...rest]);
98
- if (inlinedAsset !== undefined) {
99
- (0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, inlinedAsset, data, src);
95
+ writer.call(`wp_register_${type}`, [handle, false, ...data.rest]);
96
+ if (data.inlinedAsset !== undefined) {
97
+ (0, shared_1.appendAddInlineAssetCall)(compilation, writer, handle, type, data);
100
98
  }
101
99
  }
102
100
  }, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
@@ -115,7 +113,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
115
113
  const editorSettings = new expressions_1.Var("editor_settings");
116
114
  writer.filter("block_editor_settings_all", writer => {
117
115
  for (const [handle, data] of sortedEditorStyleHandles) {
118
- const contents = data.inlinedAsset?.contents;
116
+ const contents = data.assetContents;
119
117
  if (contents) {
120
118
  writer.appendExpr(new expressions_1.Assignment(new expressions_1.ArrayAccess(editorSettings, "styles"), new expressions_1.PHPArray({ css: (0, shared_1.wrapInlineAssetContents)(compilation, "plaudit_editor_style", handle, contents) }), true));
121
119
  }
@@ -305,7 +303,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
305
303
  const { dependencies = [], module_dependencies = undefined } = isScript === entrypointChunkIsScript ? assetData : {};
306
304
  const { lazyLoader, locations } = this.dest;
307
305
  const { flags } = (0, path_query_and_related_helpers_1.unpackEnqueuingControlFlagsFromPathQueryParameters)(typeof locations.registerScriptArgs === 'object' ? locations.registerScriptArgs : { strategy: locations.registerScriptArgs }, file, "registerScriptArgs");
308
- const { inlinedAsset, scriptArgsObject } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, flags, this.dest.enqueuingFlags), type === 'style' && (!!locations.clientEditor || locations.clientEditor === 0));
306
+ const { assetMeta, scriptArgsObject } = (0, path_query_and_related_helpers_1.convertEnqueuingControlFlagsToScriptArgsObject)(compilation, file, (0, path_query_and_related_helpers_1.mergeTwoEnqueuingControlFlagSets)(file, flags, this.dest.enqueuingFlags), type === 'style' && (!!locations.clientEditor || locations.clientEditor === 0));
309
307
  const completeScriptArgsObject = module_dependencies?.length ? { ...scriptArgsObject, module_dependencies } : scriptArgsObject;
310
308
  const rest = isScript && completeScriptArgsObject !== undefined ? [dependencies, assetData.version, completeScriptArgsObject] : [dependencies, assetData.version];
311
309
  const destPath = (0, node_path_1.join)(compilation.outputOptions.path, file);
@@ -316,7 +314,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
316
314
  locations,
317
315
  handleName: useHandleName ? locations.handle : undefined,
318
316
  lazyLoader,
319
- inlinedAsset
317
+ ...assetMeta
320
318
  });
321
319
  }
322
320
  myAssetHandles.push({ handles, handlePrefix: this.config.targetHandlePrefix });
package/dist/shared.d.ts CHANGED
@@ -15,22 +15,29 @@ export type ParsedAssetsJson = Record<string, {
15
15
  module_dependencies?: (string | WPModuleDependency)[];
16
16
  }>;
17
17
  export declare function isParsedAssetsJson(thing: any): thing is ParsedAssetsJson;
18
+ type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
19
+ export type AssetMetaSegment = {
20
+ inlinedAsset: InlinedAsset;
21
+ assetContents: string;
22
+ };
23
+ export type BaseHandleData = {
24
+ src: string;
25
+ rest: BaseRestType | [...BaseRestType, ScriptArgsObject];
26
+ };
18
27
  export type ScriptArgsObject = {
19
28
  strategy?: 'defer' | 'async';
20
29
  in_footer?: boolean;
21
30
  fetchpriority?: 'auto' | 'low' | 'high';
22
31
  module_dependencies?: (string | WPModuleDependency)[];
23
32
  };
24
- type BaseRestType = [/* dependencies: */ string[], /* version: */ string];
25
33
  export type InlinedAsset = {
26
- contents: string;
27
34
  position?: 'before' | 'after';
28
35
  };
29
- export type HandleData = {
30
- src: string;
31
- rest: BaseRestType | [...BaseRestType, ScriptArgsObject];
32
- inlinedAsset?: InlinedAsset;
33
- };
36
+ export type IAHandleData = BaseHandleData & AssetMetaSegment;
37
+ export type HandleData = BaseHandleData & (AssetMetaSegment | {
38
+ inlinedAsset?: undefined;
39
+ assetContents?: string;
40
+ });
34
41
  export declare const standardLocationNamesMeta: {
35
42
  readonly clientView: {
36
43
  readonly action: "wp_enqueue_scripts";
@@ -254,11 +261,9 @@ export declare function resolveLegacyBlockScriptsInFolder(folder: string): strin
254
261
  * @param writer
255
262
  * @param handle
256
263
  * @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
257
- * @param inlinedAsset
258
264
  * @param handleData
259
- * @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
260
265
  */
261
- export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', inlinedAsset: InlinedAsset, handleData: HandleData, file: string): void;
266
+ export declare function appendAddInlineAssetCall(compilation: Compilation, writer: PHPWriter, handle: string, type: 'script' | 'style' | 'script_module', handleData: IAHandleData): void;
262
267
  export declare function wrapInlineAssetContents(compilation: Compilation, wrapperIdPrefix: string, handle: string, contents: string): HereOrNowDoc;
263
268
  export declare function synchronousDirIterator(dirPath: string): Generator<import("node:fs").Dirent<string>, void, unknown>;
264
269
  /**
@@ -267,3 +272,7 @@ export declare function synchronousDirIterator(dirPath: string): Generator<impor
267
272
  * @link https://dev.to/jdbar
268
273
  */
269
274
  export declare function instanceOfNodeError<T extends new (...args: any) => Error>(value: unknown, errorType: T): value is InstanceType<T> & NodeJS.ErrnoException;
275
+ /**
276
+ * This tests if the name starts with a "~", is equal to "example" or "examples", or includes "example" as a name segment
277
+ */
278
+ export declare function shouldBeSkipped(name: string): boolean;
package/dist/shared.js CHANGED
@@ -53,6 +53,7 @@ exports.appendAddInlineAssetCall = appendAddInlineAssetCall;
53
53
  exports.wrapInlineAssetContents = wrapInlineAssetContents;
54
54
  exports.synchronousDirIterator = synchronousDirIterator;
55
55
  exports.instanceOfNodeError = instanceOfNodeError;
56
+ exports.shouldBeSkipped = shouldBeSkipped;
56
57
  const node_crypto_1 = require("node:crypto");
57
58
  const node_fs_1 = require("node:fs");
58
59
  const promises_1 = require("node:fs/promises");
@@ -348,19 +349,17 @@ function resolveLegacyBlockScriptsInFolder(folder) {
348
349
  * @param writer
349
350
  * @param handle
350
351
  * @param type 'script_module' is NOT supported at this time; however, it is *handled* in this function
351
- * @param inlinedAsset
352
352
  * @param handleData
353
- * @param file something that represents the file that is being inlined (this is purely for error-reporting purposes)
354
353
  */
355
- function appendAddInlineAssetCall(compilation, writer, handle, type, inlinedAsset, handleData, file) {
354
+ function appendAddInlineAssetCall(compilation, writer, handle, type, handleData) {
356
355
  if (type === 'script_module') {
357
- throw newWebpackErrorForFile("WordPress does not support inlined script modules", file);
356
+ throw newWebpackErrorForFile("WordPress does not support inlined script modules", handleData.src);
358
357
  }
359
358
  if (handleData.rest[0]?.length) { // If there are any dependencies
360
359
  compilation.errors.push(newWebpackErrorForFile("Inlined scripts MUST NOT have dependencies. It WILL cause runtime inconsistencies and potentially cause sever performance issues", handleData.src));
361
360
  }
362
- const args = [handle, wrapInlineAssetContents(compilation, `plaudit_inlined_${type}`, handle, inlinedAsset.contents)];
363
- if (type === 'script' && inlinedAsset.position === 'before') {
361
+ const args = [handle, wrapInlineAssetContents(compilation, `plaudit_inlined_${type}`, handle, handleData.assetContents)];
362
+ if (type === 'script' && handleData.inlinedAsset.position === 'before') {
364
363
  args.push('before');
365
364
  }
366
365
  writer.call(`wp_add_inline_${type}`, args);
@@ -392,3 +391,9 @@ function* synchronousDirIterator(dirPath) {
392
391
  function instanceOfNodeError(value, errorType) {
393
392
  return !!value && value instanceof errorType;
394
393
  }
394
+ /**
395
+ * This tests if the name starts with a "~", is equal to "example" or "examples", or includes "example" as a name segment
396
+ */
397
+ function shouldBeSkipped(name) {
398
+ return name.startsWith("~") || name === "example" || name === "examples" || name.startsWith("example.") || name.includes(".example.");
399
+ }
@@ -126,7 +126,7 @@ function resolveEntryFromDirectory(commonConfig, srcRoot, dest) {
126
126
  const seenExplicitHandles = { scriptHandles: {}, styleHandles: {}, scriptModuleHandles: {} };
127
127
  const loadingEntrypoints = [];
128
128
  for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
129
- if (!dirent.isDirectory() || dirent.name.startsWith("~")) {
129
+ if (!dirent.isDirectory() || (0, shared_1.shouldBeSkipped)(dirent.name)) {
130
130
  continue;
131
131
  }
132
132
  const dir = joinPossiblyAbsolutePaths(srcRoot, dirent.name);
@@ -7,7 +7,7 @@ const node_path_1 = require("node:path");
7
7
  const shared_1 = require("../shared");
8
8
  function parseLocationEncodingFilename(filename) {
9
9
  const { name, ext } = (0, node_path_1.parse)(filename);
10
- if (name.startsWith("~")) {
10
+ if ((0, shared_1.shouldBeSkipped)(name)) {
11
11
  return undefined;
12
12
  }
13
13
  let type = /^\.(?:s[ac]|p?c)ss$/i.test(ext) ? 'style' : /^\.m[jt]sx?/i.test(ext) ? 'script-module' : /^\.[jt]sx?/i.test(ext) ? 'script' : false;
@@ -55,5 +55,11 @@ export declare function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQ
55
55
  */
56
56
  export declare function convertEnqueuingControlFlagsToScriptArgsObject(compilation: Compilation, file: string, flags: NormalizedEnqueuingControlFlags | undefined, forceRecordContents?: boolean): {
57
57
  scriptArgsObject?: ScriptArgsObject;
58
- inlinedAsset?: InlinedAsset;
58
+ assetMeta?: {
59
+ inlinedAsset: InlinedAsset;
60
+ assetContents: string;
61
+ } | {
62
+ inlinedAsset?: undefined;
63
+ assetContents: string | undefined;
64
+ };
59
65
  };
@@ -196,11 +196,15 @@ function unpackEnqueuingControlFlagsFromPathQueryParameters(pathQueryParameters,
196
196
  */
197
197
  function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags, forceRecordContents = false) {
198
198
  if (flags === undefined) {
199
+ if (forceRecordContents) {
200
+ return { assetMeta: { assetContents: getAssetFileContents(compilation, file) } };
201
+ }
199
202
  return {};
200
203
  }
201
204
  const { strategy, in_footer, inline, position, fetchpriority } = flags;
202
205
  const scriptArgsObject = {};
203
206
  let inlinedAsset = undefined;
207
+ let assetContents = undefined;
204
208
  switch (strategy) {
205
209
  case 'async':
206
210
  case 'defer':
@@ -231,7 +235,8 @@ function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags
231
235
  scriptArgsObject.in_footer = in_footer;
232
236
  }
233
237
  if (inline) {
234
- inlinedAsset = { contents: getAssetFileContents(compilation, file) };
238
+ inlinedAsset = {};
239
+ assetContents = getAssetFileContents(compilation, file);
235
240
  removeFileAndAssetPHP(compilation, file);
236
241
  if (position !== undefined) {
237
242
  if (!isValidPositionForInlineStrategy(position)) {
@@ -247,7 +252,7 @@ function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags
247
252
  }
248
253
  }
249
254
  else if (forceRecordContents) {
250
- inlinedAsset = { contents: getAssetFileContents(compilation, file) };
255
+ assetContents = getAssetFileContents(compilation, file);
251
256
  }
252
257
  if (fetchpriority !== undefined) {
253
258
  if (!isValidFetchPriority(fetchpriority)) {
@@ -258,7 +263,8 @@ function convertEnqueuingControlFlagsToScriptArgsObject(compilation, file, flags
258
263
  }
259
264
  scriptArgsObject.fetchpriority = fetchpriority;
260
265
  }
261
- return Object.keys(scriptArgsObject).length > 0 ? { scriptArgsObject, inlinedAsset } : { inlinedAsset };
266
+ const assetMeta = inlinedAsset ? { inlinedAsset, assetContents: assetContents } : { assetContents };
267
+ return Object.keys(scriptArgsObject).length > 0 ? { scriptArgsObject, assetMeta } : { assetMeta };
262
268
  }
263
269
  function removeFileAndAssetPHP(compilation, file) {
264
270
  const pathParts = (0, node_path_1.parse)(file);
@@ -510,7 +510,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
510
510
  const entry = async () => {
511
511
  const rawEntrypoints = [];
512
512
  for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
513
- if (dirent.name.startsWith("~")) {
513
+ if ((0, shared_1.shouldBeSkipped)(dirent.name)) {
514
514
  continue;
515
515
  }
516
516
  if (dirent.isFile()) {
@@ -578,7 +578,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
578
578
  async function walkExtensionsTree(srcRoot, dest, applicableExtensionTest, parents) {
579
579
  const res = [];
580
580
  for await (const dirent of await (0, promises_1.opendir)(srcRoot)) {
581
- if (dirent.name.startsWith("~")) {
581
+ if ((0, shared_1.shouldBeSkipped)(dirent.name)) {
582
582
  continue;
583
583
  }
584
584
  if (dirent.isFile()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.94.0",
3
+ "version": "2.95.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/dist",