-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
107 lines (100 loc) · 3.5 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const helperUtils = require('@babel/helper-plugin-utils');
const declare = helperUtils.declare;
const pkg = require('./package.json');
const defaultTargets = {
web: 'defaults',
node: 'node >= 14'
};
module.exports = declare((api, options) => {
api.assertVersion(7);
let targets = options.targets;
// region Helpers.
const isNotExcluded = (str, then) => ((options.exclude || []).indexOf(str) === -1) ? then(str) : null;
const setOr = (value, or) => value === undefined ? or : value;
// endregion
if (!targets) {
targets = `${defaultTargets.web}, ${defaultTargets.node}`;
if (options.mode === 'web') {
targets = defaultTargets.web;
} else if (options.mode === 'node') {
targets = defaultTargets.node;
}
}
const opts = {
decorators: {},
pipeline: {},
recordAndTuple: {},
...options,
};
const presetOptions = {
useBuiltIns: setOr(opts.useBuiltIns, 'entry'),
targets: targets,
spec: setOr(opts.spec, false),
loose: setOr(opts.loose, false),
modules: setOr(opts.modules, 'auto'),
debug: setOr(opts.debug, false),
include: setOr(opts.include, []),
corejs: setOr(opts.corejs, {
version: 3,
proposals: true
}),
forceAllTransforms: setOr(opts.forceAllTransforms, false),
shippedProposals: setOr(opts.shippedProposals, false)
};
return {
presets: [
(isNotExcluded('preset-env', () => [
require('@babel/preset-env'),
presetOptions
]))
].filter(p => p !== null),
plugins: [
isNotExcluded('decorators', () => [
require('@babel/plugin-proposal-decorators'), {
version: setOr(opts.decorators.version, '2023-01'),
}
]),
isNotExcluded('transform-runtime', () => [
require('@babel/plugin-transform-runtime'), {
corejs: {
version: 3,
proposals: true
},
version: pkg.dependencies['@babel/plugin-transform-runtime']
}
]),
isNotExcluded('pipeline-operator', () => [
require('@babel/plugin-proposal-pipeline-operator'),
{
proposal: setOr(opts.pipeline.proposal, 'hack'),
topicToken: setOr(opts.pipeline.topicToken, '^^')
}
]),
isNotExcluded('record-and-tuple', () => [
require('@babel/plugin-proposal-record-and-tuple'),
{
syntaxType: setOr(opts.recordAndTuple.syntaxType, 'hash'),
importPolyfill: setOr(opts.recordAndTuple.polyfill, false),
polyfillModuleName: setOr(
opts.recordAndTuple.polyfillModuleName,
'@bloomberg/record-tuple-polyfill'
),
},
]),
isNotExcluded('async-do-expressions', () =>
require('@babel/plugin-proposal-async-do-expressions')),
isNotExcluded('export-default-from', () =>
require('@babel/plugin-proposal-export-default-from')),
isNotExcluded('function-bind', () =>
require('@babel/plugin-proposal-function-bind')),
isNotExcluded('partial-application', () =>
require('@babel/plugin-proposal-partial-application')),
isNotExcluded('throw-expressions', () =>
require('@babel/plugin-proposal-throw-expressions')),
isNotExcluded('object-assign', () =>
require('@babel/plugin-transform-object-assign')),
isNotExcluded('regexp-modifiers', () =>
require('@babel/plugin-proposal-regexp-modifiers'))
].filter(p => p !== null)
};
});