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

Make CLI perform static analysis of config lazily #2593

Merged
merged 1 commit into from
Jan 13, 2018

Conversation

bgw
Copy link
Member

@bgw bgw commented Jan 12, 2018

#2375 adds a wrapper CLI tool that parses the ~/.hyper.js configuration file. However, the static analysis logic can't possibly handle every possible configuration file without executing it.

In my case, my configuration file defines a constant at the top, which means that the module.exports definition isn't the first statement. This breaks the parsing logic.

However, this static analysis is only necessary if one wishes to use the CLI subcommands. They're not needed if one just wants to launch hyper.

Unfortunately, the existing implementation tries to read from the AST immediately when cli/api.js is imported. This changes it to be lazy, and uses memoization retain the same reference, allowing the AST to still be mutated in-place.

This PR should be ready to merge. I've tested it to the best of my ability by building a new version with yarn run dist, modifying my configuration file, and seeing that a few hyper subcommands seem to work.

vercel#2375 adds a wrapper CLI tool that parses the ~/.hyper.js
configuration file. However, the static analysis logic can't possibly
handle every possible configuration file without executing it.

In my case, [my configuration file][0] defines a constant at the top,
which means that the `module.exports` definition isn't the first
statement. This breaks the parsing logic.

However, this static analysis is only necessary if one wishes to use the
CLI subcommands. They're not needed if one just wants to launch hyper.

Unfortunately, the existing implementation tries to read from the AST
immediately when `cli/api.js` is imported. This changes it to be lazy,
and uses memoization retain the same reference, allowing the AST to
still be mutated in-place.

[0]: https://github.com/bgw/dotfiles/blob/665e83fd7a13be675ad0ae984478d5b0de502ee1/hyper.js#L4
@chabou chabou merged commit a9e4aa5 into vercel:canary Jan 13, 2018
@chabou
Copy link
Contributor

chabou commented Jan 13, 2018

Amazing work!

Thank you so much @bgw for your help 🙏

Stanzilla pushed a commit to Stanzilla/hyper that referenced this pull request Jan 17, 2018
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.

2 participants