@@ -16,6 +16,11 @@ import type {TransformResultDependency} from '../types.flow';
16
16
import type { InputConfigT } from 'metro-config/src/configTypes.flow' ;
17
17
18
18
const { getDefaultConfig, mergeConfig} = require ( 'metro-config' ) ;
19
+ const { AmbiguousModuleResolutionError} = require ( 'metro-core' ) ;
20
+ const {
21
+ DuplicateHasteCandidatesError,
22
+ default : { H : Haste } ,
23
+ } = require ( 'metro-file-map' ) ;
19
24
const path = require ( 'path' ) ;
20
25
const mockPlatform = process . platform ;
21
26
31
36
endianness : ( ) => 'LE' ,
32
37
release : ( ) => '' ,
33
38
} ) )
34
- . mock ( 'graceful-fs' , ( ) => require ( 'fs' ) ) ;
39
+ . mock ( 'graceful-fs' , ( ) => require ( 'fs' ) )
40
+ . spyOn ( console , 'warn' )
41
+ . mockImplementation ( ( ) => { } ) ;
35
42
36
43
jest . setTimeout ( 10000 ) ;
37
44
@@ -1793,9 +1800,7 @@ function dep(name: string): TransformResultDependency {
1793
1800
} ) ;
1794
1801
} ) ;
1795
1802
1796
- test ( 'fatals on multiple packages with the same name' , async ( ) => {
1797
- // $FlowFixMe[cannot-write]
1798
- console . warn = jest . fn ( ) ;
1803
+ test ( 'resolution throws on multiple packages with the same name' , async ( ) => {
1799
1804
setMockFileSystem ( {
1800
1805
'index.js' : '' ,
1801
1806
aPackage : {
@@ -1807,10 +1812,9 @@ function dep(name: string): TransformResultDependency {
1807
1812
} ,
1808
1813
} ) ;
1809
1814
1810
- await expect ( createResolver ( config ) ) . rejects . toThrow (
1811
- 'Duplicated files or mocks. Please check the console for more info' ,
1812
- ) ;
1813
- expect ( console . error ) . toHaveBeenCalledWith (
1815
+ resolver = await createResolver ( config ) ;
1816
+
1817
+ expect ( console . warn ) . toHaveBeenCalledWith (
1814
1818
[
1815
1819
'metro-file-map: Haste module naming collision: aPackage' ,
1816
1820
' The following files share their name; please adjust your hasteImpl:' ,
@@ -1823,9 +1827,26 @@ function dep(name: string): TransformResultDependency {
1823
1827
'' ,
1824
1828
] . join ( '\n' ) ,
1825
1829
) ;
1830
+
1831
+ expect ( ( ) =>
1832
+ resolver . resolve ( p ( '/root/index.js' ) , dep ( 'aPackage' ) ) ,
1833
+ ) . toThrowError (
1834
+ new AmbiguousModuleResolutionError (
1835
+ p ( '/root/index.js' ) ,
1836
+ new DuplicateHasteCandidatesError (
1837
+ 'aPackage' ,
1838
+ Haste . GENERIC_PLATFORM ,
1839
+ false ,
1840
+ new Map ( [
1841
+ [ p ( '/root/aPackage/package.json' ) , Haste . PACKAGE ] ,
1842
+ [ p ( '/root/anotherPackage/package.json' ) , Haste . PACKAGE ] ,
1843
+ ] ) ,
1844
+ ) ,
1845
+ ) . message ,
1846
+ ) ;
1826
1847
} ) ;
1827
1848
1828
- test ( 'does not support multiple global packages for different platforms' , async ( ) => {
1849
+ test ( 'resolution throws on multiple global packages for different platforms' , async ( ) => {
1829
1850
setMockFileSystem ( {
1830
1851
'index.js' : '' ,
1831
1852
'aPackage.android.js' : {
@@ -1838,10 +1859,9 @@ function dep(name: string): TransformResultDependency {
1838
1859
} ,
1839
1860
} ) ;
1840
1861
1841
- await expect ( createResolver ( config ) ) . rejects . toThrow (
1842
- 'Duplicated files or mocks. Please check the console for more info' ,
1843
- ) ;
1844
- expect ( console . error ) . toHaveBeenCalledWith (
1862
+ resolver = await createResolver ( config , 'ios' ) ;
1863
+
1864
+ expect ( console . warn ) . toHaveBeenCalledWith (
1845
1865
[
1846
1866
'metro-file-map: Haste module naming collision: aPackage' ,
1847
1867
' The following files share their name; please adjust your hasteImpl:' ,
@@ -1858,6 +1878,23 @@ function dep(name: string): TransformResultDependency {
1858
1878
'' ,
1859
1879
] . join ( '\n' ) ,
1860
1880
) ;
1881
+
1882
+ expect ( ( ) =>
1883
+ resolver . resolve ( p ( '/root/index.js' ) , dep ( 'aPackage' ) ) ,
1884
+ ) . toThrowError (
1885
+ new AmbiguousModuleResolutionError (
1886
+ p ( '/root/index.js' ) ,
1887
+ new DuplicateHasteCandidatesError (
1888
+ 'aPackage' ,
1889
+ Haste . GENERIC_PLATFORM ,
1890
+ false ,
1891
+ new Map ( [
1892
+ [ p ( '/root/aPackage.android.js/package.json' ) , Haste . PACKAGE ] ,
1893
+ [ p ( '/root/aPackage.ios.js/package.json' ) , Haste . PACKAGE ] ,
1894
+ ] ) ,
1895
+ ) ,
1896
+ ) . message ,
1897
+ ) ;
1861
1898
} ) ;
1862
1899
1863
1900
test ( 'resolves global packages before node_modules packages' , async ( ) => {
@@ -2101,17 +2138,16 @@ function dep(name: string): TransformResultDependency {
2101
2138
} ) ;
2102
2139
} ) ;
2103
2140
2104
- test ( 'fatals when there are duplicated haste names' , async ( ) => {
2141
+ test ( 'resolution throws when there are duplicated haste names' , async ( ) => {
2105
2142
setMockFileSystem ( {
2106
2143
'index.js' : '' ,
2107
2144
'hasteModule.js' : '@providesModule hasteModule' ,
2108
2145
'anotherHasteModule.js' : '@providesModule hasteModule' ,
2109
2146
} ) ;
2110
2147
2111
- await expect ( createResolver ( config ) ) . rejects . toThrow (
2112
- 'Duplicated files or mocks. Please check the console for more info' ,
2113
- ) ;
2114
- expect ( console . error ) . toHaveBeenCalledWith (
2148
+ resolver = await createResolver ( config ) ;
2149
+
2150
+ expect ( console . warn ) . toHaveBeenCalledWith (
2115
2151
[
2116
2152
'metro-file-map: Haste module naming collision: hasteModule' ,
2117
2153
' The following files share their name; please adjust your hasteImpl:' ,
@@ -2120,6 +2156,23 @@ function dep(name: string): TransformResultDependency {
2120
2156
'' ,
2121
2157
] . join ( '\n' ) ,
2122
2158
) ;
2159
+
2160
+ expect ( ( ) =>
2161
+ resolver . resolve ( p ( '/root/index.js' ) , dep ( 'hasteModule' ) ) ,
2162
+ ) . toThrowError (
2163
+ new AmbiguousModuleResolutionError (
2164
+ p ( '/root/index.js' ) ,
2165
+ new DuplicateHasteCandidatesError (
2166
+ 'hasteModule' ,
2167
+ Haste . GENERIC_PLATFORM ,
2168
+ false ,
2169
+ new Map ( [
2170
+ [ p ( '/root/anotherHasteModule.js' ) , Haste . MODULE ] ,
2171
+ [ p ( '/root/hasteModule.js' ) , Haste . MODULE ] ,
2172
+ ] ) ,
2173
+ ) ,
2174
+ ) . message ,
2175
+ ) ;
2123
2176
} ) ;
2124
2177
2125
2178
test ( 'resolves a haste module before a package in node_modules' , async ( ) => {
@@ -2143,7 +2196,7 @@ function dep(name: string): TransformResultDependency {
2143
2196
} ) ;
2144
2197
} ) ;
2145
2198
2146
- test ( 'fatals when a haste module collides with a global package' , async ( ) => {
2199
+ test ( 'resolution throws when a haste module collides with a global package' , async ( ) => {
2147
2200
setMockFileSystem ( {
2148
2201
'index.js' : '' ,
2149
2202
'hasteModule.js' : '@providesModule hasteModule' ,
@@ -2152,10 +2205,9 @@ function dep(name: string): TransformResultDependency {
2152
2205
} ,
2153
2206
} ) ;
2154
2207
2155
- await expect ( createResolver ( config ) ) . rejects . toThrow (
2156
- 'Duplicated files or mocks. Please check the console for more info' ,
2157
- ) ;
2158
- expect ( console . error ) . toHaveBeenCalledWith (
2208
+ resolver = await createResolver ( config ) ;
2209
+
2210
+ expect ( console . warn ) . toHaveBeenCalledWith (
2159
2211
[
2160
2212
'metro-file-map: Haste module naming collision: hasteModule' ,
2161
2213
' The following files share their name; please adjust your hasteImpl:' ,
@@ -2164,6 +2216,23 @@ function dep(name: string): TransformResultDependency {
2164
2216
'' ,
2165
2217
] . join ( '\n' ) ,
2166
2218
) ;
2219
+
2220
+ expect ( ( ) =>
2221
+ resolver . resolve ( p ( '/root/index.js' ) , dep ( 'hasteModule' ) ) ,
2222
+ ) . toThrowError (
2223
+ new AmbiguousModuleResolutionError (
2224
+ p ( '/root/index.js' ) ,
2225
+ new DuplicateHasteCandidatesError (
2226
+ 'hasteModule' ,
2227
+ Haste . GENERIC_PLATFORM ,
2228
+ false ,
2229
+ new Map ( [
2230
+ [ p ( '/root/aPackage/package.json' ) , Haste . PACKAGE ] ,
2231
+ [ p ( '/root/hasteModule.js' ) , Haste . MODULE ] ,
2232
+ ] ) ,
2233
+ ) ,
2234
+ ) . message ,
2235
+ ) ;
2167
2236
} ) ;
2168
2237
2169
2238
test ( 'supports collisions between haste names and global packages if they have different platforms' , async ( ) => {
@@ -2215,17 +2284,16 @@ function dep(name: string): TransformResultDependency {
2215
2284
} ) ;
2216
2285
} ) ;
2217
2286
2218
- test ( 'fatals when a filename uses a non-supported platform and there are collisions' , async ( ) => {
2287
+ test ( 'warns when a filename uses a non-supported platform and there are collisions' , async ( ) => {
2219
2288
setMockFileSystem ( {
2220
2289
'index.js' : '' ,
2221
2290
'hasteModule.js' : '@providesModule hasteModule' ,
2222
2291
'hasteModule.invalid.js' : '@providesModule hasteModule' ,
2223
2292
} ) ;
2224
2293
2225
- await expect ( createResolver ( config ) ) . rejects . toThrow (
2226
- 'Duplicated files or mocks. Please check the console for more info' ,
2227
- ) ;
2228
- expect ( console . error ) . toHaveBeenCalledWith (
2294
+ resolver = await createResolver ( config ) ;
2295
+
2296
+ expect ( console . warn ) . toHaveBeenCalledWith (
2229
2297
[
2230
2298
'metro-file-map: Haste module naming collision: hasteModule' ,
2231
2299
' The following files share their name; please adjust your hasteImpl:' ,
0 commit comments