-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathcreate-rollup-entry.mjs
87 lines (78 loc) · 2.18 KB
/
create-rollup-entry.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
// CommonJS to easily share across packages
import ts from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import _ from 'lodash'
import { readFileSync } from 'fs'
import dts from 'rollup-plugin-dts'
const pkg = JSON.parse(readFileSync('./package.json'))
/** @type {(options: { formats: string[], input: string, config: {} }) => []} */
export function createEntries (options) {
const {
formats,
input,
config = {},
dtsOptions = {},
} = options
const banner = `
/**
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} Cypress.io
* Released under the MIT License
*/
`
return formats.map((format) => {
const baseConfig = {
input,
plugins: [
resolve({ preferBuiltins: true }),
commonjs(),
ts({
check: format === 'es',
tsconfigOverride: {
compilerOptions: {
declaration: false,
target: 'es6',
module: format === 'cjs' ? 'es2015' : 'esnext',
},
exclude: ['tests'],
},
}),
],
output: {
banner,
name: 'CypressReact',
file: pkg.unpkg,
format,
},
}
const finalConfig = _.mergeWith({}, baseConfig, config, (objValue, srcValue) => {
if (_.isArray(objValue)) {
return objValue.concat(srcValue)
}
})
if (format === 'es') {
finalConfig.output.file = pkg.module
}
if (format === 'cjs') {
finalConfig.output.file = pkg.main
}
// eslint-disable-next-line no-console
console.log(`Building ${format}: ${finalConfig.output.file}`)
return finalConfig
}).concat([{
input,
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [
dts({ respectExternal: true, ...dtsOptions }),
{
name: 'cypress-types-reference',
// rollup-plugin-dts does not add '// <reference types="cypress" />' like rollup-plugin-typescript2 did so we add it here.
renderChunk (...[code]) {
return `/// <reference types="cypress" />\n\n${code}`
},
},
],
external: config.external || [],
}])
}