-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat: lock project during build or generate #4985
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #4985 +/- ##
==========================================
+ Coverage 95.05% 96.07% +1.01%
==========================================
Files 72 73 +1
Lines 2425 2469 +44
Branches 616 624 +8
==========================================
+ Hits 2305 2372 +67
+ Misses 100 82 -18
+ Partials 20 15 -5
Continue to review full report at Codecov.
|
@@ -44,6 +45,25 @@ export default { | |||
config.build.analyze = false | |||
|
|||
const nuxt = await cmd.getNuxt(config) | |||
|
|||
if (cmd.argv.lock) { | |||
cmd.setLock(await createLock({ |
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.
Is it useful at all to create separate locks for the build and generate phases?
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.
@pimlie As "build" is also included in the generate step, we could remove the lock after build for nuxt build
and after generate for nuxt generate
(if we can distinguish)
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.
We could distinguish by either using different id's or using different lock dir's. Besides as a proof-of-concept I thought having separate locks might be useful in an edge-case where the generate phase takes quiet a while to run but in the mean time you want to already rebuild the project because you also want to run the nuxt server but with a slightly different configuration.
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.
If you want to distinguish between (similar) locks started by separate commands we could remove the lock id
from the actual lockPath but then we should add a mapping between lockPaths and id's.
return Object.assign({}, defaultLockOptions, options) | ||
} | ||
|
||
export function createLockPath({ id = 'nuxt', dir, root }) { |
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 added the id
due to a remark of pi0 in the rfc about having separate locks for separate commands. I agree that that wouldnt be very useful, but having the possibility to have different locks on the same dir could be useful. Also the id
is printed in the error when a lock already exists and could be useful to have a clearer understanding of why the lock exists in the first place
packages/utils/src/locking.js
Outdated
export const lockPaths = new Set() | ||
|
||
export const defaultLockOptions = { | ||
stale: 30000, |
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.
There is no direct need for checking the validity of a lockfile when a lock already exists, proper-lockfile
sets a timer which updates the lockfile regularly and if a lockfile exists it already checks for staleness. See here for more info: https://github.com/moxystudio/node-proper-lockfile#comparison
I have set a default value for staleness of 30s, but maybe thats a bit much and we can just use the default value.
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.
Overall LGTM
fix: getGenerator mocking chore: add test for checking double locking by generate
@@ -1,4 +1,4 @@ | |||
|
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.
Maybe we could add an eslint rule for this?
This is causing an error when building on netlify
|
You can run nuxt with Any idea if this is netlify specific or ci generic? Maybe we should turn locking of by default then when running on ci? |
@husayt Could you maybe create a small reproduction that triggers the error? I tried adding timers in a build:before hook and asyncData (see here: https://github.com/pimlie/nuxt-issues/) but netlify still builds my site |
@pimlie seems like it is working now, but not sure if it is latest version or some of my workarounds. I will keep my eye on it and will let you know, if anything. Thank you |
@husayt Thanks for the feedback. It seems it was not just you, @aldarund also had issues with it on wercker. There appears to be an issue with proper-lockfile due to the staleness timer not updating the lock under heavy cpu load, but there might be another issue as well. Still investigating, so please let me know here or on discord if it happens again (and if you can help with a small reproduction that always triggers on netlify that would be very helpful) |
I have it again, this time with To get no lock working I had to use |
Types of changes
Description
This PR adds support for locking as proposed in nuxt/rfcs#23
I was not sure about the usefulness of locking when running
nuxt dev
, but will add it if you think it should also support it.Checklist: