Skip to content

Commit

Permalink
Adds versioning to the cache path
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Feb 23, 2017
1 parent 7aaee9b commit d40264d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/cli/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export const {run, setFlags} = buildSubCommands('cache', {
flags: Object,
args: Array<string>,
): Promise<void> {
const cacheFolder = config.cacheFolder;
if (cacheFolder) {
await fs.unlink(cacheFolder);
await fs.mkdirp(cacheFolder);
if (config.cacheFolder) {
await fs.unlink(config.cacheRootFolder);
await fs.mkdirp(config.cacheFolder);
reporter.success(reporter.lang('clearedCache'));
}
},
Expand Down
12 changes: 11 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const path = require('path');

export type ConfigOptions = {
cwd?: ?string,
cacheRootFolder?: ?string,
cacheFolder?: ?string,
tempFolder?: ?string,
modulesFolder?: ?string,
Expand Down Expand Up @@ -109,6 +110,9 @@ export default class Config {
//
modulesFolder: ?string;

//
cacheRootFolder: string;

//
cacheFolder: string;

Expand Down Expand Up @@ -229,8 +233,14 @@ export default class Config {
networkConcurrency: this.networkConcurrency,
});

this.cacheRootFolder = String(
opts.cacheFolder ||
this.getOption('cache-folder') ||
constants.MODULE_CACHE_DIRECTORY
);

//init & create cacheFolder, tempFolder
this.cacheFolder = String(opts.cacheFolder || this.getOption('cache-folder') || constants.MODULE_CACHE_DIRECTORY);
this.cacheFolder = path.join(this.cacheRootFolder, 'v' + String(constants.CACHE_VERSION));
this.tempFolder = opts.tempFolder || path.join(this.cacheFolder, '.tmp');
await fs.mkdirp(this.cacheFolder);
await fs.mkdirp(this.tempFolder);
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const SELF_UPDATE_VERSION_URL = 'https://yarnpkg.com/latest-version';
export const SELF_UPDATE_TARBALL_URL = 'https://yarnpkg.com/latest.tar.gz';
export const SELF_UPDATE_DOWNLOAD_FOLDER = 'updates';

// cache version, bump whenever we make backwards incompatible changes
export const CACHE_VERSION = 1;

// lockfile version, bump whenever we make backwards incompatible changes
export const LOCKFILE_VERSION = 1;

Expand Down

0 comments on commit d40264d

Please sign in to comment.