@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
102 lines (97 loc) • 4.42 kB
JavaScript
;
var chunk3ONWID2V_cjs = require('./chunk-3ONWID2V.cjs');
var json = require('@stryke/fs/json');
var path = require('@stryke/path');
var replace = require('@stryke/path/replace');
var defu = require('defu');
var ts = require('typescript');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var defu__default = /*#__PURE__*/_interopDefault(defu);
var ts__default = /*#__PURE__*/_interopDefault(ts);
function getTsconfigFilePath(projectRoot, tsconfig = "tsconfig.json") {
let tsconfigFilePath = tsconfig;
if (!path.existsSync(tsconfigFilePath)) {
tsconfigFilePath = path.joinPaths(projectRoot, replace.replacePath(tsconfig, projectRoot));
if (!path.existsSync(tsconfigFilePath)) {
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${path.joinPaths(projectRoot, replace.replacePath(tsconfig, projectRoot))} or ${tsconfigFilePath}`);
}
}
return tsconfigFilePath;
}
chunk3ONWID2V_cjs.__name(getTsconfigFilePath, "getTsconfigFilePath");
function findMatch(tsconfigType, types, extensions = [
".ts",
".tsx",
".d.ts"
]) {
return types.find((type) => tsconfigType?.toString().toLowerCase() === type?.toString().toLowerCase() || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}` || `./${tsconfigType?.toString().toLowerCase()}` === type?.toString().toLowerCase() || extensions.some((ext) => `${tsconfigType?.toString().toLowerCase()}${ext}` === type?.toString().toLowerCase() || `${tsconfigType?.toString().toLowerCase()}${ext}` === `./${type?.toString().toLowerCase()}` || `${type?.toString().toLowerCase()}${ext}` === `./${tsconfigType?.toString().toLowerCase()}` || tsconfigType?.toString().toLowerCase() === `${type?.toString().toLowerCase()}${ext}` || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}${ext}` || type?.toString().toLowerCase() === `./${tsconfigType?.toString().toLowerCase()}${ext}`));
}
chunk3ONWID2V_cjs.__name(findMatch, "findMatch");
function findIncludeMatch(tsconfigType, types) {
return findMatch(tsconfigType, types, [
".ts",
".tsx",
".d.ts",
".js",
".jsx",
".mjs",
".cjs",
".mts",
".cts",
"/*.ts",
"/*.tsx",
"/*.d.ts",
"/*.js",
"/*.jsx",
"/*.mjs",
"/*.cjs",
"/*.mts",
"/*.cts",
"/**/*.ts",
"/**/*.tsx",
"/**/*.d.ts",
"/**/*.js",
"/**/*.jsx",
"/**/*.mjs",
"/**/*.cjs",
"/**/*.mts",
"/**/*.cts"
]);
}
chunk3ONWID2V_cjs.__name(findIncludeMatch, "findIncludeMatch");
function isMatchFound(tsconfigType, types) {
return findMatch(tsconfigType, types) !== void 0;
}
chunk3ONWID2V_cjs.__name(isMatchFound, "isMatchFound");
function isIncludeMatchFound(tsconfigType, types) {
return findIncludeMatch(tsconfigType, types) !== void 0;
}
chunk3ONWID2V_cjs.__name(isIncludeMatchFound, "isIncludeMatchFound");
function getParsedTypeScriptConfig(workspaceRoot, projectRoot, tsconfig, tsconfigRaw = {}, host = ts__default.default.sys) {
const tsconfigFilePath = getTsconfigFilePath(projectRoot, tsconfig);
const tsconfigJson = json.readJsonFileSync(tsconfigFilePath);
if (!tsconfigJson) {
throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${path.joinPaths(projectRoot, tsconfig ?? "tsconfig.json")}`);
}
const parsedCommandLine = ts__default.default.parseJsonConfigFileContent(defu__default.default(tsconfigRaw ?? {}, tsconfigJson), host, path.joinPaths(workspaceRoot, projectRoot));
if (parsedCommandLine.errors.length > 0) {
const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:
${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
`;
throw new Error(errorMessage);
}
return {
...parsedCommandLine,
tsconfigJson,
tsconfigFilePath
};
}
chunk3ONWID2V_cjs.__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");
exports.findIncludeMatch = findIncludeMatch;
exports.findMatch = findMatch;
exports.getParsedTypeScriptConfig = getParsedTypeScriptConfig;
exports.getTsconfigFilePath = getTsconfigFilePath;
exports.isIncludeMatchFound = isIncludeMatchFound;
exports.isMatchFound = isMatchFound;
//# sourceMappingURL=chunk-Z72ISLE5.cjs.map
//# sourceMappingURL=chunk-Z72ISLE5.cjs.map