Skip to content

Commit

Permalink
fix bugs with hash cache folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian McKenzie committed Nov 4, 2016
1 parent 5efc97a commit ba5a203
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
12 changes: 7 additions & 5 deletions __tests__/commands/_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ export async function run(
const lockfile = await createLockfile(cwd);

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, '.yarn-global'));
await fs.mkdirp(path.join(cwd, '.yarn-link'));
await fs.mkdirp(path.join(cwd, '.yarn-cache'));
await fs.mkdirp(path.join(cwd, 'node_modules'));

try {
const config = new Config(reporter);
await config.init({
binLinks: !!flags.binLinks,
cwd,
globalFolder: path.join(cwd, '.yarn/.global'),
cacheFolder: path.join(cwd, '.yarn'),
linkFolder: path.join(cwd, '.yarn/.link'),
globalFolder: path.join(cwd, '.yarn-global'),
cacheFolder: path.join(cwd, '.yarn-cache'),
linkFolder: path.join(cwd, '.yarn-link'),
});

const install = factory(config, reporter, lockfile);
Expand All @@ -115,7 +117,7 @@ export async function run(
} finally {
// clean up
if (cleanupAfterInstall) {
await fs.unlink(cwd);
//await fs.unlink(cwd);
}
}
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fetchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('BaseFetcher.fetch', async () => {
type: 'base',
registry: 'npm',
reference: '',
hash: null,
}, await createConfig());
let error;

Expand All @@ -47,6 +48,7 @@ test('CopyFetcher.fetch', async () => {
type: 'copy',
reference: a,
registry: 'npm',
hash: null,
}, await createConfig());
await fetcher.fetch();
const content = await fs.readFile(path.join(b, 'package.json'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# yarn lockfile v1
dep-a@1.0.0:
version "1.0.0"
resolved dep-a-1.0.0.tgz
resolved dep-a-1.0.0.tgz#32681745236788ceacdd1e693a434c17a523c74f
dependencies:
dep-b "1.0.0"

dep-b@1.0.0:
version "1.0.0"
resolved dep-b-1.0.0.tgz
resolved dep-b-1.0.0.tgz#cd5e0c0e50dea8b27fe0ce3b5cc738b9c1c3d128
dependencies:
dep-c "1.0.0"

dep-c@1.0.0:
version "1.0.0"
resolved dep-c-1.0.0.tgz
resolved dep-c-1.0.0.tgz#968769f835949a29dbb6a45884b5bdcee3ab9b20
dependencies:
dep-d "1.0.0"

dep-d@1.0.0:
version "1.0.0"
resolved dep-d-1.0.0.tgz
resolved dep-d-1.0.0.tgz#0fcc8130f5ab82792e98f2efa8981a882882748c
6 changes: 3 additions & 3 deletions __tests__/fixtures/install/scripts-order/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# yarn lockfile v1
dep-a@1.0.0:
version "1.0.0"
resolved dep-a-1.0.0.tgz
resolved dep-a-1.0.0.tgz#63970c7301ec8a5d37dac4e454fff354f31c31b4
dependencies:
dep-b "1.0.0"
dep-b@1.0.0:
version "1.0.0"
resolved dep-b-1.0.0.tgz
resolved dep-b-1.0.0.tgz#569c27a4e30b1679eaa7e2299e741f30a7f70926
dependencies:
dep-c "1.0.0"
dep-c@1.0.0:
version "1.0.0"
resolved dep-c-1.0.0.tgz
resolved dep-c-1.0.0.tgz#100eef2bf00fc31b596542fb9af18186e37716cc
2 changes: 1 addition & 1 deletion __tests__/fixtures/request-cache/GET/localhost/.bin
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Date: Wed, 26 Oct 2016 22:01:42 GMT
Date: Fri, 04 Nov 2016 14:55:49 GMT
Connection: close
Content-Length: 2

Expand Down
8 changes: 3 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,9 @@ export default class Config {
uid = pkg.version || uid;
}

if (pkg.remote) {
const {hash} = pkg.remote;
if (hash) {
uid += `-${hash}`;
}
const {hash} = pkg.remote;
if (hash) {
uid += `-${hash}`;
}

return path.join(this.cacheFolder, `${name}-${uid}`);
Expand Down
14 changes: 6 additions & 8 deletions src/fetchers/git-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export default class GitFetcher extends BaseFetcher {
}

async fetchFromExternal(): Promise<FetchedOverride> {
const hash = this.hash;
invariant(hash, 'Commit hash required');
const commit = this.hash;
invariant(commit, 'Commit hash required');

const git = new Git(this.config, this.reference, hash);
const git = new Git(this.config, this.reference, commit);
await git.init();
await git.clone(this.dest);

Expand All @@ -83,20 +83,18 @@ export default class GitFetcher extends BaseFetcher {

const mirrorRootPath = this.config.getOfflineMirrorPath();
if (tarballInMirrorPath && this.hash && mirrorRootPath) {
tarballInMirrorPath = `${tarballInMirrorPath}-${this.hash}`;
tarballInMirrorPath = `${tarballInMirrorPath}-${commit}`;
const hash = await git.archive(tarballInMirrorPath);
const relativeMirrorPath = path.relative(mirrorRootPath, tarballInMirrorPath);
return {
hash,
hash: commit,
resolved: relativeMirrorPath ? `${relativeMirrorPath}#${hash}` : null,
};
}

return {
hash,
hash: commit,
resolved: null,
};
}


}
1 change: 1 addition & 0 deletions src/resolvers/exotics/file-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class FileResolver extends ExoticResolver {
manifest._remote = {
type: 'copy',
registry,
hash: null,
reference: loc,
};

Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type PackageRemote = {
registry: RegistryNames,
reference: string,
resolved?: ?string,
hash?: ?string,
hash: ?string,
};

// `dependencies` field in package info
Expand Down

0 comments on commit ba5a203

Please sign in to comment.