@plaudit/webpack-extensions 2.5.0 → 2.5.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
2
|
export default class BlockJSONStyleRemappingPlugin implements WebpackPluginInstance {
|
|
3
3
|
private readonly standaloneBlocks;
|
|
4
4
|
constructor(standaloneBlocks: boolean);
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const
|
|
8
|
+
const webpack_1 = require("webpack");
|
|
9
9
|
class BlockJSONStyleRemappingPlugin {
|
|
10
10
|
standaloneBlocks;
|
|
11
11
|
constructor(standaloneBlocks) {
|
|
@@ -62,7 +62,7 @@ class BlockJSONStyleRemappingPlugin {
|
|
|
62
62
|
for (const [name, asset] of Object.entries(compilationAssets)) {
|
|
63
63
|
if (name.endsWith("block.json") && asset.constructor.name === 'RawSource') {
|
|
64
64
|
const dirname = node_path_1.default.dirname(assetSourceFiles.get(name) ?? name);
|
|
65
|
-
const json = JSON.parse(asset.source());
|
|
65
|
+
const json = JSON.parse(asset.source().toString());
|
|
66
66
|
for (const mappableKey of mappableKeys) {
|
|
67
67
|
if (mappableKey in json) {
|
|
68
68
|
const unmappedValue = json[mappableKey];
|
|
@@ -122,7 +122,7 @@ class BlockJSONStyleRemappingPlugin {
|
|
|
122
122
|
delete json["render_template"];
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
compilation.updateAsset(name, new
|
|
125
|
+
compilation.updateAsset(name, new webpack_1.sources.RawSource(JSON.stringify(json, undefined, " ")));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
});
|
|
@@ -96,7 +96,7 @@ function addPotentiallyDuplicatedEntrypointName(entry, entrypoint, typeCounts) {
|
|
|
96
96
|
}
|
|
97
97
|
entry[potentialKey] = entrypoint[1];
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
function testForDuplicatedEntryPaths(config) {
|
|
100
100
|
const seenPaths = groupEntrypointsByAssetFile(Array.isArray(config.src) ? config.src : Object.values(config.src).map(bn => typeof bn === 'string' ? bn : bn.destination), bn => bn);
|
|
101
101
|
let projectPrefix = undefined;
|
|
102
102
|
let duplicatedPaths = "";
|
|
@@ -120,7 +120,8 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
120
120
|
console.error(`Encountered multiple paths that produce the same effective bundle name:${duplicatedPaths}`);
|
|
121
121
|
process.exit(1);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
}
|
|
124
|
+
function disableDefaultURLProcessing(webpackConfig) {
|
|
124
125
|
const cssLoader = require.resolve('css-loader');
|
|
125
126
|
if (cssLoader && webpackConfig.module?.rules) {
|
|
126
127
|
for (const rule of webpackConfig.module.rules) {
|
|
@@ -133,16 +134,11 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
+
}
|
|
138
|
+
function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
|
|
137
139
|
if (webpackConfig.module?.rules) {
|
|
138
140
|
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, (name) => {
|
|
139
|
-
|
|
140
|
-
return variables[name];
|
|
141
|
-
}
|
|
142
|
-
if (name === 'ENV') { // This is purely a backwards-compatibility issue.
|
|
143
|
-
return currentEntrypoint.endsWith('public.pcss') ? 'PUBLIC' : (currentEntrypoint.endsWith('block-editor.pcss') ? 'EDITOR' : '');
|
|
144
|
-
}
|
|
145
|
-
return undefined;
|
|
141
|
+
return variables[name] ?? (name === 'ENV' ? '' : undefined);
|
|
146
142
|
});
|
|
147
143
|
for (const rule of webpackConfig.module.rules) {
|
|
148
144
|
if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
@@ -164,10 +160,40 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
164
160
|
}
|
|
165
161
|
}
|
|
166
162
|
}
|
|
163
|
+
}
|
|
164
|
+
function parseEntrypointsJSON(dir) {
|
|
165
|
+
const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
|
|
166
|
+
if (Array.isArray(entrypointsJSON)) {
|
|
167
|
+
return mapToRealEntrypoints(entrypointsJSON, dir);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return Object.entries(entrypointsJSON).map(([name, config]) => {
|
|
171
|
+
if (typeof config === 'string') {
|
|
172
|
+
return [name, joinPossiblyAbsolutePaths(dir, config)];
|
|
173
|
+
}
|
|
174
|
+
else if (Array.isArray(config)) {
|
|
175
|
+
return [name, config.map(c => joinPossiblyAbsolutePaths(dir, c))];
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if (typeof config.import === 'string') {
|
|
179
|
+
config.import = joinPossiblyAbsolutePaths(dir, config.import);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
|
|
183
|
+
}
|
|
184
|
+
return [name, config];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
190
|
+
testForDuplicatedEntryPaths(config);
|
|
191
|
+
const { standaloneBlocks = false, variables = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p)).map(p => require(p))[0] ?? {}, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
|
|
192
|
+
disableDefaultURLProcessing(webpackConfig);
|
|
193
|
+
injectPostcssConfigOverrides(webpackConfig, variables, verbose);
|
|
167
194
|
let first = true;
|
|
168
195
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
169
196
|
return sources.map(([src, dest]) => {
|
|
170
|
-
currentEntrypoint = src;
|
|
171
197
|
const srcRoots = typeof dest !== 'string' && dest.withLegacyBlocksIn
|
|
172
198
|
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
|
|
173
199
|
: src.split(',');
|
|
@@ -184,7 +210,10 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
184
210
|
syntactic: true,
|
|
185
211
|
}
|
|
186
212
|
}
|
|
187
|
-
}), new webpack_remove_empty_scripts_1.default({
|
|
213
|
+
}), new webpack_remove_empty_scripts_1.default({
|
|
214
|
+
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
215
|
+
extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
|
|
216
|
+
}));
|
|
188
217
|
if (copyFiles) {
|
|
189
218
|
plugins.push(new BlockJSONStyleRemappingPlugin_1.default(standaloneBlocks));
|
|
190
219
|
}
|
|
@@ -224,29 +253,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
224
253
|
}
|
|
225
254
|
catch (e) {
|
|
226
255
|
try {
|
|
227
|
-
|
|
228
|
-
if (Array.isArray(entrypointsJSON)) {
|
|
229
|
-
res.push(...mapToRealEntrypoints(entrypointsJSON, dir));
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
for (const [name, config] of Object.entries(entrypointsJSON)) {
|
|
233
|
-
if (typeof config === 'string') {
|
|
234
|
-
res.push([name, joinPossiblyAbsolutePaths(dir, config)]);
|
|
235
|
-
}
|
|
236
|
-
else if (Array.isArray(config)) {
|
|
237
|
-
res.push([name, config.map(c => joinPossiblyAbsolutePaths(dir, c))]);
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
if (typeof config.import === 'string') {
|
|
241
|
-
config.import = joinPossiblyAbsolutePaths(dir, config.import);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
|
|
245
|
-
}
|
|
246
|
-
res.push([name, config]);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
256
|
+
res.push(...parseEntrypointsJSON(dir));
|
|
250
257
|
}
|
|
251
258
|
catch (e) {
|
|
252
259
|
// This just means that the directory doesn't contain any declared entrypoints.
|