-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrollup.config.js
99 lines (93 loc) · 2.7 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { getPackages } from '@lerna/project'
import filterPackages from '@lerna/filter-packages'
import batchPackages from '@lerna/batch-packages'
import typescript from '@wessberg/rollup-plugin-ts'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import path from 'path'
import minimist from 'minimist'
const external = [
// Textile
'@textile/threads-client',
'@textile/context',
'@textile/threads-id',
'@textile/multiaddr',
'@textile/security',
'@textile/threads',
'@textile/threaddb',
'@textile/transport',
'@textile/buckets',
'@textile/crypto',
'@textile/grpc-authentication',
'@textile/grpc-connection',
'@textile/hub',
'@textile/hub-filecoin',
'@textile/hub-threads-client',
'@textile/users',
// Others (add externals and valid es modules here)
'stream',
'fs',
'path',
]
/**
* @param {string[]}[scope] - packages to only build (if you don't
* want to build everything)
* @param {string[]}[ignore] - packages to not build
*
* @returns {Promise<any[]>} - sorted list of Package objects that
* represent packages to be built.
*/
async function getSortedPackages(scope, ignore) {
const packages = await getPackages(__dirname)
const filtered = filterPackages(packages, scope, ignore, false, true)
return batchPackages(filtered).reduce((arr, batch) => arr.concat(batch), [])
}
/**
* @returns Promise<RollupConfig>
*/
async function main() {
const config = []
// Support --scope and --ignore globs if passed in via commandline
const { scope, ignore } = minimist(process.argv.slice(2))
const packages = await getSortedPackages(scope, ignore)
packages.forEach((pkg) => {
if (pkg.name.includes('buck-util')) return
if (pkg.name.includes('buckr')) return
/* Absolute path to package directory */
const basePath = path.resolve(__dirname, pkg.location)
/* Absolute path to input file */
const input = path.join(basePath, 'src/index.ts')
/* Push build config for this package. */
config.push({
input,
output: [
{
exports: 'named',
file: path.join(basePath, 'dist/esm/index.js'),
format: 'es',
},
],
external,
plugins: [
json(),
resolve({
preferBuiltins: false,
browser: true,
}),
commonjs(),
typescript(),
terser(),
],
onwarn(warning, warn) {
// suppress eval warnings
if (warning.code === 'EVAL') return
warn(warning)
},
})
})
return config
}
export default main()