fix(#219): 修改dev命令以支持Windows路径加载器

ESM模块在Windows系统下的路径问题。
This commit is contained in:
feige996
2025-08-31 14:06:56 +08:00
parent 5ad4ab9aa8
commit 159bdb9e90
2 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
// fix: https://github.com/unibest-tech/unibest/issues/219
// Windows path loader for Node.js ESM
// This loader converts Windows absolute paths to file:// URLs
import { pathToFileURL } from 'node:url'
/**
* Resolve hook for ESM loader
* Converts Windows absolute paths to file:// URLs
*/
export function resolve(specifier, context, defaultResolve) {
// Check if this is a Windows absolute path (starts with drive letter like C:)
if (specifier.match(/^[a-z]:\\/i) || specifier.match(/^[a-z]:\//i)) {
// Convert Windows path to file:// URL
const fileUrl = pathToFileURL(specifier).href
return defaultResolve(fileUrl, context, defaultResolve)
}
// For all other specifiers, use the default resolve
return defaultResolve(specifier, context, defaultResolve)
}
/**
* Load hook for ESM loader
*/
export function load(url, context, defaultLoad) {
return defaultLoad(url, context, defaultLoad)
}