Enforce the use of yarn for package management#11368
Enforce the use of yarn for package management#11368rsimha merged 6 commits intoampproject:masterfrom rsimha:2017-09-20-EnforceYarn
Conversation
|
/to @choumx @jridgewell |
|
/to @danielrozenberg |
.travis.yml
Outdated
| webhooks: | ||
| - http://savage.nonblocking.io:8080/savage/travis | ||
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash |
There was a problem hiding this comment.
Not a huge fan of abusing npm to install yarn? 😆
There was a problem hiding this comment.
I'm still playing around with this. Now that we recommend the use of yarn 1.0.2 (latest stable) for development, I thought we should use the same versions on Travis too. Let me know if you can think of a more efficient way to install the correct version.
There was a problem hiding this comment.
This is one of the recommended ways to install the latest version of Yarn from yarkpkg.com, so might as well stick with it. I'm not advocating for one or the other.
I think the "better alternative" that yarkpkg.com recommends is to use the Debian packages, but it might slow down the installation (because it needs to add the ppa, update the apt packages list, and download and install yarn - as opposed to what you chose which just downloads a simple .sh file and installs it)
There was a problem hiding this comment.
I agree that we should choose the fastest install method for Travis, while recommending the "best" install method for local development. It's fine if the two aren't the same.
There was a problem hiding this comment.
Any issues with Travis's built-in version of yarn? How long does this take to install?
There was a problem hiding this comment.
It's prehistoric (0.27 I think)
There was a problem hiding this comment.
Travis uses yarn 0.27.5. Our packages install fine with that version. I thought we should eventually get to the point where everyone writing AMP code should use the same tool chain, but I'll do that in a separate PR.
I've reverted the changes in this file.
|
|
||
| // If npm is being run, print a message and cause 'npm install' to fail. | ||
| if (process.env.npm_execpath.indexOf('yarn') === -1) { | ||
| console/*OK*/.log(red( |
There was a problem hiding this comment.
Curious, what does the /*OK*/ comment do?
There was a problem hiding this comment.
We have a presubmit check that forbids the use of console.log in the AMP runtime. The /*OK*/ bypasses that check, since we know that the build tools are only going to be run in the presence of a console.
| // If npm is being run, print a message and cause 'npm install' to fail. | ||
| if (process.env.npm_execpath.indexOf('yarn') === -1) { | ||
| console/*OK*/.log(red( | ||
| '*** The AMP project now uses yarn for package management ***'), '\n'); |
There was a problem hiding this comment.
Remove the "now", this message is gonna stay here forever and the "now-ness" of it will lose relevancy within a couple of weeks
There was a problem hiding this comment.
Good point. Removed.
| console/*OK*/.log(red( | ||
| '*** The AMP project now uses yarn for package management ***'), '\n'); | ||
| console/*OK*/.log(yellow('To install all packages:')); | ||
| console/*OK*/.log(cyan('$'), 'yarn', '\n'); |
There was a problem hiding this comment.
Add a space after the $ (here and below)
There was a problem hiding this comment.
console.log automatically adds a space between comma separated arguments.
contributing/getting-started-e2e.md
Outdated
| ``` | ||
|
|
||
| You should see a progress indicator and some messages scrolling by. You may see some warnings about optional dependencies that are generally safe to ignore. | ||
| You will see a progress indicator and some messages scrolling by. You may see some warnings about optional dependencies, which are generally safe to ignore. |
There was a problem hiding this comment.
nit: one space after the period
There was a problem hiding this comment.
This file was originally written with double spacing, so I'm just sticking to the original convention. (We're only changing one word in this line.)
.travis.yml
Outdated
| webhooks: | ||
| - http://savage.nonblocking.io:8080/savage/travis | ||
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash |
There was a problem hiding this comment.
This is one of the recommended ways to install the latest version of Yarn from yarkpkg.com, so might as well stick with it. I'm not advocating for one or the other.
I think the "better alternative" that yarkpkg.com recommends is to use the Debian packages, but it might slow down the installation (because it needs to add the ppa, update the apt packages list, and download and install yarn - as opposed to what you chose which just downloads a simple .sh file and installs it)
| * Install [NodeJS](https://nodejs.org/) version >= 6 (which includes npm) | ||
| * Install the LTS version of [NodeJS](https://nodejs.org/) | ||
|
|
||
| * Install [Yarn](https://yarnpkg.com/) version >= 1.0.2, follow the instructions on the website or install it with npm: |
There was a problem hiding this comment.
Come to think of it, I think it's important that you leave this comment ("follow the instructions on the website") because each platform has its own "right way" to install Yarn. Using curl should be the last alternative
There was a problem hiding this comment.
Fair point. If there's no outright best way to install yarn, we should merely point people to the website. Paging @erwinmombay and @choumx for their opinions.
There was a problem hiding this comment.
ok - LGTM on my end, once you get a consensus on this one. Don't forget to update both getting-started-*.md files :)
There was a problem hiding this comment.
Fixed. We now just point users to the website.
| * Install [NodeJS](https://nodejs.org/) version >= 6 | ||
| * Install the LTS version of [NodeJS](https://nodejs.org/) | ||
|
|
||
| * Install [Yarn](https://yarnpkg.com/) version >= 1.0.2, follow the instructions on the website or install it with npm: `npm install -g yarn@latest` (this command might require elevated privileges using `sudo` on some platforms) |
.travis.yml
Outdated
| webhooks: | ||
| - http://savage.nonblocking.io:8080/savage/travis | ||
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash |
| * Install [NodeJS](https://nodejs.org/) version >= 6 (which includes npm) | ||
| * Install the LTS version of [NodeJS](https://nodejs.org/) | ||
|
|
||
| * Install [Yarn](https://yarnpkg.com/) version >= 1.0.2, follow the instructions on the website or install it with npm: |
There was a problem hiding this comment.
ok - LGTM on my end, once you get a consensus on this one. Don't forget to update both getting-started-*.md files :)
contributing/getting-started-e2e.md
Outdated
| amphtml uses Node.js, the Yarn package manager and the Gulp build system to build amphtml and start up a local server that lets you try out your changes. Installing these and getting amphtml built is straightforward: | ||
|
|
||
| * Install [NodeJS](https://nodejs.org/) version >= 6 (which includes npm) | ||
| * Install the LTS version of [NodeJS](https://nodejs.org/) |
There was a problem hiding this comment.
Nit: "active LTS" vs "current LTS" (https://github.com/nodejs/Release#release-schedule1) though we should probably just specify Node 6+. Node 8 will be "active LTS" next month.
| * [Install and set up Git](https://help.github.com/articles/set-up-git/); in the "Authenticating" step of that page use SSH instead of HTTPS | ||
|
|
||
| * Install [NodeJS](https://nodejs.org/) version >= 6 | ||
| * Install the LTS version of [NodeJS](https://nodejs.org/) |
.travis.yml
Outdated
| webhooks: | ||
| - http://savage.nonblocking.io:8080/savage/travis | ||
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash |
There was a problem hiding this comment.
Any issues with Travis's built-in version of yarn? How long does this take to install?
.travis.yml
Outdated
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash | ||
| - export PATH="$HOME/.yarn/bin:$PATH" | ||
| - yarn --version |
There was a problem hiding this comment.
Should we re-enable yarn caching?
There was a problem hiding this comment.
I already did in a previous PR
.travis.yml
Outdated
| webhooks: | ||
| - http://savage.nonblocking.io:8080/savage/travis | ||
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash |
There was a problem hiding this comment.
It's prehistoric (0.27 I think)
.travis.yml
Outdated
| before_install: | ||
| - curl -o- -L https://yarnpkg.com/install.sh | bash | ||
| - export PATH="$HOME/.yarn/bin:$PATH" | ||
| - yarn --version |
There was a problem hiding this comment.
I already did in a previous PR
|
|
||
| // If yarn is being run, perform a version check and proceed with the install. | ||
| const yarnVersion = getStdout('yarn --version').trim(); | ||
| if (yarnVersion.startsWith('0.')) { |
There was a problem hiding this comment.
Is this really necessary?
There was a problem hiding this comment.
I'll leave this out for now, and see about doing it at a later point in a different PR. Reverted.
| console/*OK*/.log(cyan('$'), 'yarn remove [package_name]', '\n'); | ||
| console/*OK*/.log(yellow('For detailed instructions, see'), | ||
| cyan(setupInstructionsUrl), '\n'); | ||
| return -1; |
There was a problem hiding this comment.
Aren't status codes supposed to be positive?
|
All comments addressed. PTAL @choumx @jridgewell |
| } | ||
|
|
||
| // If yarn is being run, proceed with the install. | ||
| console/*OK*/.log(green('Detected yarn. Installing packages...')); |
There was a problem hiding this comment.
I added the logging because it's confusing when preinstall in package.json prints the script name and there's no output to follow.
Fixes #11364
Fixes #11303