Skip to content

Commit b06a897

Browse files
devversionandrewseguin
authored andcommitted
build: ensure dependencies are properly locked (#13482)
* Since we lock our dependencies in the `yarn.lock` file, we need to enforce that the lock file is in sync with the `package.json` file (similar as in angular/angular) * Since we cache the dependenices & the yarn cache within Travis, it can happen that the node modules are stale (there is no checksum mechanism in Travis). In that case we need to purge the node modules and re-install.
1 parent 2e4a511 commit b06a897

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ before_install:
5656
- if [[ "$TRAVIS_EVENT_TYPE" == "cron" ]]; then ./scripts/install-angular-snapshot.sh --only-save; fi
5757

5858
install:
59-
- yarn install --frozen-lockfile --non-interactive
59+
- ./scripts/ci/travis-install.sh
6060

6161
before_script:
6262
- mkdir -p $LOGS_DIR

scripts/ci/travis-install.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Script that installs the project node module dependencies within Travis. The script also ensures that the cached
4+
# node modules are in sync with the lock file and also checks that if the lock file is in sync with the
5+
# project `package.json` file.
6+
7+
# Go to the project root directory
8+
cd $(dirname $0)/../..
9+
10+
# Yarn's integrity check command throws in the following scenarios:
11+
# 1) Cached node modules are not in sync with lock file
12+
# 2) Lock file is not in sync with `package.json`
13+
14+
# In case the integrity check passes, we just use the cached/locked node modules. If it fails, we want to purge the
15+
# node modules and run Yarn with `--frozen-lockfile`. Running with a frozen lockfile ensures that outdated/cached node
16+
# modules will be refreshed to **match** the actual lock file. Otherwise, if the `package.json` does not match with
17+
# the lock file, Yarn automatically throws an error due to the `--frozen-lockfile` option.
18+
if ! (yarn check --integrity &> /dev/null); then
19+
echo "Cached node modules are not in sync. Purging and refreshing..."
20+
rm -rf ./node_modules/
21+
yarn install --frozen-lockfile --non-interactive
22+
else
23+
echo "Cached node modules have been checked and are in sync with the lock file."
24+
fi

0 commit comments

Comments
 (0)