From f9f45a287798a05b6abdaca50035b171128fd305 Mon Sep 17 00:00:00 2001 From: Simon Nilius Date: Thu, 15 Jul 2021 17:09:39 +0200 Subject: [PATCH] feat(): reduce generated moduleNameMapper entry to one line using an optimized regex which matches either an empty string or the subpath after the packageRoot --- src/lib/library/library.factory.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/library/library.factory.ts b/src/lib/library/library.factory.ts index 3d641675a..6b9796436 100644 --- a/src/lib/library/library.factory.ts +++ b/src/lib/library/library.factory.ts @@ -113,11 +113,9 @@ function updateJestConfig( if (!jestOptions.moduleNameMapper) { jestOptions.moduleNameMapper = {}; } - const packageKeyRegex = '^' + packageKey + '$'; - const deepPackagePathRegex = '^' + packageKey + '/(.*)' + '$'; + const packageKeyRegex = '^' + packageKey + '(|/.*)$'; const packageRoot = join('' as Path, distRoot); - jestOptions.moduleNameMapper[deepPackagePathRegex] = join(packageRoot, '$1'); - jestOptions.moduleNameMapper[packageKeyRegex] = packageRoot; + jestOptions.moduleNameMapper[packageKeyRegex] = join(packageRoot, '$1'); } function updateNpmScripts(