Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Use Yarn to manage dependencies #728

Merged
merged 4 commits into from
Oct 14, 2016
Merged

Use Yarn to manage dependencies #728

merged 4 commits into from
Oct 14, 2016

Conversation

stephanethomas
Copy link
Contributor

@stephanethomas stephanethomas commented Oct 11, 2016

This pull request updates Delphin to use Yarn to manage dependencies. As mentioned here, Yarn is a fast, reliable, and secure alternative Npm client. It has several advantages over Npm such as offering an offline mode, and better network performance. Right now it divides the installation process by almost two on the first build. This process even goes from 26 seconds to less than half a second on the next builds!

Npm

First build
time npm install

[...]

real    2m10.855s
user    1m13.612s
sys     0m13.112s
Next builds
time npm install

[...]

real    0m26.348s
user    0m25.052s
sys     0m0.660s

Yarn

First build
time yarn install --force

[...]

real    1m22.335s
user    0m27.444s
sys     0m8.820s
Next builds
time yarn install

yarn install v0.15.1
success Already up-to-date.
Done in 0.20s.

real    0m0.412s
user    0m0.384s
sys     0m0.020s

Testing instructions

  1. Run npm install -g yarnpkg to install Yarn
  2. Run git checkout test/yarn and start your server
  3. Check that everything works as before

Additional notes

CircleCi still uses npm for building artifacts.

Reviews

  • Code
  • Product

@Automattic/sdev-feed

@drewblaisdell
Copy link
Contributor

This is awesome.

We no longer need npm run qs as it saves < one second now. :) I added a commit to remove it.

I was able to get it running on Circle by adding yarn to the dependencies in package.json. This way, Circle installs Yarn and then use it in npm run prod:static without failing. Feel free to remove the commit that tests this by editing circle.yml and squash the others.

It'd be good to have one more dev's opinion before merging this I think, but this works well for me and the code looks good.

@stephanethomas
Copy link
Contributor Author

Note we will have to update the readme file to mention this new dependency.

@scruffian
Copy link
Member

Note we will have to update the readme file to mention this new dependency.

Done! Uncharacteristically I had already thought of it :)

3. Execute `npm start` to install packages and start the server
4. Add `127.0.0.1 delphin.localhost` to your `hosts` file
5. Open http://delphin.localhost:1337 in your browser
3. Install Webpack: `npm install webpack -g`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we have to install webpack explicitly. Yarn will take care of that.

@@ -9,16 +9,15 @@
"build:server": "webpack --config webpack.server.config.js --progress --colors",
"build:static": "BUILD_STATIC=true REFRESH_I18N_CACHE=true node server/build/bundle",
"clean": "rm -f public/scripts/vendor.*.js && rm -f public/scripts/*.bundle.*.js && rm -f public/scripts/bundle.*.js && rm -f public/styles/bundle.*.css && rm -f public/scripts/assets.json && rm -rf server/build && npm run clean:i18n-cache && npm run clean:static",
"clean:all": "rm -rf node_modules && npm run clean",
"clean:all": "rm -rf node_modules && rm -f yarn.lock && npm run clean",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably not remove the yarn.lock file since it's basically an extension of package.json.

@Tug Tug force-pushed the test/yarn branch 2 times, most recently from 1d9b4a8 to 633266f Compare October 12, 2016 11:27
@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

Awesome indeed.
However we can't update our scripts commands to use yarn just yet. It's still a bit young and fails for many of our commands. Let's follow this issue which reports the same bug yarnpkg/yarn#733

So we'll have to use both yarn and npm for some time.

I added a simple commit to make circleci install deps using yarn instead of npm.

@gziolo
Copy link
Member

gziolo commented Oct 12, 2016

yarn run is not supported yet :D

deployment:
production:
branch: master
branch: /.*/
Copy link
Contributor

Choose a reason for hiding this comment

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

we will need to revert this to master before merging

@gziolo
Copy link
Member

gziolo commented Oct 12, 2016

Still fighting with CircleCI? :D

@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

@gziolo Indeed :)

I have found a couple more issues with yarn:

  • if node_modules is altered (for instance you remove a dependency) yarn won't see it, you need to reinstall everything.
  • It seems postinstall works for dependencies (for instance node-sass binaries are being built locally) but it seems to be failing in circle-ci, I'm still investigating but it might be a cache problem.

@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

npm cache clean on circle-ci did the trick \o/

I'm still a bit worried about how it will play out if we upgrade node for instance, yarn might not rebuild the dependencies. Maybe that's an issue for another time.

This is ready for review ;)

@gziolo
Copy link
Member

gziolo commented Oct 12, 2016

I would also recommend investigating build time on Circle CI:

screen shot 2016-10-12 at 16 52 53

Comparing for the times shared by @stephanethomas, it doesn't looks like an improvement ... Maybe it still needs some tweaks :)

@fabianapsimoes
Copy link
Contributor

Nice experiment, @stephanethomas! Also, good team work getting this ready to ship 🍰

This doesn't seem to break any of the main flows, so apart from any further performance tweaks, product 👍

@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

it doesn't looks like an improvement

That's probably because I cleared the cache for this test.

I think it's an improvement for our dev environment at least, it's a pain to wait 20s for npm to detect than nothing has changed :)

@gziolo
Copy link
Member

gziolo commented Oct 12, 2016

I took a closer look at Circle CI. Everything looks good, you just enabled deployment part for branches other than master and that increased the build time:

screen shot 2016-10-12 at 17 16 48

So I guess it looks good to go, unless @stephanethomas has some comments :)

@gziolo
Copy link
Member

gziolo commented Oct 12, 2016

One more comment. For some reasons npm test & npm run lint was executed twice on Circle CI:

screen shot 2016-10-12 at 17 26 24

On all other branches it was executed only once:

screen shot 2016-10-12 at 17 28 45

@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

Yep because I added those in our circle.yml here 64a5303
The idea is to remove it from circleci config once this is merged

dependencies:
pre:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- yarn run preinstall
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't we simply do npm install -g yarnpkg like in development?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can but the idea is to get rid of npm eventually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. It's just that I'm not a big fan of downloading and executing a shell script :).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed it's not the best, but in the end, we do have to trust some server to give us the right version of our library anyway. Granted there are more secure solution on the market!

3. Execute `npm start` to install packages and start the server
4. Add `127.0.0.1 delphin.localhost` to your `hosts` file
5. Open http://delphin.localhost:1337 in your browser
4. Install yarn: `npm install -g yarnpkg`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we simply mention it in point #1 instead?

1. Make sure you have `git`, `node`, `npm`, and [`yarn`](https://yarnpkg.com/en/docs/install) installed

I think it's better to point to Yarn's installation page since the process is different depending on the platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pushed a commit to do just that ;)

@Tug
Copy link
Contributor

Tug commented Oct 12, 2016

Product was 👍 , I removed the commit which let us build an archive version of our app for other branches than master.

This moves commands specified in the CircleCi dashboard to this configuration file. Note these commands replace the ones inferred by CircleCi.
Come on, we're no longer in beta!
@stephanethomas
Copy link
Contributor Author

I've rebased and cleaned the commits history.

@stephanethomas stephanethomas merged commit 0fc411a into master Oct 14, 2016
@stephanethomas stephanethomas deleted the test/yarn branch October 14, 2016 13:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants