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)
Sebastian McKenzie authored and bestander committed Nov 21, 2016

Verified

This commit was signed with the committer’s verified signature.
theborakompanioni Thebora Kompanioni
1 parent 8637242 commit a6b4ce6
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 24 additions & 10 deletions bin/yarn.js
Original file line number Diff line number Diff line change
@@ -4,16 +4,7 @@
/* eslint-disable flowtype/require-valid-file-annotation */
'use strict';

// init roadrunner
var mkdirp = require('mkdirp');
var constants = require('../lib-legacy/constants');
mkdirp.sync(constants.GLOBAL_INSTALL_DIRECTORY);
mkdirp.sync(constants.MODULE_CACHE_DIRECTORY);
var roadrunner = require('roadrunner');
roadrunner.load(constants.CACHE_FILENAME);
roadrunner.setup(constants.CACHE_FILENAME);

// get node version
// validate that used node version is supported
var semver = require('semver');
var ver = process.versions.node;
ver = ver.split('-')[0]; // explode and truncate tag from version #511
@@ -33,6 +24,29 @@ if (semver.satisfies(ver, '>=5.0.0')) {
process.exit(1);
}

// 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;
for (; i < possibles.length; i++) {
var possible = possibles[i];
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');
}

0 comments on commit a6b4ce6

Please sign in to comment.