@@ -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
@@ -57,7 +50,7 @@ export default defineConfig([
5750 plugins : [
5851 typescript ( {
5952 declaration : true ,
60- declarationDir : './dist/types ' ,
53+ declarationDir : './dist' ,
6154 rootDir : 'src'
6255 } ) ,
6356 makeFlatPackageInDist ( )
@@ -87,44 +80,10 @@ function makeFlatPackageInDist(): Plugin {
8780 return {
8881 name : 'makeFlatPackageInDist' ,
8982 writeBundle ( ) {
90- // append our api modules to `exports` in `package.json` then write it to `./dist`
91- const pkg = JSON . parse ( readFileSync ( 'package.json' , 'utf8' ) )
92- const mods = modules . map ( ( p ) => basename ( p ) . split ( '.' ) [ 0 ] )
93-
94- const outputPkg = {
95- ...pkg ,
96- devDependencies : { } ,
97- exports : Object . assign (
98- { } ,
99- ...mods . map ( ( mod ) => {
100- let temp : Record <
101- string ,
102- { types : string ; import : string ; require : string }
103- > = { }
104- let key = `./${ mod } `
105- if ( mod === 'index' ) {
106- key = '.'
107- }
108-
109- temp [ key ] = {
110- types : `./types/${ mod } .d.ts` ,
111- import : `./${ mod } .js` ,
112- require : `./${ mod } .cjs`
113- }
114- return temp
115- } ) ,
116- // if for some reason in the future we manually add something in the `exports` field
117- // this will ensure it doesn't get overwritten by the logic above
118- { ...( pkg . exports || { } ) }
119- )
120- }
121- writeFileSync (
122- 'dist/package.json' ,
123- JSON . stringify ( outputPkg , undefined , 2 )
124- )
125-
12683 // copy necessary files like `CHANGELOG.md` , `README.md` and Licenses to `./dist`
127- fg . sync ( '(LICENSE*|*.md)' ) . forEach ( ( f ) => copyFileSync ( f , `dist/${ f } ` ) )
84+ fg . sync ( '(LICENSE*|*.md|package.json)' ) . forEach ( ( f ) =>
85+ copyFileSync ( f , `dist/${ f } ` )
86+ )
12887 }
12988 }
13089}
0 commit comments