Skip to content

Commit

Permalink
add a cache breaker to the yarn cache based on the current version to…
Browse files Browse the repository at this point in the history
… prevent dependency shifting (#1965)
  • Loading branch information
Sebastian McKenzie authored and bestander committed Nov 21, 2016
1 parent 73ea5b4 commit 5ee3721
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -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');
}
Expand Down

0 comments on commit 5ee3721

Please sign in to comment.