From bfca8b1ab77654774a73dd7e800bf98f0a041afb Mon Sep 17 00:00:00 2001 From: vilicvane Date: Tue, 9 May 2023 23:15:47 +0800 Subject: [PATCH] Parse defaultCompilerOptions provided to cli --- packages/twoslash-cli/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/twoslash-cli/index.js b/packages/twoslash-cli/index.js index 0cd3515..2637bd6 100644 --- a/packages/twoslash-cli/index.js +++ b/packages/twoslash-cli/index.js @@ -15,6 +15,7 @@ import { join, dirname } from "path" import remarkShikiTwoslash from "remark-shiki-twoslash" import { basename, extname, sep } from "path" import { tmpdir } from "os" +import ts from "typescript" export const canConvert = (path) => { const usable = [".md", ".ts", ".js", ".tsx", ".jsx"] @@ -90,6 +91,18 @@ async function renderMarkdown(args) { const settings = getSettingsFromMarkdown(fileContent, from) || {} const markdownAST = remark().parse(fileContent) + if (settings.defaultCompilerOptions) { + const {options} = ts.convertCompilerOptionsFromJson(settings.defaultCompilerOptions, ".") + settings.defaultCompilerOptions = { + ...settings.defaultCompilerOptions, + ...Object.fromEntries( + Object + .entries(options) + .flatMap(([key, value]) => value === undefined ? [] : [[key, value]]) + ), + } + } + try { // @ts-ignore await remarkShikiTwoslash.default(settings)(markdownAST)