fix(react-native): use metro default resolver on tsconfig import (#8656)
use metro default resolver on tsconfig match result. it fixes tsconfig paths import with index files
This commit is contained in:
parent
e008caf9f9
commit
0182df4b9f
@ -44,7 +44,13 @@ export function getResolveRequest(extensions: string[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tsconfigPathsResolver(extensions, realModuleName, moduleName);
|
return tsconfigPathsResolver(
|
||||||
|
context,
|
||||||
|
extensions,
|
||||||
|
realModuleName,
|
||||||
|
moduleName,
|
||||||
|
platform
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +59,7 @@ export function getResolveRequest(extensions: string[]) {
|
|||||||
* @returns path if resolved, else undefined
|
* @returns path if resolved, else undefined
|
||||||
*/
|
*/
|
||||||
function defaultMetroResolver(
|
function defaultMetroResolver(
|
||||||
context: string,
|
context: any,
|
||||||
moduleName: string,
|
moduleName: string,
|
||||||
platform: string
|
platform: string
|
||||||
) {
|
) {
|
||||||
@ -103,28 +109,23 @@ function pnpmResolver(extensions, context, realModuleName, moduleName) {
|
|||||||
* @returns path if resolved, else undefined
|
* @returns path if resolved, else undefined
|
||||||
*/
|
*/
|
||||||
function tsconfigPathsResolver(
|
function tsconfigPathsResolver(
|
||||||
|
context: any,
|
||||||
extensions: string[],
|
extensions: string[],
|
||||||
realModuleName: string,
|
realModuleName: string,
|
||||||
moduleName: string
|
moduleName: string,
|
||||||
|
platform: string
|
||||||
) {
|
) {
|
||||||
const DEBUG = process.env.NX_REACT_NATIVE_DEBUG === 'true';
|
const DEBUG = process.env.NX_REACT_NATIVE_DEBUG === 'true';
|
||||||
const matcher = getMatcher();
|
const matcher = getMatcher();
|
||||||
let match;
|
const match = matcher(
|
||||||
|
realModuleName,
|
||||||
// find out the file extension
|
undefined,
|
||||||
const matchExtension = extensions.find((extension) => {
|
undefined,
|
||||||
match = matcher(realModuleName, undefined, undefined, ['.' + extension]);
|
extensions.map((ext) => `.${ext}`)
|
||||||
return !!match;
|
);
|
||||||
});
|
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
return {
|
return metroResolver.resolve(context, match, platform);
|
||||||
type: 'sourceFile',
|
|
||||||
filePath:
|
|
||||||
!matchExtension || match.endsWith(`.${matchExtension}`)
|
|
||||||
? match
|
|
||||||
: `${match}.${matchExtension}`,
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user