Skip to content

Commit

Permalink
fix: windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 31, 2022
1 parent 78bd21a commit 1a85e93
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import { createUnplugin } from 'unplugin'
import { createFilter } from '@rollup/pluginutils'
import { createFilter, normalizePath } from '@rollup/pluginutils'
import glob from 'fast-glob'
import { resolveOption } from './core/options'
import { parsePattern } from './core/utils'
Expand All @@ -14,27 +14,29 @@ export default createUnplugin<Options>((options = {}) => {
const map: Record<string, string[]> = {}

const name = 'unplugin-glob'
const ID_PREFIX = 'glob:'
return {
name,

resolveId(id, src) {
if (!src || !filter(src)) return
if (!id.startsWith('glob/')) return
const pattern = id.replace('glob/', '')
return `/glob${src}?pattern=${pattern}`
return `${ID_PREFIX}${src}?pattern=${pattern}`
},

async load(id) {
if (!id.startsWith('/glob')) return
if (!id.startsWith(ID_PREFIX)) return

const { src, pattern } = parsePattern(id.replace('/glob', ''))
const { src, pattern } = parsePattern(id.replace(ID_PREFIX, ''))

const files = (
await glob(pattern, {
cwd: src ? path.dirname(src) : opt.root,
absolute: true,
})
)
.map((file) => normalizePath(file))
.filter((file) => file !== src)
.sort()
map[pattern] = files
Expand Down

0 comments on commit 1a85e93

Please sign in to comment.