{"_id":"@npmcli/package-json","_rev":"188055","name":"@npmcli/package-json","description":"Programmatic API to update package.json","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"fritzy","email":""},{"name":"gar","email":""},{"name":"lukekarrys","email":""},{"name":"nlf","email":""},{"name":"npm-cli-ops","email":""},{"name":"saquibkhan","email":""}],"time":{"modified":"2023-01-23T03:01:10.000Z","created":"2021-06-22T23:24:10.542Z","3.0.0":"2022-10-14T02:00:58.968Z","2.0.0":"2022-04-05T14:02:07.676Z","1.0.1":"2021-06-23T16:26:13.768Z","1.0.0":"2021-06-22T23:24:10.542Z"},"users":{},"author":{"name":"GitHub Inc."},"repository":{"type":"git","url":"git+https://github.com/npm/package-json.git"},"versions":{"3.0.0":{"name":"@npmcli/package-json","version":"3.0.0","description":"Programmatic API to update package.json","main":"lib/index.js","scripts":{"snap":"tap","test":"tap","lint":"eslint \"**/*.js\"","lintfix":"npm run lint -- --fix","posttest":"npm run lint","postsnap":"npm run lintfix --","postlint":"template-oss-check","template-oss-apply":"template-oss-apply --force"},"keywords":["npm","oss"],"author":{"name":"GitHub Inc."},"license":"ISC","devDependencies":{"@npmcli/eslint-config":"^3.0.1","@npmcli/template-oss":"4.5.1","tap":"^16.0.1"},"dependencies":{"json-parse-even-better-errors":"^3.0.0"},"repository":{"type":"git","url":"git+https://github.com/npm/package-json.git"},"engines":{"node":"^14.17.0 || ^16.13.0 || >=18.0.0"},"templateOSS":{"//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten.","version":"4.5.1"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"]},"gitHead":"496d0cd78db183252464597d32c2eb4f322bf98e","bugs":{"url":"https://github.com/npm/package-json/issues"},"homepage":"https://github.com/npm/package-json#readme","_id":"@npmcli/package-json@3.0.0","_nodeVersion":"18.10.0","_npmVersion":"8.19.2","dist":{"shasum":"c9219a197e1be8dbf43c4ef8767a72277c0533b6","size":4484,"noattachment":false,"key":"/@npmcli/package-json/-/@npmcli/package-json-3.0.0.tgz","tarball":"http://name.csiicloud.com:7001/@npmcli/package-json/download/@npmcli/package-json-3.0.0.tgz"},"_npmUser":{"name":"lukekarrys","email":"luke@lukekarrys.com"},"directories":{},"maintainers":[{"name":"fritzy","email":""},{"name":"gar","email":""},{"name":"lukekarrys","email":""},{"name":"nlf","email":""},{"name":"npm-cli-ops","email":""},{"name":"saquibkhan","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/package-json_3.0.0_1665712858770_0.021797029178529215"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-10-16T07:22:26.190Z","publish_time":1665712858968,"_cnpm_publish_time":1665712858968},"2.0.0":{"name":"@npmcli/package-json","version":"2.0.0","description":"Programmatic API to update package.json","main":"lib/index.js","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","snap":"tap","test":"tap","lint":"eslint \"**/*.js\"","lintfix":"npm run lint -- --fix","posttest":"npm run lint","postsnap":"npm run lintfix --","postlint":"template-oss-check","template-oss-apply":"template-oss-apply --force"},"keywords":["npm","oss"],"author":{"name":"GitHub Inc."},"license":"ISC","devDependencies":{"@npmcli/eslint-config":"^3.0.1","@npmcli/template-oss":"3.2.2","tap":"^16.0.1"},"dependencies":{"json-parse-even-better-errors":"^2.3.1"},"repository":{"type":"git","url":"git+https://github.com/npm/package-json.git"},"engines":{"node":"^12.13.0 || ^14.15.0 || >=16.0.0"},"templateOSS":{"//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten.","version":"3.2.2"},"gitHead":"9d7f8d4306239f258c85755685923d8bda70ee68","bugs":{"url":"https://github.com/npm/package-json/issues"},"homepage":"https://github.com/npm/package-json#readme","_id":"@npmcli/package-json@2.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.6.0","dist":{"shasum":"3bbcf4677e21055adbe673d9f08c9f9cde942e4a","size":4490,"noattachment":false,"key":"/@npmcli/package-json/-/@npmcli/package-json-2.0.0.tgz","tarball":"http://name.csiicloud.com:7001/@npmcli/package-json/download/@npmcli/package-json-2.0.0.tgz"},"_npmUser":{"name":"gar","email":"gar+npm@danger.computer"},"directories":{},"maintainers":[{"name":"fritzy","email":""},{"name":"gar","email":""},{"name":"lukekarrys","email":""},{"name":"nlf","email":""},{"name":"npm-cli-ops","email":""},{"name":"saquibkhan","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/package-json_2.0.0_1649167327531_0.8897321946306054"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-04-05T16:29:34.762Z","publish_time":1649167327676,"_cnpm_publish_time":1649167327676},"1.0.1":{"name":"@npmcli/package-json","version":"1.0.1","description":"Programmatic API to update package.json","main":"lib/index.js","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","snap":"tap","test":"tap","npmclilint":"npmcli-lint","lint":"npm run npmclilint -- \"lib/*.*js\" \"test/*.*js\"","lintfix":"npm run lint -- --fix","posttest":"npm run lint --","postsnap":"npm run lintfix --"},"keywords":["npm","oss"],"author":{"name":"GitHub Inc."},"license":"ISC","devDependencies":{"@npmcli/lint":"^1.0.1","tap":"^15.0.9"},"dependencies":{"json-parse-even-better-errors":"^2.3.1"},"gitHead":"51fc9c583b6af6eb2c775efb2101a15ad24e651a","_id":"@npmcli/package-json@1.0.1","_nodeVersion":"16.3.0","_npmVersion":"7.15.1","dist":{"shasum":"1ed42f00febe5293c3502fd0ef785647355f6e89","size":4314,"noattachment":false,"key":"/@npmcli/package-json/-/@npmcli/package-json-1.0.1.tgz","tarball":"http://name.csiicloud.com:7001/@npmcli/package-json/download/@npmcli/package-json-1.0.1.tgz"},"_npmUser":{"name":"ruyadorno","email":"ruyadorno@hotmail.com"},"directories":{},"maintainers":[{"name":"fritzy","email":""},{"name":"gar","email":""},{"name":"lukekarrys","email":""},{"name":"nlf","email":""},{"name":"npm-cli-ops","email":""},{"name":"saquibkhan","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/package-json_1.0.1_1624465573618_0.49627158540953276"},"_hasShrinkwrap":false,"publish_time":1624465573768,"_cnpm_publish_time":1624465573768,"_cnpmcore_publish_time":"2021-12-13T18:12:01.317Z"},"1.0.0":{"name":"@npmcli/package-json","version":"1.0.0","description":"Programmatic API to update package.json","main":"lib/index.js","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","snap":"tap","test":"tap","npmclilint":"npmcli-lint","lint":"npm run npmclilint -- \"lib/*.*js\" \"test/*.*js\"","lintfix":"npm run lint -- --fix","posttest":"npm run lint --","postsnap":"npm run lintfix --"},"keywords":["npm","oss"],"author":{"name":"GitHub Inc."},"license":"ISC","devDependencies":{"@npmcli/lint":"^1.0.1","tap":"^15.0.9"},"dependencies":{"json-parse-even-better-errors":"^2.3.1"},"gitHead":"f62d8c63acec185f577a3525352d139b4eab0f28","_id":"@npmcli/package-json@1.0.0","_nodeVersion":"16.3.0","_npmVersion":"7.15.1","dist":{"shasum":"74a63b9a472a5a493d8441803769fa4dff9119d5","size":4079,"noattachment":false,"key":"/@npmcli/package-json/-/@npmcli/package-json-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/@npmcli/package-json/download/@npmcli/package-json-1.0.0.tgz"},"_npmUser":{"name":"ruyadorno","email":"ruyadorno@hotmail.com"},"directories":{},"maintainers":[{"name":"fritzy","email":""},{"name":"gar","email":""},{"name":"lukekarrys","email":""},{"name":"nlf","email":""},{"name":"npm-cli-ops","email":""},{"name":"saquibkhan","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/package-json_1.0.0_1624404250421_0.3274632041267709"},"_hasShrinkwrap":false,"publish_time":1624404250542,"_cnpm_publish_time":1624404250542,"_cnpmcore_publish_time":"2021-12-13T18:12:01.571Z"}},"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/workflow/status/npm/package-json/node-ci)](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\n## API:\n\n### `constructor(path)`\n\nCreates a new instance of `PackageJson`.\n\n- `path`: `String` that points to the folder from where to read the\n`package.json` from\n\n---\n\n### `async PackageJson.load()`\n\nLoads the `package.json` at location determined in the `path` option of\nthe constructor.\n\n### Example:\n\nLoads contents of the `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 the `package.json` file is missing or has invalid\ncontents.\n\n---\n\n### **static** `async PackageJson.load(path)`\n\nConvenience static method that returns a new instance and loads the contents of\nthe `package.json` file from that location.\n\n- `path`: `String` that points to the folder from where to read the\n`package.json` from\n\n### Example:\n\nLoads contents of the `package.json` file located at `./`:\n\n```js\nconst PackageJson = require('@npmcli/package-json')\nconst pkgJson = await PackageJson.load('./')\n```\n\n---\n\n### `PackageJson.update(content)`\n\nUpdates the contents of the `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 deduplications.\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 initializing\nthis instance.\n\n<br />\n\n## Related\n\nWhen you make a living out of reading and writing `package.json` files, you end\nup with quite the amount of packages dedicated to it, the **npm cli** also\nuses:\n\n- [read-package-json-fast](https://github.com/npm/read-package-json-fast) reads\nand normalizes `package.json` files the way the **npm cli** expects it.\n- [read-package-json](https://github.com/npm/read-package-json) reads and\nnormalizes more info from your `package.json` file. Used by `npm@6` and in\n`npm@7` for publishing.\n\n## LICENSE\n\n[ISC](./LICENSE)\n\n","_attachments":{},"homepage":"https://github.com/npm/package-json#readme","bugs":{"url":"https://github.com/npm/package-json/issues"},"license":"ISC"}