Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 4, 2019
1 parent 2bb6351 commit 71e6b34
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Options {
*
* @param source - File you want to move.
* @param destination - Where you want the file moved.
* @returns A `Promise`.
* @returns A `Promise` that resolves when the file has been moved.
*/
export default function moveFile(
source: string,
Expand Down
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ const moveFile = async (source, destination, options) => {
throw new TypeError('`source` and `destination` file required');
}

options = {overwrite: true, ...options};
options = {
overwrite: true,
...options
};

if (!options.overwrite && await pathExists(destination)) {
throw new Error('Destination file exists');
throw new Error(`The destination file exists: ${destination}`);
}

// TODO: Use the native `fs.mkdir` `recursive` option instead when targeting Node.js 10
await makeDir(path.dirname(destination));

try {
Expand All @@ -41,10 +45,13 @@ module.exports.sync = (source, destination, options) => {
throw new TypeError('`source` and `destination` file required');
}

options = {overwrite: true, ...options};
options = {
overwrite: true,
...options
};

if (!options.overwrite && fs.existsSync(destination)) {
throw new Error('Destination file exists');
throw new Error(`The destination file exists: ${destination}`);
}

makeDir.sync(path.dirname(destination));
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"partitions"
],
"dependencies": {
"cp-file": "^5.0.0",
"make-dir": "^1.1.0",
"cp-file": "^6.0.0",
"make-dir": "^2.1.0",
"path-exists": "^3.0.0"
},
"devDependencies": {
"ava": "^1.2.1",
"sinon": "^4.1.0",
"sinon": "^7.2.6",
"temp-write": "^3.3.0",
"tempy": "^0.2.1",
"tsd-check": "^0.3.0",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const moveFile = require('move-file');

(async () => {
await moveFile('source/unicorn.png', 'destination/unicorn.png');
console.log('File moved');
console.log('The file has been moved');
})();
```

Expand All @@ -36,7 +36,7 @@ const moveFile = require('move-file');

### moveFile(source, destination, [options])

Returns a `Promise`.
Returns a `Promise` that resolves when the file has been moved.

### moveFile.sync(source, destination, [options])

Expand Down
2 changes: 1 addition & 1 deletion test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ test.serial('move a file across devices', async t => {
test('overwrite option', async t => {
await t.throwsAsync(
moveFile(tempWrite.sync('x'), tempWrite.sync('y'), {overwrite: false}),
/Destination file exists/
/The destination file exists/
);
});
2 changes: 1 addition & 1 deletion test/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ test('move a file across devices', t => {
test('overwrite option', t => {
t.throws(() => {
moveFile.sync(tempWrite.sync('x'), tempWrite.sync('y'), {overwrite: false});
}, /Destination file exists/);
}, /The destination file exists/);
});

0 comments on commit 71e6b34

Please sign in to comment.