-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel:setup-env-cover.js
66 lines (59 loc) · 1.69 KB
/
babel:setup-env-cover.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import update from '../lib/update.js';
import {
includes,
replaceOrInsert,
presetCurrentNode,
presetPowerAssert,
pluginRemoveDebug,
format,
} from '../lib/babel.js';
export const description = 'Setup cover environment.';
export const commit = {
type: 'config',
scope: 'babel',
subject: description,
};
const sourceMaps = 'both';
export async function postcondition({readPkg, assert}) {
const pkgjson = await readPkg();
const env = pkgjson.babel?.env?.cover;
assert(env !== undefined);
assert(env.sourceMaps === sourceMaps);
assert(env.presets !== undefined);
assert(env.plugins !== undefined);
assert(includes(env.presets, presetCurrentNode));
assert(includes(env.presets, presetPowerAssert));
assert(includes(env.plugins, pluginRemoveDebug));
}
export async function precondition({readPkg, assert}) {
const pkgjson = await readPkg();
const env = pkgjson.babel?.env?.cover;
assert(
env?.sourceMaps !== sourceMaps ||
!includes(env?.presets, presetCurrentNode) ||
!includes(env?.presets, presetPowerAssert) ||
!includes(env?.plugins, pluginRemoveDebug),
);
}
export async function apply({readPkg, writePkg, fixConfig}) {
await update({
read: readPkg,
write: writePkg,
edit(pkgjson) {
const env = pkgjson.babel.env.cover;
env.sourceMaps = sourceMaps;
replaceOrInsert(env, 'presets', presetCurrentNode);
replaceOrInsert(env, 'presets', presetPowerAssert);
replaceOrInsert(env, 'plugins', pluginRemoveDebug);
return format(pkgjson);
},
});
await fixConfig();
}
export const dependencies = [
'config:lint-setup',
'babel:setup-presets',
'deps:add-babel-preset-power-assert',
'deps:add-babel-plugin-transform-remove-console',
'package.json:ensure-babel-env-cover',
];