-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbabel:setup-env-sort-keys.js
58 lines (49 loc) · 1.25 KB
/
babel:setup-env-sort-keys.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
import update from '../lib/update.js';
export const description = 'Sort environments keys.';
export const commit = {
type: 'config',
scope: 'babel',
subject: description,
};
const expected = ['debug', 'test', 'development', 'production'];
export async function postcondition({readPkg, assert}) {
const pkgjson = await readPkg();
assert.deepStrictEqual(
Object.keys(pkgjson.babel.env).slice(0, expected.length),
expected,
);
}
export async function precondition({readPkg, assert}) {
const pkgjson = await readPkg();
assert.notDeepStrictEqual(
Object.keys(pkgjson.babel.env).slice(0, expected.length),
expected,
);
}
export async function apply({readPkg, writePkg, fixConfig}) {
await update({
read: readPkg,
write: writePkg,
edit: (pkgjson) => {
const babel = pkgjson.babel;
const env = babel.env;
// SORT BABEL.ENV KEYS
babel.env = {
debug: env.debug,
test: env.test,
development: env.development,
production: env.production,
...env,
};
return pkgjson;
},
});
await fixConfig();
}
export const dependencies = [
'config:lint-setup',
'package.json:ensure-babel-env-test',
'package.json:ensure-babel-env-debug',
'package.json:ensure-babel-env-development',
'package.json:ensure-babel-env-production',
];