{"name":"pkg-types","version":"1.3.0","description":"Node.js utilities and TypeScript definitions for `package.json` and `tsconfig.json`","license":"MIT","main":"./dist/index.cjs","sideEffects":false,"exports":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"types":"./dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/unjs/pkg-types.git"},"scripts":{"build":"unbuild","prepack":"pnpm build","dev":"vitest --typecheck","release":"pnpm test && changelogen --release && npm publish && git push --follow-tags","lint":"eslint && prettier -c src test","lint:fix":"automd && eslint --fix . && prettier -w src test","test":"vitest run --typecheck --coverage"},"dependencies":{"confbox":"^0.1.8","mlly":"^1.7.3","pathe":"^1.1.2"},"devDependencies":{"@types/node":"^22.10.2","@vitest/coverage-v8":"^2.1.8","automd":"^0.3.12","changelogen":"^0.5.7","eslint":"^9.17.0","eslint-config-unjs":"^0.4.2","expect-type":"^1.1.0","jiti":"^2.4.2","prettier":"^3.4.2","typescript":"^5.7.2","unbuild":"^3.0.1","vitest":"^2.1.8"},"packageManager":"pnpm@9.15.1","_id":"pkg-types@1.3.0","gitHead":"a263cab04153bc8de4a82c7c8884ecacd0a13d06","bugs":{"url":"https://github.com/unjs/pkg-types/issues"},"homepage":"https://github.com/unjs/pkg-types#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-kS7yWjVFCkIw9hqdJBoMxDdzEngmkr5FXeWZZfQ6GoYacjVnsW6l2CcYW/0ThD0vF4LPJgVYnrg4d0uuhwYQbg==","shasum":"53d915eb99485798c554ad8eb2dc2af7c03006eb","tarball":"http://registry-npm.ywwl.com/pkg-types/download/pkg-types-1.3.0.tgz","fileCount":8,"unpackedSize":74109,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFwSHsNIgsS3QOxHIv7TyPCju51vUOAfdNk2mUYl5V4zAiEAkxD3tV1O6S59Zg5bhaBJBUCE4wnyn4PSFrAbLyeP6Po="}],"size":9928,"noattachment":false,"key":"/pkg-types/-/pkg-types-1.3.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pkg-types_1.3.0_1735300157372_0.9869014059547148"},"_hasShrinkwrap":false,"readme":"# pkg-types\n\n<!-- automd:badges color=yellow codecov -->\n\n[![npm version](https://img.shields.io/npm/v/pkg-types?color=yellow)](https://npmjs.com/package/pkg-types)\n[![npm downloads](https://img.shields.io/npm/dm/pkg-types?color=yellow)](https://npm.chart.dev/pkg-types)\n[![codecov](https://img.shields.io/codecov/c/gh/unjs/pkg-types?color=yellow)](https://codecov.io/gh/unjs/pkg-types)\n\n<!-- /automd -->\n\nNode.js utilities and TypeScript definitions for `package.json` and `tsconfig.json`.\n\n## Install\n\n<!-- automd:pm-i -->\n\n```sh\n# ✨ Auto-detect\nnpx nypm install pkg-types\n\n# npm\nnpm install pkg-types\n\n# yarn\nyarn add pkg-types\n\n# pnpm\npnpm install pkg-types\n\n# bun\nbun install pkg-types\n\n# deno\ndeno install pkg-types\n```\n\n<!-- /automd -->\n\n## Usage\n\n### `readPackageJSON`\n\n```js\nimport { readPackageJSON } from \"pkg-types\";\nconst localPackageJson = await readPackageJSON();\n// or\nconst packageJson = await readPackageJSON(\"/fully/resolved/path/to/folder\");\n```\n\n### `writePackageJSON`\n\n```js\nimport { writePackageJSON } from \"pkg-types\";\n\nawait writePackageJSON(\"path/to/package.json\", pkg);\n```\n\n### `resolvePackageJSON`\n\n```js\nimport { resolvePackageJSON } from \"pkg-types\";\nconst filename = await resolvePackageJSON();\n// or\nconst packageJson = await resolvePackageJSON(\"/fully/resolved/path/to/folder\");\n```\n\n### `readTSConfig`\n\n```js\nimport { readTSConfig } from \"pkg-types\";\nconst tsconfig = await readTSConfig();\n// or\nconst tsconfig2 = await readTSConfig(\"/fully/resolved/path/to/folder\");\n```\n\n### `writeTSConfig`\n\n```js\nimport { writeTSConfig } from \"pkg-types\";\n\nawait writeTSConfig(\"path/to/tsconfig.json\", tsconfig);\n```\n\n### `resolveTSConfig`\n\n```js\nimport { resolveTSConfig } from \"pkg-types\";\nconst filename = await resolveTSConfig();\n// or\nconst tsconfig = await resolveTSConfig(\"/fully/resolved/path/to/folder\");\n```\n\n### `resolveFile`\n\n```js\nimport { resolveFile } from \"pkg-types\";\nconst filename = await resolveFile(\"README.md\", {\n  startingFrom: id,\n  rootPattern: /^node_modules$/,\n  matcher: (filename) => filename.endsWith(\".md\"),\n});\n```\n\n### `resolveLockFile`\n\nFind path to the lock file (`yarn.lock`, `package-lock.json`, `pnpm-lock.yaml`, `npm-shrinkwrap.json`) or throws an error.\n\n```js\nimport { resolveLockFile } from \"pkg-types\";\nconst lockfile = await resolveLockFile(\".\");\n```\n\n### `findWorkspaceDir`\n\nTry to detect workspace dir by in order:\n\n1. Nearest `.git` directory\n2. Farthest lockfile\n3. Farthest `package.json` file\n\nIf fails, throws an error.\n\n```js\nimport { findWorkspaceDir } from \"pkg-types\";\nconst workspaceDir = await findWorkspaceDir(\".\");\n```\n\n## Types\n\n**Note:** In order to make types working, you need to install `typescript` as a devDependency.\n\nYou can directly use typed interfaces:\n\n```ts\nimport type { TSConfig, PackageJSON } from \"pkg-types\";\n```\n\nYou can also use define utils for type support for using in plain `.js` files and auto-complete in IDE.\n\n```js\nimport type { definePackageJSON } from 'pkg-types'\n\nconst pkg = definePackageJSON({})\n```\n\n```js\nimport type { defineTSConfig } from 'pkg-types'\n\nconst pkg = defineTSConfig({})\n```\n\n## Alternatives\n\n- [dominikg/tsconfck](https://github.com/dominikg/tsconfck)\n\n## License\n\n<!-- automd:contributors license=MIT author=\"pi0,danielroe\" -->\n\nPublished under the [MIT](https://github.com/unjs/pkg-types/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0), [@danielroe](https://github.com/danielroe) and [community](https://github.com/unjs/pkg-types/graphs/contributors) 💛\n<br><br>\n<a href=\"https://github.com/unjs/pkg-types/graphs/contributors\">\n<img src=\"https://contrib.rocks/image?repo=unjs/pkg-types\" />\n</a>\n\n<!-- /automd -->\n","publish_time":1735300157593,"maintainers":[{"name":"pi0","email":"pyapar@gmail.com"},{"name":"danielroe","email":"daniel@roe.dev"}],"_cnpm_publish_time":1735300157593,"dist-tags":{"latest":"2.4.0"}}