@@ -3,21 +3,31 @@ import fs from 'fs';
33import path from 'path' ;
44import PATHS from '../config/paths.js' ;
55
6- const TARGET_PACKAGES = [ 'ai' , 'charts' , 'compat' , 'main' ] ;
6+ const TARGET_PACKAGES = [ 'ai' , 'charts' , 'compat' , 'main' ] as const ;
77const INTERNAL_COMPONENTS = new Set ( [ 'ObjectPageAnchorBar' , 'Splitter' ] ) ;
88
9- function getComponentExports ( distDir , componentDir ) {
9+ interface ExportEntry {
10+ types : string ;
11+ default : string ;
12+ }
13+
14+ interface ExportsObject {
15+ [ key : string ] : ExportEntry ;
16+ }
17+
18+ function getComponentExports ( distDir : string , componentDir : string ) : ExportsObject {
1019 const dir = path . join ( distDir , componentDir ) ;
1120 if ( ! fs . existsSync ( dir ) ) return { } ;
1221
1322 const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
14- const exportsObj = { } ;
23+ const exportsObj : ExportsObject = { } ;
1524
1625 entries . forEach ( ( entry ) => {
1726 if ( entry . isDirectory ( ) ) {
1827 if ( INTERNAL_COMPONENTS . has ( entry . name ) ) {
1928 return ;
2029 }
30+
2131 const jsPath = path . join ( dir , entry . name , 'index.js' ) ;
2232 const dtsPath = path . join ( dir , entry . name , 'index.d.ts' ) ;
2333
@@ -43,10 +53,11 @@ function getComponentExports(distDir, componentDir) {
4353
4454 return exportsObj ;
4555}
56+
4657/**
4758 * Update the package.json of a given package
4859 */
49- function updatePackageJson ( pkgPath ) {
60+ function updatePackageJson ( pkgPath : string ) : void {
5061 const packageJsonPath = path . join ( pkgPath , 'package.json' ) ;
5162 const distDir = path . join ( pkgPath , 'dist' ) ;
5263
@@ -55,14 +66,14 @@ function updatePackageJson(pkgPath) {
5566 return ;
5667 }
5768
58- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
69+ const packageJson : Record < string , any > = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
5970 packageJson . exports = packageJson . exports || { } ;
6071
6172 // collect exports from "components" and "webComponents"
6273 const componentExports = getComponentExports ( distDir , 'components' ) ;
6374 const webComponentExports = getComponentExports ( distDir , 'webComponents' ) ;
6475
65- const newExports = {
76+ const newExports : ExportsObject = {
6677 ...componentExports ,
6778 ...webComponentExports ,
6879 } ;
@@ -75,7 +86,8 @@ function updatePackageJson(pkgPath) {
7586 console . log ( `✅ Updated exports in ${ packageJsonPath } ` ) ;
7687}
7788
89+ console . log ( 'ℹ️ Make sure all packages are built before running this script!' ) ;
7890TARGET_PACKAGES . forEach ( ( pkg ) => {
79- const pkgPath = PATHS [ pkg ] ;
91+ const pkgPath = PATHS [ pkg as keyof typeof PATHS ] ;
8092 updatePackageJson ( pkgPath ) ;
8193} ) ;
0 commit comments