Skip to content

Commit e9e15c1

Browse files
BinTossjoshbolduc
andauthored
fix(loadLibrary): prefix all module paths with file:/// before dynamically importing them (#792)
Fixes #744, but opens the path to previously inaccessible bugs e.g. ``` RangeError: Found rules without implementation: extends. Supported rules are: body-case, body-empty, body-full-stop, body-leading-blank, body-max-length, body-max-line-length, body-min-length, footer-empty, footer-leading-blank, footer-max-length, footer-max-line-length, footer-min-length, header-case, header-full-stop, header-max-length, header-min-length, header-trim, references-empty, scope-case, scope-empty, scope-enum, scope-max-length, scope-min-length, signed-off-by, subject-case, subject-empty, subject-full-stop, subject-max-length, subject-min-length, subject-exclamation-mark, trailer-exists, type-case, type-empty, type-enum, type-max-length, type-min-length. at lint (file:///c:/Repos/HaloSPV3/hce.shared-config/node_modules/@commitlint/lint/lib/lint.js:48:15) at async lint (c:\Repos\BinToss\joshbulduc.vscode-commitlint\dist\worker\index.js:213:22) at async handleAsync (c:\Repos\BinToss\joshbulduc.vscode-commitlint\dist\worker\index.js:238:22) ``` --------- Co-authored-by: Josh Bolduc <[email protected]>
1 parent b8da063 commit e9e15c1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/worker/loadLibrary.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve } from 'path';
2+
import { pathToFileURL } from 'url';
23
import { describe, expect, it } from 'vitest';
34
import { testLibRootPath } from '../../test/util';
45
import { loadLibrary, tryLoadDynamicLibrary } from './loadLibrary';
@@ -22,15 +23,17 @@ describe('loadLibrary', () => {
2223

2324
expect(rest).toEqual({
2425
fallback: false,
25-
path: resolve(
26-
testLibRootPath,
27-
'v11',
28-
'node_modules',
29-
'@commitlint',
30-
'load',
31-
'lib',
32-
'load.js',
33-
),
26+
path: pathToFileURL(
27+
resolve(
28+
testLibRootPath,
29+
'v11',
30+
'node_modules',
31+
'@commitlint',
32+
'load',
33+
'lib',
34+
'load.js',
35+
),
36+
).href,
3437
});
3538

3639
expect(await result).toMatchObject(expect.any(Function));

src/worker/loadLibrary.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve } from 'path';
2+
import { pathToFileURL } from 'url';
23
import type { IpcRequestContext } from '../ipcTypes';
34
import { getPrefixForLibraryLoad } from './utils/getPrefixForLibraryLoad';
45
import { getSystemGlobalLibraryPath } from './utils/getSystemGlobalLibraryPath';
@@ -54,10 +55,13 @@ export const tryLoadDynamicLibrary = <T>(
5455
],
5556
});
5657

57-
log(`loading ${name} dynamically via ${resolvePath}`);
58+
// Ensure the path is importable, e.g., on Windows
59+
const pathHref = pathToFileURL(resolvePath).href;
60+
61+
log(`loading ${name} dynamically via ${pathHref}`);
5862
return {
59-
result: importDefaultExport<T>(resolvePath),
60-
path: resolvePath,
63+
result: importDefaultExport<T>(pathHref),
64+
path: pathHref,
6165
fallback: false,
6266
};
6367
} catch (e) {

0 commit comments

Comments
 (0)