Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 2, 2023
1 parent 9ac0a0f commit c7aa6cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Up @@ -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`
Expand Down

0 comments on commit c7aa6cd

Please sign in to comment.