@plaudit/webpack-extensions 2.18.1 → 2.19.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.
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
6
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const webpack_1 = require("webpack");
|
|
@@ -37,8 +38,17 @@ class BlockJSONManagingPlugin {
|
|
|
37
38
|
const singleFileChunkToOutputName = new Map(stats.assets
|
|
38
39
|
.filter((asset) => asset.chunks?.length === 1)
|
|
39
40
|
.filter(asset => !asset.name.endsWith('.asset.php'))
|
|
40
|
-
.map(asset =>
|
|
41
|
-
|
|
41
|
+
.map(asset => {
|
|
42
|
+
let assetHash = asset.info.contenthash ?? asset.info.fullhash;
|
|
43
|
+
if (Array.isArray(assetHash)) {
|
|
44
|
+
assetHash = BlockJSONManagingPlugin.hashThingForAsset(assetHash.join('~'));
|
|
45
|
+
}
|
|
46
|
+
return [asset.chunks[0], [asset.name, assetHash ?? (() => {
|
|
47
|
+
const realAsset = compilationAssets[asset.name];
|
|
48
|
+
return BlockJSONManagingPlugin.hashThingForAsset(realAsset ? realAsset.source().toString() : Date.now().toString());
|
|
49
|
+
})]];
|
|
50
|
+
}));
|
|
51
|
+
const singleFileInputToOutputNameAndHash = new Map(stats.modules
|
|
42
52
|
.map(module => {
|
|
43
53
|
if (module.nameForCondition !== undefined && module.chunks?.length === 1) {
|
|
44
54
|
const output = singleFileChunkToOutputName.get(module.chunks[0]);
|
|
@@ -50,19 +60,20 @@ class BlockJSONManagingPlugin {
|
|
|
50
60
|
const remapValue = (value, name, dirname) => {
|
|
51
61
|
if (value.startsWith("file:")) {
|
|
52
62
|
const styleInputPath = node_path_1.default.normalize(node_path_1.default.join(compiler.context, dirname, value.substring(5)));
|
|
53
|
-
const styleOutputPath =
|
|
63
|
+
const styleOutputPath = singleFileInputToOutputNameAndHash.get(styleInputPath);
|
|
54
64
|
if (styleOutputPath !== undefined) {
|
|
55
65
|
const prefix = value.startsWith("./", 5) ? "./" : "";
|
|
56
|
-
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name), styleOutputPath);
|
|
57
|
-
return `file:${prefix}${relativePath}
|
|
66
|
+
const relativePath = node_path_1.default.relative(node_path_1.default.dirname(name), styleOutputPath[0]);
|
|
67
|
+
return [`file:${prefix}${relativePath}`, typeof styleOutputPath[1] === 'string' ? styleOutputPath[1] : styleOutputPath[1]()];
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
|
-
return value;
|
|
70
|
+
return [value, ""];
|
|
61
71
|
};
|
|
62
72
|
const blockDirConfigData = {};
|
|
63
73
|
const mappableKeys = ["editorStyle", "style", "viewStyle", "viewScript", "script", "editorScript"];
|
|
64
74
|
for (const [name, asset] of Object.entries(compilationAssets)) {
|
|
65
75
|
if (name.endsWith("block.json")) {
|
|
76
|
+
let compositeHash = "";
|
|
66
77
|
blockDirConfigData[name] = true;
|
|
67
78
|
if (asset.constructor.name === 'RawSource') {
|
|
68
79
|
const dirname = node_path_1.default.dirname(assetSourceFiles.get(name) ?? name);
|
|
@@ -71,13 +82,23 @@ class BlockJSONManagingPlugin {
|
|
|
71
82
|
if (mappableKey in json) {
|
|
72
83
|
const unmappedValue = json[mappableKey];
|
|
73
84
|
if (Array.isArray(unmappedValue)) {
|
|
74
|
-
|
|
85
|
+
const remappedValue = unmappedValue.map(value => remapValue(value, name, dirname));
|
|
86
|
+
json[mappableKey] = remappedValue.map(([resource]) => resource);
|
|
87
|
+
compositeHash += "~" + remappedValue.map(([_, hash]) => hash).join("~");
|
|
75
88
|
}
|
|
76
89
|
else if (typeof unmappedValue === 'string') {
|
|
77
|
-
|
|
90
|
+
const remappedValue = remapValue(unmappedValue, name, dirname);
|
|
91
|
+
json[mappableKey] = remappedValue[0];
|
|
92
|
+
compositeHash += "~" + remappedValue[1];
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
}
|
|
96
|
+
if (json["version"]) {
|
|
97
|
+
json["version"] = `${json["version"]}-${BlockJSONManagingPlugin.hashThingForAsset(compositeHash)}`;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
json["version"] = BlockJSONManagingPlugin.hashThingForAsset(compositeHash);
|
|
101
|
+
}
|
|
81
102
|
if (!this.standaloneBlocks && json["plaudit"] !== "simple") {
|
|
82
103
|
const sourceDir = node_path_1.default.join(compiler.context, dirname);
|
|
83
104
|
const outputDir = node_path_1.default.join(compiler.outputPath, node_path_1.default.dirname(name));
|
|
@@ -164,5 +185,8 @@ class BlockJSONManagingPlugin {
|
|
|
164
185
|
route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
|
|
165
186
|
return route.join(node_path_1.default.sep);
|
|
166
187
|
}
|
|
188
|
+
static hashThingForAsset(thing) {
|
|
189
|
+
return node_crypto_1.default.createHash('md5').update(thing).digest("hex").substring(0, 20).toLowerCase();
|
|
190
|
+
}
|
|
167
191
|
}
|
|
168
192
|
exports.default = BlockJSONManagingPlugin;
|