@@ -80,7 +80,7 @@ export class ImportOrchestrator {
8080 resourceInfoList . push ( ...( await pluginManager . getMultipleResourceInfo (
8181 project . resourceConfigs . map ( ( r ) => r . type )
8282 ) ) ) ;
83- await ImportOrchestrator . saveResults ( reporter , importResult , project , resourceInfoList )
83+ await ImportOrchestrator . saveResults ( reporter , importResult , project , resourceInfoList , pluginManager )
8484 }
8585
8686 /** Update an existing project. This will use the existing resources as the parameters (no user input required). */
@@ -104,6 +104,7 @@ export class ImportOrchestrator {
104104 importResult ,
105105 resourceInfoList ,
106106 project . codifyFiles [ 0 ] ,
107+ pluginManager ,
107108 ) ;
108109 }
109110
@@ -147,28 +148,28 @@ export class ImportOrchestrator {
147148 private static matchTypeIds ( typeIds : string [ ] , validTypeIds : string [ ] ) : string [ ] {
148149 const result : string [ ] = [ ] ;
149150 const unsupportedTypeIds : string [ ] = [ ] ;
150-
151+
151152 for ( const typeId of typeIds ) {
152153 if ( ! typeId . includes ( '*' ) && ! typeId . includes ( '?' ) ) {
153154 const matched = validTypeIds . includes ( typeId ) ;
154155 if ( ! matched ) {
155156 unsupportedTypeIds . push ( typeId ) ;
156157 continue ;
157158 }
158-
159+
159160 result . push ( typeId )
160161 continue ;
161162 }
162-
163+
163164 const matched = validTypeIds . filter ( ( valid ) => wildCardMatch ( valid , typeId ) )
164165 if ( matched . length === 0 ) {
165166 unsupportedTypeIds . push ( typeId ) ;
166167 continue ;
167168 }
168-
169+
169170 result . push ( ...matched ) ;
170171 }
171-
172+
172173 if ( unsupportedTypeIds . length > 0 ) {
173174 throw new Error ( `The following resources cannot be imported. No plugins found that support the following types:
174175${ JSON . stringify ( unsupportedTypeIds ) } `) ;
@@ -213,7 +214,13 @@ ${JSON.stringify(unsupportedTypeIds)}`);
213214 ]
214215 }
215216
216- private static async saveResults ( reporter : Reporter , importResult : ImportResult , project : Project , resourceInfoList : ResourceInfo [ ] ) : Promise < void > {
217+ private static async saveResults (
218+ reporter : Reporter ,
219+ importResult : ImportResult ,
220+ project : Project ,
221+ resourceInfoList : ResourceInfo [ ] ,
222+ pluginManager : PluginManager ,
223+ ) : Promise < void > {
217224 const projectExists = ! project . isEmpty ( ) ;
218225 const multipleCodifyFiles = project . codifyFiles . length > 1 ;
219226
@@ -233,7 +240,7 @@ ${JSON.stringify(unsupportedTypeIds)}`);
233240 const file = multipleCodifyFiles
234241 ? project . codifyFiles [ await reporter . promptOptions ( '\nIf new resources are added, where to write them?' , project . codifyFiles ) ]
235242 : project . codifyFiles [ 0 ] ;
236- await ImportOrchestrator . updateExistingFiles ( reporter , project , importResult , resourceInfoList , file ) ;
243+ await ImportOrchestrator . updateExistingFiles ( reporter , project , importResult , resourceInfoList , file , pluginManager ) ;
237244 return ;
238245 }
239246
@@ -257,6 +264,7 @@ ${JSON.stringify(unsupportedTypeIds)}`);
257264 importResult : ImportResult ,
258265 resourceInfoList : ResourceInfo [ ] ,
259266 preferredFile : string , // File to write any new resources (unknown file path)
267+ pluginManager : PluginManager ,
260268 ) : Promise < void > {
261269 const groupedResults = groupBy ( importResult . result , ( r ) =>
262270 existingProject . findSpecific ( r . type , r . name ) ?. sourceMapKey ?. split ( '#' ) ?. [ 0 ] ?? 'unknown'
@@ -277,10 +285,17 @@ ${JSON.stringify(unsupportedTypeIds)}`);
277285 ImportOrchestrator . attachResourceInfo ( existing . resourceConfigs , resourceInfoList ) ;
278286
279287 const modificationCalculator = new FileModificationCalculator ( existing ) ;
280- const modification = modificationCalculator . calculate ( imported . map ( ( resource ) => ( {
281- modification : ModificationType . INSERT_OR_UPDATE ,
282- resource
283- } ) ) ) ;
288+ const modification = await modificationCalculator . calculate (
289+ imported . map ( ( resource ) => ( {
290+ modification : ModificationType . INSERT_OR_UPDATE ,
291+ resource
292+ } ) ) ,
293+ // Handle matching here since we need the plugin to determine if two configs represent the same underlying resource
294+ async ( resource , array ) => {
295+ const match = await pluginManager . match ( resource , array . filter ( ( r ) => r . type === resource . type ) ) ;
296+ return array . findIndex ( ( i ) => i . isDeepEqual ( match ) ) ;
297+ }
298+ ) ;
284299
285300 return { file : filePath ! , modification } ;
286301 } ) ) ;
0 commit comments