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

[WIP] Babel Autoinstall #1772

Closed

Conversation

davidnagli
Copy link
Contributor

@davidnagli davidnagli commented Jul 22, 2018

Based on this twitter thread and point #3 of my comment on the auto install part 2 RFC

The idea is to automatically install any missing babel preset/plugins by localrequireing them. localrequire will automatically handle resolving the modules and installing anything that's missing, so adding this feature is relatively trivial.

I didn't have too much time to finish everything so I'm opening this up as a WIP PR so we can discuss in the meantime.

@DeMoorJasper You mentioned in your tweet that you had some concerns about security... Just wondering what you meant by that, because this should pretty much come with the same exact security side problems as the normal auto install we have now (which we try to improve btw, but that's a separate issue). Is there anything about Babel plugins/presets in particular that could be a cause for concern?

Progress

  • Support babel plugins
  • Support babel presets
  • Add Unit Tests
  • Fix duplicate install bug (looks like it's installing the same module multiple times because of workers)

Copy link
Member

@DeMoorJasper DeMoorJasper left a comment

Choose a reason for hiding this comment

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

You can probably move some babel dependencies to devDeps, like the react transform. As now we can lazyload them (install when needed).

The security issues I had with this are pretty much the same as regular autoinstall, I just figured code-transforming plugins could potentially cause more harm than a regular dependency.

And move the autoinstall to just before the return statement, as than it will not install filtered out plugins and will install the react ones if necessary.

Would also be cool if this would support adding the babel-polyfill if needed, but that might be a seperate PR.

@texastoland
Copy link

texastoland commented Jul 22, 2018

And move the autoinstall to just before the return statement

Move to getConfig since it's after filter/merge and getBabelConfig has multiple returns.

async function getConfig(asset) {
let config = await getBabelConfig(asset);
if (config) {

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Jul 23, 2018

Duplicate install bug? That shouldn't be happening, every install gets sent to the master process. Ending up in that one queue. Perhaps this queue doesn't prevent installing the same module?

Perhaps you could keep a seperate list like this:

let waiting = {
	folder: [...modules],
	anotherFolder: [...modules]
}

function checkAlreadyInQueue(module, folder) {
	if (folder.includes(module)) {
		return true;
	}

	if (folder !== rootDir) {
		return checkAlreadyInQueue(module, path.dirname(folder));
    }
}

addToQueue(modules.filter(module => !checkAlreadyInQueue(module, folder)));

// Should probably also have some logic that when a module install is called in a folder above one in the queue the queued module gets moved to the most upperlevel folder

And you should probably filter out any non node module babel plugins and presets, as you can use relative babel plugins

@devongovett
Copy link
Member

Included as part of the babel 7 upgrade: #1955

@mririgoyen
Copy link

How do you flag this off? --no-autoinstall is completely ignored.

@texastoland
Copy link

Probably quicker answer in the linked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Autoinstall 📝 WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants