|
1 | 1 | import { CustomResolutionContext, CustomResolver } from 'metro-resolver' |
2 | | -import { basename, dirname, join, sep } from 'node:path' |
| 2 | +import { basename, dirname, sep } from 'node:path' |
3 | 3 |
|
4 | 4 | type ResolverConfig = { |
5 | 5 | platform: string | null |
@@ -45,12 +45,11 @@ export const nativeResolver = ({ |
45 | 45 | const resolution = resolver(context, moduleName, platform) |
46 | 46 |
|
47 | 47 | if (cachedInternalBasePath === null) { |
48 | | - const componentsResolution = resolver(context, 'uniwind/components', platform) |
49 | | - |
50 | | - cachedInternalBasePath = componentsResolution.type === 'sourceFile' |
51 | | - // Go from src/components to root |
52 | | - ? join(dirname(componentsResolution.filePath), '../..') |
53 | | - : '' |
| 48 | + try { |
| 49 | + cachedInternalBasePath = dirname(require.resolve('uniwind/package.json')) |
| 50 | + } catch { |
| 51 | + cachedInternalBasePath = '' |
| 52 | + } |
54 | 53 | } |
55 | 54 |
|
56 | 55 | const isInternal = cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath) |
@@ -94,13 +93,13 @@ export const webResolver = ({ |
94 | 93 | const resolution = resolver(context, moduleName, platform) |
95 | 94 |
|
96 | 95 | if (cachedInternalBasePath === null) { |
97 | | - const componentsResolution = resolver(context, 'uniwind/components', platform) |
98 | | - |
99 | | - cachedInternalBasePath = componentsResolution.type === 'sourceFile' |
100 | | - // Go from dist/module/components/web to root |
101 | | - ? join(dirname(componentsResolution.filePath), '../../../..') |
102 | | - : '' |
| 96 | + try { |
| 97 | + cachedInternalBasePath = dirname(require.resolve('uniwind/package.json')) |
| 98 | + } catch { |
| 99 | + cachedInternalBasePath = '' |
| 100 | + } |
103 | 101 | } |
| 102 | + |
104 | 103 | if ( |
105 | 104 | (cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath)) |
106 | 105 | || resolution.type !== 'sourceFile' |
|
0 commit comments