-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel:setup-env-production.js
56 lines (50 loc) · 1.39 KB
/
babel:setup-env-production.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
import update from '../lib/update.js';
import {
includes,
replaceOrInsert,
pluginUnassert,
pluginRemoveDebug,
format,
} from '../lib/babel.js';
export const description = 'Setup production 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?.production;
assert(env !== undefined);
assert(env.plugins !== undefined);
assert(includes(env.plugins, pluginUnassert));
assert(includes(env.plugins, pluginRemoveDebug));
}
export async function precondition({readPkg, assert}) {
const pkgjson = await readPkg();
const env = pkgjson.babel?.env?.production;
assert(
!includes(env?.plugins, pluginUnassert) ||
!includes(env?.plugins, pluginRemoveDebug),
);
}
export async function apply({readPkg, writePkg, fixConfig}) {
await update({
read: readPkg,
write: writePkg,
edit: (pkgjson) => {
const env = pkgjson.babel.env.production;
env.plugins = replaceOrInsert(env.plugins, pluginUnassert);
env.plugins = replaceOrInsert(env.plugins, pluginRemoveDebug);
return format(pkgjson);
},
});
await fixConfig();
}
export const dependencies = [
'config:lint-setup',
'babel:setup-presets',
'deps:add-babel-plugin-unassert',
'deps:add-babel-plugin-transform-remove-console',
'package.json:ensure-babel-env-production',
];