Skip to content

Commit

Permalink
fix(loader): ensuring a cross-platform path (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkerone authored Apr 3, 2024
1 parent 820320d commit a1d9488
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/hot_hook/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chokidar from 'chokidar'
import picomatch from 'picomatch'
import { realpath } from 'node:fs/promises'
import { MessagePort } from 'node:worker_threads'
import { fileURLToPath } from 'node:url'
import { resolve as pathResolve, dirname } from 'node:path'
import type { InitializeHook, LoadHook, ResolveHook } from 'node:module'

Expand Down Expand Up @@ -140,14 +141,16 @@ export class HotHookLoader {

const result = await nextResolve(specifier, context)
const resultUrl = new URL(result.url)
const resultPath = resultUrl.pathname
if (resultUrl.protocol !== 'file:') {
return result
}

const resultPath = fileURLToPath(resultUrl)
const parentPath = fileURLToPath(parentUrl)

const reloadable = context.importAttributes.hot === 'true' ? true : false
this.#dependencyTree.addDependency(parentUrl?.pathname, { path: resultPath, reloadable })
this.#dependencyTree.addDependent(resultPath, parentUrl?.pathname)
this.#dependencyTree.addDependency(parentPath, { path: resultPath, reloadable })
this.#dependencyTree.addDependent(resultPath, parentPath)

if (this.#pathIgnoredMatcher.match(resultPath)) {
return result
Expand Down

0 comments on commit a1d9488

Please sign in to comment.