diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a82b18..346585c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.js b/index.js index c1be212..efa0960 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/package.json b/package.json index f7cd94f..0bc0649 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/readme.md b/readme.md index bd62aa5..e62ff0c 100644 --- a/readme.md +++ b/readme.md @@ -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`