@@ -16,7 +16,12 @@ function readFile(filepath: string) {
1616}
1717
1818function readJSONFile < T > ( filepath : string ) : Promise < T > {
19- return readFile ( filepath ) . then ( JSON . parse ) ;
19+ return readFile ( filepath )
20+ . then ( JSON . parse )
21+ . catch ( ( error : unknown ) => {
22+ console . error ( `Error reading ${ filepath } : ${ error } ` ) ;
23+ throw error ;
24+ } ) ;
2025}
2126
2227function fileExists ( filepath : string ) {
@@ -36,7 +41,7 @@ const versions: Record<string, string> = {};
3641const rootPkg = await readJSONFile < TshyPackageJson > (
3742 path . join ( import . meta. dirname , '../package.json' ) ,
3843) ;
39- const paths = await globby ( [ 'packages/* */package.json' , '!**/node_modules' ] ) ;
44+ const paths = await globby ( [ '*/ */package.json' , '!**/node_modules' ] ) ;
4045
4146const packages = await Promise . all (
4247 paths . map ( async ( pkgPath : string ) : Promise < [ string , TshyPackageJson ] > => {
@@ -53,33 +58,47 @@ for (const [pkgPath, pkg] of packages) {
5358 const dir = path . dirname ( pkgPath ) ;
5459 fixPeerDeps ( path . resolve ( path . join ( dir ) ) ) ;
5560
56- const isTS = await fileExists ( path . join ( dir , 'src/index.ts' ) ) ;
61+ const isTS =
62+ ( await fileExists ( path . join ( dir , 'src/index.ts' ) ) ) ||
63+ ( await fileExists ( path . join ( dir , 'tsconfig.json' ) ) ) ;
5764 const hasReadme = await fileExists ( path . join ( dir , 'README.md' ) ) ;
65+ const isPrivate = pkg . private === true ;
5866
59- // Replicate configs that should always be the same.
60- pkg . engines = rootPkg . engines ;
61- pkg . author = rootPkg . author ;
62- pkg . license = rootPkg . license ;
63- pkg . repository = rootPkg . repository ;
64- pkg . keywords = [ ...new Set ( [ ...( rootPkg . keywords ?? [ ] ) , ...( pkg . keywords ?? [ ] ) ] ) ] ;
65- pkg . sideEffects = pkg . sideEffects ?? false ;
66- pkg . publishConfig = { access : 'public' } ;
67-
68- if ( hasReadme ) {
69- const repoPath = dir . split ( '/' ) . slice ( - 2 ) . join ( '/' ) ;
70- pkg . homepage = `https://github.com/SBoudrias/Inquirer.js/blob/main/${ repoPath } /README.md` ;
67+ pkg . sideEffects ??= false ;
68+
69+ // Replicate configs that should always be the same on public package.
70+ if ( ! isPrivate ) {
71+ pkg . author = rootPkg . author ;
72+ pkg . license = rootPkg . license ;
73+ pkg . repository = rootPkg . repository ;
74+ pkg . keywords = [ ...new Set ( [ ...( rootPkg . keywords ?? [ ] ) , ...( pkg . keywords ?? [ ] ) ] ) ] ;
75+ pkg . publishConfig = { access : 'public' } ;
76+
77+ if ( hasReadme ) {
78+ const repoPath = dir . split ( '/' ) . slice ( - 2 ) . join ( '/' ) ;
79+ pkg . homepage = `https://github.com/SBoudrias/Inquirer.js/blob/main/${ repoPath } /README.md` ;
80+ }
81+ } else {
82+ // Remove publishing metadata for private packages
83+ delete pkg . author ;
84+ delete pkg . license ;
85+ delete pkg . repository ;
86+ delete pkg . keywords ;
87+ delete pkg . homepage ;
88+ delete pkg . publishConfig ;
89+ delete pkg . files ;
7190 }
7291
73- if ( isTS ) {
92+ if ( isTS && ! isPrivate ) {
7493 pkg . files = [ 'dist' ] ;
7594
76- pkg . devDependencies = pkg . devDependencies ?? { } ;
95+ pkg . devDependencies ??= { } ;
7796 pkg . devDependencies [ 'tshy' ] = versions [ 'tshy' ] ;
7897
79- pkg . tshy = pkg . tshy ?? { } ;
98+ pkg . tshy ??= { } ;
8099 pkg . tshy . exclude = [ 'src/**/*.test.ts' ] ;
81100
82- pkg . scripts = pkg . scripts ?? { } ;
101+ pkg . scripts ??= { } ;
83102 pkg . scripts [ 'tsc' ] = 'tshy' ;
84103
85104 // Only set attw if the package is using commonjs
0 commit comments