@plaudit/webpack-extensions 2.78.0 → 2.79.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.
|
@@ -15,5 +15,7 @@ export declare class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin
|
|
|
15
15
|
constructor(config: VerifiedPlauditWordpressWebpackConfig);
|
|
16
16
|
protected attachStandardPhase(compilation: Compilation): void;
|
|
17
17
|
protected attachUniquePhase(compilation: Compilation): void;
|
|
18
|
+
private withDistDevLoader;
|
|
19
|
+
private ensureDistExists;
|
|
18
20
|
}
|
|
19
21
|
export {};
|
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.UnifiedLoaderGenerator = void 0;
|
|
7
|
-
const node_path_1 =
|
|
37
|
+
const node_path_1 = __importStar(require("node:path"));
|
|
8
38
|
const php_writer_1 = require("@plaudit/php-writer");
|
|
9
39
|
const expressions_1 = require("@plaudit/php-writer/expressions");
|
|
10
40
|
const AbstractBiPhasicGroupPlugin_1 = require("./AbstractBiPhasicGroupPlugin");
|
|
11
41
|
const shared_1 = require("../shared");
|
|
12
42
|
const pseduo_semaphore_1 = require("../utils/pseduo-semaphore");
|
|
13
43
|
const webpack_1 = require("webpack");
|
|
44
|
+
const promises_1 = require("node:fs/promises");
|
|
14
45
|
class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPhasicGroupPlugin {
|
|
15
46
|
static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Unified");
|
|
16
47
|
constructor(config) {
|
|
@@ -59,17 +90,14 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
59
90
|
}
|
|
60
91
|
if (this.config.useUnifiedLoader) {
|
|
61
92
|
compilation.hooks.afterProcessAssets.tap(this.constructor.name, () => {
|
|
62
|
-
|
|
93
|
+
let writer;
|
|
63
94
|
if (compilation.outputOptions.path?.endsWith("-dev")) {
|
|
64
95
|
compilation['.gitignore' in compilation.assets ? 'updateAsset' : 'emitAsset']('.gitignore', new webpack_1.sources.RawSource('**'), { size: 2 });
|
|
96
|
+
this.ensureDistExists(compilation.outputOptions.path);
|
|
97
|
+
writer = new php_writer_1.PHPWriter();
|
|
65
98
|
}
|
|
66
99
|
else {
|
|
67
|
-
|
|
68
|
-
writer
|
|
69
|
-
.if(expressions_1.Op.binary(expressions_1.Op.binary(expressions_1.Expr.call('wp_get_environment_type', []), ' === ', 'development'), ' && ', expressions_1.Expr.call('file_exists', [devLoaderPath])))
|
|
70
|
-
.require(devLoaderPath, { once: true })
|
|
71
|
-
.append("return;")
|
|
72
|
-
.endIf();
|
|
100
|
+
writer = this.withDistDevLoader();
|
|
73
101
|
}
|
|
74
102
|
if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
|
|
75
103
|
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
@@ -82,5 +110,31 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
82
110
|
}
|
|
83
111
|
});
|
|
84
112
|
}
|
|
113
|
+
withDistDevLoader() {
|
|
114
|
+
if (this.config.omitDistDev) {
|
|
115
|
+
return new php_writer_1.PHPWriter();
|
|
116
|
+
}
|
|
117
|
+
const devLoaderPath = expressions_1.Op.concat(expressions_1.Constants.__DIR__, '-dev/unified-loader.php');
|
|
118
|
+
return new php_writer_1.PHPWriter()
|
|
119
|
+
.if(expressions_1.Op.binary(expressions_1.Op.binary(expressions_1.Expr.call('wp_get_environment_type', []), ' === ', 'development'), ' && ', expressions_1.Expr.call('file_exists', [devLoaderPath])))
|
|
120
|
+
.require(devLoaderPath, { once: true })
|
|
121
|
+
.append("return;")
|
|
122
|
+
.endIf();
|
|
123
|
+
}
|
|
124
|
+
async ensureDistExists(outputPath) {
|
|
125
|
+
if (outputPath.endsWith("-dev")) {
|
|
126
|
+
outputPath = outputPath.substring(0, outputPath.length - 4);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const contents = await (0, promises_1.readFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), 'utf-8');
|
|
130
|
+
if (!contents.includes("-dev/unified-loader.php")) {
|
|
131
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString() + contents.substring(5), 'utf-8');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
136
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), this.withDistDevLoader().toString(), 'utf-8');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
85
139
|
}
|
|
86
140
|
exports.UnifiedLoaderGenerator = UnifiedLoaderGenerator;
|
package/build/shared.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export type PlauditWordpressWebpackConfig = {
|
|
|
108
108
|
srcPrefixes?: string[];
|
|
109
109
|
useUnifiedLoader?: boolean;
|
|
110
110
|
includePostInitFallback?: boolean;
|
|
111
|
+
omitDistDev?: boolean;
|
|
111
112
|
};
|
|
112
113
|
export type FileSegmentBlockEntrypointInfo = {
|
|
113
114
|
blockJsonOrigin: string;
|
|
@@ -105,7 +105,7 @@ function injectPostcssConfigOverrides(rules, config, variables, postcssFunctions
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the
|
|
108
|
+
if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the JavaScript and TypeScript rule
|
|
109
109
|
rule.test = /\.m?[jt]sx?$/; // This hacks in support for mjs and mts files
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -157,9 +157,9 @@ function injectSupportForInliningSVGsAsStrings(rules) {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
function buildVerifiedConfig(config) {
|
|
160
|
-
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false } = config;
|
|
160
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, plainEntrypointsVersion = 1, srcDir = "", useUnifiedLoader = false, includePostInitFallback = false, omitDistDev = false } = config;
|
|
161
161
|
let outputDir = config.outputDir ?? "";
|
|
162
|
-
if (outputDir && useUnifiedLoader && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
162
|
+
if (outputDir && useUnifiedLoader && !omitDistDev && (process.env['SERVER_MODE'] ?? 'development') === 'development') {
|
|
163
163
|
outputDir += "-dev";
|
|
164
164
|
}
|
|
165
165
|
let srcPrefixes;
|
|
@@ -209,7 +209,7 @@ function buildVerifiedConfig(config) {
|
|
|
209
209
|
}
|
|
210
210
|
const cfg = {
|
|
211
211
|
currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
|
|
212
|
-
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix, useUnifiedLoader, includePostInitFallback
|
|
212
|
+
useWebpackResourceFiltering, outputDir, extensionsVersion, plainEntrypointsVersion, srcDir, srcPrefixes, targetHandlePrefix, useUnifiedLoader, includePostInitFallback, omitDistDev
|
|
213
213
|
};
|
|
214
214
|
// Destination -> source map
|
|
215
215
|
const allocatedDestinations = {};
|