Skip to content

Commit

Permalink
fix: ensure relative to config path if not specify include/exclude
Browse files Browse the repository at this point in the history
fix #272
  • Loading branch information
qmhc committed Sep 21, 2023
1 parent 19ae5ea commit a7bab4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -222,9 +222,9 @@ export interface PluginOptions {
staticImport?: boolean,

/**
* Override `include` glob
* Override `include` glob (relative to root)
*
* Defaults to `include` property of tsconfig.json
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
*/
include?: string | string[],

Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Expand Up @@ -222,9 +222,9 @@ export interface PluginOptions {
staticImport?: boolean,

/**
* 手动设置包含路径的 glob
* 手动设置包含路径的 glob(相对于 root)
*
* 默认基于 tsconfig.json 的 `include` 选项
* 默认基于 tsconfig.json 的 `include` 选项(相对于 tsconfig.json 所在目录)
*/
include?: string | string[],

Expand Down
22 changes: 17 additions & 5 deletions src/plugin.ts
Expand Up @@ -278,12 +278,24 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
}
}

include = ensureArray(options.include ?? content?.raw.include ?? '**/*').map(normalizeGlob)
exclude = ensureArray(options.exclude ?? content?.raw.exclude ?? 'node_modules/**').map(
normalizeGlob
)
const computeGlobs = (
rootGlobs: string | string[] | undefined,
tsGlobs: string | string[] | undefined,
defaultGlob: string | string[]
) => {
if (rootGlobs?.length) {
return ensureArray(rootGlobs).map(glob => normalizeGlob(ensureAbsolute(glob, root)))
}

return ensureArray(tsGlobs?.length ? tsGlobs : defaultGlob).map(glob =>
normalizeGlob(ensureAbsolute(glob, configPath ? dirname(configPath) : root))
)
}

include = computeGlobs(options.include, content?.raw.include, '**/*')
exclude = computeGlobs(options.exclude, content?.raw.exclude, 'node_modules/**')

filter = createFilter(include, exclude, { resolve: root })
filter = createFilter(include, exclude)

const rootNames = Object.values(entries)
.map(entry => ensureAbsolute(entry, root))
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Expand Up @@ -128,9 +128,9 @@ export interface PluginOptions {
staticImport?: boolean,

/**
* Override `include` glob
* Override `include` glob (relative to root)
*
* Defaults to `include` property of tsconfig.json
* Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
*/
include?: string | string[],

Expand Down

0 comments on commit a7bab4d

Please sign in to comment.