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

[cli] Use webpack to bundle all code to a single file #358

Merged
merged 2 commits into from
Nov 21, 2017
Merged

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Nov 13, 2017

⚠️ Big, scary change 🚨

This PR uses webpack to bundle the entire sanity CLI tool (excluding the functionality provided by the core-module) into a single executable JS file.

The reason behind this is to make the install process as quick as possible. npm install -g @sanity/cli should be significantly faster, basically only pulling down a single tarball with a JS file inside. Instead of waiting for a large number of dependencies to be downloaded, we bundle them all up into a single file. The CLI package has no dependencies after this change, moving all the current dependencies to dev dependencies since they are needed at build time.

There were a number of changes that needed to happen for this to work:

  • We can't lazy-require anymore. Mostly this was a simple process of rewriting to regular import/require, but the update-notifier dependency lazy-requires, so I had to create a small webpack-loader to replace them with regular require statements. We should move away from the update notifier and use something a bit simpler in the future.
  • The rc module has a module.parent-check which does a console.log() if it is falsey. Webpack doesn't set module.parent, so I had to hack it by explicitly defining module.parent to be an empty object in the webpack config.
  • All paths depending on __dirname would be wrong, since it's all moved to a separate directory when bundled. This was solved by passing the __dirname from the entry script to the main CLI module, which passes it down through options to underlying components. This also enables the CLI to work without being bundled into a single file (when in development mode).
  • The travis tests needs to ensure that the node_modules and source directories (both lib and src) are removed after building the Sanity binary, to make sure there are dangling require statements depending on unbundled dependencies or on local paths.

A bunch of formatting changes snuck in with this change because I've started to use prettier across the board, and since we're planning on moving to prettier at some point I didn't choose to go over and cherry-pick changes, sorry about that.

This change needs proper, thorough testing!

@rexxars rexxars requested a review from bjoerge November 13, 2017 16:32
@rexxars rexxars changed the base branch from master to next November 13, 2017 16:32
@bjoerge
Copy link
Member

bjoerge commented Nov 15, 2017

This is fantastic! I'm not in a position to fully understand everything of what's going on here, but have been running the cli for a while now without any problems.

+1 to formatting changes too. I'm starting thinking it may be a better strategy to just prettify project by project.

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