/
outputBundle.ts
36 lines (32 loc) · 1.07 KB
/
outputBundle.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
import { OutputAsset, OutputBundle, OutputChunk } from '../rollup/types';
export const lowercaseBundleKeys = Symbol('bundleKeys');
export const FILE_PLACEHOLDER = {
type: 'placeholder' as const
};
export interface OutputBundleWithPlaceholders {
[fileName: string]: OutputAsset | OutputChunk | typeof FILE_PLACEHOLDER;
[lowercaseBundleKeys]: Set<string>;
}
export const getOutputBundle = (outputBundleBase: OutputBundle): OutputBundleWithPlaceholders => {
const reservedLowercaseBundleKeys = new Set<string>();
return new Proxy(outputBundleBase, {
deleteProperty(target, key) {
if (typeof key === 'string') {
reservedLowercaseBundleKeys.delete(key.toLowerCase());
}
return Reflect.deleteProperty(target, key);
},
get(target, key) {
if (key === lowercaseBundleKeys) {
return reservedLowercaseBundleKeys;
}
return Reflect.get(target, key);
},
set(target, key, value) {
if (typeof key === 'string') {
reservedLowercaseBundleKeys.add(key.toLowerCase());
}
return Reflect.set(target, key, value);
}
}) as OutputBundleWithPlaceholders;
};