From 30b088d245f449874806f26d2b79b756242cbc94 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Fri, 23 Feb 2024 02:44:10 -0800 Subject: [PATCH] Adjust output package.json formatting in scripts (#43133) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43133 I noticed inconsistent handling of terminating newlines in D54006327@V1, and had also been noticing `yarn build` reformatting unrelated sections of `package.json` files. For now, this logic isn't moved to a shared util, since there will likely be a higher level abstraction for the release scripts in the next batch of improvements. Changelog: [Internal] Reviewed By: lunaleaps, cipolleschi Differential Revision: D54007565 fbshipit-source-id: 74d58362a85be4fae2f9e058b6c6622a026ff0a0 --- scripts/build/build.js | 5 +---- .../__snapshots__/set-rn-version-test.js.snap | 6 ++++-- scripts/releases/set-rn-version.js | 3 +-- .../__tests__/__snapshots__/set-version-test.js.snap | 12 ++++++++---- scripts/releases/set-version/index.js | 1 - 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/build/build.js b/scripts/build/build.js index 3fe18c98e4dff1..31f2dd04f0522a 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -184,10 +184,7 @@ async function rewritePackageExports(packageName /*: string */) { pkg.exports = rewriteExportsField(pkg.exports); - await fs.writeFile( - packageJsonPath, - prettier.format(JSON.stringify(pkg), {parser: 'json'}), - ); + await fs.writeFile(packageJsonPath, JSON.stringify(pkg, null, 2) + '\n'); } /*:: diff --git a/scripts/releases/__tests__/__snapshots__/set-rn-version-test.js.snap b/scripts/releases/__tests__/__snapshots__/set-rn-version-test.js.snap index a21f33faa62cfd..bef170436e374f 100644 --- a/scripts/releases/__tests__/__snapshots__/set-rn-version-test.js.snap +++ b/scripts/releases/__tests__/__snapshots__/set-rn-version-test.js.snap @@ -128,7 +128,8 @@ exports[`setReactNativeVersion should set nightly version: packages/react-native \\"dependencies\\": { \\"@react-native/package-a\\": \\"0.81.0-nightly-29282302-abcd1234\\" } -}" +} +" `; exports[`setReactNativeVersion should set release version: packages/react-native/Libraries/Core/ReactNativeVersion.js 1`] = ` @@ -259,5 +260,6 @@ exports[`setReactNativeVersion should set release version: packages/react-native \\"dependencies\\": { \\"@react-native/package-a\\": \\"1000.0.0\\" } -}" +} +" `; diff --git a/scripts/releases/set-rn-version.js b/scripts/releases/set-rn-version.js index 0efca718782cbf..52ea23b183f412 100755 --- a/scripts/releases/set-rn-version.js +++ b/scripts/releases/set-rn-version.js @@ -110,8 +110,7 @@ async function setReactNativePackageVersion( await fs.writeFile( path.join(REPO_ROOT, 'packages/react-native/package.json'), - JSON.stringify(packageJson, null, 2), - 'utf-8', + JSON.stringify(packageJson, null, 2) + '\n', ); } diff --git a/scripts/releases/set-version/__tests__/__snapshots__/set-version-test.js.snap b/scripts/releases/set-version/__tests__/__snapshots__/set-version-test.js.snap index 33c0979d209f4c..d79876340295b9 100644 --- a/scripts/releases/set-version/__tests__/__snapshots__/set-version-test.js.snap +++ b/scripts/releases/set-version/__tests__/__snapshots__/set-version-test.js.snap @@ -176,7 +176,8 @@ exports[`setVersion updates monorepo for nightly: packages/react-native/package. \\"metro-config\\": \\"^0.80.3\\", \\"metro-runtime\\": \\"^0.80.3\\" } -}" +} +" `; exports[`setVersion updates monorepo for nightly: packages/react-native/template/package.json 1`] = ` @@ -374,7 +375,8 @@ exports[`setVersion updates monorepo for release-candidate: packages/react-nativ \\"metro-config\\": \\"^0.80.3\\", \\"metro-runtime\\": \\"^0.80.3\\" } -}" +} +" `; exports[`setVersion updates monorepo for release-candidate: packages/react-native/template/package.json 1`] = ` @@ -572,7 +574,8 @@ exports[`setVersion updates monorepo for stable version: packages/react-native/p \\"metro-config\\": \\"^0.80.3\\", \\"metro-runtime\\": \\"^0.80.3\\" } -}" +} +" `; exports[`setVersion updates monorepo for stable version: packages/react-native/template/package.json 1`] = ` @@ -770,7 +773,8 @@ exports[`setVersion updates monorepo on main after release cut: packages/react-n \\"metro-config\\": \\"^0.80.3\\", \\"metro-runtime\\": \\"^0.80.3\\" } -}" +} +" `; exports[`setVersion updates monorepo on main after release cut: packages/react-native/template/package.json 1`] = ` diff --git a/scripts/releases/set-version/index.js b/scripts/releases/set-version/index.js index 20d241d891052c..5a38a8bb274cf7 100644 --- a/scripts/releases/set-version/index.js +++ b/scripts/releases/set-version/index.js @@ -49,7 +49,6 @@ async function updatePackageJson( return fs.writeFile( path.join(packagePath, 'package.json'), JSON.stringify(packageJson, null, 2) + '\n', - 'utf-8', ); }