@plaudit/webpack-extensions 2.58.3 → 2.59.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/plugins/BlockJSONManagingPlugin.js +1 -0
- package/build/plugins/BrowserSyncPlugin.d.ts +1 -0
- package/build/plugins/BrowserSyncPlugin.js +31 -5
- package/build/plugins/ExtensionsConfigFileGeneratorPlugin.js +3 -2
- package/build/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +1 -1
- package/build/plugins/SpecialAssetHandlingPlugin.js +1 -1
- package/build/plugins/UnifiedLoaderGenerator.d.ts +1 -0
- package/build/plugins/UnifiedLoaderGenerator.js +5 -4
- package/package.json +1 -1
|
@@ -323,6 +323,7 @@ class BlockJSONManagingPlugin {
|
|
|
323
323
|
compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
|
|
324
324
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, {
|
|
325
325
|
group: `block-json-${this.blocksDest}`,
|
|
326
|
+
requiresBaseURI: false,
|
|
326
327
|
action: writer => {
|
|
327
328
|
writer
|
|
328
329
|
.use("Plaudit\\Common\\ACF\\BlockManager")
|
|
@@ -26,10 +26,8 @@ class BrowserSyncPlugin {
|
|
|
26
26
|
static getBrowserSyncPluginOptions() {
|
|
27
27
|
return BrowserSyncPlugin.browserSyncPluginOptions ?? (BrowserSyncPlugin.browserSyncPluginOptions = new Promise(resolve => {
|
|
28
28
|
const envFile = BrowserSyncPlugin.loadEnvFile();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
stdio: ["ignore", "pipe", "inherit"]
|
|
32
|
-
}).stdout.split(/\r?\n/g).map(url => url.trim()).filter(url => url.length > 0).map(url => url.substring(url.indexOf("://") + 3));
|
|
29
|
+
//docker container inspect "$(docker compose ps --format=json | jq '. | select(. | contains({"Service": "wordpress"})) | .ID' -r)" | jq '.[].Config.Env'
|
|
30
|
+
const prefixes = BrowserSyncPlugin.getSiteUrls();
|
|
33
31
|
const targetPort = envFile.match(/WEB_PORT_SSL=(\d+)/i)?.[1] ?? "8443";
|
|
34
32
|
const targetHost = targetPort === "443" ? "localhost" : `localhost:${targetPort}`;
|
|
35
33
|
if (prefixes.length === 0 || prefixes.every(prefix => prefix.startsWith("localhost"))) {
|
|
@@ -49,7 +47,7 @@ class BrowserSyncPlugin {
|
|
|
49
47
|
callbacks: {
|
|
50
48
|
ready(err, bsi) {
|
|
51
49
|
// This ensures that the opened URL is actually a valid one
|
|
52
|
-
(0, open_1.default)(`https://${prefixes[0]}:${bsi.getOption("port") ?? 3000}`);
|
|
50
|
+
(0, open_1.default)(`https://${prefixes[0]?.replace(/:\d{2,4}/, "")}:${bsi.getOption("port") ?? 3000}`);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
}, {
|
|
@@ -173,5 +171,33 @@ class BrowserSyncPlugin {
|
|
|
173
171
|
}
|
|
174
172
|
return changedFilenames;
|
|
175
173
|
}
|
|
174
|
+
static getSiteUrls() {
|
|
175
|
+
//docker container inspect "$(docker compose ps --format=json | jq '. | select(. | contains({"Service": "wordpress"})) | .ID' -r)" | jq '.[].Config.Env'
|
|
176
|
+
const serviceId = node_child_process_1.default.spawnSync("docker", ["compose", "ps", "--format=json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "inherit"] })
|
|
177
|
+
.stdout.trim().split("\n").map(item => JSON.parse(item.trim())).find(item => item.Service === "wordpress")?.ID;
|
|
178
|
+
if (serviceId === undefined) {
|
|
179
|
+
return ["localhost"]; // This will only happen for Tomcat or misconfigured containers, both of which should use localhost
|
|
180
|
+
}
|
|
181
|
+
const inspectionResult = node_child_process_1.default.spawnSync("docker", ["container", "inspect", "--format=json", serviceId], { encoding: "utf-8", stdio: ["ignore", "pipe", "inherit"] })
|
|
182
|
+
.stdout.trim();
|
|
183
|
+
const containerEnv = Object.fromEntries(JSON.parse(inspectionResult)[0]?.Config.Env.map((envEntry) => {
|
|
184
|
+
const equalSignIndex = envEntry.indexOf('=');
|
|
185
|
+
return [envEntry.substring(0, equalSignIndex), envEntry.substring(equalSignIndex + 1)];
|
|
186
|
+
}));
|
|
187
|
+
if (containerEnv['WORDPRESS_MAPPED_DOMAINS'] !== '1') {
|
|
188
|
+
return ["localhost:8443"]; //This will only happen for legacy WordPress sites
|
|
189
|
+
}
|
|
190
|
+
let siteUrls;
|
|
191
|
+
const multisiteUrlsProcess = node_child_process_1.default.spawnSync("docker", ["compose", "exec", "--user=www-data", "wordpress", "wp", "site", "list", "--field=url", "--quiet"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }); // We're forced to mute stderr here because it is otherwise almost guaranteed to print
|
|
192
|
+
if (!multisiteUrlsProcess.error && !multisiteUrlsProcess.status && !multisiteUrlsProcess.signal) {
|
|
193
|
+
siteUrls = multisiteUrlsProcess.stdout.split("\n").map(line => line.trim()).filter(line => line.length > 0);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
siteUrls = [node_child_process_1.default.spawnSync("docker", ["compose", "exec", "--user=www-data", "wordpress", "wp", "option", "get", "siteurl"], { encoding: "utf-8", stdio: ["ignore", "pipe", "inherit"] }).stdout.trim()];
|
|
197
|
+
}
|
|
198
|
+
// Because mapped domain sites that are using my mapping scheme hyphenate instances of "www.", this is an effective test for whether it is in use.
|
|
199
|
+
// If the URL still has the "www.", then it is using David's mapping scheme and should be accessed via localhost
|
|
200
|
+
return siteUrls.map(siteUrl => siteUrl.includes("www.") ? "localhost" : siteUrl).map(siteUrl => siteUrl.replace(/^https?:\/\//i, ""));
|
|
201
|
+
}
|
|
176
202
|
}
|
|
177
203
|
exports.BrowserSyncPlugin = BrowserSyncPlugin;
|
|
@@ -96,7 +96,8 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
96
96
|
compilation.deleteAsset("assets.json");
|
|
97
97
|
ExtensionsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myCacheData);
|
|
98
98
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myCacheData.setupFiles.length > 0 || myCacheData.assets.length > 0 ? {
|
|
99
|
-
group:
|
|
99
|
+
group: `extensions-config-v2-${this.extensionsDest}`,
|
|
100
|
+
requiresBaseURI: true,
|
|
100
101
|
action: writer => {
|
|
101
102
|
let finalExtensionsDest = this.extensionsDest.endsWith("/") ? this.extensionsDest : this.extensionsDest + "/";
|
|
102
103
|
if (!finalExtensionsDest.startsWith("/")) {
|
|
@@ -131,7 +132,7 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
131
132
|
compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
|
|
132
133
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.reset(this.id);
|
|
133
134
|
compilation.hooks.processAssets.tap({ name: `${this.constructor.name}_UnifiedLoaderGeneratorIntegration`, stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED }, () => {
|
|
134
|
-
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group:
|
|
135
|
+
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, { group: `extensions-config-v1-${this.extensionsDest}`, requiresBaseURI: false, action: writer => {
|
|
135
136
|
writer
|
|
136
137
|
.use("Plaudit\\Base\\API\\ThemeUtils")
|
|
137
138
|
.call("ThemeUtils::installExtensionSupport", [new php_writer_1.Expr(`__DIR__.${php_writer_1.Expr.convertJsonToPHP(this.extensionsDest)}`)]);
|
|
@@ -104,7 +104,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin {
|
|
|
104
104
|
compilation.deleteAsset("assets.json");
|
|
105
105
|
PlainEntrypointsConfigFileGeneratorPlugin.semaphore.resolve(this.id, myAssetHandles);
|
|
106
106
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, myAssetHandles.length
|
|
107
|
-
? { group: 'plain-entrypoints-v2', action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';") }
|
|
107
|
+
? { group: 'plain-entrypoints-v2', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/plain-entrypoints-loader.php';") }
|
|
108
108
|
: undefined);
|
|
109
109
|
}
|
|
110
110
|
catch (e) {
|
|
@@ -65,7 +65,7 @@ class SpecialAssetHandlingPlugin {
|
|
|
65
65
|
}
|
|
66
66
|
SpecialAssetHandlingPlugin.semaphore.resolve(this.id, specialAssetData);
|
|
67
67
|
UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore.resolve(this.id, Object.keys(specialAssetData).length > 0
|
|
68
|
-
? { group: 'special-assets', action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
|
|
68
|
+
? { group: 'special-assets', requiresBaseURI: true, action: writer => writer.append("require_once __DIR__.'/special-assets.php';") }
|
|
69
69
|
: undefined);
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
@@ -30,14 +30,15 @@ class UnifiedLoaderGenerator {
|
|
|
30
30
|
const ap = a.priority ?? 0, bp = b.priority ?? 0;
|
|
31
31
|
return ap === bp ? a.group.localeCompare(b.group) : bp - ap;
|
|
32
32
|
})
|
|
33
|
-
.filter(a => !alreadyAllocatedGroups.has(a.group) && alreadyAllocatedGroups.add(a.group))
|
|
34
|
-
.map(a => a.action);
|
|
33
|
+
.filter(a => !alreadyAllocatedGroups.has(a.group) && alreadyAllocatedGroups.add(a.group));
|
|
35
34
|
if (writerCallbacks.length > 0) {
|
|
36
35
|
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
37
36
|
const writer = new php_writer_1.PHPWriter();
|
|
38
|
-
|
|
37
|
+
if (writerCallbacks.some(wc => wc.requiresBaseURI)) {
|
|
38
|
+
PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin.emitResolveBaseUriFunction(writer);
|
|
39
|
+
}
|
|
39
40
|
for (const writerCallback of writerCallbacks) {
|
|
40
|
-
writerCallback(writer);
|
|
41
|
+
writerCallback.action(writer);
|
|
41
42
|
}
|
|
42
43
|
writer.emitAsset(compilation, "unified-loader.php");
|
|
43
44
|
});
|