forked from ts-graphviz/ts-graphviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
118 lines (113 loc) · 2.9 KB
/
rollup.config.js
File metadata and controls
118 lines (113 loc) · 2.9 KB
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
108
109
110
111
112
113
114
115
116
117
118
import del from 'rollup-plugin-delete';
import dts from 'rollup-plugin-dts';
import replace from '@rollup/plugin-replace';
function* createOptions() {
const subPackages = ['utils', 'common', 'ast', 'core', 'adapter'];
const subPackageEntrypoints = subPackages.flatMap((subPackage) => [
`../${subPackage}/index.js`,
`../../${subPackage}/index.js`,
`../../../${subPackage}/index.js`,
`../../../../${subPackage}/index.js`,
`../../../../../${subPackage}/index.js`,
`../../../../../../${subPackage}/index.js`,
]);
yield {
input: './lib/index.js',
output: [
{
format: 'cjs',
file: './lib/index.cjs',
},
{
format: 'esm',
file: './lib/index.js',
},
],
external: subPackages.map((subPackage) => `./${subPackage}/index.js`),
};
for (const subPackage of subPackages) {
yield {
input: `./lib/${subPackage}/index.js`,
output: [
{
format: 'cjs',
file: `./lib/${subPackage}/index.cjs`,
},
{
format: 'esm',
file: `./lib/${subPackage}/index.js`,
},
],
external: [...subPackageEntrypoints, 'node:fs', 'node:stream', 'node:util', 'node:child_process'],
};
yield {
input: `lib/${subPackage}/index.d.ts`,
plugins: [
del({
targets: [`lib/${subPackage}/**/*`, `!lib/${subPackage}/**/index.*`],
hook: 'buildEnd',
}),
dts(),
],
output: [
{
format: 'esm',
file: `lib/${subPackage}/index.d.ts`,
},
],
external: subPackageEntrypoints,
};
yield {
input: `./lib/${subPackage}/index.cjs`,
output: {
format: 'cjs',
file: `./lib/${subPackage}/index.cjs`,
},
external: subPackageEntrypoints,
plugins: [
replace({
values: subPackages.reduce(
(prev, subPackage) => ({ ...prev, [`${subPackage}/index.js`]: `${subPackage}/index.cjs` }),
{},
),
preventAssignment: true,
}),
],
};
}
yield {
input: './lib/index.d.ts',
plugins: [
del({
targets: ['lib/*.js', 'lib/**/*.d.ts', '!lib/**/index.{js,d.ts}'],
hook: 'buildEnd',
}),
dts(),
],
output: [
{
format: 'esm',
file: './lib/index.d.ts',
},
],
external: subPackages.map((subPackage) => `./${subPackage}/index.js`),
};
yield {
input: './lib/index.cjs',
output: {
format: 'cjs',
file: './lib/index.cjs',
},
external: subPackages.map((subPackage) => `./${subPackage}/index.js`),
plugins: [
replace({
values: subPackages.reduce(
(prev, subPackage) => ({ ...prev, [`${subPackage}/index.js`]: `${subPackage}/index.cjs` }),
{},
),
preventAssignment: true,
}),
],
};
}
export default [...createOptions()];