File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,23 @@ function constant(value) {
8
8
return ( ) => value
9
9
}
10
10
11
+ function baseModule ( name ) {
12
+ if ( isScoped ( name ) ) {
13
+ const [ scope , pkg ] = name . split ( '/' )
14
+ return `${ scope } /${ pkg } `
15
+ }
16
+ const [ pkg ] = name . split ( '/' )
17
+ return pkg
18
+ }
19
+
11
20
export function isAbsolute ( name ) {
12
21
return name . indexOf ( '/' ) === 0
13
22
}
14
23
15
24
export function isBuiltIn ( name , settings ) {
25
+ const base = baseModule ( name )
16
26
const extras = ( settings && settings [ 'import/core-modules' ] ) || [ ]
17
- return builtinModules . indexOf ( name ) !== - 1 || extras . indexOf ( name ) > - 1
27
+ return builtinModules . indexOf ( base ) !== - 1 || extras . indexOf ( base ) > - 1
18
28
}
19
29
20
30
function isExternalPath ( path , name , settings ) {
Original file line number Diff line number Diff line change @@ -72,9 +72,21 @@ describe('importType(name)', function () {
72
72
it ( "should return 'builtin' for additional core modules" , function ( ) {
73
73
// without extra config, should be marked external
74
74
expect ( importType ( 'electron' , context ) ) . to . equal ( 'external' )
75
+ expect ( importType ( '@org/foobar' , context ) ) . to . equal ( 'external' )
75
76
76
77
const electronContext = testContext ( { 'import/core-modules' : [ 'electron' ] } )
77
78
expect ( importType ( 'electron' , electronContext ) ) . to . equal ( 'builtin' )
79
+
80
+ const scopedContext = testContext ( { 'import/core-modules' : [ '@org/foobar' ] } )
81
+ expect ( importType ( '@org/foobar' , scopedContext ) ) . to . equal ( 'builtin' )
82
+ } )
83
+
84
+ it ( "should return 'builtin' for resources inside additional core modules" , function ( ) {
85
+ const electronContext = testContext ( { 'import/core-modules' : [ 'electron' ] } )
86
+ expect ( importType ( 'electron/some/path/to/resource.json' , electronContext ) ) . to . equal ( 'builtin' )
87
+
88
+ const scopedContext = testContext ( { 'import/core-modules' : [ '@org/foobar' ] } )
89
+ expect ( importType ( '@org/foobar/some/path/to/resource.json' , scopedContext ) ) . to . equal ( 'builtin' )
78
90
} )
79
91
80
92
it ( "should return 'external' for module from 'node_modules' with default config" , function ( ) {
You can’t perform that action at this time.
0 commit comments