Skip to content

refactor: replace archiver with modern-tar - #1427

Open
ayuhito wants to merge 1 commit into
testcontainers:mainfrom
ayuhito:refactor/modern-tar-archiver
Open

refactor: replace archiver with modern-tar#1427
ayuhito wants to merge 1 commit into
testcontainers:mainfrom
ayuhito:refactor/modern-tar-archiver

Conversation

@ayuhito

@ayuhito ayuhito commented Aug 8, 2026

Copy link
Copy Markdown

Overview

Related #1161 #1410

This replaces archiver with modern-tar. Nets in a reduced dependency surface and some performance improvements for related workloads (although most likely not noticeable).

There are likely some very low level differences between these libraries when it comes to error or symlink handling, but I would like to believe modern-tar follows more correct behaviour. archiver does a lot of non-standard things based on years of changes.

Notes

Additionally, modern-tar is an ESM-only package, however, with dynamic imports we should be covered against cases like #1365.

I'll also make follow-up PRs to replace some instances of tar-fs in the codebase. Unfortunately, it's not possible to create stacked PRs from forks so that will happen after this PR is merged 📦

@netlify

netlify Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 48e7f96
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6a7743ead9307e0009b592ab
😎 Deploy Preview https://deploy-preview-1427--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ayuhito ayuhito changed the title Refactor: Replace Archiver with Modern Tar refactor: replace archiver with modern-tar Aug 8, 2026
@ayuhito
ayuhito marked this pull request as ready for review August 8, 2026 16:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48e7f96f26

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/testcontainers/src/utils/tar.ts
@cristianrgreco

Copy link
Copy Markdown
Collaborator

modern-tar is an ESM-only package

Ah, I didn't know modern-tar was ESM only 🫣 In that case this would require a major release, but I'd need to see if there are workarounds for Jest users. Although with dynamic imports we won't encounter issues at load time like in #1365, any usage of modern-tar would still fail

@cristianrgreco

cristianrgreco commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

I notice modern-tar has no deps, and uses tsdown for its build. Would it be possible / is it something you would want to do, to enable dual-publishing? I think it would be a config addition via tsdown, and shouldn't require any changes for existing users, but would add CJS compatibility. It would however increase your bundle size

@ayuhito

ayuhito commented Aug 8, 2026

Copy link
Copy Markdown
Author

Oops, yeah I didn't think that through. This PR can't be merged as is.

enable dual-publishing?

In principle, I don't want to support CJS as a way to push the ecosystem forward and also the added package bloat. Sorry for being a bit uncooperative on this matter. Jest is one of the unfortunate incumbents 😔

uses tsdown for its build

But, this actually is a really interesting idea if we were to apply it to testcontainers-node? If this package is open to using a bundler like tsdown, then it would be possible to inline bundle any future ESM dependencies as a workaround without needing a major release?

@cristianrgreco

Copy link
Copy Markdown
Collaborator

In principle, I don't want to support CJS as a way to push the ecosystem forward and also the added package bloat. Sorry for being a bit uncooperative on this matter. Jest is one of the unfortunate incumbents 😔

No problem at all, I agree it would take away a bit the "modern" part of modern-tar 🙂

But, this actually is a really interesting idea if we were to apply it to testcontainers-node?

It is interesting. It'd solve such future problems as well. For example we're currently stuck on an old version of get-port for the same reason.

There are downsides, e.g. our bundle size will increase, clients won't dedupe dependencies, etc. But for small libs, especially with no deps like modern-tar and get-port, it may be a good compromise.

I will need time to look into it. A first approach may be to bundle the latest get-port and get that released. If it's all good then we could add modern-tar to the list in this PR and that'd be it

@ayuhito

ayuhito commented Aug 9, 2026

Copy link
Copy Markdown
Author

Feel free to close this PR if needed and handle things which you think is best! Happy to help in the future whenever 👍

@cristianrgreco

cristianrgreco commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks @ayuhito.

Btw what do you think if I were to create a fork of modern-tar which repackages modern-tar as CJS, and published it to a lib called modern-tar-cjs? I could setup Dependabot so that we automatically rebuild and republish any changes made to modern-tar. Could try my best to follow your versions, etc.

I am slightly hesitant to replace Testcontainer's build system, so wondering if managing forks is a better alternative

@ayuhito

ayuhito commented Aug 9, 2026

Copy link
Copy Markdown
Author

create a fork

It would work but I fear it isn't an ideal precedent to set, nor would be a good burden to maintain.

I am slightly hesitant to replace Testcontainer's build system, so wondering if managing forks is a better alternative

But I can understand this and the motivation for a fork.

I was curious what the tsdown migration could look like (relied on AI to churn on the edge cases) for a "best case" scenario. That includes enabling package validation integrations like publint and attw as well as inlining modern-tar. The Jest smoke test now also adds file copying as part of the coverage. You can check it out here: ayuhito@2678ee6.

The diff is mostly package-lock.json (excluding it is +284 / -695). Builds are still outputted to build/ but the shape is definitely not the same as tsc. Some postbuild scripts were moved to tsdown.copy too.

Not sure if this is the direction you want to go, but it does seem quite feasible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants