From d1bf828398f81c8bef6537004547a52260af76b4 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Thu, 4 Jul 2024 08:04:56 -0700 Subject: [PATCH] fix(cli): replace `querystring` with `URLSearchParam` (#45125) Summary: [`querystring`](https://www.npmjs.com/package/querystring) package is deprecated. In this Pull Request I've replaced usage of `querystring` with `URLSearchParam` what is recommended by Node.js. It's also causing a warning when installing dependencies inside a React Native app: ``` warning react-native > react-native/community-cli-plugin > querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. ``` ## Changelog: [INTERNAL] [FIXED] - Replace `querystring` package with `URLSearchParam` Pull Request resolved: https://github.com/facebook/react-native/pull/45125 Test Plan: Params should be parsed in the same way and warning shouldn't be presented. js1 jest xplat/js/tools/metro/packages/metro/src/cli/__tests__/parseKeyValueParamArray-test.js Reviewed By: cipolleschi Differential Revision: D58948498 Pulled By: GijsWeterings fbshipit-source-id: 79b1f7b3feae230d2d3641205c513b98b3fda511 --- packages/community-cli-plugin/package.json | 1 - .../src/utils/parseKeyValueParamArray.js | 9 +++++---- yarn.lock | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/community-cli-plugin/package.json b/packages/community-cli-plugin/package.json index ca98ca671cc..255810bbbf5 100644 --- a/packages/community-cli-plugin/package.json +++ b/packages/community-cli-plugin/package.json @@ -32,7 +32,6 @@ "metro-config": "^0.80.3", "metro-core": "^0.80.3", "node-fetch": "^2.2.0", - "querystring": "^0.2.1", "readline": "^1.3.0" }, "devDependencies": { diff --git a/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js b/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js index 021529007ae..2ebdebb4fa0 100644 --- a/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js +++ b/packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js @@ -9,8 +9,6 @@ * @oncall react_native */ -import querystring from 'querystring'; - export default function parseKeyValueParamArray( keyValueArray: $ReadOnlyArray, ): Record { @@ -23,8 +21,11 @@ export default function parseKeyValueParamArray( if (item.indexOf('&') !== -1) { throw new Error('Parameter cannot include "&" but found: ' + item); } - Object.assign(result, querystring.parse(item)); + const params = new URLSearchParams(item); + params.forEach((value, key) => { + // $FlowExpectedError[prop-missing] + result[key] = value; + }); } - return result; } diff --git a/yarn.lock b/yarn.lock index 4fd997e0347..67ee7669f0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8150,11 +8150,6 @@ query-string@^6.12.1: split-on-first "^1.0.0" strict-uri-encode "^2.0.0" -querystring@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd" - integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg== - queue-microtask@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"