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

🙋 Automatically install missing dependencies, part 2 #376

Closed
devongovett opened this issue Dec 22, 2017 · 28 comments
Closed

🙋 Automatically install missing dependencies, part 2 #376

devongovett opened this issue Dec 22, 2017 · 28 comments
Labels

Comments

@devongovett
Copy link
Member

Now that #306 has landed, it would be awesome to take this even further. Currently we automatically install dependencies loaded by the internal localRequire helper. These are things like compilers (e.g. typescript, coffeescript), and plugins (e.g. postcss plugins, parcel plugins, etc.).

It would be super cool to take this even further and transparently install any npm dependencies you require in your code for you. e.g. if you add require('react') in your code, and it's not installed, Parcel can install it for you.

Thoughts?

@devongovett
Copy link
Member Author

cc @DeMoorJasper

Also, looks like there is a webpack plugin that does something similar https://github.com/webpack-contrib/npm-install-webpack-plugin

@brandon93s
Copy link
Contributor

So, to make sure I understand....

Instead of this:

$ git clone https://github.com/project/repo.git
$ yarn install
$ yarn start

All I would need is this:

$ git clone https://github.com/project/repo.git
$ yarn start

Assume yarn start points to parcel {entry} in these examples.

@devongovett
Copy link
Member Author

Sure, or you have parcel already started, and change your code to import a new dependency. No need to ctrl+C and install it anymore, parcel will just install it automatically when it detects the import.

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017

That came out a bit more rant-y than I wanted, but the gist is that if someone wants to set up react, it takes them ten seconds to install the dependencies.

If someone wants to use react without Parcel, it takes them ten minutes to configure Webpack.

That's why Parcel is valuable. Saving ten seconds at the cost of maintainability and extensibility seems like a bad tradeoff, but maybe users feel differently. I don't know.

@devongovett
Copy link
Member Author

Parcel is all about developer experience. Anything we can do, no matter how small, to save developers time is a win in my book. Developer hours add up quick!

We'll be working on things like improving plugins etc. in good time. Feel free to discuss how we can improve other aspects of Parcel in separate issues. There is room for everyone here.

@brandon93s
Copy link
Contributor

@shawwn - It will be interesting to see how this plays out. The project is moving at breakneck pace at the moment, it's hard to say what things will look like tomorrow, nonetheless next week at the moment. I suspect if there is community outcry for or against a feature like this, the project will react accordingly. Let's see how the community feels about it.

From triaging issues that come in, I can say this will fix the occasional "what do I install" question.

I agree auto-install may feel a bit gimmicky on the surface right now, but I'd like to give it a chance to see what it becomes and how the community adopts it.

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@brandon93s
Copy link
Contributor

Sure, or you have parcel already started, and change your code to import a new dependency. No need to ctrl+C and install it anymore, parcel will just install it automatically when it detects the import.

Open question here would be whether or not it shows up in your package.json dependencies "automagically" or not. Would be pretty wild if I just add require('lodash') to a file and it installs it and adds the dependency for me. That sounds like a developer experience I can get behind. Your focus becomes the code you're writing, and nothing else at that point.

@devongovett
Copy link
Member Author

@brandon93s That's exactly how it works now for compilers. e.g. import a .ts file and typescript is automatically installed and saved into devDependencies.

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@devongovett
Copy link
Member Author

Not really a fan of overloading the require function or import syntax. but yeah, that's a valid concern.

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@parcel-bundler parcel-bundler deleted a comment from sompylasar Dec 22, 2017
@parcel-bundler parcel-bundler deleted a comment from shawwn Dec 22, 2017
@DeMoorJasper
Copy link
Member

Why would there be a cli option to turn it off?
If you install the dependencies up front then it wouldn't even care to look to install them?
You can just still use it the same way @shawwn
And about the errors it's pretty straightforward it says it fails to autoinstall so than u just run the command in very restricted business environments or wathever, we could even extend this warning to literally give them the command.

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@DeMoorJasper
Copy link
Member

'Those cases cost more time than the small convenience afforded.' Imo clearing out the cache once everytime u change a config doesn't cost much time. (Keeping in mind building speed goes down from a few secs to millisecs thanks to this...)
And same for dragging dependencies to dev-dependencies or vice versa, would save more time than it costs as far as i know.

But everyone has his own way of developing and u can't please everyone i guess...

@shawwn
Copy link
Contributor

shawwn commented Dec 22, 2017 via email

@rondonjon
Copy link

@shawwn is raising some very good points here IMO. I agree that this whole auto-installation thing may be nice at first sight but extends the scope of this project into fields that should be left to actual package managers. Users should be kept in control of their dependency management, especially in work environments. At the same time, the freed-up resources could be spent on key features of a better bundler.

@jdanyow
Copy link
Contributor

jdanyow commented Dec 26, 2017

I wonder if this will cause any issues in monorepos managed by lerna, yarn, workspaces, etc.

@devongovett
Copy link
Member Author

@jdanyow it triggers the install at the nearest directory containing a package.json to the file where the import occurred.

@shawwn
Copy link
Contributor

shawwn commented Dec 31, 2017 via email

@DeMoorJasper
Copy link
Member

@shawwn it'll prefer yarn over package.json so if a yarn file is present in the tree it'll take that one

@jamiebuilds
Copy link
Member

Can we be sure to have an option to disable this behavior? Especially in CI environments

@davidnagli
Copy link
Contributor

davidnagli commented Jan 29, 2018

I’m a really big fan of this idea. I think we should go ahead and start thinking through how we can try implementing it.

Some questions we need to answer first:

  1. Should we run this automagic install in production build mode (parcel build command)?
  2. How are we implementing this!?? Here’s a few options:
    a) During the build process when we are resolving JS dependencies, if we come accross a dependency we can’t resolve (and it’s not a local file), then we attempt to npm install it (or use yarn if available)
    b) We run as usual, if we fail with an error, we go back and try to figure out which dependencies to install to make the error go away (dirty, but potentially necessary in some cases)
  3. How do we tell apart imports of npm modules and local files?
    a) I’m pretty sure we can just check if the first characters are ./ since I think those are the required way to signify a local import, but we definitely need to research the proper way to detect this and cover any/all edge cases
  4. Should we also cover installing dependencies that tools along the way need?
    a) For example, if babel needs to install a plugin/preset
    b) How would we detect this? Maybe we need to read the error output from Babel? Maybe we can figure out which installs it’ll need ahead of time by also parsing .babelrc?

The only SUPER important question here is number 2. Once we get that out of the way, we can begin implementing this feature and keep discussions about the rest of the points parallel to development.

@dpikt
Copy link

dpikt commented Mar 29, 2018

For future reference: flag to disable this behavior is --no-autoinstall

@DeMoorJasper
Copy link
Member

@dpikt fyi this is documented in the docs: https://parceljs.org/cli.html#disable-autoinstall

@yumindeckard
Copy link

With all due respect, sir, you should try to suppress the impulse of making decisions for the users. You can give them the options and if they need it, they can just turn it on.

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

No branches or pull requests

10 participants