weboptimizer 4.0.20 → 4.0.21
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/browser.js +3 -4
- package/configurator.d.ts +0 -2
- package/configurator.js +10 -66
- package/ejsLoader.js +1 -1
- package/package.json +9 -9
- package/stylelintConfigurator.d.ts +1 -1
- package/stylelintConfigurator.js +1 -5
- package/webpackConfigurator.js +18 -11
package/browser.js
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
19
|
import { CONSOLE_METHODS, Logger, timeout } from 'clientnode';
|
|
20
|
-
import webOptimizerDefaultTemplate from 'webOptimizerDefaultTemplateFilePath';
|
|
21
20
|
// endregion
|
|
22
21
|
// region declaration
|
|
23
22
|
|
|
@@ -100,17 +99,17 @@ if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
|
100
99
|
NOTE: We load dependencies now to avoid having file imports
|
|
101
100
|
after test runner has finished to isolate the environment.
|
|
102
101
|
*/
|
|
103
|
-
const ejsLoader = (await import('./ejsLoader')).default;
|
|
102
|
+
const ejsLoader = (await import('./ejsLoader.js')).default;
|
|
104
103
|
const content = await (await import('fs')).promises.readFile(filePath, {
|
|
105
104
|
encoding: 'utf-8'
|
|
106
105
|
});
|
|
107
106
|
await ejsLoader.bind({
|
|
108
107
|
resourcePath: filePath,
|
|
109
|
-
async: (error, result) => {
|
|
108
|
+
async: () => (error, result) => {
|
|
110
109
|
if (error) throw error;else evaluatedContent = result;
|
|
111
110
|
}
|
|
112
111
|
})(content);
|
|
113
|
-
} else evaluatedContent =
|
|
112
|
+
} else evaluatedContent = (await import('webOptimizerDefaultTemplateFilePath')).default;
|
|
114
113
|
render(evaluatedContent);
|
|
115
114
|
// endregion
|
|
116
115
|
})().catch(error => {
|
package/configurator.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ResolvedConfiguration } from './type';
|
|
2
2
|
import { Logger } from 'clientnode';
|
|
3
|
-
export declare const require: NodeJS.Require;
|
|
4
|
-
export declare const optionalRequire: <T = unknown>(id: string) => null | T;
|
|
5
3
|
export declare let loadedConfiguration: null | ResolvedConfiguration;
|
|
6
4
|
export declare const log: Logger;
|
|
7
5
|
/**
|
package/configurator.js
CHANGED
|
@@ -16,63 +16,6 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
const _rewrite = (specifier, options) => {
|
|
20
|
-
if (typeof specifier !== 'string') {
|
|
21
|
-
throw new TypeError(`rewrite error: expected specifier of type string, not ${typeof specifier}`);
|
|
22
|
-
}
|
|
23
|
-
let replacementMap;
|
|
24
|
-
if (options.replaceExtensions) {
|
|
25
|
-
Object.entries(options.replaceExtensions).some(([target, replacement]) => {
|
|
26
|
-
if (target.startsWith('^') || target.endsWith('$')) {
|
|
27
|
-
const targetRegExp = new RegExp(target);
|
|
28
|
-
const capturingGroups = Array.from(specifier.match(targetRegExp) || []);
|
|
29
|
-
if (capturingGroups.length) {
|
|
30
|
-
replacementMap = [targetRegExp, replacement, capturingGroups];
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
} else if (specifier.endsWith(target)) {
|
|
34
|
-
replacementMap = [target, replacement, []];
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
let finalImportPath = specifier;
|
|
40
|
-
if (replacementMap) {
|
|
41
|
-
const [target, replacement, capturingGroups] = replacementMap;
|
|
42
|
-
finalImportPath = finalImportPath.replace(target, typeof replacement === 'string' ? replacement : replacement({
|
|
43
|
-
specifier,
|
|
44
|
-
capturingGroups,
|
|
45
|
-
filepath: '/__w/weboptimizer/weboptimizer/configurator.ts'
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
const isRelative = finalImportPath.startsWith('./') || finalImportPath.startsWith('.\\') || finalImportPath.startsWith('../') || finalImportPath.startsWith('..\\') || finalImportPath === '.' || finalImportPath === '..';
|
|
49
|
-
if (options.appendExtension && isRelative) {
|
|
50
|
-
const endsWithSlash = /(\/|\\)$/.test(finalImportPath);
|
|
51
|
-
const basenameIsDots = /(^\.?\.(\/|\\)?$)|((\/|\\)\.?\.(\/|\\)?$)/.test(finalImportPath);
|
|
52
|
-
const extensionToAppend = typeof options.appendExtension === 'string' ? options.appendExtension : options.appendExtension({
|
|
53
|
-
specifier,
|
|
54
|
-
capturingGroups: [],
|
|
55
|
-
filepath: '/__w/weboptimizer/weboptimizer/configurator.ts'
|
|
56
|
-
});
|
|
57
|
-
if (extensionToAppend !== undefined) {
|
|
58
|
-
if (basenameIsDots) {
|
|
59
|
-
finalImportPath += `${endsWithSlash ? '' : '/'}index${extensionToAppend}`;
|
|
60
|
-
} else {
|
|
61
|
-
const hasRecognizedExtension = !endsWithSlash && options.recognizedExtensions.some(extension => {
|
|
62
|
-
return finalImportPath.endsWith(extension);
|
|
63
|
-
});
|
|
64
|
-
if (!hasRecognizedExtension) {
|
|
65
|
-
finalImportPath = endsWithSlash ? finalImportPath + `index${extensionToAppend}` : finalImportPath + extensionToAppend;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return finalImportPath;
|
|
71
|
-
},
|
|
72
|
-
_rewrite_options = {
|
|
73
|
-
"appendExtension": ".js",
|
|
74
|
-
"recognizedExtensions": [".js", ".jsx", ".d.ts", ".ts", ".tsx", ".json"]
|
|
75
|
-
};
|
|
76
19
|
import { convertCircularObjectToJSON, copy, evaluateAsyncDynamicData, evaluateDynamicData, extend, getUTCTimestamp, importsPromise, isFileSync, isObject, isPlainObject, Logger, MAXIMAL_NUMBER_OF_ITERATIONS, modifyObject, optionalImport, parseEncodedObject, removeKeyPrefixes, UTILITY_SCOPE } from 'clientnode';
|
|
77
20
|
import fileSystem, { lstatSync, readFileSync, unlinkSync } from 'fs';
|
|
78
21
|
import { createRequire } from 'node:module';
|
|
@@ -81,14 +24,6 @@ import { determineAssetType, determineModuleFilePath, determineModuleLocations,
|
|
|
81
24
|
import packageConfiguration from './package.json' with { type: 'json' };
|
|
82
25
|
import { SubConfigurationTypes } from "./type.js";
|
|
83
26
|
// endregion
|
|
84
|
-
export const require = createRequire(import.meta.url);
|
|
85
|
-
export const optionalRequire = id => {
|
|
86
|
-
try {
|
|
87
|
-
return require(_rewrite(id, _rewrite_options));
|
|
88
|
-
} catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
27
|
const {
|
|
93
28
|
configuration: metaConfiguration
|
|
94
29
|
} = packageConfiguration;
|
|
@@ -184,7 +119,16 @@ environment = eval('process.env')) => {
|
|
|
184
119
|
if (debug) configuration = extend(true, modifyObject(metaConfiguration.default, metaConfiguration.debug), metaConfiguration.debug);else configuration = metaConfiguration.default;
|
|
185
120
|
configuration.debug = debug;
|
|
186
121
|
if (typeof configuration.library === 'object') extend(true, modifyObject(libraryConfiguration, configuration.library), configuration.library);
|
|
187
|
-
if (configuration.library && specificConfiguration.library !== false)
|
|
122
|
+
if (configuration.library && specificConfiguration.library !== false) {
|
|
123
|
+
const modifiedConfiguration = modifyObject(configuration, libraryConfiguration);
|
|
124
|
+
configuration = extend(true,
|
|
125
|
+
/*
|
|
126
|
+
NOTE: We have to copy both objects otherwise the
|
|
127
|
+
substucture under "path" is not extended as expected.
|
|
128
|
+
*/
|
|
129
|
+
copy(modifiedConfiguration), copy(libraryConfiguration));
|
|
130
|
+
}
|
|
131
|
+
|
|
188
132
|
// endregion
|
|
189
133
|
// region merging and evaluating task specific and dynamic configurations
|
|
190
134
|
/// region load additional dynamically given configuration
|
package/ejsLoader.js
CHANGED
|
@@ -29,7 +29,6 @@ import { determineModuleFilePath } from "./helper.js";
|
|
|
29
29
|
// region types
|
|
30
30
|
|
|
31
31
|
// endregion
|
|
32
|
-
const configuration = await getConfiguration();
|
|
33
32
|
export const log = new Logger({
|
|
34
33
|
name: 'weboptimizer.ejs-loader'
|
|
35
34
|
});
|
|
@@ -40,6 +39,7 @@ export const log = new Logger({
|
|
|
40
39
|
*/
|
|
41
40
|
export const loader = async function (source) {
|
|
42
41
|
const callback = this.async();
|
|
42
|
+
const configuration = await getConfiguration();
|
|
43
43
|
const givenOptions = convertSubstringInPlainObject(extend(true, {
|
|
44
44
|
compiler: {
|
|
45
45
|
async: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.21",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"lint:base": "eslint --no-warn-ignored *.ts */*.ts test/*/*.ts",
|
|
78
78
|
"prepare": "yarn build",
|
|
79
79
|
"prettify": "yarn lint:base --fix || true",
|
|
80
|
-
"test": "yarn build:test && jest --config ./weboptimizerJest.json --noStackTrace --root-dir './' --test-regex '/test/.+\\\\.js$' test/browser.js test/configurator.js test/helper.js test/ejsLoader.js test/stylelintConfigurator.js test/index.js test/webpackConfigurator.js",
|
|
80
|
+
"test": "yarn build:test && node --experimental-vm-modules node_modules/.bin/jest --config ./weboptimizerJest.json --noStackTrace --root-dir './' --test-regex '/test/.+\\\\.js$' test/browser.js test/configurator.js test/helper.js test/ejsLoader.js test/stylelintConfigurator.js test/index.js test/webpackConfigurator.js",
|
|
81
81
|
"test:coverage": "yarn test --ci --coverage --coverageReporters=text --coverageReporters=text-summary --silent --testLocationInResults",
|
|
82
82
|
"test:coverage:report": "yarn test:coverage --coverageDirectory=.coverage --coverageReporters=lcov --outputFile=lcov.info",
|
|
83
83
|
"test:watch": "yarn test --watch",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"babel-plugin-polyfill-corejs3": "^1.0.0",
|
|
96
96
|
"babel-plugin-transform-rewrite-imports": "^1.5.4",
|
|
97
97
|
"babel-preset-minify": "^0.5.2",
|
|
98
|
-
"clientnode": "4.0.
|
|
98
|
+
"clientnode": "4.0.1451",
|
|
99
99
|
"core-js": "^3.49.0",
|
|
100
100
|
"ejs": "^6.0.1",
|
|
101
101
|
"exports-loader": "^5.0.0",
|
|
@@ -128,12 +128,12 @@
|
|
|
128
128
|
"@types/postcss-url": "^10.0.4",
|
|
129
129
|
"@types/webpack-env": "^1.18.8",
|
|
130
130
|
"@types/webpack-sources": "^3.2.3",
|
|
131
|
-
"@typescript-eslint/parser": "^8.
|
|
131
|
+
"@typescript-eslint/parser": "^8.64.0",
|
|
132
132
|
"css-loader": "^7.1.4",
|
|
133
133
|
"cssnano": "^8.0.2",
|
|
134
|
-
"eslint": "^10.
|
|
134
|
+
"eslint": "^10.7.0",
|
|
135
135
|
"eslint-config-google": "^0.14.0",
|
|
136
|
-
"eslint-plugin-jsdoc": "^63.0.
|
|
136
|
+
"eslint-plugin-jsdoc": "^63.0.13",
|
|
137
137
|
"favicons": "^7.3.0",
|
|
138
138
|
"favicons-webpack-plugin": "^6.0.1",
|
|
139
139
|
"globals": "^17.7.0",
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
"mini-css-extract-plugin": "^2.10.2",
|
|
144
144
|
"mkdirp": "^3.0.1",
|
|
145
145
|
"node-fetch": "^3.3.2",
|
|
146
|
-
"postcss": "^8.5.
|
|
146
|
+
"postcss": "^8.5.19",
|
|
147
147
|
"postcss-fontpath": "^1.0.0",
|
|
148
148
|
"postcss-import": "^16.1.1",
|
|
149
149
|
"postcss-loader": "^8.2.1",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"stylelint-config-standard": "^40.0.0",
|
|
157
157
|
"stylelint-config-standard-scss": "^17.0.0",
|
|
158
158
|
"terser-webpack-plugin": "^5.6.1",
|
|
159
|
-
"typescript-eslint": "^8.
|
|
159
|
+
"typescript-eslint": "^8.64.0",
|
|
160
160
|
"typescript-plugin-css-modules": "^5.2.0",
|
|
161
161
|
"web-documentation": "^1.0.42",
|
|
162
162
|
"workbox-webpack-plugin": "^7.4.1"
|
|
@@ -950,7 +950,7 @@
|
|
|
950
950
|
"#": "The autoprefixer has to be disabled in this context since it would remove all needed vendor prefixes from the preceding processing (every prefix should be needed here).",
|
|
951
951
|
"preset": [
|
|
952
952
|
{
|
|
953
|
-
"__await_evaluate__": "module.optionalImport('cssnano-preset-default')"
|
|
953
|
+
"__await_evaluate__": "module.optionalImport('cssnano-preset-default').then((module) => module?.default)"
|
|
954
954
|
},
|
|
955
955
|
{
|
|
956
956
|
"autoprefixer": false,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("clientnode").PlainObject;
|
|
2
2
|
export default _default;
|
package/stylelintConfigurator.js
CHANGED
|
@@ -15,10 +15,6 @@
|
|
|
15
15
|
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
|
-
// region imports
|
|
19
18
|
import getConfiguration from "./configurator.js";
|
|
20
|
-
import { ResolvedConfiguration } from "./type.js";
|
|
21
|
-
// endregion
|
|
22
19
|
const configuration = await getConfiguration();
|
|
23
|
-
|
|
24
|
-
export default module.exports;
|
|
20
|
+
export default configuration.stylelint;
|
package/webpackConfigurator.js
CHANGED
|
@@ -42,12 +42,12 @@ import HTMLTransformation from "./plugins/HTMLTransformation.js";
|
|
|
42
42
|
await importsPromise;
|
|
43
43
|
|
|
44
44
|
/// region optional imports
|
|
45
|
-
const postcssCSSnano = await optionalImport('cssnano');
|
|
46
|
-
const postcssFontpath = await optionalImport('postcss-fontpath');
|
|
47
|
-
const postcssImport = await optionalImport('postcss-import');
|
|
48
|
-
const postcssSprites = await optionalImport('postcss-sprites');
|
|
49
|
-
const updateRule = (await optionalImport('postcss-sprites/lib/core'))?.updateRule;
|
|
50
|
-
const postcssURL = await optionalImport('postcss-url');
|
|
45
|
+
const postcssCSSnano = (await optionalImport('cssnano'))?.default;
|
|
46
|
+
const postcssFontpath = (await optionalImport('postcss-fontpath'))?.default;
|
|
47
|
+
const postcssImport = (await optionalImport('postcss-import'))?.default;
|
|
48
|
+
const postcssSprites = (await optionalImport('postcss-sprites'))?.default;
|
|
49
|
+
const updateRule = (await optionalImport('postcss-sprites/lib/core'))?.default.updateRule;
|
|
50
|
+
const postcssURL = (await optionalImport('postcss-url'))?.default;
|
|
51
51
|
/// endregion
|
|
52
52
|
export const log = new Logger({
|
|
53
53
|
name: 'weboptimizer.webpack-configurator'
|
|
@@ -70,12 +70,15 @@ for (const [name, alias] of Object.entries(pluginNameResourceMapping)) {
|
|
|
70
70
|
if ('default' in plugin) plugins[name] = plugin.default;else plugins[name] = plugin;
|
|
71
71
|
} else log.debug(`Optional webpack plugin "${name}" not available.`);
|
|
72
72
|
}
|
|
73
|
+
|
|
73
74
|
// endregion
|
|
74
75
|
const configuration = await getConfiguration();
|
|
75
76
|
Logger.configureAllInstances({
|
|
76
77
|
level: configuration.debug ? 'debug' : 'warn'
|
|
77
78
|
});
|
|
78
|
-
const
|
|
79
|
+
const {
|
|
80
|
+
module
|
|
81
|
+
} = configuration;
|
|
79
82
|
// region initialization
|
|
80
83
|
/// region determine library name
|
|
81
84
|
const exportFormatsNeedingAValidVariableName = ['assign', 'global', 'this', 'var', 'window'];
|
|
@@ -720,8 +723,11 @@ if (htmlAvailable && configuration.debug && configuration.development.server.liv
|
|
|
720
723
|
// endregion
|
|
721
724
|
// region plugins
|
|
722
725
|
for (const pluginConfiguration of configuration.plugins) {
|
|
723
|
-
|
|
724
|
-
if (plugin)
|
|
726
|
+
let plugin = await optionalImport(pluginConfiguration.name.module);
|
|
727
|
+
if (plugin) {
|
|
728
|
+
if ('default' in plugin) plugin = plugin.default;
|
|
729
|
+
pluginInstances.push(new plugin[pluginConfiguration.name.initializer](...pluginConfiguration.parameters));
|
|
730
|
+
} else log.warn(`Configured plugin module "${pluginConfiguration.name.module}"`, 'could not be loaded.');
|
|
725
731
|
}
|
|
726
732
|
// endregion
|
|
727
733
|
// region minimizer and image compression
|
|
@@ -858,9 +864,10 @@ if (Array.isArray(module.skipParseRegularExpressions) ? module.skipParseRegularE
|
|
|
858
864
|
};
|
|
859
865
|
if (configuration.path.configuration.javaScript) try {
|
|
860
866
|
import.meta.resolve(configuration.path.configuration.javaScript);
|
|
861
|
-
|
|
867
|
+
let result = await optionalImport(configuration.path.configuration.javaScript);
|
|
862
868
|
if (isPlainObject(result)) {
|
|
863
|
-
if (
|
|
869
|
+
if ('default' in result) result = result.default;
|
|
870
|
+
if ('replaceWebOptimizer' in result) webpackConfiguration = result.replaceWebOptimizer;else extend(true, webpackConfiguration, result);
|
|
864
871
|
} else log.debug('Failed to load given JavaScript configuration file path', `"${configuration.path.configuration.javaScript}".`);
|
|
865
872
|
} catch {
|
|
866
873
|
log.debug('Optional configuration file script', `"${configuration.path.configuration.javaScript}" not available.`);
|