Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bestzip

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bestzip - npm Package Compare versions

Comparing version 2.1.6 to 2.1.7

147

lib/bestzip.js

@@ -19,29 +19,78 @@ // creates a zip file using either the native `zip` command if available,

function expandSources(cwd, source, done) {
// options to behave more like the native zip's glob support
const globOpts = {
cwd,
dot: false, // ignore .dotfiles
noglobstar: true, // treat ** as *
noext: true, // no (a|b)
nobrace: true // no {a,b}
};
// first handle arrays
if (Array.isArray(source)) {
return async.concat(
source,
(_source, next) => expandSources(cwd, _source, next),
done
);
}
// then expand magic
if (typeof source !== "string") {
throw new Error(`source is (${typeof source}) `);
}
if (glob.hasMagic(source, globOpts)) {
// archiver uses this library but somehow ends up with different results on windows:
// archiver.glob('*') will include subdirectories, but omit their contents on windows
// so we'll use glob directly, and add all of the files it finds
glob(source, globOpts, done);
} else {
// or just trigger the callback with the source string if there is no magic
process.nextTick(() => {
// always return an array
done(null, [source]);
});
}
}
function walkDir(fullPath) {
const files = fs.readdirSync(fullPath).map(f => {
const filePath = path.join(fullPath, f);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
return walkDir(filePath);
}
return filePath;
});
return files.reduce((acc, cur) => acc.concat(cur), []);
}
const nativeZip = options =>
new Promise((resolve, reject) => {
const sources = Array.isArray(options.source)
? options.source.join(" ")
: options.source;
const command = `zip --quiet --recurse-paths ${
options.destination
} ${sources}`;
const zipProcess = cp.exec(command, {
stdio: "inherit",
cwd: options.cwd
const cwd = options.cwd || process.cwd();
const command = "zip";
expandSources(cwd, options.source, (err, sources) => {
const args = ["--quiet", "--recurse-paths", options.destination].concat(
sources
);
const zipProcess = cp.spawn(command, args, {
stdio: "inherit",
cwd
});
zipProcess.on("error", reject);
zipProcess.on("close", exitCode => {
if (exitCode === 0) {
resolve();
} else {
// exit code 12 means "nothing to do" right?
//console.log('rejecting', zipProcess)
reject(
new Error(
`Unexpected exit code from native zip: ${exitCode}\n executed command '${command} ${args.join(
" "
)}'\n executed in directory '${cwd}'`
)
);
}
});
});
zipProcess.on("error", reject);
zipProcess.on("close", exitCode => {
if (exitCode === 0) {
resolve();
} else {
// exit code 12 means "nothing to do" right?
//console.log('rejecting', zipProcess)
reject(
new Error(
`Unexpected exit code from native zip command: ${exitCode}\n executed command '${command}'\n executed inin directory '${options.cwd ||
process.cwd()}'`
)
);
}
});
});

@@ -61,39 +110,2 @@

const globOpts = {
cwd: cwd,
// options to behave more like the native zip's glob support
dot: false, // ignore .dotfiles
noglobstar: true, // treat ** as *
noext: true, // no (a|b)
nobrace: true // no {a,b}
};
function findSource(source, next) {
if (glob.hasMagic(source, globOpts)) {
// archiver uses this library but somehow ends up with different results on windows:
// archiver.glob('*') will include subdirectories, but omit their contents on windows
// so we'll use glob directly, and add all of the files it finds
glob(source, globOpts, function(err, files) {
if (err) {
return next(err);
}
async.forEach(files, addSource, next);
});
} else {
addSource(source, next);
}
}
function walkDir(fullPath) {
const files = fs.readdirSync(fullPath).map(f => {
const filePath = path.join(fullPath, f);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
return walkDir(filePath);
}
return filePath;
});
return files.reduce((acc, cur) => acc.concat(cur), []);
}
function addSource(source, next) {

@@ -122,11 +134,12 @@ const fullPath = path.resolve(cwd, source);

const sources = Array.isArray(options.source)
? options.source
: [options.source];
async.forEach(sources, findSource, function(err) {
expandSources(cwd, options.source, (err, expandedSources) => {
if (err) {
return reject(err);
}
archive.finalize();
async.forEach(expandedSources, addSource, err => {
if (err) {
return reject(err);
}
archive.finalize();
});
});

@@ -133,0 +146,0 @@ });

{
"name": "bestzip",
"version": "2.1.6",
"version": "2.1.7",
"description": "Uses OS zip command if avaliable (for better performance and speed) or node.js version if there is no system command avaliable. Can be called via node or command line.",

@@ -25,3 +25,3 @@ "main": "lib/bestzip.js",

"archiver": "^4.0.2",
"async": "^2.6.1",
"async": "^3.2.0",
"glob": "^7.1.3",

@@ -28,0 +28,0 @@ "which": "^1.3.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc