UNPKG

@stryke/fs

Version:

A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.

1 lines 3.47 kB
{"version":3,"file":"tsconfig.mjs","names":[],"sources":["../src/tsconfig.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport { findFileExtension, findFilePath } from \"@stryke/path/file-path-fns\";\nimport { isNpmScopedPackage } from \"@stryke/path/is-type\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { TsConfigJson } from \"@stryke/types/tsconfig\";\nimport defu from \"defu\";\nimport { existsSync } from \"./exists\";\nimport { readJsonFile } from \"./json\";\nimport { resolve } from \"./resolve\";\n\n/**\n * Loads a tsconfig.json file and returns the parsed JSON object.\n *\n * @param filePath - The directory to start searching for the tsconfig.json file.\n * @returns The parsed tsconfig.json object or null if not found.\n */\nexport async function loadTsConfig(\n filePath: string = cwd()\n): Promise<TsConfigJson> {\n let tsconfigFilePath =\n findFileExtension(filePath) === \"json\"\n ? filePath\n : joinPaths(filePath, \"tsconfig.json\");\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = await resolve(filePath, { extensions: [\"json\"] });\n if (!existsSync(tsconfigFilePath)) {\n throw new Error(\n `tsconfig.json not found at ${tsconfigFilePath}. Please ensure the file exists.`\n );\n }\n }\n\n let config = await readJsonFile<TsConfigJson>(tsconfigFilePath);\n if (config?.compilerOptions?.rootDir) {\n config.compilerOptions.rootDir = joinPaths(\n findFilePath(tsconfigFilePath),\n config.compilerOptions.rootDir\n );\n }\n\n if (config?.extends) {\n for (const extendsName of toArray(config.extends)) {\n const parentConfig = await loadTsConfig(\n isNpmScopedPackage(extendsName)\n ? extendsName\n : joinPaths(findFilePath(tsconfigFilePath), extendsName)\n );\n if (parentConfig) {\n config = defu(config, parentConfig ?? {});\n }\n }\n }\n\n config.extends = undefined;\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,eAAsB,aACpB,WAAmB,KAAK,EACD;CACvB,IAAI,mBACF,kBAAkB,SAAS,KAAK,SAC5B,WACA,UAAU,UAAU,gBAAgB;AAC1C,KAAI,CAAC,WAAW,iBAAiB,EAAE;AACjC,qBAAmB,MAAM,QAAQ,UAAU,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC;AACpE,MAAI,CAAC,WAAW,iBAAiB,CAC/B,OAAM,IAAI,MACR,8BAA8B,iBAAiB,kCAChD;;CAIL,IAAI,SAAS,MAAM,aAA2B,iBAAiB;AAC/D,KAAI,QAAQ,iBAAiB,QAC3B,QAAO,gBAAgB,UAAU,UAC/B,aAAa,iBAAiB,EAC9B,OAAO,gBAAgB,QACxB;AAGH,KAAI,QAAQ,QACV,MAAK,MAAM,eAAe,QAAQ,OAAO,QAAQ,EAAE;EACjD,MAAM,eAAe,MAAM,aACzB,mBAAmB,YAAY,GAC3B,cACA,UAAU,aAAa,iBAAiB,EAAE,YAAY,CAC3D;AACD,MAAI,aACF,UAAS,KAAK,QAAQ,gBAAgB,EAAE,CAAC;;AAK/C,QAAO,UAAU;AACjB,QAAO"}