Skip to content

Commit a457fdc

Browse files
pathurspvdlg
authored andcommitted
fix: skip tarball move if config is cwd
1 parent 9498e21 commit a457fdc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/prepare.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ module.exports = async ({tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRe
3232
);
3333

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

test/prepare.test.js

+26
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)