Skip to content

Commit c7aa6cd

Browse files
committedNov 2, 2023
Require Node.js 18
1 parent 9ac0a0f commit c7aa6cd

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed
 

‎.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 20
1314
- 18
14-
- 16
1515
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-node@v3
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
- run: npm install

‎index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ export function parsePackage(packageFile, {normalize = true} = {}) {
3939
throw new TypeError('`packageFile` should be either an `object` or a `string`.');
4040
}
4141

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

5044
return _readPackage(clonedPackageFile, normalize);
5145
}

‎package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"type": "module",
14-
"exports": "./index.js",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
1518
"engines": {
16-
"node": ">=16"
19+
"node": ">=18"
1720
},
1821
"scripts": {
1922
"test": "xo && tsd && cd test && ava"
@@ -34,14 +37,14 @@
3437
"normalize"
3538
],
3639
"dependencies": {
37-
"@types/normalize-package-data": "^2.4.1",
40+
"@types/normalize-package-data": "^2.4.3",
3841
"normalize-package-data": "^6.0.0",
39-
"parse-json": "^7.0.0",
40-
"type-fest": "^4.2.0"
42+
"parse-json": "^8.0.0",
43+
"type-fest": "^4.6.0"
4144
},
4245
"devDependencies": {
4346
"ava": "^5.3.1",
44-
"tsd": "^0.28.1",
47+
"tsd": "^0.29.0",
4548
"xo": "^0.56.0"
4649
}
4750
}

‎readme.md

-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ Default: `true`
5757

5858
Parses an object or string into JSON.
5959

60-
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.
61-
6260
#### packageFile
6361

6462
Type: `object | string`

0 commit comments

Comments
 (0)
Please sign in to comment.