UNPKG

tsd

Version:

Check TypeScript type definitions

37 lines (36 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const typescript_1 = require("@tsd/typescript"); /** * Load the configuration settings. * * @param pkg - The package.json object. * @returns The config object. */ exports.default = (pkg, cwd) => { var _a, _b, _c; const pkgConfig = (_a = pkg.tsd) !== null && _a !== void 0 ? _a : {}; const tsConfigCompilerOptions = getOptionsFromTsConfig(cwd); const packageJsonCompilerOptions = parseCompilerConfigObject((_b = pkgConfig.compilerOptions) !== null && _b !== void 0 ? _b : {}, cwd); const combinedCompilerOptions = Object.assign(Object.assign({}, tsConfigCompilerOptions), packageJsonCompilerOptions); const module = (_c = combinedCompilerOptions.module) !== null && _c !== void 0 ? _c : typescript_1.ModuleKind.CommonJS; return Object.assign(Object.assign({ directory: 'test-d' }, pkgConfig), { compilerOptions: Object.assign(Object.assign({ strict: true, jsx: typescript_1.JsxEmit.React, lib: parseRawLibs(['es2020', 'dom', 'dom.iterable'], cwd), module, target: typescript_1.ScriptTarget.ES2020, esModuleInterop: true, noUnusedLocals: false }, combinedCompilerOptions), { moduleResolution: module === typescript_1.ModuleKind.NodeNext ? typescript_1.ModuleResolutionKind.NodeNext : module === typescript_1.ModuleKind.Node16 ? typescript_1.ModuleResolutionKind.Node16 : typescript_1.ModuleResolutionKind.NodeJs, skipLibCheck: false }) }); }; function getOptionsFromTsConfig(cwd) { const configPath = (0, typescript_1.findConfigFile)(cwd, typescript_1.sys.fileExists); if (!configPath) { return {}; } return (0, typescript_1.parseJsonSourceFileConfigFileContent)((0, typescript_1.readJsonConfigFile)(configPath, typescript_1.sys.readFile), typescript_1.sys, cwd, undefined, configPath).options; } function parseCompilerConfigObject(compilerOptions, cwd) { return (0, typescript_1.parseJsonConfigFileContent)({ compilerOptions: compilerOptions || {} }, typescript_1.sys, cwd).options; } function parseRawLibs(libs, cwd) { var _a; return (_a = parseCompilerConfigObject({ lib: libs }, cwd).lib) !== null && _a !== void 0 ? _a : []; }