-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel:setup-presets.js
52 lines (46 loc) · 1.2 KB
/
babel:setup-presets.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
52
import update from '../lib/update.js';
import {
includes,
replaceOrInsert,
presetDefaults,
pluginRemoveDebug,
presetCurrentNode,
format,
} from '../lib/babel.js';
export const description = 'Setup default presets.';
export const commit = {
type: 'config',
scope: 'babel',
subject: description,
};
export async function postcondition({readPkg, assert}) {
const pkgjson = await readPkg();
const env = pkgjson.babel;
assert(env !== undefined);
assert(env.presets !== undefined);
assert(includes(env.presets, presetDefaults));
}
export async function precondition({readPkg, assert}) {
const pkgjson = await readPkg();
const env = pkgjson.babel;
assert(!includes(env?.plugins, pluginRemoveDebug));
assert(!includes(env?.presets, presetCurrentNode));
assert(!includes(env?.presets, presetDefaults));
}
export async function apply({readPkg, writePkg, fixConfig}) {
await update({
read: readPkg,
write: writePkg,
edit: (pkgjson) => {
const env = pkgjson.babel;
env.presets = replaceOrInsert(env.presets, presetDefaults);
return format(pkgjson);
},
});
await fixConfig();
}
export const dependencies = [
'config:lint-setup',
'package.json:ensure-babel',
'deps:add-@babel-preset-env',
];