From 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Apr 2017 03:09:25 +0200 Subject: Reorganize module loading. We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node. --- node_modules/archiver/lib/core.js | 111 +++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 49 deletions(-) (limited to 'node_modules/archiver/lib/core.js') diff --git a/node_modules/archiver/lib/core.js b/node_modules/archiver/lib/core.js index 6103d43e4..9bb80711c 100644 --- a/node_modules/archiver/lib/core.js +++ b/node_modules/archiver/lib/core.js @@ -9,6 +9,8 @@ var fs = require('fs'); var glob = require('glob'); var async = require('async'); var _ = require('lodash'); +var path = require('path'); +var walkdir = require('walkdir'); var util = require('archiver-utils'); var inherits = require('util').inherits; @@ -16,6 +18,10 @@ var Transform = require('readable-stream').Transform; var win32 = process.platform === 'win32'; +if (process._loggedBulkDeprecation === undefined) { + process._loggedBulkDeprecation = false; +} + /** * @constructor * @param {String} format The archive format to use. @@ -58,8 +64,6 @@ var Archiver = function(format, options) { }; this._streams = []; - - this._loggedBulkDeprecation = false; }; inherits(Archiver, Transform); @@ -557,8 +561,8 @@ Archiver.prototype.append = function(source, data) { * @return {this} */ Archiver.prototype.bulk = function(mappings) { - if (!this._loggedBulkDeprecation) { - this._loggedBulkDeprecation = true; + if (process._loggedBulkDeprecation === false) { + process._loggedBulkDeprecation = true; var warning = 'Archiver.bulk() deprecated since 0.21.0'; if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') { process.emitWarning(warning, 'DeprecationWarning'); @@ -655,38 +659,43 @@ Archiver.prototype.directory = function(dirpath, destpath, data) { data = {}; } - var self = this; + function onWalkPath(filepath, stats){ + var entryData = _.extend({}, data); + entryData.name = path.relative(dirpath, filepath).replace(/\\/g, '/'); + entryData.prefix = destpath; + entryData.stats = stats; - util.walkdir(dirpath, function(err, results) { - if (err) { - self.emit('error', err); - } else { - results.forEach(function(file) { - var entryData = _.extend({}, data); - entryData.name = file.relative; - entryData.prefix = destpath; - entryData.stats = file.stats; - - try { - if (dataFunction) { - entryData = dataFunction(entryData); - - if (typeof entryData !== 'object') { - throw new Error('directory: invalid data returned from custom function'); - } - } - } catch(e) { - self.emit('error', e); - return; - } + try { + if (dataFunction) { + entryData = dataFunction(entryData); - self._append(file.path, entryData); - }); + if (typeof entryData !== 'object') { + throw new Error('directory: invalid data returned from custom function'); + } + } + } catch(e) { + this.emit('error', e); + return; } - self._pending--; - self._maybeFinalize(); - }); + this._append(filepath, entryData); + } + + function onWalkEnd() { + this._pending--; + this._maybeFinalize(); + } + + function onWalkError(err) { + this.emit('error', 'directory: ' + err); + } + + var walker = walkdir(dirpath); + + walker.on('error', onWalkError.bind(this)); + walker.on('directory', onWalkPath.bind(this)); + walker.on('file', onWalkPath.bind(this)); + walker.on('end', onWalkEnd.bind(this)); return this; }; @@ -736,26 +745,30 @@ Archiver.prototype.glob = function(pattern, options, data) { stat: false }); - var globber = glob(pattern, options, function(err, files) { - if (err) { - this.emit('error', err); - return this; - } + function onGlobEnd() { + this._pending--; + this._maybeFinalize(); + } - files.forEach(function(file) { - entryData = _.extend({}, data); + function onGlobError(err) { + this.emit('error', 'glob: ' + err); + } - if (options.cwd) { - entryData.name = file; - file = globber._makeAbs(file); - } + function onGlobMatch(match){ + entryData = _.extend({}, data); - this._append(file, entryData); - }, this); + if (options.cwd) { + entryData.name = match; + match = globber._makeAbs(match); + } - this._pending--; - this._maybeFinalize(); - }.bind(this)); + this._append(match, entryData); + } + + var globber = glob(pattern, options); + globber.on('error', onGlobError.bind(this)); + globber.on('match', onGlobMatch.bind(this)); + globber.on('end', onGlobEnd.bind(this)); return this; }; @@ -890,4 +903,4 @@ module.exports = Archiver; * when working with methods like `directory` or `glob`. * @property {fs.Stats} [stats] Sets the fs stat data for this entry allowing * for reduction of fs stat calls when stat data is already known. - */ \ No newline at end of file + */ -- cgit v1.2.3