archiver-node 8.0.1 → 8.0.3

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/cjs/Archiver.js CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var Archiver_exports = {};
19
29
  __export(Archiver_exports, {
@@ -22,14 +32,15 @@ __export(Archiver_exports, {
22
32
  module.exports = __toCommonJS(Archiver_exports);
23
33
  var import_fs = require("fs");
24
34
  var import_is_stream = require("is-stream");
25
- var import_readdir_glob = require("readdir-glob");
35
+ var import_readdir_glob = __toESM(require("readdir-glob"), 1);
26
36
  var import_lazystream = require("./lazystream.js");
27
37
  var import_async = require("async");
28
38
  var import_path = require("path");
29
39
  var import_error = require("./error.js");
30
40
  var import_readable_stream = require("readable-stream");
31
41
  var import_utils = require("./utils.js");
32
- const { ReaddirGlob } = import_readdir_glob.readdirGlob;
42
+ const readdirGlob = import_readdir_glob.default || import_readdir_glob.readdirGlob;
43
+ const { ReaddirGlob } = readdirGlob;
33
44
  const win32 = process.platform === "win32";
34
45
  class Archiver extends import_readable_stream.Transform {
35
46
  _supportsDirectory = false;
@@ -589,7 +600,7 @@ class Archiver extends import_readable_stream.Transform {
589
600
  }
590
601
  this._append(match.absolute, entryData);
591
602
  }
592
- const globber = (0, import_readdir_glob.readdirGlob)(dirpath, globOptions);
603
+ const globber = readdirGlob(dirpath, globOptions);
593
604
  globber.on("error", onGlobError.bind(this));
594
605
  globber.on("match", onGlobMatch.bind(this));
595
606
  globber.on("end", onGlobEnd.bind(this));
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "archiver-node/cjs",
3
+ "type": "commonjs",
4
+ "private": true
5
+ }
package/lib/Archiver.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { createReadStream, lstat, readlinkSync, Stats } from "fs";
2
2
  import { isStream } from "is-stream";
3
- import { readdirGlob } from "readdir-glob";
3
+ // `readdir-glob` has different exports in `esm` and `cjs`:
4
+ // in `esm` it's a named export but in `cjs` it's a default export.
5
+ // https://github.com/Yqnn/node-readdir-glob/issues/28
6
+ // As a result, this package's code can't be transpiled properly.
7
+ // Copy-pasted `readdir-glob` code here to fix that.
8
+ import{ readdirGlob } from "./readdir-glob.js";
4
9
  import { Readable } from "./lazystream.js";
5
10
  import { queue } from "async";
6
11
  import {
@@ -0,0 +1,216 @@
1
+ // `readdir-glob` has different exports in `esm` and `cjs`:
2
+ // in `esm` it's a named export but in `cjs` it's a default export.
3
+ // https://github.com/Yqnn/node-readdir-glob/issues/28
4
+ // As a result, this package's code can't be transpiled properly.
5
+ // Copy-pasted `readdir-glob` code here to fix that.
6
+
7
+ // Converted TypeScript to Javascript on TypeScript website:
8
+ // https://www.typescriptlang.org/play/?target=9#
9
+
10
+ import * as fs from 'fs';
11
+ import { EventEmitter } from 'events';
12
+ import { Minimatch } from 'minimatch';
13
+ import { resolve } from 'path';
14
+ function readdir(dir, strict) {
15
+ return new Promise((resolve, reject) => {
16
+ fs.readdir(dir, { withFileTypes: true }, (err, files) => {
17
+ if (err) {
18
+ switch (err.code) {
19
+ case 'ENOTDIR': // Not a directory
20
+ if (strict) {
21
+ reject(err);
22
+ }
23
+ else {
24
+ resolve([]);
25
+ }
26
+ break;
27
+ case 'ENOTSUP': // Operation not supported
28
+ case 'ENOENT': // No such file or directory
29
+ case 'ENAMETOOLONG': // Filename too long
30
+ case 'UNKNOWN':
31
+ resolve([]);
32
+ break;
33
+ case 'ELOOP': // Too many levels of symbolic links
34
+ default:
35
+ reject(err);
36
+ break;
37
+ }
38
+ }
39
+ else {
40
+ resolve(files);
41
+ }
42
+ });
43
+ });
44
+ }
45
+ function getStat(file, followSymlinks) {
46
+ return new Promise((resolve) => {
47
+ const statFunc = followSymlinks ? fs.stat : fs.lstat;
48
+ statFunc(file, (err, stats) => {
49
+ if (err) {
50
+ switch (err.code) {
51
+ case 'ENOENT':
52
+ if (followSymlinks) {
53
+ // Fallback to lstat to handle broken links as files
54
+ resolve(getStat(file, false));
55
+ }
56
+ else {
57
+ resolve(null);
58
+ }
59
+ break;
60
+ default:
61
+ resolve(null);
62
+ break;
63
+ }
64
+ }
65
+ else {
66
+ resolve(stats);
67
+ }
68
+ });
69
+ });
70
+ }
71
+ async function* exploreWalkAsync(dir, path, followSymlinks, useStat, shouldSkip, strict) {
72
+ let files = await readdir(path + dir, strict);
73
+ for (const file of files) {
74
+ let name = file.name;
75
+ const filename = dir + '/' + name;
76
+ const relative = filename.slice(1); // Remove the leading /
77
+ const absolute = path + '/' + relative;
78
+ let stat = file;
79
+ if (useStat || followSymlinks) {
80
+ stat = await getStat(absolute, followSymlinks) ?? stat;
81
+ }
82
+ if (stat.isDirectory()) {
83
+ if (!shouldSkip(relative)) {
84
+ yield { relative, absolute, stat };
85
+ yield* exploreWalkAsync(filename, path, followSymlinks, useStat, shouldSkip, false);
86
+ }
87
+ }
88
+ else {
89
+ yield { relative, absolute, stat };
90
+ }
91
+ }
92
+ }
93
+ async function* explore(path, followSymlinks, useStat, shouldSkip) {
94
+ yield* exploreWalkAsync('', path, followSymlinks, useStat, shouldSkip, true);
95
+ }
96
+ function readOptions(options) {
97
+ return {
98
+ pattern: options.pattern,
99
+ dot: !!options.dot,
100
+ noglobstar: !!options.noglobstar,
101
+ matchBase: !!options.matchBase,
102
+ nocase: !!options.nocase,
103
+ ignore: options.ignore,
104
+ skip: options.skip,
105
+ follow: !!options.follow,
106
+ stat: !!options.stat,
107
+ nodir: !!options.nodir,
108
+ mark: !!options.mark,
109
+ silent: !!options.silent,
110
+ absolute: !!options.absolute
111
+ };
112
+ }
113
+ export class ReaddirGlob extends EventEmitter {
114
+ constructor(cwd, options, cb) {
115
+ super();
116
+ if (typeof options === 'function') {
117
+ cb = options;
118
+ options = undefined;
119
+ }
120
+ this.options = readOptions(options || {});
121
+ this.matchers = [];
122
+ if (this.options.pattern) {
123
+ const matchers = Array.isArray(this.options.pattern) ? this.options.pattern : [this.options.pattern];
124
+ this.matchers = matchers.map(m => new Minimatch(m, {
125
+ dot: this.options.dot,
126
+ noglobstar: this.options.noglobstar,
127
+ matchBase: this.options.matchBase,
128
+ nocase: this.options.nocase
129
+ }));
130
+ }
131
+ this.ignoreMatchers = [];
132
+ if (this.options.ignore) {
133
+ const ignorePatterns = Array.isArray(this.options.ignore) ? this.options.ignore : [this.options.ignore];
134
+ this.ignoreMatchers = ignorePatterns.map(ignore => new Minimatch(ignore, { dot: true }));
135
+ }
136
+ this.skipMatchers = [];
137
+ if (this.options.skip) {
138
+ const skipPatterns = Array.isArray(this.options.skip) ? this.options.skip : [this.options.skip];
139
+ this.skipMatchers = skipPatterns.map(skip => new Minimatch(skip, { dot: true }));
140
+ }
141
+ this.iterator = explore(resolve(cwd || '.'), this.options.follow, this.options.stat, this._shouldSkipDirectory.bind(this));
142
+ this.paused = false;
143
+ this.inactive = false;
144
+ this.aborted = false;
145
+ if (cb) {
146
+ const nonNullCb = cb;
147
+ const matches = [];
148
+ this.on('match', match => matches.push(this.options.absolute ? match.absolute : match.relative));
149
+ this.on('error', err => nonNullCb(err));
150
+ this.on('end', () => nonNullCb(null, matches));
151
+ }
152
+ setTimeout(() => this._next());
153
+ }
154
+ _shouldSkipDirectory(relative) {
155
+ return this.skipMatchers.some(m => m.match(relative));
156
+ }
157
+ _fileMatches(relative, isDirectory) {
158
+ const file = relative + (isDirectory ? '/' : '');
159
+ return (this.matchers.length === 0 || this.matchers.some(m => m.match(file)))
160
+ && !this.ignoreMatchers.some(m => m.match(file))
161
+ && (!this.options.nodir || !isDirectory);
162
+ }
163
+ _next() {
164
+ if (!this.paused && !this.aborted) {
165
+ this.iterator.next()
166
+ .then((obj) => {
167
+ if (!obj.done) {
168
+ const isDirectory = obj.value.stat.isDirectory();
169
+ if (this._fileMatches(obj.value.relative, isDirectory)) {
170
+ let relative = obj.value.relative;
171
+ let absolute = obj.value.absolute;
172
+ if (this.options.mark && isDirectory) {
173
+ relative += '/';
174
+ absolute += '/';
175
+ }
176
+ if (this.options.stat) {
177
+ this.emit('match', { relative, absolute, stat: obj.value.stat });
178
+ }
179
+ else {
180
+ this.emit('match', { relative, absolute });
181
+ }
182
+ }
183
+ this._next();
184
+ }
185
+ else {
186
+ this.emit('end');
187
+ }
188
+ })
189
+ .catch((err) => {
190
+ this.abort();
191
+ this.emit('error', err);
192
+ if (!err.code && !this.options.silent) {
193
+ console.error(err);
194
+ }
195
+ });
196
+ }
197
+ else {
198
+ this.inactive = true;
199
+ }
200
+ }
201
+ abort() {
202
+ this.aborted = true;
203
+ }
204
+ pause() {
205
+ this.paused = true;
206
+ }
207
+ resume() {
208
+ this.paused = false;
209
+ if (this.inactive) {
210
+ this.inactive = false;
211
+ this._next();
212
+ }
213
+ }
214
+ }
215
+ export const readdirGlob = (pattern, options, cb) => new ReaddirGlob(pattern, options, cb);
216
+ readdirGlob.ReaddirGlob = ReaddirGlob;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archiver-node",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
4
4
  "description": "a streaming interface for archive generation",
5
5
  "homepage": "https://github.com/catamphetamine/node-archiver",
6
6
  "author": {
@@ -37,7 +37,8 @@
37
37
  "scripts": {
38
38
  "build:clean": "rimraf cjs",
39
39
  "build:cjs": "esbuild lib/**/*.js --outdir=cjs --platform=node --format=cjs",
40
- "build": "npm-run-all build:clean build:cjs",
40
+ "build:cjs:package.json": "node scripts/create-commonjs-package-json.js",
41
+ "build": "npm-run-all build:clean build:cjs build:cjs:package.json",
41
42
  "test": "mocha --reporter dot",
42
43
  "bench": "node benchmark/simple/pack-zip.js"
43
44
  },
@@ -45,6 +46,7 @@
45
46
  "async": "^3.2.6",
46
47
  "buffer-crc32": "^1.0.0",
47
48
  "is-stream": "^4.0.1",
49
+ "minimatch": "^10.2.2",
48
50
  "normalize-path": "^3.0.0",
49
51
  "readable-stream": "^4.7.0",
50
52
  "readdir-glob": "^2.0.2",