-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
85 lines (74 loc) · 2.63 KB
/
rollup.config.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
import typescriptPlugin from 'rollup-plugin-typescript2';
import { tmpdir } from 'node:os';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';
import { dirname, join as pathJoin } from 'node:path';
const MODULES = [
'cacher',
'redis',
];
const coreModules = builtinModules.filter(name => (
!/(^_|\/)/.test(name)
));
const rootDir = dirname(fileURLToPath(import.meta.url));
const cacheRoot = pathJoin(tmpdir(), '.rpt2_cache');
/** @param {string} path */
const getModulePath = path => (
pathJoin(rootDir, 'packages', path)
);
export default async () => (
Promise.all(
MODULES
.map(getModulePath)
.map(async (modulePath) => {
/**
* @type {{
* dependencies?: Record<string, string>,
* peerDependencies?: Record<string, string>,
* }}
*/
const modulePkg = await import(
pathJoin(modulePath, 'package.json'),
{
assert: {
type: 'json',
},
}
);
const src = pathJoin(modulePath, 'src');
const lib = pathJoin(modulePath, 'lib');
return {
input: pathJoin(src, 'index.ts'),
plugins: [
typescriptPlugin({
cacheRoot,
useTsconfigDeclarationDir: false,
tsconfigOverride: {
outDir: lib,
rootDir: src,
include: [src],
},
}),
],
external: [
...Object.keys(modulePkg.dependencies || {}),
...Object.keys(modulePkg.peerDependencies || {}),
// TODO: To make better
...MODULES.map(moduleName => `@cacher/${moduleName}`),
...coreModules,
],
output: [
{
file: pathJoin(modulePath, 'lib/index.js'),
format: 'cjs',
exports: 'named',
},
{
file: pathJoin(modulePath, 'lib/index.mjs'),
format: 'esm',
},
],
};
})
)
);