1
- import { dirname , isAbsolute , posix , relative , resolve } from 'path'
1
+ import { dirname , isAbsolute , posix , relative , resolve , sep } from 'path'
2
2
import { promises as fs } from 'fs'
3
3
import { slash , throttle , toArray } from '@antfu/utils'
4
4
import { createFilter } from '@rollup/pluginutils'
@@ -30,7 +30,7 @@ export function createContext(options: Options = {}, root = process.cwd()) {
30
30
31
31
const cachePath = isCache === false
32
32
? false
33
- : resolve ( root , typeof isCache === 'string' ? 'string' : 'node_modules/.cache/unplugin-auto-import.json' )
33
+ : resolve ( root , typeof isCache === 'string' ? isCache : 'node_modules/.cache/unplugin-auto-import.json' )
34
34
35
35
const unimport = createUnimport ( {
36
36
imports : [ ] ,
@@ -159,7 +159,8 @@ ${dts}`.trim()}\n`
159
159
const cacheData = await getCacheData ( cachePath )
160
160
await Promise . allSettled ( Object . keys ( cacheData ) . map ( async ( filePath ) => {
161
161
try {
162
- await fs . access ( posix . resolve ( root , filePath ) )
162
+ const normalizeRoot = root . replaceAll ( sep , posix . sep )
163
+ await fs . access ( posix . join ( normalizeRoot , filePath ) )
163
164
}
164
165
catch {
165
166
Reflect . deleteProperty ( cacheData , filePath )
@@ -184,7 +185,7 @@ ${dts}`.trim()}\n`
184
185
const cacheData = await getCacheData ( cachePath )
185
186
186
187
if ( id && importList ) {
187
- const filePath = posix . normalize ( relative ( root , id ) )
188
+ const filePath = posix . normalize ( posix . relative ( root , id ) )
188
189
importList = importList . filter ( i => ( i . name ?? i . as ) && i . name !== 'default' )
189
190
if ( importList . length )
190
191
cacheData [ filePath ] = importList
0 commit comments