Skip to content

解决zip空文件夹无法打包问题 #65

Open
@mazhaoshuo

Description

@mazhaoshuo

修改 lib/zip/stream.js 文件中添加 _addDirEntry 方法如下,添加一下代码,此方法为临时修复,希望作者可以给出相应的修复方案,更新npm包
此方案只修复zip打包方式,其他打包请参考

//需要头部导入两个包
const fs = require('fs');
const utils = require('../utils');

_addDirEntry(entry, opts) {
    //先创建文件夹
    this._zipfile.addEmptyDirectory(opts.relativePath || path.basename(entry), opts);
    fs.readdir(entry, (err, files) => {
      if (err) return this.emit('error', err);
      const relativePath = opts.relativePath || '';
      files.forEach(fileOrDir => {
        const newOpts = utils.clone(opts);
        if (opts.ignoreBase) {
          newOpts.relativePath = path.join(relativePath, fileOrDir);
        } else {
          newOpts.relativePath = path.join(relativePath, path.basename(entry), fileOrDir);
        }
        newOpts.ignoreBase = true;
        this.addEntry(path.join(entry, fileOrDir), newOpts);
      });
      this._onEntryFinish();
    });
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions