forked from isomorphic-git/isomorphic-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
91 lines (83 loc) · 1.89 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
import fs from 'fs'
import path from 'path'
import pkg from './package.json'
const external = [
'fs',
'path',
'crypto',
'stream',
'crc/lib/crc32.js',
'sha.js/sha1',
'sha.js/sha1.js',
...Object.keys(pkg.dependencies),
]
// Modern modules
const ecmaConfig = (input, output) => ({
input: `src/${input}`,
external: [...external],
output: [
{
format: 'es',
file: `${output}`,
},
],
})
// Legacy CommonJS2 modules
const nodeConfig = (input, output) => ({
input: `src/${input}`,
external: [...external],
output: [
{
format: 'cjs',
file: `${output}`,
exports: 'named',
},
],
})
// Script tags that "export" a global var for those browser environments that
// still don't support `import` (Workers and ServiceWorkers)
const umdConfig = (input, output, name) => ({
input: `src/${input}`,
output: [
{
format: 'umd',
file: `${output}`,
name,
exports: 'named',
},
],
})
const template = umd =>
JSON.stringify(
{
type: 'module',
main: 'index.cjs',
module: 'index.js',
typings: 'index.d.ts',
unpkg: umd ? 'index.umd.js' : undefined,
},
null,
2
)
const pkgify = (input, output, name) => {
fs.mkdirSync(path.join(__dirname, output), { recursive: true })
fs.writeFileSync(
path.join(__dirname, output, 'package.json'),
template(!!name)
)
return [
ecmaConfig(`${input}/index.js`, `${output}/index.js`),
nodeConfig(`${input}/index.js`, `${output}/index.cjs`),
...(name
? [umdConfig(`${input}/index.js`, `${output}/index.umd.js`, name)]
: []),
]
}
export default [
ecmaConfig('index.js', 'index.js'),
nodeConfig('index.js', 'index.cjs'),
ecmaConfig('internal-apis.js', 'internal-apis.js'),
nodeConfig('internal-apis.js', 'internal-apis.cjs'),
...pkgify('http/node', 'http/node'),
...pkgify('http/web', 'http/web', 'GitHttp'),
]