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
Tags 30.0.0
No related merge requests found
......@@ -2,24 +2,34 @@ import is from '@sindresorhus/is';
import { CONFIG_VALIDATION } from '../constants/error-messages';
import { re2 } from '../expose.cjs';
import { logger } from '../logger';
let RegEx: RegExpConstructor;
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 {
const RE2 = re2();
// Test if native is working
new RE2('.*').exec('test');
logger.debug('Using RE2 as regex engine');
RegEx = RE2;
status = { type: 'available' };
} 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(
pattern: string | RegExp,
......@@ -49,7 +59,6 @@ export function regEx(
}
return instance;
} catch (err) {
logger.trace({ err }, 'RegEx constructor error');
const error = new Error(CONFIG_VALIDATION);
error.validationMessage = err.message;
error.validationSource = pattern.toString();
......
......@@ -20,6 +20,7 @@ import { getProblems, logger, setMeta } from '../../logger';
import * as hostRules from '../../util/host-rules';
import * as queue from '../../util/http/queue';
import * as throttle from '../../util/http/throttle';
import { regexEngineStatus } from '../../util/regex';
import { addSecretForSanitizing } from '../../util/sanitize';
import * as repositoryWorker from '../repository';
import { autodiscoverRepositories } from './autodiscover';
......@@ -111,6 +112,18 @@ export async function resolveGlobalExtends(
}
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;
try {
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.
Finish editing this message first!
Please register or to comment