weboptimizer 4.0.73 → 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 +1 -1
- package/package.json +1 -1
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
|
@@ -248,7 +248,7 @@ export const loader = async function (source) {
|
|
|
248
248
|
minified: givenOptions.compress?.javaScript,
|
|
249
249
|
presets: [],
|
|
250
250
|
sourceMaps: false,
|
|
251
|
-
sourceType: '
|
|
251
|
+
sourceType: 'module'
|
|
252
252
|
}, (error, file) => {
|
|
253
253
|
if (error) reject(error);else resolve(file);
|
|
254
254
|
});
|