Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: windows paths handling #6

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fifty-roses-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"hot-hook": patch
---

`--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.

9 changes: 7 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ jobs:
run: pnpm typecheck

tests:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 10

steps:
Expand All @@ -72,4 +75,6 @@ jobs:
pnpm -r build

- name: Run tests
run: FORCE_COLOR=1 pnpm test
env:
FORCE_COLOR: 1
run: pnpm test
1 change: 1 addition & 0 deletions packages/hot_hook/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class HotHookLoader {
*/
const isReloadable = this.#dependencyTree.isReloadable(realFilePath)
if (!isReloadable) {
debug('Full reload %s', realFilePath)
return this.#messagePort?.postMessage({ type: 'hot-hook:full-reload', path: realFilePath })
}

Expand Down
24 changes: 12 additions & 12 deletions packages/hot_hook/src/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ import { resolve } from 'node:path'
import picomatch from 'picomatch'

export class Matcher {
#rootDirectory: string
#matcher: picomatch.Matcher

constructor(rootDirectory: string, patterns: picomatch.Glob = []) {
this.#rootDirectory = rootDirectory

patterns = Array.isArray(patterns) ? patterns : [patterns]

const absolutePatterns = patterns
.map((pattern) => {
if (pattern.startsWith('../')) return resolve(rootDirectory, pattern)
return pattern
/**
* Do not resolve double star patterns because they are not relative to the root
*/
if (pattern.startsWith('**')) return pattern

/**
* Resolve the pattern to the root directory. All patterns are relative to the root
*/
return resolve(rootDirectory, pattern)
})
.map((path) => path.replace(/\\/g, '/'))

this.#matcher = picomatch(absolutePatterns || [], { dot: true })
this.#matcher = picomatch(absolutePatterns || [], { dot: true, posixSlashes: true })
}

/**
* Check if a path matches the patterns
*/
match(filePath: string) {
filePath = filePath.replace(/\\/g, '/')
if (filePath.startsWith(this.#rootDirectory)) {
filePath = filePath.slice(this.#rootDirectory.length).replace(/^\//, '')
}

return this.#matcher(filePath)
return this.#matcher(resolve(filePath))
}
}
Loading