Skip to content

Commit 3dd058f

Browse files
committed
Improve regex to replace root dir
1 parent bb17736 commit 3dd058f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/babel-jest/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
transformSync as babelTransform,
1818
} from '@babel/core';
1919
import chalk from 'chalk';
20-
import {escapeStrForRegex} from 'jest-regex-util';
20+
import {escapePathForRegex} from 'jest-regex-util';
2121
import slash from 'slash';
2222

2323
const THIS_FILE = fs.readFileSync(__filename);
@@ -69,7 +69,7 @@ const createTransformer = (
6969
function getRootDirRegExp(rootDir: Config.Path): RegExp {
7070
if (!rootDirRegExpCache[rootDir]) {
7171
rootDirRegExpCache[rootDir] = new RegExp(
72-
`^${escapeStrForRegex(rootDir)}(${escapeStrForRegex(path.sep)}|$)`,
72+
`^${escapePathForRegex(rootDir)}(?=${escapePathForRegex(path.sep)}|$)`,
7373
);
7474
}
7575

@@ -86,7 +86,7 @@ const createTransformer = (
8686
// babel options to relativize paths
8787
return JSON.stringify(babelOptions.options, (_key, value) => {
8888
if (typeof value === 'string') {
89-
return value.replace(rootDirRegExp, '<rootDir>$1');
89+
return value.replace(rootDirRegExp, '<rootDir>');
9090
}
9191
return value;
9292
});

0 commit comments

Comments
 (0)