Skip to content
Snippets Groups Projects
Unverified Commit b06af660 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(regex): Inverse dependency on logger util (#26997)

parent 3ea3fa26
No related branches found
No related tags found
No related merge requests found
...@@ -2,24 +2,34 @@ import is from '@sindresorhus/is'; ...@@ -2,24 +2,34 @@ import is from '@sindresorhus/is';
import { CONFIG_VALIDATION } from '../constants/error-messages'; import { CONFIG_VALIDATION } from '../constants/error-messages';
import { re2 } from '../expose.cjs'; import { re2 } from '../expose.cjs';
import { logger } from '../logger';
let RegEx: RegExpConstructor;
const cache = new Map<string, RegExp>(); const cache = new Map<string, RegExp>();
if (!process.env.RENOVATE_X_IGNORE_RE2) { type RegExpEngineStatus =
| { type: 'available' }
| {
type: 'unavailable';
err: Error;
}
| { type: 'ignored' };
let status: RegExpEngineStatus;
let RegEx: RegExpConstructor = RegExp;
// istanbul ignore next
if (process.env.RENOVATE_X_IGNORE_RE2) {
status = { type: 'ignored' };
} else {
try { try {
const RE2 = re2(); const RE2 = re2();
// Test if native is working // Test if native is working
new RE2('.*').exec('test'); new RE2('.*').exec('test');
logger.debug('Using RE2 as regex engine');
RegEx = RE2; RegEx = RE2;
status = { type: 'available' };
} catch (err) { } catch (err) {
logger.warn({ err }, 'RE2 not usable, falling back to RegExp'); status = { type: 'unavailable', err };
} }
} }
RegEx ??= RegExp;
export const regexEngineStatus = status;
export function regEx( export function regEx(
pattern: string | RegExp, pattern: string | RegExp,
...@@ -49,7 +59,6 @@ export function regEx( ...@@ -49,7 +59,6 @@ export function regEx(
} }
return instance; return instance;
} catch (err) { } catch (err) {
logger.trace({ err }, 'RegEx constructor error');
const error = new Error(CONFIG_VALIDATION); const error = new Error(CONFIG_VALIDATION);
error.validationMessage = err.message; error.validationMessage = err.message;
error.validationSource = pattern.toString(); error.validationSource = pattern.toString();
......
...@@ -20,6 +20,7 @@ import { getProblems, logger, setMeta } from '../../logger'; ...@@ -20,6 +20,7 @@ import { getProblems, logger, setMeta } from '../../logger';
import * as hostRules from '../../util/host-rules'; import * as hostRules from '../../util/host-rules';
import * as queue from '../../util/http/queue'; import * as queue from '../../util/http/queue';
import * as throttle from '../../util/http/throttle'; import * as throttle from '../../util/http/throttle';
import { regexEngineStatus } from '../../util/regex';
import { addSecretForSanitizing } from '../../util/sanitize'; import { addSecretForSanitizing } from '../../util/sanitize';
import * as repositoryWorker from '../repository'; import * as repositoryWorker from '../repository';
import { autodiscoverRepositories } from './autodiscover'; import { autodiscoverRepositories } from './autodiscover';
...@@ -111,6 +112,18 @@ export async function resolveGlobalExtends( ...@@ -111,6 +112,18 @@ export async function resolveGlobalExtends(
} }
export async function start(): Promise<number> { export async function start(): Promise<number> {
// istanbul ignore next
if (regexEngineStatus.type === 'available') {
logger.debug('Using RE2 regex engine');
} else if (regexEngineStatus.type === 'unavailable') {
logger.warn(
{ err: regexEngineStatus.err },
'RE2 not usable, falling back to RegExp',
);
} else if (regexEngineStatus.type === 'ignored') {
logger.debug('RE2 regex engine is ignored via RENOVATE_X_IGNORE_RE2');
}
let config: AllConfig; let config: AllConfig;
try { try {
if (is.nonEmptyStringAndNotWhitespace(process.env.AWS_SECRET_ACCESS_KEY)) { if (is.nonEmptyStringAndNotWhitespace(process.env.AWS_SECRET_ACCESS_KEY)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment