From 3fb9e44699c8b7936a711dd82d873be09b770453 Mon Sep 17 00:00:00 2001 From: Derek Worthen Date: Mon, 27 Jul 2020 13:50:01 -0700 Subject: [PATCH] Follow linked folders (#36) * Update archiver dependency * Support compressing symlinks on Windows - Add test cases for file and directory symlinks - Add support for compressing file and symlinks on Windows - Test on Windows 10 node 12.16.1 - Test on Ubuntu 18.04 node 12.16.1 both with and without native zip available in path. * Fix EMFILE error, too many open readStream issue. --- .gitignore | 2 + lib/bestzip.js | 21 +- package-lock.json | 273 +++++++++++++++--------- package.json | 2 +- test/__snapshots__/bestzip.spec.js.snap | 84 ++++++++ test/bestzip.spec.js | 23 +- 6 files changed, 299 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index c8903c7..caff73a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ node_modules/ .idea tmp/ +test/fixtures/subdir-symlink +test/fixtures/file-symlink.txt test/validArchive.zip test/validARchiveExtract .DS_Store \ No newline at end of file diff --git a/lib/bestzip.js b/lib/bestzip.js index 4c7e305..26f58c1 100644 --- a/lib/bestzip.js +++ b/lib/bestzip.js @@ -82,6 +82,18 @@ const nodeZip = options => } } + 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) { const fullPath = path.resolve(cwd, source); const destPath = source; @@ -90,7 +102,14 @@ const nodeZip = options => return next(err); } if (stats.isDirectory()) { - archive.directory(fullPath, destPath); + // Walk directory. Works on directories and directory symlinks. + const files = walkDir(fullPath); + files.forEach(f => { + const subPath = f.substring(fullPath.length); + archive.file(f, { + name: destPath + subPath + }); + }); } else if (stats.isFile()) { archive.file(fullPath, { stats: stats, name: destPath }); } diff --git a/package-lock.json b/package-lock.json index 3d0a854..4fba81a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -644,36 +644,84 @@ } }, "archiver": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/archiver/-/archiver-3.0.0.tgz", - "integrity": "sha512-5QeR6Xc5hSA9X1rbQfcuQ6VZuUXOaEdB65Dhmk9duuRJHYif/ZyJfuyJqsQrj34PFjU5emv5/MmfgA8un06onw==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/archiver/-/archiver-4.0.2.tgz", + "integrity": "sha512-B9IZjlGwaxF33UN4oPbfBkyA4V1SxNLeIhR1qY8sRXSsbdUkEHrrOvwlYFPx+8uQeCe9M+FG6KgO+imDmQ79CQ==", "requires": { - "archiver-utils": "^2.0.0", - "async": "^2.0.0", + "archiver-utils": "^2.1.0", + "async": "^3.2.0", "buffer-crc32": "^0.2.1", - "glob": "^7.0.0", - "readable-stream": "^2.0.0", - "tar-stream": "^1.5.0", - "zip-stream": "^2.0.1" + "glob": "^7.1.6", + "readable-stream": "^3.6.0", + "tar-stream": "^2.1.2", + "zip-stream": "^3.0.1" + }, + "dependencies": { + "async": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "archiver-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-2.0.0.tgz", - "integrity": "sha512-JRBgcVvDX4Mwu2RBF8bBaHcQCSxab7afsxAPYDQ5W+19quIPP5CfKE7Ql+UHs9wYvwsaNR8oDuhtf5iqrKmzww==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-2.1.0.tgz", + "integrity": "sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==", "requires": { - "glob": "^7.0.0", - "graceful-fs": "^4.1.0", + "glob": "^7.1.4", + "graceful-fs": "^4.2.0", "lazystream": "^1.0.0", - "lodash.assign": "^4.2.0", "lodash.defaults": "^4.2.0", "lodash.difference": "^4.5.0", "lodash.flatten": "^4.4.0", "lodash.isplainobject": "^4.0.6", - "lodash.toarray": "^4.4.0", "lodash.union": "^4.6.0", "normalize-path": "^3.0.0", "readable-stream": "^2.0.0" + }, + "dependencies": { + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" + } } }, "argparse": { @@ -941,9 +989,9 @@ } }, "base64-js": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", - "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" }, "bcrypt-pbkdf": { "version": "1.0.2", @@ -965,12 +1013,30 @@ } }, "bl": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", - "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz", + "integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==", "requires": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "brace-expansion": { @@ -1044,38 +1110,19 @@ } }, "buffer": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.0.tgz", - "integrity": "sha512-nUJyfChH7PMJy75eRDCCKtszSEFokUNXC1hNVSe+o+VdcgvDPLs20k3v8UXI8ruRYAJiYtyRea8mYyqPxoHWDw==", + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", "requires": { "base64-js": "^1.0.2", "ieee754": "^1.1.4" } }, - "buffer-alloc": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", - "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", - "requires": { - "buffer-alloc-unsafe": "^1.1.0", - "buffer-fill": "^1.0.0" - } - }, - "buffer-alloc-unsafe": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", - "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==" - }, "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" }, - "buffer-fill": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", - "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" - }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", @@ -1346,22 +1393,28 @@ "dev": true }, "compress-commons": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-1.2.2.tgz", - "integrity": "sha1-UkqfEJA/OoEzibAiXSfEi7dRiQ8=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-3.0.0.tgz", + "integrity": "sha512-FyDqr8TKX5/X0qo+aVfaZ+PVmNJHJeckFBlq8jZGSJOgnynhfifoyl24qaqdUdDIBe0EVTHByN6NAkqYvE/2Xg==", "requires": { - "buffer-crc32": "^0.2.1", - "crc32-stream": "^2.0.0", - "normalize-path": "^2.0.0", - "readable-stream": "^2.0.0" + "buffer-crc32": "^0.2.13", + "crc32-stream": "^3.0.1", + "normalize-path": "^3.0.0", + "readable-stream": "^2.3.7" }, "dependencies": { - "normalize-path": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", - "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { - "remove-trailing-separator": "^1.0.1" + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" } } } @@ -1397,12 +1450,24 @@ } }, "crc32-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz", - "integrity": "sha1-483TtN8xaN10494/u8t7KX/pCPQ=", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-3.0.1.tgz", + "integrity": "sha512-mctvpXlbzsvK+6z8kJwSJ5crm7yBwrQMTybJzMw1O4lLGJqjlDCXY2Zw7KheiA6XBEcBmfLx1D88mjRGVJtY9w==", "requires": { "crc": "^3.4.4", - "readable-stream": "^2.0.0" + "readable-stream": "^3.4.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "cross-spawn": { @@ -2850,7 +2915,8 @@ "graceful-fs": { "version": "4.1.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", + "dev": true }, "growly": { "version": "1.3.0", @@ -2997,9 +3063,9 @@ } }, "ieee754": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz", - "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA==" + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "ignore": { "version": "4.0.6", @@ -4296,11 +4362,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" }, - "lodash.assign": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=" - }, "lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", @@ -4327,11 +4388,6 @@ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, - "lodash.toarray": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.toarray/-/lodash.toarray-4.4.0.tgz", - "integrity": "sha1-JMS/zWsvuji/0FlNsRedjptlZWE=" - }, "lodash.union": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.union/-/lodash.union-4.6.0.tgz", @@ -5135,7 +5191,8 @@ "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", - "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=" + "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", + "dev": true }, "repeat-element": { "version": "1.1.3", @@ -5775,17 +5832,27 @@ } }, "tar-stream": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.1.tgz", - "integrity": "sha512-IFLM5wp3QrJODQFPm6/to3LJZrONdBY/otxcvDIQzu217zKye6yVR3hhi9lAjrC2Z+m/j5oDxMPb1qcd8cIvpA==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.3.tgz", + "integrity": "sha512-Z9yri56Dih8IaK8gncVPx4Wqt86NDmQTSh49XLZgjWpGZL9GK9HKParS2scqHCC4w6X9Gh2jwaU45V47XTKwVA==", "requires": { - "bl": "^1.0.0", - "buffer-alloc": "^1.1.0", - "end-of-stream": "^1.0.0", + "bl": "^4.0.1", + "end-of-stream": "^1.4.1", "fs-constants": "^1.0.0", - "readable-stream": "^2.3.0", - "to-buffer": "^1.1.0", - "xtend": "^4.0.0" + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "test-exclude": { @@ -5833,11 +5900,6 @@ "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", "dev": true }, - "to-buffer": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", - "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" - }, "to-object-path": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", @@ -6244,11 +6306,6 @@ "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", "dev": true }, - "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" - }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", @@ -6371,13 +6428,25 @@ } }, "zip-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-2.0.1.tgz", - "integrity": "sha512-c+eUhhkDpaK87G/py74wvWLtz2kzMPNCCkUApkun50ssE0oQliIQzWpTnwjB+MTKVIf2tGzIgHyqW/Y+W77ecQ==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-3.0.1.tgz", + "integrity": "sha512-r+JdDipt93ttDjsOVPU5zaq5bAyY+3H19bDrThkvuVxC0xMQzU1PJcS6D+KrP3u96gH9XLomcHPb+2skoDjulQ==", "requires": { - "archiver-utils": "^2.0.0", - "compress-commons": "^1.2.0", - "readable-stream": "^2.0.0" + "archiver-utils": "^2.1.0", + "compress-commons": "^3.0.0", + "readable-stream": "^3.6.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } } } diff --git a/package.json b/package.json index a5d364b..ccba377 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lib/" ], "dependencies": { - "archiver": "^3.0.0", + "archiver": "^4.0.2", "async": "^2.6.1", "glob": "^7.1.3", "which": "^1.3.1", diff --git a/test/__snapshots__/bestzip.spec.js.snap b/test/__snapshots__/bestzip.spec.js.snap index 74f6ba4..809f40b 100644 --- a/test/__snapshots__/bestzip.spec.js.snap +++ b/test/__snapshots__/bestzip.spec.js.snap @@ -4,11 +4,14 @@ exports[`file structure cli with --force=node: {"cwd":"test/","source":"fixtures Array [ "/fixtures", "/fixtures/.dotfile", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -16,11 +19,14 @@ Array [ exports[`file structure cli with --force=node: {"cwd":"test/","source":"fixtures/*"} 1`] = ` Array [ "/fixtures", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -30,6 +36,8 @@ Array [ "/fixtures", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -92,11 +100,14 @@ Array [ exports[`file structure cli with --force=node: {"cwd":"test/fixtures/","source":"*"} 1`] = ` Array [ + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -104,11 +115,21 @@ Array [ exports[`file structure cli with --force=node: {"cwd":"test/fixtures/","source":"./"} 1`] = ` Array [ "/.dotfile", + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", + "/test.zip", +] +`; + +exports[`file structure cli with --force=node: {"cwd":"test/fixtures/","source":"file-symlink.txt"} 1`] = ` +Array [ + "/file-symlink.txt", "/test.zip", ] `; @@ -124,11 +145,14 @@ exports[`file structure cli: {"cwd":"test/","source":"fixtures/"} 1`] = ` Array [ "/fixtures", "/fixtures/.dotfile", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -136,11 +160,14 @@ Array [ exports[`file structure cli: {"cwd":"test/","source":"fixtures/*"} 1`] = ` Array [ "/fixtures", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -150,6 +177,8 @@ Array [ "/fixtures", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -212,11 +241,14 @@ Array [ exports[`file structure cli: {"cwd":"test/fixtures/","source":"*"} 1`] = ` Array [ + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -224,11 +256,21 @@ Array [ exports[`file structure cli: {"cwd":"test/fixtures/","source":"./"} 1`] = ` Array [ "/.dotfile", + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", + "/test.zip", +] +`; + +exports[`file structure cli: {"cwd":"test/fixtures/","source":"file-symlink.txt"} 1`] = ` +Array [ + "/file-symlink.txt", "/test.zip", ] `; @@ -244,11 +286,14 @@ exports[`file structure programmatic with nodeZip: {"cwd":"test/","source":"fixt Array [ "/fixtures", "/fixtures/.dotfile", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -256,11 +301,14 @@ Array [ exports[`file structure programmatic with nodeZip: {"cwd":"test/","source":"fixtures/*"} 1`] = ` Array [ "/fixtures", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -270,6 +318,8 @@ Array [ "/fixtures", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -332,11 +382,14 @@ Array [ exports[`file structure programmatic with nodeZip: {"cwd":"test/fixtures/","source":"*"} 1`] = ` Array [ + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -344,11 +397,21 @@ Array [ exports[`file structure programmatic with nodeZip: {"cwd":"test/fixtures/","source":"./"} 1`] = ` Array [ "/.dotfile", + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", + "/test.zip", +] +`; + +exports[`file structure programmatic with nodeZip: {"cwd":"test/fixtures/","source":"file-symlink.txt"} 1`] = ` +Array [ + "/file-symlink.txt", "/test.zip", ] `; @@ -364,11 +427,14 @@ exports[`file structure programmatic: {"cwd":"test/","source":"fixtures/"} 1`] = Array [ "/fixtures", "/fixtures/.dotfile", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -376,11 +442,14 @@ Array [ exports[`file structure programmatic: {"cwd":"test/","source":"fixtures/*"} 1`] = ` Array [ "/fixtures", + "/fixtures/file-symlink.txt", "/fixtures/file.txt", "/fixtures/multiline.txt", "/fixtures/obama.jpg", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -390,6 +459,8 @@ Array [ "/fixtures", "/fixtures/subdir", "/fixtures/subdir/subfile.txt", + "/fixtures/subdir-symlink", + "/fixtures/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -452,11 +523,14 @@ Array [ exports[`file structure programmatic: {"cwd":"test/fixtures/","source":"*"} 1`] = ` Array [ + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", "/test.zip", ] `; @@ -464,11 +538,21 @@ Array [ exports[`file structure programmatic: {"cwd":"test/fixtures/","source":"./"} 1`] = ` Array [ "/.dotfile", + "/file-symlink.txt", "/file.txt", "/multiline.txt", "/obama.jpg", "/subdir", "/subdir/subfile.txt", + "/subdir-symlink", + "/subdir-symlink/subfile.txt", + "/test.zip", +] +`; + +exports[`file structure programmatic: {"cwd":"test/fixtures/","source":"file-symlink.txt"} 1`] = ` +Array [ + "/file-symlink.txt", "/test.zip", ] `; diff --git a/test/bestzip.spec.js b/test/bestzip.spec.js index ea02768..75dbd57 100644 --- a/test/bestzip.spec.js +++ b/test/bestzip.spec.js @@ -19,7 +19,6 @@ const testCases = [ { cwd: "test/fixtures/", source: "./" }, // include .dotfiles { cwd: "test/", source: "fixtures/*" }, { cwd: "test/", source: "fixtures/" }, - { cwd: "test/fixtures", source: "file.txt" }, { cwd: "test/fixtures", source: "obama.jpg" }, { cwd: "test/fixtures", source: ["file.txt", "obama.jpg"] }, { cwd: "test/fixtures", source: ["file.txt", ".dotfile"] }, @@ -27,7 +26,9 @@ const testCases = [ { cwd: "test/fixtures", source: "subdir/subfile.txt" }, { cwd: "test/", source: "fixtures/subdir/subfile.txt" }, { cwd: "test/", source: "fixtures/*/*.txt" }, - { cwd: "test/fixtures/subdir", source: "../file.txt" } + { cwd: "test/fixtures/subdir", source: "../file.txt" }, + { cwd: "test/fixtures/", source: "file-symlink.txt" }, + { cwd: "test/fixtures", source: "file.txt" } ]; const cleanup = () => @@ -52,10 +53,28 @@ const getStructure = tmpdir => { ); }; +const createSymlink = () => { + if (!fs.existsSync(path.resolve("test/fixtures/subdir-symlink"))) { + fs.symlinkSync( + path.resolve("test/fixtures/subdir/"), + path.resolve("test/fixtures/subdir-symlink"), + "dir" + ); + } + if (!fs.existsSync(path.resolve("test/fixtures/file-symlink.txt"))) { + fs.symlinkSync( + path.resolve("test/fixtures/file.txt"), + path.resolve("test/fixtures/file-symlink.txt"), + "file" + ); + } +}; + describe("file structure", () => { const hasNativeZip = bestzip.hasNativeZip(); const testIfHasNativeZip = hasNativeZip ? test : test.skip; + beforeAll(createSymlink); beforeEach(cleanup); // these tests have known good snapshots