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

Use Yarn to manage dependencies #38481

Merged
merged 43 commits into from
Nov 16, 2017
Merged

Use Yarn to manage dependencies #38481

merged 43 commits into from
Nov 16, 2017

Conversation

joaomoreno
Copy link
Member

@joaomoreno joaomoreno commented Nov 16, 2017

cc @felixfbecker

We moved to Yarn to manage our dependencies. The big advantage is, of course, speed. I report 3x faster install times on my macOS machine. There are other consequences such as locking down our dev dependencies (which sometimes bite us: #37698, et al).


For everyone in @Microsoft/vscode, please read:

What do I have to do?

  1. Update Node to the latest stable version (currently: 8.9.1).
  2. Install Yarn globally: npm i -g yarn
  3. Clean up your vscode repo: git clean -xfd
  4. Install all dependencies: yarn. You can now have a very short espresso ☕️ while you wait Compare that to the tall venti moccachino soy latte from the good old npm 4 times. Too many calories.

You're good to go.

FAQ

How do I do ./scripts/npm.sh install now?

Just:

yarn

Pretty cool, amirite?

I've also adapted scripts/npm.{sh,bat} to simply invoke yarn for the sanity of your own muscle memory.

What about npm run TASK?

You can still do that. No problem.

How can I add or update a dependency?

Both installing and updating dependencies are the same command:

yarn add [--dev] dependency[@version]

Example:

yarn add semver@4.3.6

As always, carefully review the changes made to package.json and (now) yarn.lock files before blindly committing them when adding or updating dependencies.

What are yarn.lock files?

They replace our shrinkwrap files and represent a snapshot of the dependencies to install when installing... dependencies. You don't touch them. Only Yarn touches them.

Can I manually edit dependencies in package.json or yarn.lock?

No, since those files should only be managed by Yarn itself.

On Windows, yarn fails with EBUSY errors

Yarn tries to parallelise native module compilation in order to be faster. node-gyp doesn't like this on Windows. You can set CHILD_CONCURRENCY to 1 in your user's environment to fix this.

Why not NPM5?

Basically because of npm/npm#17722


As always, please be alert to any runtime errors, missing dependencies, strangeness; and let me know asap.

@joaomoreno joaomoreno added the engineering VS Code - Build / issue tracking / etc. label Nov 16, 2017
@joaomoreno joaomoreno added this to the November 2017 milestone Nov 16, 2017
@joaomoreno joaomoreno self-assigned this Nov 16, 2017
@joaomoreno joaomoreno changed the title Use yarn Use yarn to manage dependencies Nov 16, 2017
@joaomoreno joaomoreno changed the title Use yarn to manage dependencies Use Yarn to manage dependencies Nov 16, 2017
@joaomoreno joaomoreno merged commit 67cd925 into master Nov 16, 2017
@joaomoreno joaomoreno deleted the joao/yarn branch November 16, 2017 10:23
@joaomoreno joaomoreno mentioned this pull request Nov 16, 2017
@joaomoreno
Copy link
Member Author

@bpasero @Tyriar FYI the electronVersion flag is gone from package.json. You gotta edit the .yarnrc file now, when updating Electron: https://github.com/Microsoft/vscode/blob/master/.yarnrc#L2

@octref
Copy link
Contributor

octref commented Nov 16, 2017

One tip I found useful: yarn <command> will fallback to yarn run <command> if the first command is not a top level one. This makes it really easy for me to run npm scripts. I run yarn compile all the time.

@Stanzilla
Copy link

yarn config set child-concurrency 1 to set the option.

@favna
Copy link

favna commented Dec 20, 2017

Concerning this line:

Install Yarn globally: npm i -g yarn

Yarn themselves recommend installing Yarn through other means than the node package manager for Linux and MacOS with the former varying on the distro and the latter having options for both Homebrew and MacPorts. Installing Yarn through npm i -g yarn on those non-Windows operating systems will have Yarn spurt out a warning recommending users to install Yarn through the for-their-operating-system recommend method (last I checked) on every command you fire up with it.

I therefore strongly suggest referencing the Yarn installation page for readers that are not using Windows: https://yarnpkg.com/lang/en/docs/install/

@felixfbecker
Copy link
Contributor

@favna is there any reason why it should be done that way?

@favna
Copy link

favna commented Dec 20, 2017

@felixfbecker I have too little experience with the aforementioned non-Windows environments to be able to properly answer that, therefore I can only assume that if there wasn't a compelling reason to do so then Yarn wouldn't be recommending its users to install it through their recommend ways.

@felixfbecker
Copy link
Contributor

felixfbecker commented Dec 20, 2017

@favna I could see how they don't want to be "coupled" in any way to npm, i.e. no want to require npm to install yarn, as they are a competitor to npm. It always felt weird using npm to install bower. That is definitely not a reason to "strongly suggest" stop using npm...

@Stanzilla
Copy link

As long as there is no functioning way to self-update Yarn, people will always prefer the npm method, imo.

@MonsieurMan
Copy link

@joaomoreno, you should edit this part like so as @octref mentionned :

What about npm run TASK?

You can still do that. No problem.
Or run yarn <task> if the taskname is not conflicting with any native yarn command.
It'll save time to everybody 😄

@t-sauer
Copy link

t-sauer commented Jan 23, 2018

@felixfbecker you can find their reasons under „Install with npm“ under the alternatives tab on the installation docs

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engineering VS Code - Build / issue tracking / etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants