@plaudit/webpack-extensions 2.10.0 → 2.11.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.
- package/build/wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin.js +4 -4
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.d.ts +2 -1
- package/build/wordpress-scripts-wrapper/ExtensionsConfigFileGeneratorPlugin.js +64 -31
- package/build/wordpress-scripts-wrapper/static-configs.js +25 -25
- package/build/wordpress-scripts-wrapper.js +2 -2
- package/package.json +12 -12
|
@@ -18,12 +18,12 @@ class AdditionalDependencyInjectorPlugin {
|
|
|
18
18
|
}, compilationAssets => {
|
|
19
19
|
const assetSources = new Map();
|
|
20
20
|
for (const entrypoint of compilation.entrypoints.values()) {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
21
|
+
const req = entrypoint.origins.filter(origin => /\.m?tsx?$/.test(origin.request))[0]?.request;
|
|
22
|
+
if (req) {
|
|
23
23
|
for (const chunk of entrypoint.chunks) {
|
|
24
24
|
for (const file of chunk.files) {
|
|
25
25
|
if (file.endsWith('.asset.php')) {
|
|
26
|
-
assetSources.set(file,
|
|
26
|
+
assetSources.set(file, req);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -37,7 +37,7 @@ class AdditionalDependencyInjectorPlugin {
|
|
|
37
37
|
}
|
|
38
38
|
const additionalDependencies = [...this.entrypointAdditionalDependencies];
|
|
39
39
|
const firstLine = node_fs_1.default.readFileSync(assetSource, 'utf8').trim().split(/\r?\n/)[0];
|
|
40
|
-
if (firstLine
|
|
40
|
+
if (firstLine?.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
|
|
41
41
|
additionalDependencies.push(...firstLine.substring(26).trim().split(',').map(dep => dep.trim()));
|
|
42
42
|
}
|
|
43
43
|
if (additionalDependencies.length > 0) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Compiler, type WebpackPluginInstance } from "webpack";
|
|
2
2
|
export default class ExtensionsConfigFileGeneratorPlugin implements WebpackPluginInstance {
|
|
3
|
-
|
|
3
|
+
private readonly extensionsPath;
|
|
4
|
+
constructor(extensionsPath: string);
|
|
4
5
|
apply(compiler: Compiler): void;
|
|
5
6
|
}
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
3
8
|
const webpack_1 = require("webpack");
|
|
4
9
|
class ExtensionsConfigFileGeneratorPlugin {
|
|
5
|
-
|
|
10
|
+
extensionsPath;
|
|
11
|
+
constructor(extensionsPath) {
|
|
12
|
+
this.extensionsPath = extensionsPath;
|
|
13
|
+
}
|
|
6
14
|
apply(compiler) {
|
|
15
|
+
compiler.hooks.make.tapPromise('ExtensionsConfigFileGeneratorPlugin', async (compilation) => {
|
|
16
|
+
if (!compilation.contextDependencies.has(this.extensionsPath)) {
|
|
17
|
+
compilation.contextDependencies.add(this.extensionsPath);
|
|
18
|
+
}
|
|
19
|
+
const emissionPromises = [];
|
|
20
|
+
for (const setupFilePath of await promises_1.default.readdir(this.extensionsPath)) {
|
|
21
|
+
if (setupFilePath.endsWith("-setup.php")) {
|
|
22
|
+
const setupFileSourcePath = node_path_1.default.join(this.extensionsPath, setupFilePath);
|
|
23
|
+
compilation.fileDependencies.add(setupFileSourcePath);
|
|
24
|
+
emissionPromises.push(promises_1.default.readFile(setupFileSourcePath)
|
|
25
|
+
.then(contents => compilation.emitAsset(setupFilePath, new webpack_1.sources.RawSource(contents), { size: Buffer.byteLength(contents) })));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
await Promise.all(emissionPromises);
|
|
29
|
+
});
|
|
7
30
|
compiler.hooks.thisCompilation.tap("ExtensionsConfigFileGeneratorPlugin", compilation => {
|
|
8
31
|
compilation.hooks.processAssets.tap({
|
|
9
32
|
name: "ExtensionsConfigFileGeneratorPlugin_ProcessAssets",
|
|
@@ -27,46 +50,56 @@ class ExtensionsConfigFileGeneratorPlugin {
|
|
|
27
50
|
}
|
|
28
51
|
const mapping = {};
|
|
29
52
|
for (const asset of stats.assets) {
|
|
30
|
-
if (asset.chunks?.length
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (match[2] === "editor-script") {
|
|
38
|
-
key = "editorScript";
|
|
39
|
-
}
|
|
40
|
-
else if (match[2] === "view-script") {
|
|
41
|
-
key = "viewScript";
|
|
42
|
-
}
|
|
43
|
-
else if (match[2] === "editor-style") {
|
|
44
|
-
key = "editorStyle";
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
key = match[2];
|
|
48
|
-
}
|
|
49
|
-
if (!mapping[match[1]][key]) {
|
|
50
|
-
mapping[match[1]][key] = [];
|
|
51
|
-
}
|
|
52
|
-
mapping[match[1]][key].push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset.name]);
|
|
53
|
+
if ((asset.chunks?.length ?? -1) > 1 || !asset.size) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
let match;
|
|
57
|
+
if ((match = /^(.+?)-setup.php$/i.exec(asset.name)) && match[1]) {
|
|
58
|
+
if (!mapping[match[1]]) {
|
|
59
|
+
mapping[match[1]] = { resources: {} };
|
|
53
60
|
}
|
|
61
|
+
mapping[match[1]].setup = `${asset.name}`;
|
|
62
|
+
}
|
|
63
|
+
else if ((match = /^(.+?)-(editor-style|style|view-script|editor-script|script)\.(?:css|m?js)$/i.exec(asset.name)) && match[1] && match[2]) {
|
|
64
|
+
if (!mapping[match[1]]) {
|
|
65
|
+
mapping[match[1]] = { resources: {} };
|
|
66
|
+
}
|
|
67
|
+
let key;
|
|
68
|
+
if (match[2] === "editor-script") {
|
|
69
|
+
key = "editorScript";
|
|
70
|
+
}
|
|
71
|
+
else if (match[2] === "view-script") {
|
|
72
|
+
key = "viewScript";
|
|
73
|
+
}
|
|
74
|
+
else if (match[2] === "editor-style") {
|
|
75
|
+
key = "editorStyle";
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
key = match[2];
|
|
79
|
+
}
|
|
80
|
+
(mapping[match[1]].resources[key] ?? (mapping[match[1]].resources[key] = [])).push([`plaudit_block-extension_${match[1]}-${match[2]}`, asset.name]);
|
|
54
81
|
}
|
|
55
82
|
}
|
|
56
83
|
let contents = `a:${Object.keys(mapping).length}:{`;
|
|
57
|
-
for (const [blockSlug,
|
|
84
|
+
for (const [blockSlug, { setup, resources }] of Object.entries(mapping)) {
|
|
58
85
|
contents += `s:${blockSlug.length}:"${blockSlug}";`;
|
|
59
|
-
contents += `a:${
|
|
60
|
-
|
|
86
|
+
contents += `a:${setup ? 2 : 1}:{`; // Open the mapping for the current block as a whole
|
|
87
|
+
// Open the mapping for the current block's resource files
|
|
88
|
+
contents += `i:0;a:${Object.entries(resources).length}:{`;
|
|
89
|
+
for (const [mapping, handlerFiles] of Object.entries(resources)) {
|
|
61
90
|
contents += `s:${mapping.length}:"${mapping}";`;
|
|
62
91
|
contents += `a:${handlerFiles.length}:{`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
contents += `i:${
|
|
92
|
+
let count = 0;
|
|
93
|
+
for (const handlerFile of handlerFiles) {
|
|
94
|
+
contents += `i:${count++};a:2:{i:0;s:${handlerFile[0].length}:"${handlerFile[0]}";i:1;s:${handlerFile[1].length}:"${handlerFile[1]}";}`;
|
|
66
95
|
}
|
|
67
96
|
contents += "}";
|
|
68
97
|
}
|
|
69
|
-
contents += "}";
|
|
98
|
+
contents += "}"; // Close the mapping for the current block's resource files
|
|
99
|
+
if (setup) {
|
|
100
|
+
contents += `i:1;s:${setup.length}:"${setup}";`;
|
|
101
|
+
}
|
|
102
|
+
contents += "}"; // Close the mapping for the current block as a whole
|
|
70
103
|
}
|
|
71
104
|
contents += "}";
|
|
72
105
|
compilation.emitAsset("mapping.config", new webpack_1.sources.RawSource(contents.trim()));
|
|
@@ -16,7 +16,7 @@ const nanoConfig = {
|
|
|
16
16
|
'cssnano-preset-default',
|
|
17
17
|
{
|
|
18
18
|
safe: true,
|
|
19
|
-
autoprefixer: false,
|
|
19
|
+
autoprefixer: false, // Unsafe
|
|
20
20
|
calc: false,
|
|
21
21
|
colormin: true,
|
|
22
22
|
convertValues: false,
|
|
@@ -29,10 +29,10 @@ const nanoConfig = {
|
|
|
29
29
|
discardDuplicates: true,
|
|
30
30
|
discardEmpty: true,
|
|
31
31
|
discardOverridden: true,
|
|
32
|
-
discardUnused: false,
|
|
33
|
-
mergeIdents: false,
|
|
32
|
+
discardUnused: false, // Unsafe
|
|
33
|
+
mergeIdents: false, // Unsafe
|
|
34
34
|
mergeLonghand: true,
|
|
35
|
-
mergeRules: false,
|
|
35
|
+
mergeRules: false, // Off for speed
|
|
36
36
|
minifyFontValues: true,
|
|
37
37
|
minifyGradients: true,
|
|
38
38
|
minifyParams: true,
|
|
@@ -47,12 +47,12 @@ const nanoConfig = {
|
|
|
47
47
|
normalizeUrl: true,
|
|
48
48
|
normalizeWhitespace: true,
|
|
49
49
|
orderedValues: true,
|
|
50
|
-
reduceIdents: false,
|
|
50
|
+
reduceIdents: false, // Unsafe
|
|
51
51
|
reduceInitial: true,
|
|
52
52
|
reduceTransforms: true,
|
|
53
|
-
svgo: false,
|
|
53
|
+
svgo: false, // Off for speed
|
|
54
54
|
uniqueSelectors: true,
|
|
55
|
-
zindex: false,
|
|
55
|
+
zindex: false, // Unsafe
|
|
56
56
|
filterPlugins: false // I don't know where this one came from. It is not listed in the documentation.
|
|
57
57
|
}
|
|
58
58
|
]
|
|
@@ -60,25 +60,25 @@ const nanoConfig = {
|
|
|
60
60
|
function postcssConfigBuilder(verbose, variables) {
|
|
61
61
|
return {
|
|
62
62
|
plugins: [
|
|
63
|
-
require("postcss-import")(),
|
|
64
|
-
require("@plaudit/postcss-silent-extend")({ warnOfUnused: verbose }),
|
|
65
|
-
require("postcss-mixins")(),
|
|
66
|
-
require("@plaudit/postcss-variables")({ variables }),
|
|
67
|
-
require("postcss-quantity-queries")(),
|
|
68
|
-
require("postcss-short-position")(),
|
|
69
|
-
require("postcss-short-size")(),
|
|
70
|
-
require("postcss-short-spacing")(),
|
|
71
|
-
require("postcss-fallback")(),
|
|
72
|
-
require("postcss-property-lookup")({ logLevel: "warn" }),
|
|
73
|
-
require("@plaudit/postcss-strip-units")(),
|
|
74
|
-
require("postcss-media-minmax")(),
|
|
75
|
-
require("postcss-inline-svg")(),
|
|
76
|
-
require("postcss-nested")(),
|
|
63
|
+
require("postcss-import")(), // Once
|
|
64
|
+
require("@plaudit/postcss-silent-extend")({ warnOfUnused: verbose }), // Once (marks), OnceExit (apply)
|
|
65
|
+
require("postcss-mixins")(), // There is a PostCSS 8 version, but we're forced to use the old one because the new one uses AtRule, which is too late in the process
|
|
66
|
+
require("@plaudit/postcss-variables")({ variables }), // Once
|
|
67
|
+
require("postcss-quantity-queries")(), // Legacy
|
|
68
|
+
require("postcss-short-position")(), // Legacy
|
|
69
|
+
require("postcss-short-size")(), // Legacy
|
|
70
|
+
require("postcss-short-spacing")(), // Legacy
|
|
71
|
+
require("postcss-fallback")(), // Legacy
|
|
72
|
+
require("postcss-property-lookup")({ logLevel: "warn" }), // Rule
|
|
73
|
+
require("@plaudit/postcss-strip-units")(), // AtRule, Declaration
|
|
74
|
+
require("postcss-media-minmax")(), // AtRule
|
|
75
|
+
require("postcss-inline-svg")(), // AtRule
|
|
76
|
+
require("postcss-nested")(), // Rule
|
|
77
77
|
require("postcss-url")(),
|
|
78
|
-
require("postcss-calc")(calcOptions),
|
|
79
|
-
require("@plaudit/postcss-color-function")(),
|
|
80
|
-
require("autoprefixer")(autoprefixerOptions),
|
|
81
|
-
require("postcss-reporter")({ clearReportedMessages: true }),
|
|
78
|
+
require("postcss-calc")(calcOptions), // OnceExit
|
|
79
|
+
require("@plaudit/postcss-color-function")(), // OnceExit
|
|
80
|
+
require("autoprefixer")(autoprefixerOptions), // OnceExit
|
|
81
|
+
require("postcss-reporter")({ clearReportedMessages: true }), // OnceExit
|
|
82
82
|
(0, cssnano_1.default)(nanoConfig)
|
|
83
83
|
]
|
|
84
84
|
};
|
|
@@ -235,7 +235,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
235
235
|
}
|
|
236
236
|
plugins.push(new AdditionalDependencyInjectorPlugin_1.default(typeof dest !== 'string' && dest.additionalDependencies ? dest.additionalDependencies : []));
|
|
237
237
|
if (srcIsDirectory && (typeof dest !== 'string' && dest.directoryLayout === 'extensions')) {
|
|
238
|
-
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default());
|
|
238
|
+
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default(srcRoot));
|
|
239
239
|
}
|
|
240
240
|
if (first) {
|
|
241
241
|
first = false;
|
|
@@ -295,7 +295,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
295
295
|
const perAssetPathGroupedEntrypoints = groupEntrypointsByAssetFile(rawEntrypoints, e => e[0]);
|
|
296
296
|
const currentEntry = {};
|
|
297
297
|
for (const groupedEntrypoints of perAssetPathGroupedEntrypoints.values()) {
|
|
298
|
-
if (groupedEntrypoints.length === 1) {
|
|
298
|
+
if (groupedEntrypoints.length === 1 && groupedEntrypoints[0] !== undefined) {
|
|
299
299
|
currentEntry[groupedEntrypoints[0][0]] = groupedEntrypoints[0][1];
|
|
300
300
|
}
|
|
301
301
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -19,31 +19,31 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/browser-sync-webpack-plugin": "^2.2.3",
|
|
22
|
-
"@types/node": "^20.
|
|
23
|
-
"@types/tapable": "^2.2.
|
|
24
|
-
"@types/webpack": "^5.28.
|
|
25
|
-
"@types/webpack-sources": "^3.2.
|
|
26
|
-
"postcss-load-config": "^4.0.
|
|
27
|
-
"postcss-loader": "^7.3.
|
|
28
|
-
"ts-node": "^10.9.
|
|
29
|
-
"typescript": "^5.
|
|
22
|
+
"@types/node": "^20.10.6",
|
|
23
|
+
"@types/tapable": "^2.2.7",
|
|
24
|
+
"@types/webpack": "^5.28.5",
|
|
25
|
+
"@types/webpack-sources": "^3.2.3",
|
|
26
|
+
"postcss-load-config": "^4.0.2",
|
|
27
|
+
"postcss-loader": "^7.3.4",
|
|
28
|
+
"ts-node": "^10.9.2",
|
|
29
|
+
"typescript": "^5.3.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@plaudit/postcss-color-function": "^5.0.0",
|
|
33
33
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
34
34
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
35
35
|
"@plaudit/postcss-variables": "^1.0.0",
|
|
36
|
-
"@wordpress/scripts": "^26.
|
|
36
|
+
"@wordpress/scripts": "^26.19.0",
|
|
37
37
|
"autoprefixer": "^10.4.16",
|
|
38
38
|
"browser-sync": "^2.29.3",
|
|
39
39
|
"browser-sync-webpack-plugin": "^2.3.0",
|
|
40
40
|
"clean-webpack-plugin": "^4.0.0",
|
|
41
41
|
"copy-webpack-plugin": "^11.0.0",
|
|
42
|
-
"cssnano": "^6.0.
|
|
42
|
+
"cssnano": "^6.0.3",
|
|
43
43
|
"eslint": "^8.50.0",
|
|
44
44
|
"eslint-plugin-jsdoc": "^46.8.2",
|
|
45
45
|
"fork-ts-checker-webpack-plugin": "^8.0.0",
|
|
46
|
-
"postcss": "^8.4.
|
|
46
|
+
"postcss": "^8.4.33",
|
|
47
47
|
"postcss-calc": "^9.0.1",
|
|
48
48
|
"postcss-discard-comments": "^6.0.0",
|
|
49
49
|
"postcss-fallback": "^0.1.0",
|