[cli] Use webpack to bundle all code to a single file #358
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR uses webpack to bundle the entire
sanity
CLI tool (excluding the functionality provided by thecore
-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:
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.rc
module has amodule.parent
-check which does aconsole.log()
if it is falsey. Webpack doesn't setmodule.parent
, so I had to hack it by explicitly definingmodule.parent
to be an empty object in the webpack config.__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).node_modules
and source directories (bothlib
andsrc
) 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!