|
| 1 | +// CommonJS to easily share across packages |
| 2 | +import ts from 'rollup-plugin-typescript2' |
| 3 | +import resolve from '@rollup/plugin-node-resolve' |
| 4 | +import commonjs from '@rollup/plugin-commonjs' |
| 5 | +import _ from 'lodash' |
| 6 | +import { readFileSync } from 'fs' |
| 7 | + |
| 8 | +const pkg = JSON.parse(readFileSync('./package.json')) |
| 9 | + |
| 10 | +/** @type {(options: { formats: string[], input: string, config: {} }) => []} */ |
| 11 | +export function createEntries (options) { |
| 12 | + const { |
| 13 | + formats, |
| 14 | + input, |
| 15 | + config = {}, |
| 16 | + } = options |
| 17 | + |
| 18 | + const banner = ` |
| 19 | +/** |
| 20 | + * ${pkg.name} v${pkg.version} |
| 21 | + * (c) ${new Date().getFullYear()} Cypress.io |
| 22 | + * Released under the MIT License |
| 23 | + */ |
| 24 | +` |
| 25 | + |
| 26 | + return formats.map((format) => { |
| 27 | + const baseConfig = { |
| 28 | + input, |
| 29 | + plugins: [ |
| 30 | + resolve({ preferBuiltins: true }), |
| 31 | + commonjs(), |
| 32 | + ts({ |
| 33 | + check: format === 'es', |
| 34 | + tsconfigOverride: { |
| 35 | + compilerOptions: { |
| 36 | + declaration: format === 'es', |
| 37 | + target: 'es6', |
| 38 | + module: format === 'cjs' ? 'es2015' : 'esnext', |
| 39 | + }, |
| 40 | + exclude: ['tests'], |
| 41 | + }, |
| 42 | + }), |
| 43 | + ], |
| 44 | + output: { |
| 45 | + banner, |
| 46 | + name: 'CypressReact', |
| 47 | + file: pkg.unpkg, |
| 48 | + format, |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + const finalConfig = _.mergeWith({}, baseConfig, config, (objValue, srcValue) => { |
| 53 | + if (_.isArray(objValue)) { |
| 54 | + return objValue.concat(srcValue) |
| 55 | + } |
| 56 | + }) |
| 57 | + |
| 58 | + if (format === 'es') { |
| 59 | + finalConfig.output.file = pkg.module |
| 60 | + } |
| 61 | + |
| 62 | + if (format === 'cjs') { |
| 63 | + finalConfig.output.file = pkg.main |
| 64 | + } |
| 65 | + |
| 66 | + // eslint-disable-next-line no-console |
| 67 | + console.log(`Building ${format}: ${finalConfig.output.file}`) |
| 68 | + |
| 69 | + return finalConfig |
| 70 | + }) |
| 71 | +} |
0 commit comments