@@ -7,14 +7,7 @@ import typescript from '@rollup/plugin-typescript'
77import terser from '@rollup/plugin-terser'
88import fg from 'fast-glob'
99import { basename , join } from 'path'
10- import {
11- writeFileSync ,
12- copyFileSync ,
13- opendirSync ,
14- rmSync ,
15- Dir ,
16- readFileSync
17- } from 'fs'
10+ import { copyFileSync , opendirSync , rmSync , Dir } from 'fs'
1811import { fileURLToPath } from 'url'
1912
2013// cleanup dist dir
@@ -45,7 +38,7 @@ export default defineConfig([
4538 plugins : [
4639 typescript ( {
4740 declaration : true ,
48- declarationDir : './dist/types ' ,
41+ declarationDir : './dist' ,
4942 rootDir : 'src'
5043 } ) ,
5144 makeFlatPackageInDist ( )
@@ -75,40 +68,10 @@ function makeFlatPackageInDist(): Plugin {
7568 return {
7669 name : 'makeFlatPackageInDist' ,
7770 writeBundle ( ) {
78- // append our api modules to `exports` in `package.json` then write it to `./dist`
79- const pkg = JSON . parse ( readFileSync ( 'package.json' , 'utf8' ) )
80- const mods = modules . map ( ( p ) => basename ( p ) . split ( '.' ) [ 0 ] )
81-
82- const outputPkg = {
83- ...pkg ,
84- devDependencies : { } ,
85- exports : Object . assign (
86- { } ,
87- ...mods . map ( ( mod ) => {
88- const exports : Record <
89- string ,
90- { types : string ; import : string ; require : string }
91- > = { }
92- const key = mod === 'index' ? '.' : `./${ mod } `
93- exports [ key ] = {
94- types : `./types/${ mod } .d.ts` ,
95- import : `./${ mod } .js` ,
96- require : `./${ mod } .cjs`
97- }
98- return exports
99- } ) ,
100- // if for some reason in the future we manually add something in the `exports` field
101- // this will ensure it doesn't get overwritten by the logic above
102- { ...( pkg . exports || { } ) }
103- )
104- }
105- writeFileSync (
106- 'dist/package.json' ,
107- JSON . stringify ( outputPkg , undefined , 2 )
108- )
109-
11071 // copy necessary files like `CHANGELOG.md` , `README.md` and Licenses to `./dist`
111- fg . sync ( '(LICENSE*|*.md)' ) . forEach ( ( f ) => copyFileSync ( f , `dist/${ f } ` ) )
72+ fg . sync ( '(LICENSE*|*.md|package.json)' ) . forEach ( ( f ) =>
73+ copyFileSync ( f , `dist/${ f } ` )
74+ )
11275 }
11376 }
11477}
0 commit comments