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
refactor: use fs.promises #4314
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4314 +/- ##
==========================================
- Coverage 98.69% 98.46% -0.23%
==========================================
Files 205 205
Lines 7331 7306 -25
Branches 2084 2082 -2
==========================================
- Hits 7235 7194 -41
- Misses 36 54 +18
+ Partials 60 58 -2
Continue to review full report at Codecov.
|
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.
Looks like a good improvement!
src/utils/fs.ts
Outdated
new Promise<string>((fulfil, reject) => | ||
fs.readFile(file, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents))) | ||
); | ||
export function readFile(file: string): Promise<string> { |
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.
I think we could inline this one as it only existed to do manual promise wrapping 😉
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.
aaah, ok. I was under the impression that it had to be in that fs.ts
file because of the browser
build. that was just a bad guess tho without having looked into the details.
in that case, I'll remove it. 👍
src/utils/fs.ts
Outdated
const dir = dirname(path); | ||
fs.mkdirSync(dir, { recursive: true }); | ||
await fs.mkdir(dir, { recursive: true }); |
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.
While we are inlining things, considering this has recently been reduced to two lines and the only usage location is also a very short one, maybe inline it as well? But you can also keep it separate if you prefer.
just noticed the re-export of 'fs': |
5c4978c
to
ca8887e
Compare
it seems the tests are having some timing issues now since everything is full async. responsible for some of the failures is the order of module ids, which, in an async context, are non-deterministic. I suppose the fsSync methods (plus the callback Promise wrapper) somehow made those deterministic (or "deterministic enough"). |
The removal of blocking I/O in this PR could potentially improve CPU utilization in rollup for faster overall bundling speed. How much effort would be involved to rework the 9 failing tests due to the race conditions exposed by this PR? Side note: the potential speed gains could be limited by the use of sync
|
I haven't looked at this PR for a while as I was waiting for the mac ci run to stabilize first.
yeah, I was hoping for the same.
good question. I vaguely remember it had to do with the sorting of imported module ids. let me rebase this to refresh my mind. |
5afb390
to
2cea507
Compare
I'll get back to this one after: #4319 |
de74a3a
to
2cea507
Compare
@kzc we should probably look into the plugin code (eventually) as well. |
I'll break this PR up into smaller PRs. that way, some non-test-breaking things can be pulled in separately. |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
since the code already has an async flow, I think it makes sense to use the fs promise functions replacing the synchronous (aka blocking) versions as well as the callback Promise wrapped functions. also added some additional typings.
note:
while
import { promises as fs } from 'fs'
is a bit on the uglier side of things, we can change it toimport { readFile } from 'fs/promises'
for v3 (if targeting node.js v14+)