diff --git a/src/system/FileLoader.ts b/src/system/FileLoader.ts index ebb4e47..6cd1144 100644 --- a/src/system/FileLoader.ts +++ b/src/system/FileLoader.ts @@ -3,6 +3,7 @@ import * as path from 'node:path'; //common import type { FileSystem } from '../types.js'; import Exception from '../Exception.js'; +import { pathToFileURL } from 'node:url'; /** * Loader @@ -159,8 +160,7 @@ export default class FileLoader { } catch(e) {} return {} as T; } - - const imports = await import(absolute); + const imports = await import(pathToFileURL(absolute).href); if (getDefault) { return imports.default as T; } diff --git a/tests/FileLoader.test.ts b/tests/FileLoader.test.ts index a1eeafc..424582b 100644 --- a/tests/FileLoader.test.ts +++ b/tests/FileLoader.test.ts @@ -6,6 +6,10 @@ import { expect } from 'chai'; import FileLoader from '../src/system/FileLoader'; import NodeFS from '../src/system/NodeFS'; +function normalize(path: string) { + return path.replaceAll('\\', '/').replace(/^[A-Za-z]:/, ''); +} + describe('FileLoader Tests', () => { it('Instantiate File Loader', () => { const fs = new NodeFS(); @@ -29,11 +33,11 @@ describe('FileLoader Tests', () => { const expected2 = path.join(import.meta.dirname, 'foo/bar.ts'); expect(actual2).to.equal(expected2); - const actual3 = await loader.absolute('/foo/bar'); + const actual3 = normalize(await loader.absolute('/foo/bar')); const expected3 = '/foo/bar'; expect(actual3).to.equal(expected3); - const actual4 = await loader.absolute('/foo/bar.ts'); + const actual4 = normalize(await loader.absolute('/foo/bar.ts')); const expected4 = '/foo/bar.ts'; expect(actual4).to.equal(expected4); @@ -79,7 +83,8 @@ describe('FileLoader Tests', () => { const loader = new FileLoader(fs, import.meta.dirname); const actual = loader.relative('/foo/bar/zoo.js', '/foo/zoo/bar.js', true); - expect(actual).to.equal('../zoo/bar.js') + const normalized = normalize(actual); + expect(normalized).to.equal('../zoo/bar.js') }); it('Should get resolve file/folder', async () => {