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

fix: use readable-stream #1782

Closed
wants to merge 6 commits into from
Closed

fix: use readable-stream #1782

wants to merge 6 commits into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Nov 23, 2022

No description provided.

@ronag ronag requested a review from mcollina November 23, 2022 08:16
@ronag
Copy link
Member Author

ronag commented Nov 23, 2022

Could have impact when vendoring into node. Should probably use proper stream in that case... is there an easy fix for that? i.e. alias readable-stream with stream when required by core? @targos

@mcollina
Copy link
Member

We should definitely not bundle readable-stream when preparing the code for core.

@ronag
Copy link
Member Author

ronag commented Nov 23, 2022

@targos

@targos
Copy link
Member

targos commented Nov 23, 2022

What about this:

diff --git a/package.json b/package.json
index a02ae10..222a235 100644
--- a/package.json
+++ b/package.json
@@ -41,7 +41,8 @@
     "docs"
   ],
   "scripts": {
-    "build:node": "npx esbuild@0.14.38 index-fetch.js --bundle --platform=node --outfile=undici-fetch.js",
+    "build:node": "npx esbuild@0.15.15 index-fetch.js --bundle --external:readable-stream --platform=node --outfile=undici-fetch.js",
+    "postbuild:node": "sed -i 's/require(\"readable-stream\")/require(\"stream\")/g' undici-fetch.js",
     "prebuild:wasm": "docker build -t llhttp_wasm_builder -f build/Dockerfile .",
     "build:wasm": "node build/wasm.js --docker",
     "lint": "standard | snazzy",

@ronag
Copy link
Member Author

ronag commented Nov 23, 2022

Thank you! Applied.

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

@mcollina wdyt?

@mcollina
Copy link
Member

CI seems really unhappy with this change.

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

@mcollina yea, assuming I managed to fix that, do you have any further objections?

@mcollina
Copy link
Member

Not, it should have been like this from the beginning but we were stuck with a very old and legacy version of readable-stream.

@targos
Copy link
Member

targos commented Nov 25, 2022

Isn't the fix simply to npm install readable-stream ?

@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2022

Codecov Report

Base: 90.27% // Head: 94.85% // Increases project coverage by +4.58% 🎉

Coverage data is based on head (213cbfe) compared to base (93f150f).
Patch coverage: 42.85% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1782      +/-   ##
==========================================
+ Coverage   90.27%   94.85%   +4.58%     
==========================================
  Files          58       39      -19     
  Lines        5182     2859    -2323     
==========================================
- Hits         4678     2712    -1966     
+ Misses        504      147     -357     
Impacted Files Coverage Δ
lib/core/util.js 81.32% <33.33%> (-16.61%) ⬇️
lib/api/api-pipeline.js 100.00% <100.00%> (ø)
lib/api/api-stream.js 100.00% <100.00%> (ø)
lib/api/readable.js 82.75% <100.00%> (-8.63%) ⬇️
lib/mock/pending-interceptors-formatter.js 100.00% <100.00%> (ø)
index.js 80.00% <0.00%> (-20.00%) ⬇️
lib/handler/RedirectHandler.js 83.75% <0.00%> (-11.25%) ⬇️
lib/mock/mock-utils.js 93.95% <0.00%> (-6.05%) ⬇️
... and 21 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jimmywarting
Copy link
Contributor

I would prefer if you just used node:stream instead of depending on a npm package

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

I would prefer if you just used node:stream instead of depending on a npm package

Why?

@jimmywarting
Copy link
Contributor

jimmywarting commented Nov 25, 2022

I would prefer if you just used node:stream instead of depending on a npm package

Why?

  • Fewer dependencies
    • faster to download
  • node:stream is always up to date with newest features
  • readable-stream have lagged behind in features
  • readable-stream also depends on buffer which itself haven't been updated for 2y
  • so it will use a npm:buffer instead of nodes which is also slower than node:buffer when it comes to things like buf.toString() as it dosen't use native code and so on.
  • every sub dependency you have no control over is a potential security risk

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

@mcollina wdyt?

@mcollina
Copy link
Member

Why did you want to do this change in the first place?

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

Make sure we have the latest stream fixes even when not running latest version of Node. The same reason why readable-stream exists in the first place.

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

  • node:stream is always up to date with newest features

This is a truth with modification. Only if/when you are running latest version of Node. Otherwise, the opposite should be true.

  • readable-stream have lagged behind in features

I think and hope that situation is no longer true.

  • readable-stream also depends on buffer which itself haven't been updated for 2y

Yea, I guess that is a problem.

  • so it will use a npm:buffer instead of nodes which is also slower than node:buffer when it comes to things like buf.toString() as it dosen't use native code and so on.

Also true.

@jimmywarting
Copy link
Contributor

jimmywarting commented Nov 25, 2022

also it uses abort-controller polyfill instead of using built in whenever available. and it too lacks things like AbortSignal.prototype.reason

i don't know but how compatible it is with built in node:http and other core features about accepting 3th party abort signals?

The same reason why readable-stream exists in the first place.

I mostly saw it as "just to bring it outside of nodejs" and was only mostly ment for browserify and webpack... all those legacy package never updated their own code after a while and those started to lack newer features such as async iterable

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

I mostly saw it as "just to bring it outside of nodejs". all those legacy package never updated their own code after a while and those started to lack newer features such as async iterable

For me. I want to have all the latest fixes and features from Node streams even when running LTS. I prefer using both undici and streams from npm instead of core for this reason.

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

Would be nice if it only used the polyfills when required, i.e. running an older Node version than expected.

@mcollina
Copy link
Member

@jimmywarting those sounds good improvements to do to readable-stream. Maybe open a few issues there / or send PRs?

@ronag
Copy link
Member Author

ronag commented Nov 25, 2022

So it seems to me like this could be a good idea but would require some more things from readable-streams:

  • interop broken readable-stream#501
  • Only install/use events package when Node version < expected
  • Only install/use process package when Node version < expected
  • Only install/use buffer package when Node version < expected
  • Only install/use abort-controller package when Node version < expected

Would peer dependencies help with the former 2?

@ronag ronag added the Status: blocked Progress is blocked, and will continue eventually label Nov 25, 2022
@jimmywarting
Copy link
Contributor

jimmywarting commented Nov 25, 2022

Maybe open a few issues there / or send PRs?

I'm not so keen at working on buffer and/or stream. i have a huge cross compatible code mindset, such as (async)Iterators + uint8array instead (and now web streams). also got a huge bundlephobia for large packages 😝

But you can go ahead and do that...
conditional import when required is a 👍

I just recently did a config.js in one of my project that only exported the things i needed to work with such as:

const config = {
  ReadableStream: globalThis.ReadableStream,
  WritableStream: globalThis.WritableStream,
  TransformStream: globalThis.TransformStream,
  Promise: globalThis.Promise,
  DOMException: globalThis.DOMException,
  Blob: globalThis.Blob,
  File: globalThis.File
}

export default config

and if developers wanted to they could override all those things before i even start using anything of it...

import config from 'mod/config.js'
config[xyz] = zxy
import mod

so if they needed to support older version then they could bring their own polyfill and the version they needed/wanted/or already had

package.json Outdated Show resolved Hide resolved
Co-authored-by: Michaël Zasso <targos@protonmail.com>
@ronag ronag closed this Feb 25, 2024
@Uzlopak Uzlopak deleted the readable-stream-pkg branch February 26, 2024 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: blocked Progress is blocked, and will continue eventually
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants