Skip to content

Commit

Permalink
fix: make re2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Jan 26, 2022
1 parent 957b11b commit cc43039
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 94 deletions.
11 changes: 9 additions & 2 deletions lib/parsers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict';

const RE2 = require('re2');
const regEx = (() => {
try {
const RE2 = require('re2');
return typeof RE2 === 'function' ? RE2 : RegExp;
} catch (e) {
return RegExp;
}
})();

const { referenceRegexp, anchoredNameRegexp, anchoredIdentifierRegexp } = require('./regexp');
const { validateDigest, isDigest } = require('./digest');
Expand Down Expand Up @@ -85,7 +92,7 @@ function _parseQualifiedName(regexp, name) {
}

exports.parseQualifiedNameOptimized = (name) => {
return _parseQualifiedName(new RE2(referenceRegexp), name);
return _parseQualifiedName(new regEx(referenceRegexp), name);
};

exports.parseQualifiedName = (name) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"rimraf": "^2.6.1",
"typescript": "^4.5.3"
},
"dependencies": {
"re2": "^1.16.0"
"optionalDependencies": {
"re2": "^1.17.3"
}
}
Loading

0 comments on commit cc43039

Please sign in to comment.