Skip to content

Commit

Permalink
Remove unnecessary through2 package (#1430)
Browse files Browse the repository at this point in the history
Summary:
through2 is a legacy dependency and is no longer required. Metro targets Node 18 where Transform streams are stable and do not need a userland package.

Changelog: [Internal] Remove unnecessary through2 package

Pull Request resolved: #1430

Test Plan:
All tests pass on Node 18:

<img width="752" alt="Screenshot 2025-01-21 at 00 38 31" src="https://github.com/user-attachments/assets/4c3179a7-7203-41c9-9ed9-e14d83238048" />

Reviewed By: vzaidman

Differential Revision: D68437314

Pulled By: robhogan

fbshipit-source-id: d70503ad8c5638392b7af883b20a8edd3f7db38b
  • Loading branch information
talentlessguy authored and facebook-github-bot committed Jan 21, 2025
1 parent 14c4d43 commit d8bf840
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 85 deletions.
1 change: 0 additions & 1 deletion packages/metro-symbolicate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"metro-source-map": "0.81.0",
"nullthrows": "^1.1.1",
"source-map": "^0.5.6",
"through2": "^2.0.1",
"vlq": "^1.0.0"
},
"engines": {
Expand Down
58 changes: 28 additions & 30 deletions packages/metro-symbolicate/src/symbolicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const Symbolication = require('./Symbolication.js');
const fs = require('fs');
// flowlint-next-line untyped-import:off
const SourceMapConsumer = require('source-map').SourceMapConsumer;
// flowlint-next-line untyped-import:off
const through2 = require('through2');
const {Transform} = require('stream');

function printHelp() {
const usages = [
Expand Down Expand Up @@ -167,35 +166,34 @@ async function main(
),
);
} else if (argv[0] === '--attribution') {
let buffer = '';
let lineBuffer = '';

const streamToLines: Transform = new Transform({
transform(data, _enc, callback) {
// Take arbitrary strings, output single lines
lineBuffer += data.toString();
const lines = lineBuffer.split('\n');
for (let i = 0, e = lines.length - 1; i < e; i++) {
streamToLines.push(lines[i]);
}
lineBuffer = lines[lines.length - 1];
callback();
},
});

const symbolicateLines: Transform = new Transform({
transform(data, enc, callback) {
// This is JSONL, so each line is a separate JSON object
const obj = JSON.parse(data.toString());
context.symbolicateAttribution(obj);
symbolicateLines.push(JSON.stringify(obj) + '\n');
callback();
},
objectMode: true,
});

await waitForStream(
stdin
.pipe(
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s)
* required by Flow's LTI update could not be added via codemod */
through2(function (data, enc, callback) {
// Take arbitrary strings, output single lines
buffer += data;
const lines = buffer.split('\n');
for (let i = 0, e = lines.length - 1; i < e; i++) {
this.push(lines[i]);
}
buffer = lines[lines.length - 1];
callback();
}),
)
.pipe(
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s)
* required by Flow's LTI update could not be added via codemod */
through2.obj(function (data, enc, callback) {
// This is JSONL, so each line is a separate JSON object
const obj = JSON.parse(data);
context.symbolicateAttribution(obj);
this.push(JSON.stringify(obj) + '\n');
callback();
}),
)
.pipe(stdout),
stdin.pipe(streamToLines).pipe(symbolicateLines).pipe(stdout),
);
} else if (argv[0].endsWith('.cpuprofile')) {
// NOTE: synchronous
Expand Down
55 changes: 1 addition & 54 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2230,11 +2230,6 @@ core-js-pure@^3.25.1:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.26.1.tgz#653f4d7130c427820dcecd3168b594e8bb095a33"
integrity sha512-VVXcDpp/xJ21KdULRq/lXdLzQAtX7+37LzpyfFM973il0tWSsDEoyzG38G14AjTpK9VTfiNM9jnFauq/CpaWGQ==

core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cosmiconfig@^5.0.5:
version "5.2.1"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
Expand Down Expand Up @@ -3501,11 +3496,6 @@ is-weakref@^1.0.2:
dependencies:
call-bind "^1.0.2"

isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=

isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
Expand Down Expand Up @@ -4851,11 +4841,6 @@ pretty-format@^29.7.0:
ansi-styles "^5.0.0"
react-is "^18.0.0"

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==

progress@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
Expand Down Expand Up @@ -4938,19 +4923,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/react/-/react-19.0.0.tgz#6e1969251b9f108870aa4bff37a0ce9ddfaaabdd"
integrity sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==

readable-stream@~2.3.6:
version "2.3.7"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
dependencies:
core-util-is "~1.0.0"
inherits "~2.0.3"
isarray "~1.0.0"
process-nextick-args "~2.0.0"
safe-buffer "~5.1.1"
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

recast@^0.21.0:
version "0.21.5"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.21.5.tgz#e8cd22bb51bcd6130e54f87955d33a2b2e57b495"
Expand Down Expand Up @@ -5106,7 +5078,7 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

safe-buffer@~5.1.0, safe-buffer@~5.1.1:
safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
Expand Down Expand Up @@ -5347,13 +5319,6 @@ string.prototype.trimstart@^1.0.5:
define-properties "^1.1.4"
es-abstract "^1.19.5"

string_decoder@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
dependencies:
safe-buffer "~5.1.0"

strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
Expand Down Expand Up @@ -5476,14 +5441,6 @@ throat@^5.0.0:
resolved "https://registry.yarnpkg.com/throat/-/throat-5.0.0.tgz#c5199235803aad18754a667d659b5e72ce16764b"
integrity sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==

through2@^2.0.1:
version "2.0.5"
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd"
integrity sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==
dependencies:
readable-stream "~2.3.6"
xtend "~4.0.1"

"through@>=2.2.7 <3":
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
Expand Down Expand Up @@ -5634,11 +5591,6 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
Expand Down Expand Up @@ -5736,11 +5688,6 @@ xml@^1.0.1:
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==

xtend@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
Expand Down

0 comments on commit d8bf840

Please sign in to comment.