@plaudit/webpack-extensions 2.71.0 → 2.72.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,10 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ExtensionsConfigFileGeneratorPlugin = void 0;
7
7
  const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const php_writer_1 = require("@plaudit/php-writer");
10
+ const expressions_1 = require("@plaudit/php-writer/expressions");
9
11
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
10
12
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
11
13
  const shared_1 = require("../shared");
12
- const php_writer_1 = require("../utils/php-writer");
13
14
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
14
15
  const webpack_1 = require("webpack");
15
16
  class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
@@ -98,10 +99,9 @@ class ExtensionsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryP
98
99
  return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
99
100
  })
100
101
  .toSorted(([a], [b]) => a.localeCompare(b)));
101
- new php_writer_1.PHPWriter()
102
- .call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), php_writer_1.Op.concat(php_writer_1.Constants.__DIR__, '/'),
103
- php_writer_1.Expr.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__])])
104
- .emitAsset(compilation, node_path_1.default.join(this.dest.destination, "extensions-loader.php"));
102
+ (0, shared_1.emitPHPWriterAsAsset)(new php_writer_1.PHPWriter()
103
+ .call("Plaudit\\Common\\Lib\\GutenbergUtils::loadExtensionsV3", [new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig, false)), expressions_1.Op.concat(expressions_1.Constants.__DIR__, '/'),
104
+ expressions_1.Expr.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__])]), compilation, node_path_1.default.join(this.dest.destination, "extensions-loader.php"));
105
105
  }
106
106
  attachUniquePhase(compilation) {
107
107
  compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ExtensionsConfigFileGeneratorPluginV1 = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const php_writer_1 = require("@plaudit/php-writer");
9
+ const expressions_1 = require("@plaudit/php-writer/expressions");
8
10
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
9
11
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
10
- const php_serializer_1 = require("../utils/php-serializer");
11
- const php_writer_1 = require("../utils/php-writer");
12
12
  const webpack_1 = require("webpack");
13
13
  class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
14
14
  extensionsDest;
@@ -28,11 +28,11 @@ class ExtensionsConfigFileGeneratorPluginV1 extends AbstractBiPhasicGroupAndEntr
28
28
  (resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, fileWithAssetData]);
29
29
  }
30
30
  }
31
- compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_serializer_1.phpSerialize)(mapping)));
31
+ compilation.emitAsset(node_path_1.default.join(this.extensionsDest, "mapping.config"), new webpack_1.sources.RawSource((0, php_writer_1.phpSerialize)(mapping)));
32
32
  UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
33
33
  writer
34
34
  .use("Plaudit\\Common\\Lib\\GutenbergUtils")
35
- .call("GutenbergUtils::installExtensionsSupport", [php_writer_1.Op.concat(php_writer_1.Constants.__DIR__, this.extensionsDest)]);
35
+ .call("GutenbergUtils::installExtensionsSupport", [expressions_1.Op.concat(expressions_1.Constants.__DIR__, this.extensionsDest)]);
36
36
  } });
37
37
  }
38
38
  }
@@ -5,8 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PlainEntrypointsConfigFileGeneratorPlugin = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const php_writer_1 = require("@plaudit/php-writer");
9
+ const expressions_1 = require("@plaudit/php-writer/expressions");
8
10
  const shared_1 = require("../shared");
9
- const php_writer_1 = require("../utils/php-writer");
10
11
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
11
12
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
12
13
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
@@ -78,12 +79,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
78
79
  if (!this.useUnifiedLoader) {
79
80
  (0, shared_1.emitResolveBaseUriFunction)(writer);
80
81
  }
81
- const baseUriVar = new php_writer_1.Var("base_uri");
82
+ const baseUriVar = new expressions_1.Var("base_uri");
82
83
  for (const [priority, prioritizedHandleList] of PlainEntrypointsConfigFileGeneratorPlugin.separateHandleListByPriority(handleLists.register)) {
83
84
  writer.action("init", writer => {
84
- writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: baseUriVar });
85
+ writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar });
85
86
  for (const { handle, type, data } of prioritizedHandleList) {
86
- writer.call(`wp_register_${type}`, [handle, php_writer_1.Op.concat(baseUriVar, node_path_1.default.relative(emitDir, data.src)), ...data.rest]);
87
+ writer.call(`wp_register_${type}`, [handle, expressions_1.Op.concat(baseUriVar, node_path_1.default.relative(emitDir, data.src)), ...data.rest]);
87
88
  }
88
89
  }, { priority, accountForAlreadyDoing: this.config.includePostInitFallback });
89
90
  }
@@ -100,7 +101,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
100
101
  }
101
102
  }
102
103
  PlainEntrypointsConfigFileGeneratorPlugin.appendEnqueuingHandleLists(writer, handleLists);
103
- writer.emitAsset(compilation, "plain-entrypoints-loader.php");
104
+ (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, "plain-entrypoints-loader.php");
104
105
  }
105
106
  static addHandlesToHandleLists(type, handles, handleLists) {
106
107
  for (const [handle, data] of handles) {
@@ -10,8 +10,9 @@ const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const node_path_1 = __importDefault(require("node:path"));
11
11
  const AbstractBiPhasicGroupAndEntryPlugin_1 = require("./AbstractBiPhasicGroupAndEntryPlugin");
12
12
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
13
+ const php_writer_1 = require("@plaudit/php-writer");
14
+ const expressions_1 = require("@plaudit/php-writer/expressions");
13
15
  const shared_1 = require("../shared");
14
- const php_writer_1 = require("../utils/php-writer");
15
16
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
16
17
  const webpack_1 = require("webpack");
17
18
  class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
@@ -119,12 +120,11 @@ class PlainEntrypointsStyleBlockJSONPlugin extends AbstractBiPhasicGroupAndEntry
119
120
  if (this.config.useUnifiedLoader) {
120
121
  const metadata = blockData['__metadata'];
121
122
  delete blockData['__metadata'];
122
- new php_writer_1.PHPWriter()
123
+ (0, shared_1.emitPHPWriterAsAsset)(new php_writer_1.PHPWriter()
123
124
  .action("init", writer => {
124
- writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [php_writer_1.Constants.__DIR__, new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")),
125
- php_writer_1.Constants.__FILE__, new php_writer_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(metadata, false, "\t")), null]);
126
- }, { accountForAlreadyDoing: this.config.includePostInitFallback })
127
- .emitAsset(compilation, node_path_1.default.join(this.dest.destination, "blockdir-loader.php"));
125
+ writer.call("\\Plaudit\\Common\\ACF\\BlockManager::autoloadSubfoldersV3", [expressions_1.Constants.__DIR__, new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(blockData, false, "\t")),
126
+ expressions_1.Constants.__FILE__, new expressions_1.EnclosedLiteral((0, shared_1.makeEmittableConfigPHP)(metadata, false, "\t")), null]);
127
+ }, { accountForAlreadyDoing: this.config.includePostInitFallback }), compilation, node_path_1.default.join(this.dest.destination, "blockdir-loader.php"));
128
128
  }
129
129
  else {
130
130
  compilation.emitAsset(node_path_1.default.join(this.dest.destination, "blockdir.config.php"), new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockData, true)));
@@ -5,8 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SpecialAssetHandlingPlugin = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const php_writer_1 = require("@plaudit/php-writer");
9
+ const expressions_1 = require("@plaudit/php-writer/expressions");
8
10
  const shared_1 = require("../shared");
9
- const php_writer_1 = require("../utils/php-writer");
10
11
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
11
12
  const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
12
13
  const UnifiedLoaderGenerator_1 = require("./UnifiedLoaderGenerator");
@@ -68,7 +69,7 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
68
69
  const writer = new php_writer_1.PHPWriter();
69
70
  if (!preloadedAssets.length) {
70
71
  if (!this.config.useUnifiedLoader) {
71
- writer.emitAsset(compilation, outputFile);
72
+ (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, outputFile);
72
73
  }
73
74
  return;
74
75
  }
@@ -76,8 +77,8 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
76
77
  (0, shared_1.emitResolveBaseUriFunction)(writer);
77
78
  }
78
79
  writer.action("wp_head", writer => {
79
- const baseUriVar = new php_writer_1.Var("base_uri");
80
- writer.call("plaudit_webpack_extensions__resolve_base_uri", [php_writer_1.Constants.__DIR__], { assignTo: baseUriVar }).closePHP();
80
+ const baseUriVar = new expressions_1.Var("base_uri");
81
+ writer.call("plaudit_webpack_extensions__resolve_base_uri", [expressions_1.Constants.__DIR__], { assignTo: baseUriVar }).closePHP();
81
82
  for (let [filename, { preload, fetchpriority, crossorigin }] of preloadedAssets) {
82
83
  if (!preload) {
83
84
  continue;
@@ -116,11 +117,11 @@ class SpecialAssetHandlingPlugin extends AbstractBiPhasicGroupPlugin_1.AbstractB
116
117
  attributes.push(["crossorigin", crossorigin]);
117
118
  }
118
119
  const dynamicAttrs = attributes.map(([k, v]) => v ? `${k}="${v}"` : k).join(" ");
119
- writer.append(`<link rel="preload" href="<?= ${php_writer_1.Expr.call("esc_url", [php_writer_1.Op.concat(baseUriVar, filename)])} ?>" ${dynamicAttrs}>`);
120
+ writer.append(`<link rel="preload" href="<?= ${expressions_1.Expr.call("esc_url", [expressions_1.Op.concat(baseUriVar, filename)])} ?>" ${dynamicAttrs}>`);
120
121
  }
121
122
  writer.openPHP();
122
123
  });
123
- writer.emitAsset(compilation, outputFile);
124
+ (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, outputFile);
124
125
  }
125
126
  attachUniquePhase(compilation) {
126
127
  compilation.hooks.processAssets.tapPromise({ name: this.constructor.name, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT }, async () => {
@@ -1,6 +1,6 @@
1
+ import { PHPWriter } from "@plaudit/php-writer";
1
2
  import { AbstractBiPhasicGroupPlugin } from "./AbstractBiPhasicGroupPlugin";
2
3
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
- import { PHPWriter } from "../utils/php-writer";
4
4
  import { PseudoSemaphore } from "../utils/pseduo-semaphore";
5
5
  import { Compilation } from "webpack";
6
6
  type LoaderInfo = {
@@ -5,10 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.UnifiedLoaderGenerator = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const php_writer_1 = require("@plaudit/php-writer");
8
9
  const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
9
10
  const shared_1 = require("../shared");
10
- const json_to_php_but_with____injection_1 = __importDefault(require("../utils/json-to-php-but-with-__-injection"));
11
- const php_writer_1 = require("../utils/php-writer");
12
11
  const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
13
12
  const webpack_1 = require("webpack");
14
13
  class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
@@ -53,7 +52,7 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
53
52
  continue;
54
53
  }
55
54
  const parsedPath = node_path_1.default.parse(file);
56
- const contents = `<?php return ${(0, json_to_php_but_with____injection_1.default)(assetData)};\n`;
55
+ const contents = `<?php return ${(0, php_writer_1.json2php)(assetData)};\n`;
57
56
  compilation.emitAsset(node_path_1.default.join(parsedPath.dir, parsedPath.name) + ".asset.php", new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) });
58
57
  }
59
58
  if (this.config.useUnifiedLoader) {
@@ -65,7 +64,7 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
65
64
  for (const { action } of groupedLoaderInfo) {
66
65
  action(writer);
67
66
  }
68
- writer.emitAsset(compilation, "unified-loader.php");
67
+ (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, "unified-loader.php");
69
68
  });
70
69
  }
71
70
  });
package/build/shared.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { PHPWriter } from "./utils/php-writer";
1
+ import { PHPWriter } from "@plaudit/php-writer";
2
2
  import type { Options as PostcssFunctionsOptions } from "postcss-functions";
3
- import { Compilation, type Configuration, WebpackError } from "webpack";
3
+ import { AssetInfo, Compilation, type Configuration, WebpackError } from "webpack";
4
4
  export type ParsedAssetsJson = Record<string, {
5
5
  dependencies: string[];
6
6
  version: string;
@@ -129,7 +129,7 @@ export declare const scriptExtension: RegExp;
129
129
  export declare const scriptWithoutModuleExtension: RegExp;
130
130
  export declare const scriptWithModuleExtension: RegExp;
131
131
  export declare const styleExtension: RegExp;
132
- export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "" | "style" | "script";
132
+ export declare function scriptOrStyleTest(entryPath: string, scriptExtension: RegExp): "style" | "script" | "";
133
133
  export declare function isStyleField(field: string): field is 'style' | 'viewStyle' | 'editorStyle';
134
134
  export declare function isScriptModuleField(field: string): field is 'scriptModule' | 'viewScriptModule';
135
135
  export declare function getHandleGroup(field: string): 'styleHandles' | 'scriptHandles' | 'scriptModuleHandles';
@@ -146,4 +146,6 @@ export declare function newWebpackErrorForFile(error: string | ConstructorParame
146
146
  */
147
147
  export declare function emitResolveBaseUriFunction(writer: PHPWriter): void;
148
148
  export declare function getAssetsJson(compilation: Compilation): ParsedAssetsJson;
149
+ export declare function emitPHPWriterAsAsset(writer: PHPWriter, compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
150
+ export declare function dedent(text: TemplateStringsArray): string;
149
151
  export {};
package/build/shared.js CHANGED
@@ -24,9 +24,11 @@ exports.parseEnvFile = parseEnvFile;
24
24
  exports.newWebpackErrorForFile = newWebpackErrorForFile;
25
25
  exports.emitResolveBaseUriFunction = emitResolveBaseUriFunction;
26
26
  exports.getAssetsJson = getAssetsJson;
27
+ exports.emitPHPWriterAsAsset = emitPHPWriterAsAsset;
28
+ exports.dedent = dedent;
27
29
  const promises_1 = __importDefault(require("node:fs/promises"));
28
- const json_to_php_but_with____injection_1 = __importDefault(require("./utils/json-to-php-but-with-__-injection"));
29
- const php_writer_1 = require("./utils/php-writer");
30
+ const php_writer_1 = require("@plaudit/php-writer");
31
+ const expressions_1 = require("@plaudit/php-writer/expressions");
30
32
  const webpack_1 = require("webpack");
31
33
  function isParsedAssetsJson(thing) {
32
34
  if (!thing || typeof thing !== 'object') {
@@ -73,7 +75,7 @@ function convertUsageLocationsHandleToEmittableHandle(handle, generatedHandle) {
73
75
  return emittableHandle.replaceAll("{basename}", generatedHandle);
74
76
  }
75
77
  function makeEmittableConfigPHP(data, asFullFile, parentIndent = "") {
76
- const prettyPrintedMetadata = json_to_php_but_with____injection_1.default.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, parentIndent)
78
+ const prettyPrintedMetadata = php_writer_1.json2php.make({ indent: "\t", linebreak: "\n", shortArraySyntax: true })(data, parentIndent)
77
79
  .replaceAll(/(\n\t*)\[\s+],/gs, "$1[],")
78
80
  .replaceAll(/\[\n\t+([^\n]+)\n\t+]/gs, (_, inner) => `[${inner.trim()}]`)
79
81
  .replaceAll(/'rest' => \[\n\t+(\[(?:'[^']+')?]),\n\t+('[^']+')(?:,\n\t+(\[[^\n]+]))?\n\t+]/gs, (_, deps, hash, args) => `'rest' => [${[deps, hash, args].filter(value => !!value).join(", ")}]`);
@@ -143,24 +145,24 @@ function newWebpackErrorForFile(error, file) {
143
145
  * The primary benefit of emitting a function instead of baking its contents into each function that uses it is that it allows us to avoid recomputing the base uri multiple times
144
146
  */
145
147
  function emitResolveBaseUriFunction(writer) {
146
- const dir = new php_writer_1.Var("dir");
147
- const baseUris = new php_writer_1.Var("base_uris");
148
- const assignmentTarget = new php_writer_1.ArrayAccess(baseUris, dir);
149
- const path = new php_writer_1.Var("path");
148
+ const dir = new expressions_1.Var("dir");
149
+ const baseUris = new expressions_1.Var("base_uris");
150
+ const assignmentTarget = new expressions_1.ArrayAccess(baseUris, dir);
151
+ const path = new expressions_1.Var("path");
150
152
  writer.function("plaudit_webpack_extensions__resolve_base_uri", [dir], writer => {
151
153
  writer
152
154
  .static(baseUris, { initializer: [] })
153
- .if(php_writer_1.Expr.isset(assignmentTarget))
155
+ .if(expressions_1.Expr.isset(assignmentTarget))
154
156
  .return(assignmentTarget)
155
- .elseIf(php_writer_1.Expr.call("str_starts_with", [dir, php_writer_1.Constants.ABSPATH]))
156
- .assign(path, php_writer_1.Expr.call("ltrim", [php_writer_1.Expr.call("substr", [dir, php_writer_1.Expr.call("strlen", [php_writer_1.Constants.ABSPATH])]), "/"]))
157
- .elseIf(php_writer_1.Expr.call("str_starts_with", [dir, "/workspace/website"]))
158
- .assign(path, php_writer_1.Expr.call("ltrim", [php_writer_1.Expr.call("substr", [dir, 18]), "/"]))
157
+ .elseIf(expressions_1.Expr.call("str_starts_with", [dir, expressions_1.Constants.ABSPATH]))
158
+ .assign(path, expressions_1.Expr.call("ltrim", [expressions_1.Expr.call("substr", [dir, expressions_1.Expr.call("strlen", [expressions_1.Constants.ABSPATH])]), "/"]))
159
+ .elseIf(expressions_1.Expr.call("str_starts_with", [dir, "/workspace/website"]))
160
+ .assign(path, expressions_1.Expr.call("ltrim", [expressions_1.Expr.call("substr", [dir, 18]), "/"]))
159
161
  .else()
160
162
  .call("error_log", ["UNABLE TO FIGURE OUT WHAT THE RELATIVE PATH TO THE BUILT FILES DIRECTORY SHOULD BE"])
161
163
  .assign(path, "")
162
164
  .endIf()
163
- .call("trailingslashit", [php_writer_1.Expr.call("home_url", [path])], { return: true, assignTo: assignmentTarget });
165
+ .call("trailingslashit", [expressions_1.Expr.call("home_url", [path])], { return: true, assignTo: assignmentTarget });
164
166
  }, { returnType: "string", includeExistenceCheck: true });
165
167
  }
166
168
  function getAssetsJson(compilation) {
@@ -178,3 +180,15 @@ function getAssetsJson(compilation) {
178
180
  compilation.updateAsset("assets.json", s => s, a => ({ ...a, "parsed-assets-json": parsedAssetJson }));
179
181
  return parsedAssetJson;
180
182
  }
183
+ function emitPHPWriterAsAsset(writer, compilation, file, assetInfo) {
184
+ const contents = writer.toString() + "\n";
185
+ compilation[file in compilation.assets ? 'updateAsset' : 'emitAsset'](file, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents), ...assetInfo });
186
+ }
187
+ function dedent(text) {
188
+ const actualText = text.join("\n");
189
+ const firstLineIndent = actualText.split("\r?\n").find(line => line.length > 0)?.match(/^\s+/)?.[0];
190
+ if (!firstLineIndent) {
191
+ return actualText;
192
+ }
193
+ return actualText.replaceAll(new RegExp("^" + firstLineIndent, 'mg'), "").replace(/\n{2}$/, "\n");
194
+ }
@@ -22,7 +22,6 @@ const VariablesJSMonitorPlugin_1 = require("./plugins/VariablesJSMonitorPlugin")
22
22
  const WPMLConfigBuilder_1 = require("./plugins/WPMLConfigBuilder");
23
23
  const static_configs_1 = require("./plugins/static-configs");
24
24
  const UnifiedLoaderGenerator_1 = require("./plugins/UnifiedLoaderGenerator");
25
- const dependency_extraction_webpack_plugin_1 = __importDefault(require("@wordpress/dependency-extraction-webpack-plugin"));
26
25
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
27
26
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
28
27
  const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
@@ -400,10 +399,16 @@ function buildCommonPluginConfig(webpackConfig, config, bundleAnalyzer, assumeGl
400
399
  plugins.push(new SpecialAssetHandlingPlugin_1.SpecialAssetHandlingPlugin(config));
401
400
  }
402
401
  plugins.push(new VariablesJSMonitorPlugin_1.VariablesJSMonitorPlugin(config));
403
- const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin instanceof dependency_extraction_webpack_plugin_1.default);
402
+ // We have to use constructor.name here the version desyncs can result in multiple equivalent versions kicking around
403
+ const dependencyExtractionPluginIndex = plugins.findIndex(plugin => plugin.constructor.name === 'DependencyExtractionWebpackPlugin');
404
404
  if (dependencyExtractionPluginIndex === -1) {
405
- console.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");
406
- throw new Error();
405
+ console.error((0, shared_1.dedent) `
406
+ Unable to find the DependencyExtractionWebpackPlugin.
407
+ If this is your first time seeing this error, please run: pnpm up && pnpm dedupe && pnpm up
408
+ Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.
409
+ `);
410
+ console.error("Once those commands have finished, re-run whichever command had this error. If it still doesn't work, report the issue immediately.");
411
+ 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");
407
412
  }
408
413
  const builtDependencyExtractionWebpackPlugin = (0, dependency_extraction_webpack_plugin_config_builder_1.makeDependencyExtractionPlugin)(externals, assumeGlobalizedPlauditLibraries, true, externalize);
409
414
  plugins[dependencyExtractionPluginIndex] = builtDependencyExtractionWebpackPlugin.instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.71.0",
3
+ "version": "2.72.1",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build"
@@ -20,9 +20,9 @@
20
20
  }
21
21
  },
22
22
  "devDependencies": {
23
- "@plaudit/gutenberg-api-extensions": "^2.77.2",
23
+ "@plaudit/gutenberg-api-extensions": "^2.78.1",
24
24
  "@types/browser-sync-webpack-plugin": "^2.2.5",
25
- "@types/node": "^24.7.1",
25
+ "@types/node": "^24.9.2",
26
26
  "@types/postcss-functions": "^4.0.4",
27
27
  "@types/tapable": "^2.3.0",
28
28
  "@types/webpack": "^5.28.5",
@@ -34,13 +34,14 @@
34
34
  "webpack-bundle-analyzer": "^4.10.2"
35
35
  },
36
36
  "dependencies": {
37
+ "@plaudit/php-writer": "^1.2.3",
37
38
  "@plaudit/postcss-color-function": "^5.0.0",
38
39
  "@plaudit/postcss-legacy-shorthand": "^1.0.0",
39
40
  "@plaudit/postcss-silent-extend": "^3.0.0",
40
41
  "@plaudit/postcss-strip-units": "^3.0.0",
41
42
  "@plaudit/postcss-variables": "^1.1.0",
42
- "@wordpress/dependency-extraction-webpack-plugin": "^6.32.0",
43
- "@wordpress/scripts": "^30.25.0",
43
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.34.0",
44
+ "@wordpress/scripts": "^30.27.0",
44
45
  "autoprefixer": "^10.4.21",
45
46
  "browser-sync": "^3.0.4",
46
47
  "copy-webpack-plugin": "^10.2.4",
@@ -1,11 +0,0 @@
1
- type MakeProps = {
2
- linebreak?: string;
3
- indent?: string;
4
- shortArraySyntax?: boolean;
5
- stripSpaces?: boolean;
6
- };
7
- declare const make: (props?: MakeProps) => (obj: unknown, parentIndent?: string) => string;
8
- declare const json2php: ReturnType<typeof make> & {
9
- make: typeof make;
10
- };
11
- export default json2php;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const acceptedObjectTypes = ['[object Array]', '[object Object]'];
4
- const make = (props = {}) => {
5
- const linebreak = props.linebreak ?? '';
6
- const indent = props.indent ?? '';
7
- const stripSpaces = props.stripSpaces ?? false;
8
- const shortArraySyntax = props.shortArraySyntax ?? true;
9
- const arrOpen = shortArraySyntax ? '[' : 'array(';
10
- const arrClose = shortArraySyntax ? ']' : ')';
11
- const arrow = stripSpaces ? '=>' : ' => ';
12
- function transformInner(obj, parentIndent, state) {
13
- switch (typeof obj) {
14
- case 'undefined':
15
- return 'null';
16
- case 'bigint':
17
- case 'number':
18
- case 'boolean':
19
- return obj.toString();
20
- case 'string':
21
- const res = obj.replace("\\", '\\\\').replaceAll("'", "\\'");
22
- if (!/\s*/.test(res) && !state.isKey && state.path.length === 4 && state.path[1] === 'attributes' && state.path[3] === 'default' && state.parent?.['translatable']) {
23
- return `__('${res}')`;
24
- }
25
- return `'${res}'`;
26
- case 'object':
27
- if (obj === null)
28
- return 'null';
29
- const objType = Object.prototype.toString.call(obj);
30
- if (objType === '[object Date]')
31
- return obj.toISOString();
32
- if (!acceptedObjectTypes.includes(objType))
33
- return 'null';
34
- const nestIndent = parentIndent + indent;
35
- const items = Array.isArray(obj)
36
- ? obj.map((item, i) => transformInner(item, nestIndent, { path: [...state.path, i], parent: obj }))
37
- : Object.entries(obj).map(([key, value]) => {
38
- return transformInner(key, nestIndent, { path: [...state.path, key], parent: obj, isKey: true })
39
- + arrow + transformInner(value, nestIndent, { path: [...state.path, key], parent: obj });
40
- });
41
- const itemStr = items.join(`,${linebreak === '' && !stripSpaces ? ' ' : linebreak + nestIndent}`);
42
- return `${arrOpen}${linebreak + nestIndent}${itemStr}${linebreak + parentIndent}${arrClose}`;
43
- default:
44
- return 'null';
45
- }
46
- }
47
- return function transform(obj, parentIndent = '') {
48
- return transformInner(obj, parentIndent, { path: [] });
49
- };
50
- };
51
- const json2php = make();
52
- json2php.make = make;
53
- exports.default = json2php;
@@ -1,6 +0,0 @@
1
- type Config = {
2
- objectsAsArrays?: boolean;
3
- excludedKeys?: string[];
4
- };
5
- export declare function phpSerialize(value: any, config?: Config): string;
6
- export {};
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.phpSerialize = phpSerialize;
4
- function phpSerialize(value, config) {
5
- switch (typeof value) {
6
- case "undefined":
7
- return "N;";
8
- case "object":
9
- if (value === null) {
10
- return "N;"; // Yep. Null is an "object" in JavaScript
11
- }
12
- else if (Array.isArray(value)) {
13
- let res = `a:${value.length}:{`;
14
- for (let i = 0; i < value.length; i++) {
15
- res += `i:${i};${phpSerialize(value[i], config)}`;
16
- }
17
- return (res.endsWith('};') ? res.substring(0, res.length - 1) : res) + "}";
18
- }
19
- return entriesInArrayAndObjectFormat(config?.objectsAsArrays ?? true ? 'a' : 'O:8:"stdClass"', Object.entries(value), config);
20
- case "boolean":
21
- return `b:${value ? 1 : 0};`;
22
- case "number":
23
- return Number.isInteger(value) ? serializeInteger(value) : `d:${value};`;
24
- case "string":
25
- return `s:${Buffer.byteLength(value, 'utf8')}:"${value}";`;
26
- case "function":
27
- throw new Error(`We are unable to serialize functions into a form readable by PHP.`);
28
- case "symbol":
29
- value = value.toString();
30
- return `s:${Buffer.byteLength(value, 'utf8')}:"${value}";`;
31
- case "bigint":
32
- return serializeInteger(value);
33
- }
34
- }
35
- function serializeInteger(value) {
36
- const str = value.toString();
37
- if (str.includes("e") || str.includes("E")) {
38
- return `d:${str.replace(/e/i, ".0e")};`;
39
- }
40
- return `i:${str};`;
41
- }
42
- function entriesInArrayAndObjectFormat(prefix, entries, config) {
43
- const excludedKeys = config?.excludedKeys ?? [];
44
- let res = "";
45
- let count = 0;
46
- for (const [k, v] of entries) {
47
- if (!excludedKeys.includes(k)) {
48
- count++;
49
- res += `${phpSerialize(k, config)}${phpSerialize(v, config)}`;
50
- }
51
- }
52
- return `${prefix}:${count}:{` + (res.endsWith('};') ? res.substring(0, res.length - 1) : res) + "}";
53
- }