尝试使用最新版本的tar,但是tar.Pack在使用tar 4.4.6版本时失败,并显示以下错误

时间:2018-12-16 03:04:30

标签: node.js

我正在尝试使该文件节点10兼容。节点10带有自己的4.4.6版本的tar,但是上面的代码是用tar 2.2.1编写的。该错误是因为以前使用的tar.Pack现在无法使用,因为它现在编写的方式不同于以前的方式。我只想使下面的代码节点10兼容,而不会破坏功能。如果有人知道如何请帮助。

var packer = tar.Pack({
                 ^

TypeError: Class constructor  cannot be invoked without 'new'
    at Object.<anonymous> (C:\Users\LJ045283\Desktop\jenkins\user-scripts\tar-dir.js:67:18)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)





My code is here.

/**
 * Pack the entire directory to outfile.tgz
 *
 * Note: ignores the cache directory and install-io.json
 *
 * @param dir {String} Path to the source directory
 * @param outfile {String} Path/filename to the output file
 */
var fs = require('fs'),
    path = require('path'),
    zlib = require('zlib'),
    tar = require(path.join(node_env, './node_modules/tar')),
    fsignore = require(path.join(node_env, './node_modules/fstream-ignore')),
    ignores = {
        files: ['.ignore', '.gitignore'],
        rules: ['/cache/', 'install-io.json']
    },
    folder = process.argv[2],
    out = process.argv[3];

if (!folder) throw new Error('Require source directory');

folder = path.resolve(folder);

var folderStat = fs.statSync(folder);
if (!folderStat.isDirectory())
    throw new Error(util.core.format('[%s] is not a valid directory', folder));

console.log('Source directory: [%s]', folder);

// If out is not specified then use the source directory name.
out = out || process.cwd() + path.basename(folder);

if (path.extname(out) !== '.tgz') path += '.tgz';
out = path.resolve(out);

console.log('Output file to: [%s]', out);

var tgzStream = fs.createWriteStream(out),
    options = {
        path: folder
    };

tgzStream.on('close', function () {
    console.log('tgz stream closed');
});

tgzStream.on('error', function (err) {
    assert.ifError(err);
});

options.ignoreFiles = ignores.files;
options.follow = true;

var folderStream = fsignore(options);
folderStream.addIgnoreRules(ignores.rules, 'custom-rules');

folderStream.on('entry', function (e) {
    console.log('fstream entry: %s', e.path);
});
var packer = tar.Pack({
    noProprietary: true
});
folderStream.pipe(packer).pipe(zlib.Gzip()).pipe(tgzStream);

我正在使用节点10.13.0和tar 4.4.6。它与tar 2.2.1兼容。有没有解决办法?任何建议都会有所帮助。

0 个答案:

没有答案