From a1d94885cff7f958c782a830b3822939f3ad389d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20SHA=C3=8FTA?= Date: Wed, 3 Apr 2024 22:36:00 +0200 Subject: [PATCH] fix(loader): ensuring a cross-platform path (#3) --- packages/hot_hook/src/loader.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/hot_hook/src/loader.ts b/packages/hot_hook/src/loader.ts index 2f7c220..070a31c 100644 --- a/packages/hot_hook/src/loader.ts +++ b/packages/hot_hook/src/loader.ts @@ -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' @@ -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