-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite-exports.ts
More file actions
38 lines (30 loc) · 1.1 KB
/
write-exports.ts
File metadata and controls
38 lines (30 loc) · 1.1 KB
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
import { spawnSync } from 'node:child_process'
import fs from 'node:fs'
import { Options } from 'tsdown'
import packageJSON from './package.json' with { type: 'json' }
import _tsDownConfig from './tsdown.config.ts'
const tsDownConfig = _tsDownConfig as Options
const outDir = tsDownConfig.outDir ?? './dist'
const pkgJSON = structuredClone(packageJSON) as any
pkgJSON.exports = {}
pkgJSON.typesVersions = {}
Object.keys(tsDownConfig.entry ?? {}).forEach((key) => {
if (key === 'index') {
pkgJSON.main = `${outDir}/${key}.cjs`
pkgJSON.module = `${outDir}/${key}.mjs`
}
pkgJSON.exports[key === 'index' ? '.' : `./${key}`] = {
import: `${outDir}/${key}.mjs`,
require: `${outDir}/${key}.cjs`,
}
pkgJSON.typesVersions['*'] ??= {}
pkgJSON.typesVersions['*'][key === 'index' ? '.' : key] = [
`${outDir}/${key}.d.mts`,
`${outDir}/${key}.d.cts`,
]
})
console.log('📢 Writing package.json...')
fs.writeFileSync('./package.json', JSON.stringify(pkgJSON, null, 2))
console.log('✨ Running prettier...')
spawnSync('npx', ['prettier', '--write', './package.json'])
console.log('✅ Done')