Skip to content

Commit

Permalink
fix: improve fine types path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Aug 17, 2023
1 parent a7df7fd commit f1ac4d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/plugin.ts
Expand Up @@ -21,6 +21,7 @@ import {
import {
ensureAbsolute,
ensureArray,
fileTypesPath,
isNativeObj,
isRegExp,
normalizePath,
Expand Down Expand Up @@ -538,12 +539,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
} catch (e) {}

const entryNames = Object.keys(entries)
const types =
pkg.types ||
pkg.typings ||
pkg.publishConfig?.types ||
pkg.publishConfig?.typings ||
(pkg.exports?.['.'] || pkg.exports?.['./'])?.types
const types = fileTypesPath(pkg.publishConfig, pkg)
const multiple = entryNames.length > 1

let typesPath = types ? resolve(root, types) : resolve(outDir, indexName)
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Expand Up @@ -322,3 +322,15 @@ export function toCapitalCase<T extends string>(value: T) {
''
) as CapitalCase<T>
}

export function fileTypesPath(...pkgs: Record<any, any>[]) {
let path: string

for (const pkg of pkgs) {
if (typeof pkg !== 'object') continue

path = pkg.types || pkg.typings || pkg.exports?.['.']?.types || pkg.exports?.['./']?.types

if (path) return path
}
}

0 comments on commit f1ac4d6

Please sign in to comment.