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(
42
42
let knownFramework = options . knownFramework || [ ]
43
43
let knownFirstparty = options . knownFirstparty || [ ]
44
44
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
+
45
57
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 )
50
59
}
51
60
52
61
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 )
57
63
}
58
64
59
65
return [
You can’t perform that action at this time.
0 commit comments