{"name":"@npmcli/package-json","version":"6.1.0","description":"Programmatic API to update package.json","keywords":["npm","oss"],"repository":{"type":"git","url":"git+https://github.com/npm/package-json.git"},"license":"ISC","author":{"name":"GitHub Inc."},"main":"lib/index.js","scripts":{"snap":"tap","test":"tap","lint":"npm run eslint","lintfix":"npm run eslint -- --fix","posttest":"npm run lint","postsnap":"npm run lintfix --","postlint":"template-oss-check","template-oss-apply":"template-oss-apply --force","eslint":"eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""},"dependencies":{"@npmcli/git":"^6.0.0","glob":"^10.2.2","hosted-git-info":"^8.0.0","json-parse-even-better-errors":"^4.0.0","normalize-package-data":"^7.0.0","proc-log":"^5.0.0","semver":"^7.5.3"},"devDependencies":{"@npmcli/eslint-config":"^5.0.0","@npmcli/template-oss":"4.23.5","read-package-json":"^7.0.0","read-package-json-fast":"^4.0.0","tap":"^16.0.1"},"engines":{"node":"^18.17.0 || >=20.5.0"},"templateOSS":{"//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten.","version":"4.23.5","publish":"true"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"]},"_id":"@npmcli/package-json@6.1.0","gitHead":"79cb556342b83b4b298a413677758b39c4d9c839","bugs":{"url":"https://github.com/npm/package-json/issues"},"homepage":"https://github.com/npm/package-json#readme","_nodeVersion":"22.11.0","_npmVersion":"10.9.1","dist":{"integrity":"sha512-t6G+6ZInT4X+tqj2i+wlLIeCKnKOTuz9/VFYDtj+TGTur5q7sp/OYrQA19LdBbWfXDOi0Y4jtedV6xtB8zQ9ug==","shasum":"34f0875da178b04df1a7746c02bdc26479819afb","tarball":"http://registry-npm.ywwl.com/@npmcli/package-json/download/@npmcli/package-json-6.1.0.tgz","fileCount":10,"unpackedSize":43232,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@npmcli%2fpackage-json@6.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEZo8hRVpVaqrkHgic0ig/UNWlh1xWyEGTUDE9PUWpdtAiBXv1gVK1S2KqD18lCGuAC41IWGCprnhEeyfQnDxfdNJQ=="}],"size":12151,"noattachment":false,"key":"/@npmcli/package-json/-/@npmcli/package-json-6.1.0.tgz"},"_npmUser":{"name":"npm-cli-ops","email":"npm-cli+bot@github.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/package-json_6.1.0_1732729214851_0.20544677723030502"},"_hasShrinkwrap":false,"readme":"# @npmcli/package-json\n\n[![npm version](https://img.shields.io/npm/v/@npmcli/package-json)](https://www.npmjs.com/package/@npmcli/package-json)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/npm/package-json/ci.yml?branch=main)](https://github.com/npm/package-json)\n\nProgrammatic API to update `package.json` files. Updates and saves files the\nsame way the **npm cli** handles them.\n\n## Install\n\n`npm install @npmcli/package-json`\n\n## Usage:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load(path)\n// $ cat package.json\n// {\n//   \"name\": \"foo\",\n//   \"version\": \"1.0.0\",\n//   \"dependencies\": {\n//     \"a\": \"^1.0.0\",\n//     \"abbrev\": \"^1.1.1\"\n//   }\n// }\n\npkgJson.update({\n  dependencies: {\n    a: '^1.0.0',\n    b: '^1.2.3',\n  },\n  workspaces: [\n    './new-workspace',\n  ],\n})\n\nawait pkgJson.save()\n// $ cat package.json\n// {\n//   \"name\": \"foo\",\n//   \"version\": \"1.0.0\",\n//   \"dependencies\": {\n//     \"a\": \"^1.0.0\",\n//     \"b\": \"^1.2.3\"\n//   },\n//   \"workspaces\": [\n//     \"./new-workspace\"\n//   ]\n// }\n```\n\nThere is also a helper function exported for opening a package.json file\nwith no extra normalization or saving functionality.\n\n```js\nconst { readPackage } = require('@npmcli/package-json/lib/read-package')\nconst rawData = await readPackage('./package.json')\n// rawData will now have the package.json contents with no changes or normalizations\n```\n\n## API:\n\n### `constructor()`\n\nCreates a new empty instance of `PackageJson`.\n\n---\n\n### `async PackageJson.create(path)`\n\nCreates an empty `package.json` at the given path. If one already exists\nit will be overwritten.\n\n---\n\n### `async PackageJson.load(path, opts = {})`\n\nLoads a `package.json` at the given path.\n\n- `opts`: `Object` can contain:\n  - `create`: `Boolean` if true, a new package.json will be created if one does not already exist. Will not clobber ane existing package.json that can not be parsed.\n\n### Example:\n\nLoads contents of a `package.json` file located at `./`:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = new PackageJson()\nawait pkgJson.load('./')\n```\n\nThrows an error in case a `package.json` file is missing or has invalid contents.\n\n---\n\n### **static** `async PackageJson.load(path)`\n\nConvenience static method that returns a new instance and loads the contents of a `package.json` file from that location.\n\n- `path`: `String` that points to the folder from where to read the `package.json` from\n\n### Example:\n\nLoads contents of a `package.json` file located at `./`:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load('./')\n```\n\n---\n\n### `async PackageJson.normalize()`\n\nIntended for normalizing package.json files in a node_modules tree.  Some light normalization is done to ensure that it is ready for use in `@npmcli/arborist`\n\n- `path`: `String` that points to the folder from where to read the `package.json` from\n- `opts`: `Object` can contain:\n  - `strict`: `Boolean` enables optional strict mode when applying the `normalizeData` step\n  - `steps`: `Array` optional normalization steps that will be applied to the `package.json` file, replacing the default steps\n  - `root`: `Path` optional git root to provide when applying the `gitHead` step\n  - `changes`: `Array` if provided, a message about each change that was made to the packument will be added to this array\n\n---\n\n### **static** `async PackageJson.normalize(path, opts = {})`\n\nConvenience static that calls `load` before calling `normalize`\n\n- `path`: `String` that points to the folder from where to read the `package.json` from\n- `opts`: `Object` can contain:\n  - `strict`: `Boolean` enables optional strict mode when applying the `normalizeData` step\n  - `steps`: `Array` optional normalization steps that will be applied to the `package.json` file, replacing the default steps\n  - `root`: `Path` optional git root to provide when applying the `gitHead` step\n  - `changes`: `Array` if provided, a message about each change that was made to the packument will be added to this array\n\n---\n\n### `async PackageJson.prepare()`\n\nLike `normalize` but intended for preparing package.json files for publish.\n\n---\n\n### **static** `async PackageJson.prepare(path, opts = {})`\n\nConvenience static that calls `load` before calling `prepare`\n\n- `path`: `String` that points to the folder from where to read the `package.json` from\n- `opts`: `Object` can contain:\n  - `strict`: `Boolean` enables optional strict mode when applying the `normalizeData` step\n  - `steps`: `Array` optional normalization steps that will be applied to the `package.json` file, replacing the default steps\n  - `root`: `Path` optional git root to provide when applying the `gitHead` step\n  - `changes`: `Array` if provided, a message about each change that was made to the packument will be added to this array\n\n---\n\n### `async PackageJson.fix()`\n\nLike `normalize` but intended for the `npm pkg fix` command.\n\n---\n\n### `PackageJson.update(content)`\n\nUpdates the contents of a `package.json` with the `content` provided.\n\n- `content`: `Object` containing the properties to be updated/replaced in the\n`package.json` file.\n\nSpecial properties like `dependencies`, `devDependencies`,\n`optionalDependencies`, `peerDependencies` will have special logic to handle\nthe update of these options, such as sorting and deduplication.\n\n### Example:\n\nAdds a new script named `new-script` to your `package.json` `scripts` property:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load('./')\npkgJson.update({\n  scripts: {\n    ...pkgJson.content.scripts,\n    'new-script': 'echo \"Bom dia!\"'\n  }\n})\n```\n\n**NOTE:** When working with dependencies, it's important to provide values for\nall known dependency types as the update logic has some interdependence in\nbetween these properties.\n\n### Example:\n\nA safe way to add a `devDependency` AND remove all peer dependencies of an\nexisting `package.json`:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load('./')\npkgJson.update({\n  dependencies: pkgJson.content.dependencies,\n  devDependencies: {\n    ...pkgJson.content.devDependencies,\n    foo: '^foo@1.0.0',\n  },\n  peerDependencies: {},\n  optionalDependencies: pkgJson.content.optionalDependencies,\n})\n```\n\n---\n\n### **get** `PackageJson.content`\n\nGetter that retrieves the normalized `Object` read from the loaded\n`package.json` file.\n\n### Example:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load('./')\npkgJson.content\n// -> {\n//   name: 'foo',\n//   version: '1.0.0'\n// }\n```\n\n---\n\n### `async PackageJson.save()`\n\nSaves the current `content` to the same location used when calling\n`load()`.\n\n## LICENSE\n\n[ISC](./LICENSE)\n","publish_time":1732729215035,"maintainers":[{"name":"fritzy","email":"fritzy@github.com"},{"name":"gar","email":"gar+npm@danger.computer"},{"name":"saquibkhan","email":"saquibkhan@github.com"},{"name":"npm-cli-ops","email":"npm-cli+bot@github.com"},{"name":"reggi","email":"reggi@github.com"},{"name":"hashtagchris","email":"hashtagchris@github.com"}],"_cnpm_publish_time":1732729215035,"dist-tags":{"latest":"8.0.0"}}