Skip to content

Commit bff0a72

Browse files
committedDec 5, 2019
fix: do not overwrite existing files
1 parent 66f9d27 commit bff0a72

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed
 

‎__tests__/install.spec.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ const { directory } = require('tempy');
44
const { resolve } = require('path');
55
const { promisify } = require('util');
66
const stripEOF = require('strip-final-newline');
7+
const fs = require('fs');
78
const execFile = promisify(require('child_process').execFile);
8-
const rm = promisify(require('fs').unlink);
9-
const stat = promisify(require('fs').stat);
9+
10+
const rm = promisify(fs.unlink);
11+
const stat = promisify(fs.stat);
12+
const writeFile = promisify(fs.writeFile);
13+
const readFile = promisify(fs.readFile);
1014

1115
describe('test installing the package', () => {
1216
const kFilename = 'deploy.tgz';
@@ -47,6 +51,23 @@ describe('test installing the package', () => {
4751
expect((await stat('.releaserc.json')).isFile()).toBe(true);
4852
expect((await stat('.commitlintrc.js')).isFile()).toBe(true);
4953
});
54+
55+
test('on reinstall doesnt overwrite existing .releaserc.js(on)', async () => {
56+
expect.assertions(1);
57+
58+
await writeFile('.releaserc.json', 'overwrite');
59+
const { stderr } = await execFile('yarn', ['add', tarball]);
60+
console.info(stderr);
61+
await expect(readFile('.releaserc.json', 'utf8')).resolves.toBe('overwrite');
62+
}, 240000);
63+
64+
test('on reinstall doesnt overwrite existing .commitlintrc.js', async () => {
65+
expect.assertions(1);
66+
67+
await writeFile('.commitlintrc.js', 'overwrite');
68+
await execFile('yarn', ['add', tarball]);
69+
await expect(readFile('.commitlintrc.js', 'utf8')).resolves.toBe('overwrite');
70+
}, 240000);
5071
});
5172

5273
describe('installs globally', () => {

‎scripts/setup-semantic-release.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ async function isInstallingGlobally() {
6666
return globalDirs.includes(rootDir());
6767
}
6868

69-
async function copyConfiguration(filename, _fallback) {
70-
const fallback = Array.isArray(_fallback) ? [filename].concat(_fallback) : [filename];
69+
async function copyConfiguration(filename, _fallback = []) {
70+
const names = Array.isArray(_fallback) ? [filename].concat(_fallback) : [filename];
7171
const prefix = rootDir();
7272
const rcpath = path.join(prefix, filename);
7373

74-
for (const idx of fallback) {
74+
for (const name of names) {
7575
try {
76-
const datum = await stat(path.join(prefix, fallback[idx]));
76+
const datum = await stat(path.join(prefix, name));
7777
if (datum.isFile() === true) return; // do not overwrite
7878
} catch (e) {
79+
debug('failed to stat', e);
7980
// no file - write a new one down
8081
}
8182
}

0 commit comments

Comments
 (0)
Please sign in to comment.