@@ -4,9 +4,14 @@ import { join, extname } from "node:path";
44const rootDir = process . cwd ( ) ;
55const registryDir = join ( rootDir , "registry" , "default" ) ;
66const packageJsonPath = join ( rootDir , "package.json" ) ;
7+ const registryManifestPath = join ( rootDir , "registry.json" ) ;
78
89const packageJson = JSON . parse ( readFileSync ( packageJsonPath , "utf8" ) ) ;
910const declared = new Set ( Object . keys ( packageJson . dependencies ?? { } ) ) ;
11+ const registryManifest = JSON . parse ( readFileSync ( registryManifestPath , "utf8" ) ) ;
12+ const registryItem = ( registryManifest . items ?? [ ] ) . find ( ( item ) => item . name === "editor" ) ;
13+ const registryDeclared = new Set ( registryItem ?. dependencies ?? [ ] ) ;
14+ const IGNORED_PACKAGES = new Set ( [ "react" , "react-dom" ] ) ;
1015
1116const sourceFiles = [ ] ;
1217const walk = ( dir ) => {
@@ -56,26 +61,56 @@ const readImports = (source) => {
5661
5762walk ( registryDir ) ;
5863
59- const missing = new Map ( ) ;
64+ const missingInPackage = new Map ( ) ;
65+ const missingInRegistryManifest = new Map ( ) ;
6066for ( const file of sourceFiles ) {
6167 const source = readFileSync ( file , "utf8" ) ;
6268 for ( const specifier of readImports ( source ) ) {
6369 if ( ! isPackageImport ( specifier ) ) continue ;
6470 const packageName = toPackageName ( specifier ) ;
65- if ( declared . has ( packageName ) ) continue ;
66-
67- if ( ! missing . has ( packageName ) ) missing . set ( packageName , new Set ( ) ) ;
68- missing . get ( packageName ) . add ( specifier ) ;
71+ if ( IGNORED_PACKAGES . has ( packageName ) ) continue ;
72+ if ( ! declared . has ( packageName ) ) {
73+ if ( ! missingInPackage . has ( packageName ) ) missingInPackage . set ( packageName , new Set ( ) ) ;
74+ missingInPackage . get ( packageName ) . add ( specifier ) ;
75+ }
76+ if ( ! registryDeclared . has ( packageName ) ) {
77+ if ( ! missingInRegistryManifest . has ( packageName ) ) {
78+ missingInRegistryManifest . set ( packageName , new Set ( ) ) ;
79+ }
80+ missingInRegistryManifest . get ( packageName ) . add ( specifier ) ;
81+ }
6982 }
7083}
7184
72- if ( missing . size > 0 ) {
73- console . error ( "Registry dependency check failed. Missing dependencies:" ) ;
74- for ( const [ pkg , specifiers ] of missing . entries ( ) ) {
75- const used = Array . from ( specifiers ) . sort ( ) . join ( ", " ) ;
76- console . error ( `- ${ pkg } (imports: ${ used } )` ) ;
85+ if ( missingInPackage . size > 0 || missingInRegistryManifest . size > 0 ) {
86+ console . error ( "Registry dependency check failed." ) ;
87+ if ( missingInPackage . size > 0 ) {
88+ console . error ( "Missing from package.json dependencies:" ) ;
89+ for ( const [ pkg , specifiers ] of missingInPackage . entries ( ) ) {
90+ const used = Array . from ( specifiers ) . sort ( ) . join ( ", " ) ;
91+ console . error ( `- ${ pkg } (imports: ${ used } )` ) ;
92+ }
93+ }
94+ if ( missingInRegistryManifest . size > 0 ) {
95+ console . error ( "Missing from registry.json item dependencies:" ) ;
96+ for ( const [ pkg , specifiers ] of missingInRegistryManifest . entries ( ) ) {
97+ const used = Array . from ( specifiers ) . sort ( ) . join ( ", " ) ;
98+ console . error ( `- ${ pkg } (imports: ${ used } )` ) ;
99+ }
77100 }
78101 process . exit ( 1 ) ;
79102}
80103
104+ if ( ! registryItem ) {
105+ console . error ( 'Registry dependency check failed. Missing "editor" item in registry.json.' ) ;
106+ process . exit ( 1 ) ;
107+ }
108+
109+ for ( const pkg of registryDeclared ) {
110+ if ( ! declared . has ( pkg ) ) {
111+ console . error ( `Registry dependency check failed. "${ pkg } " is in registry.json but missing from package.json dependencies.` ) ;
112+ process . exit ( 1 ) ;
113+ }
114+ }
115+
81116console . log ( "Registry dependency check passed." ) ;
0 commit comments