-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): vendor readable-stream from esm.sh (#2584)
This commit replaces the Node.js streams implementation with an ESM version of the readable-stream package. The goal is to reduce maintenance burden while allowing Deno to stay up to date with changes in the Node.js implementation.
- Loading branch information
Showing
26 changed files
with
648 additions
and
3,903 deletions.
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.