Skip to content

Commit

Permalink
fix: ensure paths are absolute when process public root
Browse files Browse the repository at this point in the history
fix #238
  • Loading branch information
qmhc committed Jul 8, 2023
1 parent 53c58c8 commit 3628877
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/plugin.ts
Expand Up @@ -260,6 +260,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
filter = createFilter(include, exclude, { resolve: root })

const rootNames = Object.values(entries)
.map(entry => ensureAbsolute(entry, root))
.concat(content?.fileNames.filter(filter) || [])
.map(normalizePath)

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

const startTime = Date.now()
const outDir = outDirs[0]
const service = program.__vue.languageService as unknown as ts.LanguageService

rootFiles.delete(id)
Expand All @@ -335,6 +337,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
id,
code,
root: publicRoot,
outDir,
host,
program,
service
Expand All @@ -348,7 +351,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

if (sourceFile) {
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text)
outputFiles.set(resolve(publicRoot, relative(outDir, outputFile.name)), outputFile.text)
}
}
}
Expand Down Expand Up @@ -426,7 +429,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {

if (rootFiles.has(sourceFile.fileName)) {
for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) {
outputFiles.set(resolve(publicRoot, outputFile.name), outputFile.text)
outputFiles.set(resolve(publicRoot, relative(outDir, outputFile.name)), outputFile.text)
}

rootFiles.delete(sourceFile.fileName)
Expand Down
6 changes: 4 additions & 2 deletions src/resolvers/vue.ts
@@ -1,3 +1,5 @@
import { relative } from 'node:path'

import { resolve } from '../utils'

import type { Resolver } from '../types'
Expand All @@ -10,7 +12,7 @@ export function VueResolver(): Resolver {
supports(id) {
return vueRE.test(id)
},
transform({ id, root, program, service }) {
transform({ id, root, outDir, program, service }) {
const sourceFile =
program.getSourceFile(id) ||
program.getSourceFile(id + '.ts') ||
Expand All @@ -22,7 +24,7 @@ export function VueResolver(): Resolver {

return service.getEmitOutput(sourceFile.fileName, true).outputFiles.map(file => {
return {
path: resolve(root, file.name),
path: resolve(root, relative(outDir, file.name)),
content: file.text
}
})
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -21,6 +21,7 @@ export interface Resolver {
id: string,
code: string,
root: string,
outDir: string,
host: ts.CompilerHost,
program: ts.Program,
service: ts.LanguageService
Expand Down

0 comments on commit 3628877

Please sign in to comment.