Skip to content

Commit

Permalink
Fix tarball file (#3221)
Browse files Browse the repository at this point in the history
* Fixes #3168

* Adds tests

* Fixes linting
  • Loading branch information
arcanis authored and bestander committed Apr 26, 2017
1 parent e4a5102 commit d54fff3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions __tests__/commands/install/lockfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const fsNode = require('fs');
const path = require('path');
const os = require('os');

test.concurrent('does fetch files from the local filesystem', (): Promise<void> => {
return runInstall({}, 'install-should-fetch-local-tarballs', (config): Promise<void> => {
return Promise.resolve();
});
});

test.concurrent("doesn't write new lockfile if existing one satisfied", (): Promise<void> => {
return runInstall({}, 'install-dont-write-lockfile-if-satisfied', async (config): Promise<void> => {
const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"license": "MIT",
"dependencies": {
"fake-dependency": "./fake-dependency-1.0.1.tgz"
}
}
8 changes: 7 additions & 1 deletion src/fetchers/tarball-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class TarballFetcher extends BaseFetcher {
const tarballMirrorPath = this.getTarballMirrorPath();
const tarballCachePath = this.getTarballCachePath();

const tarballPath = override || tarballMirrorPath || tarballCachePath;
const tarballPath = path.resolve(this.config.cwd, override || tarballMirrorPath || tarballCachePath);

if (!tarballPath || !await fsUtil.exists(tarballPath)) {
throw new MessageError(this.config.reporter.lang('tarballNotInNetworkOrCache', this.reference, tarballPath));
Expand Down Expand Up @@ -178,6 +178,12 @@ export default class TarballFetcher extends BaseFetcher {
}

async _fetch(): Promise<FetchedOverride> {
const urlParse = url.parse(this.reference);

if (urlParse.protocol === null && urlParse.pathname.match(/^\.\.?[\/\\]/)) {
return await this.fetchFromLocal(this.reference);
}

if (await this.getLocalAvailabilityStatus()) {
return await this.fetchFromLocal();
} else {
Expand Down

0 comments on commit d54fff3

Please sign in to comment.