美文网首页
node.js npm 之 trash

node.js npm 之 trash

作者: 织雪纱奈 | 来源:发表于2019-05-30 17:48 被阅读0次

    老狼说要每天阅读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);
    };
    

    相关文章

      网友评论

          本文标题:node.js npm 之 trash

          本文链接:https://www.haomeiwen.com/subject/bwavtctx.html