Skip to content

Commit a224497

Browse files
pathurspvdlg
authored andcommitted
fix: skip tarball move if config is cwd
1 parent d2932ba commit a224497

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/prepare.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ module.exports = async ({tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRe
3535
);
3636

3737
const tarball = (await packResult).stdout.split('\n').pop();
38-
await move(path.resolve(cwd, tarball), path.resolve(cwd, tarballDir.trim(), tarball));
38+
const tarballSource = path.resolve(cwd, tarball);
39+
const tarballDestination = path.resolve(cwd, tarballDir.trim(), tarball);
40+
41+
// Only move the tarball if we need to
42+
// Fixes: https://github.com/semantic-release/npm/issues/169
43+
if (tarballSource !== tarballDestination) {
44+
await move(tarballSource, tarballDestination);
45+
}
3946
}
4047
};

test/prepare.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,29 @@ test('Create the package in the "tarballDir" directory', async t => {
226226
// Verify the logger has been called with the version updated
227227
t.deepEqual(t.context.log.args[0], ['Write version %s to package.json in %s', '1.0.0', cwd]);
228228
});
229+
230+
test('Only move the created tarball if the "tarballDir" directory is not the CWD', async t => {
231+
const cwd = tempy.directory();
232+
const packagePath = path.resolve(cwd, 'package.json');
233+
const pkg = {name: 'my-pkg', version: '0.0.0-dev'};
234+
await outputJson(packagePath, pkg);
235+
236+
await prepare(
237+
{tarballDir: '.'},
238+
{
239+
cwd,
240+
env: {},
241+
stdout: t.context.stdout,
242+
stderr: t.context.stderr,
243+
nextRelease: {version: '1.0.0'},
244+
logger: t.context.logger,
245+
}
246+
);
247+
248+
// Verify package.json has been updated
249+
t.is((await readJson(packagePath)).version, '1.0.0');
250+
251+
t.true(await pathExists(path.resolve(cwd, `${pkg.name}-1.0.0.tgz`)));
252+
// Verify the logger has been called with the version updated
253+
t.deepEqual(t.context.log.args[0], ['Write version %s to package.json in %s', '1.0.0', cwd]);
254+
});

0 commit comments

Comments
 (0)