UNPKG

@swc-node/register

Version:
41 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readDefaultTsConfig = void 0; const tslib_1 = require("tslib"); const fs_1 = require("fs"); const path_1 = require("path"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const debug_1 = tslib_1.__importDefault(require("debug")); const ts = tslib_1.__importStar(require("typescript")); const debug = debug_1.default('@swc-node'); function readDefaultTsConfig() { var _a, _b; const tsConfigPath = (_b = (_a = process.env.SWC_NODE_PROJECT) !== null && _a !== void 0 ? _a : process.env.TS_NODE_PROJECT) !== null && _b !== void 0 ? _b : path_1.join(process.cwd(), 'tsconfig.json'); let compilerOptions = { target: ts.ScriptTarget.ES2018, module: ts.ModuleKind.CommonJS, moduleResolution: ts.ModuleResolutionKind.NodeJs, sourceMap: true, esModuleInterop: true, }; if (tsConfigPath && fs_1.existsSync(tsConfigPath)) { try { debug(`Read config file from ${tsConfigPath}`); const { config } = ts.readConfigFile(tsConfigPath, ts.sys.readFile); const { options, errors, fileNames } = ts.parseJsonConfigFileContent(config, ts.sys, path_1.parse(tsConfigPath).dir); if (!errors.length) { compilerOptions = options; compilerOptions.files = fileNames; } else { console.info(chalk_1.default.yellow(`Convert compiler options from json failed, ${errors.map((d) => d.messageText).join('\n')}`)); } } catch (e) { console.info(chalk_1.default.yellow(`Read ${tsConfigPath} failed: ${e.message}`)); } } return compilerOptions; } exports.readDefaultTsConfig = readDefaultTsConfig; //# sourceMappingURL=read-default-tsconfig.js.map