fix: babel/core required

This commit is contained in:
zernonia 2023-09-18 23:47:43 +08:00
parent 54e8f520b7
commit 22e46c16f5
3 changed files with 13 additions and 11 deletions

View File

@ -22,7 +22,7 @@
}, },
{ {
"name": "CommandGroup.vue", "name": "CommandGroup.vue",
"content": "<script setup lang=\"ts\">\nimport type { ComboboxGroupProps } from 'radix-vue'\nimport { ComboboxGroup, ComboboxLabel } from 'radix-vue'\nimport { cn } from '@/lib/utils'\n\nconst props = defineProps<ComboboxGroupProps & {\n heading?: string\n}>()\n</script>\n\n<template>\n <ComboboxGroup\n v-bind=\"props\"\n :class=\"cn('overflow-hidden p-1 text-foreground', $attrs.class ?? '')\"\n >\n <ComboboxLabel class=\"px-2 py-1.5 text-xs font-medium text-muted-foreground\">\n {{ heading }}\n </ComboboxLabel>\n <slot />\n </ComboboxGroup>\n</template>\n" "content": "<script setup lang=\"ts\">\nimport type { ComboboxGroupProps } from 'radix-vue'\nimport { ComboboxGroup, ComboboxLabel } from 'radix-vue'\nimport { cn } from '@/lib/utils'\n\nconst props = defineProps<ComboboxGroupProps & {\n heading?: string\n}>()\n</script>\n\n<template>\n <ComboboxGroup\n v-bind=\"props\"\n :class=\"cn('overflow-hidden p-1 text-foreground', $attrs.class ?? '')\"\n >\n <ComboboxLabel v-if=\"heading\" class=\"px-2 py-1.5 text-xs font-medium text-muted-foreground\">\n {{ heading }}\n </ComboboxLabel>\n <slot />\n </ComboboxGroup>\n</template>\n"
}, },
{ {
"name": "CommandInput.vue", "name": "CommandInput.vue",

View File

@ -8,7 +8,6 @@ import template from 'lodash.template'
import ora from 'ora' import ora from 'ora'
import prompts from 'prompts' import prompts from 'prompts'
import * as z from 'zod' import * as z from 'zod'
import { transform as transformByDetype } from 'detype'
import * as templates from '../utils/templates' import * as templates from '../utils/templates'
import { import {
getRegistryBaseColor, getRegistryBaseColor,
@ -18,6 +17,7 @@ import {
import { logger } from '../utils/logger' import { logger } from '../utils/logger'
import { handleError } from '../utils/handle-error' import { handleError } from '../utils/handle-error'
import { getPackageManager } from '../utils/get-package-manager' import { getPackageManager } from '../utils/get-package-manager'
import { transformByDetype } from '../utils/transformers/transform-sfc'
import { import {
type Config, type Config,
DEFAULT_COMPONENTS, DEFAULT_COMPONENTS,

View File

@ -1,18 +1,20 @@
import { createRequire } from 'node:module' import { createRequire } from 'node:module'
import { type SourceFile, SyntaxKind } from 'ts-morph'
import { transform as transformByDetype } from 'detype'
import type { Config } from '../get-config'
import { transformImport } from './transform-import'
import type { Transformer } from '@/src/utils/transformers' import type { Transformer } from '@/src/utils/transformers'
// required cause Error: Dynamic require of "@babel/core" is not supported
const require = createRequire(import.meta.url)
const { transform } = require('detype')
export async function transformByDetype(content: string, filename: string) {
return await transform(content, filename, {
removeTsComments: true,
})
}
export const transformSFC: Transformer<string> = async ({ sourceFile, config }) => { export const transformSFC: Transformer<string> = async ({ sourceFile, config }) => {
const output = sourceFile?.getFullText() const output = sourceFile?.getFullText()
if (config?.typescript) if (config?.typescript)
return output return output
const clean = await transformByDetype(output, 'app.vue', { return await transformByDetype(output, 'app.vue')
removeTsComments: true,
})
return clean
} }