Skip to content

Enforce the use of yarn for package management#11368

Merged
rsimha merged 6 commits intoampproject:masterfrom
rsimha:2017-09-20-EnforceYarn
Sep 21, 2017
Merged

Enforce the use of yarn for package management#11368
rsimha merged 6 commits intoampproject:masterfrom
rsimha:2017-09-20-EnforceYarn

Conversation

@rsimha
Copy link
Copy Markdown
Contributor

@rsimha rsimha commented Sep 21, 2017

Fixes #11364
Fixes #11303

@rsimha rsimha self-assigned this Sep 21, 2017
@rsimha
Copy link
Copy Markdown
Contributor Author

rsimha commented Sep 21, 2017

/to @choumx @jridgewell

@rsimha
Copy link
Copy Markdown
Contributor Author

rsimha commented Sep 21, 2017

/to @danielrozenberg

.travis.yml Outdated
webhooks:
- http://savage.nonblocking.io:8080/savage/travis
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a huge fan of abusing npm to install yarn? 😆

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any issues with Travis's built-in version of yarn? How long does this take to install?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's prehistoric (0.27 I think)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(
Copy link
Copy Markdown
Member

@danielrozenberg danielrozenberg Sep 21, 2017

Choose a reason for hiding this comment

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

Curious, what does the /*OK*/ comment do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove the "now", this message is gonna stay here forever and the "now-ness" of it will lose relevancy within a couple of weeks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a space after the $ (here and below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

console.log automatically adds a space between comma separated arguments.

```

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: one space after the period

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok - LGTM on my end, once you get a consensus on this one. Don't forget to update both getting-started-*.md files :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree with @danielrozenberg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@rsimha rsimha requested a review from erwinmombay September 21, 2017 16:36
.travis.yml Outdated
webhooks:
- http://savage.nonblocking.io:8080/savage/travis
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

* 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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok - LGTM on my end, once you get a consensus on this one. Don't forget to update both getting-started-*.md files :)

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/)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

* [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/)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ditto.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

.travis.yml Outdated
webhooks:
- http://savage.nonblocking.io:8080/savage/travis
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should we re-enable yarn caching?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.')) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this really necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't status codes supposed to be positive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@rsimha
Copy link
Copy Markdown
Contributor Author

rsimha commented Sep 21, 2017

All comments addressed. PTAL @choumx @jridgewell

}

// If yarn is being run, proceed with the install.
console/*OK*/.log(green('Detected yarn. Installing packages...'));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the logging because it's confusing when preinstall in package.json prints the script name and there's no output to follow.

@rsimha rsimha merged commit 4710863 into ampproject:master Sep 21, 2017
@rsimha rsimha deleted the 2017-09-20-EnforceYarn branch September 21, 2017 22:50
dmvjs pushed a commit to dmvjs/amphtml that referenced this pull request Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants