Refactored to ESM ("EcmaScript Modules")#356
Conversation
ZJONSSON
left a comment
There was a problem hiding this comment.
This is awesome — really appreciate the work here.
Could you split this into a few smaller PRs? Right now it blends several different changes together, which makes it difficult to review each one properly.
Ideally, each PR should cover one logical change. For example, ESM changes only could be one PR, Bluebird removal another, and any unrelated cleanup or behavior changes should be separate as well.
|
Hi, Indeed, I agree. If someone submitted a PR in my repo, I'd probably have answered the same. The thing is, I got a bit carried away while doing the refactoring and decided to also update all dependencies due to how massive the ESM change alone would be. Frankly, all of the dependency replacements do make sense from my point of view. The general rule is: the smaller the count of dependencies, the better (in public opinion). And also: the fresher the dependency packages, the better. Both principles were applied when doing the refactoring. Could I split it in several atomic PRs? I could but if all those are gonna eventually be merged anyway then there would be no point really and it would feel pointless doing that. So I think that I'll pass. I'd just prefer to be done with it and not open it again, haha. If you're interested, I already shipped this PR in 'read-excel-file' package. For no reason, really. Just had some fun refactoring on a chill day. |
|
I can see you've added CI tests 👌 I'll see why it didn't pass when I get home later. |
|
Well I really appreciate your efforts, so I will take a look and see if I can split them up.
Could not agree more
The CI tests have been there for years - but I had to permission them for each build. You should be able to |
|
Ok, I’ll see if I could split them as well. I could create a new branch
where I’d move the non-essential stuff.
…On Sun, 21 Jun 2026 at 22:37, Ziggy Jonsson ***@***.***> wrote:
*ZJONSSON* left a comment (ZJONSSON/node-unzipper#356)
<#356 (comment)>
Well I really appreciate your efforts, so I will take a look and see if I
can split them up.
Frankly, all of the dependency replacements do make sense from my point of
view. The general rule is: the smaller the count of dependencies, the
better (in public opinion). And also: the fresher the dependency packages,
the better. Both principles were applied when doing the refactoring.
Could not agree more
I can see you've added CI tests
The CI tests have been there for years - but I had to permission them for
each build. You should be able to npm run test locally and see if
everything works.
—
Reply to this email directly, view it on GitHub
<#356?email_source=notifications&email_token=AADUP3ZSAI6DX5CRZVTSU3T5BA2PPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZWGMYDONRRGI2KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4763076124>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADUP3Y3ENALHF3EAZOKYBT5BA2PPAVCNFSNUABEKJSXA33TNF2G64TZHM3DENRUGA2TSOJ3JFZXG5LFHM2DMMZTGM2TCNJUG2QXMAQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Here's a shortened version that's just about ESM: #360 |
|
@ZJONSSON Hi. I can see you've merged the ESM refactor. This PR has been updated to reflect the other changes. These "other" changes are completely optional and see for yourself if you like some of them or not. |
| @@ -0,0 +1,89 @@ | |||
| // Copy-pasted from `duplexer3` source code on Jun 19th, 2026: | |||
There was a problem hiding this comment.
You can just use Duplex.from
There was a problem hiding this comment.
Replacing duplexer with Duplex.from results in errors in tests:
Error: test end() method called more than once
The reason is that there's code like this:
const extractor = src.pipe(Extract({ path: dest }));
extractor.on('close', function() {
t.ok(fs.existsSync(path.join(dest, 'subdir', 'file.txt')), 'normal entry must be extracted');
t.end();
});The close event can be emitted multiple times when using Duplex.from():
- When the readable stream closes
- When the writable stream closes
- When the duplex stream closes
Workarounds:
- Use
import { finished } from 'stream'instead ofstream.on('close', ...)- That would have to be replaced throughout the code (+ tests) and there's a hypothetical probability of stuff malfunctioning after the change, so I won't go this way.
- Use
.once()instead of.on()- This one seems even hackier, so I'll pass too.
In summary, there seems to be no simple find-and-replace solution so DuplexStream.js is not removed.
There was a problem hiding this comment.
I wonder if there is a way to solve that


Changes:
DefinitelyTyped.import("@aws-sdk/client-s3")with optional predefined global variablesglobal.GetObjectCommandandglobal.HeadObjectCommand.unzipperpackage because of that dynamicimport()statement when@aws-sdk/client-s3package is not already installed by someone else in the application directory.duplexer2with a copy ofduplexer3.duplexer3just says: "Modern version of duplexer2".duplexer3had to be copy-pasted (with the tests) because it didn't provide CommonJS exports. Called itDuplexStream.js.bluebirdwith a combination of nativePromises and a copy ofp-map.unzipperitself.p-maphad to be copy-pasted (with the tests) because it didn't provide CommonJS exports. Called itmapPromises.js.fs-extra.ensureDir.js.While this pull request is in review, the changes have been published as a separate package: https://www.npmjs.com/package/unzipper-esm
P.S.
There's a strange issue with the tests: the results seem visually same, yet the testing framework complains about some kind of a mismatch.
The same issue can be observed when cloning the original unmodified repo and running the tests. Therefore, I assume that tests are actually passing and it's just an operating system compatibility issue (I'm on Windows). Perhaps it's related to line endings being different between Windows and Linux.