Skip to content

Commit 3b23de7

Browse files
committed
Require Node.js 8
1 parent a59b8df commit 3b23de7

10 files changed

Lines changed: 87 additions & 94 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,*.yml}]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto
1+
* text=auto eol=lf

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os: osx
22
language: node_js
33
node_js:
4-
- '6'
5-
- '4'
4+
- '10'
5+
- '8'

index.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
'use strict';
2+
const {promisify} = require('util');
23
const fs = require('fs');
34
const path = require('path');
45
const childProcess = require('child_process');
56
const runApplescript = require('run-applescript');
6-
const pify = require('pify');
77
const rimraf = require('rimraf');
88
const xdgTrashdir = require('xdg-trashdir');
99
const pathExists = require('path-exists');
1010
const pFilter = require('p-filter');
1111

12-
const emptyTrash = dir => {
13-
return pify(fs.readdir)(dir).then(files => {
14-
return Promise.all(files.map(file => pify(rimraf)(path.join(dir, file))));
15-
});
12+
const execFileP = promisify(childProcess.execFile);
13+
const readdirP = promisify(fs.readdir);
14+
const rimrafP = promisify(rimraf);
15+
16+
const linuxEmptyTrash = async directory => {
17+
const files = await readdirP(directory);
18+
await Promise.all(files.map(file => rimrafP(path.join(directory, file))));
19+
};
20+
21+
const linuxEmptyTrashes = async () => {
22+
const directories = await pFilter(await xdgTrashdir.all(), pathExists);
23+
await Promise.all(directories.map(linuxEmptyTrash));
1624
};
1725

18-
module.exports = () => {
26+
module.exports = async () => {
1927
if (process.platform === 'darwin') {
20-
return runApplescript('tell app "Finder" to if (count of items in trash) > 0 then empty trash');
28+
await runApplescript('tell app "Finder" to if (count of items in trash) > 0 then empty trash');
29+
return;
2130
}
2231

2332
if (process.platform === 'win32') {
24-
return pify(childProcess.execFile)(path.join(__dirname, 'lib', 'empty-recycle-bin.exe'));
33+
await execFileP(path.join(__dirname, 'lib/empty-recycle-bin.exe'));
34+
return;
2535
}
2636

27-
return xdgTrashdir.all()
28-
.then(dirs => pFilter(dirs, pathExists))
29-
.then(dirs => Promise.all(dirs.map(emptyTrash)));
37+
await linuxEmptyTrashes();
3038
};

license

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

33
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
116

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
{
2-
"name": "empty-trash",
3-
"version": "2.1.1",
4-
"description": "Empty the trash",
5-
"license": "MIT",
6-
"repository": "sindresorhus/empty-trash",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=4"
14-
},
15-
"scripts": {
16-
"test": "xo && ava"
17-
},
18-
"files": [
19-
"index.js",
20-
"lib"
21-
],
22-
"keywords": [
23-
"trash",
24-
"recycle",
25-
"file",
26-
"files",
27-
"dir",
28-
"directory",
29-
"directories",
30-
"empty",
31-
"clear",
32-
"macos",
33-
"osx",
34-
"windows",
35-
"linux"
36-
],
37-
"dependencies": {
38-
"p-filter": "^1.0.0",
39-
"path-exists": "^3.0.0",
40-
"pify": "^2.2.0",
41-
"rimraf": "^2.4.3",
42-
"run-applescript": "^3.0.0",
43-
"xdg-trashdir": "^2.1.0"
44-
},
45-
"devDependencies": {
46-
"ava": "*",
47-
"trash": "^3.3.0",
48-
"user-home": "^2.0.0",
49-
"xo": "*"
50-
},
51-
"xo": {
52-
"esnext": true
53-
}
2+
"name": "empty-trash",
3+
"version": "2.1.1",
4+
"description": "Empty the trash",
5+
"license": "MIT",
6+
"repository": "sindresorhus/empty-trash",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=8"
14+
},
15+
"scripts": {
16+
"test": "xo && ava"
17+
},
18+
"files": [
19+
"index.js",
20+
"lib"
21+
],
22+
"keywords": [
23+
"trash",
24+
"recycle",
25+
"file",
26+
"files",
27+
"dir",
28+
"directory",
29+
"directories",
30+
"empty",
31+
"clear",
32+
"macos",
33+
"osx",
34+
"windows",
35+
"linux"
36+
],
37+
"dependencies": {
38+
"p-filter": "^1.0.0",
39+
"path-exists": "^3.0.0",
40+
"rimraf": "^2.4.3",
41+
"run-applescript": "^3.0.0",
42+
"xdg-trashdir": "^2.1.0"
43+
},
44+
"devDependencies": {
45+
"ava": "^0.25.0",
46+
"trash": "^4.3.0",
47+
"xo": "^0.23.0"
48+
}
5449
}

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# empty-trash [![Build Status](https://travis-ci.org/sindresorhus/empty-trash.svg?branch=master)](https://travis-ci.org/sindresorhus/empty-trash)
22

3-
> Empty the [trash](http://en.wikipedia.org/wiki/Trash_(computing))
3+
> Empty the [trash](https://en.wikipedia.org/wiki/Trash_(computing))
44
55
Works on macOS, Linux, and Windows.
66

77

88
## Install
99

1010
```
11-
$ npm install --save empty-trash
11+
$ npm install empty-trash
1212
```
1313

1414

@@ -17,9 +17,9 @@ $ npm install --save empty-trash
1717
```js
1818
const emptyTrash = require('empty-trash');
1919

20-
emptyTrash().then(() => {
21-
console.log('done');
22-
});
20+
(async () => {
21+
await emptyTrash();
22+
})();
2323
```
2424

2525

test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import fs from 'fs';
2+
import os from 'os';
23
import path from 'path';
34
import test from 'ava';
45
import trash from 'trash';
5-
import userHome from 'user-home';
66
import pathExists from 'path-exists';
7-
import m from '.';
7+
import emptyTrash from '.';
88

9-
test(async t => {
10-
const file = 'emptytrashfixture';
11-
const trashFile = path.join(userHome, '.Trash', file);
9+
test('main', async t => {
10+
const file = 'empty-trash-fixture';
11+
const trashFile = path.join(os.homedir(), '.Trash', file);
1212
fs.writeFileSync(file, '');
1313
await trash([file]);
1414
t.true(pathExists.sync(trashFile));
15-
await m();
15+
await emptyTrash();
1616
t.false(pathExists.sync(trashFile));
1717
});

0 commit comments

Comments
 (0)