Skip to content

Commit 2dd7a39

Browse files
authored
Merge pull request #8 from cdsiats/main
added file loader fix for invalid protocol error on windows, updated tests for FileLoader 1h
2 parents 765fc32 + cb762b6 commit 2dd7a39

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/system/FileLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'node:path';
33
//common
44
import type { FileSystem } from '../types.js';
55
import Exception from '../Exception.js';
6+
import { pathToFileURL } from 'node:url';
67

78
/**
89
* Loader
@@ -159,8 +160,7 @@ export default class FileLoader {
159160
} catch(e) {}
160161
return {} as T;
161162
}
162-
163-
const imports = await import(absolute);
163+
const imports = await import(pathToFileURL(absolute).href);
164164
if (getDefault) {
165165
return imports.default as T;
166166
}

tests/FileLoader.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { expect } from 'chai';
66
import FileLoader from '../src/system/FileLoader';
77
import NodeFS from '../src/system/NodeFS';
88

9+
function normalize(path: string) {
10+
return path.replaceAll('\\', '/').replace(/^[A-Za-z]:/, '');
11+
}
12+
913
describe('FileLoader Tests', () => {
1014
it('Instantiate File Loader', () => {
1115
const fs = new NodeFS();
@@ -29,11 +33,11 @@ describe('FileLoader Tests', () => {
2933
const expected2 = path.join(import.meta.dirname, 'foo/bar.ts');
3034
expect(actual2).to.equal(expected2);
3135

32-
const actual3 = await loader.absolute('/foo/bar');
36+
const actual3 = normalize(await loader.absolute('/foo/bar'));
3337
const expected3 = '/foo/bar';
3438
expect(actual3).to.equal(expected3);
3539

36-
const actual4 = await loader.absolute('/foo/bar.ts');
40+
const actual4 = normalize(await loader.absolute('/foo/bar.ts'));
3741
const expected4 = '/foo/bar.ts';
3842
expect(actual4).to.equal(expected4);
3943

@@ -79,7 +83,8 @@ describe('FileLoader Tests', () => {
7983
const loader = new FileLoader(fs, import.meta.dirname);
8084

8185
const actual = loader.relative('/foo/bar/zoo.js', '/foo/zoo/bar.js', true);
82-
expect(actual).to.equal('../zoo/bar.js')
86+
const normalized = normalize(actual);
87+
expect(normalized).to.equal('../zoo/bar.js')
8388
});
8489

8590
it('Should get resolve file/folder', async () => {

0 commit comments

Comments
 (0)