mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
Major update breaking changes: - ESLint 7.0.0 (https://eslint.org/docs/user-guide/migrating-to-7.0.0) now includes .eslint.rc.js in its list, which is fine for us. Other changes are not applicable for us. - eslint-plugin-mocha (https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md#700-may-13-2020) drops support for ESLint <7, but this CL updates to 7+. Other changes are not applicable for us. DISABLE_THIRD_PARTY_CHECK=Updating ESLint R=petermarshall@chromium.org Change-Id: I7760e084ef87f73a92f9ea4e075fb4c065047f5a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2534873 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var path = require("path");
|
|
/**
|
|
* Converts an absolute baseUrl and paths to an array of absolute mapping entries.
|
|
* The array is sorted by longest prefix.
|
|
* Having an array with entries allows us to keep a sorting order rather than
|
|
* sort by keys each time we use the mappings.
|
|
* @param absoluteBaseUrl
|
|
* @param paths
|
|
* @param addMatchAll
|
|
*/
|
|
function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
|
|
// Resolve all paths to absolute form once here, and sort them by
|
|
// longest prefix once here, this saves time on each request later.
|
|
// We need to put them in an array to preseve the sorting order.
|
|
var sortedKeys = sortByLongestPrefix(Object.keys(paths));
|
|
var absolutePaths = [];
|
|
for (var _i = 0, sortedKeys_1 = sortedKeys; _i < sortedKeys_1.length; _i++) {
|
|
var key = sortedKeys_1[_i];
|
|
absolutePaths.push({
|
|
pattern: key,
|
|
paths: paths[key].map(function (pathToResolve) {
|
|
return path.join(absoluteBaseUrl, pathToResolve);
|
|
})
|
|
});
|
|
}
|
|
// If there is no match-all path specified in the paths section of tsconfig, then try to match
|
|
// all paths relative to baseUrl, this is how typescript works.
|
|
if (!paths["*"] && addMatchAll) {
|
|
absolutePaths.push({
|
|
pattern: "*",
|
|
paths: [absoluteBaseUrl.replace(/\/$/, "") + "/*"]
|
|
});
|
|
}
|
|
return absolutePaths;
|
|
}
|
|
exports.getAbsoluteMappingEntries = getAbsoluteMappingEntries;
|
|
/**
|
|
* Sort path patterns.
|
|
* If a module name can be matched with multiple patterns then pattern with the longest prefix will be picked.
|
|
*/
|
|
function sortByLongestPrefix(arr) {
|
|
return arr
|
|
.concat()
|
|
.sort(function (a, b) { return getPrefixLength(b) - getPrefixLength(a); });
|
|
}
|
|
function getPrefixLength(pattern) {
|
|
var prefixLength = pattern.indexOf("*");
|
|
return pattern.substr(0, prefixLength).length;
|
|
}
|