{"id":13526871,"url":"https://github.com/sindresorhus/write-package","last_synced_at":"2025-04-06T01:07:35.211Z","repository":{"id":1223961,"uuid":"41790634","full_name":"sindresorhus/write-package","owner":"sindresorhus","description":"Write a package.json file","archived":false,"fork":false,"pushed_at":"2024-07-26T11:27:20.000Z","size":51,"stargazers_count":88,"open_issues_count":1,"forks_count":13,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T00:09:37.624Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-09-02T08:51:44.000Z","updated_at":"2025-03-10T10:42:26.000Z","dependencies_parsed_at":"2024-04-15T00:41:06.796Z","dependency_job_id":"9176310c-b079-4918-80ed-778cfba162c9","html_url":"https://github.com/sindresorhus/write-package","commit_stats":{"total_commits":46,"total_committers":9,"mean_commits":5.111111111111111,"dds":"0.26086956521739135","last_synced_commit":"9f44ea9e0b706675bd506b0bc549958dd2557a02"},"previous_names":["sindresorhus/write-package","sindresorhus/write-pkg"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fwrite-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fwrite-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fwrite-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fwrite-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/write-package/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246759720,"owners_count":20829146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:36.470Z","updated_at":"2025-04-06T01:07:35.190Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# write-package\n\n\u003e 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//=\u003e { \"foo\": true }\n\nawait updatePackage({foo: false, bar: true});\n//=\u003e { \"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//=\u003e { \"foo\": true }\n\nawait addPackageDependencies({foo: '1.0.0'});\n//=\u003e { \"foo\": true, \"dependencies\": { \"foo\": \"1.0.0\" } }\n\nawait addPackageDependencies({dependencies: {foo: '1.0.0'}, devDependencies: {bar: '1.0.0'}});\n//=\u003e { \"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\u003cstring, string\u003e | Partial\u003cRecord\u003c'dependencies' | 'devDependencies' | 'optionalDependencies' | 'peerDependencies', Record\u003cstring, string\u003e\u003e\u003e`\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//=\u003e { \"foo\": true, \"dependencies\": { \"foo\": \"1.0.0\" }, \"devDependencies\": { \"bar\": \"1.0.0\" } }\n\nawait removePackageDependencies(['foo']);\n//=\u003e { \"foo\": true, \"devDependencies\": { \"bar\": \"1.0.0\" } }\n\nawait removePackageDependencies({devDependencies: ['bar']});\n//=\u003e { \"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\u003cRecord\u003c'dependencies' | 'devDependencies' | 'optionalDependencies' | 'peerDependencies', string[]\u003e\u003e`\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##### 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","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Repository","JavaScript"],"sub_categories":["NPM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fwrite-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fwrite-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fwrite-package/lists"}