@plaudit/webpack-extensions 2.54.0 → 2.55.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/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.js +3 -3
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.d.ts +4 -2
- package/build/{wordpress-scripts-wrapper → plugins}/BlockJSONManagingPlugin.js +14 -9
- package/build/{wordpress-scripts-wrapper → plugins}/ExtensionsConfigFileGeneratorPlugin.d.ts +6 -3
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +173 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.d.ts +24 -0
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +244 -0
- package/build/plugins/SpecialAssetHandlingPlugin.d.ts +12 -0
- package/build/plugins/SpecialAssetHandlingPlugin.js +135 -0
- package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.js +1 -1
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.d.ts +3 -2
- package/build/{wordpress-scripts-wrapper → plugins}/WPMLConfigBuilder.js +7 -3
- package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.d.ts +1 -7
- package/build/shared.d.ts +45 -18
- package/build/shared.js +18 -5
- package/build/utils/common-config-helpers.d.ts +26 -0
- package/build/utils/common-config-helpers.js +336 -0
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.d.ts +1 -1
- package/build/{wordpress-scripts-wrapper → utils}/php-serializer.js +1 -1
- package/build/utils/php-writer.d.ts +54 -0
- package/build/utils/php-writer.js +191 -0
- package/build/utils/pseduo-semaphore.d.ts +13 -0
- package/build/utils/pseduo-semaphore.js +63 -0
- package/build/wordpress-scripts-wrapper.d.ts +1 -20
- package/build/wordpress-scripts-wrapper.js +232 -443
- package/package.json +4 -4
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.js +0 -125
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.d.ts +0 -7
- package/build/wordpress-scripts-wrapper/SpecialAssetHandlingPlugin.js +0 -107
- /package/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/BrowserSyncPlugin.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/MiniCSSExtractPluginErrorCleaner.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/PackageConfigSanityChecker.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/VariablesJSMonitorPlugin.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/dependency-extraction-webpack-plugin-config-builder.js +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → plugins}/static-configs.js +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.d.ts +0 -0
- /package/build/{wordpress-scripts-wrapper → utils}/json-to-php-but-with-__-injection.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.55.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"/build"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@plaudit/gutenberg-api-extensions": "^2.75.0",
|
|
20
20
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
21
|
-
"@types/node": "^22.
|
|
21
|
+
"@types/node": "^22.17.0",
|
|
22
22
|
"@types/postcss-functions": "^4.0.4",
|
|
23
23
|
"@types/tapable": "^2.2.7",
|
|
24
24
|
"@types/webpack": "^5.28.5",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"postcss-load-config": "^4.0.2",
|
|
27
27
|
"postcss-loader": "^7.3.4",
|
|
28
28
|
"ts-node": "^10.9.2",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.9.2",
|
|
30
30
|
"webpack-bundle-analyzer": "^4.10.2"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"postcss-url": "^10.1.3",
|
|
64
64
|
"react": "^18.3.1",
|
|
65
65
|
"react-dom": "^18.3.1",
|
|
66
|
-
"webpack": "^5.
|
|
66
|
+
"webpack": "^5.101.0",
|
|
67
67
|
"webpack-remove-empty-scripts": "^1.1.1",
|
|
68
68
|
"xml-formatter": "^3.6.6"
|
|
69
69
|
},
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ExtensionsConfigFileGeneratorPlugin = void 0;
|
|
7
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const php_serializer_1 = __importDefault(require("./php-serializer"));
|
|
10
|
-
const shared_1 = require("../shared");
|
|
11
|
-
const webpack_1 = require("webpack");
|
|
12
|
-
class ExtensionsConfigFileGeneratorPlugin {
|
|
13
|
-
extensionsPath;
|
|
14
|
-
version;
|
|
15
|
-
cache;
|
|
16
|
-
constructor(extensionsPath, version, cache) {
|
|
17
|
-
this.extensionsPath = extensionsPath;
|
|
18
|
-
this.version = version;
|
|
19
|
-
this.cache = cache;
|
|
20
|
-
}
|
|
21
|
-
apply(compiler) {
|
|
22
|
-
compiler.hooks.make.tapPromise(this.constructor.name, async (compilation) => {
|
|
23
|
-
if (!compilation.contextDependencies.has(this.extensionsPath)) {
|
|
24
|
-
compilation.contextDependencies.add(this.extensionsPath);
|
|
25
|
-
}
|
|
26
|
-
const emissionPromises = [];
|
|
27
|
-
for (const setupFilePath of await promises_1.default.readdir(this.extensionsPath)) {
|
|
28
|
-
if (setupFilePath.endsWith("-setup.php")) {
|
|
29
|
-
const setupFileSourcePath = node_path_1.default.join(this.extensionsPath, setupFilePath);
|
|
30
|
-
compilation.fileDependencies.add(setupFileSourcePath);
|
|
31
|
-
emissionPromises.push(promises_1.default.readFile(setupFileSourcePath)
|
|
32
|
-
.then(contents => compilation.emitAsset(setupFilePath, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) })));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
await Promise.all(emissionPromises);
|
|
36
|
-
});
|
|
37
|
-
if (this.version === 2) {
|
|
38
|
-
const tapName = { name: `${this.constructor.name}_ProcessBlockJSONFiles`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_REPORT };
|
|
39
|
-
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
40
|
-
this.cache.extensionsConfig = undefined;
|
|
41
|
-
compilation.hooks.processAssets.tap(tapName, assets => {
|
|
42
|
-
if (this.cache.extensionsConfig === undefined) {
|
|
43
|
-
this.cache.extensionsConfig = { assets: [], setupFiles: [] };
|
|
44
|
-
compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_GenerateConfigFile`, () => {
|
|
45
|
-
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
46
|
-
const blockExtensionsConfig = { metadata: { version: this.version }, scriptHandles: {}, styleHandles: {}, blocks: {}, setupFiles: {} };
|
|
47
|
-
for (const assetDataSource of this.cache.extensionsConfig?.assets ?? []) {
|
|
48
|
-
for (const [assetPath, assetData] of Object.entries(assetDataSource)) {
|
|
49
|
-
let match, blockSlug, assetType;
|
|
50
|
-
if ((match = regex.exec(assetPath)) && (blockSlug = match[1]) && (assetType = match[2])) {
|
|
51
|
-
const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
52
|
-
const handle = `plaudit_block-extension_${blockSlug}-${assetType}`;
|
|
53
|
-
const isCss = assetType.endsWith("tyle");
|
|
54
|
-
blockExtensionsConfig[isCss ? 'styleHandles' : 'scriptHandles'][handle] = {
|
|
55
|
-
src: isCss ? assetPath.replace(/\.js$/, ".css") : assetPath,
|
|
56
|
-
rest: isCss || key.startsWith("editor")
|
|
57
|
-
? [assetData.dependencies, assetData.version]
|
|
58
|
-
: [assetData.dependencies, assetData.version, { strategy: 'defer' }]
|
|
59
|
-
};
|
|
60
|
-
(blockExtensionsConfig.blocks[blockSlug] ?? (blockExtensionsConfig.blocks[blockSlug] = {}))[key] = handle;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
for (const [blockSlug, asset] of this.cache.extensionsConfig?.setupFiles ?? []) {
|
|
64
|
-
blockExtensionsConfig.setupFiles[blockSlug] = asset;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
blockExtensionsConfig.scriptHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.scriptHandles)
|
|
68
|
-
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
69
|
-
blockExtensionsConfig.styleHandles = Object.fromEntries(Object.entries(blockExtensionsConfig.styleHandles)
|
|
70
|
-
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
71
|
-
blockExtensionsConfig.setupFiles = Object.fromEntries(Object.entries(blockExtensionsConfig.setupFiles)
|
|
72
|
-
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
73
|
-
blockExtensionsConfig.blocks = Object.fromEntries(Object.entries(blockExtensionsConfig.blocks)
|
|
74
|
-
.map(block => {
|
|
75
|
-
return [block[0], Object.fromEntries(Object.entries(block[1]).toSorted(([a], [b]) => a.localeCompare(b)))];
|
|
76
|
-
})
|
|
77
|
-
.toSorted(([a], [b]) => a.localeCompare(b)));
|
|
78
|
-
compilation.emitAsset("mapping.config.php", new webpack_1.sources.RawSource((0, shared_1.makeEmittableConfigPHP)(blockExtensionsConfig)));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
for (const asset of Object.keys(compilation.assets)) {
|
|
82
|
-
const blockSlug = /^(.+?)-setup.php$/i.exec(asset)?.[1];
|
|
83
|
-
if (blockSlug) {
|
|
84
|
-
this.cache.extensionsConfig.setupFiles.push([blockSlug, asset]);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const rawAssetDataSource = assets["assets.json"]?.source();
|
|
88
|
-
if (typeof rawAssetDataSource !== 'string') {
|
|
89
|
-
throw new Error("assets.json is unexpectedly missing or not a string");
|
|
90
|
-
}
|
|
91
|
-
const assetDataSource = JSON.parse(rawAssetDataSource);
|
|
92
|
-
if (!(0, shared_1.isRawAssetData)(assetDataSource)) {
|
|
93
|
-
throw new Error("assets.json is does not match the RawAssetData format");
|
|
94
|
-
}
|
|
95
|
-
this.cache.extensionsConfig.assets.push(assetDataSource);
|
|
96
|
-
compilation.deleteAsset("assets.json");
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
|
|
102
|
-
compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_AfterProcessAssets`, this.makeVersionOneAfterProcessAssets(compilation));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
makeVersionOneAfterProcessAssets(compilation) {
|
|
107
|
-
return compilationAssets => {
|
|
108
|
-
const regex = /^(.+?)-((?:editor-|view-|)(?:style|script|script-module))\.(?:css|m?js)$/i;
|
|
109
|
-
const mapping = {};
|
|
110
|
-
for (const asset of Object.keys(compilationAssets)) {
|
|
111
|
-
let match;
|
|
112
|
-
if ((match = /^(.+?)-setup.php$/i.exec(asset)) && match[1]) {
|
|
113
|
-
(mapping[match[1]] ?? (mapping[match[1]] = [{}]))[1] = `${asset}`;
|
|
114
|
-
}
|
|
115
|
-
else if ((match = regex.exec(asset)) && match[1] && match[2]) {
|
|
116
|
-
const resourceInfo = (mapping[match[1]] ?? (mapping[match[1]] = [{}]))[0];
|
|
117
|
-
const key = match[2].replace(/-[sm]/gi, chars => chars.substring(1).toUpperCase());
|
|
118
|
-
(resourceInfo[key] ?? (resourceInfo[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
compilation.emitAsset("mapping.config", new webpack_1.sources.RawSource((0, php_serializer_1.default)(mapping)));
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.ExtensionsConfigFileGeneratorPlugin = ExtensionsConfigFileGeneratorPlugin;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Compiler, WebpackPluginInstance } from "webpack";
|
|
2
|
-
import { SharedCache } from "../shared";
|
|
3
|
-
export declare class SpecialAssetHandlingPlugin implements WebpackPluginInstance {
|
|
4
|
-
private readonly cache;
|
|
5
|
-
constructor(cache: SharedCache);
|
|
6
|
-
apply(compiler: Compiler): void;
|
|
7
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SpecialAssetHandlingPlugin = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const webpack_1 = require("webpack");
|
|
9
|
-
class SpecialAssetHandlingPlugin {
|
|
10
|
-
cache;
|
|
11
|
-
constructor(cache) {
|
|
12
|
-
this.cache = cache;
|
|
13
|
-
}
|
|
14
|
-
apply(compiler) {
|
|
15
|
-
compiler.hooks.compilation.tap(this.constructor.name, compilation => {
|
|
16
|
-
this.cache.specialAssets = undefined;
|
|
17
|
-
compilation.hooks.processAssets.tap(this.constructor.name, assets => {
|
|
18
|
-
for (const pathname of Object.keys(assets)) {
|
|
19
|
-
const assetInfo = compilation.assetsInfo.get(pathname);
|
|
20
|
-
if (!assetInfo?.sourceFilename) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const queryStart = assetInfo.sourceFilename.indexOf('?');
|
|
24
|
-
if (queryStart < 0) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const params = new URLSearchParams(assetInfo.sourceFilename.substring(queryStart + 1)
|
|
28
|
-
.replace(/(?:fetchPriority|crossOrigin)=/gi, str => str.toLowerCase()) //This ensures consistent capitalization of the fetchPriority parameter
|
|
29
|
-
);
|
|
30
|
-
if (this.cache.specialAssets === undefined) {
|
|
31
|
-
this.cache.specialAssets = { files: {} };
|
|
32
|
-
const outputFile = node_path_1.default.join(node_path_1.default.dirname(node_path_1.default.dirname(pathname)), "special-assets.php");
|
|
33
|
-
compilation.hooks.afterProcessAssets.tap(`${this.constructor.name}_GeneratePreloadingFile`, () => {
|
|
34
|
-
if (!this.cache.specialAssets?.files) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const hookTextLines = [
|
|
38
|
-
"<?php",
|
|
39
|
-
"add_action('wp_head', function() {",
|
|
40
|
-
"\tif (str_starts_with(__DIR__, ABSPATH)) {",
|
|
41
|
-
"\t\t$path = ltrim(substr(__DIR__, strlen(ABSPATH)), '/');",
|
|
42
|
-
"\t} else if (str_starts_with(__DIR__, '/workspace/website')) {",
|
|
43
|
-
"\t\t$path = ltrim(substr(__DIR__, 18), '/');",
|
|
44
|
-
"\t} else {",
|
|
45
|
-
"\t\terror_log('UNABLE TO FIGURE OUT WHAT THE RELATIVE PATH TO THE FONT DIRECTORY SHOULD BE');",
|
|
46
|
-
"\t\treturn;",
|
|
47
|
-
"\t}",
|
|
48
|
-
"\t$base_uri = trailingslashit(home_url($path));",
|
|
49
|
-
"\t?>"
|
|
50
|
-
];
|
|
51
|
-
const preloadedFonts = Object.entries(this.cache.specialAssets.files)
|
|
52
|
-
.filter(([_, { preload }]) => preload)
|
|
53
|
-
.sort(([a], [b]) => a.localeCompare(b));
|
|
54
|
-
for (let [filename, { preload, fetchpriority, crossorigin }] of preloadedFonts) {
|
|
55
|
-
if (!preload) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
let fileExtension = node_path_1.default.extname(filename);
|
|
59
|
-
if (fileExtension.startsWith(".")) {
|
|
60
|
-
fileExtension = fileExtension.substring(1).toLowerCase();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
fileExtension = fileExtension.toLowerCase();
|
|
64
|
-
}
|
|
65
|
-
const attributes = [];
|
|
66
|
-
if (["woff", "woff2", "ttf", "otf", "eot"].includes(fileExtension)) {
|
|
67
|
-
if (!crossorigin) {
|
|
68
|
-
crossorigin = "anonymous";
|
|
69
|
-
}
|
|
70
|
-
attributes.push(["as", "font"], ["type", `font/${fileExtension}`]);
|
|
71
|
-
}
|
|
72
|
-
else if (fileExtension === "svg") {
|
|
73
|
-
attributes.push(["as", "image"], ["type", `image/svg+xml`]);
|
|
74
|
-
}
|
|
75
|
-
else if (fileExtension === "jpeg" || fileExtension === "jpg") {
|
|
76
|
-
attributes.push(["as", "image"], ["type", `image/jpeg`]);
|
|
77
|
-
}
|
|
78
|
-
else if (["png", "webp", "avif", "gif", "bmp"].includes(fileExtension)) {
|
|
79
|
-
attributes.push(["as", "image"], ["type", `image/${fileExtension}`]);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
compilation.errors.push(new Error(`Encountered preloading markup on an unsupported file extension (${fileExtension}). Full resource path: ${assetInfo.sourceFilename}`));
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (fetchpriority && fetchpriority !== 'auto') {
|
|
86
|
-
attributes.push(["fetchpriority", fetchpriority]);
|
|
87
|
-
}
|
|
88
|
-
if (crossorigin || crossorigin === "") {
|
|
89
|
-
attributes.push(["crossorigin", crossorigin]);
|
|
90
|
-
}
|
|
91
|
-
const dynamicAttrs = attributes.map(([k, v]) => v ? `${k}="${v}"` : k).join(" ");
|
|
92
|
-
hookTextLines.push(`\t<link rel="preload" href="<?= esc_url($base_uri.'${filename}') ?>" ${dynamicAttrs}>`);
|
|
93
|
-
}
|
|
94
|
-
hookTextLines.push("\t<?php", "});\n");
|
|
95
|
-
compilation.emitAsset(outputFile, new webpack_1.sources.RawSource(hookTextLines.join("\n")));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
const filename = node_path_1.default.join(node_path_1.default.basename(node_path_1.default.dirname(pathname)), node_path_1.default.basename(pathname));
|
|
99
|
-
if (params.has("preload")) {
|
|
100
|
-
this.cache.specialAssets.files[filename] = { preload: true, fetchpriority: params.get("fetchpriority"), crossorigin: params.get("crossorigin") };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.SpecialAssetHandlingPlugin = SpecialAssetHandlingPlugin;
|
/package/build/{wordpress-scripts-wrapper → plugins}/AdditionalDependencyInjectorPlugin.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|