(
id: string,
{ setResolvedCache, getResolvedCache, dir, data }: PackageData,
options: InternalResolveOptions,
externalize?: boolean,
)
| 1044 | } |
| 1045 | |
| 1046 | function resolveDeepImport( |
| 1047 | id: string, |
| 1048 | { setResolvedCache, getResolvedCache, dir, data }: PackageData, |
| 1049 | options: InternalResolveOptions, |
| 1050 | externalize?: boolean, |
| 1051 | ): string | undefined { |
| 1052 | const cache = getResolvedCache(id, options) |
| 1053 | if (cache) { |
| 1054 | return cache |
| 1055 | } |
| 1056 | |
| 1057 | let relativeId: string | undefined | void = id |
| 1058 | const { exports: exportsField, browser: browserField } = data |
| 1059 | |
| 1060 | // map relative based on exports data |
| 1061 | if (exportsField) { |
| 1062 | if (isObject(exportsField) && !Array.isArray(exportsField)) { |
| 1063 | // resolve without postfix (see #7098) |
| 1064 | const { file, postfix } = splitFileAndPostfix(relativeId) |
| 1065 | const exportsId = resolveExportsOrImports( |
| 1066 | data, |
| 1067 | file, |
| 1068 | options, |
| 1069 | 'exports', |
| 1070 | externalize, |
| 1071 | ) |
| 1072 | if (exportsId !== undefined) { |
| 1073 | relativeId = exportsId + postfix |
| 1074 | } else { |
| 1075 | relativeId = undefined |
| 1076 | } |
| 1077 | } else { |
| 1078 | // not exposed |
| 1079 | relativeId = undefined |
| 1080 | } |
| 1081 | if (!relativeId) { |
| 1082 | throw new Error( |
| 1083 | `Package subpath '${relativeId}' is not defined by "exports" in ` + |
| 1084 | `${path.join(dir, 'package.json')}.`, |
| 1085 | ) |
| 1086 | } |
| 1087 | } else if (options.mainFields.includes('browser') && isObject(browserField)) { |
| 1088 | // resolve without postfix (see #7098) |
| 1089 | const { file, postfix } = splitFileAndPostfix(relativeId) |
| 1090 | const mapped = mapWithBrowserField(file, browserField) |
| 1091 | if (mapped) { |
| 1092 | relativeId = mapped + postfix |
| 1093 | } else if (mapped === false) { |
| 1094 | setResolvedCache(id, browserExternalId, options) |
| 1095 | return browserExternalId |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | if (relativeId) { |
| 1100 | const resolved = tryFsResolve( |
| 1101 | path.join(dir, relativeId), |
| 1102 | options, |
| 1103 | !exportsField, // try index only if no exports field |
nothing calls this directly
no test coverage detected