weboptimizer 3.0.28 → 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/browser.js +93 -205
- package/configurator.js +222 -335
- package/ejsLoader.js +212 -170
- package/eslint.config.mjs +4 -0
- package/helper.js +230 -540
- package/index.js +245 -574
- package/jestSetup.js +7 -5
- package/package.json +31 -35
- package/plugins/HTMLTransformation.js +68 -109
- package/plugins/InPlaceAssetsIntoHTML.js +66 -69
- package/stylelintConfigurator.js +4 -8
- package/type.js +15 -6
- package/webpackConfigurator.js +389 -600
package/helper.js
CHANGED
|
@@ -16,26 +16,26 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
import "core-js/modules/es.array.push.js";
|
|
20
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
21
|
+
import "core-js/modules/es.iterator.map.js";
|
|
22
|
+
import "core-js/modules/es.json.parse.js";
|
|
23
|
+
import "core-js/modules/es.set.difference.v2.js";
|
|
24
|
+
import "core-js/modules/es.set.intersection.v2.js";
|
|
25
|
+
import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
26
|
+
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
27
|
+
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
28
|
+
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
29
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
30
|
+
import { copy, currentRequire, Encoding, escapeRegularExpressions, extend, File, isAnyMatching, isDirectorySync, isFileSync, isPlainObject, Logger, Mapping, PlainObject, represent, walkDirectoryRecursivelySync } from 'clientnode';
|
|
31
|
+
import { existsSync, readFileSync } from 'fs';
|
|
32
|
+
import { basename, dirname, extname, join, normalize, resolve, sep, relative } from 'path';
|
|
33
|
+
import { BuildConfiguration, Extensions, GivenInjection, GivenInjectionConfiguration, NormalizedGivenInjection, PathConfiguration, PackageConfiguration, PackageDescriptor, Replacements, ResolvedBuildConfiguration, ResolvedBuildConfigurationItem, SpecificExtensions } from './type';
|
|
34
34
|
// endregion
|
|
35
35
|
// region constants
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
name: 'weboptimizer
|
|
36
|
+
export const KNOWN_FILE_EXTENSIONS = ['js', 'ts', 'json', 'css', 'eot', 'gif', 'html', 'ico', 'jpg', 'png', 'ejs', 'svg', 'ttf', 'woff', '.woff2'];
|
|
37
|
+
export const log = new Logger({
|
|
38
|
+
name: 'weboptimizer.helper'
|
|
39
39
|
});
|
|
40
40
|
// endregion
|
|
41
41
|
// region functions
|
|
@@ -47,19 +47,8 @@ var log = exports.log = new _clientnode.Logger({
|
|
|
47
47
|
* @returns Value "true" if given file path is within one of given locations or
|
|
48
48
|
* "false" otherwise.
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
_step;
|
|
53
|
-
try {
|
|
54
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
55
|
-
var pathToCheck = _step.value;
|
|
56
|
-
if ((0, _path.resolve)(filePath).startsWith((0, _path.resolve)(pathToCheck))) return true;
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
_iterator.e(err);
|
|
60
|
-
} finally {
|
|
61
|
-
_iterator.f();
|
|
62
|
-
}
|
|
50
|
+
export const isFilePathInLocation = (filePath, locationsToCheck) => {
|
|
51
|
+
for (const pathToCheck of locationsToCheck) if (resolve(filePath).startsWith(resolve(pathToCheck))) return true;
|
|
63
52
|
return false;
|
|
64
53
|
};
|
|
65
54
|
// endregion
|
|
@@ -70,8 +59,8 @@ var isFilePathInLocation = exports.isFilePathInLocation = function isFilePathInL
|
|
|
70
59
|
* @param moduleID - Module request to strip.
|
|
71
60
|
* @returns Given module id stripped.
|
|
72
61
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
export const stripLoader = moduleID => {
|
|
63
|
+
const moduleIDWithoutLoader = moduleID.substring(moduleID.lastIndexOf('!') + 1).replace(/\.webpack\[.+\/.+\]$/, '');
|
|
75
64
|
return moduleIDWithoutLoader.includes('?') ? moduleIDWithoutLoader.substring(0, moduleIDWithoutLoader.indexOf('?')) : moduleIDWithoutLoader;
|
|
76
65
|
};
|
|
77
66
|
// endregion
|
|
@@ -81,13 +70,11 @@ var stripLoader = exports.stripLoader = function stripLoader(moduleID) {
|
|
|
81
70
|
* @param paths - File paths.
|
|
82
71
|
* @returns The given file path list with normalized unique values.
|
|
83
72
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})));
|
|
90
|
-
};
|
|
73
|
+
export const normalizePaths = paths => Array.from(new Set(paths.map(givenPath => {
|
|
74
|
+
givenPath = normalize(givenPath);
|
|
75
|
+
if (givenPath.endsWith('/')) return givenPath.substring(0, givenPath.length - 1);
|
|
76
|
+
return givenPath;
|
|
77
|
+
})));
|
|
91
78
|
// endregion
|
|
92
79
|
// region file handler
|
|
93
80
|
/**
|
|
@@ -97,22 +84,17 @@ var normalizePaths = exports.normalizePaths = function normalizePaths(paths) {
|
|
|
97
84
|
* @param scope - Scope to use for processing.
|
|
98
85
|
* @returns Processed file path.
|
|
99
86
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
scope = _objectSpread({
|
|
87
|
+
export const renderFilePathTemplate = (template, scope = {}) => {
|
|
88
|
+
scope = {
|
|
103
89
|
'[chunkhash]': '.__dummy__',
|
|
104
90
|
'[contenthash]': '.__dummy__',
|
|
105
91
|
'[fullhash]': '.__dummy__',
|
|
106
92
|
'[id]': '.__dummy__',
|
|
107
|
-
'[name]': '.__dummy__'
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
placeholderName = _Object$entries$_i[0],
|
|
113
|
-
value = _Object$entries$_i[1];
|
|
114
|
-
filePath = filePath.replace(new RegExp((0, _clientnode.escapeRegularExpressions)(placeholderName), 'g'), String(value));
|
|
115
|
-
}
|
|
93
|
+
'[name]': '.__dummy__',
|
|
94
|
+
...scope
|
|
95
|
+
};
|
|
96
|
+
let filePath = template;
|
|
97
|
+
for (const [placeholderName, value] of Object.entries(scope)) filePath = filePath.replace(new RegExp(escapeRegularExpressions(placeholderName), 'g'), String(value));
|
|
116
98
|
return filePath;
|
|
117
99
|
};
|
|
118
100
|
/**
|
|
@@ -126,31 +108,17 @@ var renderFilePathTemplate = exports.renderFilePathTemplate = function renderFil
|
|
|
126
108
|
* for modules in.
|
|
127
109
|
* @returns A new resolved request.
|
|
128
110
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
_step2;
|
|
140
|
-
try {
|
|
141
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
142
|
-
var modulePath = _step2.value;
|
|
143
|
-
var pathPrefix = (0, _path.resolve)(referencePath, modulePath);
|
|
144
|
-
if (request.startsWith(pathPrefix)) {
|
|
145
|
-
request = request.substring(pathPrefix.length);
|
|
146
|
-
if (request.startsWith('/')) request = request.substring(1);
|
|
147
|
-
return applyModuleReplacements(applyAliases(request.substring(request.lastIndexOf('!') + 1), aliases), moduleReplacements);
|
|
148
|
-
}
|
|
111
|
+
export const applyContext = (request, context = './', referencePath = './', aliases = {}, moduleReplacements = {}, relativeModuleLocations = ['node_modules']) => {
|
|
112
|
+
referencePath = resolve(referencePath);
|
|
113
|
+
if (request.startsWith('./') && resolve(context) !== referencePath) {
|
|
114
|
+
request = resolve(context, request);
|
|
115
|
+
for (const modulePath of relativeModuleLocations) {
|
|
116
|
+
const pathPrefix = resolve(referencePath, modulePath);
|
|
117
|
+
if (request.startsWith(pathPrefix)) {
|
|
118
|
+
request = request.substring(pathPrefix.length);
|
|
119
|
+
if (request.startsWith('/')) request = request.substring(1);
|
|
120
|
+
return applyModuleReplacements(applyAliases(request.substring(request.lastIndexOf('!') + 1), aliases), moduleReplacements);
|
|
149
121
|
}
|
|
150
|
-
} catch (err) {
|
|
151
|
-
_iterator2.e(err);
|
|
152
|
-
} finally {
|
|
153
|
-
_iterator2.f();
|
|
154
122
|
}
|
|
155
123
|
if (request.startsWith(referencePath)) {
|
|
156
124
|
request = request.substring(referencePath.length);
|
|
@@ -196,82 +164,37 @@ var applyContext = exports.applyContext = function applyContext(request) {
|
|
|
196
164
|
* @returns A new resolved request indicating whether given request is an
|
|
197
165
|
* external one.
|
|
198
166
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
external: ['.compiled.js', '.js', '.json'],
|
|
209
|
-
internal: KNOWN_FILE_EXTENSIONS.map(function (suffix) {
|
|
210
|
-
return ".".concat(suffix);
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
var referencePath = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : './';
|
|
215
|
-
var pathsToIgnore = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : ['.git'];
|
|
216
|
-
var relativeModuleLocations = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : ['node_modules'];
|
|
217
|
-
var packageEntryFileNames = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : ['index', 'main'];
|
|
218
|
-
var packageMainPropertyNames = arguments.length > 12 && arguments[12] !== undefined ? arguments[12] : ['main', 'module'];
|
|
219
|
-
var packageAliasPropertyNames = arguments.length > 13 && arguments[13] !== undefined ? arguments[13] : [];
|
|
220
|
-
var includePattern = arguments.length > 14 && arguments[14] !== undefined ? arguments[14] : [];
|
|
221
|
-
var excludePattern = arguments.length > 15 && arguments[15] !== undefined ? arguments[15] : [];
|
|
222
|
-
var inPlaceNormalLibrary = arguments.length > 16 && arguments[16] !== undefined ? arguments[16] : false;
|
|
223
|
-
var inPlaceDynamicLibrary = arguments.length > 17 && arguments[17] !== undefined ? arguments[17] : true;
|
|
224
|
-
var encoding = arguments.length > 18 && arguments[18] !== undefined ? arguments[18] : 'utf-8';
|
|
225
|
-
context = (0, _path.resolve)(context);
|
|
226
|
-
requestContext = (0, _path.resolve)(requestContext);
|
|
227
|
-
referencePath = (0, _path.resolve)(referencePath);
|
|
167
|
+
export const determineExternalRequest = (request, context = './', requestContext = './', normalizedGivenInjection = {}, relativeExternalModuleLocations = ['node_modules'], aliases = {}, moduleReplacements = {}, extensions = {
|
|
168
|
+
file: {
|
|
169
|
+
external: ['.compiled.js', '.js', '.json'],
|
|
170
|
+
internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
171
|
+
}
|
|
172
|
+
}, referencePath = './', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], includePattern = [], excludePattern = [], inPlaceNormalLibrary = false, inPlaceDynamicLibrary = true, encoding = 'utf-8') => {
|
|
173
|
+
context = resolve(context);
|
|
174
|
+
requestContext = resolve(requestContext);
|
|
175
|
+
referencePath = resolve(referencePath);
|
|
228
176
|
// NOTE: We apply alias on externals additionally.
|
|
229
|
-
|
|
230
|
-
if (resolvedRequest === false ||
|
|
177
|
+
const resolvedRequest = applyModuleReplacements(applyAliases(request.substring(request.lastIndexOf('!') + 1), aliases), moduleReplacements);
|
|
178
|
+
if (resolvedRequest === false || isAnyMatching(resolvedRequest, excludePattern)) return null;
|
|
231
179
|
/*
|
|
232
180
|
NOTE: Aliases and module replacements doesn't have to be forwarded
|
|
233
181
|
since we pass an already resolved request.
|
|
234
182
|
*/
|
|
235
|
-
|
|
183
|
+
const filePath = determineModuleFilePath(resolvedRequest, {}, {}, {
|
|
236
184
|
file: extensions.file.external.concat(extensions.file.internal)
|
|
237
185
|
}, context, requestContext, pathsToIgnore, relativeModuleLocations, packageEntryFileNames, packageMainPropertyNames, packageAliasPropertyNames, encoding);
|
|
238
186
|
/*
|
|
239
187
|
NOTE: We mark dependencies as external if there file couldn't be
|
|
240
188
|
resolved or are specified to be external explicitly.
|
|
241
189
|
*/
|
|
242
|
-
if (!(filePath || inPlaceNormalLibrary) ||
|
|
243
|
-
for (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
249
|
-
var moduleID = _step3.value;
|
|
250
|
-
if (determineModuleFilePath(moduleID, aliases, moduleReplacements, {
|
|
251
|
-
file: extensions.file.internal
|
|
252
|
-
}, context, requestContext, pathsToIgnore, relativeModuleLocations, packageEntryFileNames, packageMainPropertyNames, packageAliasPropertyNames, encoding) === filePath) return null;
|
|
253
|
-
}
|
|
254
|
-
} catch (err) {
|
|
255
|
-
_iterator3.e(err);
|
|
256
|
-
} finally {
|
|
257
|
-
_iterator3.f();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
var parts = context.split('/');
|
|
261
|
-
var externalModuleLocations = [];
|
|
190
|
+
if (!(filePath || inPlaceNormalLibrary) || isAnyMatching(resolvedRequest, includePattern)) return applyContext(resolvedRequest, requestContext, referencePath, aliases, moduleReplacements, relativeModuleLocations) || null;
|
|
191
|
+
for (const chunk of Object.values(normalizedGivenInjection)) for (const moduleID of chunk) if (determineModuleFilePath(moduleID, aliases, moduleReplacements, {
|
|
192
|
+
file: extensions.file.internal
|
|
193
|
+
}, context, requestContext, pathsToIgnore, relativeModuleLocations, packageEntryFileNames, packageMainPropertyNames, packageAliasPropertyNames, encoding) === filePath) return null;
|
|
194
|
+
const parts = context.split('/');
|
|
195
|
+
const externalModuleLocations = [];
|
|
262
196
|
while (parts.length > 0) {
|
|
263
|
-
|
|
264
|
-
_step4;
|
|
265
|
-
try {
|
|
266
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
267
|
-
var relativePath = _step4.value;
|
|
268
|
-
externalModuleLocations.push((0, _path.join)('/', parts.join('/'), relativePath));
|
|
269
|
-
}
|
|
270
|
-
} catch (err) {
|
|
271
|
-
_iterator4.e(err);
|
|
272
|
-
} finally {
|
|
273
|
-
_iterator4.f();
|
|
274
|
-
}
|
|
197
|
+
for (const relativePath of relativeExternalModuleLocations) externalModuleLocations.push(join('/', parts.join('/'), relativePath));
|
|
275
198
|
parts.splice(-1, 1);
|
|
276
199
|
}
|
|
277
200
|
/*
|
|
@@ -279,7 +202,7 @@ var determineExternalRequest = exports.determineExternalRequest = function deter
|
|
|
279
202
|
in their request and aren't part of the current main package or have a
|
|
280
203
|
file extension other than javaScript aware.
|
|
281
204
|
*/
|
|
282
|
-
if (!inPlaceNormalLibrary && (extensions.file.external.length === 0 || filePath && extensions.file.external.includes(
|
|
205
|
+
if (!inPlaceNormalLibrary && (extensions.file.external.length === 0 || filePath && extensions.file.external.includes(extname(filePath)) || !filePath && extensions.file.external.includes('')) && !(inPlaceDynamicLibrary && request.includes('!')) && (!filePath && inPlaceDynamicLibrary || filePath && (!filePath.startsWith(context) || isFilePathInLocation(filePath, externalModuleLocations)))) return applyContext(resolvedRequest, requestContext, referencePath, aliases, moduleReplacements, relativeModuleLocations) || null;
|
|
283
206
|
return null;
|
|
284
207
|
};
|
|
285
208
|
/**
|
|
@@ -291,21 +214,13 @@ var determineExternalRequest = exports.determineExternalRequest = function deter
|
|
|
291
214
|
* @returns Determined file type or "null" of given file couldn't be
|
|
292
215
|
* determined.
|
|
293
216
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
for (
|
|
217
|
+
export const determineAssetType = (filePath, buildConfiguration, paths) => {
|
|
218
|
+
let result = null;
|
|
219
|
+
for (const type in buildConfiguration) if (extname(filePath) === `.${buildConfiguration[type].extension}`) {
|
|
297
220
|
result = type;
|
|
298
221
|
break;
|
|
299
222
|
}
|
|
300
|
-
if (!result) for (
|
|
301
|
-
var _type = _arr[_i3];
|
|
302
|
-
for (var _i4 = 0, _Object$entries2 = Object.entries(_type.asset); _i4 < _Object$entries2.length; _i4++) {
|
|
303
|
-
var _Object$entries2$_i = (0, _slicedToArray2["default"])(_Object$entries2[_i4], 2),
|
|
304
|
-
assetType = _Object$entries2$_i[0],
|
|
305
|
-
assetConfiguration = _Object$entries2$_i[1];
|
|
306
|
-
if (assetType !== 'base' && assetConfiguration && filePath.startsWith(assetConfiguration)) return assetType;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
223
|
+
if (!result) for (const type of [paths.source, paths.target]) for (const [assetType, assetConfiguration] of Object.entries(type.asset)) if (assetType !== 'base' && assetConfiguration && filePath.startsWith(assetConfiguration)) return assetType;
|
|
309
224
|
return result;
|
|
310
225
|
};
|
|
311
226
|
/**
|
|
@@ -319,40 +234,24 @@ var determineAssetType = exports.determineAssetType = function determineAssetTyp
|
|
|
319
234
|
* @param mainFileBasenames - File basenames to sort into the front.
|
|
320
235
|
* @returns Converted build configuration.
|
|
321
236
|
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
var buildConfiguration = [];
|
|
327
|
-
for (var _i5 = 0, _Object$values2 = Object.values(configuration); _i5 < _Object$values2.length; _i5++) {
|
|
328
|
-
var value = _Object$values2[_i5];
|
|
329
|
-
var newItem = (0, _clientnode.extend)(true, {
|
|
237
|
+
export const resolveBuildConfigurationFilePaths = (configuration, entryPath = './', pathsToIgnore = ['.git'], mainFileBasenames = ['index', 'main']) => {
|
|
238
|
+
const buildConfiguration = [];
|
|
239
|
+
for (const value of Object.values(configuration)) {
|
|
240
|
+
const newItem = extend(true, {
|
|
330
241
|
filePaths: []
|
|
331
242
|
}, value);
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
var file = _step5.value;
|
|
340
|
-
if ((_file$stats = file.stats) !== null && _file$stats !== void 0 && _file$stats.isFile() && file.path.endsWith(".".concat(newItem.extension)) && !(newItem.ignoredExtension && file.path.endsWith(".".concat(newItem.ignoredExtension))) && !new RegExp(newItem.filePathPattern).test(file.path)) newItem.filePaths.push(file.path);
|
|
341
|
-
}
|
|
342
|
-
} catch (err) {
|
|
343
|
-
_iterator5.e(err);
|
|
344
|
-
} finally {
|
|
345
|
-
_iterator5.f();
|
|
346
|
-
}
|
|
347
|
-
newItem.filePaths.sort(function (firstFilePath, secondFilePath) {
|
|
348
|
-
if (mainFileBasenames.includes((0, _path.basename)(firstFilePath, (0, _path.extname)(firstFilePath)))) {
|
|
349
|
-
if (mainFileBasenames.includes((0, _path.basename)(secondFilePath, (0, _path.extname)(secondFilePath)))) return 0;
|
|
350
|
-
} else if (mainFileBasenames.includes((0, _path.basename)(secondFilePath, (0, _path.extname)(secondFilePath)))) return 1;
|
|
243
|
+
for (const file of walkDirectoryRecursivelySync(entryPath, file => {
|
|
244
|
+
if (isFilePathInLocation(file.path, pathsToIgnore)) return false;
|
|
245
|
+
})) if (file.stats?.isFile() && file.path.endsWith(`.${newItem.extension}`) && !(newItem.ignoredExtension && file.path.endsWith(`.${newItem.ignoredExtension}`)) && !new RegExp(newItem.filePathPattern).test(file.path)) newItem.filePaths.push(file.path);
|
|
246
|
+
newItem.filePaths.sort((firstFilePath, secondFilePath) => {
|
|
247
|
+
if (mainFileBasenames.includes(basename(firstFilePath, extname(firstFilePath)))) {
|
|
248
|
+
if (mainFileBasenames.includes(basename(secondFilePath, extname(secondFilePath)))) return 0;
|
|
249
|
+
} else if (mainFileBasenames.includes(basename(secondFilePath, extname(secondFilePath)))) return 1;
|
|
351
250
|
return 0;
|
|
352
251
|
});
|
|
353
252
|
buildConfiguration.push(newItem);
|
|
354
253
|
}
|
|
355
|
-
return buildConfiguration.sort(
|
|
254
|
+
return buildConfiguration.sort((first, second) => {
|
|
356
255
|
if (first.outputExtension !== second.outputExtension) {
|
|
357
256
|
if (first.outputExtension === 'js') return -1;
|
|
358
257
|
if (second.outputExtension === 'js') return 1;
|
|
@@ -385,48 +284,23 @@ var resolveBuildConfigurationFilePaths = exports.resolveBuildConfigurationFilePa
|
|
|
385
284
|
* @returns Object with a file path and directory path key mapping to
|
|
386
285
|
* corresponding list of paths.
|
|
387
286
|
*/
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var packageEntryFileNames = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : ['__package__', '', 'index', 'main'];
|
|
401
|
-
var packageMainPropertyNames = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : ['main', 'module'];
|
|
402
|
-
var packageAliasPropertyNames = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : [];
|
|
403
|
-
var encoding = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : 'utf-8';
|
|
404
|
-
var filePaths = [];
|
|
405
|
-
var directoryPaths = [];
|
|
406
|
-
var normalizedGivenInjection = resolveModulesInFolders(normalizeGivenInjection(givenInjection), aliases, moduleReplacements, context, referencePath, pathsToIgnore);
|
|
407
|
-
for (var _i6 = 0, _Object$values3 = Object.values(normalizedGivenInjection); _i6 < _Object$values3.length; _i6++) {
|
|
408
|
-
var chunk = _Object$values3[_i6];
|
|
409
|
-
var _iterator6 = _createForOfIteratorHelper(chunk),
|
|
410
|
-
_step6;
|
|
411
|
-
try {
|
|
412
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
413
|
-
var moduleID = _step6.value;
|
|
414
|
-
var filePath = determineModuleFilePath(moduleID, aliases, moduleReplacements, extensions, context, referencePath, pathsToIgnore, relativeModuleLocations, packageEntryFileNames, packageMainPropertyNames, packageAliasPropertyNames, encoding);
|
|
415
|
-
if (filePath) {
|
|
416
|
-
filePaths.push(filePath);
|
|
417
|
-
var directoryPath = (0, _path.dirname)(filePath);
|
|
418
|
-
if (!directoryPaths.includes(directoryPath)) directoryPaths.push(directoryPath);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
} catch (err) {
|
|
422
|
-
_iterator6.e(err);
|
|
423
|
-
} finally {
|
|
424
|
-
_iterator6.f();
|
|
287
|
+
export const determineModuleLocations = (givenInjection, aliases = {}, moduleReplacements = {}, extensions = {
|
|
288
|
+
file: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
289
|
+
}, context = './', referencePath = '', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['__package__', '', 'index', 'main'], packageMainPropertyNames = ['main', 'module'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
|
|
290
|
+
const filePaths = [];
|
|
291
|
+
const directoryPaths = [];
|
|
292
|
+
const normalizedGivenInjection = resolveModulesInFolders(normalizeGivenInjection(givenInjection), aliases, moduleReplacements, context, referencePath, pathsToIgnore);
|
|
293
|
+
for (const chunk of Object.values(normalizedGivenInjection)) for (const moduleID of chunk) {
|
|
294
|
+
const filePath = determineModuleFilePath(moduleID, aliases, moduleReplacements, extensions, context, referencePath, pathsToIgnore, relativeModuleLocations, packageEntryFileNames, packageMainPropertyNames, packageAliasPropertyNames, encoding);
|
|
295
|
+
if (filePath) {
|
|
296
|
+
filePaths.push(filePath);
|
|
297
|
+
const directoryPath = dirname(filePath);
|
|
298
|
+
if (!directoryPaths.includes(directoryPath)) directoryPaths.push(directoryPath);
|
|
425
299
|
}
|
|
426
300
|
}
|
|
427
301
|
return {
|
|
428
|
-
filePaths
|
|
429
|
-
directoryPaths
|
|
302
|
+
filePaths,
|
|
303
|
+
directoryPaths
|
|
430
304
|
};
|
|
431
305
|
};
|
|
432
306
|
/**
|
|
@@ -441,52 +315,25 @@ var determineModuleLocations = exports.determineModuleLocations = function deter
|
|
|
441
315
|
* @param pathsToIgnore - Paths which marks location to ignore.
|
|
442
316
|
* @returns Given injections with resolved folder pointing modules.
|
|
443
317
|
*/
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
var index = 0;
|
|
455
|
-
var _iterator7 = _createForOfIteratorHelper((0, _clientnode.copy)(chunk)),
|
|
456
|
-
_step7;
|
|
457
|
-
try {
|
|
458
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
459
|
-
var moduleID = _step7.value;
|
|
460
|
-
var resolvedModuleID = applyModuleReplacements(applyAliases(stripLoader(moduleID), aliases), moduleReplacements);
|
|
461
|
-
if (resolvedModuleID === false) {
|
|
462
|
-
chunk.splice(index, 1);
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
var resolvedPath = (0, _path.resolve)(referencePath, resolvedModuleID);
|
|
466
|
-
if ((0, _clientnode.isDirectorySync)(resolvedPath)) {
|
|
467
|
-
chunk.splice(index, 1);
|
|
468
|
-
var _iterator8 = _createForOfIteratorHelper((0, _clientnode.walkDirectoryRecursivelySync)(resolvedPath, function (file) {
|
|
469
|
-
if (isFilePathInLocation(file.path, pathsToIgnore)) return false;
|
|
470
|
-
})),
|
|
471
|
-
_step8;
|
|
472
|
-
try {
|
|
473
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
474
|
-
var _file$stats2;
|
|
475
|
-
var file = _step8.value;
|
|
476
|
-
if ((_file$stats2 = file.stats) !== null && _file$stats2 !== void 0 && _file$stats2.isFile()) chunk.push('./' + (0, _path.relative)(context, (0, _path.resolve)(resolvedPath, file.path)));
|
|
477
|
-
}
|
|
478
|
-
} catch (err) {
|
|
479
|
-
_iterator8.e(err);
|
|
480
|
-
} finally {
|
|
481
|
-
_iterator8.f();
|
|
482
|
-
}
|
|
483
|
-
} else if (resolvedModuleID.startsWith('./') && !resolvedModuleID.startsWith("./".concat((0, _path.relative)(context, referencePath)))) chunk[index] = "./".concat((0, _path.relative)(context, resolvedPath));
|
|
484
|
-
index += 1;
|
|
318
|
+
export const resolveModulesInFolders = (normalizedGivenInjection, aliases = {}, moduleReplacements = {}, context = './', referencePath = '', pathsToIgnore = ['.git']) => {
|
|
319
|
+
if (referencePath.startsWith('/')) referencePath = relative(context, referencePath);
|
|
320
|
+
const result = copy(normalizedGivenInjection);
|
|
321
|
+
for (const chunk of Object.values(result)) {
|
|
322
|
+
let index = 0;
|
|
323
|
+
for (const moduleID of copy(chunk)) {
|
|
324
|
+
const resolvedModuleID = applyModuleReplacements(applyAliases(stripLoader(moduleID), aliases), moduleReplacements);
|
|
325
|
+
if (resolvedModuleID === false) {
|
|
326
|
+
chunk.splice(index, 1);
|
|
327
|
+
continue;
|
|
485
328
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
329
|
+
const resolvedPath = resolve(referencePath, resolvedModuleID);
|
|
330
|
+
if (isDirectorySync(resolvedPath)) {
|
|
331
|
+
chunk.splice(index, 1);
|
|
332
|
+
for (const file of walkDirectoryRecursivelySync(resolvedPath, file => {
|
|
333
|
+
if (isFilePathInLocation(file.path, pathsToIgnore)) return false;
|
|
334
|
+
})) if (file.stats?.isFile()) chunk.push('./' + relative(context, resolve(resolvedPath, file.path)));
|
|
335
|
+
} else if (resolvedModuleID.startsWith('./') && !resolvedModuleID.startsWith(`./${relative(context, referencePath)}`)) chunk[index] = `./${relative(context, resolvedPath)}`;
|
|
336
|
+
index += 1;
|
|
490
337
|
}
|
|
491
338
|
}
|
|
492
339
|
return result;
|
|
@@ -498,43 +345,25 @@ var resolveModulesInFolders = exports.resolveModulesInFolders = function resolve
|
|
|
498
345
|
* @param givenInjection - Given entry injection to normalize.
|
|
499
346
|
* @returns Normalized representation of given entry injection.
|
|
500
347
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
348
|
+
export const normalizeGivenInjection = givenInjection => {
|
|
349
|
+
let result = {};
|
|
503
350
|
if (Array.isArray(givenInjection)) result = {
|
|
504
351
|
index: givenInjection
|
|
505
352
|
};else if (typeof givenInjection === 'string') result = {
|
|
506
353
|
index: [givenInjection]
|
|
507
|
-
};else if (
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
for (
|
|
511
|
-
|
|
512
|
-
chunkName = _Object$entries3$_i[0],
|
|
513
|
-
chunk = _Object$entries3$_i[1];
|
|
514
|
-
if (Array.isArray(chunk)) {
|
|
515
|
-
if (chunk.length > 0) {
|
|
516
|
-
hasContent = true;
|
|
517
|
-
result[chunkName] = chunk;
|
|
518
|
-
} else chunkNamesToDelete.push(chunkName);
|
|
519
|
-
} else {
|
|
354
|
+
};else if (isPlainObject(givenInjection)) {
|
|
355
|
+
let hasContent = false;
|
|
356
|
+
const chunkNamesToDelete = [];
|
|
357
|
+
for (const [chunkName, chunk] of Object.entries(givenInjection)) if (Array.isArray(chunk)) {
|
|
358
|
+
if (chunk.length > 0) {
|
|
520
359
|
hasContent = true;
|
|
521
|
-
result[chunkName] =
|
|
522
|
-
}
|
|
360
|
+
result[chunkName] = chunk;
|
|
361
|
+
} else chunkNamesToDelete.push(chunkName);
|
|
362
|
+
} else {
|
|
363
|
+
hasContent = true;
|
|
364
|
+
result[chunkName] = [chunk];
|
|
523
365
|
}
|
|
524
|
-
if (hasContent) {
|
|
525
|
-
var _iterator9 = _createForOfIteratorHelper(chunkNamesToDelete),
|
|
526
|
-
_step9;
|
|
527
|
-
try {
|
|
528
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
529
|
-
var _chunkName = _step9.value;
|
|
530
|
-
delete result[_chunkName];
|
|
531
|
-
}
|
|
532
|
-
} catch (err) {
|
|
533
|
-
_iterator9.e(err);
|
|
534
|
-
} finally {
|
|
535
|
-
_iterator9.f();
|
|
536
|
-
}
|
|
537
|
-
} else result = {
|
|
366
|
+
if (hasContent) for (const chunkName of chunkNamesToDelete) delete result[chunkName];else result = {
|
|
538
367
|
index: []
|
|
539
368
|
};
|
|
540
369
|
}
|
|
@@ -555,55 +384,30 @@ var normalizeGivenInjection = exports.normalizeGivenInjection = function normali
|
|
|
555
384
|
* @param pathsToIgnore - Paths which marks location to ignore.
|
|
556
385
|
* @returns Given injection with resolved marked indicators.
|
|
557
386
|
*/
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
})
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var context = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : './';
|
|
570
|
-
var referencePath = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : '';
|
|
571
|
-
var pathsToIgnore = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ['.git'];
|
|
572
|
-
var injection = (0, _clientnode.copy)(givenInjection);
|
|
573
|
-
var moduleFilePathsToExclude = determineModuleLocations(givenInjection.autoExclude.paths, aliases, moduleReplacements, {
|
|
387
|
+
export const resolveAutoInjection = (givenInjection, buildConfigurations, aliases = {}, moduleReplacements = {}, extensions = {
|
|
388
|
+
file: {
|
|
389
|
+
external: ['compiled.js', '.js', '.json'],
|
|
390
|
+
internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
391
|
+
}
|
|
392
|
+
}, context = './', referencePath = '', pathsToIgnore = ['.git']) => {
|
|
393
|
+
const injection = copy(givenInjection);
|
|
394
|
+
const moduleFilePathsToExclude = determineModuleLocations(givenInjection.autoExclude.paths, aliases, moduleReplacements, {
|
|
574
395
|
file: extensions.file.internal
|
|
575
396
|
}, context, referencePath, pathsToIgnore).filePaths;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
for (var _i0 = 0, _Object$values5 = Object.values(modules); _i0 < _Object$values5.length; _i0++) {
|
|
591
|
-
var subChunk = _Object$values5[_i0];
|
|
592
|
-
chunk.push(subChunk);
|
|
593
|
-
}
|
|
594
|
-
/*
|
|
595
|
-
Reverse array to let javaScript and main files be
|
|
596
|
-
the last ones to export them rather.
|
|
597
|
-
*/
|
|
598
|
-
chunk.reverse();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
} else if (injectionType === '__auto__') injection[name] = getAutoInjection(buildConfigurations, moduleFilePathsToExclude, givenInjection.autoExclude.pattern, referencePath);
|
|
602
|
-
}
|
|
603
|
-
} catch (err) {
|
|
604
|
-
_iterator0.e(err);
|
|
605
|
-
} finally {
|
|
606
|
-
_iterator0.f();
|
|
397
|
+
for (const name of ['entry', 'external']) {
|
|
398
|
+
const injectionType = injection[name];
|
|
399
|
+
if (isPlainObject(injectionType)) {
|
|
400
|
+
for (let [chunkName, chunk] of Object.entries(injectionType)) if (chunk === '__auto__') {
|
|
401
|
+
chunk = injectionType[chunkName] = [];
|
|
402
|
+
const modules = getAutoInjection(buildConfigurations, moduleFilePathsToExclude, givenInjection.autoExclude.pattern, referencePath);
|
|
403
|
+
for (const subChunk of Object.values(modules)) chunk.push(subChunk);
|
|
404
|
+
/*
|
|
405
|
+
Reverse array to let javaScript and main files be
|
|
406
|
+
the last ones to export them rather.
|
|
407
|
+
*/
|
|
408
|
+
chunk.reverse();
|
|
409
|
+
}
|
|
410
|
+
} else if (injectionType === '__auto__') injection[name] = getAutoInjection(buildConfigurations, moduleFilePathsToExclude, givenInjection.autoExclude.pattern, referencePath);
|
|
607
411
|
}
|
|
608
412
|
return injection;
|
|
609
413
|
};
|
|
@@ -617,55 +421,35 @@ var resolveAutoInjection = exports.resolveAutoInjection = function resolveAutoIn
|
|
|
617
421
|
* @param context - File path to use as starting point.
|
|
618
422
|
* @returns All determined module file paths.
|
|
619
423
|
*/
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
try {
|
|
632
|
-
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
633
|
-
var moduleFilePath = _step10.value;
|
|
634
|
-
if (!(moduleFilePathsToExclude.includes(moduleFilePath) || (0, _clientnode.isAnyMatching)(moduleFilePath.substring(context.length), moduleFilePathPatternToExclude))) {
|
|
635
|
-
var relativeModuleFilePath = "./".concat((0, _path.relative)(context, moduleFilePath));
|
|
636
|
-
var directoryPath = (0, _path.dirname)(relativeModuleFilePath);
|
|
637
|
-
var baseName = (0, _path.basename)(relativeModuleFilePath, ".".concat(buildConfiguration.extension));
|
|
638
|
-
var moduleID = baseName;
|
|
639
|
-
if (directoryPath !== '.') moduleID = (0, _path.join)(directoryPath, baseName);
|
|
424
|
+
export const getAutoInjection = (buildConfigurations, moduleFilePathsToExclude, moduleFilePathPatternToExclude, context) => {
|
|
425
|
+
const result = {};
|
|
426
|
+
const injectedModuleIDs = {};
|
|
427
|
+
for (const buildConfiguration of buildConfigurations) {
|
|
428
|
+
if (!Object.prototype.hasOwnProperty.call(injectedModuleIDs, buildConfiguration.outputExtension)) injectedModuleIDs[buildConfiguration.outputExtension] = [];
|
|
429
|
+
for (const moduleFilePath of buildConfiguration.filePaths) if (!(moduleFilePathsToExclude.includes(moduleFilePath) || isAnyMatching(moduleFilePath.substring(context.length), moduleFilePathPatternToExclude))) {
|
|
430
|
+
const relativeModuleFilePath = `./${relative(context, moduleFilePath)}`;
|
|
431
|
+
const directoryPath = dirname(relativeModuleFilePath);
|
|
432
|
+
const baseName = basename(relativeModuleFilePath, `.${buildConfiguration.extension}`);
|
|
433
|
+
let moduleID = baseName;
|
|
434
|
+
if (directoryPath !== '.') moduleID = join(directoryPath, baseName);
|
|
640
435
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
} catch (err) {
|
|
660
|
-
_iterator10.e(err);
|
|
661
|
-
} finally {
|
|
662
|
-
_iterator10.f();
|
|
436
|
+
/*
|
|
437
|
+
Ensure that each output type has only one source
|
|
438
|
+
representation.
|
|
439
|
+
*/
|
|
440
|
+
if (!injectedModuleIDs[buildConfiguration.outputExtension].includes(moduleID)) {
|
|
441
|
+
/*
|
|
442
|
+
Ensure that same module ids and different output types
|
|
443
|
+
can be distinguished by their extension
|
|
444
|
+
(JavaScript-Modules remains without extension since
|
|
445
|
+
they will be handled first because the build
|
|
446
|
+
configurations are expected to be sorted in this
|
|
447
|
+
context).
|
|
448
|
+
*/
|
|
449
|
+
if (Object.prototype.hasOwnProperty.call(result, moduleID)) result[relativeModuleFilePath] = relativeModuleFilePath;else result[moduleID] = relativeModuleFilePath;
|
|
450
|
+
injectedModuleIDs[buildConfiguration.outputExtension].push(moduleID);
|
|
663
451
|
}
|
|
664
452
|
}
|
|
665
|
-
} catch (err) {
|
|
666
|
-
_iterator1.e(err);
|
|
667
|
-
} finally {
|
|
668
|
-
_iterator1.f();
|
|
669
453
|
}
|
|
670
454
|
return result;
|
|
671
455
|
};
|
|
@@ -679,54 +463,29 @@ var getAutoInjection = exports.getAutoInjection = function getAutoInjection(buil
|
|
|
679
463
|
* @param encoding - Encoding to use for file names during file traversing.
|
|
680
464
|
* @returns Path if found and / or additional package aliases to consider.
|
|
681
465
|
*/
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
var packageAliasPropertyNames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
685
|
-
var encoding = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'utf-8';
|
|
686
|
-
var result = {
|
|
466
|
+
export const determineModuleFilePathInPackage = (packagePath, packageMainPropertyNames = ['main'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
|
|
467
|
+
const result = {
|
|
687
468
|
fileName: null,
|
|
688
469
|
packageAliases: null
|
|
689
470
|
};
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
if (
|
|
693
|
-
|
|
471
|
+
if (isDirectorySync(packagePath)) {
|
|
472
|
+
const pathToPackageJSON = resolve(packagePath, 'package.json');
|
|
473
|
+
if (isFileSync(pathToPackageJSON)) {
|
|
474
|
+
let localConfiguration = {};
|
|
694
475
|
try {
|
|
695
|
-
localConfiguration = JSON.parse(
|
|
696
|
-
encoding
|
|
476
|
+
localConfiguration = JSON.parse(readFileSync(pathToPackageJSON, {
|
|
477
|
+
encoding
|
|
697
478
|
}));
|
|
698
479
|
} catch (error) {
|
|
699
|
-
log.warn(
|
|
480
|
+
log.warn(`Package configuration file "${pathToPackageJSON}"`, `could not parsed: ${represent(error)}`);
|
|
700
481
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
705
|
-
var propertyName = _step11.value;
|
|
706
|
-
if (Object.prototype.hasOwnProperty.call(localConfiguration, propertyName) && typeof localConfiguration[propertyName] === 'string' && localConfiguration[propertyName]) {
|
|
707
|
-
result.fileName = localConfiguration[propertyName];
|
|
708
|
-
break;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
} catch (err) {
|
|
712
|
-
_iterator11.e(err);
|
|
713
|
-
} finally {
|
|
714
|
-
_iterator11.f();
|
|
482
|
+
for (const propertyName of packageMainPropertyNames) if (Object.prototype.hasOwnProperty.call(localConfiguration, propertyName) && typeof localConfiguration[propertyName] === 'string' && localConfiguration[propertyName]) {
|
|
483
|
+
result.fileName = localConfiguration[propertyName];
|
|
484
|
+
break;
|
|
715
485
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
720
|
-
var _propertyName = _step12.value;
|
|
721
|
-
if (Object.prototype.hasOwnProperty.call(localConfiguration, _propertyName) && (0, _clientnode.isPlainObject)(localConfiguration[_propertyName])) {
|
|
722
|
-
result.packageAliases = localConfiguration[_propertyName];
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
} catch (err) {
|
|
727
|
-
_iterator12.e(err);
|
|
728
|
-
} finally {
|
|
729
|
-
_iterator12.f();
|
|
486
|
+
for (const propertyName of packageAliasPropertyNames) if (Object.prototype.hasOwnProperty.call(localConfiguration, propertyName) && isPlainObject(localConfiguration[propertyName])) {
|
|
487
|
+
result.packageAliases = localConfiguration[propertyName];
|
|
488
|
+
break;
|
|
730
489
|
}
|
|
731
490
|
}
|
|
732
491
|
}
|
|
@@ -754,93 +513,36 @@ var determineModuleFilePathInPackage = exports.determineModuleFilePathInPackage
|
|
|
754
513
|
* @returns File path or given module id if determinations has failed or wasn't
|
|
755
514
|
* necessary.
|
|
756
515
|
*/
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
var extensions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
761
|
-
file: KNOWN_FILE_EXTENSIONS.map(function (suffix) {
|
|
762
|
-
return ".".concat(suffix);
|
|
763
|
-
})
|
|
764
|
-
};
|
|
765
|
-
var context = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : './';
|
|
766
|
-
var referencePath = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
|
|
767
|
-
var pathsToIgnore = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : ['.git'];
|
|
768
|
-
var relativeModuleLocations = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ['node_modules'];
|
|
769
|
-
var packageEntryFileNames = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : ['index'];
|
|
770
|
-
var packageMainPropertyNames = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : ['main'];
|
|
771
|
-
var packageAliasPropertyNames = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : [];
|
|
772
|
-
var encoding = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : 'utf-8';
|
|
516
|
+
export const determineModuleFilePath = (moduleID, aliases = {}, moduleReplacements = {}, extensions = {
|
|
517
|
+
file: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
518
|
+
}, context = './', referencePath = '', pathsToIgnore = ['.git'], relativeModuleLocations = ['node_modules'], packageEntryFileNames = ['index'], packageMainPropertyNames = ['main'], packageAliasPropertyNames = [], encoding = 'utf-8') => {
|
|
773
519
|
if (!moduleID) return null;
|
|
774
520
|
moduleID = applyModuleReplacements(applyAliases(stripLoader(moduleID), aliases), moduleReplacements);
|
|
775
521
|
if (!moduleID) return null;
|
|
776
|
-
|
|
777
|
-
if (moduleFilePath.startsWith('./')) moduleFilePath =
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}));
|
|
781
|
-
var parts = context.split('/');
|
|
522
|
+
let moduleFilePath = moduleID;
|
|
523
|
+
if (moduleFilePath.startsWith('./')) moduleFilePath = join(referencePath, moduleFilePath);
|
|
524
|
+
const moduleLocations = [referencePath].concat(relativeModuleLocations.map(filePath => resolve(context, filePath)));
|
|
525
|
+
const parts = context.split('/');
|
|
782
526
|
parts.splice(-1, 1);
|
|
783
527
|
while (parts.length > 0) {
|
|
784
|
-
|
|
785
|
-
_step13;
|
|
786
|
-
try {
|
|
787
|
-
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
788
|
-
var relativePath = _step13.value;
|
|
789
|
-
moduleLocations.push((0, _path.join)('/', parts.join('/'), relativePath));
|
|
790
|
-
}
|
|
791
|
-
} catch (err) {
|
|
792
|
-
_iterator13.e(err);
|
|
793
|
-
} finally {
|
|
794
|
-
_iterator13.f();
|
|
795
|
-
}
|
|
528
|
+
for (const relativePath of relativeModuleLocations) moduleLocations.push(join('/', parts.join('/'), relativePath));
|
|
796
529
|
parts.splice(-1, 1);
|
|
797
530
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
var fileName = _step15.value;
|
|
808
|
-
var _iterator16 = _createForOfIteratorHelper([''].concat(extensions.file)),
|
|
809
|
-
_step16;
|
|
810
|
-
try {
|
|
811
|
-
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
812
|
-
var fileExtension = _step16.value;
|
|
813
|
-
var currentModuleFilePath = void 0;
|
|
814
|
-
if (moduleFilePath.startsWith('/')) currentModuleFilePath = (0, _path.resolve)(moduleFilePath);else currentModuleFilePath = (0, _path.resolve)(moduleLocation, moduleFilePath);
|
|
815
|
-
var packageAliases = {};
|
|
816
|
-
if (fileName === '__package__') {
|
|
817
|
-
var result = determineModuleFilePathInPackage(currentModuleFilePath, packageMainPropertyNames, packageAliasPropertyNames, encoding);
|
|
818
|
-
if (result.fileName) fileName = result.fileName;
|
|
819
|
-
if (result.packageAliases) packageAliases = result.packageAliases;
|
|
820
|
-
if (fileName === '__package__') continue;
|
|
821
|
-
}
|
|
822
|
-
var resolvedFileName = applyModuleReplacements(applyAliases(fileName, packageAliases), moduleReplacements);
|
|
823
|
-
if (resolvedFileName === false) continue;
|
|
824
|
-
if (resolvedFileName) currentModuleFilePath = (0, _path.resolve)(currentModuleFilePath, "".concat(resolvedFileName).concat(fileExtension));else currentModuleFilePath += "".concat(resolvedFileName).concat(fileExtension);
|
|
825
|
-
if (isFilePathInLocation(currentModuleFilePath, pathsToIgnore)) continue;
|
|
826
|
-
if ((0, _clientnode.isFileSync)(currentModuleFilePath)) return currentModuleFilePath;
|
|
827
|
-
}
|
|
828
|
-
} catch (err) {
|
|
829
|
-
_iterator16.e(err);
|
|
830
|
-
} finally {
|
|
831
|
-
_iterator16.f();
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
} catch (err) {
|
|
835
|
-
_iterator15.e(err);
|
|
836
|
-
} finally {
|
|
837
|
-
_iterator15.f();
|
|
838
|
-
}
|
|
531
|
+
for (const moduleLocation of [referencePath].concat(moduleLocations)) for (let fileName of ['', '__package__'].concat(packageEntryFileNames)) for (const fileExtension of [''].concat(extensions.file)) {
|
|
532
|
+
let currentModuleFilePath;
|
|
533
|
+
if (moduleFilePath.startsWith('/')) currentModuleFilePath = resolve(moduleFilePath);else currentModuleFilePath = resolve(moduleLocation, moduleFilePath);
|
|
534
|
+
let packageAliases = {};
|
|
535
|
+
if (fileName === '__package__') {
|
|
536
|
+
const result = determineModuleFilePathInPackage(currentModuleFilePath, packageMainPropertyNames, packageAliasPropertyNames, encoding);
|
|
537
|
+
if (result.fileName) fileName = result.fileName;
|
|
538
|
+
if (result.packageAliases) packageAliases = result.packageAliases;
|
|
539
|
+
if (fileName === '__package__') continue;
|
|
839
540
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
541
|
+
const resolvedFileName = applyModuleReplacements(applyAliases(fileName, packageAliases), moduleReplacements);
|
|
542
|
+
if (resolvedFileName === false) continue;
|
|
543
|
+
if (resolvedFileName) currentModuleFilePath = resolve(currentModuleFilePath, `${resolvedFileName}${fileExtension}`);else currentModuleFilePath += `${resolvedFileName}${fileExtension}`;
|
|
544
|
+
if (isFilePathInLocation(currentModuleFilePath, pathsToIgnore)) continue;
|
|
545
|
+
if (isFileSync(currentModuleFilePath)) return currentModuleFilePath;
|
|
844
546
|
}
|
|
845
547
|
return null;
|
|
846
548
|
};
|
|
@@ -851,15 +553,10 @@ var determineModuleFilePath = exports.determineModuleFilePath = function determi
|
|
|
851
553
|
* @param aliases - Mapping of aliases to take into account.
|
|
852
554
|
* @returns The alias applied given module id.
|
|
853
555
|
*/
|
|
854
|
-
|
|
855
|
-
for (
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
alias = _Object$entries5$_i[1];
|
|
859
|
-
if (name.endsWith('$')) {
|
|
860
|
-
if (moduleID === name.substring(0, name.length - 1)) moduleID = alias;
|
|
861
|
-
} else if (typeof moduleID === 'string') moduleID = moduleID.replace(name, alias);
|
|
862
|
-
}
|
|
556
|
+
export const applyAliases = (moduleID, aliases) => {
|
|
557
|
+
for (const [name, alias] of Object.entries(aliases)) if (name.endsWith('$')) {
|
|
558
|
+
if (moduleID === name.substring(0, name.length - 1)) moduleID = alias;
|
|
559
|
+
} else if (typeof moduleID === 'string') moduleID = moduleID.replace(name, alias);
|
|
863
560
|
return moduleID;
|
|
864
561
|
};
|
|
865
562
|
/**
|
|
@@ -869,14 +566,9 @@ var applyAliases = exports.applyAliases = function applyAliases(moduleID, aliase
|
|
|
869
566
|
* replacements.
|
|
870
567
|
* @returns The replacement applied given module id.
|
|
871
568
|
*/
|
|
872
|
-
|
|
569
|
+
export const applyModuleReplacements = (moduleID, replacements) => {
|
|
873
570
|
if (moduleID === false) return moduleID;
|
|
874
|
-
for (
|
|
875
|
-
var _Object$entries6$_i = (0, _slicedToArray2["default"])(_Object$entries6[_i10], 2),
|
|
876
|
-
search = _Object$entries6$_i[0],
|
|
877
|
-
replacement = _Object$entries6$_i[1];
|
|
878
|
-
moduleID = moduleID.replace(new RegExp(search), replacement);
|
|
879
|
-
}
|
|
571
|
+
for (const [search, replacement] of Object.entries(replacements)) moduleID = moduleID.replace(new RegExp(search), replacement);
|
|
880
572
|
return moduleID;
|
|
881
573
|
};
|
|
882
574
|
/**
|
|
@@ -885,21 +577,20 @@ var applyModuleReplacements = exports.applyModuleReplacements = function applyMo
|
|
|
885
577
|
* @param fileName - Package configuration file name.
|
|
886
578
|
* @returns Determined file path.
|
|
887
579
|
*/
|
|
888
|
-
|
|
889
|
-
var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'package.json';
|
|
580
|
+
export const findPackageDescriptorFilePath = (start, fileName = 'package.json') => {
|
|
890
581
|
if (typeof start === 'string') {
|
|
891
|
-
if (!start.endsWith(
|
|
892
|
-
start = start.split(
|
|
582
|
+
if (!start.endsWith(sep)) start += sep;
|
|
583
|
+
start = start.split(sep);
|
|
893
584
|
}
|
|
894
585
|
if (!start.length) return null;
|
|
895
586
|
start.pop();
|
|
896
|
-
|
|
587
|
+
const result = resolve(start.join(sep), fileName);
|
|
897
588
|
try {
|
|
898
|
-
if (
|
|
899
|
-
} catch
|
|
589
|
+
if (existsSync(result)) return result;
|
|
590
|
+
} catch {
|
|
900
591
|
// Continue regardless of an error.
|
|
901
592
|
}
|
|
902
|
-
return
|
|
593
|
+
return findPackageDescriptorFilePath(start, fileName);
|
|
903
594
|
};
|
|
904
595
|
/**
|
|
905
596
|
* Determines the nearest package configuration from given module file path.
|
|
@@ -909,20 +600,19 @@ var _findPackageDescriptorFilePath = exports.findPackageDescriptorFilePath = fun
|
|
|
909
600
|
* @returns A object containing found parsed configuration an their
|
|
910
601
|
* corresponding file path.
|
|
911
602
|
*/
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
var configuration = (0, _clientnode.currentRequire)(filePath);
|
|
603
|
+
export const getClosestPackageDescriptor = (modulePath, fileName = 'package.json') => {
|
|
604
|
+
const filePath = findPackageDescriptorFilePath(modulePath, fileName);
|
|
605
|
+
if (!(filePath && currentRequire)) return null;
|
|
606
|
+
const configuration = currentRequire(filePath);
|
|
917
607
|
/*
|
|
918
608
|
If the package.json does not have a name property, try again from
|
|
919
609
|
one level higher.
|
|
920
610
|
*/
|
|
921
|
-
if (!configuration.name) return
|
|
611
|
+
if (!configuration.name) return getClosestPackageDescriptor(resolve(dirname(filePath), '..'), fileName);
|
|
922
612
|
if (!configuration.version) configuration.version = 'not set';
|
|
923
613
|
return {
|
|
924
|
-
configuration
|
|
925
|
-
filePath
|
|
614
|
+
configuration,
|
|
615
|
+
filePath
|
|
926
616
|
};
|
|
927
617
|
};
|
|
928
618
|
// endregion
|