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

fix: lazy-load package.json and cache. get rid of pkg-conf dependency. #544

Merged
merged 1 commit into from Jul 9, 2016

Conversation

bcoe
Copy link
Member

@bcoe bcoe commented Jul 9, 2016

we dug into some of the performance concerns with yargs in #521, and came up with an initial quick win.

In this pull request we:

  • eliminate pkg-conf in favor of using read-pkg-up exclusively.
  • we lazy-load read-pkg-up (the require time for modules was leading to some of yargs' bad performance benchmarks).
  • we cache the package.json the first time we load it.
  • published this to next tag and made sure that pkgConf and yargs configuration continues working as expected.

@bcoe bcoe mentioned this pull request Jul 9, 2016
3 tasks
@bcoe
Copy link
Member Author

bcoe commented Jul 9, 2016

reviewers: @nexdrew, @marneborn

@coveralls
Copy link

coveralls commented Jul 9, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling eb247cf on lazy-pkg-conf into 588a8c1 on master.

@bcoe bcoe merged commit 2609b2e into master Jul 9, 2016
@bcoe bcoe deleted the lazy-pkg-conf branch July 9, 2016 20:57
@bcoe
Copy link
Member Author

bcoe commented Jul 9, 2016

tested this thoroughly on the next branch, please feel free to provide commentary after the fact -- I want to get us to a 4.8.0 release this afternoon, and start working on some of the 5.0.0 breaking changes.

options.configObjects = (options.configObjects || []).concat(conf)
}

return self
}

var pkg = null
function pkgUp (path) {
if (pkg && !path) return pkg
Copy link
Member

Choose a reason for hiding this comment

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

There's a slight bug with this logic. If pkgUp is called first with a path (as in .pkgConf('kewl', process.cwd())) and then subsequently without a path (as in .version()), the parsed pkg object returned will be from the call with the path, which is most likely the wrong package.json file.

To fix, we should probably cache a map of path -> pkg object and return the cached object that matches the given path (normalized to '__no_path__' or something similar).

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

Successfully merging this pull request may close these issues.

None yet

3 participants