1
1
import { parse , join } from "path" ;
2
2
import { statSync } from "fs" ;
3
3
4
- export function getResolver ( platforms : string [ ] , explicitResolve : string [ ] = [ ] ) {
5
- const platformSpecificExt = [ ".ts" , ".js" , ".scss" , ".less" , ".css" , ".html" , ".xml" , ".vue" , ".json" ] ;
6
- const nsPackageFilters = [
7
- 'nativescript' ,
8
- 'tns' ,
9
- 'ns'
10
- ] ;
4
+ export function getResolver ( platforms : string [ ] , options : { nsPackageFilters ?: string [ ] , explicitResolve ?: string [ ] , platformSpecificExt ?: string [ ] } = { } ) {
5
+ options . nsPackageFilters = options . nsPackageFilters || [ 'nativescript' , 'tns' , 'ns' ] ;
6
+ options . explicitResolve = options . explicitResolve || [ ] ;
7
+ options . platformSpecificExt = options . platformSpecificExt || [ ".ts" , ".js" , ".scss" , ".less" , ".css" , ".html" , ".xml" , ".vue" , ".json" ] ;
8
+
9
+ const { nsPackageFilters, explicitResolve, platformSpecificExt } = options ;
11
10
12
11
return function ( path : string ) {
13
12
const nmIndex = path . lastIndexOf ( 'node_modules' ) ;
@@ -16,7 +15,7 @@ export function getResolver(platforms: string[], explicitResolve: string[] = [])
16
15
const subPath = path . substr ( nmIndex + 'node_modules' . length ) . replace ( / \\ / g, '/' ) ;
17
16
const shouldResolve = explicitResolve . length && explicitResolve . some ( packageName => subPath . indexOf ( packageName ) !== - 1 ) ;
18
17
const pathParts = subPath . split ( / [ / \- _ ] / ) ;
19
-
18
+
20
19
if ( ! shouldResolve && pathParts . every ( p => nsPackageFilters . every ( f => f !== p ) ) ) {
21
20
return path ;
22
21
}
0 commit comments