@@ -66,13 +66,17 @@ function resolveFile(source, file, config) {
66
66
// iff path is neither absolute nor relative
67
67
if (
68
68
/ \. j s x ? $ / . test ( foundNodePath ) &&
69
- ! / ^ @ t y p e s [ \ /\\ ] / . test ( source ) &&
69
+ ! / ^ @ t y p e s [ / \\ ] / . test ( source ) &&
70
70
! path . isAbsolute ( source ) &&
71
71
source [ 0 ] !== '.'
72
72
) {
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 ;
76
80
}
77
81
}
78
82
@@ -91,12 +95,29 @@ function resolveFile(source, file, config) {
91
95
found : false ,
92
96
} ;
93
97
}
98
+
94
99
function packageFilter ( pkg ) {
95
100
pkg . main =
96
101
pkg . types || pkg . typings || pkg . module || pkg [ 'jsnext:main' ] || pkg . main ;
97
102
return pkg ;
98
103
}
99
104
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
+
100
121
module . exports = {
101
122
interfaceVersion : 2 ,
102
123
resolve : resolveFile ,
0 commit comments