Skip to content

Commit

Permalink
fix: skip tarball move if config is cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
pathurs authored and pvdlg committed Aug 21, 2019
1 parent d2932ba commit a224497
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/prepare.js
Expand Up @@ -35,6 +35,13 @@ module.exports = async ({tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRe
);

const tarball = (await packResult).stdout.split('\n').pop();
await move(path.resolve(cwd, tarball), path.resolve(cwd, tarballDir.trim(), tarball));
const tarballSource = path.resolve(cwd, tarball);
const tarballDestination = path.resolve(cwd, tarballDir.trim(), tarball);

// Only move the tarball if we need to
// Fixes: https://github.com/semantic-release/npm/issues/169
if (tarballSource !== tarballDestination) {
await move(tarballSource, tarballDestination);
}
}
};
26 changes: 26 additions & 0 deletions test/prepare.test.js
Expand Up @@ -226,3 +226,29 @@ test('Create the package in the "tarballDir" directory', async t => {
// Verify the logger has been called with the version updated
t.deepEqual(t.context.log.args[0], ['Write version %s to package.json in %s', '1.0.0', cwd]);
});

test('Only move the created tarball if the "tarballDir" directory is not the CWD', async t => {
const cwd = tempy.directory();
const packagePath = path.resolve(cwd, 'package.json');
const pkg = {name: 'my-pkg', version: '0.0.0-dev'};
await outputJson(packagePath, pkg);

await prepare(
{tarballDir: '.'},
{
cwd,
env: {},
stdout: t.context.stdout,
stderr: t.context.stderr,
nextRelease: {version: '1.0.0'},
logger: t.context.logger,
}
);

// Verify package.json has been updated
t.is((await readJson(packagePath)).version, '1.0.0');

t.true(await pathExists(path.resolve(cwd, `${pkg.name}-1.0.0.tgz`)));
// Verify the logger has been called with the version updated
t.deepEqual(t.context.log.args[0], ['Write version %s to package.json in %s', '1.0.0', cwd]);
});

0 comments on commit a224497

Please sign in to comment.