-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.mjs
93 lines (90 loc) · 2.18 KB
/
rollup.config.mjs
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import fs from 'fs';
import path from 'path';
const packageJson = JSON.parse(
fs.readFileSync('./package.json', { encoding: 'utf-8' }),
);
function buildConfig({ input, output, declaration = false }) {
return {
input,
plugins: [
typescript({
compilerOptions: {
declaration,
declarationDir: declaration ? '/' : undefined,
},
}),
resolve(),
commonjs(),
{
name: 'package-json',
resolveId(id) {
return id.startsWith('package-json:') ? id : null;
},
load(id) {
if (!id.startsWith('package-json:')) {
return null;
}
const matches = /^package-json:([^]*)$/.exec(id);
if (matches) {
const name = matches[1];
let value = packageJson[matches[1]];
if (name === 'version' && !value) {
value = 'dev';
}
if (value) {
return `export default ${JSON.stringify(`${value}`)};`;
}
}
throw new Error('Error reading from package.json');
},
},
].filter(Boolean),
onLog: (level, log, handler) => {
if (
log.code === 'CIRCULAR_DEPENDENCY' &&
[
path.resolve('src/nodes/quantifier.ts'),
path.resolve('src/character-reader/character-reader-level-0.ts'),
].includes(log.ids[0])
) {
return;
}
if (level === 'warn') {
// treat warnings as errors
handler('error', log);
} else {
handler(level, log);
}
},
output,
};
}
export default [
buildConfig({
input: 'src/redos-detector.ts',
declaration: true,
output: [
{
name: 'RedosDetector',
file: 'dist/redos-detector.js',
format: 'umd',
},
{
file: 'dist/redos-detector.mjs',
format: 'es',
},
],
}),
buildConfig({
input: 'src/cli.ts',
output: [
{
file: 'dist/cli.js',
format: 'commonjs',
},
],
}),
];