nodejs / nodejs/corepack

Corepack strips empty lines from package.json when inserting `packageManager`

Open
#504 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.8k
Forks
279
Avg merge
1h 47m
Merged PRs (30d)
2

Description

If I have a package.json with some empty lines (in this case intentionally), that doesn't specify packageManager, then running a shim (for example yarn install) adds the packageManager attribute but removes the empty lines. I would expect that any existing whitespace in the file would be preserved.

Versions
$ corepack --version
0.28.2
$ node --version
v18.20.2
Reproduction

For example, starting with:

{
  "name": "example",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",

    "postinstall": "patch-package"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.8",

    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-community/datetimepicker": "8.0.1",
    "@react-native-community/netinfo": "11.3.1",
    "@react-navigation/native": "~6.0.13",
    "@react-navigation/stack": "~6.3.2",
    "Base64": "^1.1.0",
    "deprecated-react-native-prop-types": "~4.1.0",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "moment-range": "^4.0.2",
    "rc-swipeout": "~2.0.11",
    "react-native-animatable": "^1.3.3",
    "react-native-blob-util": "~0.18.3",
    "react-native-camera": "~4.2.1",
    "react-native-draggable-flatlist": "~4.0.1",
    "react-native-elements": "~2.1.0",
    "react-native-fs": "~2.18.0",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-image-picker": "2.3.0",
    "react-native-keyboard-aware-scroll-view": "~0.9.5",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-markdown-renderer": "^3.2.8",
    "react-native-modal-selector": "~2.0.9",
    "react-native-orientation-locker": "1.4.0",
    "react-native-pdf": "~6.6.2",
    "react-native-reanimated": "~3.10.1",
    "react-native-safe-area-context": "4.10.1",
    "react-native-screens": "3.31.1",
    "react-native-signature-capture": "^0.4.10",
    "react-native-svg": "15.2.0",
    "react-native-svg-charts": "^5.3.0",
    "react-native-table-component": "~1.2.2",
    "react-native-vector-icons": "~9.2.0",
    "react-native-video": "~5.2.1",
    "react-native-webview": "13.8.6",
    "react-redux": "~7.2.9",
    "redux": "^4.0.4",
    "redux-persist": "^6.0.0",
    "redux-persist-filesystem-storage": "~4.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4",

    "@babel/plugin-transform-class-properties": "~7.22.5",
    "@babel/plugin-transform-private-methods": "~7.22.5",
    "@testing-library/jest-native": "^5.4.2",
    "@testing-library/react-native": "^7.2.0",
    "babel-eslint": "^10.1.0",
    "eslint-plugin-react": "^7.20.6",
    "eslint-plugin-react-native": "~4.0.0",
    "patch-package": "~7.0.0"
  },
  "engines": {
    "node": ">=18"
  }
}

running:

yarn install

modifies this to:

{
  "name": "example",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.8",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-community/datetimepicker": "8.0.1",
    "@react-native-community/netinfo": "11.3.1",
    "@react-navigation/native": "~6.0.13",
    "@react-navigation/stack": "~6.3.2",
    "Base64": "^1.1.0",
    "deprecated-react-native-prop-types": "~4.1.0",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "moment-range": "^4.0.2",
    "rc-swipeout": "~2.0.11",
    "react-native-animatable": "^1.3.3",
    "react-native-blob-util": "~0.18.3",
    "react-native-camera": "~4.2.1",
    "react-native-draggable-flatlist": "~4.0.1",
    "react-native-elements": "~2.1.0",
    "react-native-fs": "~2.18.0",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-image-picker": "2.3.0",
    "react-native-keyboard-aware-scroll-view": "~0.9.5",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-markdown-renderer": "^3.2.8",
    "react-native-modal-selector": "~2.0.9",
    "react-native-orientation-locker": "1.4.0",
    "react-native-pdf": "~6.6.2",
    "react-native-reanimated": "~3.10.1",
    "react-native-safe-area-context": "4.10.1",
    "react-native-screens": "3.31.1",
    "react-native-signature-capture": "^0.4.10",
    "react-native-svg": "15.2.0",
    "react-native-svg-charts": "^5.3.0",
    "react-native-table-component": "~1.2.2",
    "react-native-vector-icons": "~9.2.0",
    "react-native-video": "~5.2.1",
    "react-native-webview": "13.8.6",
    "react-redux": "~7.2.9",
    "redux": "^4.0.4",
    "redux-persist": "^6.0.0",
    "redux-persist-filesystem-storage": "~4.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4",
    "@babel/plugin-transform-class-properties": "~7.22.5",
    "@babel/plugin-transform-private-methods": "~7.22.5",
    "@testing-library/jest-native": "^5.4.2",
    "@testing-library/react-native": "^7.2.0",
    "babel-eslint": "^10.1.0",
    "eslint-plugin-react": "^7.20.6",
    "eslint-plugin-react-native": "~4.0.0",
    "patch-package": "~7.0.0"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with Corepack 0.28.2 and Node v18.20.2, using the package.json shown and running yarn install. Trace the code that inserts packageManager, then verify that the existing empty lines remain unchanged while the attribute is added.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.