Skip to content
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

Merged
merged 11 commits into from
Mar 3, 2019
Merged

Conversation

pimlie
Copy link

@pimlie pimlie commented Feb 8, 2019

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@codecov-io
Copy link

codecov-io commented Feb 8, 2019

Codecov Report

Merging #4985 into dev will increase coverage by 1.01%.
The diff coverage is 97.77%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/cli/src/utils/index.js 96.72% <0%> (+35.05%) ⬆️
packages/utils/src/locking.js 100% <100%> (ø)
packages/cli/src/command.js 98.87% <100%> (+0.15%) ⬆️
packages/cli/src/commands/generate.js 100% <100%> (ø) ⬆️
packages/cli/src/commands/build.js 86.36% <100%> (+1.36%) ⬆️
packages/cli/src/utils/formatting.js 80.95% <0%> (+9.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04cdd60...6036de5. Read the comment docs.

@@ -44,6 +45,25 @@ export default {
config.build.analyze = false

const nuxt = await cmd.getNuxt(config)

if (cmd.argv.lock) {
cmd.setLock(await createLock({
Copy link
Author

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?

Copy link
Member

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)

Copy link
Author

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.

Copy link
Author

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 }) {
Copy link
Author

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

export const lockPaths = new Set()

export const defaultLockOptions = {
stale: 30000,
Copy link
Author

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.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

packages/cli/src/command.js Show resolved Hide resolved
packages/cli/src/utils/index.js Show resolved Hide resolved
@galvez galvez assigned manniL and pimlie and unassigned manniL Feb 8, 2019
@@ -1,4 +1,4 @@

Copy link
Author

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?

pi0
pi0 previously approved these changes Feb 11, 2019
@pi0 pi0 merged commit 4e51723 into nuxt:dev Mar 3, 2019
@husayt
Copy link
Contributor

husayt commented Mar 4, 2019

This is causing an error when building on netlify

12:26:56 PM: webpackbar 12:26:56 ℹ Compiling Client
12:27:18 PM: /opt/build/repo/node_modules/proper-lockfile/lib/lockfile.js:181
12:27:18 PM:         onCompromised: (err) => { throw err; },
12:27:18 PM:                                   ^
12:27:18 PM: Error: Unable to update lock within the stale threshold
12:27:18 PM:     at options.fs.utimes (/opt/build/repo/node_modules/proper-lockfile/lib/lockfile.js:109:21)
12:27:18 PM:     at FSReqWrap.oncomplete (fs.js:135:15)

@pimlie
Copy link
Author

pimlie commented Mar 4, 2019

You can run nuxt with --no-lock to disable locking.

Any idea if this is netlify specific or ci generic? Maybe we should turn locking of by default then when running on ci?

@pimlie pimlie deleted the feat-lock-file branch March 4, 2019 13:22
@pimlie
Copy link
Author

pimlie commented Mar 5, 2019

@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

@husayt
Copy link
Contributor

husayt commented Mar 6, 2019

@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

@pimlie
Copy link
Author

pimlie commented Mar 6, 2019

@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)

@husayt
Copy link
Contributor

husayt commented Mar 13, 2019

I have it again, this time with nuxt-ts and --no-lock doesn't help either

To get no lock working I had to use -- --no-lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants