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/helper.js CHANGED
@@ -16,26 +16,26 @@
16
16
  endregion
17
17
  */
18
18
  // region imports
19
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
20
- Object.defineProperty(exports, "__esModule", {
21
- value: true
22
- });
23
- exports.stripLoader = exports.resolveModulesInFolders = exports.resolveBuildConfigurationFilePaths = exports.resolveAutoInjection = exports.renderFilePathTemplate = exports.normalizePaths = exports.normalizeGivenInjection = exports.log = exports.isFilePathInLocation = exports.getClosestPackageDescriptor = exports.getAutoInjection = exports.findPackageDescriptorFilePath = exports.determineModuleLocations = exports.determineModuleFilePathInPackage = exports.determineModuleFilePath = exports.determineExternalRequest = exports.determineAssetType = exports.applyModuleReplacements = exports.applyContext = exports.applyAliases = exports.KNOWN_FILE_EXTENSIONS = void 0;
24
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
25
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
26
- var _clientnode = require("clientnode");
27
- var _fs = require("fs");
28
- var _path = require("path");
29
- 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; }
30
- 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; }
31
- 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; } } }; }
32
- 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; } }
33
- 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.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
- var KNOWN_FILE_EXTENSIONS = exports.KNOWN_FILE_EXTENSIONS = ['js', 'ts', 'json', 'css', 'eot', 'gif', 'html', 'ico', 'jpg', 'png', 'ejs', 'svg', 'ttf', 'woff', '.woff2'];
37
- var log = exports.log = new _clientnode.Logger({
38
- name: 'weboptimizer-helper-logger'
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
- var isFilePathInLocation = exports.isFilePathInLocation = function isFilePathInLocation(filePath, locationsToCheck) {
51
- var _iterator = _createForOfIteratorHelper(locationsToCheck),
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
- var stripLoader = exports.stripLoader = function stripLoader(moduleID) {
74
- var moduleIDWithoutLoader = moduleID.substring(moduleID.lastIndexOf('!') + 1).replace(/\.webpack\[.+\/.+\]$/, '');
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
- var normalizePaths = exports.normalizePaths = function normalizePaths(paths) {
85
- return Array.from(new Set(paths.map(function (givenPath) {
86
- givenPath = (0, _path.normalize)(givenPath);
87
- if (givenPath.endsWith('/')) return givenPath.substring(0, givenPath.length - 1);
88
- return givenPath;
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
- var renderFilePathTemplate = exports.renderFilePathTemplate = function renderFilePathTemplate(template) {
101
- var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
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
- }, scope);
109
- var filePath = template;
110
- for (var _i = 0, _Object$entries = Object.entries(scope); _i < _Object$entries.length; _i++) {
111
- var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
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
- var applyContext = exports.applyContext = function applyContext(request) {
130
- var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
131
- var referencePath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : './';
132
- var aliases = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
133
- var moduleReplacements = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
134
- var relativeModuleLocations = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ['node_modules'];
135
- referencePath = (0, _path.resolve)(referencePath);
136
- if (request.startsWith('./') && (0, _path.resolve)(context) !== referencePath) {
137
- request = (0, _path.resolve)(context, request);
138
- var _iterator2 = _createForOfIteratorHelper(relativeModuleLocations),
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
- var determineExternalRequest = exports.determineExternalRequest = function determineExternalRequest(request) {
200
- var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
201
- var requestContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : './';
202
- var normalizedGivenInjection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
203
- var relativeExternalModuleLocations = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : ['node_modules'];
204
- var aliases = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
205
- var moduleReplacements = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
206
- var extensions = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : {
207
- file: {
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
- var resolvedRequest = applyModuleReplacements(applyAliases(request.substring(request.lastIndexOf('!') + 1), aliases), moduleReplacements);
230
- if (resolvedRequest === false || (0, _clientnode.isAnyMatching)(resolvedRequest, excludePattern)) return null;
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
- var filePath = determineModuleFilePath(resolvedRequest, {}, {}, {
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) || (0, _clientnode.isAnyMatching)(resolvedRequest, includePattern)) return applyContext(resolvedRequest, requestContext, referencePath, aliases, moduleReplacements, relativeModuleLocations) || null;
243
- for (var _i2 = 0, _Object$values = Object.values(normalizedGivenInjection); _i2 < _Object$values.length; _i2++) {
244
- var chunk = _Object$values[_i2];
245
- var _iterator3 = _createForOfIteratorHelper(chunk),
246
- _step3;
247
- try {
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
- var _iterator4 = _createForOfIteratorHelper(relativeExternalModuleLocations),
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((0, _path.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;
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
- var determineAssetType = exports.determineAssetType = function determineAssetType(filePath, buildConfiguration, paths) {
295
- var result = null;
296
- for (var type in buildConfiguration) if ((0, _path.extname)(filePath) === ".".concat(buildConfiguration[type].extension)) {
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 (var _i3 = 0, _arr = [paths.source, paths.target]; _i3 < _arr.length; _i3++) {
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
- var resolveBuildConfigurationFilePaths = exports.resolveBuildConfigurationFilePaths = function resolveBuildConfigurationFilePaths(configuration) {
323
- var entryPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
324
- var pathsToIgnore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['.git'];
325
- var mainFileBasenames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['index', 'main'];
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
- var _iterator5 = _createForOfIteratorHelper((0, _clientnode.walkDirectoryRecursivelySync)(entryPath, function (file) {
333
- if (isFilePathInLocation(file.path, pathsToIgnore)) return false;
334
- })),
335
- _step5;
336
- try {
337
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
338
- var _file$stats;
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(function (first, second) {
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
- var determineModuleLocations = exports.determineModuleLocations = function determineModuleLocations(givenInjection) {
389
- var aliases = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
390
- var moduleReplacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
391
- var extensions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
392
- file: KNOWN_FILE_EXTENSIONS.map(function (suffix) {
393
- return ".".concat(suffix);
394
- })
395
- };
396
- var context = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : './';
397
- var referencePath = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
398
- var pathsToIgnore = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : ['.git'];
399
- var relativeModuleLocations = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ['node_modules'];
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: filePaths,
429
- directoryPaths: 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
- var resolveModulesInFolders = exports.resolveModulesInFolders = function resolveModulesInFolders(normalizedGivenInjection) {
445
- var aliases = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
446
- var moduleReplacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
447
- var context = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : './';
448
- var referencePath = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
449
- var pathsToIgnore = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ['.git'];
450
- if (referencePath.startsWith('/')) referencePath = (0, _path.relative)(context, referencePath);
451
- var result = (0, _clientnode.copy)(normalizedGivenInjection);
452
- for (var _i7 = 0, _Object$values4 = Object.values(result); _i7 < _Object$values4.length; _i7++) {
453
- var chunk = _Object$values4[_i7];
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
- } catch (err) {
487
- _iterator7.e(err);
488
- } finally {
489
- _iterator7.f();
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
- var normalizeGivenInjection = exports.normalizeGivenInjection = function normalizeGivenInjection(givenInjection) {
502
- var result = {};
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 ((0, _clientnode.isPlainObject)(givenInjection)) {
508
- var hasContent = false;
509
- var chunkNamesToDelete = [];
510
- for (var _i8 = 0, _Object$entries3 = Object.entries(givenInjection); _i8 < _Object$entries3.length; _i8++) {
511
- var _Object$entries3$_i = (0, _slicedToArray2["default"])(_Object$entries3[_i8], 2),
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] = [chunk];
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
- var resolveAutoInjection = exports.resolveAutoInjection = function resolveAutoInjection(givenInjection, buildConfigurations) {
559
- var aliases = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
560
- var moduleReplacements = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
561
- var extensions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
562
- file: {
563
- external: ['compiled.js', '.js', '.json'],
564
- internal: KNOWN_FILE_EXTENSIONS.map(function (suffix) {
565
- return ".".concat(suffix);
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
- var _iterator0 = _createForOfIteratorHelper(['entry', 'external']),
577
- _step0;
578
- try {
579
- for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
580
- var name = _step0.value;
581
- var injectionType = injection[name];
582
- if ((0, _clientnode.isPlainObject)(injectionType)) {
583
- for (var _i9 = 0, _Object$entries4 = Object.entries(injectionType); _i9 < _Object$entries4.length; _i9++) {
584
- var _Object$entries4$_i = (0, _slicedToArray2["default"])(_Object$entries4[_i9], 2),
585
- chunkName = _Object$entries4$_i[0],
586
- chunk = _Object$entries4$_i[1];
587
- if (chunk === '__auto__') {
588
- chunk = injectionType[chunkName] = [];
589
- var modules = getAutoInjection(buildConfigurations, moduleFilePathsToExclude, givenInjection.autoExclude.pattern, referencePath);
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
- var getAutoInjection = exports.getAutoInjection = function getAutoInjection(buildConfigurations, moduleFilePathsToExclude, moduleFilePathPatternToExclude, context) {
621
- var result = {};
622
- var injectedModuleIDs = {};
623
- var _iterator1 = _createForOfIteratorHelper(buildConfigurations),
624
- _step1;
625
- try {
626
- for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
627
- var buildConfiguration = _step1.value;
628
- if (!Object.prototype.hasOwnProperty.call(injectedModuleIDs, buildConfiguration.outputExtension)) injectedModuleIDs[buildConfiguration.outputExtension] = [];
629
- var _iterator10 = _createForOfIteratorHelper(buildConfiguration.filePaths),
630
- _step10;
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
- Ensure that each output type has only one source
643
- representation.
644
- */
645
- if (!injectedModuleIDs[buildConfiguration.outputExtension].includes(moduleID)) {
646
- /*
647
- Ensure that same module ids and different output types
648
- can be distinguished by their extension
649
- (JavaScript-Modules remains without extension since
650
- they will be handled first because the build
651
- configurations are expected to be sorted in this
652
- context).
653
- */
654
- if (Object.prototype.hasOwnProperty.call(result, moduleID)) result[relativeModuleFilePath] = relativeModuleFilePath;else result[moduleID] = relativeModuleFilePath;
655
- injectedModuleIDs[buildConfiguration.outputExtension].push(moduleID);
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
- var determineModuleFilePathInPackage = exports.determineModuleFilePathInPackage = function determineModuleFilePathInPackage(packagePath) {
683
- var packageMainPropertyNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['main'];
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 ((0, _clientnode.isDirectorySync)(packagePath)) {
691
- var pathToPackageJSON = (0, _path.resolve)(packagePath, 'package.json');
692
- if ((0, _clientnode.isFileSync)(pathToPackageJSON)) {
693
- var localConfiguration = {};
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((0, _fs.readFileSync)(pathToPackageJSON, {
696
- encoding: encoding
476
+ localConfiguration = JSON.parse(readFileSync(pathToPackageJSON, {
477
+ encoding
697
478
  }));
698
479
  } catch (error) {
699
- log.warn("Package configuration file \"".concat(pathToPackageJSON, "\""), "could not parsed: ".concat((0, _clientnode.represent)(error)));
480
+ log.warn(`Package configuration file "${pathToPackageJSON}"`, `could not parsed: ${represent(error)}`);
700
481
  }
701
- var _iterator11 = _createForOfIteratorHelper(packageMainPropertyNames),
702
- _step11;
703
- try {
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
- var _iterator12 = _createForOfIteratorHelper(packageAliasPropertyNames),
717
- _step12;
718
- try {
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
- var determineModuleFilePath = exports.determineModuleFilePath = function determineModuleFilePath(moduleID) {
758
- var aliases = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
759
- var moduleReplacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
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
- var moduleFilePath = moduleID;
777
- if (moduleFilePath.startsWith('./')) moduleFilePath = (0, _path.join)(referencePath, moduleFilePath);
778
- var moduleLocations = [referencePath].concat(relativeModuleLocations.map(function (filePath) {
779
- return (0, _path.resolve)(context, filePath);
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
- var _iterator13 = _createForOfIteratorHelper(relativeModuleLocations),
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
- var _iterator14 = _createForOfIteratorHelper([referencePath].concat(moduleLocations)),
799
- _step14;
800
- try {
801
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
802
- var moduleLocation = _step14.value;
803
- var _iterator15 = _createForOfIteratorHelper(['', '__package__'].concat(packageEntryFileNames)),
804
- _step15;
805
- try {
806
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
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
- } catch (err) {
841
- _iterator14.e(err);
842
- } finally {
843
- _iterator14.f();
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
- var applyAliases = exports.applyAliases = function applyAliases(moduleID, aliases) {
855
- for (var _i1 = 0, _Object$entries5 = Object.entries(aliases); _i1 < _Object$entries5.length; _i1++) {
856
- var _Object$entries5$_i = (0, _slicedToArray2["default"])(_Object$entries5[_i1], 2),
857
- name = _Object$entries5$_i[0],
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
- var applyModuleReplacements = exports.applyModuleReplacements = function applyModuleReplacements(moduleID, replacements) {
569
+ export const applyModuleReplacements = (moduleID, replacements) => {
873
570
  if (moduleID === false) return moduleID;
874
- for (var _i10 = 0, _Object$entries6 = Object.entries(replacements); _i10 < _Object$entries6.length; _i10++) {
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
- var _findPackageDescriptorFilePath = exports.findPackageDescriptorFilePath = function findPackageDescriptorFilePath(start) {
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(_path.sep)) start += _path.sep;
892
- start = start.split(_path.sep);
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
- var result = (0, _path.resolve)(start.join(_path.sep), fileName);
587
+ const result = resolve(start.join(sep), fileName);
897
588
  try {
898
- if ((0, _fs.existsSync)(result)) return result;
899
- } catch (_unused) {
589
+ if (existsSync(result)) return result;
590
+ } catch {
900
591
  // Continue regardless of an error.
901
592
  }
902
- return _findPackageDescriptorFilePath(start, fileName);
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
- var _getClosestPackageDescriptor = exports.getClosestPackageDescriptor = function getClosestPackageDescriptor(modulePath) {
913
- var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'package.json';
914
- var filePath = _findPackageDescriptorFilePath(modulePath, fileName);
915
- if (!(filePath && _clientnode.currentRequire)) return null;
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 _getClosestPackageDescriptor((0, _path.resolve)((0, _path.dirname)(filePath), '..'), fileName);
611
+ if (!configuration.name) return getClosestPackageDescriptor(resolve(dirname(filePath), '..'), fileName);
922
612
  if (!configuration.version) configuration.version = 'not set';
923
613
  return {
924
- configuration: configuration,
925
- filePath: filePath
614
+ configuration,
615
+ filePath
926
616
  };
927
617
  };
928
618
  // endregion