Skip to content

Commit

Permalink
fix: ignore namespace from declaration collect
Browse files Browse the repository at this point in the history
fix #352
  • Loading branch information
qmhc committed Jul 24, 2024
1 parent 8eb6c17 commit b9c3947
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions examples/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ export default data

export type { User as MyUser } from './types'
export type { AliasType } from '@alias/type'

export type * from './namespace'
export type * from './modules'
5 changes: 5 additions & 0 deletions examples/ts/src/modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'tslib' {
export type Test = { newField: string }
}

export {}
10 changes: 10 additions & 0 deletions examples/ts/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace NameSpace {
export const namespace = 'namespace'
export const enum NamespaceEnum {
A,
B,
C,
D
}
}
4 changes: 1 addition & 3 deletions examples/ts/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import dts from '../../src'
emptyDir(resolve(__dirname, 'dist'))
emptyDir(resolve(__dirname, 'types'))

console.log('a')

export default defineConfig({
resolve: {
alias: {
Expand All @@ -29,7 +27,7 @@ export default defineConfig({
// aliasesExclude: [/^@components/],
staticImport: true,
// insertTypesEntry: true,
// rollupTypes: true,
rollupTypes: true,
declarationOnly: true
})
]
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
await runParallel(cpus().length, [...rollupFiles], async filePath => {
await writeOutput(
filePath,
(await readFile(filePath, 'utf-8')) + (declared ? `\n${declared}\n` : ''),
(await readFile(filePath, 'utf-8')) + (declared ? `\n${declared}` : ''),
dirname(filePath)
)
})
Expand Down
2 changes: 2 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export function transformCode(options: {

if (ts.isModuleDeclaration(node)) {
if (
node.modifiers?.[0] &&
node.modifiers[0].kind === ts.SyntaxKind.DeclareKeyword &&
node.body &&
ts.isModuleBlock(node.body) &&
!node.body.statements.some(
Expand Down

0 comments on commit b9c3947

Please sign in to comment.