From f547743124d987661f299c527554df6137d44bad Mon Sep 17 00:00:00 2001 From: ADITYA CHAUHAN <125276621+hooiv@users.noreply.github.com> Date: Sun, 16 Aug 2026 00:06:35 +0530 Subject: [PATCH] feat(directory): add option to configure followSymlinks in directory() --- lib/core.js | 9 +++++++++ test/archiver.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/core.js b/lib/core.js index 1bcf33af9..50cb7811b 100644 --- a/lib/core.js +++ b/lib/core.js @@ -589,9 +589,18 @@ export default class Archiver extends Transform { } else if (typeof data !== "object") { data = {}; } + + let followSymlinks = false; + if (typeof data.followSymlinks === "boolean") { + followSymlinks = data.followSymlinks; + } else if (typeof this.options.followSymlinks === "boolean") { + followSymlinks = this.options.followSymlinks; + } + var globOptions = { stat: true, dot: true, + follow: followSymlinks, }; function onGlobEnd() { this._pending--; diff --git a/test/archiver.js b/test/archiver.js index 20de9ad19..e53345345 100644 --- a/test/archiver.js +++ b/test/archiver.js @@ -268,6 +268,34 @@ describe("archiver", function () { assert.property(entries, "Win/DS/level0.txt"); }); }); + describe("#directory (followSymlinks)", function () { + var actual; + var archive; + var entries = {}; + before(function (done) { + archive = new JsonArchive(); + var testStream = new WriteStream("tmp/directory-followed.json"); + testStream.on("close", function () { + actual = readJSON("tmp/directory-followed.json"); + actual.forEach(function (entry) { + entries[entry.name] = entry; + }); + done(); + }); + archive.pipe(testStream); + archive + .directory("test/fixtures/directory", "followed", { + followSymlinks: true, + }) + .finalize(); + }); + it("should support followSymlinks: true option", function () { + assert.property(entries, "followed/subdir/level0link.txt"); + if (!win32) { + assert.equal(entries["followed/subdir/level0link.txt"].type, "file"); + } + }); + }); describe("#file", function () { var actual; var archive;