weboptimizer 3.0.29 → 4.0.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/configurator.js CHANGED
@@ -16,30 +16,19 @@
16
16
  endregion
17
17
  */
18
18
  // region imports
19
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
20
- var _typeof3 = require("@babel/runtime/helpers/typeof");
21
- Object.defineProperty(exports, "__esModule", {
22
- value: true
23
- });
24
- exports.log = exports.loadedConfiguration = exports.load = exports.get = exports["default"] = void 0;
25
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
26
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
27
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
28
- var _clientnode = require("clientnode");
29
- var _fs = _interopRequireWildcard(require("fs"));
30
- var _path2 = _interopRequireWildcard(require("path"));
31
- var _helper = require("./helper");
32
- var _package = _interopRequireWildcard(require("./package.json"));
33
- var _type4 = require("./type");
34
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
35
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
36
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
37
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
38
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
39
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
+ import "core-js/modules/es.iterator.constructor.js";
20
+ import "core-js/modules/es.iterator.filter.js";
21
+ import "core-js/modules/es.iterator.map.js";
22
+ import "core-js/modules/es.json.parse.js";
23
+ import { convertCircularObjectToJSON, copy, currentRequire, evaluateDynamicData, extend, getUTCTimestamp, isFileSync, isObject, isolatedRequire, isPlainObject, Logger, MAXIMAL_NUMBER_OF_ITERATIONS, Mapping, modifyObject, optionalRequire, parseEncodedObject, PlainObject, RecursiveEvaluateable, removeKeyPrefixes, UTILITY_SCOPE } from 'clientnode';
24
+ import fileSystem, { lstatSync, readFileSync, unlinkSync } from 'fs';
25
+ import path, { basename, dirname, join, resolve } from 'path';
26
+ import { determineAssetType, determineModuleFilePath, determineModuleLocations, resolveAutoInjection, resolveBuildConfigurationFilePaths, resolveModulesInFolders, normalizeGivenInjection, normalizePaths } from './helper';
27
+ import packageConfiguration, { configuration as metaConfiguration } from './package.json';
28
+ import { DefaultConfiguration, GivenInjection, GivenInjectionConfiguration, InjectionConfiguration, ResolvedBuildConfigurationItem, ResolvedConfiguration, RuntimeInformation, SubConfigurationTypes } from './type';
40
29
  // endregion
41
- var loadedConfiguration = exports.loadedConfiguration = null;
42
- var log = exports.log = new _clientnode.Logger({
30
+ export let loadedConfiguration = null;
31
+ export const log = new Logger({
43
32
  name: 'weboptimizer.configurator'
44
33
  });
45
34
  /**
@@ -52,332 +41,230 @@ var log = exports.log = new _clientnode.Logger({
52
41
  * @param environment - Environment variables to take into account.
53
42
  * @returns Nothing.
54
43
  */
55
- var load = exports.load = function load(context) {
56
- var currentWorkingDirectory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.cwd();
57
- var commandLineArguments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : process.argv;
58
- var webOptimizerPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : __dirname;
59
- var environment = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : eval('process.env');
60
- return function (_specificConfiguratio, _specificConfiguratio2) {
61
- // region determine application context location
62
- if (context) _package.configuration["default"].path.context = context;else {
63
- /*
64
- To assume to go two folder up from this file until there is no
65
- "node_modules" parent folder is usually resilient again dealing
66
- with projects where current working directory isn't the projects
67
- directory and this library is located as a nested dependency.
68
- */
69
- _package.configuration["default"].path.context = webOptimizerPath;
70
- for (var level = 0; level < _clientnode.MAXIMAL_NUMBER_OF_ITERATIONS.value; level++) {
71
- _package.configuration["default"].path.context = (0, _path2.resolve)(_package.configuration["default"].path.context, '../../');
72
- if ((0, _path2.basename)((0, _path2.dirname)(_package.configuration["default"].path.context)) !== 'node_modules') break;
73
- }
74
- if ((0, _path2.basename)((0, _path2.dirname)(currentWorkingDirectory)) === 'node_modules' || (0, _path2.basename)((0, _path2.dirname)(currentWorkingDirectory)) === '.staging' && (0, _path2.basename)((0, _path2.dirname)((0, _path2.dirname)(currentWorkingDirectory))) === 'node_modules') {
75
- /*
76
- NOTE: If we are dealing was a dependency project use current
77
- directory as context.
78
- */
79
- _package.configuration["default"].path.context = currentWorkingDirectory;
80
- _package.configuration["default"].contextType = 'dependency';
81
- } else
82
- /*
83
- NOTE: If the current working directory references this file via
84
- a linked "node_modules" folder using current working directory
85
- as context is a better assumption than two folders up the
86
- hierarchy.
87
- */
88
- try {
89
- if ((0, _fs.lstatSync)((0, _path2.join)(currentWorkingDirectory, 'node_modules')).isSymbolicLink()) _package.configuration["default"].path.context = currentWorkingDirectory;
90
- } catch (_unused) {
91
- // Continue regardless of error.
92
- }
93
- }
94
- // endregion
95
- // region load application specific configuration
96
- var specificConfiguration = {};
97
- try {
98
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
99
- specificConfiguration = (0, _clientnode.currentRequire)((0, _path2.join)(_package.configuration["default"].path.context, 'package'));
100
- } catch (_unused2) {
101
- _package.configuration["default"].path.context = currentWorkingDirectory;
102
- }
103
- // endregion
104
- // region determine application name and web optimizer configuration
105
- var name = typeof specificConfiguration.name === 'string' ? specificConfiguration.name : typeof ((_specificConfiguratio = specificConfiguration.webOptimizer) === null || _specificConfiguratio === void 0 ? void 0 : _specificConfiguratio.name) === 'string' ? (_specificConfiguratio2 = specificConfiguration.webOptimizer) === null || _specificConfiguratio2 === void 0 ? void 0 : _specificConfiguratio2.name : 'mockup';
106
- specificConfiguration = specificConfiguration.webOptimizer || {};
107
- specificConfiguration.name = name;
108
- // endregion
109
- // region determine debug mode
110
- // NOTE: Given node command line arguments results in "npm_config_*"
111
- // environment variables.
112
- var debug = _package.configuration["default"].debug;
113
- if (typeof specificConfiguration.debug === 'boolean') debug = specificConfiguration.debug;else if (environment.npm_config_dev === 'true' || typeof environment.NODE_ENV === 'string' && ['debug', 'dev', 'development'].includes(environment.NODE_ENV)) debug = true;
114
- if (debug) environment.NODE_ENV = 'development';
115
- // endregion
116
- // region loading default configuration
117
- _package.configuration["default"].path.context += '/';
118
- // Merges final default configuration object depending on given target
119
- // environment.
120
- var libraryConfiguration = _package.configuration.library;
121
- var configuration;
122
- if (debug) configuration = (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)(_package.configuration["default"], _package.configuration.debug), _package.configuration.debug);else configuration = _package.configuration["default"];
123
- configuration.debug = debug;
124
- if ((0, _typeof2["default"])(configuration.library) === 'object') (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)(libraryConfiguration, configuration.library), configuration.library);
125
- if (configuration.library && specificConfiguration.library !== false) configuration = (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)(configuration, libraryConfiguration), libraryConfiguration);
126
- // endregion
127
- // region merging and evaluating task specific and dynamic configurations
128
- /// region load additional dynamically given configuration
129
- var count = 0;
130
- var filePath = null;
131
- for (var iteration = 0; iteration < _clientnode.MAXIMAL_NUMBER_OF_ITERATIONS.value; iteration++) {
132
- var newFilePath = "".concat(configuration.path.context, ".dynamicConfiguration-") + "".concat(String(count), ".json");
133
- if (!(0, _clientnode.isFileSync)(newFilePath)) break;
134
- filePath = newFilePath;
135
- count += 1;
136
- }
137
- var runtimeInformation = {
138
- givenCommandLineArguments: commandLineArguments
139
- };
140
- if (filePath) {
141
- var fileContent = (0, _fs.readFileSync)(filePath, {
142
- encoding: configuration.encoding
143
- });
144
- runtimeInformation = JSON.parse(fileContent);
145
- (0, _fs.unlinkSync)(filePath);
146
- }
147
- //// region task specific configuration
148
- ///// region apply task type specific configuration
149
- if (runtimeInformation.givenCommandLineArguments.length > 2) {
150
- var _iterator = _createForOfIteratorHelper(_type4.SubConfigurationTypes),
151
- _step;
152
- try {
153
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
154
- var type = _step.value;
155
- if (runtimeInformation.givenCommandLineArguments[2] === type || debug && type === 'debug' || type === 'test' && runtimeInformation.givenCommandLineArguments[2].startsWith('test:') && runtimeInformation.givenCommandLineArguments[2] !== 'test:browser') for (var _i = 0, _arr = [configuration, specificConfiguration]; _i < _arr.length; _i++) {
156
- var configurationTarget = _arr[_i];
157
- if ((0, _clientnode.isPlainObject)(configurationTarget[type])) (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)(configurationTarget, configurationTarget[type]), configurationTarget[type]);
158
- }
159
- }
160
- } catch (err) {
161
- _iterator.e(err);
162
- } finally {
163
- _iterator.f();
164
- }
165
- }
166
- ///// endregion
167
- ///// region clear task type specific configurations
168
- var _iterator2 = _createForOfIteratorHelper(_type4.SubConfigurationTypes),
169
- _step2;
170
- try {
171
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
172
- var _type3 = _step2.value;
173
- for (var _i7 = 0, _arr2 = [configuration, specificConfiguration]; _i7 < _arr2.length; _i7++) {
174
- var _configurationTarget = _arr2[_i7];
175
- if (Object.prototype.hasOwnProperty.call(_configurationTarget, _type3) && (0, _typeof2["default"])(_configurationTarget[_type3]) === 'object') delete _configurationTarget[_type3];
176
- }
177
- }
178
- ///// endregion
179
- //// endregion
180
- /// endregion
181
- } catch (err) {
182
- _iterator2.e(err);
183
- } finally {
184
- _iterator2.f();
185
- }
186
- (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)((0, _clientnode.modifyObject)(configuration, specificConfiguration), runtimeInformation), specificConfiguration, runtimeInformation);
187
- var result = null;
188
- if (runtimeInformation.givenCommandLineArguments.length > 3) result = (0, _clientnode.parseEncodedObject)(runtimeInformation.givenCommandLineArguments[runtimeInformation.givenCommandLineArguments.length - 1], configuration, 'configuration');
189
- if ((0, _clientnode.isObject)(result)) {
190
- if (Object.prototype.hasOwnProperty.call(result, '__reference__')) {
191
- var referenceNames = [].concat(result.__reference__);
192
- delete result.__reference__;
193
- var _iterator3 = _createForOfIteratorHelper(referenceNames),
194
- _step3;
195
- try {
196
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
197
- var _name = _step3.value;
198
- if (Object.prototype.hasOwnProperty.call(configuration, _name)) (0, _clientnode.extend)(true, result, configuration[_name]);else if ((0, _clientnode.isFileSync)(_name)) (0, _clientnode.extend)(true, result, JSON.parse((0, _fs.readFileSync)(_name, configuration.encoding)));else log.warn("Given dynamic referenced configuration \"".concat(_name, "\""), 'could not be resolved.');
199
- }
200
- } catch (err) {
201
- _iterator3.e(err);
202
- } finally {
203
- _iterator3.f();
204
- }
205
- }
206
- (0, _clientnode.extend)(true, (0, _clientnode.modifyObject)(configuration, result), result);
207
- }
208
- // Removing comments (default key name to delete is "#").
209
- configuration = (0, _clientnode.removeKeyPrefixes)(configuration);
210
- // endregion
211
- /// region build absolute paths
212
- configuration.path.base = (0, _path2.resolve)(configuration.path.context, configuration.path.base);
213
- for (var _i2 = 0, _Object$entries = Object.entries(configuration.path); _i2 < _Object$entries.length; _i2++) {
214
- var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i2], 2),
215
- key = _Object$entries$_i[0],
216
- _path = _Object$entries$_i[1];
217
- if (!['base', 'configuration'].includes(key)) if (typeof _path === 'string') configuration.path[key] = (0, _path2.resolve)(configuration.path.base, _path) + '/';else if ((0, _clientnode.isPlainObject)(_path)) {
218
- if (Object.prototype.hasOwnProperty.call(_path, 'base')) configuration.path[key].base = (0, _path2.resolve)(configuration.path.base, _path.base);
219
- for (var _i3 = 0, _Object$entries2 = Object.entries(_path); _i3 < _Object$entries2.length; _i3++) {
220
- var _Object$entries2$_i = (0, _slicedToArray2["default"])(_Object$entries2[_i3], 2),
221
- subKey = _Object$entries2$_i[0],
222
- subPath = _Object$entries2$_i[1];
223
- if (!['base', 'public'].includes(subKey) && typeof subPath === 'string') _path[subKey] = (0, _path2.resolve)(_path.base, subPath) + '/';else if (subKey !== 'options' && (0, _clientnode.isPlainObject)(subPath)) {
224
- subPath.base = (0, _path2.resolve)(_path.base, subPath.base);
225
- for (var _i4 = 0, _Object$entries3 = Object.entries(subPath); _i4 < _Object$entries3.length; _i4++) {
226
- var _Object$entries3$_i = (0, _slicedToArray2["default"])(_Object$entries3[_i4], 2),
227
- subSubKey = _Object$entries3$_i[0],
228
- subSubPath = _Object$entries3$_i[1];
229
- if (subSubKey !== 'base' && typeof subSubPath === 'string') subPath[subSubKey] = (0, _path2.resolve)(subPath.base, subSubPath) + '/';
230
- }
231
- }
232
- }
233
- }
234
- }
235
- /// endregion
236
- // region evaluate dynamic configuration structures
237
- var now = new Date();
44
+ export const load = (context, currentWorkingDirectory = process.cwd(), commandLineArguments = process.argv, webOptimizerPath = __dirname,
45
+ /*
46
+ NOTE: We have to avoid that some pre-processor removes this
47
+ assignment.
48
+ */
49
+ // eslint-disable-next-lien no-eval
50
+ environment = eval('process.env')) => {
51
+ // region determine application context location
52
+ if (context) metaConfiguration.default.path.context = context;else {
238
53
  /*
239
- NOTE: The configuration is not yet fully resolved but will be
240
- transformed in place in the following lines of code.
54
+ To assume to go two folder up from this file until there is no
55
+ "node_modules" parent folder is usually resilient again dealing
56
+ with projects where current working directory isn't the projects
57
+ directory and this library is located as a nested dependency.
241
58
  */
242
- var resolvedConfiguration = (0, _clientnode.evaluateDynamicData)(configuration, _objectSpread(_objectSpread({}, _clientnode.UTILITY_SCOPE), {}, {
243
- currentPath: currentWorkingDirectory,
244
- fs: _fs["default"],
245
- packageConfiguration: _package["default"],
246
- optionalRequire: _clientnode.optionalRequire,
247
- path: _path2["default"],
248
- require: _clientnode.isolatedRequire,
249
- webOptimizerPath: webOptimizerPath,
250
- now: now,
251
- nowUTCTimestamp: (0, _clientnode.getUTCTimestamp)(now)
252
- }));
253
- // endregion
254
- // region consolidate file specific build configuration
255
- // Apply default file level build configurations to all file type specific
256
- // ones.
257
- var defaultConfiguration = resolvedConfiguration.buildContext.types["default"];
258
- delete resolvedConfiguration.buildContext.types["default"];
259
- for (var _i5 = 0, _Object$entries4 = Object.entries(resolvedConfiguration.buildContext.types); _i5 < _Object$entries4.length; _i5++) {
260
- var _Object$entries4$_i = (0, _slicedToArray2["default"])(_Object$entries4[_i5], 2),
261
- _type = _Object$entries4$_i[0],
262
- _context = _Object$entries4$_i[1];
263
- resolvedConfiguration.buildContext.types[_type] = (0, _clientnode.extend)(true, (0, _clientnode.copy)(defaultConfiguration), (0, _clientnode.extend)(true, {
264
- extension: _type
265
- }, _context, {
266
- type: _type
267
- }));
59
+ metaConfiguration.default.path.context = webOptimizerPath;
60
+ for (let level = 0; level < MAXIMAL_NUMBER_OF_ITERATIONS.value; level++) {
61
+ metaConfiguration.default.path.context = resolve(metaConfiguration.default.path.context, '../../');
62
+ if (basename(dirname(metaConfiguration.default.path.context)) !== 'node_modules') break;
268
63
  }
269
- // endregion
270
- // region resolve module location and which asset types are needed
271
- resolvedConfiguration.module.locations = (0, _helper.determineModuleLocations)(resolvedConfiguration.injection.entry.normalized, resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, {
272
- file: resolvedConfiguration.extensions.file.internal
273
- }, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base);
274
- resolvedConfiguration.injection = (0, _helper.resolveAutoInjection)(resolvedConfiguration.injection, (0, _helper.resolveBuildConfigurationFilePaths)(resolvedConfiguration.buildContext.types, resolvedConfiguration.path.source.asset.base, (0, _helper.normalizePaths)(resolvedConfiguration.path.ignore.concat(resolvedConfiguration.module.directoryNames, resolvedConfiguration.loader.directoryNames).map(function (filePath) {
275
- return (0, _path2.resolve)(resolvedConfiguration.path.context, filePath);
276
- }).filter(function (filePath) {
277
- return !resolvedConfiguration.path.context.startsWith(filePath);
278
- })), resolvedConfiguration["package"].main.fileNames), resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, resolvedConfiguration.extensions, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base, resolvedConfiguration.path.ignore);
279
- var givenInjection = resolvedConfiguration.injection.entry;
280
- resolvedConfiguration.injection.entry = {
281
- given: givenInjection,
282
- normalized: (0, _helper.resolveModulesInFolders)((0, _helper.normalizeGivenInjection)(givenInjection), resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base, resolvedConfiguration.path.ignore.concat(resolvedConfiguration.module.directoryNames, resolvedConfiguration.loader.directoryNames).map(function (filePath) {
283
- return (0, _path2.resolve)(resolvedConfiguration.path.context, filePath);
284
- }).filter(function (filePath) {
285
- return !resolvedConfiguration.path.context.startsWith(filePath);
286
- }))
287
- };
288
- resolvedConfiguration.needed = {
289
- javaScript: configuration.debug && ['serve', 'test:browser'].includes(resolvedConfiguration.givenCommandLineArguments[2])
290
- };
291
-
292
- /// region determine which asset types are needed
293
- for (var _i6 = 0, _Object$values = Object.values(resolvedConfiguration.injection.entry.normalized); _i6 < _Object$values.length; _i6++) {
294
- var chunk = _Object$values[_i6];
295
- var _iterator4 = _createForOfIteratorHelper(chunk),
296
- _step4;
64
+ if (basename(dirname(currentWorkingDirectory)) === 'node_modules' || basename(dirname(currentWorkingDirectory)) === '.staging' && basename(dirname(dirname(currentWorkingDirectory))) === 'node_modules') {
65
+ /*
66
+ NOTE: If we are dealing was a dependency project use current
67
+ directory as context.
68
+ */
69
+ metaConfiguration.default.path.context = currentWorkingDirectory;
70
+ metaConfiguration.default.contextType = 'dependency';
71
+ } else
72
+ /*
73
+ NOTE: If the current working directory references this file via
74
+ a linked "node_modules" folder using current working directory
75
+ as context is a better assumption than two folders up the
76
+ hierarchy.
77
+ */
297
78
  try {
298
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
299
- var moduleID = _step4.value;
300
- var _filePath = (0, _helper.determineModuleFilePath)(moduleID, resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, {
301
- file: resolvedConfiguration.extensions.file.internal
302
- }, resolvedConfiguration.path.context,
303
- /*
304
- NOTE: We doesn't use
305
- "resolvedConfiguration.path.source.asset.base" because we
306
- already have resolved all module ids.
307
- */
308
- '', resolvedConfiguration.path.ignore, resolvedConfiguration.module.directoryNames, resolvedConfiguration["package"].main.fileNames, resolvedConfiguration["package"].main.propertyNames, resolvedConfiguration["package"].aliasPropertyNames, resolvedConfiguration.encoding);
309
- var _type2 = void 0;
310
- if (_filePath) _type2 = (0, _helper.determineAssetType)(_filePath, resolvedConfiguration.buildContext.types, resolvedConfiguration.path);else throw new Error("Given request \"".concat(moduleID, "\" couldn't be resolved."));
311
- if (_type2) resolvedConfiguration.needed[_type2] = true;
312
- }
313
- } catch (err) {
314
- _iterator4.e(err);
315
- } finally {
316
- _iterator4.f();
79
+ if (lstatSync(join(currentWorkingDirectory, 'node_modules')).isSymbolicLink()) metaConfiguration.default.path.context = currentWorkingDirectory;
80
+ } catch {
81
+ // Continue regardless of error.
317
82
  }
83
+ }
84
+ // endregion
85
+ // region load application specific configuration
86
+ let specificConfiguration = {};
87
+ try {
88
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89
+ specificConfiguration = currentRequire(join(metaConfiguration.default.path.context, 'package'));
90
+ } catch {
91
+ metaConfiguration.default.path.context = currentWorkingDirectory;
92
+ }
93
+ // endregion
94
+ // region determine application name and web optimizer configuration
95
+ const name = typeof specificConfiguration.name === 'string' ? specificConfiguration.name : typeof specificConfiguration.webOptimizer?.name === 'string' ? specificConfiguration.webOptimizer?.name : 'mockup';
96
+ specificConfiguration = specificConfiguration.webOptimizer || {};
97
+ specificConfiguration.name = name;
98
+ // endregion
99
+ // region determine debug mode
100
+ // NOTE: Given node command line arguments results in "npm_config_*"
101
+ // environment variables.
102
+ let debug = metaConfiguration.default.debug;
103
+ if (typeof specificConfiguration.debug === 'boolean') debug = specificConfiguration.debug;else if (environment.npm_config_dev === 'true' || typeof environment.NODE_ENV === 'string' && ['debug', 'dev', 'development'].includes(environment.NODE_ENV)) debug = true;
104
+ if (debug) environment.NODE_ENV = 'development';
105
+ // endregion
106
+ // region loading default configuration
107
+ metaConfiguration.default.path.context += '/';
108
+ // Merges final default configuration object depending on given target
109
+ // environment.
110
+ const libraryConfiguration = metaConfiguration.library;
111
+ let configuration;
112
+ if (debug) configuration = extend(true, modifyObject(metaConfiguration.default, metaConfiguration.debug), metaConfiguration.debug);else configuration = metaConfiguration.default;
113
+ configuration.debug = debug;
114
+ if (typeof configuration.library === 'object') extend(true, modifyObject(libraryConfiguration, configuration.library), configuration.library);
115
+ if (configuration.library && specificConfiguration.library !== false) configuration = extend(true, modifyObject(configuration, libraryConfiguration), libraryConfiguration);
116
+ // endregion
117
+ // region merging and evaluating task specific and dynamic configurations
118
+ /// region load additional dynamically given configuration
119
+ let count = 0;
120
+ let filePath = null;
121
+ for (let iteration = 0; iteration < MAXIMAL_NUMBER_OF_ITERATIONS.value; iteration++) {
122
+ const newFilePath = `${configuration.path.context}.dynamicConfiguration-` + `${String(count)}.json`;
123
+ if (!isFileSync(newFilePath)) break;
124
+ filePath = newFilePath;
125
+ count += 1;
126
+ }
127
+ let runtimeInformation = {
128
+ givenCommandLineArguments: commandLineArguments
129
+ };
130
+ if (filePath) {
131
+ const fileContent = readFileSync(filePath, {
132
+ encoding: configuration.encoding
133
+ });
134
+ runtimeInformation = JSON.parse(fileContent);
135
+ unlinkSync(filePath);
136
+ }
137
+ //// region task specific configuration
138
+ ///// region apply task type specific configuration
139
+ if (runtimeInformation.givenCommandLineArguments.length > 2) for (const type of SubConfigurationTypes) if (runtimeInformation.givenCommandLineArguments[2] === type || debug && type === 'debug' || type === 'test' && runtimeInformation.givenCommandLineArguments[2].startsWith('test:') && runtimeInformation.givenCommandLineArguments[2] !== 'test:browser') for (const configurationTarget of [configuration, specificConfiguration]) if (isPlainObject(configurationTarget[type])) extend(true, modifyObject(configurationTarget, configurationTarget[type]), configurationTarget[type]);
140
+ ///// endregion
141
+ ///// region clear task type specific configurations
142
+ for (const type of SubConfigurationTypes) for (const configurationTarget of [configuration, specificConfiguration]) if (Object.prototype.hasOwnProperty.call(configurationTarget, type) && typeof configurationTarget[type] === 'object') delete configurationTarget[type];
143
+ ///// endregion
144
+ //// endregion
145
+ /// endregion
146
+ extend(true, modifyObject(modifyObject(configuration, specificConfiguration), runtimeInformation), specificConfiguration, runtimeInformation);
147
+ let result = null;
148
+ if (runtimeInformation.givenCommandLineArguments.length > 3) result = parseEncodedObject(runtimeInformation.givenCommandLineArguments[runtimeInformation.givenCommandLineArguments.length - 1], configuration, 'configuration');
149
+ if (isObject(result)) {
150
+ if (Object.prototype.hasOwnProperty.call(result, '__reference__')) {
151
+ const referenceNames = [].concat(result.__reference__);
152
+ delete result.__reference__;
153
+ for (const name of referenceNames) if (Object.prototype.hasOwnProperty.call(configuration, name)) extend(true, result, configuration[name]);else if (isFileSync(name)) extend(true, result, JSON.parse(readFileSync(name, configuration.encoding)));else log.warn(`Given dynamic referenced configuration "${name}"`, 'could not be resolved.');
318
154
  }
319
- /// endregion
320
- // endregion
321
- // region adding special aliases
322
- /*
323
- NOTE: This alias couldn't be set in the "package.json" file since this
324
- would result in an endless loop.
325
- */
326
- resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader = '';
327
- var _iterator5 = _createForOfIteratorHelper(Array.isArray(resolvedConfiguration.files.defaultHTML.template.use) ? resolvedConfiguration.files.defaultHTML.template.use : [resolvedConfiguration.files.defaultHTML.template.use]),
328
- _step5;
329
- try {
330
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
331
- var loader = _step5.value;
332
- if (resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader) resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += '!';
333
- resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += loader.loader;
334
- if (loader.options) resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += '?' + (0, _clientnode.convertCircularObjectToJSON)(loader.options);
335
- }
336
- } catch (err) {
337
- _iterator5.e(err);
338
- } finally {
339
- _iterator5.f();
155
+ extend(true, modifyObject(configuration, result), result);
156
+ }
157
+ // Removing comments (default key name to delete is "#").
158
+ configuration = removeKeyPrefixes(configuration);
159
+ // endregion
160
+ /// region build absolute paths
161
+ configuration.path.base = resolve(configuration.path.context, configuration.path.base);
162
+ for (const [key, path] of Object.entries(configuration.path)) if (!['base', 'configuration'].includes(key)) if (typeof path === 'string') configuration.path[key] = resolve(configuration.path.base, path) + '/';else if (isPlainObject(path)) {
163
+ if (Object.prototype.hasOwnProperty.call(path, 'base')) configuration.path[key].base = resolve(configuration.path.base, path.base);
164
+ for (const [subKey, subPath] of Object.entries(path)) if (!['base', 'public'].includes(subKey) && typeof subPath === 'string') path[subKey] = resolve(path.base, subPath) + '/';else if (subKey !== 'options' && isPlainObject(subPath)) {
165
+ subPath.base = resolve(path.base, subPath.base);
166
+ for (const [subSubKey, subSubPath] of Object.entries(subPath)) if (subSubKey !== 'base' && typeof subSubPath === 'string') subPath[subSubKey] = resolve(subPath.base, subSubPath) + '/';
340
167
  }
341
- resolvedConfiguration.module.aliases.webOptimizerDefaultTemplateFilePath = resolvedConfiguration.files.defaultHTML.template.filePath;
342
- // endregion
343
- // region apply html webpack plugin workarounds
168
+ }
169
+ /// endregion
170
+ // region evaluate dynamic configuration structures
171
+ const now = new Date();
172
+ /*
173
+ NOTE: The configuration is not yet fully resolved but will be
174
+ transformed in place in the following lines of code.
175
+ */
176
+ const resolvedConfiguration = evaluateDynamicData(configuration, {
177
+ ...UTILITY_SCOPE,
178
+ currentPath: currentWorkingDirectory,
179
+ fs: fileSystem,
180
+ packageConfiguration,
181
+ optionalRequire,
182
+ path,
183
+ require: isolatedRequire,
184
+ webOptimizerPath,
185
+ now,
186
+ nowUTCTimestamp: getUTCTimestamp(now)
187
+ });
188
+ // endregion
189
+ // region consolidate file specific build configuration
190
+ // Apply default file level build configurations to all file type specific
191
+ // ones.
192
+ const defaultConfiguration = resolvedConfiguration.buildContext.types.default;
193
+ delete resolvedConfiguration.buildContext.types.default;
194
+ for (const [type, context] of Object.entries(resolvedConfiguration.buildContext.types)) resolvedConfiguration.buildContext.types[type] = extend(true, copy(defaultConfiguration), extend(true, {
195
+ extension: type
196
+ }, context, {
197
+ type
198
+ }));
199
+ // endregion
200
+ // region resolve module location and which asset types are needed
201
+ resolvedConfiguration.module.locations = determineModuleLocations(resolvedConfiguration.injection.entry.normalized, resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, {
202
+ file: resolvedConfiguration.extensions.file.internal
203
+ }, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base);
204
+ resolvedConfiguration.injection = resolveAutoInjection(resolvedConfiguration.injection, resolveBuildConfigurationFilePaths(resolvedConfiguration.buildContext.types, resolvedConfiguration.path.source.asset.base, normalizePaths(resolvedConfiguration.path.ignore.concat(resolvedConfiguration.module.directoryNames, resolvedConfiguration.loader.directoryNames).map(filePath => resolve(resolvedConfiguration.path.context, filePath)).filter(filePath => !resolvedConfiguration.path.context.startsWith(filePath))), resolvedConfiguration.package.main.fileNames), resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, resolvedConfiguration.extensions, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base, resolvedConfiguration.path.ignore);
205
+ const givenInjection = resolvedConfiguration.injection.entry;
206
+ resolvedConfiguration.injection.entry = {
207
+ given: givenInjection,
208
+ normalized: resolveModulesInFolders(normalizeGivenInjection(givenInjection), resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, resolvedConfiguration.path.context, resolvedConfiguration.path.source.asset.base, resolvedConfiguration.path.ignore.concat(resolvedConfiguration.module.directoryNames, resolvedConfiguration.loader.directoryNames).map(filePath => resolve(resolvedConfiguration.path.context, filePath)).filter(filePath => !resolvedConfiguration.path.context.startsWith(filePath)))
209
+ };
210
+ resolvedConfiguration.needed = {
211
+ javaScript: configuration.debug && ['serve', 'test:browser'].includes(resolvedConfiguration.givenCommandLineArguments[2])
212
+ };
213
+
214
+ /// region determine which asset types are needed
215
+ for (const chunk of Object.values(resolvedConfiguration.injection.entry.normalized)) for (const moduleID of chunk) {
216
+ const filePath = determineModuleFilePath(moduleID, resolvedConfiguration.module.aliases, resolvedConfiguration.module.replacements.normal, {
217
+ file: resolvedConfiguration.extensions.file.internal
218
+ }, resolvedConfiguration.path.context,
344
219
  /*
345
- NOTE: Provides a workaround to handle a bug with chained loader
346
- configurations.
220
+ NOTE: We doesn't use
221
+ "resolvedConfiguration.path.source.asset.base" because we
222
+ already have resolved all module ids.
347
223
  */
348
- var _iterator6 = _createForOfIteratorHelper(resolvedConfiguration.files.html),
349
- _step6;
350
- try {
351
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
352
- var htmlConfiguration = _step6.value;
353
- (0, _clientnode.extend)(true, htmlConfiguration, resolvedConfiguration.files.defaultHTML);
354
- htmlConfiguration.template.request = htmlConfiguration.template.filePath;
355
- if (htmlConfiguration.template.filePath !== resolvedConfiguration.files.defaultHTML.template.filePath && htmlConfiguration.template.options) {
356
- var requestString = new String(htmlConfiguration.template.request + (0, _clientnode.convertCircularObjectToJSON)(htmlConfiguration.template.options));
357
- requestString.replace = function (value) {
358
- return function () {
359
- return value;
360
- };
361
- }(htmlConfiguration.template.filePath);
362
- htmlConfiguration.template.request = requestString;
363
- }
364
- }
365
- // endregion
366
- } catch (err) {
367
- _iterator6.e(err);
368
- } finally {
369
- _iterator6.f();
224
+ '', resolvedConfiguration.path.ignore, resolvedConfiguration.module.directoryNames, resolvedConfiguration.package.main.fileNames, resolvedConfiguration.package.main.propertyNames, resolvedConfiguration.package.aliasPropertyNames, resolvedConfiguration.encoding);
225
+ let type;
226
+ if (filePath) type = determineAssetType(filePath, resolvedConfiguration.buildContext.types, resolvedConfiguration.path);else throw new Error(`Given request "${moduleID}" couldn't be resolved.`);
227
+ if (type) resolvedConfiguration.needed[type] = true;
228
+ }
229
+ /// endregion
230
+ // endregion
231
+ // region adding special aliases
232
+ /*
233
+ NOTE: This alias couldn't be set in the "package.json" file since this
234
+ would result in an endless loop.
235
+ */
236
+ resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader = '';
237
+ for (const loader of Array.isArray(resolvedConfiguration.files.defaultHTML.template.use) ? resolvedConfiguration.files.defaultHTML.template.use : [resolvedConfiguration.files.defaultHTML.template.use]) {
238
+ if (resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader) resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += '!';
239
+ resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += loader.loader;
240
+ if (loader.options) resolvedConfiguration.loader.aliases.webOptimizerDefaultTemplateFileLoader += '?' + convertCircularObjectToJSON(loader.options);
241
+ }
242
+ resolvedConfiguration.module.aliases.webOptimizerDefaultTemplateFilePath = resolvedConfiguration.files.defaultHTML.template.filePath;
243
+ // endregion
244
+ // region apply html webpack plugin workarounds
245
+ /*
246
+ NOTE: Provides a workaround to handle a bug with chained loader
247
+ configurations.
248
+ */
249
+ for (const htmlConfiguration of resolvedConfiguration.files.html) {
250
+ extend(true, htmlConfiguration, resolvedConfiguration.files.defaultHTML);
251
+ htmlConfiguration.template.request = htmlConfiguration.template.filePath;
252
+ if (htmlConfiguration.template.filePath !== resolvedConfiguration.files.defaultHTML.template.filePath && htmlConfiguration.template.options) {
253
+ const requestString = new String(htmlConfiguration.template.request + convertCircularObjectToJSON(htmlConfiguration.template.options));
254
+ requestString.replace = (value => () => value)(htmlConfiguration.template.filePath);
255
+ htmlConfiguration.template.request = requestString;
370
256
  }
371
- return resolvedConfiguration;
372
- }();
257
+ }
258
+ // endregion
259
+ return resolvedConfiguration;
373
260
  };
374
261
  /**
375
262
  * Get cached or determined configuration object.
376
263
  * @returns Nothing.
377
264
  */
378
- var get = exports.get = function get() {
265
+ export const get = () => {
379
266
  if (loadedConfiguration) return loadedConfiguration;
380
- exports.loadedConfiguration = loadedConfiguration = load();
267
+ loadedConfiguration = load();
381
268
  return loadedConfiguration;
382
269
  };
383
- var _default = exports["default"] = get;
270
+ export default get;