@plaudit/webpack-extensions 3.16.0 → 3.18.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/CHANGELOG.md +88 -1
- package/README.md +22 -2
- package/USER-GUIDE.md +21 -16
- package/dist/plugins/AbstractBiPhasicGroupAndEntryPlugin.d.ts +1 -1
- package/dist/plugins/AbstractBiPhasicGroupPlugin.d.ts +3 -3
- package/dist/plugins/EnhancedBlockJSONPlugin.d.ts +1 -0
- package/dist/plugins/EnhancedBlockJSONPlugin.js +36 -25
- package/dist/plugins/MiniCSSExtractPluginErrorCleaner.d.ts +2 -3
- package/dist/plugins/PackageConfigSanityChecker.d.ts +2 -3
- package/dist/plugins/PlainEntrypointsConfigFileGeneratorPlugin.js +22 -9
- package/dist/plugins/VariablesJSMonitorPlugin.d.ts +2 -3
- package/dist/plugins/WPMLConfigBuilder.d.ts +2 -3
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.d.ts +3 -6
- package/dist/plugins/dependency-extraction-webpack-plugin-config-builder.js +8 -21
- package/dist/shared.d.ts +24 -24
- package/dist/shared.js +41 -54
- package/dist/utils/common-config-helpers.d.ts +2 -2
- package/dist/utils/common-config-helpers.js +21 -13
- package/dist/utils/css-writer.js +3 -3
- package/dist/utils/entrypoint-resolution-logic.d.ts +5 -2
- package/dist/utils/location-encoding-filename-parser.d.ts +0 -1
- package/dist/utils/location-encoding-filename-parser.js +4 -3
- package/dist/utils/path-query-and-related-helpers.d.ts +0 -1
- package/dist/utils/path-query-and-related-helpers.js +0 -4
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.d.ts +72 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/index.js +522 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.d.ts +56 -0
- package/dist/wordpress-ports/dependency-extraction-webpack-plugin/util.js +150 -0
- package/dist/wordpress-scripts-wrapper.js +151 -89
- package/package.json +32 -8
- package/dist/plugins/BrowserSyncPlugin.d.ts +0 -25
- package/dist/plugins/BrowserSyncPlugin.js +0 -212
|
@@ -1,212 +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.BrowserSyncPlugin = void 0;
|
|
7
|
-
const node_child_process_1 = __importDefault(require("node:child_process"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const shared_1 = require("../shared");
|
|
11
|
-
const browser_sync_1 = __importDefault(require("browser-sync"));
|
|
12
|
-
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
13
|
-
class BrowserSyncPlugin {
|
|
14
|
-
static isBrowserSyncRunning = false;
|
|
15
|
-
static browserSyncPluginOptions;
|
|
16
|
-
pluginOptions;
|
|
17
|
-
browserSyncInstance;
|
|
18
|
-
isWebpackWatching = false;
|
|
19
|
-
mostRecentChunkHashes = {};
|
|
20
|
-
shouldNotify = false;
|
|
21
|
-
constructor(pluginOptions) {
|
|
22
|
-
this.pluginOptions = { reload: true, name: "plaudit-bs-plugin", injectCss: true, ...pluginOptions };
|
|
23
|
-
this.browserSyncInstance = browser_sync_1.default.has(this.pluginOptions.name) ? browser_sync_1.default.get(this.pluginOptions.name) : browser_sync_1.default.create(this.pluginOptions.name);
|
|
24
|
-
}
|
|
25
|
-
static getBrowserSyncPluginOptions() {
|
|
26
|
-
return BrowserSyncPlugin.browserSyncPluginOptions ?? (BrowserSyncPlugin.browserSyncPluginOptions = new Promise(async (resolve) => {
|
|
27
|
-
const envFilePath = BrowserSyncPlugin.findEnvFile();
|
|
28
|
-
const envFile = envFilePath ? await (0, shared_1.loadEnvFile)(envFilePath) : {};
|
|
29
|
-
const prefixes = BrowserSyncPlugin.getSiteUrls();
|
|
30
|
-
const targetPort = envFile["WEB_PORT_SSL"]?.match(/^\d+$/) ? envFile["WEB_PORT_SSL"] : "8443";
|
|
31
|
-
const targetHost = targetPort === "443" ? "localhost" : `localhost:${targetPort}`;
|
|
32
|
-
if (prefixes.length === 0 || prefixes.every(prefix => prefix.startsWith("localhost"))) {
|
|
33
|
-
resolve([{
|
|
34
|
-
host: 'localhost',
|
|
35
|
-
port: 3000,
|
|
36
|
-
https: true,
|
|
37
|
-
proxy: `https://${targetHost}`
|
|
38
|
-
}, {}]);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
resolve([{
|
|
42
|
-
port: 3000,
|
|
43
|
-
listen: "0.0.0.0",
|
|
44
|
-
https: true,
|
|
45
|
-
open: false,
|
|
46
|
-
callbacks: {
|
|
47
|
-
ready(err, bsi) {
|
|
48
|
-
// This ensures that the opened URL is actually a valid one
|
|
49
|
-
import("open").then(open => open.default(`https://${prefixes[0]?.replace(/:\d{2,4}/, "")}:${bsi.getOption("port") ?? 3000}`));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}, {
|
|
53
|
-
middlewareBuilder: (options) => {
|
|
54
|
-
const proxyPort = options.port?.toString() ?? "3000";
|
|
55
|
-
const router = prefixes.reduce((router, prefix) => {
|
|
56
|
-
router[`${prefix}:${proxyPort}`] = {
|
|
57
|
-
protocol: 'https:',
|
|
58
|
-
slashes: true,
|
|
59
|
-
auth: null,
|
|
60
|
-
host: prefix,
|
|
61
|
-
port: targetPort,
|
|
62
|
-
hostname: targetHost,
|
|
63
|
-
hash: null,
|
|
64
|
-
search: null,
|
|
65
|
-
query: null,
|
|
66
|
-
pathname: '/',
|
|
67
|
-
path: '/',
|
|
68
|
-
href: `https://${targetHost}/`
|
|
69
|
-
};
|
|
70
|
-
return router;
|
|
71
|
-
}, {});
|
|
72
|
-
const portInjectionPattern = new RegExp(`(${prefixes.join('|')})(?!:3000)`, "gi");
|
|
73
|
-
return (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
74
|
-
changeOrigin: true, router, secure: false, xfwd: true, selfHandleResponse: true, target: `https://${targetHost}`,
|
|
75
|
-
on: {
|
|
76
|
-
proxyRes: (0, http_proxy_middleware_1.responseInterceptor)(async (responseBuffer, proxyRes) => {
|
|
77
|
-
const contentType = proxyRes.headers["content-type"];
|
|
78
|
-
if (contentType && (contentType.startsWith("text/") || contentType === "application/x-javascript")) {
|
|
79
|
-
return responseBuffer.toString('utf-8').replaceAll(portInjectionPattern, "$1:3000");
|
|
80
|
-
}
|
|
81
|
-
return responseBuffer;
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}]);
|
|
87
|
-
}
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
static findEnvFile() {
|
|
91
|
-
for (let envFileHolderPath = process.cwd(); envFileHolderPath.length > 5; envFileHolderPath = node_path_1.default.dirname(envFileHolderPath)) {
|
|
92
|
-
if (node_fs_1.default.existsSync(node_path_1.default.join(envFileHolderPath, ".env"))) {
|
|
93
|
-
return node_path_1.default.join(envFileHolderPath, ".env");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
apply(compiler) {
|
|
99
|
-
if (!process.argv.includes('--browser-sync') && process.env['BROWSER_SYNC'] !== 'true') {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
let devTarget = process.env['DEV_TARGET'] ?? process.argv.find(a => a.startsWith("--dev-target="))?.substring(13);
|
|
103
|
-
if (devTarget === undefined) {
|
|
104
|
-
const flagIndex = process.argv.findIndex(a => a === "--dev-target");
|
|
105
|
-
if (flagIndex > -1) {
|
|
106
|
-
devTarget = process.argv[flagIndex + 1];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (devTarget !== undefined && devTarget !== node_path_1.default.basename(process.cwd()) && !(devTarget === "theme" && node_fs_1.default.existsSync(node_path_1.default.join(process.cwd(), "style.css")))) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
compiler.hooks.watchRun.tap(BrowserSyncPlugin.name, () => {
|
|
113
|
-
this.isWebpackWatching = true;
|
|
114
|
-
});
|
|
115
|
-
compiler.hooks.compilation.tap(BrowserSyncPlugin.name, () => {
|
|
116
|
-
if (BrowserSyncPlugin.isBrowserSyncRunning && this.shouldNotify) {
|
|
117
|
-
this.browserSyncInstance.notify('Rebuilding...');
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
compiler.hooks.done.tapPromise(BrowserSyncPlugin.name, async (stats) => {
|
|
121
|
-
if (!this.isWebpackWatching) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (!BrowserSyncPlugin.isBrowserSyncRunning) {
|
|
125
|
-
const [browserSyncOptions, pluginOptions] = await BrowserSyncPlugin.getBrowserSyncPluginOptions();
|
|
126
|
-
const actualPluginOptions = { ...this.pluginOptions, ...pluginOptions };
|
|
127
|
-
const middleware = actualPluginOptions.middlewareBuilder?.(browserSyncOptions);
|
|
128
|
-
this.browserSyncInstance.init(middleware
|
|
129
|
-
? { ...browserSyncOptions, server: { middleware: Array.isArray(middleware) ? middleware : [middleware] } }
|
|
130
|
-
: browserSyncOptions, this.pluginOptions.callback);
|
|
131
|
-
if (browserSyncOptions.notify) {
|
|
132
|
-
this.shouldNotify = true;
|
|
133
|
-
}
|
|
134
|
-
BrowserSyncPlugin.isBrowserSyncRunning = true;
|
|
135
|
-
}
|
|
136
|
-
if (this.pluginOptions.reload) {
|
|
137
|
-
if (this.pluginOptions.injectCss) {
|
|
138
|
-
const cssOnlyEmittedAssets = this.getCssOnlyEmittedAssetsNames(stats);
|
|
139
|
-
if (cssOnlyEmittedAssets !== undefined) {
|
|
140
|
-
this.browserSyncInstance.reload(cssOnlyEmittedAssets);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
this.browserSyncInstance.reload();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
getCssOnlyEmittedAssetsNames(stats) {
|
|
149
|
-
const compiledStats = stats.compilation.getStats().toJson({
|
|
150
|
-
hash: true,
|
|
151
|
-
publicPath: true,
|
|
152
|
-
assets: true,
|
|
153
|
-
chunks: true,
|
|
154
|
-
modules: false,
|
|
155
|
-
source: false,
|
|
156
|
-
errorDetails: false,
|
|
157
|
-
timings: false
|
|
158
|
-
});
|
|
159
|
-
const chunks = compiledStats.chunks
|
|
160
|
-
?.filter((chunk) => chunk.names !== undefined && chunk.files !== undefined);
|
|
161
|
-
if (!chunks) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
const mostRecentChunkHashes = this.mostRecentChunkHashes;
|
|
165
|
-
this.mostRecentChunkHashes = Object.fromEntries(chunks.flatMap(chunk => chunk.names.map(cn => [cn, chunk.hash])));
|
|
166
|
-
if (Object.keys(mostRecentChunkHashes).length !== chunks.length) {
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
const changedFilenames = chunks
|
|
170
|
-
.filter(chunk => chunk.names.some(name => mostRecentChunkHashes[name] !== chunk.hash))
|
|
171
|
-
.flatMap(chunk => [...chunk.files, ...(chunk.auxiliaryFiles ?? [])])
|
|
172
|
-
.filter(filename => !filename.endsWith(".asset.php"));
|
|
173
|
-
if (changedFilenames.length === 0) {
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
for (const filename of changedFilenames) {
|
|
177
|
-
if (!filename.includes(".css")) {
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return changedFilenames;
|
|
182
|
-
}
|
|
183
|
-
static getSiteUrls() {
|
|
184
|
-
//docker container inspect "$(docker compose ps --format=json | jq '. | select(. | contains({"Service": "wordpress"})) | .ID' -r)" | jq '.[].Config.Env'
|
|
185
|
-
const serviceId = node_child_process_1.default.spawnSync("docker", ["compose", "ps", "--format=json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "inherit"] })
|
|
186
|
-
.stdout.trim().split("\n").map(item => JSON.parse(item.trim())).find(item => item.Service === "wordpress")?.ID;
|
|
187
|
-
if (serviceId === undefined) {
|
|
188
|
-
return ["localhost"]; // This will only happen for Tomcat or misconfigured containers, both of which should use localhost
|
|
189
|
-
}
|
|
190
|
-
const inspectionResult = node_child_process_1.default.spawnSync("docker", ["container", "inspect", "--format=json", serviceId], { encoding: "utf-8", stdio: ["ignore", "pipe", "inherit"] })
|
|
191
|
-
.stdout.trim();
|
|
192
|
-
const containerEnv = Object.fromEntries(JSON.parse(inspectionResult)[0]?.Config.Env.map((envEntry) => {
|
|
193
|
-
const equalSignIndex = envEntry.indexOf('=');
|
|
194
|
-
return [envEntry.substring(0, equalSignIndex), envEntry.substring(equalSignIndex + 1)];
|
|
195
|
-
}));
|
|
196
|
-
if (containerEnv['WORDPRESS_MAPPED_DOMAINS'] !== '1') {
|
|
197
|
-
return ["localhost:8443"]; //This will only happen for legacy WordPress sites
|
|
198
|
-
}
|
|
199
|
-
let siteUrls;
|
|
200
|
-
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
|
|
201
|
-
if (!multisiteUrlsProcess.error && !multisiteUrlsProcess.status && !multisiteUrlsProcess.signal) {
|
|
202
|
-
siteUrls = multisiteUrlsProcess.stdout.split("\n").map(line => line.trim()).filter(line => line.length > 0);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
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()];
|
|
206
|
-
}
|
|
207
|
-
// 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.
|
|
208
|
-
// If the URL still has the "www.", then it is using David's mapping scheme and should be accessed via localhost
|
|
209
|
-
return siteUrls.map(siteUrl => siteUrl.includes("www.") ? "localhost" : siteUrl).map(siteUrl => siteUrl.replace(/^https?:\/\//i, ""));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
exports.BrowserSyncPlugin = BrowserSyncPlugin;
|