@plaudit/webpack-extensions 2.78.0 → 2.78.1
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 static withDistDevLoader;
|
|
19
|
+
private static 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
|
+
UnifiedLoaderGenerator.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 = UnifiedLoaderGenerator.withDistDevLoader();
|
|
73
101
|
}
|
|
74
102
|
if (groupedLoaderInfo.some(wc => wc.requiresBaseURI)) {
|
|
75
103
|
(0, shared_1.emitResolveBaseUriFunction)(writer);
|
|
@@ -82,5 +110,28 @@ class UnifiedLoaderGenerator extends AbstractBiPhasicGroupPlugin_1.AbstractBiPha
|
|
|
82
110
|
}
|
|
83
111
|
});
|
|
84
112
|
}
|
|
113
|
+
static withDistDevLoader() {
|
|
114
|
+
const devLoaderPath = expressions_1.Op.concat(expressions_1.Constants.__DIR__, '-dev/unified-loader.php');
|
|
115
|
+
return new php_writer_1.PHPWriter()
|
|
116
|
+
.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])))
|
|
117
|
+
.require(devLoaderPath, { once: true })
|
|
118
|
+
.append("return;")
|
|
119
|
+
.endIf();
|
|
120
|
+
}
|
|
121
|
+
static async ensureDistExists(outputPath) {
|
|
122
|
+
if (outputPath.endsWith("-dev")) {
|
|
123
|
+
outputPath = outputPath.substring(0, outputPath.length - 4);
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const contents = await (0, promises_1.readFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), 'utf-8');
|
|
127
|
+
if (!contents.includes("-dev/unified-loader.php")) {
|
|
128
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), UnifiedLoaderGenerator.withDistDevLoader().toString() + contents.substring(5), 'utf-8');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
133
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(outputPath, "unified-loader.php"), UnifiedLoaderGenerator.withDistDevLoader().toString(), 'utf-8');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
85
136
|
}
|
|
86
137
|
exports.UnifiedLoaderGenerator = UnifiedLoaderGenerator;
|