Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/read-pkg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.1.0
Choose a base ref
...
head repository: sindresorhus/read-pkg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.0.0
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 2, 2023

  1. Require Node.js 18

    sindresorhus committed Nov 2, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    joyeecheung Joyee Cheung
    Copy the full SHA
    c7aa6cd View commit details
  2. 9.0.0

    sindresorhus committed Nov 2, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    joyeecheung Joyee Cheung
    Copy the full SHA
    896b075 View commit details
Showing with 14 additions and 19 deletions.
  1. +3 −3 .github/workflows/main.yml
  2. +1 −7 index.js
  3. +10 −7 package.json
  4. +0 −2 readme.md
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 20
- 18
- 16
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -39,13 +39,7 @@ export function parsePackage(packageFile, {normalize = true} = {}) {
throw new TypeError('`packageFile` should be either an `object` or a `string`.');
}

// Input should not be modified - if `structuredClone` is available, do a deep clone, shallow otherwise
// TODO: Remove shallow clone when targeting Node.js 18
const clonedPackageFile = isObject
? (globalThis.structuredClone === undefined
? {...packageFile}
: structuredClone(packageFile))
: packageFile;
const clonedPackageFile = isObject ? structuredClone(packageFile) : packageFile;

return _readPackage(clonedPackageFile, normalize);
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "read-pkg",
"version": "8.1.0",
"version": "9.0.0",
"description": "Read a package.json file",
"license": "MIT",
"repository": "sindresorhus/read-pkg",
@@ -11,9 +11,12 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"scripts": {
"test": "xo && tsd && cd test && ava"
@@ -34,14 +37,14 @@
"normalize"
],
"dependencies": {
"@types/normalize-package-data": "^2.4.1",
"@types/normalize-package-data": "^2.4.3",
"normalize-package-data": "^6.0.0",
"parse-json": "^7.0.0",
"type-fest": "^4.2.0"
"parse-json": "^8.0.0",
"type-fest": "^4.6.0"
},
"devDependencies": {
"ava": "^5.3.1",
"tsd": "^0.28.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -57,8 +57,6 @@ Default: `true`

Parses an object or string into JSON.

Note: `packageFile` is cloned using [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) to prevent modification to the input object. This function is available from Node.js 18 on. In environments without `structuredClone` (such as Node.js 16), a shallow spread is used instead, which can cause deep properties of the object to be modified. Consider cloning the object before using `parsePackage` if that's the case.

#### packageFile

Type: `object | string`