-
Notifications
You must be signed in to change notification settings - Fork 0
/
zenload.js
44 lines (33 loc) · 933 Bytes
/
zenload.js
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
32
33
34
35
36
37
38
39
40
41
42
43
import {getLoaders} from './get-loaders.js';
import {readConfig} from './read-config.js';
const cutShebang = (a) => a.replace('#!/usr/bin/env node', '');
const list = await readConfig();
const loaders = await getLoaders(list);
const returns = (a) => () => a;
export function globalPreload({port}) {
for (const loader of loaders) {
loader.globalPreload?.({port});
}
}
async function run(url, format, source) {
source = cutShebang(String(source));
const options = {
format,
};
for (const loader of loaders)
({source} = await loader.load(url, options, returns({
source,
format,
})));
return {
format,
source,
};
}
export const load = async (url, context, defaultLoad) => {
const {
format,
source,
} = await defaultLoad(url, context);
return await run(url, format, source);
};