@@ -41,61 +41,71 @@ export class ComponentSetBuilder {
41
41
const csAggregator : ComponentLike [ ] = [ ] ;
42
42
43
43
const { sourcepath, manifest, metadata, packagenames, apiversion, sourceapiversion } = options ;
44
+ try {
45
+ if ( sourcepath ) {
46
+ logger . debug ( `Building ComponentSet from sourcepath: ${ sourcepath . toString ( ) } ` ) ;
47
+ sourcepath . forEach ( ( filepath ) => {
48
+ if ( fs . fileExistsSync ( filepath ) ) {
49
+ csAggregator . push ( ...ComponentSet . fromSource ( path . resolve ( filepath ) ) ) ;
50
+ } else {
51
+ throw new SfdxError ( `The sourcepath "${ filepath } " is not a valid source file path.` ) ;
52
+ }
53
+ } ) ;
54
+ }
44
55
45
- if ( sourcepath ) {
46
- logger . debug ( `Building ComponentSet from sourcepath: ${ sourcepath . toString ( ) } ` ) ;
47
- sourcepath . forEach ( ( filepath ) => {
48
- if ( fs . fileExistsSync ( filepath ) ) {
49
- csAggregator . push ( ...ComponentSet . fromSource ( path . resolve ( filepath ) ) ) ;
50
- } else {
51
- throw new SfdxError ( `The sourcepath "${ filepath } " is not a valid source file path.` ) ;
52
- }
53
- } ) ;
54
- }
55
-
56
- // Return empty ComponentSet and use packageNames in the library via `.retrieve` options
57
- if ( packagenames ) {
58
- logger . debug ( `Building ComponentSet for packagenames: ${ packagenames . toString ( ) } ` ) ;
59
- csAggregator . push ( ...new ComponentSet ( [ ] ) ) ;
60
- }
61
-
62
- // Resolve manifest with source in package directories.
63
- if ( manifest ) {
64
- logger . debug ( `Building ComponentSet from manifest: ${ manifest . manifestPath } ` ) ;
65
- const directoryPaths = options . manifest . directoryPaths ;
66
- logger . debug ( `Searching in packageDir: ${ directoryPaths . join ( ', ' ) } for matching metadata` ) ;
67
- const compSet = await ComponentSet . fromManifest ( {
68
- manifestPath : manifest . manifestPath ,
69
- resolveSourcePaths : options . manifest . directoryPaths ,
70
- forceAddWildcards : true ,
71
- } ) ;
72
- csAggregator . push ( ...compSet ) ;
73
- }
56
+ // Return empty ComponentSet and use packageNames in the library via `.retrieve` options
57
+ if ( packagenames ) {
58
+ logger . debug ( `Building ComponentSet for packagenames: ${ packagenames . toString ( ) } ` ) ;
59
+ csAggregator . push ( ...new ComponentSet ( [ ] ) ) ;
60
+ }
74
61
75
- // Resolve metadata entries with source in package directories.
76
- if ( metadata ) {
77
- logger . debug ( `Building ComponentSet from metadata: ${ metadata . metadataEntries . toString ( ) } ` ) ;
78
- const registry = new RegistryAccess ( ) ;
62
+ // Resolve manifest with source in package directories.
63
+ if ( manifest ) {
64
+ logger . debug ( `Building ComponentSet from manifest: ${ manifest . manifestPath } ` ) ;
65
+ const directoryPaths = options . manifest . directoryPaths ;
66
+ logger . debug ( `Searching in packageDir: ${ directoryPaths . join ( ', ' ) } for matching metadata` ) ;
67
+ const compSet = await ComponentSet . fromManifest ( {
68
+ manifestPath : manifest . manifestPath ,
69
+ resolveSourcePaths : options . manifest . directoryPaths ,
70
+ forceAddWildcards : true ,
71
+ } ) ;
72
+ csAggregator . push ( ...compSet ) ;
73
+ }
79
74
80
- // Build a Set of metadata entries
81
- const filter = new ComponentSet ( ) ;
82
- metadata . metadataEntries . forEach ( ( entry ) => {
83
- const splitEntry = entry . split ( ':' ) ;
84
- // try and get the type by name to ensure no typos or errors in type name
85
- // matches toolbelt functionality
86
- registry . getTypeByName ( splitEntry [ 0 ] ) ;
87
- filter . add ( {
88
- type : splitEntry [ 0 ] ,
89
- fullName : splitEntry . length === 1 ? '*' : splitEntry [ 1 ] ,
75
+ // Resolve metadata entries with source in package directories.
76
+ if ( metadata ) {
77
+ logger . debug ( `Building ComponentSet from metadata: ${ metadata . metadataEntries . toString ( ) } ` ) ;
78
+ const registry = new RegistryAccess ( ) ;
79
+
80
+ // Build a Set of metadata entries
81
+ const filter = new ComponentSet ( ) ;
82
+ metadata . metadataEntries . forEach ( ( entry ) => {
83
+ const splitEntry = entry . split ( ':' ) ;
84
+ // try and get the type by name to ensure no typos or errors in type name
85
+ // matches toolbelt functionality
86
+ registry . getTypeByName ( splitEntry [ 0 ] ) ;
87
+ filter . add ( {
88
+ type : splitEntry [ 0 ] ,
89
+ fullName : splitEntry . length === 1 ? '*' : splitEntry [ 1 ] ,
90
+ } ) ;
90
91
} ) ;
91
- } ) ;
92
92
93
- const directoryPaths = options . metadata . directoryPaths ;
94
- logger . debug ( `Searching for matching metadata in directories: ${ directoryPaths . join ( ', ' ) } ` ) ;
95
- const fromSource = ComponentSet . fromSource ( { fsPaths : directoryPaths , include : filter } ) ;
96
- // If no matching metadata is found, default to the original component set
97
- const finalized = fromSource . size > 0 ? fromSource : filter ;
98
- csAggregator . push ( ...finalized ) ;
93
+ const directoryPaths = options . metadata . directoryPaths ;
94
+ logger . debug ( `Searching for matching metadata in directories: ${ directoryPaths . join ( ', ' ) } ` ) ;
95
+ const fromSource = ComponentSet . fromSource ( { fsPaths : directoryPaths , include : filter } ) ;
96
+ // If no matching metadata is found, default to the original component set
97
+ const finalized = fromSource . size > 0 ? fromSource : filter ;
98
+ csAggregator . push ( ...finalized ) ;
99
+ }
100
+ } catch ( e ) {
101
+ if ( ( e as Error ) . message . includes ( 'Missing metadata type definition in registry for id' ) ) {
102
+ // to remain generic to catch missing metadata types regardless of parameters, split on '
103
+ // example message : Missing metadata type definition in registry for id 'NonExistentType'
104
+ const issueType = ( e as Error ) . message . split ( "'" ) [ 1 ] ;
105
+ throw new SfdxError ( `The specified metadata type is unsupported: [${ issueType } ]` ) ;
106
+ } else {
107
+ throw e ;
108
+ }
99
109
}
100
110
101
111
const componentSet = new ComponentSet ( csAggregator ) ;
0 commit comments