-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun-plugin-replit.js
51 lines (45 loc) · 1.08 KB
/
bun-plugin-replit.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
44
45
46
47
48
49
50
51
/**
* @param {import('bun').OnLoadArgs} args
* @returns {Promise<Object>}
*/
const writeTypes = async (args) => {
const config = Bun.TOML.parse(await Bun.file(`.replit`).text());
const types = `declare module "*.replit" {
const config: ${Bun.inspect(config)};
export default config
}`;
await Bun.write("index.d.ts", types);
return config;
};
/**
* @param {import('bun').OnLoadArgs} args
* @returns {Promise<Object>}
*/
const parseConfig = async (args, createTypes = writeTypes) => {
return {
default: await createTypes(args),
};
};
/**
* @param {import('bun').OnLoadArgs} args
* @returns {Promise<import("bun").OnLoadCallback>}
*/
const resolveConfig = async (/**@type {import('bun').OnLoadArgs} */ args) => {
return {
loader: "object",
exports: await parseConfig(args),
};
};
Bun.build({
entrypoints: ["./.replit"],
plugins: [
{
name: "bun-plugin-replit",
setup(build) {
build.onLoad({ filter: /.replit$/ }, async (build) => {
return await resolveConfig(build);
});
},
},
],
});