Skip to content

Commit

Permalink
fix: incorrect lib path process when rollup types
Browse files Browse the repository at this point in the history
fix #232
  • Loading branch information
qmhc committed Jul 3, 2023
1 parent dab70c6 commit 292b8b7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
12 changes: 11 additions & 1 deletion examples/ts/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends FnMap> {
public emit<K extends keyof T>(...values: Parameters<T[K]>) {
console.log(values)
}
}
2 changes: 1 addition & 1 deletion examples/ts/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig({
exclude: ['src/ignore'],
// aliasesExclude: [/^@components/],
staticImport: true,
// rollupTypes: true,
rollupTypes: true,
insertTypesEntry: true
})
]
Expand Down
5 changes: 4 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -523,6 +524,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

rollupDeclarationFiles({
root,
configPath,
compilerOptions: rawCompilerOptions,
outDir,
entryPath: path,
Expand All @@ -537,6 +539,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
} else {
rollupDeclarationFiles({
root,
configPath,
compilerOptions: rawCompilerOptions,
outDir,
entryPath: typesPath,
Expand Down
6 changes: 4 additions & 2 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type ts from 'typescript'

export interface BundleOptions {
root: string,
configPath?: string,
compilerOptions: ts.CompilerOptions,
outDir: string,
entryPath: string,
Expand All @@ -26,6 +27,7 @@ const dtsRE = /\.d\.tsx?$/

export function rollupDeclarationFiles({
root,
configPath,
compilerOptions,
outDir,
entryPath,
Expand All @@ -47,7 +49,7 @@ export function rollupDeclarationFiles({
mainEntryPointFilePath: entryPath,
bundledPackages,
compiler: {
// tsconfigFilePath: tsConfigPath,
tsconfigFilePath: configPath,
overrideTsconfig: {
$schema: 'http://json.schemastore.org/tsconfig',
compilerOptions: {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 292b8b7

Please sign in to comment.