diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 9fac1bab0c..e68f8fc7f6 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -22,12 +22,17 @@ const path = require('path'); const stream = require('stream'); const os = require('os'); -async function mockConstants(mocks: Object, cb: (config: Config) => Promise): Promise { +async function mockConstants(base: Config, mocks: Object, cb: (config: Config) => Promise): Promise { // We cannot put this function inside _helpers, because we need to change the "request" variable // after resetting the modules. Updating this variable is required because some tests check what // happened during the Yarn execution, and they need to use the same instance of "request" than // the Yarn environment. + const opts = {}; + + for (let name of [ 'binLinks', 'cwd', 'globalFolder', 'linkFolder', 'production' ]) opts[name] = base[name]; + opts.cacheFolder = base._cacheRootFolder; + const automock = jest.genMockFromModule('../../../src/constants'); jest.setMock('../../../src/constants', Object.assign(automock, mocks)); @@ -35,7 +40,7 @@ async function mockConstants(mocks: Object, cb: (config: Config) => Promise { await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise => { - const cacheFolder = path.join(config.versionedCacheFolder, 'npm-dummy-0.0.0'); + const cacheFolder = path.join(config.cacheFolder, 'npm-dummy-0.0.0'); assert.deepEqual( (await fs.readJson(path.join(cacheFolder, constants.METADATA_FILENAME))).artifacts, ['dummy', path.join('dummy', 'dummy.txt'), 'dummy.txt'], @@ -65,7 +70,7 @@ test('changes the cache path when bumping the cache version', async () => { await cache(config, reporter, {}, ['dir']); assert.ok(!!(JSON.parse(String(inOut.read())) : any).data.match(/[\\\/]v1[\\\/]?$/)); - await mockConstants({CACHE_VERSION: 42}, async (config): Promise => { + await mockConstants(config, {CACHE_VERSION: 42}, async (config): Promise => { await cache(config, reporter, {}, ['dir']); assert.ok(!!(JSON.parse(String(inOut.read())) : any).data.match(/[\\\/]v42[\\\/]?$/)); }); @@ -85,14 +90,14 @@ test('changes the cache directory when bumping the cache version', async () => { await fs.writeFile(path.join(cachePath, 'yarn.test'), 'YARN TEST'); await fs.unlink(path.join(config.cwd, 'node_modules')); - const firstReinstall = new Install({}, config, reporter, lockfile); + const firstReinstall = new Install({skipIntegrityCheck: true}, config, reporter, lockfile); await firstReinstall.init(); assert.ok(await fs.exists(path.join(config.cwd, 'node_modules', 'is-array', 'yarn.test'))); - await mockConstants({CACHE_VERSION: 42}, async (config): Promise => { - const firstReinstall = new Install({}, config, reporter, lockfile); - await firstReinstall.init(); + await mockConstants(config, {CACHE_VERSION: 42}, async (config): Promise => { + const secondReinstall = new Install({skipIntegrityCheck: true}, config, reporter, lockfile); + await secondReinstall.init(); assert.ok(!await fs.exists(path.join(config.cwd, 'node_modules', 'is-array', 'yarn.test'))); }); diff --git a/__tests__/package-resolver.js b/__tests__/package-resolver.js index 90fb62929a..1a993f2a7b 100644 --- a/__tests__/package-resolver.js +++ b/__tests__/package-resolver.js @@ -39,10 +39,10 @@ function addTest(pattern, registry = 'npm', init: ?(cacheFolder: string) => Prom }, reporter); await fs.mkdirp(path.join(loc, 'node_modules')); - await fs.mkdirp(config.versionedCacheFolder); + await fs.mkdirp(config.cacheFolder); if (init) { - await init(config.versionedCacheFolder); + await init(config.cacheFolder); } const resolver = new PackageResolver(config, lockfile); diff --git a/src/cli/commands/cache.js b/src/cli/commands/cache.js index ae9168510e..539fb11868 100644 --- a/src/cli/commands/cache.js +++ b/src/cli/commands/cache.js @@ -20,7 +20,7 @@ export const {run, setFlags} = buildSubCommands('cache', { args: Array, ): Promise { async function readCacheMetadata( - parentDir = config.versionedCacheFolder, + parentDir = config.cacheFolder, metadataFile = METADATA_FILENAME, ): Promise<[]> { const folders = await fs.readdir(parentDir); @@ -31,7 +31,7 @@ export const {run, setFlags} = buildSubCommands('cache', { continue; } - const loc = path.join(config.versionedCacheFolder, parentDir.replace(config.versionedCacheFolder, ''), folder); + const loc = path.join(config.cacheFolder, parentDir.replace(config.cacheFolder, ''), folder); // Check if this is a scoped package if (!(await fs.exists(path.join(loc, metadataFile)))) { // If so, recurrently read scoped packages metadata @@ -54,7 +54,7 @@ export const {run, setFlags} = buildSubCommands('cache', { config: Config, reporter: Reporter, ) { - reporter.log(config.versionedCacheFolder); + reporter.log(config.cacheFolder); }, async clean( @@ -63,9 +63,9 @@ export const {run, setFlags} = buildSubCommands('cache', { flags: Object, args: Array, ): Promise { - if (config.versionedCacheFolder) { - await fs.unlink(config.cacheFolder); - await fs.mkdirp(config.versionedCacheFolder); + if (config.cacheFolder) { + await fs.unlink(config._cacheRootFolder); + await fs.mkdirp(config.cacheFolder); reporter.success(reporter.lang('clearedCache')); } }, diff --git a/src/cli/commands/global.js b/src/cli/commands/global.js index 99b1ff4470..53cdb207d9 100644 --- a/src/cli/commands/global.js +++ b/src/cli/commands/global.js @@ -41,8 +41,7 @@ async function updateCwd(config: Config): Promise { cwd: config.globalFolder, binLinks: true, globalFolder: config.globalFolder, - cacheFolder: config.cacheFolder, - versionedCacheFolder: config.versionedCacheFolder, + cacheFolder: config._cacheRootFolder, linkFolder: config.linkFolder, }); } diff --git a/src/cli/index.js b/src/cli/index.js index 99901ee3ec..52d14f95db 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -362,8 +362,7 @@ config.init({ binLinks: commander.binLinks, modulesFolder: commander.modulesFolder, globalFolder: commander.globalFolder, - cacheFolder: commander.cacheFolder, - versionedCacheFolder: commander.versionedCacheFolder, + cacheRootFolder: commander.cacheFolder, preferOffline: commander.preferOffline, captureHar: commander.har, ignorePlatform: commander.ignorePlatform, diff --git a/src/config.js b/src/config.js index a464d51dc5..339488fa5c 100644 --- a/src/config.js +++ b/src/config.js @@ -21,8 +21,8 @@ const path = require('path'); export type ConfigOptions = { cwd?: ?string, + _cacheRootFolder?: ?string, cacheFolder?: ?string, - versionedCacheFolder?: ?string, tempFolder?: ?string, modulesFolder?: ?string, globalFolder?: ?string, @@ -112,10 +112,10 @@ export default class Config { modulesFolder: ?string; // - cacheFolder: string; + _cacheRootFolder: string; // - versionedCacheFolder: string; + cacheFolder: string; // tempFolder: string; @@ -235,17 +235,16 @@ export default class Config { key: String(opts.key || this.getOption('key') || ''), networkConcurrency: this.networkConcurrency, }); - - this.cacheFolder = String( + this._cacheRootFolder = String( opts.cacheFolder || this.getOption('cache-folder') || constants.MODULE_CACHE_DIRECTORY, ); //init & create cacheFolder, tempFolder - this.versionedCacheFolder = path.join(this.cacheFolder, 'v' + String(constants.CACHE_VERSION)); - this.tempFolder = opts.tempFolder || path.join(this.versionedCacheFolder, '.tmp'); - await fs.mkdirp(this.versionedCacheFolder); + 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); if (opts.production === 'false') { @@ -300,7 +299,7 @@ export default class Config { */ generateHardModulePath(pkg: ?PackageReference, ignoreLocation?: ?boolean): string { - invariant(this.versionedCacheFolder, 'No package root'); + invariant(this.cacheFolder, 'No package root'); invariant(pkg, 'Undefined package'); if (pkg.location && !ignoreLocation) { @@ -322,7 +321,7 @@ export default class Config { uid += `-${hash}`; } - return path.join(this.versionedCacheFolder, `${name}-${uid}`); + return path.join(this.cacheFolder, `${name}-${uid}`); } /** diff --git a/src/resolvers/registries/npm-resolver.js b/src/resolvers/registries/npm-resolver.js index 2ff2127e62..9cd906e5bb 100644 --- a/src/resolvers/registries/npm-resolver.js +++ b/src/resolvers/registries/npm-resolver.js @@ -89,8 +89,8 @@ export default class NpmResolver extends RegistryResolver { // find modules of this name const prefix = scope ? this.name.split(/\/|%2f/)[1] : `npm-${this.name}-`; - invariant(this.config.versionedCacheFolder, 'expected packages root'); - const cacheFolder = path.join(this.config.versionedCacheFolder, scope ? 'npm-' + scope : ''); + invariant(this.config.cacheFolder, 'expected packages root'); + const cacheFolder = path.join(this.config.cacheFolder, scope ? 'npm-' + scope : ''); const files = await this.config.getCache('cachedPackages', async (): Promise> => { const files = await fs.readdir(cacheFolder);