@plaudit/webpack-extensions 2.65.1 → 2.65.3

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.
@@ -52,9 +52,8 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
52
52
  finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
53
53
  }
54
54
  else {
55
- const baseFinalHandleName = `${handlePrefix}.${(0, shared_1.kebabCase)(basename)}`;
56
55
  const handleNameMap = usedHandleNames[type];
57
- finalHandleName = (0, shared_1.convertUsageLocationsHandleToEmittableHandle)(handleName, basename);
56
+ const baseFinalHandleName = finalHandleName = `${handlePrefix}.${(0, shared_1.convertUsageLocationsHandleToEmittableHandle)((0, shared_1.kebabCase)(basename), basename)}`;
58
57
  for (let count = 0; finalHandleName in handleNameMap && handleNameMap[finalHandleName] !== src;) {
59
58
  finalHandleName = `${baseFinalHandleName}-${++count}`;
60
59
  }
@@ -202,7 +201,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
202
201
  PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
203
202
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
204
203
  ? {
205
- group: this.group, requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';"),
204
+ group: this.group, requiresBaseURI: true, action: writer => writer.require("/plain-entrypoints-loader.php", { dirRelative: true, once: true }),
206
205
  staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray())
207
206
  }
208
207
  : undefined);
@@ -22,4 +22,5 @@ export declare class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhas
22
22
  private static remapReferencedPHPFilesOnKey;
23
23
  private static normalizeRenderTemplate;
24
24
  protected attachUniquePhase(compilation: Compilation): void;
25
+ protected attachStandardPhase(compilation: Compilation): void;
25
26
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PlainEntrypointsStyleBlockJSONPlugin = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
9
10
  const node_path_1 = __importDefault(require("node:path"));
10
11
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
@@ -13,7 +14,6 @@ const shared_1 = require("../shared");
13
14
  const php_writer_1 = require("../utils/php-writer");
14
15
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
15
16
  const webpack_1 = require("webpack");
16
- const promises_1 = __importDefault(require("node:fs/promises"));
17
17
  class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
18
18
  blocksDest;
19
19
  webpackRemoveEmptyScriptsPlugin;
@@ -31,13 +31,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
31
31
  if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
32
32
  continue;
33
33
  }
34
- const entrypointChunk = entrypoint.getEntrypointChunk();
35
- for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
36
- if (!danglingBlockJsFile.endsWith("block.json")) {
37
- compilation.deleteAsset(danglingBlockJsFile);
38
- }
39
- }
40
- const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypointChunk)][0]?.originalSource();
34
+ const asset = [...compilation.chunkGraph.getChunkEntryModulesIterable(entrypoint.getEntrypointChunk())][0]?.originalSource();
41
35
  if (asset) {
42
36
  //TODO: Can we guarantee that entrypoint.name is always non-null?
43
37
  const epBlockJson = entrypoint.name + ".json";
@@ -99,7 +93,7 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
99
93
  group: this.group,
100
94
  requiresBaseURI: false,
101
95
  staticallyLoadedEntrypoints: relevantEntrypoints.flatMap(re => re.entrypoint.getEntrypointChunk().files.values().toArray()),
102
- action: writer => writer.append(`require_once __DIR__.${php_writer_1.Expr.convertJsonToPHP("/" + node_path_1.default.join(this.blocksDest, "blockdir-loader.php"))};`)
96
+ action: writer => writer.require(node_path_1.default.join(this.blocksDest, "blockdir-loader.php"), { dirRelative: true, once: true })
103
97
  } : undefined);
104
98
  }
105
99
  emitBlockLoaderFile(compilation, blockData) {
@@ -378,5 +372,22 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
378
372
  this.emitBlockLoaderFile(compilation, blockData);
379
373
  });
380
374
  }
375
+ attachStandardPhase(compilation) {
376
+ super.attachStandardPhase(compilation);
377
+ compilation.hooks.processAssets.tapPromise({ name: `${this.constructor.name}_CompileLoader`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER }, async () => {
378
+ const relevantEntrypoints = this.getRelevantEntrypoints(compilation).toArray();
379
+ for (const { entrypoint, metadata, srcPath } of relevantEntrypoints) {
380
+ if (node_path_1.default.basename(srcPath).toLowerCase() !== "block.json" || !('purpose' in metadata) || metadata.purpose !== "block-json-inclusion-assurance") {
381
+ continue;
382
+ }
383
+ const entrypointChunk = entrypoint.getEntrypointChunk();
384
+ for (const danglingBlockJsFile of [...entrypointChunk.files, ...entrypointChunk.auxiliaryFiles]) {
385
+ if (!danglingBlockJsFile.endsWith("block.json")) {
386
+ compilation.deleteAsset(danglingBlockJsFile);
387
+ }
388
+ }
389
+ }
390
+ });
391
+ }
381
392
  }
382
393
  exports.PlainEntrypointsStyleBlockJSONPlugin = PlainEntrypointsStyleBlockJSONPlugin;
@@ -48,7 +48,7 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
48
48
  }
49
49
  SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
50
50
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
51
- ? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
51
+ ? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.require("/special-assets.php", { dirRelative: true, once: true }) }
52
52
  : undefined);
53
53
  }
54
54
  catch (e) {
@@ -130,6 +130,10 @@ export declare abstract class Constants {
130
130
  static readonly __DIR__: EnclosedLiteral;
131
131
  static readonly ABSPATH: EnclosedLiteral;
132
132
  }
133
+ export type AppendExprArgs = {
134
+ chain?: boolean;
135
+ return?: boolean;
136
+ };
133
137
  export type ActionOrFilterArgs = {
134
138
  priority?: number | Expr;
135
139
  functionArgParameters?: string[];
@@ -143,6 +147,10 @@ export type FunctionCreationArgs = {
143
147
  assignToName?: boolean;
144
148
  scopeActionDescription?: string;
145
149
  };
150
+ export type RequireOrIncludeArgs = {
151
+ dirRelative?: boolean;
152
+ once?: boolean;
153
+ } & AppendExprArgs;
146
154
  export declare class PHPWriter {
147
155
  private readonly inlineFirstLine;
148
156
  private readonly scopeStack;
@@ -167,14 +175,8 @@ export declare class PHPWriter {
167
175
  * @param expr This is treated as literal *regardless of its type*
168
176
  * @param opts flags to add additional markup around the expression
169
177
  */
170
- appendExpr(expr: string | Expr, opts?: {
171
- chain?: boolean;
172
- return?: boolean;
173
- }): this;
174
- assign(assignee: ConstructorParameters<typeof Assignment>[0] | string, expression: unknown, opts?: {
175
- chain?: boolean;
176
- return?: boolean;
177
- }): this;
178
+ appendExpr(expr: string | Expr, opts?: AppendExprArgs): this;
179
+ assign(assignee: ConstructorParameters<typeof Assignment>[0] | string, expression: unknown, opts?: AppendExprArgs): this;
178
180
  return(expression: unknown | Expr): this;
179
181
  static(variable: Var | string, opts?: {
180
182
  initializer?: unknown | Literal;
@@ -187,10 +189,8 @@ export declare class PHPWriter {
187
189
  * @param opts
188
190
  */
189
191
  call(func: string | EnclosableExpression, args: unknown[], opts?: {
190
- chain?: boolean;
191
192
  assignTo?: ConstructorParameters<typeof Assignment>[0];
192
- return?: boolean;
193
- }): this;
193
+ } & AppendExprArgs): this;
194
194
  action(name: string | Expr, contents: (writer: PHPWriter) => void, args?: ActionOrFilterArgs): this;
195
195
  filter(name: string | Expr, contents: (writer: PHPWriter) => void, args?: ActionOrFilterArgs): this;
196
196
  actionOrFilter(type: 'action' | 'filter', name: string | Expr, contents: (writer: PHPWriter) => void, args: ActionOrFilterArgs): this;
@@ -207,6 +207,9 @@ export declare class PHPWriter {
207
207
  openPHP(): this;
208
208
  namespace(namespace: string): this;
209
209
  use(...uses: string[]): this;
210
+ require(filePath: string | Expr, args?: RequireOrIncludeArgs): this;
211
+ include(filePath: string | Expr, args?: RequireOrIncludeArgs): this;
212
+ requireOrInclude(type: 'require' | 'include', filePath: string | Expr, args: RequireOrIncludeArgs): this;
210
213
  /**
211
214
  * Starts a scope that, when paired with {@link #closeScope()}, allows for automating unset calls.
212
215
  * All scopes started MUST be paired with either an {@link #closeScope()} or {@link #popScope()} call.
@@ -12,6 +12,7 @@ class Expr {
12
12
  static jsonToPHPConverter = json_to_php_but_with____injection_1.default.make({ shortArraySyntax: true });
13
13
  static convertJsonToPHP = (obj) => obj instanceof Expr ? obj.toString() : Expr.jsonToPHPConverter(obj);
14
14
  constructor() { }
15
+ // noinspection JSUnusedGlobalSymbols - this technically-unused method is necessary for TypeScript to differentiate subclasses of Expr from any
15
16
  typeName() {
16
17
  return this.constructor.name;
17
18
  }
@@ -514,6 +515,20 @@ class PHPWriter {
514
515
  }
515
516
  return this;
516
517
  }
518
+ require(filePath, args = {}) {
519
+ return this.requireOrInclude('require', filePath, args);
520
+ }
521
+ include(filePath, args = {}) {
522
+ return this.requireOrInclude('include', filePath, args);
523
+ }
524
+ requireOrInclude(type, filePath, args) {
525
+ const command = args.once ? `${type}_once` : type;
526
+ if (args.dirRelative && typeof filePath === 'string' && !filePath.startsWith("/")) {
527
+ filePath = "/" + filePath;
528
+ }
529
+ const path = args.dirRelative ? Op.join(Constants.__DIR__, filePath) : Expr.convertJsonToPHP(filePath);
530
+ return this.appendExpr(`${command} ${path}`, args);
531
+ }
517
532
  /**
518
533
  * Starts a scope that, when paired with {@link #closeScope()}, allows for automating unset calls.
519
534
  * All scopes started MUST be paired with either an {@link #closeScope()} or {@link #popScope()} call.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.65.1",
3
+ "version": "2.65.3",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"