@plaudit/webpack-extensions 2.0.2 → 2.1.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.
|
@@ -6,11 +6,11 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
6
6
|
const node_path_1 = __importDefault(require("node:path"));
|
|
7
7
|
const AdditionalDependencyInjectorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin"));
|
|
8
8
|
const BlockJSONStyleRemappingPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/BlockJSONStyleRemappingPlugin"));
|
|
9
|
+
const static_configs_1 = require("./wordpress-scripts-wrapper/static-configs");
|
|
9
10
|
const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webpack-plugin"));
|
|
10
11
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
11
12
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
12
13
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
13
|
-
const static_configs_1 = require("./wordpress-scripts-wrapper/static-configs");
|
|
14
14
|
function joinPossiblyAbsolutePaths(...paths) {
|
|
15
15
|
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
16
16
|
}
|
|
@@ -23,14 +23,49 @@ function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypo
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
function isTruthy(value) {
|
|
27
|
+
return !!value;
|
|
28
|
+
}
|
|
26
29
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
30
|
+
const seenPaths = new Map();
|
|
31
|
+
for (const bundleName of (Array.isArray(config.src) ? config.src : Object.values(config.src))) {
|
|
32
|
+
const key = bundleName.substring(0, bundleName.length - node_path_1.default.extname(bundleName).length);
|
|
33
|
+
let seen = seenPaths.get(key);
|
|
34
|
+
if (seen === undefined) {
|
|
35
|
+
seenPaths.set(key, seen = []);
|
|
36
|
+
}
|
|
37
|
+
seen.push(bundleName);
|
|
38
|
+
node_path_1.default.basename(bundleName, node_path_1.default.extname(bundleName));
|
|
39
|
+
}
|
|
40
|
+
let projectPrefix = undefined;
|
|
41
|
+
let duplicatedPaths = "";
|
|
42
|
+
for (const sameNamePaths of seenPaths.values()) {
|
|
43
|
+
if (sameNamePaths.length > 1) {
|
|
44
|
+
if (projectPrefix === undefined) {
|
|
45
|
+
for (let p = process.cwd(); p.length > 1; p = node_path_1.default.dirname(p)) {
|
|
46
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(p, "docker-compose.yml"))) {
|
|
47
|
+
projectPrefix = new RegExp(`^${p}`);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (projectPrefix === undefined) {
|
|
52
|
+
projectPrefix = /^/;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
duplicatedPaths += `\n* ${node_path_1.default.dirname(sameNamePaths[0]).replace(projectPrefix, '')}/[${sameNamePaths.map(p => node_path_1.default.basename(p)).join(', ')}]`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (duplicatedPaths.length !== 0) {
|
|
59
|
+
console.error(`Encountered multiple paths that produce the same effective bundle name:${duplicatedPaths}`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
27
62
|
const { legacyPostcssPlugins = false, variables = ["variables.js", "preprocess/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;
|
|
28
63
|
const cssLoader = require.resolve('css-loader');
|
|
29
64
|
if (cssLoader && webpackConfig.module?.rules) {
|
|
30
65
|
for (const rule of webpackConfig.module.rules) {
|
|
31
|
-
if (typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
|
|
66
|
+
if (isTruthy(rule) && typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
|
|
32
67
|
for (const useElement of rule.use) {
|
|
33
|
-
if (typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
|
|
68
|
+
if (isTruthy(useElement) && typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
|
|
34
69
|
useElement.options['url'] = false;
|
|
35
70
|
}
|
|
36
71
|
}
|
|
@@ -49,9 +84,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
49
84
|
return undefined;
|
|
50
85
|
});
|
|
51
86
|
for (const rule of webpackConfig.module.rules) {
|
|
52
|
-
if (typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
87
|
+
if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
53
88
|
for (const useItem of rule.use) {
|
|
54
|
-
if (typeof useItem === 'object' && typeof useItem.options === 'object') {
|
|
89
|
+
if (isTruthy(useItem) && typeof useItem === 'object' && typeof useItem.options === 'object') {
|
|
55
90
|
if (useItem.options["sourceMap"] === false) {
|
|
56
91
|
useItem.options["sourceMap"] = true;
|
|
57
92
|
}
|
|
@@ -76,7 +111,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
76
111
|
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
77
112
|
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
|
|
78
113
|
const copyFiles = srcIsDirectory && src !== dest;
|
|
79
|
-
const plugins = webpackConfig.plugins
|
|
114
|
+
const plugins = webpackConfig.plugins?.filter(isTruthy) ?? [];
|
|
80
115
|
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
81
116
|
typescript: {
|
|
82
117
|
diagnosticOptions: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/browser-sync-webpack-plugin": "^2.2.2",
|
|
17
|
-
"@types/node": "^20.3.
|
|
17
|
+
"@types/node": "^20.3.1",
|
|
18
18
|
"@types/tapable": "^2.2.3",
|
|
19
19
|
"@types/webpack": "^5.28.1",
|
|
20
20
|
"@types/webpack-sources": "^3.2.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"postcss-simple-vars": "^7.0.1",
|
|
57
57
|
"react": "^18.2.0",
|
|
58
58
|
"react-dom": "^18.2.0",
|
|
59
|
-
"webpack": "^5.
|
|
59
|
+
"webpack": "^5.87.0",
|
|
60
60
|
"webpack-remove-empty-scripts": "^1.0.3",
|
|
61
61
|
"webpack-sources": "^3.2.3"
|
|
62
62
|
},
|