Skip to content
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
4 changes: 2 additions & 2 deletions src/system/FileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions tests/FileLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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 () => {
Expand Down
Loading