Skip to content

Commit

Permalink
Update offline blog to match v0.23.2 (#466)
Browse files Browse the repository at this point in the history
- Add the correct description for generating offline-mirror
yarn.lock file with v0.23.2
- Add tips for running yarn install with offline flag
  • Loading branch information
Sunyang730 authored and bestander committed Apr 25, 2017
1 parent e210399 commit 571273f
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions _posts/2016-11-24-offline-mirror.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,24 @@ First we need to setup a directory to be our “Offline mirror” storage, we ca

```bash
$ yarn config set yarn-offline-mirror ./npm-packages-offline-cache
yarn config v0.17.8
yarn config v0.23.2
success Set "yarn-offline-mirror" to "./npm-packages-offline-cache".
✨ Done in 0.06s.
```

> `./npm-packages-offline-cache` is an example location relative to home folder where all the source` .tar.gz` files will be downloaded to from the registry.

Offline mirror does not come with removing tarballs. In order to keep the cache folder up to date, you need to add the following to the config file:

This feature is only available in version 0.23.0 and above.

```bash
$ yarn config set yarn-offline-mirror-pruning true
yarn config v0.23.2
success Set "yarn-offline-mirror-pruning" to "true".
✨ Done in 0.06s.
```


This will create a .yarnrc file in your HOME directory.
Let's move this file to the project root so that offline mirror would be used only for this project.
Expand All @@ -105,33 +116,32 @@ success Saved lockfile.
✨ Done in 0.57s.
```

The dependency resolutions in your `yarn.lock` should now look like this:
The dependency resolutions in your `yarn.lock` should look the same as the original:

```yaml
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
is-array@^1.0.1:
version "1.0.1"
resolved is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a
resolved "https://registry.yarnpkg.com/is-array/-/is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a"
left-pad@^1.1.3:
version "1.1.3"
resolved left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
mime-db@~1.25.0:
version "1.25.0"
resolved mime-db-1.25.0.tgz#c18dbd7c73a5dbf6f44a024dc0d165a1e7b1c392
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.25.0.tgz#c18dbd7c73a5dbf6f44a024dc0d165a1e7b1c392"
mime-types@^2.1.13:
version "2.1.13"
resolved mime-types-2.1.13.tgz#e07aaa9c6c6b9a7ca3012c69003ad25a39e92a88
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.13.tgz#e07aaa9c6c6b9a7ca3012c69003ad25a39e92a88"
dependencies:
mime-db "~1.25.0"
```

The `resolved` field for each resolution should now contain file names relative to the `npm-packages-offline-cache` folder that was configured earlier.
Each `resolved` dependency also contains a checksum after the file name to ensure that no one mangles with the downloaded files.
The offline cache filename is derived from the base name of the resolved URL. It will be stored in the npm-packages-offline-cache folder that was configured earlier. Each resolved dependency also contains a checksum after the file name to ensure that no one mangles with the downloaded files.

And inside the “Offline mirror” folder we have the .tgz files that yarn will use for the following builds without reaching out to network.

Expand All @@ -140,6 +150,11 @@ $ ls npm-packages-offline-cache/
is-array-1.0.1.tgz left-pad-1.1.3.tgz mime-db-1.25.0.tgz mime-types-2.1.13.tgz
```

> How can you test to make sure it is offline?
- Clear your global cache with "yarn cache clean"
- Turn off wifi
- Run "yarn install --offline". The offline flag will make sure yarn does not reach out to the network

> In a nutshell, to enable “Offline mirror” for your project you need:
- add “yarn-offline-mirror” configuration to .yarnrc file
- generate a new yarn.lock with “yarn install” command
Expand All @@ -150,7 +165,7 @@ is-array-1.0.1.tgz left-pad-1.1.3.tgz mime-db-1.25.0.tgz mime-types-2.1

### You can check in “Offline mirror” into git or mercurial repository

The “Offline Mirror” can be shared between build servers or development machines in any way that is convenient: a Dropbox folder, stored in source control or on a network drive. At Facebook the offline mirror lives inside of our big Mercurial “monorepo”.
The “Offline Mirror” can be shared between build servers or development machines in any way that is convenient: a Box / Dropbox folder, stored in source control or on a network drive. At Facebook the offline mirror lives inside of our big Mercurial “monorepo”.

Whether to commit binary files into a repository or not depends on the number and size of your project's dependencies.
For example, out of 849 React Native dependencies totaling 23MB, only 10% are larger than 30KB.
Expand All @@ -172,7 +187,7 @@ In comparison, updating a third-party dependency with the Offline Mirror adds ju

```bash
$ yarn add [email protected] --dev
yarn add v0.17.8
yarn add v0.23.2
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
Expand Down Expand Up @@ -247,7 +262,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
Just check it into your project's repository and use it in the build script:

```bash
node ./yarn-0.17.8.js install
node ./yarn-0.23.2.js install
```

This is quite convenient for teams that use multiple operating systems and want to have atomic updates for Yarn.
Expand Down

0 comments on commit 571273f

Please sign in to comment.