-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-loader.mjs
31 lines (26 loc) · 924 Bytes
/
test-loader.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fs from 'node:fs';
import path from 'node:path';
export async function getFormat(resolved, context, defaultGetFormat) {
if (!path.extname(resolved)) {
// https://github.com/nodejs/node/issues/34049
return { format: 'commonjs' };
}
return defaultGetFormat(resolved, context, defaultGetFormat);
}
export async function getSource(urlString, context, defaultGetSource) {
return defaultGetSource(urlString, context, defaultGetSource);
}
export function resolve(specifier, context, defaultResolve) {
return defaultResolve(specifier, context, defaultResolve);
}
export async function load(url, context, defaultLoad) {
const fileUrl = new URL(url);
if (!path.extname(fileUrl.pathname)) {
// https://github.com/nodejs/node/issues/34049
return {
format: 'commonjs',
source: await fs.promises.readFile(fileUrl, `utf8`)
};
}
return defaultLoad(url, context, defaultLoad);
}