Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/get-modules-matcher.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { memoize } from 'ramda';

/**
* Creates a test function from a list of module names. The resulting function
* accepts a string id and returns whether it matches a module in the list.
Expand All @@ -9,8 +11,6 @@
* @returns {function(String): (boolean)} Predicate function accepting a string id.
*/
export default function getModulesMatcher(modulesNames) {
const regexps = modulesNames.map(moduleRegExp);
return id => regexps.some(regexp => regexp.test(id));
const modulesPattern = new RegExp(`^(${modulesNames.join("|")})($|/)`);
return memoize(id => modulesPattern.test(id));
}

const moduleRegExp = module => new RegExp(`^${module}(\\/\.+)*$`);