-
Notifications
You must be signed in to change notification settings - Fork 633
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(node): vendor readable-stream from esm.sh #2584
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c9dc5d
fix(node): vendor readable-stream from esm.sh
cjihrig e1c9c7d
update failing tests to match node
cjihrig 8761118
get test-stream-aliases-legacy.js passing
cjihrig c69f914
clean up old code
cjihrig e8e9b49
add script to vendor readable-stream
cjihrig 176a3b8
add node tools readme file
cjihrig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Node.js Compatibility Tooling | ||
|
||
This directory contains tooling for implementing Deno's Node.js compatibility | ||
layer. | ||
|
||
## Updating the Streams Implementation | ||
|
||
The Node.js streams implementation is based on the `readable-stream` module on | ||
npm. To update the code, run the following command: | ||
|
||
``` | ||
deno run -A --unstable node/_tools/vendor_readable_stream.ts | ||
``` | ||
|
||
At the top of this script, there is a variable named `sourceUrl`. This is the | ||
implementation that is downloaded, modified, and included in `node/_stream.mjs`. | ||
To change the vendored version of `readable-stream`, update this URL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
// usage: deno run -A --unstable node/_tools/vendor_readable_stream.ts | ||
const sourceUrl = | ||
"https://esm.sh/v92/[email protected]/es2022/readable-stream.js"; | ||
const header = | ||
`// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
// Copyright Joyent and Node contributors. All rights reserved. MIT license. | ||
// deno-fmt-ignore-file | ||
// deno-lint-ignore-file | ||
import { nextTick } from "./_next_tick.ts"; | ||
import { stdio } from "./_process/stdio.mjs"; | ||
|
||
`; | ||
const outputFile = new URL("../_stream.mjs", import.meta.url).pathname; | ||
const endMarker = "/* End esm.sh bundle */"; | ||
|
||
// Download the readable-stream module. | ||
const res = await fetch(sourceUrl); | ||
let src = await res.text(); | ||
|
||
// Remove the AbortController fallback code since AbortController always | ||
// exists in Deno. | ||
src = src.replaceAll(/import { AbortController as.+?;/g, ""); | ||
src = src.replaceAll("||__abort_controller$AbortController", ""); | ||
|
||
// Replace Node.js core module imports with Deno std modules. | ||
src = src.replaceAll(/"\/v\d+\/node_buffer.js"/g, '"./buffer.ts"'); | ||
src = src.replaceAll(/"\/v\d+\/string_decoder.+?"/g, '"./string_decoder.ts"'); | ||
src = src.replaceAll(/"\/v\d+\/events@.+?"/g, '"./events.ts"'); | ||
|
||
// Replace import of the Node.js process object with the APIs that are actually | ||
// used to avoid issues with circular imports. | ||
src = src.replaceAll( | ||
/import __Process\$ from "\/v\d+\/node_process.js";/g, | ||
"const __Process$ = { nextTick, stdio };", | ||
); | ||
|
||
// Get any additional code from the end of the current file. | ||
const current = Deno.readTextFileSync(outputFile); | ||
const trailer = current.split(endMarker)[1] ?? ""; | ||
|
||
// Prepend copyrights, Deno tooling directives, and necessary imports and make | ||
// sure any code at the end of the file is maintained. | ||
src = header + src + endMarker + trailer; | ||
|
||
// Update the local file. | ||
Deno.writeTextFileSync(outputFile, src); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍