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