-
Notifications
You must be signed in to change notification settings - Fork 47
/
babel.config.cjs
68 lines (64 loc) · 1.66 KB
/
babel.config.cjs
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
const fs = require('fs');
const os = require('os');
const path = require('path');
const cwd = process.cwd();
const pkg = require(`${cwd}/package.json`);
const dist = pkg.files?.map(f => path.join(cwd, f));
function getPackageJSON(rel) {
let cache = getPackageJSON.cache = getPackageJSON.cache || new Map();
if (cache.has(rel)) return cache.get(rel);
let pkg = path.join(rel, 'package.json');
let dir = path.dirname(rel);
if (fs.existsSync(pkg)) {
cache.set(rel, JSON.parse(fs.readFileSync(pkg)));
return cache.get(rel);
} else if (dir !== rel && dir !== os.homedir()) {
return getPackageJSON(dir);
}
}
module.exports = {
overrides: [{
test: name => dist?.includes(name) === false &&
getPackageJSON(name).type === 'module',
presets: [
['@babel/env', {
modules: false,
targets: { node: '14' }
}]
]
}, {
test: name => dist?.includes(name) === false &&
getPackageJSON(name).type !== 'module',
presets: [
['@babel/env', {
modules: 'commonjs',
targets: { node: '14' }
}]
]
}, {
test: (name, { envName }) => envName === 'test' &&
getPackageJSON(name).type !== 'module',
plugins: [
['module-resolver', {
cwd: __dirname,
alias: {
'^@percy/((?!dom)[^/]+)$': './packages/\\1/src/index.js',
'^@percy/([^/]+)/((?!test|src).+)$': './packages/\\1/src/\\2'
}
}]
]
}],
env: {
test: {
plugins: [
['istanbul', {
exclude: ['dist', 'test']
}]
]
},
dev: {
presets: ["@babel/preset-env"],
plugins: ["babel-plugin-transform-import-meta"]
}
}
};