{"name":"get-tsconfig","version":"3.0.0","description":"Find and parse the tsconfig.json file from a directory path","keywords":["get-tsconfig","get","typescript","tsconfig","tsconfig.json"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/privatenumber/get-tsconfig.git"},"funding":"https://github.com/privatenumber/get-tsconfig?sponsor=1","author":{"name":"Hiroki Osame","email":"hiroki.osame@gmail.com"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"lint":"eslint .","build":"pkgroll --minify","test":"esno tests"},"husky":{"hooks":{"pre-commit":"npm run build && lint-staged && npm test"}},"lint-staged":{"*.{js,ts}":["eslint","npm test"]},"devDependencies":{"@pvtnbr/eslint-config":"^0.19.1","@types/node":"^17.0.23","es-jest":"^1.5.0","eslint":"^8.12.0","esno":"^0.14.1","execa":"^6.1.0","husky":"^4.3.8","jsonc-parser":"^3.0.0","lint-staged":"^12.3.7","manten":"^0.0.3","pkgroll":"file:vendors/pkgroll-0.0.0.tgz","slash":"^4.0.0","type-fest":"github:privatenumber/type-fest#built/tsconfig-watch-options","typescript":"^4.6.3"},"eslintConfig":{"extends":"@pvtnbr/eslint-config","ignorePatterns":["tests/fixtures"],"overrides":[{"files":"tests/**/*.ts","rules":{"@typescript-eslint/no-shadow":["error",{"allow":["test","describe"]}]}}]},"gitHead":"e58443a8ad12a28060a8a667297ddc14a31689d2","bugs":{"url":"https://github.com/privatenumber/get-tsconfig/issues"},"homepage":"https://github.com/privatenumber/get-tsconfig#readme","_id":"get-tsconfig@3.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-6M+rJ2v+VULEBkV6g59960wtjdoevNgWWhx+UMi8u2xDiIHg8CtVmB0bpUyAY0znHCT00BvOPr4JoH6FGDx+zQ==","shasum":"193b0cb0f6a3be3c702ea9be704f407c064857b6","tarball":"http://registry-npm.ywwl.com/get-tsconfig/download/get-tsconfig-3.0.0.tgz","fileCount":6,"unpackedSize":49203,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBgD9rXQOR61Xa/Xroa8KyQESVjFQ/oQwxnV6lma21F1AiBZh/hgmHVXs8EYe/aswtmwjcaMnmEhw3J4Ew4UzKL5KA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiRd/vACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrjRA/+Nee+XJDXkfsohMFjeLR+HqNX+/4ga4RC+0LRKA4zRRgoAb7y\r\nNQoNPIkNZyfxXzkQQnhK+odIRKoRGzJo0kw92LLOV5N70MQfxggUOPQW/f+L\r\nuc/McRF3v0YGl8qLcGFLFIfmdicLdSOiVdUHnDG60kVnhdzpWrnGkTPJE60U\r\n+vIRIgNdLYtmzJGjfLPfUf11EUQvkQ6yMxcHAlmfkxt9O1g8W1jaH4HvSFk9\r\n0S2uJlyU5hAcc+bHFvLXTm2rJqTA3Jhvdukm1h5Ru/6ORND7S7GVRPuqbmkF\r\nCOygQyqk0AjcZFTkjf9nXTtN+0NmoGK4la/cYZTCLwM/33bUbRg9908brGOm\r\nQQtdHkPxUnbm+mGJare7f6yFVVqItVkQyfyccEiqQ1ApDF26MbkA4zyXQm8Q\r\no8Ug91B4U3p7qsVfk1f0QmeBhoO8IDvh0EUg4k+B54/WUDbKmfAYkKe6GELC\r\nrc4fpjL5IGSw6e9SwMz0O6CSeKno1uQ0+Hjbw1lLWJud0Bh/eYT7P4TF5GX1\r\nrtyFUNUXJuXIfPnLwvWMWM5iz+JWwl2AX9G+5K3Yx/Uhy/m09wIIynJHFLBV\r\n6ktUTAuBL3S/0LVMrI22wYgdxTeuR2gVw7NR3U99mb2PK1OZVWRN5lelyKUE\r\n5dF59td7+AF2V2y+UvCwl2NVaKp7QXGqkuY=\r\n=SyBh\r\n-----END PGP SIGNATURE-----\r\n","size":13712,"noattachment":false,"key":"/get-tsconfig/-/get-tsconfig-3.0.0.tgz"},"_npmUser":{"name":"hirokiosame","email":"hiroki.osame@gmail.com"},"directories":{},"maintainers":[{"name":"hirokiosame","email":"hiroki.osame@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-tsconfig_3.0.0_1648746478793_0.8709627030076144"},"_hasShrinkwrap":false,"readme":"<p align=\"center\">\n\t<img width=\"160\" src=\".github/logo.webp\">\n</p>\n<h1 align=\"center\">\n\t<sup>get-tsconfig</sup>\n\t<br>\n\t<a href=\"https://npm.im/get-tsconfig\"><img src=\"https://badgen.net/npm/v/get-tsconfig\"></a> <a href=\"https://npm.im/get-tsconfig\"><img src=\"https://badgen.net/npm/dm/get-tsconfig\"></a>\n</h1>\n\nFind and parse `tsconfig.json` files.\n\n### Features\n- Zero dependency (not even TypeScript)\n- Tested against TypeScript for correctness\n- Supports comments & dangling commas in `tsconfig.json`\n- Resolves [`extends`](https://www.typescriptlang.org/tsconfig/#extends)\n- Fully typed `tsconfig.json`\n- Validates and throws parsing errors\n- Tiny! `7 kB` Minified + Gzipped\n\n<br>\n\n<p align=\"center\">\n\t<a href=\"https://github.com/sponsors/privatenumber/sponsorships?tier_id=398771\"><img width=\"412\" src=\"https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/donate.webp\"></a>\n\t<a href=\"https://github.com/sponsors/privatenumber/sponsorships?tier_id=397608\"><img width=\"412\" src=\"https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/sponsor.webp\"></a>\n</p>\n<p align=\"center\"><sup><i>Already a sponsor?</i> Join the discussion in the <a href=\"https://github.com/pvtnbr/get-tsconfig\">Development repo</a>!</sup></p>\n\n## Install\n\n```bash\nnpm install get-tsconfig\n```\n\n## Why?\nFor TypeScript related tooling to correctly parse `tsconfig.json` file without depending on TypeScript.\n\n## API\n\n### getTsconfig(searchPath?, configName?, cache?)\nSearches for a `tsconfig.json` file and parses it. Returns `null` if a config file cannot be found, or an object containing the path and parsed TSConfig object if found.\n\nReturns:\n\n```ts\ntype TsconfigResult = {\n\n    /**\n     * The path to the tsconfig.json file\n     */\n    path: string\n\n    /**\n     * The resolved tsconfig.json file\n     */\n    config: TsConfigJsonResolved\n}\n```\n\n#### searchPath\nType: `string`\n\nDefault: `process.cwd()`\n\nAccepts a path to a file or directory to search up for a `tsconfig.json` file.\n\n#### configName\nType: `string`\n\nDefault: `tsconfig.json`\n\nThe file name of the TypeScript config file.\n\n#### cache\nType: `Map<string, any>`\n\nDefault: `new Map()`\n\nOptional cache for fs operations.\n\n#### Example\n\n```ts\nimport { getTsconfig } from 'get-tsconfig'\n\n// Searches for tsconfig.json starting in the current directory\nconsole.log(getTsconfig())\n\n// Find tsconfig.json from a TypeScript file path\nconsole.log(getTsconfig('./path/to/index.ts'))\n\n// Find tsconfig.json from a directory file path\nconsole.log(getTsconfig('./path/to/directory'))\n\n// Explicitly pass in tsconfig.json path\nconsole.log(getTsconfig('./path/to/tsconfig.json'))\n\n// Search for jsconfig.json - https://code.visualstudio.com/docs/languages/jsconfig\nconsole.log(getTsconfig('.', 'jsconfig.json'))\n```\n\n---\n\n### parseTsconfig(tsconfigPath, cache?)\nThe `tsconfig.json` parser used internally by `getTsconfig`. Returns the parsed tsconfig as `TsConfigJsonResolved`.\n\n#### tsconfigPath\nType: `string`\n\nRequired path to the tsconfig file.\n\n#### cache\nType: `Map<string, any>`\n\nDefault: `new Map()`\n\nOptional cache for fs operations.\n\n#### Example\n\n```ts\nimport { parseTsconfig } from 'get-tsconfig'\n\n// Must pass in a path to an existing tsconfig.json file\nconsole.log(parseTsconfig('./path/to/tsconfig.custom.json'))\n```\n\n### createFileMatcher(tsconfig: TsconfigResult, caseSensitivePaths?: boolean)\n\nGiven a `tsconfig.json` file, it returns a file-matcher function that determines whether it should apply to a file path.\n\n```ts\ntype FileMatcher = (filePath: string) => TsconfigResult['config'] | undefined\n```\n\n#### tsconfig\nType: `TsconfigResult`\n\nPass in the return value from `getTsconfig`, or a `TsconfigResult` object.\n\n#### caseSensitivePaths\nType: `boolean`\n\nBy default, it uses [`is-fs-case-sensitive`](https://github.com/privatenumber/is-fs-case-sensitive) to detect whether the file-system is case-sensitive.\n\nPass in `true` to make it case-sensitive.\n\n#### Example\n\nFor example, if it's called with a `tsconfig.json` file that has `include`/`exclude`/`files` defined, the file-matcher will return the config for files that match `include`/`files`, and return `undefined` for files that don't match or match `exclude`.\n\n```ts\nconst tsconfig = getTsconfig()\nconst fileMatcher = tsconfig && createFileMatcher(tsconfig)\n\n/*\n * Returns tsconfig.json if it matches the file,\n * undefined if not\n */\nconst configForFile = fileMatcher?.('/path/to/file.ts')\nconst distCode = compileTypescript({\n    code: sourceCode,\n    tsconfig: configForFile\n})\n```\n\n---\n\n### createPathsMatcher(tsconfig: TsconfigResult)\n\nGiven a tsconfig with [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) defined, it returns a matcher function.\n\nThe matcher function accepts an [import specifier (the path to resolve)](https://nodejs.org/api/esm.html#terminology), checks it against `compilerOptions.paths`, and returns an array of possible paths to check:\n```ts\nfunction pathsMatcher(specifier: string): string[]\n```\n\nThis function only returns possible paths and doesn't actually do any resolution. This helps increase compatibility wtih file/build systems which usually have their own resolvers.\n\n#### Example\n\n```ts\nimport { getTsconfig, createPathsMatcher } from 'get-tsconfig'\n\nconst tsconfig = getTsconfig()\nconst pathsMatcher = createPathsMatcher(tsconfig)\n\nconst exampleResolver = (request: string) => {\n    if (pathsMatcher) {\n        const tryPaths = pathsMatcher(request)\n\n        // Check if paths in `tryPaths` exist\n    }\n}\n```\n\n## FAQ\n\n### How can I use TypeScript to parse `tsconfig.json`?\nThis package is a re-implementation of TypeScript's `tsconfig.json` parser.\n\nHowever, if you already have TypeScript as a dependency, you can simply use it's API:\n\n```ts\nimport {\n    sys as tsSys,\n    findConfigFile,\n    readConfigFile,\n    parseJsonConfigFileContent\n} from 'typescript'\n\n// Find tsconfig.json file\nconst tsconfigPath = findConfigFile(process.cwd(), tsSys.fileExists, 'tsconfig.json')\n\n// Read tsconfig.json file\nconst tsconfigFile = readConfigFile(tsconfigPath, tsSys.readFile)\n\n// Resolve extends\nconst parsedTsconfig = parseJsonConfigFileContent(\n    tsconfigFile.config,\n    tsSys,\n    path.dirname(tsconfigPath)\n)\n```\n\n## Sponsors\n<p align=\"center\">\n\t<a href=\"https://github.com/sponsors/privatenumber\">\n\t\t<img src=\"https://cdn.jsdelivr.net/gh/privatenumber/sponsors/sponsorkit/sponsors.svg\">\n\t</a>\n</p>\n","publish_time":1648746479196,"_cnpm_publish_time":1648746479196,"dist-tags":{"beta":"5.0.0-beta.6","latest":"4.14.3"}}