weboptimizer 4.0.72 → 4.0.74
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 +67 -74
- package/configurator.js +3 -3
- package/ejsLoader.js +56 -60
- package/package.json +4 -4
package/browser.js
CHANGED
|
@@ -37,84 +37,77 @@ export const log = new Logger({
|
|
|
37
37
|
});
|
|
38
38
|
// endregion
|
|
39
39
|
// region ensure presence of common browser environment
|
|
40
|
-
if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node') {
|
|
41
|
+
// region mock browser environment
|
|
42
|
+
const [{
|
|
43
|
+
JSDOM,
|
|
44
|
+
VirtualConsole: VirtualConsoleImplementation
|
|
45
|
+
}, path] = await Promise.all([import('jsdom'), import('path')]);
|
|
46
|
+
const virtualConsole = new VirtualConsoleImplementation();
|
|
47
|
+
for (const name of CONSOLE_METHODS) virtualConsole.on(name, console[name].bind(console));
|
|
48
|
+
virtualConsole.on('error', error => {
|
|
49
|
+
if (!browser.debug && ['XMLHttpRequest', 'resource loading'].includes(error.type)) log.warn(`Loading resource failed: ${error.toString()}.`);else log.error(error.stack, error.detail);
|
|
50
|
+
});
|
|
51
|
+
const render = template => {
|
|
52
|
+
browser.DOM = JSDOM;
|
|
53
|
+
browser.initialized = true;
|
|
54
|
+
browser.instance = new browser.DOM(template, {
|
|
55
|
+
beforeParse: window => {
|
|
56
|
+
// We want to use it in a polymorphic way.
|
|
57
|
+
/*
|
|
58
|
+
eslint-disable
|
|
59
|
+
@typescript-eslint/no-unnecessary-type-assertion
|
|
60
|
+
*/
|
|
61
|
+
browser.window = global.window ?? window;
|
|
62
|
+
/*
|
|
63
|
+
eslint-enable
|
|
64
|
+
@typescript-eslint/no-unnecessary-type-assertion
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
window.document.addEventListener('DOMContentLoaded', () => {
|
|
62
68
|
/*
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
Move template results into global
|
|
70
|
+
pre-defined dom.
|
|
65
71
|
*/
|
|
66
|
-
|
|
72
|
+
if (global.window) for (const type of ['head', 'body']) global.window.document[type].innerHTML = window.document[type].innerHTML;
|
|
73
|
+
browser.domContentLoaded = true;
|
|
74
|
+
});
|
|
75
|
+
window.addEventListener('load', () => {
|
|
67
76
|
/*
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
NOTE: Maybe we have miss the "DOMContentLoaded"
|
|
78
|
+
event caused by a race condition.
|
|
70
79
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const ejsLoader = (await import('./ejsLoader.js')).default;
|
|
103
|
-
const content = await (await import('fs')).promises.readFile(filePath, {
|
|
104
|
-
encoding: 'utf-8'
|
|
105
|
-
});
|
|
106
|
-
await ejsLoader.bind({
|
|
107
|
-
resourcePath: filePath,
|
|
108
|
-
async: () => (error, result) => {
|
|
109
|
-
if (error) throw error;else evaluatedContent = result;
|
|
110
|
-
}
|
|
111
|
-
})(content);
|
|
112
|
-
} else evaluatedContent = (await import('webOptimizerDefaultTemplateFilePath')).default;
|
|
113
|
-
render(evaluatedContent);
|
|
114
|
-
// endregion
|
|
115
|
-
})().catch(error => {
|
|
116
|
-
log.error(error);
|
|
117
|
-
});else {
|
|
80
|
+
browser.domContentLoaded = browser.windowLoaded = true;
|
|
81
|
+
});
|
|
82
|
+
for (const callback of onCreatedListener) void callback();
|
|
83
|
+
},
|
|
84
|
+
resources: 'usable',
|
|
85
|
+
runScripts: 'dangerously',
|
|
86
|
+
url: 'http://localhost',
|
|
87
|
+
virtualConsole
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
let evaluatedContent = '';
|
|
91
|
+
if (typeof NAME === 'undefined' || NAME === 'webOptimizer') {
|
|
92
|
+
const filePath = path.join(import.meta.dirname, 'index.html.ejs');
|
|
93
|
+
/*
|
|
94
|
+
NOTE: We load dependencies now to avoid having file imports
|
|
95
|
+
after test runner has finished to isolate the environment.
|
|
96
|
+
*/
|
|
97
|
+
const ejsLoader = (await import('./ejsLoader.js')).default;
|
|
98
|
+
const content = await (await import('fs')).promises.readFile(filePath, {
|
|
99
|
+
encoding: 'utf-8'
|
|
100
|
+
});
|
|
101
|
+
await ejsLoader.bind({
|
|
102
|
+
resourcePath: filePath,
|
|
103
|
+
async: () => (error, result) => {
|
|
104
|
+
if (error) throw error;else evaluatedContent = result;
|
|
105
|
+
}
|
|
106
|
+
})(content);
|
|
107
|
+
} else evaluatedContent = (await import('webOptimizerDefaultTemplateFilePath')).default;
|
|
108
|
+
render(evaluatedContent);
|
|
109
|
+
// endregion
|
|
110
|
+
} else {
|
|
118
111
|
browser.initialized = true;
|
|
119
112
|
browser.window = window;
|
|
120
113
|
window.document.addEventListener('DOMContentLoaded', () => {
|
package/configurator.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
import { convertCircularObjectToJSON, copy, evaluateAsyncDynamicData, evaluateDynamicData, extend, getUTCTimestamp, importFilesystemAPI,
|
|
19
|
+
import { convertCircularObjectToJSON, copy, evaluateAsyncDynamicData, evaluateDynamicData, extend, getUTCTimestamp, importFilesystemAPI, isFile, isObject, isPlainObject, Logger, MAXIMAL_NUMBER_OF_ITERATIONS, modifyObject, optionalImport, parseEncodedObject, removeKeyPrefixes, UTILITY_SCOPE } from 'clientnode';
|
|
20
20
|
import fileSystemSynchronous from 'fs';
|
|
21
21
|
import fileSystem, { lstat, readFile, unlink } from 'fs/promises';
|
|
22
22
|
import path, { basename, dirname, join, resolve } from 'path';
|
|
@@ -136,7 +136,7 @@ environment = eval('process.env')) => {
|
|
|
136
136
|
let filePath = null;
|
|
137
137
|
for (let iteration = 0; iteration < MAXIMAL_NUMBER_OF_ITERATIONS.value; iteration++) {
|
|
138
138
|
const newFilePath = `${configuration.path.context}.dynamicConfiguration-` + `${String(count)}.json`;
|
|
139
|
-
if (!
|
|
139
|
+
if (!(await isFile(newFilePath))) break;
|
|
140
140
|
filePath = newFilePath;
|
|
141
141
|
count += 1;
|
|
142
142
|
}
|
|
@@ -166,7 +166,7 @@ environment = eval('process.env')) => {
|
|
|
166
166
|
if (Object.prototype.hasOwnProperty.call(result, '__reference__')) {
|
|
167
167
|
const referenceNames = [].concat(result.__reference__);
|
|
168
168
|
delete result.__reference__;
|
|
169
|
-
for (const name of referenceNames) if (Object.prototype.hasOwnProperty.call(configuration, name)) extend(true, result, configuration[name]);else if (
|
|
169
|
+
for (const name of referenceNames) if (Object.prototype.hasOwnProperty.call(configuration, name)) extend(true, result, configuration[name]);else if (await isFile(name)) extend(true, result, JSON.parse(await readFile(name, configuration.encoding)));else log.warn(`Given dynamic referenced configuration "${name}"`, 'could not be resolved.');
|
|
170
170
|
}
|
|
171
171
|
extend(true, modifyObject(configuration, result), result);
|
|
172
172
|
}
|
package/ejsLoader.js
CHANGED
|
@@ -174,67 +174,63 @@ export const loader = async function (source) {
|
|
|
174
174
|
const templateInstance = new ejs.Template(template, options);
|
|
175
175
|
templateInstance.compile();
|
|
176
176
|
const compiledSourceCode = templateInstance.source;
|
|
177
|
-
result = `
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
result = `export default ${options.async ? 'async ' : ''}function(${options.localsName}) {
|
|
178
|
+
var escapeFn = function(value) {
|
|
179
|
+
return String(value)
|
|
180
|
+
.replace(
|
|
181
|
+
/[&<>"']/g,
|
|
182
|
+
function(char) {
|
|
183
|
+
return {
|
|
184
|
+
'&': '&',
|
|
185
|
+
'<': '<',
|
|
186
|
+
'>': '>',
|
|
187
|
+
'"': '"',
|
|
188
|
+
"'": "'"
|
|
189
|
+
}[char]
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
};
|
|
193
|
+
var include = function() {
|
|
194
|
+
throw new Error('Include not implemented.')
|
|
195
|
+
};
|
|
196
|
+
var rethrow = function rethrow(
|
|
197
|
+
err, str, flnm, lineno, esc
|
|
180
198
|
) {
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
curr == lineno ?
|
|
215
|
-
' >> ' :
|
|
216
|
-
' '
|
|
217
|
-
) +
|
|
218
|
-
curr +
|
|
219
|
-
'| ' +
|
|
220
|
-
line;
|
|
221
|
-
})
|
|
222
|
-
.join('\\n');
|
|
223
|
-
// Alter exception message
|
|
224
|
-
err.path = filename;
|
|
225
|
-
err.message =
|
|
226
|
-
(filename || 'ejs') +
|
|
227
|
-
':' +
|
|
228
|
-
lineno +
|
|
229
|
-
'\\n' +
|
|
230
|
-
context +
|
|
231
|
-
'\\n\\n' +
|
|
232
|
-
err.message;
|
|
233
|
-
throw err;
|
|
234
|
-
};
|
|
235
|
-
${compiledSourceCode}
|
|
199
|
+
var lines = str.split('\\n');
|
|
200
|
+
var start = Math.max(lineno - 3, 0);
|
|
201
|
+
var end = Math.min(
|
|
202
|
+
lines.length, lineno + 3
|
|
203
|
+
);
|
|
204
|
+
var filename = esc(flnm);
|
|
205
|
+
// Error context
|
|
206
|
+
var context = lines
|
|
207
|
+
.slice(start, end)
|
|
208
|
+
.map(function (line, i) {
|
|
209
|
+
var curr = i + start + 1;
|
|
210
|
+
return (
|
|
211
|
+
curr == lineno ?
|
|
212
|
+
' >> ' :
|
|
213
|
+
' '
|
|
214
|
+
) +
|
|
215
|
+
curr +
|
|
216
|
+
'| ' +
|
|
217
|
+
line;
|
|
218
|
+
})
|
|
219
|
+
.join('\\n');
|
|
220
|
+
// Alter exception message
|
|
221
|
+
err.path = filename;
|
|
222
|
+
err.message =
|
|
223
|
+
(filename || 'ejs') +
|
|
224
|
+
':' +
|
|
225
|
+
lineno +
|
|
226
|
+
'\\n' +
|
|
227
|
+
context +
|
|
228
|
+
'\\n\\n' +
|
|
229
|
+
err.message;
|
|
230
|
+
throw err;
|
|
236
231
|
};
|
|
237
|
-
|
|
232
|
+
${compiledSourceCode}
|
|
233
|
+
};`.trim();
|
|
238
234
|
} else result = ejs.compile(result, options);
|
|
239
235
|
}
|
|
240
236
|
} else {
|
|
@@ -252,7 +248,7 @@ export const loader = async function (source) {
|
|
|
252
248
|
minified: givenOptions.compress?.javaScript,
|
|
253
249
|
presets: [],
|
|
254
250
|
sourceMaps: false,
|
|
255
|
-
sourceType: '
|
|
251
|
+
sourceType: 'module'
|
|
256
252
|
}, (error, file) => {
|
|
257
253
|
if (error) reject(error);else resolve(file);
|
|
258
254
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.74",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"rimraf": "^6.1.3",
|
|
121
121
|
"script-loader": "^0.7.2",
|
|
122
122
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
123
|
-
"webpack": "^5.110.
|
|
123
|
+
"webpack": "^5.110.3",
|
|
124
124
|
"webpack-cli": "^7.2.3",
|
|
125
125
|
"webpack-sources": "^3.5.1"
|
|
126
126
|
},
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"@types/html-minifier": "^4.0.6",
|
|
135
135
|
"@types/html-minifier-terser": "^7.0.2",
|
|
136
136
|
"@types/imagemin": "^9.0.1",
|
|
137
|
-
"@types/node": "^26.4.
|
|
137
|
+
"@types/node": "^26.4.1",
|
|
138
138
|
"@types/postcss-import": "^14.0.3",
|
|
139
139
|
"@types/postcss-url": "^10.0.4",
|
|
140
140
|
"@types/webpack-env": "^1.18.8",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"cssnano": "^9.0.2",
|
|
145
145
|
"eslint": "^10.9.1",
|
|
146
146
|
"eslint-config-google": "^0.14.0",
|
|
147
|
-
"eslint-plugin-jsdoc": "^64.3.
|
|
147
|
+
"eslint-plugin-jsdoc": "^64.3.4",
|
|
148
148
|
"favicons": "^7.3.1",
|
|
149
149
|
"favicons-webpack-plugin": "^6.0.1",
|
|
150
150
|
"globals": "^17.12.0",
|