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

Add yarn support #895

Merged
merged 7 commits into from
Nov 18, 2016
Merged

Add yarn support #895

merged 7 commits into from
Nov 18, 2016

Conversation

BanzaiMan
Copy link
Contributor

@BanzaiMan BanzaiMan commented Nov 17, 2016

This PR adds yarn support to Travis CI.

See travis-ci/travis-ci#6720

How Yarn support works

Yarn usage detection

If both packag.json and yarn.lock file exist in the repository root, we activate yarn support.

If yarn.lock exists but the defined Node.js version does not meet the minimum requirement for Yarn (versions less than 4), we fall back to the default npm install.

Making the yarn command available

During the default install phase, if the yarn command is not available, it is installed with the following command, as described in https://yarnpkg.com/en/docs/install#alternatives-tab:

curl -o- -L https://yarnpkg.com/install.sh | bash

This is much faster on OS X/macOS than the documented brew update && brew install yarn, and as fast as (or slightly faster than) installing it via apt-get install on Ubuntu.

If repositories are already installing yarn in some way during the before_install or the overridden install, the installation will not take place (because yarn is available in the former case, and our installation steps will not take place in the latter case).

Caching

This PR also defines a new cache directive:

cache: yarn

or, equivalently, with other cache directives:

cache:
  yarn: true
  bundler: true
  directories:
    - node_modules

@Daniel15
Copy link

Awesome, thank you @BanzaiMan! 😄

@@ -169,6 +194,12 @@ def setup_npm_cache
def iojs_3_plus?
(config[:node_js] || '').to_s.split('.')[0].to_i >= 3
end

def install_yarn
sh.cmd "curl -o- -L https://yarnpkg.com/install.sh | bash", echo: true

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@BanzaiMan
Copy link
Contributor Author

I should add that the cache directive will cache $HOME/.yarn-cache, and that we modify $PATH to include $HOME/.yarn/bin.

BanzaiMan added a commit to travis-ci/docs-travis-ci-com that referenced this pull request Nov 17, 2016
@BanzaiMan
Copy link
Contributor Author

Documentation PR is travis-ci/docs-travis-ci-com#811.

@jaumard
Copy link

jaumard commented Nov 18, 2016

The problem by using yarn.lock is that project who don't put this file under versioning will not be able to use yarn at all :(

Use case : a node framework that want to test his installation with npm and yarn will not be able to do it, with Trails framework we want to test installations and generators with both.

A packageManager: npm/yarn field on travis.yml would be also great.

Anyway, thanks for your great job !! :D

@BanzaiMan
Copy link
Contributor Author

BanzaiMan commented Nov 18, 2016

@jaumard Could you elaborate on what you are asking? If there is no yarn.lock in the repository root and you still want to use yarn, you can always override the install phase to use yarn. You'd still need to install yarn until we roll out images that have it pre-installed, but I tend to think this is an unusual use case. Am I mistaken?

Even when `yarn.lock` is present, if Node.js requirement is not met, we
fall back to the default `npm install` command.
BanzaiMan added a commit to travis-ci/docs-travis-ci-com that referenced this pull request Nov 18, 2016
@jaumard
Copy link

jaumard commented Nov 18, 2016

@BanzaiMan of course we can always override install phase but I think it will be better/easier/natural to just have a field to choose witch package manager we want like we choose the node versions or os.

this is an unusual use case

Yes and no if all library/frameworks/generators modules want to test yarn and npm install it will be a lot of cases ^^

Copy link
Contributor

@joshk joshk left a comment

Choose a reason for hiding this comment

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

This looks fantastic, big 👍 from me!

@joshk joshk merged commit 67955fc into master Nov 18, 2016
@BanzaiMan
Copy link
Contributor Author

BanzaiMan commented Nov 18, 2016

We will consider package_manager key for future enhancement.

We will deploy this Monday next week.

@BanzaiMan
Copy link
Contributor Author

By the way, you can see the test here: https://staging.travis-ci.org/BanzaiMan/example-yarn-package/builds/525479

@mattgrande
Copy link

I just had a build complete (node 6.9.1, yarn.lock file present) and I noticed that it still used npm install.

As I'm typing this, I'm noticing that this was just merged in three hours ago... Can I assume this is still being rolled out, and my builds will eventually use yarn, as it becomes available?

@SpaceK33z
Copy link

We will deploy this Monday next week.

see above

@mattgrande
Copy link

Missed that; thanks.

@@ -41,7 +41,20 @@ def announce

def install
sh.if '-f package.json' do
sh.cmd "npm install #{config[:npm_args]}", retry: true, fold: 'install'
sh.if "-f yarn.lock" do
if version.to_i < 4

This comment was marked as spam.

This comment was marked as spam.

@jdevalk
Copy link

jdevalk commented Nov 21, 2016

Is deploy still planned for today?

@joshk
Copy link
Contributor

joshk commented Nov 21, 2016

@jdevalk that is the plan :)

Hiro lives on the East Coast, so will be online soon to start the roll out.

@jdevalk
Copy link

jdevalk commented Nov 21, 2016

Awesome, I hope @BanzaiMan will update us when it's live :D my builds are waiting ;)

@ai
Copy link
Contributor

ai commented Nov 21, 2016

Agree, let's merge current patch and then will improve it in other PRs. I soooo waiting yarn support without long before_install scripts 😊

devversion added a commit to devversion/flex-layout that referenced this pull request Jan 13, 2017
ThomasBurleson pushed a commit to angular/flex-layout that referenced this pull request Jan 14, 2017
* build: cleanup travis ci setup

* travis-ci/travis-build#895

* Fix that Travis doesn't show if the tests failed

* Cleanup browser providers

* Update karma version

* Properly report exit code to gulp

* Return error

* That's it
if data.cache?(:yarn)
sh.fold 'cache.yarn' do
sh.echo ''
directory_cache.add '$HOME/.yarn-cache'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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.