-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
118 lines (114 loc) · 3.12 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
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 nodeResolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import {copyPlugin} from "@alorel/rollup-plugin-copy";
import commonjs from "@rollup/plugin-commonjs";
import * as fs from 'node:fs';
import {randomUUID} from 'node:crypto';
const srcInclude = /src[\\/].+\.m?ts$/;
const srcExclude = /node_modules[\\/]/;
export default async function initRollup(cfg) {
const modules = fs.readdirSync('src/modules', 'utf8');
const MAIN = randomUUID();
const watching = cfg.watch === true;
return {
input: modules
.reduce((acc, mod) => {
acc[mod] = `src/modules/${mod}/index.mts`;
return acc;
}, {[MAIN]: 'src/index.mts'}),
context: 'global',
moduleContext: 'global',
output: {
generatedCode: {
constBindings: true,
},
dir: 'dist',
format: 'commonjs',
preserveModules: false,
sourcemap: false,
entryFileNames: ({name}) => name === MAIN ? 'release.js' : `${name}/${name}.js`,
chunkFileNames: '_common/[name].js',
assetFileNames: '[name][extname]',
},
plugins: [
nodeResolve({
exportConditions: [
'es2015',
'module',
'import',
'default',
],
mainFields: [
'es2015',
'esm2015',
'module',
'browser',
'main',
],
}),
{
name: 'json-loader',
transform(code, id) {
if (id.endsWith('.json')) {
return {code: `export default ${code}`, map: {mappings: ''}};
}
}
},
typescript({
exclude: srcExclude,
include: srcInclude,
noEmitOnError: true,
// compilerOptions: {
// sourceMap: watching,
// }
}),
commonjs({
exclude: ['.js', '.ts'],
include: [/node_modules/, /^polyfill-node\.[^.]+\.js$/],
mainFields: ['fesm2015', 'es2015', 'esm2015', 'module', 'main'],
}),
!watching && process.env.NODE_ENV !== 'dev' && (await import('@alorel/rollup-plugin-threaded-terser')).threadedTerserPlugin({
terserOpts: {
enclose: (args => `${args}:${args}`)([
'require',
'Reflect',
'console',
'Object',
'Error',
'JSON',
'Math',
'process',
'TypeError',
'undefined',
'Symbol',
].join(',')),
ecma: 2020,
toplevel: true,
},
}),
copyPlugin({
copy: [
{from: 'action.yml', opts: {glob: {cwd: 'src'}}},
'LICENSE',
...modules.map(mod => ({
from: `${mod}/action.yml`,
opts: {glob: {cwd: 'src/modules'}},
}))
],
defaultOpts: {
emitNameKind: 'fileName',
},
watch: watching,
}),
],
watch: {
exclude: 'node_modules/**/*',
},
onLog(level, log, handler) {
if (log.code === 'CIRCULAR_DEPENDENCY' && log.message.includes('node_modules/@actions/core/lib/core.js')) {
return;
}
handler(level, log);
},
}
}