Comparing version 7.2.0 to 8.0.0
@@ -1,10 +0,8 @@ | ||
declare namespace trash { | ||
interface Options { | ||
/** | ||
Enable globbing when matching file paths. | ||
export interface Options { | ||
/** | ||
Enable globbing when matching file paths. | ||
@default true | ||
*/ | ||
readonly glob?: boolean; | ||
} | ||
@default true | ||
*/ | ||
readonly glob?: boolean; | ||
} | ||
@@ -19,14 +17,10 @@ | ||
``` | ||
import trash = require('trash'); | ||
import trash from 'trash'; | ||
(async () => { | ||
await trash(['*.png', '!rainbow.png']); | ||
})(); | ||
await trash(['*.png', '!rainbow.png']); | ||
``` | ||
*/ | ||
declare function trash( | ||
export default function trash( | ||
input: string | readonly string[], | ||
options?: trash.Options | ||
options?: Options | ||
): Promise<void>; | ||
export = trash; |
36
index.js
@@ -1,13 +0,13 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const globby = require('globby'); | ||
const isPathInside = require('is-path-inside'); | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
import globby from 'globby'; | ||
import isPathInside from 'is-path-inside'; | ||
const trash = async (paths, options) => { | ||
paths = (typeof paths === 'string' ? [paths] : paths).map(path => String(path)); | ||
export default async function trash(paths, options) { | ||
paths = [paths].flat().map(path => String(path)); | ||
options = { | ||
glob: true, | ||
...options | ||
...options, | ||
}; | ||
@@ -20,3 +20,3 @@ | ||
nodir: false, | ||
nonull: true | ||
nonull: true, | ||
}); | ||
@@ -31,3 +31,2 @@ } | ||
try { | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins -- It's Node 10.1+ | ||
await fs.promises.lstat(filePath); | ||
@@ -51,14 +50,15 @@ } catch (error) { | ||
let trash; | ||
let module; | ||
if (process.platform === 'darwin') { | ||
trash = require('./lib/macos.js'); | ||
// eslint-disable-next-line node/no-unsupported-features/es-syntax | ||
module = await import('./lib/macos.js'); | ||
} else if (process.platform === 'win32') { | ||
trash = require('./lib/windows.js'); | ||
// eslint-disable-next-line node/no-unsupported-features/es-syntax | ||
module = await import('./lib/windows.js'); | ||
} else { | ||
trash = require('./lib/linux.js'); | ||
// eslint-disable-next-line node/no-unsupported-features/es-syntax | ||
module = await import('./lib/linux.js'); | ||
} | ||
return trash(paths); | ||
}; | ||
module.exports = trash; | ||
return module.default(paths); | ||
} |
@@ -1,12 +0,13 @@ | ||
const {promisify} = require('util'); | ||
const {execFile} = require('child_process'); | ||
import {promisify} from 'node:util'; | ||
import {execFile} from 'node:child_process'; | ||
import {fileURLToPath} from 'node:url'; | ||
import chunkify from '@sindresorhus/chunkify'; | ||
const pExecFile = promisify(execFile); | ||
module.exports = async (binary, paths, maxPaths) => { | ||
// TODO: Use https://github.com/sindresorhus/chunkify when targeting Node.js 12. | ||
for (let group = 0; paths.length > group; group += maxPaths) { | ||
export default async function chunkedExec(binary, paths, maxPaths) { | ||
for (const chunk of chunkify(paths, maxPaths)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await pExecFile(binary, paths.slice(group, group + maxPaths)); | ||
await pExecFile(fileURLToPath(binary), chunk); | ||
} | ||
}; | ||
} |
@@ -1,16 +0,10 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const uuid = require('uuid'); | ||
const xdgTrashdir = require('xdg-trashdir'); | ||
const pMap = require('p-map'); | ||
const makeDir = require('make-dir'); | ||
const moveFile = require('move-file'); | ||
const {procfs} = require('@stroncium/procfs'); | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import {v4 as uuidv4} from 'uuid'; | ||
import xdgTrashdir from 'xdg-trashdir'; | ||
import pMap from 'p-map'; | ||
import {moveFile} from 'move-file'; | ||
import {procfs} from '@stroncium/procfs'; | ||
const lstat = promisify(fs.lstat); | ||
const writeFile = promisify(fs.writeFile); | ||
// Educated guess, values of 16 to 64 seem to be optimal for modern SSD, 8-16 and 64-128 can be a bit slower. | ||
@@ -23,11 +17,11 @@ // We should be ok as long as ssdCount <= cpuCount <= ssdCount*16. | ||
const getDeletionDate = date => date.getFullYear() + | ||
'-' + pad(date.getMonth() + 1) + | ||
'-' + pad(date.getDate()) + | ||
'T' + pad(date.getHours()) + | ||
':' + pad(date.getMinutes()) + | ||
':' + pad(date.getSeconds()); | ||
const getDeletionDate = date => date.getFullYear() | ||
+ '-' + pad(date.getMonth() + 1) | ||
+ '-' + pad(date.getDate()) | ||
+ 'T' + pad(date.getHours()) | ||
+ ':' + pad(date.getMinutes()) | ||
+ ':' + pad(date.getSeconds()); | ||
const trash = async (filePath, trashPaths) => { | ||
const name = uuid.v4(); | ||
const name = uuidv4(); | ||
const destination = path.join(trashPaths.filesPath, name); | ||
@@ -38,3 +32,3 @@ const trashInfoPath = path.join(trashPaths.infoPath, `${name}.trashinfo`); | ||
await writeFile(trashInfoPath, trashInfoData); | ||
await fs.promises.writeFile(trashInfoPath, trashInfoData); | ||
await moveFile(filePath, destination); | ||
@@ -44,7 +38,7 @@ | ||
path: destination, | ||
info: trashInfoPath | ||
info: trashInfoPath, | ||
}; | ||
}; | ||
module.exports = async paths => { | ||
export default async function linux(paths) { | ||
const mountPointMap = new Map(procfs.processMountinfo().map(info => [info.devId, info.mountPoint])); | ||
@@ -60,7 +54,6 @@ const trashPathsCache = new Map(); | ||
filesPath: path.join(trashPath, 'files'), | ||
infoPath: path.join(trashPath, 'info') | ||
infoPath: path.join(trashPath, 'info'), | ||
}; | ||
// TODO: Use the `fs.mkdir` with `recursive` option when targeting Node.js 12. | ||
await makeDir(paths.filesPath, {mode: 0o700}); | ||
await makeDir(paths.infoPath, {mode: 0o700}); | ||
await fs.promises.mkdir(paths.filesPath, {mode: 0o700, recursive: true}); | ||
await fs.promises.mkdir(paths.infoPath, {mode: 0o700, recursive: true}); | ||
return paths; | ||
@@ -75,6 +68,6 @@ })(); | ||
return pMap(paths, async filePath => { | ||
const stats = await lstat(filePath); | ||
const stats = await fs.promises.lstat(filePath); | ||
const trashPaths = await getDeviceTrashPaths(stats.dev); | ||
return trash(filePath, trashPaths); | ||
}, {concurrency}); | ||
}; | ||
} |
@@ -1,5 +0,3 @@ | ||
'use strict'; | ||
const os = require('os'); | ||
const path = require('path'); | ||
const chunkedExec = require('./chunked-exec.js'); | ||
import os from 'node:os'; | ||
import chunkedExec from './chunked-exec.js'; | ||
@@ -9,5 +7,5 @@ const isOlderThanMountainLion = Number(os.release().split('.')[0]) < 12; | ||
// Binary source: https://github.com/sindresorhus/macos-trash | ||
const binary = path.join(__dirname, 'macos-trash'); | ||
const binary = new URL('macos-trash', import.meta.url); | ||
module.exports = async paths => { | ||
export default async function macOS(paths) { | ||
if (isOlderThanMountainLion) { | ||
@@ -18,2 +16,2 @@ throw new Error('macOS 10.12 or later required'); | ||
await chunkedExec(binary, paths, 1000); | ||
}; | ||
} |
@@ -1,10 +0,8 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const chunkedExec = require('./chunked-exec.js'); | ||
import chunkedExec from './chunked-exec.js'; | ||
// Binary source: https://github.com/sindresorhus/recycle-bin | ||
const binary = path.join(__dirname, 'windows-trash.exe'); | ||
const binary = new URL('windows-trash.exe', import.meta.url); | ||
module.exports = async paths => { | ||
export default async function windows(paths) { | ||
await chunkedExec(binary, paths, 200); | ||
}; | ||
} |
{ | ||
"name": "trash", | ||
"version": "7.2.0", | ||
"version": "8.0.0", | ||
"description": "Move files and folders to the trash", | ||
@@ -13,7 +13,9 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
"test": "xo && ava --timeout=10m && tsd" | ||
}, | ||
@@ -44,8 +46,8 @@ "files": [ | ||
"dependencies": { | ||
"@sindresorhus/chunkify": "^0.2.0", | ||
"@stroncium/procfs": "^1.2.1", | ||
"globby": "^7.1.1", | ||
"is-path-inside": "^3.0.2", | ||
"make-dir": "^3.1.0", | ||
"move-file": "^2.0.0", | ||
"p-map": "^4.0.0", | ||
"is-path-inside": "^4.0.0", | ||
"move-file": "^3.0.0", | ||
"p-map": "^5.1.0", | ||
"uuid": "^8.3.2", | ||
@@ -55,7 +57,8 @@ "xdg-trashdir": "^3.1.0" | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tempfile": "^3.0.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.37.1" | ||
"ava": "^3.15.0", | ||
"tempfile": "^4.0.0", | ||
"tsd": "^0.17.0", | ||
"typescript": "^4.4.3", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -13,5 +13,5 @@ # ![trash](media/logo.svg) | ||
```sh | ||
npm install trash | ||
``` | ||
$ npm install trash | ||
``` | ||
@@ -21,7 +21,5 @@ ## Usage | ||
```js | ||
const trash = require('trash'); | ||
import trash from 'trash'; | ||
(async () => { | ||
await trash(['*.png', '!rainbow.png']); | ||
})(); | ||
await trash(['*.png', '!rainbow.png']); | ||
``` | ||
@@ -28,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
0
Yes
47916
5
155
73
+ Added@sindresorhus/chunkify@0.2.0(transitive)
+ Addedaggregate-error@4.0.1(transitive)
+ Addedclean-stack@4.2.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedis-path-inside@4.0.0(transitive)
+ Addedmove-file@3.1.0(transitive)
+ Addedp-map@5.5.0(transitive)
+ Addedpath-exists@5.0.0(transitive)
- Removedmake-dir@^3.1.0
- Removedaggregate-error@3.1.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedis-path-inside@3.0.3(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedmove-file@2.1.0(transitive)
- Removedp-map@4.0.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedsemver@6.3.1(transitive)
Updatedis-path-inside@^4.0.0
Updatedmove-file@^3.0.0
Updatedp-map@^5.1.0