Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in AbortController #552

Open
james-pre opened this issue Feb 13, 2025 · 2 comments
Open

Use built-in AbortController #552

james-pre opened this issue Feb 13, 2025 · 2 comments

Comments

@james-pre
Copy link

james-pre commented Feb 13, 2025

AbortController is available as a built-in on all platforms. readable-stream currently uses the abort-controller dependency. Since AbortController already exists, this dependency can be removed, which decreases the size of readable-stream while increasing supply chain security. Furthermore, native implementations are likely faster.

I'm willing to do a PR for this.

@MattiasBuelens
Copy link
Contributor

AbortController was added in Node 14.17.0. However, readable-stream supports Node 12 and higher (see README). So I'm afraid we can't remove this dependency just yet.

Note that if globalThis.AbortController exists, readable-stream will use it and not load abort-controller:

const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
const AbortController = globalThis.AbortController || require('abort-controller').AbortController

So if you don't need to support Node 12 in your app and can assume that globalThis.AbortController will always exist, you can configure your package manager or bundler to remove that dependency while building.

@james-pre
Copy link
Author

If that's the case, a conditional dependency should be used. This would allow abort-controller to not be installed when using a new enough version of Node.

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

No branches or pull requests

2 participants