diff --git a/examples/ts/src/index.ts b/examples/ts/src/index.ts index 7c7e1d9..581a264 100644 --- a/examples/ts/src/index.ts +++ b/examples/ts/src/index.ts @@ -6,9 +6,10 @@ export interface Test extends TestBase { export { testFn } from './comment' export { Decorator } from './decorator' -export { test, method } from './test' export { addOne, add } from '@/js-test.js' export { ESClass } from './es-class' export { manualDts } from './manual-dts' +export { ParametersTest, test, method } from './test' + export type { User } from './types' diff --git a/examples/ts/src/test.ts b/examples/ts/src/test.ts index c292781..d0b9298 100644 --- a/examples/ts/src/test.ts +++ b/examples/ts/src/test.ts @@ -14,9 +14,19 @@ export const test: TestBase = { export const CONSTANT = ['one', 'two'] as const export interface WithConstant { - constant: typeof CONSTANT[number] + constant: (typeof CONSTANT)[number] } export function method(arg: string) { console.log(arg) } + +export interface FnMap { + [key: string]: () => void +} + +export class ParametersTest { + public emit(...values: Parameters) { + console.log(values) + } +} diff --git a/examples/ts/vite.config.ts b/examples/ts/vite.config.ts index 8e9efd2..05eeed2 100644 --- a/examples/ts/vite.config.ts +++ b/examples/ts/vite.config.ts @@ -26,7 +26,7 @@ export default defineConfig({ exclude: ['src/ignore'], // aliasesExclude: [/^@components/], staticImport: true, - // rollupTypes: true, + rollupTypes: true, insertTypesEntry: true }) ] diff --git a/src/plugin.ts b/src/plugin.ts index 3b70422..2271d9f 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -84,6 +84,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { let publicRoot = '' let entryRoot = options.entryRoot ?? '' + let configPath: string | undefined let compilerOptions: ts.CompilerOptions let rawCompilerOptions: ts.CompilerOptions @@ -221,7 +222,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { timeRecord = 0 const startTime = Date.now() - const configPath = tsconfigPath + configPath = tsconfigPath ? ensureAbsolute(tsconfigPath, root) : ts.findConfigFile(root, ts.sys.fileExists) @@ -523,6 +524,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { rollupDeclarationFiles({ root, + configPath, compilerOptions: rawCompilerOptions, outDir, entryPath: path, @@ -537,6 +539,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { } else { rollupDeclarationFiles({ root, + configPath, compilerOptions: rawCompilerOptions, outDir, entryPath: typesPath, diff --git a/src/rollup.ts b/src/rollup.ts index 875a469..b27af43 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -14,6 +14,7 @@ import type ts from 'typescript' export interface BundleOptions { root: string, + configPath?: string, compilerOptions: ts.CompilerOptions, outDir: string, entryPath: string, @@ -26,6 +27,7 @@ const dtsRE = /\.d\.tsx?$/ export function rollupDeclarationFiles({ root, + configPath, compilerOptions, outDir, entryPath, @@ -47,7 +49,7 @@ export function rollupDeclarationFiles({ mainEntryPointFilePath: entryPath, bundledPackages, compiler: { - // tsconfigFilePath: tsConfigPath, + tsconfigFilePath: configPath, overrideTsconfig: { $schema: 'http://json.schemastore.org/tsconfig', compilerOptions: { @@ -90,7 +92,7 @@ export function rollupDeclarationFiles({ const compilerState = CompilerState.create(extractorConfig, { localBuild: false, showVerboseMessages: false, - typescriptCompilerFolder: libFolder ? resolve(libFolder, '..') : undefined + typescriptCompilerFolder: libFolder ? resolve(libFolder) : undefined } as IExtractorInvokeOptions) const sourceMapper = new SourceMapper()