From 5ee3721c08dc9a052cbce1b1f7c40663a1a14184 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 21 Nov 2016 11:57:38 +0000 Subject: [PATCH] add a cache breaker to the yarn cache based on the current version to prevent dependency shifting (#1965) --- bin/yarn.js | 16 +++++++++++++++- src/constants.js | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/yarn.js b/bin/yarn.js index 076c97aba0..a3241be2d0 100755 --- a/bin/yarn.js +++ b/bin/yarn.js @@ -24,13 +24,27 @@ if (semver.satisfies(ver, '>=5.0.0')) { process.exit(1); } -// init roadrunner +// ensure cache directory exists var mkdirp = require('mkdirp'); var constants = require('../lib-legacy/constants'); mkdirp.sync(constants.GLOBAL_INSTALL_DIRECTORY); mkdirp.sync(constants.MODULE_CACHE_DIRECTORY); + +// init roadrunner +var YARN_VERSION = require('../package.json').version; var roadrunner = require('roadrunner'); + +// load cache roadrunner.load(constants.CACHE_FILENAME); +var cacheVersion = roadrunner.get('CACHE_BREAKER').version; +if (!cacheVersion || cacheVersion !== YARN_VERSION) { + // reset cache if it's for an older yarn + roadrunner.reset(constants.CACHE_FILENAME); +} +// set this cache to the current yarn version +roadrunner.set('CACHE_BREAKER', {version: YARN_VERSION}); + +// save cache on SIGINT roadrunner.setup(constants.CACHE_FILENAME); var i = 0; diff --git a/src/constants.js b/src/constants.js index e0620b5f27..72ee138e67 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,8 @@ /* @flow */ + const path = require('path'); let userHome = require('user-home'); + if (process.platform === 'linux' && process.env.USER === 'root') { userHome = path.resolve('/usr/local/share'); }