forked from reduxjs/reselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
52 lines (48 loc) · 1.41 KB
/
tsup.config.ts
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
import { defineConfig, Options } from 'tsup'
import fs from 'fs'
import sh from 'shelljs'
import type { ExecOptions } from 'shelljs'
function execAsync(cmd: string, opts: ExecOptions = {}) {
return new Promise(function (resolve, reject) {
// Execute the command, reject if we exit non-zero (i.e. error)
sh.exec(cmd, opts, function (code, stdout, stderr) {
if (code !== 0) return reject(new Error(stderr))
return resolve(stdout)
})
})
}
export default defineConfig(options => {
const commonOptions: Partial<Options> = {
entry: {
reselect: 'src/index.ts'
},
...options
}
return [
{
...commonOptions,
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: true,
clean: true,
async onSuccess() {
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
fs.copyFileSync('dist/reselect.mjs', 'dist/reselect.legacy-esm.js')
console.log('onSuccess')
console.log('Generating TS 4.6 types...')
await execAsync('yarn tsc -p tsconfig.ts46types.json')
fs.copyFileSync(
'src/versionedTypes/package.dist.json',
'dist/versionedTypes/ts46/versionedTypes/package.json'
)
console.log('TS 4.6 types done')
}
},
{
...commonOptions,
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' })
}
]
})