@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 12.2 kB
Source Map (JSON)
{"version":3,"sources":["../../src/lib/typescript/tsconfig.ts"],"names":["getTsconfigFilePath","projectRoot","tsconfig","tsconfigFilePath","existsSync","joinPaths","replacePath","Error","findMatch","tsconfigType","types","extensions","find","type","toString","toLowerCase","some","ext","findIncludeMatch","isMatchFound","undefined","isIncludeMatchFound","getParsedTypeScriptConfig","workspaceRoot","tsconfigRaw","host","ts","sys","tsconfigJson","readJsonFileSync","parsedCommandLine","parseJsonConfigFileContent","defu","errors","length","errorMessage","map","error","category","code","messageText","join"],"mappings":";;;;;;;;;;;;;;AAkCO,SAASA,mBAAAA,CACdC,WAAAA,EACAC,QAAAA,GAAW,eAAA,EAAe;AAE1B,EAAA,IAAIC,gBAAAA,GAAmBD,QAAAA;AACvB,EAAA,IAAI,CAACE,eAAAA,CAAWD,gBAAAA,CAAAA,EAAmB;AACjCA,IAAAA,gBAAAA,GAAmBE,cAAAA,CACjBJ,WAAAA,EACAK,mBAAAA,CAAYJ,QAAAA,EAAUD,WAAAA,CAAAA,CAAAA;AAExB,IAAA,IAAI,CAACG,eAAAA,CAAWD,gBAAAA,CAAAA,EAAmB;AACjC,MAAA,MAAM,IAAII,KAAAA,CACR,CAAA,wDAAA,EAA2DF,cAAAA,CACzDJ,WAAAA,EACAK,mBAAAA,CAAYJ,QAAAA,EAAUD,WAAAA,CAAAA,CAAAA,CAAAA,IAAAA,EAChBE,gBAAAA,CAAAA,CAAkB,CAAA;AAE9B,IAAA;AACF,EAAA;AAEA,EAAA,OAAOA,gBAAAA;AACT;AArBgBH,wBAAAA,CAAAA,mBAAAA,EAAAA,qBAAAA,CAAAA;AA8BT,SAASQ,SAAAA,CACdC,YAAAA,EACAC,KAAAA,EACAC,UAAAA,GAAuB;AAAC,EAAA,KAAA;AAAO,EAAA,MAAA;AAAQ,EAAA;AAAQ,CAAA,EAAA;AAE/C,EAAA,OAAOD,KAAAA,CAAME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,IAAAA,CAAK,IAAA,CAAA;;AAGJ,IAAA,MAAM,IAAIlC,MAAM4B,YAAAA,CAAAA;AAClB,EAAA;AAEA,EAAA,OAAO;IACL,GAAGL,iBAAAA;AACHF,IAAAA,YAAAA;AACAzB,IAAAA;AACF,GAAA;AACF;AA7CgBmB,wBAAAA,CAAAA,yBAAAA,EAAAA,2BAAAA,CAAAA","file":"chunk-Z72ISLE5.cjs","sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Storm Stack\n\n This code was released as part of the Storm Stack project. Storm Stack\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/storm-stack.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/storm-stack\n Documentation: https://docs.stormsoftware.com/projects/storm-stack\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { readJsonFileSync } from \"@stryke/fs/json\";\nimport { existsSync, joinPaths } from \"@stryke/path\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { FilterPattern } from \"@stryke/types/file\";\nimport defu from \"defu\";\nimport ts from \"typescript\";\nimport { ParsedTypeScriptConfig, TSConfig } from \"../../types/tsconfig\";\n\n/**\n * Get the path to the tsconfig.json file.\n *\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @returns The absolute path to the tsconfig.json file.\n * @throws If the tsconfig.json file does not exist.\n */\nexport function getTsconfigFilePath(\n projectRoot: string,\n tsconfig = \"tsconfig.json\"\n): string {\n let tsconfigFilePath = tsconfig;\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = joinPaths(\n projectRoot,\n replacePath(tsconfig, projectRoot)\n );\n if (!existsSync(tsconfigFilePath)) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file at ${joinPaths(\n projectRoot,\n replacePath(tsconfig, projectRoot)\n )} or ${tsconfigFilePath}`\n );\n }\n }\n\n return tsconfigFilePath;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[],\n extensions: string[] = [\".ts\", \".tsx\", \".d.ts\"]\n): string | RegExp | null | undefined {\n return types.find(\n type =>\n tsconfigType?.toString().toLowerCase() ===\n type?.toString().toLowerCase() ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}` ||\n `./${tsconfigType?.toString().toLowerCase()}` ===\n type?.toString().toLowerCase() ||\n extensions.some(\n ext =>\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n type?.toString().toLowerCase() ||\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n `./${type?.toString().toLowerCase()}` ||\n `${type?.toString().toLowerCase()}${ext}` ===\n `./${tsconfigType?.toString().toLowerCase()}` ||\n tsconfigType?.toString().toLowerCase() ===\n `${type?.toString().toLowerCase()}${ext}` ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}${ext}` ||\n type?.toString().toLowerCase() ===\n `./${tsconfigType?.toString().toLowerCase()}${ext}`\n )\n );\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findIncludeMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): string | RegExp | null | undefined {\n return findMatch(tsconfigType, types, [\n \".ts\",\n \".tsx\",\n \".d.ts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n \".mts\",\n \".cts\",\n \"/*.ts\",\n \"/*.tsx\",\n \"/*.d.ts\",\n \"/*.js\",\n \"/*.jsx\",\n \"/*.mjs\",\n \"/*.cjs\",\n \"/*.mts\",\n \"/*.cts\",\n \"/**/*.ts\",\n \"/**/*.tsx\",\n \"/**/*.d.ts\",\n \"/**/*.js\",\n \"/**/*.jsx\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.mts\",\n \"/**/*.cts\"\n ]);\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isMatchFound(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): boolean {\n return findMatch(tsconfigType, types) !== undefined;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isIncludeMatchFound(\n tsconfigType: FilterPattern,\n types: FilterPattern[]\n): boolean {\n return (\n findIncludeMatch(\n tsconfigType as string | RegExp | null,\n types as (string | RegExp | null)[]\n ) !== undefined\n );\n}\n\n/**\n * Get the parsed TypeScript configuration.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @param tsconfigRaw - The raw tsconfig.json content.\n * @param host - The TypeScript parse config host.\n * @returns The resolved TypeScript configuration.\n */\nexport function getParsedTypeScriptConfig(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig?: string,\n tsconfigRaw: TSConfig = {},\n host: ts.ParseConfigHost = ts.sys\n): ParsedTypeScriptConfig {\n const tsconfigFilePath = getTsconfigFilePath(projectRoot, tsconfig);\n const tsconfigJson = readJsonFileSync<TSConfig>(tsconfigFilePath);\n if (!tsconfigJson) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file at ${joinPaths(\n projectRoot,\n tsconfig ?? \"tsconfig.json\"\n )}`\n );\n }\n\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n defu(tsconfigRaw ?? {}, tsconfigJson),\n host,\n joinPaths(workspaceRoot, projectRoot)\n );\n if (parsedCommandLine.errors.length > 0) {\n const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:\n${parsedCommandLine.errors\n .map(\n error =>\n `- ${\n (error.category !== undefined && error.code\n ? `[${error.category}-${error.code}]: `\n : \"\") + error.messageText.toString()\n }`\n )\n .join(\"\\n\")}\n `;\n\n throw new Error(errorMessage);\n }\n\n return {\n ...parsedCommandLine,\n tsconfigJson,\n tsconfigFilePath\n };\n}\n"]}