@plaudit/webpack-extensions 2.1.4 → 2.2.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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Compiler, WebpackPluginInstance } from "webpack";
|
|
2
2
|
export default class BlockJSONStyleRemappingPlugin implements WebpackPluginInstance {
|
|
3
3
|
apply(compiler: Compiler): void;
|
|
4
|
+
findCommonAncestor(...paths: string[]): string[];
|
|
5
|
+
findRelativeRouteBetween(path1: string, path2: string): string;
|
|
4
6
|
}
|
|
@@ -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_fs_1 = __importDefault(require("node:fs"));
|
|
6
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
7
8
|
const webpack_sources_1 = require("webpack-sources");
|
|
8
9
|
class BlockJSONStyleRemappingPlugin {
|
|
@@ -69,11 +70,76 @@ class BlockJSONStyleRemappingPlugin {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
}
|
|
73
|
+
if (json["plaudit"] !== "simple") {
|
|
74
|
+
const sourceDir = node_path_1.default.join(compiler.context, dirname);
|
|
75
|
+
const outputDir = node_path_1.default.join(compiler.outputPath, node_path_1.default.dirname(name));
|
|
76
|
+
const stripFilePrefix = (file) => file.startsWith("file:./") ? file.substring(7) : file;
|
|
77
|
+
let setupFiles = (json["plaudit"]?.["setup"]
|
|
78
|
+
? (typeof json["plaudit"]["setup"] === 'string' ? [json["plaudit"]["setup"]] : json["plaudit"]["setup"])
|
|
79
|
+
: ["setup.php"])
|
|
80
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, stripFilePrefix(p))))
|
|
81
|
+
.filter(p => node_fs_1.default.existsSync(p))
|
|
82
|
+
.map(p => `file:./${this.findRelativeRouteBetween(outputDir, p)}`);
|
|
83
|
+
if (setupFiles.length === 0) {
|
|
84
|
+
if (json["plaudit"]?.["setup"] !== undefined) {
|
|
85
|
+
delete json["plaudit"]["setup"];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (typeof json["plaudit"] !== 'object') {
|
|
90
|
+
json["plaudit"] = {};
|
|
91
|
+
}
|
|
92
|
+
json["plaudit"]["setup"] = setupFiles.length === 1 ? setupFiles[0] : setupFiles;
|
|
93
|
+
}
|
|
94
|
+
if (json["render"] && (json["acf"] || json["plaudit"])) {
|
|
95
|
+
json["render_template"] = json["render"];
|
|
96
|
+
delete json["render"];
|
|
97
|
+
}
|
|
98
|
+
if (json["acf"]) {
|
|
99
|
+
if (json["acf"]["renderTemplate"]) {
|
|
100
|
+
json["render_template"] = json["acf"]["renderTemplate"];
|
|
101
|
+
delete json["acf"]["renderTemplate"];
|
|
102
|
+
}
|
|
103
|
+
else if (json["acf"]["render_template"]) {
|
|
104
|
+
json["render_template"] = json["acf"]["render_template"];
|
|
105
|
+
delete json["acf"]["render_template"];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let renderTemplate = (json["render_template"]
|
|
109
|
+
? (typeof json["render_template"] === 'string' ? [json["render_template"]] : json["render_template"])
|
|
110
|
+
: ["template.php", "template.twig"])
|
|
111
|
+
.map(p => node_path_1.default.normalize(node_path_1.default.join(sourceDir, stripFilePrefix(p))))
|
|
112
|
+
.filter(p => node_fs_1.default.existsSync(p))
|
|
113
|
+
.map(p => `file:./${this.findRelativeRouteBetween(outputDir, p)}`);
|
|
114
|
+
if (renderTemplate.length !== 0) {
|
|
115
|
+
json["render_template"] = renderTemplate[0];
|
|
116
|
+
}
|
|
117
|
+
else if (json["render_template"] !== undefined) {
|
|
118
|
+
delete json["render_template"];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
72
121
|
compilation.updateAsset(name, new webpack_sources_1.RawSource(JSON.stringify(json, undefined, " ")));
|
|
73
122
|
}
|
|
74
123
|
}
|
|
75
124
|
});
|
|
76
125
|
});
|
|
77
126
|
}
|
|
127
|
+
findCommonAncestor(...paths) {
|
|
128
|
+
return paths.map(p => node_path_1.default.normalize(p).split(node_path_1.default.sep)).reduce((prior, current) => {
|
|
129
|
+
for (let i = 0, limit = Math.min(prior.length, current.length); i < limit; i++) {
|
|
130
|
+
if (prior[i] !== current[i]) {
|
|
131
|
+
return prior.slice(0, i);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return current.length < prior.length ? current : prior;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
findRelativeRouteBetween(path1, path2) {
|
|
138
|
+
const commonAncestor = this.findCommonAncestor(path1, path2);
|
|
139
|
+
const route = Array(path1.split(node_path_1.default.sep).length - commonAncestor.length).fill("..");
|
|
140
|
+
`..${node_path_1.default.sep}`.repeat(path1.split(node_path_1.default.sep).length - commonAncestor.length);
|
|
141
|
+
route.push(node_path_1.default.relative(commonAncestor.join(node_path_1.default.sep), path2));
|
|
142
|
+
return route.join(node_path_1.default.sep);
|
|
143
|
+
}
|
|
78
144
|
}
|
|
79
145
|
exports.default = BlockJSONStyleRemappingPlugin;
|