@plaudit/webpack-extensions 2.58.4 → 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.
|
@@ -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;
|