老狼说要每天阅读10个 npm 源码,我信了你的邪
读
读
读
trash源码阅读
由 sindresorhus 编写,他写了很多模块,萨摩耶头像好可爱
喂喂喂,偏离主题了
主要实现功能,移到废纸篓,而不是 rm
以下是核心代码,
1.首先是路径,检查路径,选择平台
2.promisify 封装,调用 swift trash
const isPathInside = require('is-path-inside');
paths = paths.filter(filePath => {
if (paths.some(otherPath => isPathInside(filePath, otherPath))) {
return false;
}
try {
return fs.lstatSync(filePath);
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw error;
}
});
switch (process.platform) {
case 'darwin':
return macos(paths);
case 'win32':
return windows(paths);
default:
return linux(paths);
}
const {promisify} = require('util');
const os = require('os');
const path = require('path');
const {execFile} = require('child_process');
module.exports = async paths => {
await pExecFile(binary, paths);
};
网友评论