Files
cypress/npm/mount-utils/create-rollup-entry.mjs
T
BaboonKing 854a6497be feat: supported type of vue@2.7+ (#28818)
* feat: supported type of vue@2.7+

* chore[build]: respectExternal back to false for vue2 in dts

* 更新 rollup.config.mjs

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* updating changelog

* updating link

---------

Co-authored-by: Bill Glesias <bglesias@gmail.com>
Co-authored-by: Matt Schile <mschile@cypress.io>
2024-03-12 10:57:36 -04:00

88 lines
2.2 KiB
JavaScript

// 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 || [],
}])
}