From e3d0885845505c30be1cef7dbacf818b7d445416 Mon Sep 17 00:00:00 2001 From: wanghaitao <15124505701@163.com> Date: Wed, 25 May 2022 02:28:41 +0800 Subject: [PATCH] fix: windows path (#182) Co-authored-by: Anthony Fu --- src/core/ctx.ts | 4 ++-- test/dts.test.ts | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/ctx.ts b/src/core/ctx.ts index 2fdb2c5..5934ab2 100644 --- a/src/core/ctx.ts +++ b/src/core/ctx.ts @@ -1,4 +1,4 @@ -import { dirname, relative, resolve } from 'path' +import { dirname, isAbsolute, relative, resolve } from 'path' import { promises as fs } from 'fs' import { slash, throttle, toArray } from '@antfu/utils' import { createFilter } from '@rollup/pluginutils' @@ -63,7 +63,7 @@ export function createContext(options: Options = {}, root = process.cwd()) { const dir = dirname(file) return unimport.generateTypeDecarations({ resolvePath: (i) => { - if (i.from.startsWith('.') || i.from.startsWith('/')) { + if (i.from.startsWith('.') || isAbsolute(i.from)) { const related = slash(relative(dir, i.from).replace(/\.ts$/, '')) return !related.startsWith('.') ? `./${related}` diff --git a/test/dts.test.ts b/test/dts.test.ts index 83b3ab6..9959eab 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -1,10 +1,7 @@ import { join } from 'path' import { createContext } from '../src/core/ctx' -const isWindows = process.platform === 'win32' - -// TODO: fix windows -it.skipIf(isWindows)('dts', () => { +it('dts', () => { const cwd = process.cwd() const ctx = createContext({ imports: [