@@ -2,8 +2,9 @@ import * as fs from 'node:fs'
22import * as path from 'node:path'
33import { globSync } from 'node:fs'
44import { minimatch } from 'minimatch'
5- import { printLog , printError , runMain , printWarning } from './lib/executionUtils.ts'
5+ import { printLog , runMain , printWarning } from './lib/executionUtils.ts'
66import { command } from './lib/command.ts'
7+ import { checkPackageJsonFiles } from './lib/checkBrowserSdkPackageJsonFiles.ts'
78
89interface PackageFile {
910 path : string
@@ -14,20 +15,16 @@ interface NpmPackOutput {
1415}
1516
1617runMain ( ( ) => {
17- let success = true
18+ checkPackageJsonFiles ( )
19+
1820 for ( const packagePath of globSync ( 'packages/*' ) ) {
19- success = checkPackage ( packagePath ) && success
21+ checkBrowserSdkPackage ( packagePath )
2022 }
2123
22- if ( success ) {
23- printLog ( 'Packages check done.' )
24- } else {
25- printError ( 'Packages check failed.' )
26- process . exitCode = 1
27- }
24+ printLog ( 'Packages check done.' )
2825} )
2926
30- function checkPackage ( packagePath : string ) : boolean {
27+ function checkBrowserSdkPackage ( packagePath : string ) {
3128 const packageJson = getPackageJson ( packagePath )
3229
3330 if ( packageJson ?. private ) {
@@ -39,7 +36,8 @@ function checkPackage(packagePath: string): boolean {
3936
4037 const packageFiles = getPackageFiles ( packagePath )
4138
42- return checkPackageJsonEntryPoints ( packageJson , packageFiles ) && checkNpmIgnore ( packagePath , packageFiles )
39+ checkPackageJsonEntryPoints ( packageJson , packageFiles )
40+ checkNpmIgnore ( packagePath , packageFiles )
4341}
4442
4543function getPackageFiles ( packagePath : string ) : string [ ] {
@@ -53,23 +51,21 @@ function getPackageFiles(packagePath: string): string[] {
5351 return parsed [ 0 ] . files . map ( ( file ) => file . path )
5452}
5553
56- function checkPackageJsonEntryPoints ( packageJson : PackageJson , packageFiles : string [ ] ) : boolean {
54+ function checkPackageJsonEntryPoints ( packageJson : PackageJson , packageFiles : string [ ] ) {
5755 const filesFromPackageJsonEntryPoints = [ packageJson . main , packageJson . module , packageJson . types ] . filter ( Boolean )
5856
5957 for ( const file of filesFromPackageJsonEntryPoints ) {
6058 if ( ! packageFiles . includes ( file ) ) {
61- printError ( `File ${ file } used as an entry point in ${ packageJson . name } is missing from the package` )
62- return false
59+ throw new Error ( `File ${ file } used as an entry point in ${ packageJson . name } is missing from the package` )
6360 }
6461 }
65- return true
6662}
6763
6864// NPM will [always include some files][1] like `package.json` and `README.md`.
6965// [1]: https://docs.npmjs.com/cli/v9/using-npm/developers#keeping-files-out-of-your-package
7066const FILES_ALWAYS_INCLUDED_BY_NPM = [ 'package.json' , 'README.md' ]
7167
72- function checkNpmIgnore ( packagePath : string , packageFiles : string [ ] ) : boolean {
68+ function checkNpmIgnore ( packagePath : string , packageFiles : string [ ] ) {
7369 const npmIgnorePath = path . join ( packagePath , '.npmignore' )
7470 const npmNegatedIgnoreRules = fs
7571 . readFileSync ( npmIgnorePath , { encoding : 'utf8' } )
@@ -81,20 +77,16 @@ function checkNpmIgnore(packagePath: string, packageFiles: string[]): boolean {
8177 // Ensure that each file is explicitly included by checking if at least a negated rule matches it
8278 for ( const file of packageFiles ) {
8379 if ( ! FILES_ALWAYS_INCLUDED_BY_NPM . includes ( file ) && ! npmNegatedIgnoreRules . some ( ( rule ) => rule . match ( `/${ file } ` ) ) ) {
84- printError ( `File ${ file } is not explicitly included in ${ npmIgnorePath } ` )
85- return false
80+ throw new Error ( `File ${ file } is not explicitly included in ${ npmIgnorePath } ` )
8681 }
8782 }
8883
8984 // Ensure that expected files are correctly included by checking if each negated rule matches at least one file
9085 for ( const rule of npmNegatedIgnoreRules ) {
9186 if ( ! packageFiles . some ( ( file ) => rule . match ( `/${ file } ` ) ) ) {
92- printError ( `Rule ${ rule . pattern } does not match any file ${ npmIgnorePath } ` )
93- return false
87+ throw new Error ( `Rule ${ rule . pattern } does not match any file ${ npmIgnorePath } ` )
9488 }
9589 }
96-
97- return true
9890}
9991
10092function getPackageJson ( packagePath : string ) {
0 commit comments