bestzip 2.2.5 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +14 -9
- package/lib/bestzip.js +10 -15
- package/package.json +9 -9
- package/readme.md +19 -11
package/bin/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as bestzip from "../lib/bestzip.js";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import yargs from "yargs";
|
|
6
|
+
import { hideBin } from "yargs/helpers";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
const argv = yargs(hideBin(process.argv))
|
|
8
9
|
.usage("\nUsage: bestzip destination.zip sources/")
|
|
9
10
|
.option("force", {
|
|
10
11
|
describe: "Force use of node.js or native zip methods",
|
|
@@ -17,8 +18,8 @@ var argv = require("yargs")
|
|
|
17
18
|
})
|
|
18
19
|
.demand(2).argv;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const destination = argv._.shift();
|
|
22
|
+
const source = argv._;
|
|
22
23
|
|
|
23
24
|
if (argv.level < -1 || argv.level > 9) {
|
|
24
25
|
console.error("Invalid compression level, must be >= 0 and <= 9");
|
|
@@ -27,15 +28,19 @@ if (argv.level < -1 || argv.level > 9) {
|
|
|
27
28
|
|
|
28
29
|
console.log("Writing %s to %s...", source.join(", "), destination);
|
|
29
30
|
|
|
31
|
+
let zip;
|
|
32
|
+
|
|
30
33
|
if (argv.force === "node") {
|
|
31
|
-
zip =
|
|
34
|
+
zip = bestzip.nodeZip;
|
|
32
35
|
} else if (argv.force === "native") {
|
|
33
|
-
zip =
|
|
36
|
+
zip = bestzip.nativeZip;
|
|
37
|
+
} else {
|
|
38
|
+
zip = bestzip.zip;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
zip({
|
|
37
|
-
source
|
|
38
|
-
destination
|
|
42
|
+
source,
|
|
43
|
+
destination,
|
|
39
44
|
verbose: !!argv.verbose,
|
|
40
45
|
level: argv.level,
|
|
41
46
|
})
|
package/lib/bestzip.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// creates a zip file using either the native `zip` command if available,
|
|
2
2
|
// or a node.js zip implementation otherwise.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import cp from "node:child_process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const archiver = require("archiver");
|
|
11
|
-
const { glob, hasMagic } = require("glob");
|
|
12
|
-
const which = require("which");
|
|
8
|
+
import { ZipArchive } from "archiver";
|
|
9
|
+
import { glob, hasMagic } from "glob";
|
|
10
|
+
import which from "which";
|
|
13
11
|
|
|
14
12
|
function hasNativeZip() {
|
|
15
13
|
return Boolean(which.sync("zip", { nothrow: true }));
|
|
@@ -103,7 +101,7 @@ const nativeZip = async (options) => {
|
|
|
103
101
|
const nodeZip = async (options) => {
|
|
104
102
|
const cwd = options.cwd || process.cwd();
|
|
105
103
|
const output = fs.createWriteStream(path.resolve(cwd, options.destination));
|
|
106
|
-
const archive =
|
|
104
|
+
const archive = new ZipArchive({
|
|
107
105
|
zlib: { level: options.level },
|
|
108
106
|
});
|
|
109
107
|
|
|
@@ -174,9 +172,6 @@ function zip(options) {
|
|
|
174
172
|
}
|
|
175
173
|
}
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
module.exports.nativeZip = nativeZip;
|
|
181
|
-
module.exports.bestzip = zip;
|
|
182
|
-
module.exports.hasNativeZip = hasNativeZip;
|
|
175
|
+
export default zip;
|
|
176
|
+
|
|
177
|
+
export { zip, nodeZip, nativeZip, hasNativeZip };
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bestzip",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Uses OS zip command if available (for better performance and speed) or node.js version if there is no system command available. Can be called via node or command line.",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./lib/bestzip.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"bestzip": "bin/cli.js"
|
|
8
9
|
},
|
|
9
10
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
11
|
+
"node": ">=22"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
14
|
"lint": "eslint .",
|
|
14
15
|
"lint-fix": "eslint --fix .",
|
|
15
|
-
"unit-test": "
|
|
16
|
+
"unit-test": "node --experimental-test-snapshots --test",
|
|
17
|
+
"update-snapshot": "npm run unit-test -- --test-update-snapshots",
|
|
16
18
|
"test": "npm run lint && npm run unit-test"
|
|
17
19
|
},
|
|
18
20
|
"author": "Nathan Friedly - http://nfriedly.com/",
|
|
@@ -27,21 +29,19 @@
|
|
|
27
29
|
"lib/"
|
|
28
30
|
],
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"archiver": "^
|
|
32
|
+
"archiver": "^8.0.0",
|
|
31
33
|
"glob": "^13.0.6",
|
|
32
34
|
"which": "^6.0.1",
|
|
33
35
|
"yargs": "^16.2.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"chai": "^4.3.4",
|
|
37
38
|
"command-line-test": "^1.0.10",
|
|
38
39
|
"eslint": "^8.57.1",
|
|
39
40
|
"eslint-config-prettier": "^8.1.0",
|
|
40
41
|
"eslint-plugin-prettier": "^3.3.1",
|
|
41
|
-
"jest": "^29.7.0",
|
|
42
42
|
"klaw-sync": "^6.0.0",
|
|
43
43
|
"prettier": "^2.2.1",
|
|
44
|
-
"rimraf": "^3.0.2",
|
|
45
44
|
"unzip-stream": "^0.3.1"
|
|
46
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"packageManager": "npm@11.14.1"
|
|
47
47
|
}
|
package/readme.md
CHANGED
|
@@ -39,19 +39,24 @@ package.json:
|
|
|
39
39
|
## Programmatic usage from within Node.js
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
|
|
42
|
+
import zip from 'bestzip';
|
|
43
|
+
// use version 2.x for require()
|
|
43
44
|
|
|
44
|
-
zip
|
|
45
|
+
// zip a single source
|
|
46
|
+
await zip({
|
|
45
47
|
source: 'build/*',
|
|
46
48
|
destination: './destination.zip'
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// zip multiple sources, starting in a different CWD (current working directory)
|
|
52
|
+
await zip({
|
|
53
|
+
source: ['img1.jpg', 'img2.jpg', 'imgn.jpg'],
|
|
54
|
+
destination: '../images.zip',
|
|
55
|
+
cwd: './images/' // optional, defaults to process.cwd()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Promises also work: zip({source, destination}).then(...).catch(...)
|
|
59
|
+
// Callbacks also work: zip(destination, sources, callback)
|
|
55
60
|
```
|
|
56
61
|
|
|
57
62
|
### Options
|
|
@@ -59,7 +64,6 @@ zip({
|
|
|
59
64
|
* `source`: Path or paths to files and folders to include in the zip file. String or Array of Strings.
|
|
60
65
|
* `destination`: Path to generated .zip file.
|
|
61
66
|
* `cwd`: Set the Current Working Directory that source and destination paths are relative to. Defaults to `process.cwd()`
|
|
62
|
-
* `level`: Set the level of compression. (Number 0-9, with 0 being no compression and 9 being the most compressed.)
|
|
63
67
|
|
|
64
68
|
## How to control the directory structure
|
|
65
69
|
|
|
@@ -90,3 +94,7 @@ Wildcards (`*`) ignore dotfiles.
|
|
|
90
94
|
|
|
91
95
|
* `bestzip output.zip foo/bar/file.txt` now includes the foo/bar/ folders, previously it would place file.txt at the top-level
|
|
92
96
|
* This was done to more closely align with the native zip command
|
|
97
|
+
|
|
98
|
+
## Breaking changes for v3
|
|
99
|
+
|
|
100
|
+
* Switched from CJS to ESM
|