/
options.ts
63 lines (58 loc) · 1.66 KB
/
options.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
52
53
54
55
56
57
58
59
60
61
62
63
import { InputOptions, NormalizedInputOptions, WarningHandler } from '../../rollup/types';
export interface GenericConfigObject {
[key: string]: unknown;
}
export const defaultOnWarn: WarningHandler = warning => console.warn(warning.message || warning);
export function warnUnknownOptions(
passedOptions: GenericConfigObject,
validOptions: string[],
optionType: string,
warn: WarningHandler,
ignoredKeys = /$./
): void {
const validOptionSet = new Set(validOptions);
const unknownOptions = Object.keys(passedOptions).filter(
key => !(validOptionSet.has(key) || ignoredKeys.test(key))
);
if (unknownOptions.length > 0) {
warn({
code: 'UNKNOWN_OPTION',
message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${[
...validOptionSet
]
.sort()
.join(', ')}`
});
}
}
type ObjectValue<Base> = Base extends Record<string, any> ? Base : never;
export const treeshakePresets: {
[key in NonNullable<
ObjectValue<InputOptions['treeshake']>['preset']
>]: NormalizedInputOptions['treeshake'];
} = {
recommended: {
annotations: true,
correctVarValueBeforeDeclaration: false,
moduleSideEffects: () => true,
propertyReadSideEffects: true,
tryCatchDeoptimization: true,
unknownGlobalSideEffects: false
},
safest: {
annotations: true,
correctVarValueBeforeDeclaration: true,
moduleSideEffects: () => true,
propertyReadSideEffects: true,
tryCatchDeoptimization: true,
unknownGlobalSideEffects: true
},
smallest: {
annotations: true,
correctVarValueBeforeDeclaration: false,
moduleSideEffects: () => false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
unknownGlobalSideEffects: false
}
};