File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -42,18 +42,24 @@ export default function(
4242 let knownFramework = options . knownFramework || [ ]
4343 let knownFirstparty = options . knownFirstparty || [ ]
4444
45+ /**
46+ * Transforms the option string to JSON and back again, so that
47+ * RegExp escapes are maintained.
48+ */
49+ function moduleMatchesOption ( module , option ) {
50+ let [ base ] = module . split ( path . sep )
51+ return [ option ] . some ( ( opt : string ) => {
52+ let pattern = JSON . parse ( `{"regex": ${ JSON . stringify ( opt ) } }` )
53+ return RegExp ( `${ pattern } $` ) . test ( base )
54+ } )
55+ }
56+
4557 function isFrameworkModule ( imported : IImport ) {
46- let [ base ] = imported . moduleName . split ( path . sep )
47- return knownFramework . some ( ( prefix : string ) =>
48- RegExp ( `${ prefix } $` ) . test ( base ) ,
49- )
58+ return moduleMatchesOption ( imported . moduleName , knownFramework )
5059 }
5160
5261 function isFirstPartyModule ( imported : IImport ) {
53- let [ base ] = imported . moduleName . split ( path . sep )
54- return knownFirstparty . some ( ( prefix : string ) =>
55- RegExp ( `${ prefix } $` ) . test ( base ) ,
56- )
62+ return moduleMatchesOption ( imported . moduleName , knownFirstparty )
5763 }
5864
5965 return [
You can’t perform that action at this time.
0 commit comments