11import * as fs from 'fs'
22import * as path from 'path'
3- import { globSync } from 'glob '
3+ import { globSync } from 'node:fs '
44import { minimatch } from 'minimatch'
5- import { printLog , printError , runMain } from './lib/executionUtils.ts'
5+ import { printLog , printError , runMain , printWarning } from './lib/executionUtils.ts'
66import { command } from './lib/command.ts'
77
88interface PackageFile {
@@ -28,9 +28,18 @@ runMain(() => {
2828} )
2929
3030function checkPackage ( packagePath : string ) : boolean {
31+ const packageJson = getPackageJson ( packagePath )
32+
33+ if ( packageJson ?. private ) {
34+ printWarning ( `Skipping private package ${ packageJson . name } ` )
35+ return true
36+ }
37+
3138 printLog ( `Checking ${ packagePath } ` )
39+
3240 const packageFiles = getPackageFiles ( packagePath )
33- return checkPackageJsonEntryPoints ( packagePath , packageFiles ) && checkNpmIgnore ( packagePath , packageFiles )
41+
42+ return checkPackageJsonEntryPoints ( packageJson , packageFiles ) && checkNpmIgnore ( packagePath , packageFiles )
3443}
3544
3645function getPackageFiles ( packagePath : string ) : string [ ] {
@@ -44,19 +53,12 @@ function getPackageFiles(packagePath: string): string[] {
4453 return parsed [ 0 ] . files . map ( ( file ) => file . path )
4554}
4655
47- function checkPackageJsonEntryPoints ( packagePath : string , packageFiles : string [ ] ) : boolean {
48- const filesFromPackageJsonEntryPoints = packageFiles
49- . filter ( ( file ) => file . endsWith ( 'package.json' ) )
50- . flatMap ( ( packageJsonPath ) => {
51- const content = JSON . parse ( fs . readFileSync ( path . join ( packagePath , packageJsonPath ) , 'utf8' ) )
52- return [ content . main , content . module , content . types ]
53- . filter ( Boolean )
54- . map ( ( entryPointPath : string ) => path . join ( path . dirname ( packageJsonPath ) , entryPointPath ) )
55- } )
56+ function checkPackageJsonEntryPoints ( packageJson : PackageJson , packageFiles : string [ ] ) : boolean {
57+ const filesFromPackageJsonEntryPoints = [ packageJson . main , packageJson . module , packageJson . types ] . filter ( Boolean )
5658
5759 for ( const file of filesFromPackageJsonEntryPoints ) {
5860 if ( ! packageFiles . includes ( file ) ) {
59- printError ( `File ${ file } used as an entry point in ${ packagePath } is missing from the package` )
61+ printError ( `File ${ file } used as an entry point in ${ packageJson . name } is missing from the package` )
6062 return false
6163 }
6264 }
@@ -94,3 +96,17 @@ function checkNpmIgnore(packagePath: string, packageFiles: string[]): boolean {
9496
9597 return true
9698}
99+
100+ function getPackageJson ( packagePath : string ) {
101+ return globSync ( path . join ( packagePath , 'package.json' ) ) . map (
102+ ( packageJsonFile ) => JSON . parse ( fs . readFileSync ( packageJsonFile , 'utf8' ) ) as PackageJson
103+ ) [ 0 ]
104+ }
105+
106+ interface PackageJson {
107+ name : string
108+ private ?: boolean
109+ main : string
110+ module : string
111+ types : string
112+ }
0 commit comments