(options, targetFilePath, packageDirectory, packageName, exports, conditions, mode)
| 122408 | MatchingMode[MatchingMode["Pattern"] = 2] = "Pattern"; |
| 122409 | })(MatchingMode || (MatchingMode = {})); |
| 122410 | function tryGetModuleNameFromExports(options, targetFilePath, packageDirectory, packageName, exports, conditions, mode) { |
| 122411 | if (mode === void 0) { mode = 0 /* MatchingMode.Exact */; } |
| 122412 | if (typeof exports === "string") { |
| 122413 | var pathOrPattern = ts.getNormalizedAbsolutePath(ts.combinePaths(packageDirectory, exports), /*currentDirectory*/ undefined); |
| 122414 | var extensionSwappedTarget = ts.hasTSFileExtension(targetFilePath) ? ts.removeFileExtension(targetFilePath) + tryGetJSExtensionForFile(targetFilePath, options) : undefined; |
| 122415 | switch (mode) { |
| 122416 | case 0 /* MatchingMode.Exact */: |
| 122417 | if (ts.comparePaths(targetFilePath, pathOrPattern) === 0 /* Comparison.EqualTo */ || (extensionSwappedTarget && ts.comparePaths(extensionSwappedTarget, pathOrPattern) === 0 /* Comparison.EqualTo */)) { |
| 122418 | return { moduleFileToTry: packageName }; |
| 122419 | } |
| 122420 | break; |
| 122421 | case 1 /* MatchingMode.Directory */: |
| 122422 | if (ts.containsPath(pathOrPattern, targetFilePath)) { |
| 122423 | var fragment = ts.getRelativePathFromDirectory(pathOrPattern, targetFilePath, /*ignoreCase*/ false); |
| 122424 | return { moduleFileToTry: ts.getNormalizedAbsolutePath(ts.combinePaths(ts.combinePaths(packageName, exports), fragment), /*currentDirectory*/ undefined) }; |
| 122425 | } |
| 122426 | break; |
| 122427 | case 2 /* MatchingMode.Pattern */: |
| 122428 | var starPos = pathOrPattern.indexOf("*"); |
| 122429 | var leadingSlice = pathOrPattern.slice(0, starPos); |
| 122430 | var trailingSlice = pathOrPattern.slice(starPos + 1); |
| 122431 | if (ts.startsWith(targetFilePath, leadingSlice) && ts.endsWith(targetFilePath, trailingSlice)) { |
| 122432 | var starReplacement = targetFilePath.slice(leadingSlice.length, targetFilePath.length - trailingSlice.length); |
| 122433 | return { moduleFileToTry: packageName.replace("*", starReplacement) }; |
| 122434 | } |
| 122435 | if (extensionSwappedTarget && ts.startsWith(extensionSwappedTarget, leadingSlice) && ts.endsWith(extensionSwappedTarget, trailingSlice)) { |
| 122436 | var starReplacement = extensionSwappedTarget.slice(leadingSlice.length, extensionSwappedTarget.length - trailingSlice.length); |
| 122437 | return { moduleFileToTry: packageName.replace("*", starReplacement) }; |
| 122438 | } |
| 122439 | break; |
| 122440 | } |
| 122441 | } |
| 122442 | else if (Array.isArray(exports)) { |
| 122443 | return ts.forEach(exports, function (e) { return tryGetModuleNameFromExports(options, targetFilePath, packageDirectory, packageName, e, conditions); }); |
| 122444 | } |
| 122445 | else if (typeof exports === "object" && exports !== null) { // eslint-disable-line no-null/no-null |
| 122446 | if (ts.allKeysStartWithDot(exports)) { |
| 122447 | // sub-mappings |
| 122448 | // 3 cases: |
| 122449 | // * directory mappings (legacyish, key ends with / (technically allows index/extension resolution under cjs mode)) |
| 122450 | // * pattern mappings (contains a *) |
| 122451 | // * exact mappings (no *, does not end with /) |
| 122452 | return ts.forEach(ts.getOwnKeys(exports), function (k) { |
| 122453 | var subPackageName = ts.getNormalizedAbsolutePath(ts.combinePaths(packageName, k), /*currentDirectory*/ undefined); |
| 122454 | var mode = ts.endsWith(k, "/") ? 1 /* MatchingMode.Directory */ |
| 122455 | : ts.stringContains(k, "*") ? 2 /* MatchingMode.Pattern */ |
| 122456 | : 0 /* MatchingMode.Exact */; |
| 122457 | return tryGetModuleNameFromExports(options, targetFilePath, packageDirectory, subPackageName, exports[k], conditions, mode); |
| 122458 | }); |
| 122459 | } |
| 122460 | else { |
| 122461 | // conditional mapping |
| 122462 | for (var _i = 0, _a = ts.getOwnKeys(exports); _i < _a.length; _i++) { |
| 122463 | var key = _a[_i]; |
| 122464 | if (key === "default" || conditions.indexOf(key) >= 0 || ts.isApplicableVersionedTypesKey(conditions, key)) { |
| 122465 | var subTarget = exports[key]; |
| 122466 | var result = tryGetModuleNameFromExports(options, targetFilePath, packageDirectory, packageName, subTarget, conditions); |
| 122467 | if (result) { |
no test coverage detected