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