{"name":"write-package","version":"7.2.0","description":"Write a package.json file","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/write-package.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["json","write","stringify","file","fs","graceful","package"],"dependencies":{"deepmerge-ts":"^7.1.0","read-pkg":"^9.0.1","sort-keys":"^5.0.0","type-fest":"^4.23.0","write-json-file":"^6.0.0"},"devDependencies":{"ava":"^6.1.3","esmock":"^2.6.7","filter-anything":"^4.0.2","tempy":"^3.1.0","tsd":"^0.31.1","xo":"^0.59.2"},"ava":{"nodeArguments":["--loader=esmock","--no-warnings=ExperimentalWarning"]},"_id":"write-package@7.2.0","gitHead":"6797091ffdbee30f1ca87af35abb171c432bf6b1","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/write-package/issues"},"homepage":"https://github.com/sindresorhus/write-package#readme","_nodeVersion":"20.19.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-uMQTubF/vcu+Wd0b5BGtDmiXePd/+44hUWQz2nZPbs92/BnxRo74tqs+hqDo12RLiEd+CXFKUwxvvIZvtt34Jw==","shasum":"d84e5a0dfe92cb7d17399adc8c083d38671cd871","tarball":"http://registry-npm.ywwl.com/write-package/download/write-package-7.2.0.tgz","fileCount":9,"unpackedSize":21692,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEv/q+beAmI16XcmcVMXyXKpzYMah8msig0sqAhsswDDAiB2/wt4IDbQtMoPPTKlq64zG9B0sSiZEUvekryHrbn1Lw=="}],"size":4386,"noattachment":false,"key":"/write-package/-/write-package-7.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/write-package_7.2.0_1757585883781_0.32198459687443903"},"_hasShrinkwrap":false,"readme":"# write-package\n\n> Write a `package.json` file\n\nWrites atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.\n\n## Install\n\n```sh\nnpm install write-package\n```\n\n## Usage\n\n```js\nimport path from 'node:path';\nimport {writePackage} from 'write-package';\n\nawait writePackage({foo: true});\nconsole.log('done');\n\nawait writePackage(path.join('unicorn', 'package.json'), {foo: true});\nconsole.log('done');\n```\n\n## API\n\n### writePackage(path?, data, options?)\n\nReturns a `Promise` that resolves when the `package.json` file has been written.\n\n### writePackageSync(path?, data, options?)\n\n#### path\n\nType: `string`\\\nDefault: `process.cwd()`\n\nThe path to where the `package.json` file should be written or its directory.\n\n#### data\n\nType `object`\n\nJSON data to write to the `package.json` file.\n\n#### options\n\nType: `object`\n\nSee [Options](#options-4).\n\n### updatePackage(path?, data, options?)\n\nReturns a `Promise` that resolves when the `package.json` file has been updated.\n\n### updatePackageSync(path?, data, options?)\n\n```js\nimport {updatePackage} from 'write-package';\n\nawait updatePackage({foo: true});\n//=> { \"foo\": true }\n\nawait updatePackage({foo: false, bar: true});\n//=> { \"foo\": false, \"bar\": true }\n```\n\n#### path\n\nType: `string`\\\nDefault: `process.cwd()`\n\nThe path to where the `package.json` file should be written or its directory.\n\n#### data\n\nType `object`\n\nJSON data to write to the `package.json` file. If the file already exists, existing fields will be merged with the values in `data`.\n\n#### options\n\nType: `object`\n\nSee [Options](#options-4).\n\n### addPackageDependencies(path?, dependencies, options?)\n\nReturns a `Promise` that resolves when the `package.json` file has been written.\n\n### addPackageDependenciesSync(path?, dependencies, options?)\n\n```js\nimport {writePackage, addPackageDependencies} from 'write-package';\n\nawait writePackage({foo: true});\n//=> { \"foo\": true }\n\nawait addPackageDependencies({foo: '1.0.0'});\n//=> { \"foo\": true, \"dependencies\": { \"foo\": \"1.0.0\" } }\n\nawait addPackageDependencies({dependencies: {foo: '1.0.0'}, devDependencies: {bar: '1.0.0'}});\n//=> { \"foo\": true, \"dependencies\": { \"foo\": \"1.0.0\" }, \"devDependencies\": { \"bar\": \"1.0.0\" } }\n```\n\n#### path\n\nType: `string`\\\nDefault: `process.cwd()`\n\nThe path to where the `package.json` file should be written or its directory.\n\n#### dependencies\n\nType: `Record<string, string> | Partial<Record<'dependencies' | 'devDependencies' | 'optionalDependencies' | 'peerDependencies', Record<string, string>>>`\n\nDependencies to add to the `package.json` file.\n\n#### options\n\nType: `object`\n\nSee [Options](#options-4).\n\n### removePackageDependencies(path?, dependencies, options?)\n\nReturns a `Promise` that resolves when the `package.json` file has been written. Does not throw if the file does not exist.\n\n### removePackageDependenciesSync(path?, dependencies, options?)\n\n```js\nimport {writePackage, removePackageDependencies} from 'write-package';\n\nawait writePackage({foo: true, dependencies: {foo: '1.0.0'}, devDependencies: {bar: '1.0.0'}});\n//=> { \"foo\": true, \"dependencies\": { \"foo\": \"1.0.0\" }, \"devDependencies\": { \"bar\": \"1.0.0\" } }\n\nawait removePackageDependencies(['foo']);\n//=> { \"foo\": true, \"devDependencies\": { \"bar\": \"1.0.0\" } }\n\nawait removePackageDependencies({devDependencies: ['bar']});\n//=> { \"foo\": true }\n```\n\n#### path\n\nType: `string`\\\nDefault: `process.cwd()`\n\nThe path to where the `package.json` file should be written or its directory.\n\n#### dependencies\n\nType `string[] | Partial<Record<'dependencies' | 'devDependencies' | 'optionalDependencies' | 'peerDependencies', string[]>>`\n\nDependencies to remove from the `package.json` file.\n\n#### options\n\nType: `object`\n\nSee [Options](#options-4).\n\n### Options\n\n##### indent\n\nType: `string | number`\\\nDefault: Auto-detected or `'\\t'`\n\nThe indentation to use for new files.\n\nAccepts `'\\t'` for tab indentation or a number of spaces.\n\nIf the file already exists, the existing indentation will be used.\n\n##### detectIndent\n\nType: `boolean`\\\nDefault: `true`\n\nDetect indentation automatically if the file exists.\n\n##### normalize\n\nType: `boolean`\\\nDefault: `true`\n\nRemove empty `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` objects.\n\n## Related\n\n- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a `package.json` file\n- [write-json-file](https://github.com/sindresorhus/write-json-file) - Stringify and write JSON to a file atomically\n","publish_time":1757585883946,"_cnpm_publish_time":1757585883946,"dist-tags":{"latest":"7.2.0"}}