generated from mishabruml/ts-node-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
additionalEntrypointsGlobPlugin.ts
51 lines (45 loc) · 1.29 KB
/
additionalEntrypointsGlobPlugin.ts
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
import { Plugin } from "esbuild";
import tinyGlob from "tiny-glob";
export const additionalEntrypointsGlobPlugin = ({
additionalEntrypoints,
}: {
additionalEntrypoints: string[];
}) => {
const plugin: Plugin = {
name: "additionalGlobEntrypoints",
async setup(build) {
const initialEntrypoints = build.initialOptions.entryPoints;
if (!Array.isArray(initialEntrypoints)) {
throw new TypeError(
"additionalGlobEntrypoints plugin currently only supports array entrypoints"
);
}
if (
!Array.isArray(additionalEntrypoints) ||
!additionalEntrypoints.every((s) => typeof s === "string")
) {
throw new TypeError(
`additionalEntrypoints must be an array of strings. Recieved ${additionalEntrypoints}`
);
}
console.info(
`Resolving additionalEntrypoints [ ${additionalEntrypoints
.map((s) => `'${s}'`)
.join(",")} ]`
);
const resolvedAdditionalEntrypoints = (
await Promise.all(additionalEntrypoints.map((str) => tinyGlob(str)))
).flat();
console.info(
`Resolved additional files [ ${resolvedAdditionalEntrypoints
.map((s) => `'${s}'`)
.join(",")} ] from additional entrypoints`
);
build.initialOptions.entryPoints = [
...initialEntrypoints,
...resolvedAdditionalEntrypoints,
];
},
};
return plugin;
};