-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore rootDir to determine the cache key of transformed files in babel-jest #7947
Ignore rootDir to determine the cache key of transformed files in babel-jest #7947
Conversation
3a5f5ea
to
b653405
Compare
packages/babel-jest/src/index.ts
Outdated
.update(JSON.stringify(babelOptions.options)) | ||
.update( | ||
// Not pretty but not coupled to a specific signature of the | ||
// babel options to relativize paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on this? 🤷🏻♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the replacer
argument of JSON.stringify
to do the transform on-the-fly while serializing. The current approach is hacky, and might fail for paths containing weird characters (e.g. a double quote, which will appear in JSON as \\"
; or in Windows, where the backslash is double-escaped (i.e. \\
).
9e8b58e
to
47ffedb
Compare
@mjesun does this lgty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test is failing on Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Let's get rid of the ugly $1
, though.
packages/babel-jest/src/index.ts
Outdated
// babel options to relativize paths | ||
return JSON.stringify(babelOptions.options, (_key, value) => { | ||
if (typeof value === 'string') { | ||
return value.replace(rootDirRegExp, '<rootDir>$1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return value.replace(rootDirRegExp, '<rootDir>$1'); | |
return value.replace(rootDirRegExp, '<rootDir>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I thought lookahead wasn't supported in Node <9 but that was lookbehind 😅😅
Bah, ignore the node 6 failure, I'll fix it tomorrow. syntax error in a babel plugin (trailing function commas), nothing major |
@SimenB no worries, there's no rush. I can fix it tomorrow. |
ba8e8bb
to
f9d0ca6
Compare
f9d0ca6
to
3aacfa0
Compare
After some internal testing we've decided not to go forward with this approach. We've found that there are some cases where parent directories of the We were using
If we wanted to fix this in Sorry guys I wasted your time with this one (at least it was useful to find #7945). |
Could babel improve their algorithm? Seems silly to crawl the FS e.g. for sibling files - you'll find the same thing (barring |
I assume they do have an in-memory cache for that, but that's still not great for our use case. It's also not our main blocker (we knew about it and could've accepted the consequences). |
So they don't actually crawl for every single file? (sorry, just trying to understand) |
I'm not an expert but I see some caching mechanisms here: https://github.com/babel/babel/blob/master/packages/babel-core/src/config/config-chain.js I'd say the correct thing to do is to have an in-memory cache of the babel configuration files and then merge and apply for each file, but I haven't checked it's actually what it does. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Removes the root directory from the determination of the cache key in
babel-jest
.The cache directory used by Jest depends on the root directory so different projects store their artifacts in different caches. With that guarantee, we don't need to take the root directory into account to compute the cache key of the transformed files, so we can store them remotely and restore them in different hosts/locations.
Test plan
Added a test to verify this behaviour.
In terms of performance, we crawl the filesystem by default to find Babel configuration files and that's an order of magnitude higher than the additional processing we're doing with this change.