@plaudit/webpack-extensions 2.56.4 → 2.57.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.
@@ -12,6 +12,7 @@ export declare class BlockJSONManagingPlugin implements WebpackPluginInstance {
12
12
  private static readonly blockJsonAssetKeyMapping;
13
13
  private static readonly syncsManager;
14
14
  readonly additionalMetadata: Map<string, any>;
15
+ private readonly id;
15
16
  constructor(standaloneBlocks: boolean, processingModules: boolean | undefined, blocksDest: string);
16
17
  static recordRawDependency(entrypoint: string, dependency: string): void;
17
18
  static recordBlockJSONAssetSourceDir(entrypoint: string, source: string): void;
@@ -9,6 +9,8 @@ const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const shared_1 = require("../shared");
11
11
  const webpack_1 = require("webpack");
12
+ const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
13
+ const php_writer_1 = require("../utils/php-writer");
12
14
  class BlockJSONManagingPlugin {
13
15
  standaloneBlocks;
14
16
  processingModules;
@@ -22,10 +24,15 @@ class BlockJSONManagingPlugin {
22
24
  static blockJsonAssetKeyMapping = new Map();
23
25
  static syncsManager = new shared_1.SyncsManager();
24
26
  additionalMetadata = new Map();
27
+ id;
25
28
  constructor(standaloneBlocks, processingModules, blocksDest) {
26
29
  this.standaloneBlocks = standaloneBlocks;
27
30
  this.processingModules = processingModules;
28
31
  this.blocksDest = blocksDest;
32
+ this.id = Math.random().toString();
33
+ if (!this.processingModules) {
34
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
35
+ }
29
36
  }
30
37
  static recordRawDependency(entrypoint, dependency) {
31
38
  let deps = BlockJSONManagingPlugin.blockJsonRawDependenciesMap.get(entrypoint);
@@ -42,6 +49,7 @@ class BlockJSONManagingPlugin {
42
49
  this.additionalMetadata.clear();
43
50
  this.registerAssetProcessor(compilation);
44
51
  if (!this.processingModules) {
52
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
45
53
  this.registerBlockJsonProcessor(compilation);
46
54
  }
47
55
  });
@@ -312,6 +320,15 @@ class BlockJSONManagingPlugin {
312
320
  }
313
321
  registerBlockJsonProcessor(compilation) {
314
322
  const blockDirConfigData = {};
323
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
324
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, ['block.json', writer => {
325
+ writer
326
+ .use("Plaudit\\Common\\ACF\\BlockManager")
327
+ .action("init", writer => {
328
+ writer.call("BlockManager::autoloadSubfolders", [new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + this.blocksDest)}`)]);
329
+ });
330
+ }]);
331
+ });
315
332
  compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_GenerateMetadata`, compilationAssets => {
316
333
  const currentBlockJSONAssets = BlockJSONManagingPlugin.blockJSONAssetSourceDirs.entries()
317
334
  .filter(([name]) => name in compilationAssets)
@@ -3,10 +3,11 @@ export declare class ExtensionsConfigFileGeneratorPlugin implements WebpackPlugi
3
3
  private readonly extensionsPath;
4
4
  private readonly version;
5
5
  private readonly extensionsDest;
6
+ private readonly handlePrefix;
6
7
  private static readonly semaphore;
7
8
  private static cache;
8
9
  private readonly id;
9
- constructor(extensionsPath: string, version: 1 | 2, extensionsDest: string);
10
+ constructor(extensionsPath: string, version: 1 | 2, extensionsDest: string, handlePrefix: string);
10
11
  apply(compiler: Compiler): void;
11
12
  private makeVersionOneAfterProcessAssets;
12
13
  private stripExtensionsDest;
@@ -10,19 +10,24 @@ const shared_1 = require("../shared");
10
10
  const php_serializer_1 = require("../utils/php-serializer");
11
11
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
12
12
  const webpack_1 = require("webpack");
13
+ const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
14
+ const php_writer_1 = require("../utils/php-writer");
13
15
  class ExtensionsConfigFileGeneratorPlugin {
14
16
  extensionsPath;
15
17
  version;
16
18
  extensionsDest;
17
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ assets: [], setupFiles: [] });
19
+ handlePrefix;
20
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore({ assets: [], setupFiles: [] }, "Extensions");
18
21
  static cache = undefined;
19
22
  id;
20
- constructor(extensionsPath, version, extensionsDest) {
23
+ constructor(extensionsPath, version, extensionsDest, handlePrefix) {
21
24
  this.extensionsPath = extensionsPath;
22
25
  this.version = version;
23
26
  this.extensionsDest = extensionsDest;
27
+ this.handlePrefix = handlePrefix;
24
28
  this.id = Math.random().toString();
25
29
  ExtensionsConfigFileGeneratorPlugin.semaphore.register(this.id);
30
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
26
31
  }
27
32
  apply(compiler) {
28
33
  compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
@@ -46,6 +51,20 @@ class ExtensionsConfigFileGeneratorPlugin {
46
51
  compiler.hooks.compilation.tap(this.constructor.name, compilation => {
47
52
  ExtensionsConfigFileGeneratorPlugin.cache = undefined;
48
53
  ExtensionsConfigFileGeneratorPlugin.semaphore.reset(this.id);
54
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
55
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
56
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, ['extensions-config-v2', writer => {
57
+ writer
58
+ .use("Plaudit\\Base\\API\\ThemeUtils")
59
+ .call("trailingslashit", [new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + this.extensionsDest)}`)], { assignTo: "$filePathPrefix" })
60
+ .call("plaudit_webpack_extensions__resolve_base_uri", [new php_writer_1.Expr(`__DIR__.'/${this.extensionsDest}'`)], { assignTo: "$fileUriPrefix" })
61
+ .call("ThemeUtils::loadExtensionsV2", [
62
+ new php_writer_1.Expr(`$filePathPrefix.'mapping.config.php'`), new php_writer_1.Expr("$filePathPrefix"), new php_writer_1.Expr("$fileUriPrefix"),
63
+ `${this.handlePrefix ? this.handlePrefix : node_path_1.default.basename(process.cwd())}_extension_`
64
+ ])
65
+ .call("unset", [new php_writer_1.Expr("$filePathPrefix"), new php_writer_1.Expr("$fileUriPrefix")]);
66
+ }]);
67
+ });
49
68
  compilation.hooks.processAssets.tapPromise(tapName, async (assets) => {
50
69
  try {
51
70
  //TODO: Add handling of extracted CSS from JS
@@ -144,6 +163,14 @@ class ExtensionsConfigFileGeneratorPlugin {
144
163
  }
145
164
  else {
146
165
  compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
166
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
167
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
168
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, ['extensions-config-v1', writer => {
169
+ writer
170
+ .use("Plaudit\\Base\\API\\ThemeUtils")
171
+ .call("ThemeUtils::installExtensionSupport", [new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDest)}`)]);
172
+ }]);
173
+ });
147
174
  compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_AfterProcessAssets`, this.makeVersionOneAfterProcessAssets(compilation));
148
175
  });
149
176
  }
@@ -12,7 +12,6 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin implements Webpac
12
12
  constructor(buildRoot: string, outputDir: string, usageLocations: UsageLocations, handlePrefix: string);
13
13
  apply(compiler: Compiler): void;
14
14
  private static afterProcessAssets;
15
- private static getEmitPath;
16
15
  private static addHandlesToHandleLists;
17
16
  private static appendEnqueuingHandleLists;
18
17
  private static separateHandleListByPriority;
@@ -21,4 +20,3 @@ export declare class PlainEntrypointsConfigFileGeneratorPlugin implements Webpac
21
20
  */
22
21
  static emitResolveBaseUriFunction(writer: PHPWriter): void;
23
22
  }
24
- export declare function kebabCase(value: string): string;
@@ -4,18 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PlainEntrypointsConfigFileGeneratorPlugin = void 0;
7
- exports.kebabCase = kebabCase;
8
7
  const node_path_1 = __importDefault(require("node:path"));
9
8
  const shared_1 = require("../shared");
10
9
  const php_writer_1 = require("../utils/php-writer");
11
10
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
12
11
  const webpack_1 = require("webpack");
12
+ const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
13
13
  class PlainEntrypointsConfigFileGeneratorPlugin {
14
14
  buildRoot;
15
15
  outputDir;
16
16
  usageLocations;
17
17
  handlePrefix;
18
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore([]);
18
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore([], "Plain");
19
19
  static cache = undefined;
20
20
  id;
21
21
  constructor(buildRoot, outputDir, usageLocations, handlePrefix) {
@@ -25,12 +25,19 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
25
25
  this.handlePrefix = handlePrefix;
26
26
  this.id = Math.random().toString();
27
27
  PlainEntrypointsConfigFileGeneratorPlugin.semaphore.register(this.id);
28
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
28
29
  }
29
30
  apply(compiler) {
30
31
  const tapName = { name: `${this.constructor.name}_ProcessPlainEntrypointFiles`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT };
31
32
  compiler.hooks.compilation.tap(this.constructor.name, compilation => {
32
33
  PlainEntrypointsConfigFileGeneratorPlugin.cache = undefined;
33
34
  PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reset(this.id);
35
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
36
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
37
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, ['plain-entrypoints-v2', writer => {
38
+ writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';");
39
+ }]);
40
+ });
34
41
  compilation.hooks.processAssets.tapPromise(tapName, async (assets) => {
35
42
  try {
36
43
  const emitDir = node_path_1.default.join(this.buildRoot, this.outputDir);
@@ -100,6 +107,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
100
107
  }
101
108
  catch (e) {
102
109
  PlainEntrypointsConfigFileGeneratorPlugin.semaphore.reject(this.id);
110
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reject(this.id);
103
111
  throw e;
104
112
  }
105
113
  });
@@ -135,7 +143,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
135
143
  }
136
144
  else {
137
145
  const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
138
- const baseFinalHandleName = `${handlePrefix}.${kebabCase(basename)}`;
146
+ const baseFinalHandleName = `${handlePrefix}.${(0, shared_1.kebabCase)(basename)}`;
139
147
  const handleNameMap = (isScript ? usedScriptHandleNames : usedStyleHandleNames);
140
148
  finalHandleName = baseFinalHandleName;
141
149
  for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
@@ -185,11 +193,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
185
193
  }
186
194
  }
187
195
  PlainEntrypointsConfigFileGeneratorPlugin.appendEnqueuingHandleLists(writer, handleLists);
188
- const assetPath = PlainEntrypointsConfigFileGeneratorPlugin.getEmitPath(compilation, emitDir);
189
- writer.emitAsset(compilation, assetPath);
190
- }
191
- static getEmitPath(compilation, emitDir) {
192
- return node_path_1.default.relative(compilation.outputOptions.path ?? process.cwd(), node_path_1.default.join(emitDir, "plain-entrypoints-loader.php"));
196
+ writer.emitAsset(compilation, "plain-entrypoints-loader.php");
193
197
  }
194
198
  static addHandlesToHandleLists(type, handles, handleLists) {
195
199
  for (const [handle, data] of handles) {
@@ -263,7 +267,3 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
263
267
  }
264
268
  }
265
269
  exports.PlainEntrypointsConfigFileGeneratorPlugin = PlainEntrypointsConfigFileGeneratorPlugin;
266
- function kebabCase(value) {
267
- const kebabCaseRegexes = [[/([a-z])([A-Z])/g, "$1-$2"], [/[\s_.\-]+/g, "-"]];
268
- return kebabCaseRegexes.reduce((str, [pattern, replacement]) => str.replace(pattern, replacement), value).toLowerCase();
269
- }
@@ -1,8 +1,7 @@
1
- import type { Compiler, WebpackPluginInstance } from "webpack";
1
+ import { type Compiler, type WebpackPluginInstance } from "webpack";
2
2
  export declare class SpecialAssetHandlingPlugin implements WebpackPluginInstance {
3
3
  private readonly outputDir;
4
4
  private static readonly semaphore;
5
- private static readonly previouslyIncludedFilenames;
6
5
  private static hasAttachedAssetCollatorForCurrentBatch;
7
6
  private static validPathname?;
8
7
  private readonly id;
@@ -8,10 +8,11 @@ const node_path_1 = __importDefault(require("node:path"));
8
8
  const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./PlainEntrypointsConfigFileGeneratorPlugin");
9
9
  const php_writer_1 = require("../utils/php-writer");
10
10
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
11
+ const webpack_1 = require("webpack");
12
+ const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
11
13
  class SpecialAssetHandlingPlugin {
12
14
  outputDir;
13
- static semaphore = new pseduo_semaphore_1.PseudoSemaphore({});
14
- static previouslyIncludedFilenames = new Set(); // This allows us to ensure that assets that were previously being preloaded can be removed
15
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore({}, "Special");
15
16
  static hasAttachedAssetCollatorForCurrentBatch = false;
16
17
  static validPathname = undefined;
17
18
  id;
@@ -19,11 +20,18 @@ class SpecialAssetHandlingPlugin {
19
20
  this.outputDir = outputDir;
20
21
  this.id = Math.random().toString();
21
22
  SpecialAssetHandlingPlugin.semaphore.register(this.id);
23
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.register(this.id);
22
24
  }
23
25
  apply(compiler) {
24
26
  compiler.hooks.compilation.tap(this.constructor.name, compilation => {
25
27
  SpecialAssetHandlingPlugin.hasAttachedAssetCollatorForCurrentBatch = false;
26
28
  SpecialAssetHandlingPlugin.semaphore.reset(this.id);
29
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
30
+ compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
31
+ UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, ['special-assets', writer => {
32
+ writer.append("require_once __DIR__.'/special-assets.php';");
33
+ }]);
34
+ });
27
35
  compilation.hooks.processAssets.tapPromise(this.constructor.name, async (assets) => {
28
36
  try {
29
37
  const specialAssetData = {};
@@ -38,13 +46,6 @@ class SpecialAssetHandlingPlugin {
38
46
  const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
39
47
  const queryStart = assetInfo.sourceFilename.indexOf('?');
40
48
  if (queryStart < 0) {
41
- if (SpecialAssetHandlingPlugin.previouslyIncludedFilenames.has(filename)) {
42
- specialAssetData[filename] = {
43
- preload: false,
44
- fetchpriority: null,
45
- crossorigin: null
46
- };
47
- }
48
49
  continue;
49
50
  }
50
51
  const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
@@ -0,0 +1,10 @@
1
+ import { PseudoSemaphore } from "../utils/pseduo-semaphore";
2
+ import { PHPWriter } from "../utils/php-writer";
3
+ import { Compiler, WebpackPluginInstance } from "webpack";
4
+ export declare class UnifiedLoaderGenerator implements WebpackPluginInstance {
5
+ static readonly semaphore: PseudoSemaphore<[string, (writer: PHPWriter) => void] | undefined>;
6
+ private static attached;
7
+ private readonly id;
8
+ constructor();
9
+ apply(compiler: Compiler): void;
10
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnifiedLoaderGenerator = void 0;
4
+ const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
5
+ const php_writer_1 = require("../utils/php-writer");
6
+ const webpack_1 = require("webpack");
7
+ const PlainEntrypointsConfigFileGeneratorPlugin_1 = require("./PlainEntrypointsConfigFileGeneratorPlugin");
8
+ class UnifiedLoaderGenerator {
9
+ static semaphore = new pseduo_semaphore_1.PseudoSemaphore(undefined, "Unified");
10
+ static attached = false;
11
+ id;
12
+ constructor() {
13
+ this.id = Math.random().toString();
14
+ UnifiedLoaderGenerator.semaphore.register(this.id);
15
+ }
16
+ apply(compiler) {
17
+ const tapName = { name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT };
18
+ compiler.hooks.compilation.tap(this.constructor.name, compilation => {
19
+ UnifiedLoaderGenerator.attached = false;
20
+ UnifiedLoaderGenerator.semaphore.reset(this.id);
21
+ compilation.hooks.processAssets.tapPromise(tapName, async () => {
22
+ try {
23
+ UnifiedLoaderGenerator.semaphore.resolve(this.id, undefined);
24
+ if (!UnifiedLoaderGenerator.attached) {
25
+ UnifiedLoaderGenerator.attached = true;
26
+ const writerCallbacks = Object.values(Object.fromEntries((await UnifiedLoaderGenerator.semaphore.wait())
27
+ .filter(a => a !== undefined))); // A simple deduplication trick
28
+ if (writerCallbacks.length > 0) {
29
+ compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
30
+ const writer = new php_writer_1.PHPWriter();
31
+ PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin.emitResolveBaseUriFunction(writer);
32
+ for (const writerCallback of writerCallbacks) {
33
+ writerCallback(writer);
34
+ }
35
+ writer.emitAsset(compilation, "unified-loader.php");
36
+ });
37
+ }
38
+ }
39
+ }
40
+ catch (e) {
41
+ UnifiedLoaderGenerator.semaphore.reject(this.id);
42
+ throw e;
43
+ }
44
+ });
45
+ });
46
+ }
47
+ }
48
+ exports.UnifiedLoaderGenerator = UnifiedLoaderGenerator;
package/build/shared.d.ts CHANGED
@@ -92,4 +92,6 @@ export declare const scriptWithoutModuleExtension: RegExp;
92
92
  export declare const scriptWithModuleExtension: RegExp;
93
93
  export declare const styleExtension: RegExp;
94
94
  export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "" | "script" | "style";
95
+ export declare function hasAtLeastOneItem<T>(list: T[]): list is [T, ...T[]];
96
+ export declare function kebabCase(value: string): string;
95
97
  export {};
package/build/shared.js CHANGED
@@ -9,6 +9,8 @@ exports.determineCurrentSourceType = determineCurrentSourceType;
9
9
  exports.makeEmittableConfigPHP = makeEmittableConfigPHP;
10
10
  exports.leadingSlashIt = leadingSlashIt;
11
11
  exports.scriptOrStyleTest = scriptOrStyleTest;
12
+ exports.hasAtLeastOneItem = hasAtLeastOneItem;
13
+ exports.kebabCase = kebabCase;
12
14
  const json_to_php_but_with____injection_1 = __importDefault(require("./utils/json-to-php-but-with-__-injection"));
13
15
  function isRawAssetData(thing) {
14
16
  if (!thing || typeof thing !== 'object') {
@@ -78,3 +80,10 @@ exports.styleExtension = /(?<filename>.+)(?<extension>\.(p?c|sa)ss)$/i;
78
80
  function scriptOrStyleTest(entryPath, scriptExtension) {
79
81
  return scriptExtension.test(entryPath) ? "script" : (exports.styleExtension.test(entryPath) ? "style" : "");
80
82
  }
83
+ function hasAtLeastOneItem(list) {
84
+ return list.length > 0;
85
+ }
86
+ function kebabCase(value) {
87
+ const kebabCaseRegexes = [[/([a-z])([A-Z])/g, "$1-$2"], [/[\s_.\-]+/g, "-"]];
88
+ return kebabCaseRegexes.reduce((str, [pattern, replacement]) => str.replace(pattern, replacement), value).toLowerCase();
89
+ }
@@ -1,8 +1,10 @@
1
1
  export declare class PseudoSemaphore<T> {
2
2
  private readonly defaultValue;
3
+ private readonly name;
3
4
  private flagSet;
4
5
  private readonly flags;
5
- constructor(defaultValue: T);
6
+ private readonly debugMode;
7
+ constructor(defaultValue: T, name: string);
6
8
  register(id: string): void;
7
9
  resolve(id: string, value: T): void;
8
10
  reject(id: string): void;
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PseudoSemaphore = void 0;
4
4
  class PseudoSemaphore {
5
5
  defaultValue;
6
+ name;
6
7
  flagSet = 0;
7
8
  flags = new Map();
8
- constructor(defaultValue) {
9
+ debugMode = false;
10
+ constructor(defaultValue, name) {
9
11
  this.defaultValue = defaultValue;
12
+ this.name = name;
10
13
  }
11
14
  register(id) {
12
15
  if (this.flags.has(id)) {
@@ -16,16 +19,25 @@ class PseudoSemaphore {
16
19
  this.resolve(id, this.defaultValue);
17
20
  }
18
21
  resolve(id, value) {
22
+ if (this.debugMode) {
23
+ console.error("RESOLVED:", this.name, id);
24
+ }
19
25
  const flag = this.getFlag(id);
20
26
  flag[1].resolve(value); // This is deliberately unsafe - I would rather see a cascading failure than a silent one
21
27
  flag[2] = true;
22
28
  }
23
29
  reject(id) {
30
+ if (this.debugMode) {
31
+ console.error("REJECTED:", this.name, id);
32
+ }
24
33
  const flag = this.getFlag(id);
25
34
  flag[1].reject(); // This is deliberately unsafe - I would rather see a cascading failure than a silent one
26
35
  flag[2] = true;
27
36
  }
28
37
  reset(id) {
38
+ if (this.debugMode) {
39
+ console.error("RESET:", this.name, id);
40
+ }
29
41
  const flag = this.getFlag(id);
30
42
  // We reject if we reset early to avoid any permanently-hanging promises
31
43
  if (!flag[2]) {
@@ -22,6 +22,7 @@ const dependency_extraction_webpack_plugin_config_builder_1 = require("./plugins
22
22
  const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
23
23
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
24
24
  const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
25
+ const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
25
26
  function resolveLegacyBlockScriptsInFolder(folder) {
26
27
  const blockScriptEntrypoints = [];
27
28
  for (const blockDir of node_fs_1.default.readdirSync(folder)) {
@@ -168,7 +169,7 @@ function injectSupportForInliningSVGsAsStrings(rules) {
168
169
  });
169
170
  }
170
171
  function buildVerifiedConfig(config) {
171
- const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "", extensionsVersion = 1, plainEntrypointsHandlePrefix = "", plainEntrypointsVersion = 1, srcDir = "" } = config;
172
+ const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "", extensionsVersion = 1, plainEntrypointsVersion = 1, srcDir = "" } = config;
172
173
  let srcPrefixes;
173
174
  const trailingSlashedSrcDir = srcDir && !srcDir.endsWith("/") ? srcDir + "/" : srcDir;
174
175
  if (config.srcPrefixes === undefined) {
@@ -177,9 +178,13 @@ function buildVerifiedConfig(config) {
177
178
  else {
178
179
  srcPrefixes = (srcDir && !config.srcPrefixes.includes(trailingSlashedSrcDir) ? [...config.srcPrefixes, trailingSlashedSrcDir] : config.srcPrefixes);
179
180
  }
181
+ let plainEntrypointsHandlePrefix = config.plainEntrypointsHandlePrefix ?? "";
180
182
  if (plainEntrypointsVersion > 1) {
181
183
  if (!plainEntrypointsHandlePrefix) {
182
- throw new Error("Plain Entrypoints V2 and higher require 'plainEntrypointsHandlePrefix' to be set");
184
+ plainEntrypointsHandlePrefix = derivePlainEntrypointsHandlePrefixFromComposerJsonOrThemeName();
185
+ if (!plainEntrypointsHandlePrefix) {
186
+ throw new Error("Plain Entrypoints V2 and higher require either 'plainEntrypointsHandlePrefix' to be set or an adjacent composer.json or style.css file to be present");
187
+ }
183
188
  }
184
189
  if (!outputDir) {
185
190
  throw new Error("Plain Entrypoints V2 and higher require 'outputDir' to be set");
@@ -279,6 +284,28 @@ function finalizeEntryDestination(entry, dynamicEffectiveDestinationsWithExpecte
279
284
  allocatedDestinations[derivedDestination] = entry[0];
280
285
  return [entry[0], { ...entry[1], destination: derivedDestination }];
281
286
  }
287
+ function derivePlainEntrypointsHandlePrefixFromComposerJsonOrThemeName() {
288
+ let composerJson;
289
+ try {
290
+ composerJson = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "composer.json"), 'utf-8'));
291
+ }
292
+ catch {
293
+ // Then composer.json doesn't exist
294
+ return derivePlainEntrypointsHandlePrefixFromThemeName();
295
+ }
296
+ if (typeof composerJson !== 'object' || typeof composerJson.name !== 'string' || !composerJson.name) {
297
+ throw new ReferenceError("plainEntrypointsHandlePrefix was not set and the adjacent composer.json file does not have a valid name in it");
298
+ }
299
+ return (0, shared_1.kebabCase)(composerJson.name.replace(/plaudit\/plaudit/, 'plaudit'));
300
+ }
301
+ function derivePlainEntrypointsHandlePrefixFromThemeName() {
302
+ const styleFileContents = node_fs_1.default.readFileSync(node_path_1.default.join(process.cwd(), "style.css"), 'utf-8');
303
+ const themeName = /^\W*Theme\s*Name:\s*(.+)$/im.exec(styleFileContents)?.[1]?.trim();
304
+ if (!themeName) {
305
+ throw new ReferenceError("plainEntrypointsHandlePrefix was not set and the adjacent style.css file does not have a valid name in it");
306
+ }
307
+ return (0, shared_1.kebabCase)(themeName);
308
+ }
282
309
  function withDerivedOutputDir(cfg, sources) {
283
310
  const destinations = sources.map(([_, { destination }]) => destination.split(/[\/\\]/g));
284
311
  if (destinations.length < 2) {
@@ -353,6 +380,9 @@ function buildCommonPluginConfig(srcRoot, scriptExtension, webpackConfig, dest,
353
380
  extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
354
381
  });
355
382
  plugins.push(removeEmptyScriptsPlugin, new MiniCSSExtractPluginErrorCleaner_1.MiniCSSExtractPluginErrorCleaner());
383
+ if (config.outputDir) {
384
+ plugins.push(new UnifiedLoaderGenerator_1.UnifiedLoaderGenerator());
385
+ }
356
386
  if (config.useWebpackResourceFiltering) {
357
387
  plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config.outputDir));
358
388
  }
@@ -467,7 +497,7 @@ function makeBlocksWebpackConfig(config, commonConfig, webpackConfig, dest, src,
467
497
  return (0, common_config_helpers_1.commonMakeWebpackConfig)(config, commonConfig, webpackConfig, true, dest, src, srcRoot, (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest), plugins);
468
498
  }
469
499
  function makeExtensionsWebpackConfig(config, commonConfig, webpackConfig, dest, src, srcRoot, plugins) {
470
- plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot, config.extensionsVersion, dest.destination));
500
+ plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.ExtensionsConfigFileGeneratorPlugin(srcRoot, config.extensionsVersion, dest.destination, config.plainEntrypointsHandlePrefix));
471
501
  const entry = async () => {
472
502
  const rawEntrypoints = [];
473
503
  for await (const dirent of await promises_1.default.opendir(srcRoot)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.56.4",
3
+ "version": "2.57.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "/build"