66 */
77import path from 'node:path' ;
88import fs from 'node:fs' ;
9- import { SfProject } from '@salesforce/core' ;
109import { glob } from 'glob' ;
1110import { parseStringPromise } from 'xml2js' ;
11+ import { SfProject } from '@salesforce/core' ;
1212
1313export type LwcMetadata = {
1414 LightningComponentBundle : {
@@ -26,33 +26,32 @@ export class ComponentUtils {
2626 return componentName . replace ( / ( [ A - Z ] ) / g, ' $1' ) . replace ( / ^ ./ , ( str ) => str . toUpperCase ( ) ) ;
2727 }
2828
29- public static async getComponentPaths ( project : SfProject ) : Promise < string [ ] > {
29+ public static async getNamespacePaths ( project : SfProject ) : Promise < string [ ] > {
3030 const packageDirs = project . getPackageDirectories ( ) ;
31- const namespacePaths = (
32- await Promise . all ( packageDirs . map ( ( dir ) => glob ( `${ dir . fullPath } /**/lwc` , { absolute : true } ) ) )
33- ) . flat ( ) ;
3431
35- return (
36- await Promise . all (
37- namespacePaths . map ( async ( namespacePath ) : Promise < string [ ] > => {
38- const children = await fs . promises . readdir ( namespacePath , { withFileTypes : true } ) ;
32+ return ( await Promise . all ( packageDirs . map ( ( dir ) => glob ( `${ dir . fullPath } /**/lwc` , { absolute : true } ) ) ) ) . flat ( ) ;
33+ }
3934
40- return children
41- . filter ( ( child ) => child . isDirectory ( ) )
42- . map ( ( child ) => path . join ( child . parentPath , child . name ) ) ;
43- } )
44- )
35+ public static async getAllComponentPaths ( namespacePaths : string [ ] ) : Promise < string [ ] > {
36+ return (
37+ await Promise . all ( namespacePaths . map ( ( namespacePath ) => ComponentUtils . getComponentPaths ( namespacePath ) ) )
4538 ) . flat ( ) ;
4639 }
4740
41+ public static async getComponentPaths ( namespacePath : string ) : Promise < string [ ] > {
42+ const children = await fs . promises . readdir ( namespacePath , { withFileTypes : true } ) ;
43+
44+ return children . filter ( ( child ) => child . isDirectory ( ) ) . map ( ( child ) => path . join ( child . parentPath , child . name ) ) ;
45+ }
46+
4847 public static async getComponentMetadata ( dirname : string ) : Promise < LwcMetadata | undefined > {
4948 const componentName = path . basename ( dirname ) ;
5049 const metaXmlPath = path . join ( dirname , `${ componentName } .js-meta.xml` ) ;
5150 if ( ! fs . existsSync ( metaXmlPath ) ) {
5251 return undefined ;
5352 }
5453
55- const xmlContent = fs . readFileSync ( metaXmlPath , 'utf8' ) ;
54+ const xmlContent = await fs . promises . readFile ( metaXmlPath , 'utf8' ) ;
5655 const parsedData = ( await parseStringPromise ( xmlContent ) ) as LwcMetadata ;
5756 if ( ! this . isLwcMetadata ( parsedData ) ) {
5857 return undefined ;
0 commit comments