@@ -66,13 +66,17 @@ function resolveFile(source, file, config) {
6666 // iff path is neither absolute nor relative
6767 if (
6868 / \. j s x ? $ / . test ( foundNodePath ) &&
69- ! / ^ @ t y p e s [ \ /\\ ] / . test ( source ) &&
69+ ! / ^ @ t y p e s [ / \\ ] / . test ( source ) &&
7070 ! path . isAbsolute ( source ) &&
7171 source [ 0 ] !== '.'
7272 ) {
73- const definitely = resolveFile ( '@types/' + source , file , config ) ;
74- if ( definitely . found ) {
75- return definitely ;
73+ const definitelyTyped = resolveFile (
74+ '@types' + path . sep + mangleScopedPackage ( source ) ,
75+ file ,
76+ config ,
77+ ) ;
78+ if ( definitelyTyped . found ) {
79+ return definitelyTyped ;
7680 }
7781 }
7882
@@ -91,12 +95,29 @@ function resolveFile(source, file, config) {
9195 found : false ,
9296 } ;
9397}
98+
9499function packageFilter ( pkg ) {
95100 pkg . main =
96101 pkg . types || pkg . typings || pkg . module || pkg [ 'jsnext:main' ] || pkg . main ;
97102 return pkg ;
98103}
99104
105+ /**
106+ * For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`.
107+ *
108+ * @param {string } moduleName
109+ * @returns {string }
110+ */
111+ function mangleScopedPackage ( moduleName ) {
112+ if ( moduleName [ 0 ] === '@' ) {
113+ const replaceSlash = moduleName . replace ( path . sep , '__' ) ;
114+ if ( replaceSlash !== moduleName ) {
115+ return replaceSlash . slice ( 1 ) ; // Take off the "@"
116+ }
117+ }
118+ return moduleName ;
119+ }
120+
100121module . exports = {
101122 interfaceVersion : 2 ,
102123 resolve : resolveFile ,
0 commit comments