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

Automagically install missing dependancies #306

Merged
merged 17 commits into from
Dec 21, 2017
Merged

Automagically install missing dependancies #306

merged 17 commits into from
Dec 21, 2017

Conversation

DeMoorJasper
Copy link
Member

@DeMoorJasper DeMoorJasper commented Dec 16, 2017

Attempt to achieve what's been discussed here: #213

@DeMoorJasper DeMoorJasper changed the title Automatically install missing dependancies using npm Automatically install missing dependancies Dec 16, 2017
@devongovett
Copy link
Member

Oh this is clever.

module.exports = async function(dir, name) {
let yarn;
try {
yarn = await config.resolve(dir, ['yarn.lock']);
Copy link
Member

Choose a reason for hiding this comment

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

maybe instead of trying to detect yarn based on yarn.lock we should just look for the command?

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds like a more solid approach, will change it

cwd: dir
};

let install = spawn('yarn', ['add', name, '--dev'], options);
Copy link
Member

Choose a reason for hiding this comment

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

should they be dev dependencies or normal dependencies? I could see arguments for both.

Copy link
Member Author

@DeMoorJasper DeMoorJasper Dec 16, 2017

Choose a reason for hiding this comment

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

I think because it's a bundler it should always be dev deps not sure though

if (e.code === 'MODULE_NOT_FOUND' && triedInstall === false) {
// TODO: Make this use logger
console.log(`INSTALLING ${name}...\n`);
await install(basedir, name);
Copy link
Member

Choose a reason for hiding this comment

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

maybe we only want to do this for the top-level project, not for packages inside node_modules?

Copy link
Member Author

@DeMoorJasper DeMoorJasper Dec 16, 2017

Choose a reason for hiding this comment

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

Than wouldn't this still break if a dependancy isn't using a base language?
Or do you mean installing the dependancies in top-level all the time and how would this be achieved?

Choose a reason for hiding this comment

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

but some packages like request-promise don't install by default dependencies

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you mean @EduardoRFS ? This PR is just for auto installing missing parsers, through changing localRequire, ofcourse this can be used for way more things in the future

@DeMoorJasper DeMoorJasper changed the title Automatically install missing dependancies Automagically install missing dependancies Dec 16, 2017
const {spawn} = require('child_process');
const config = require('./config');

function testYarn(options) {
Copy link
Contributor

@brandon93s brandon93s Dec 16, 2017

Choose a reason for hiding this comment

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

An alternative would be to check for a yarn.lock file in the cwd. It's probably a quicker check than spawning a whole process, and worst case we fall back to npm. This may also be desirable for the scenario that the user has yarn but the project is using npm.

Copy link
Member Author

@DeMoorJasper DeMoorJasper Dec 16, 2017

Choose a reason for hiding this comment

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

Checking for a yarn file in comparison with spawning an instance is an insane speed difference i'll pivot back towards my initial setup, thank you for your input.

451ms <-> 1ms (tested on macbook pro dual core i5)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, didn't realize you'd started with that setup!

Copy link
Contributor

@davidnagli davidnagli left a comment

Choose a reason for hiding this comment

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

Wow great job!

I’m adding a blocking review to make sure that nobody merges this PR until we reach a consensus in #213. Some people are against this approach.

@DeMoorJasper
Copy link
Member Author

DeMoorJasper commented Dec 17, 2017

This just automatically installs dependencies not plugins, at least not yet

@davidnagli
Copy link
Contributor

davidnagli commented Dec 17, 2017

Oh cool, didn’t realize it was a wip

@DeMoorJasper
Copy link
Member Author

It's not a wip, it's just a function that can be used for installing packages instead of throwing "Module not found" Atm if a plugin is not installed it will just not parse the file the correct way, even with this merged.
For this i'm also waiting on what we eventually decide on.
@davidnagli

Copy link

@rondonjon rondonjon left a comment

Choose a reason for hiding this comment

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

No offense @DeMoorJasper, but when I see commit messages like stuff in a project with so much attention and hopes attached to it, it kind of breaks my heart.

@devongovett devongovett merged commit 6f493f0 into parcel-bundler:master Dec 21, 2017
@fritx
Copy link

fritx commented Apr 21, 2018

Why use yarn instead of npm?

@fritx
Copy link

fritx commented Apr 21, 2018

Ok, would pick up yarn if there is a yarn.lock even it's been deprecated or regardless

devongovett pushed a commit that referenced this pull request Oct 15, 2018
* run prettier

* initial try

* minor bugfixes

* fix secu vuln and add yarn support

* minor bugfix

* cleanup output

* test command instead of lockfile

* pivot back to finding the package/yarn file

* tiny cleanup
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* run prettier

* initial try

* minor bugfixes

* fix secu vuln and add yarn support

* minor bugfix

* cleanup output

* test command instead of lockfile

* pivot back to finding the package/yarn file

* tiny cleanup
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.

7 participants