UNPKG

@bleed-believer/path-alias

Version:
63 lines (62 loc) 1.98 kB
import { dirname, resolve } from "path"; import micromatch from "micromatch"; const cache = new Map(); export function toSWCConfig(tsConfigBase) { if (cache.has(tsConfigBase)) { return cache.get(tsConfigBase); } const options = {}; const { path, config } = tsConfigBase; const { emitDecoratorMetadata, experimentalDecorators, removeComments, module, target, sourceMap, sourceRoot, jsx, inlineSourceMap, baseUrl, paths } = config.compilerOptions ?? {}; options.cwd = dirname(path); options.sourceRoot = sourceRoot; options.sourceMaps = inlineSourceMap ? 'inline' : sourceMap; options.exclude = config.exclude?.map((x)=>micromatch.makeRe(x).source); options.jsc = { target: target?.toLowerCase() ?? 'es2022', parser: { syntax: 'typescript', decorators: experimentalDecorators, tsx: !!jsx }, transform: { decoratorMetadata: emitDecoratorMetadata }, preserveAllComments: !removeComments, baseUrl: resolve(dirname(path), baseUrl ?? '.'), paths }; switch(module){ case 'umd': case 'none': case 'system': case 'commonjs': { options.isModule = false; break; } case 'nodenext': { options.isModule = true; options.module = { strict: true, strictMode: true, type: 'nodenext', resolveFully: true }; break; } default: { options.isModule = true; options.module = { strict: true, strictMode: true, type: 'es6', resolveFully: true }; } } cache.set(tsConfigBase, options); return options; }