Skip to content

Commit 5f6de24

Browse files
authored
fix: windows paths handling (#6)
1 parent 2c6f314 commit 5f6de24

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

.changeset/fifty-roses-heal.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"hot-hook": patch
3+
---
4+
5+
`--import=hot-hook/register` was broken due to a bug in path handling that wasn't cross platform. This has been fixed and also added a Windows CI to prevent this from happening again.
6+

.github/workflows/check.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ jobs:
5050
run: pnpm typecheck
5151

5252
tests:
53-
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
os: [ubuntu-latest, windows-latest]
56+
runs-on: ${{ matrix.os }}
5457
timeout-minutes: 10
5558

5659
steps:
@@ -72,4 +75,6 @@ jobs:
7275
pnpm -r build
7376
7477
- name: Run tests
75-
run: FORCE_COLOR=1 pnpm test
78+
env:
79+
FORCE_COLOR: 1
80+
run: pnpm test

packages/hot_hook/src/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class HotHookLoader {
6363
*/
6464
const isReloadable = this.#dependencyTree.isReloadable(realFilePath)
6565
if (!isReloadable) {
66+
debug('Full reload %s', realFilePath)
6667
return this.#messagePort?.postMessage({ type: 'hot-hook:full-reload', path: realFilePath })
6768
}
6869

packages/hot_hook/src/matcher.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ import { resolve } from 'node:path'
22
import picomatch from 'picomatch'
33

44
export class Matcher {
5-
#rootDirectory: string
65
#matcher: picomatch.Matcher
76

87
constructor(rootDirectory: string, patterns: picomatch.Glob = []) {
9-
this.#rootDirectory = rootDirectory
10-
118
patterns = Array.isArray(patterns) ? patterns : [patterns]
9+
1210
const absolutePatterns = patterns
1311
.map((pattern) => {
14-
if (pattern.startsWith('../')) return resolve(rootDirectory, pattern)
15-
return pattern
12+
/**
13+
* Do not resolve double star patterns because they are not relative to the root
14+
*/
15+
if (pattern.startsWith('**')) return pattern
16+
17+
/**
18+
* Resolve the pattern to the root directory. All patterns are relative to the root
19+
*/
20+
return resolve(rootDirectory, pattern)
1621
})
1722
.map((path) => path.replace(/\\/g, '/'))
1823

19-
this.#matcher = picomatch(absolutePatterns || [], { dot: true })
24+
this.#matcher = picomatch(absolutePatterns || [], { dot: true, posixSlashes: true })
2025
}
2126

2227
/**
2328
* Check if a path matches the patterns
2429
*/
2530
match(filePath: string) {
26-
filePath = filePath.replace(/\\/g, '/')
27-
if (filePath.startsWith(this.#rootDirectory)) {
28-
filePath = filePath.slice(this.#rootDirectory.length).replace(/^\//, '')
29-
}
30-
31-
return this.#matcher(filePath)
31+
return this.#matcher(resolve(filePath))
3232
}
3333
}

0 commit comments

Comments
 (0)