@@ -10,39 +10,43 @@ import { cleanupTxzFiles } from "./utils/cleanup";
1010import  {  apiDir  }  from  "./utils/paths" ; 
1111import  {  getVendorBundleName ,  getVendorFullPath  }  from  "./build-vendor-store" ; 
1212import  {  getAssetUrl  }  from  "./utils/bucket-urls" ; 
13+ import  {  validateStandaloneManifest ,  getStandaloneManifestPath  }  from  "./utils/manifest-validator" ; 
1314
1415
15- // Recursively search  for manifest files 
16+ // Check  for manifest files in expected locations  
1617const  findManifestFiles  =  async  ( dir : string ) : Promise < string [ ] >  =>  { 
18+   const  files : string [ ]  =  [ ] ; 
19+   
20+   // Check standalone subdirectory (preferred) 
21+   try  { 
22+     const  standaloneDir  =  join ( dir ,  "standalone" ) ; 
23+     const  entries  =  await  readdir ( standaloneDir ,  {  withFileTypes : true  } ) ; 
24+     for  ( const  entry  of  entries )  { 
25+       if  ( entry . isFile ( )  &&  entry . name  ===  "standalone.manifest.json" )  { 
26+         files . push ( "standalone/standalone.manifest.json" ) ; 
27+       } 
28+     } 
29+   }  catch  ( error )  { 
30+     // Directory doesn't exist, continue checking other locations 
31+   } 
32+   
33+   // Check root directory for backwards compatibility 
1734  try  { 
1835    const  entries  =  await  readdir ( dir ,  {  withFileTypes : true  } ) ; 
19-     const  files : string [ ]  =  [ ] ; 
20- 
2136    for  ( const  entry  of  entries )  { 
22-       const  fullPath  =  join ( dir ,  entry . name ) ; 
23-       if  ( entry . isDirectory ( ) )  { 
24-         try  { 
25-           files . push ( ...( await  findManifestFiles ( fullPath ) ) ) ; 
26-         }  catch  ( error )  { 
27-           // Log and continue if a subdirectory can't be read 
28-           console . warn ( `Warning: Could not read directory ${ fullPath } ${ error . message }  ) ; 
29-         } 
30-       }  else  if  ( 
31-         entry . isFile ( )  && 
32-         entry . name  ===  "standalone.manifest.json" 
33-       )  { 
34-         files . push ( entry . name ) ; 
37+       if  ( entry . isFile ( )  &&  entry . name  ===  "standalone.manifest.json" )  { 
38+         files . push ( "standalone.manifest.json" ) ; 
3539      } 
3640    } 
37- 
38-     return  files ; 
3941  }  catch  ( error )  { 
4042    if  ( error . code  ===  'ENOENT' )  { 
4143      console . warn ( `Directory does not exist: ${ dir }  ) ; 
4244      return  [ ] ; 
4345    } 
4446    throw  error ;  // Re-throw other errors 
4547  } 
48+   
49+   return  files ; 
4650} ; 
4751
4852// Function to store vendor archive information in a recoverable location 
@@ -123,16 +127,41 @@ const validateSourceDir = async (validatedEnv: TxzEnv) => {
123127  } 
124128
125129  const  manifestFiles  =  await  findManifestFiles ( webcomponentDir ) ; 
126-   const  hasStandaloneManifest  =  manifestFiles . includes ( "standalone.manifest.json" ) ; 
130+   const  hasStandaloneManifest  =  manifestFiles . some ( file  =>  
131+     file  ===  "standalone.manifest.json"  ||  file  ===  "standalone/standalone.manifest.json" 
132+   ) ; 
127133
128134  // Only require standalone.manifest.json for new standalone apps 
129135  if  ( ! hasStandaloneManifest )  { 
130136    console . log ( "Existing Manifest Files:" ,  manifestFiles ) ; 
131137    throw  new  Error ( 
132138      `Webcomponents missing required file: standalone.manifest.json - `  + 
133-       `run 'pnpm build' in web to generate standalone.manifest.json` 
139+       `run 'pnpm build' in web to generate standalone.manifest.json in the standalone/ subdirectory ` 
134140    ) ; 
135141  } 
142+   
143+   // Validate the manifest contents 
144+   const  manifestPath  =  getStandaloneManifestPath ( webcomponentDir ) ; 
145+   if  ( manifestPath )  { 
146+     const  validation  =  await  validateStandaloneManifest ( manifestPath ) ; 
147+     
148+     if  ( ! validation . isValid )  { 
149+       console . error ( "Standalone manifest validation failed:" ) ; 
150+       validation . errors . forEach ( error  =>  console . error ( `  ❌ ${ error }  ) ) ; 
151+       if  ( validation . warnings . length  >  0 )  { 
152+         console . warn ( "Warnings:" ) ; 
153+         validation . warnings . forEach ( warning  =>  console . warn ( `  ⚠️  ${ warning }  ) ) ; 
154+       } 
155+       throw  new  Error ( "Standalone manifest validation failed. See errors above." ) ; 
156+     } 
157+     
158+     if  ( validation . warnings . length  >  0 )  { 
159+       console . warn ( "Standalone manifest validation warnings:" ) ; 
160+       validation . warnings . forEach ( warning  =>  console . warn ( `  ⚠️  ${ warning }  ) ) ; 
161+     } 
162+     
163+     console . log ( "✅ Standalone manifest validation passed" ) ; 
164+   } 
136165
137166  if  ( ! existsSync ( apiDir ) )  { 
138167    throw  new  Error ( `API directory ${ apiDir }  ) ; 
0 commit comments