From 93a01cf0dddded24a94c6a349c9950276f53b66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Di=C3=A9ffrei=20Quadros?= Date: Thu, 1 Aug 2024 22:15:07 -0300 Subject: [PATCH] fix(fht): fht/ft not being applied for post deployment (#101) * fix(fht): fht/ft not being applied for post deployment * chore: remove unecessary workingDirectory attribute on fht yml file path * Revert "chore: remove unecessary workingDirectory attribute on fht yml file path" This reverts commit a82cd0a85c67214c2dafea9a4800645b280813dc. * chore: set default value for working directory --- src/core/metadata/CustomFieldFetcher.ts | 54 ++++++++++++------- src/core/package/SfpPackage.ts | 2 +- .../deploymentCustomizers/FHTEnabler.ts | 3 +- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/core/metadata/CustomFieldFetcher.ts b/src/core/metadata/CustomFieldFetcher.ts index 033b653b7..611864adf 100644 --- a/src/core/metadata/CustomFieldFetcher.ts +++ b/src/core/metadata/CustomFieldFetcher.ts @@ -5,12 +5,12 @@ import { XMLParser } from 'fast-xml-parser'; import MetadataFetcher from './MetadataFetcher'; import { ComponentSet, + ComponentSetBuilder, MetadataConverter, - MetadataResolver, - ZipTreeContainer, + RegistryAccess, } from '@salesforce/source-deploy-retrieve'; import path from 'path'; -import { makeRandomId } from '../utils/RandomId'; +import { SfProject } from '@salesforce/core'; export default class CustomFieldFetcher extends MetadataFetcher { constructor(logger: Logger) { @@ -22,24 +22,42 @@ export default class CustomFieldFetcher extends MetadataFetcher { let retriveLocation = await this.fetchPackageFromOrg(org, { types: { name: 'CustomField', members: fields.length > 1 ? fields : fields[0] }, }); + const sfProjectJson = { + packageDirectories: [ + { + path: 'source', + default: true, + }, + ], + name: 'retrieve', + namespace: '', + sourceApiVersion: await org.retrieveMaxApiVersion() + }; + fs.mkdirpSync(path.join(retriveLocation.unzippedLocation, 'source')); + fs.writeFileSync( + path.join(retriveLocation.unzippedLocation, 'sfdx-project.json'), + JSON.stringify(sfProjectJson) + ); + //Write a force ignore file as its required for component set resolution + fs.writeFileSync(path.resolve(retriveLocation.unzippedLocation, '.forceignore'), '# .forceignore v2'); - const zipTree = await ZipTreeContainer.create(fs.readFileSync(retriveLocation.zipLocation)); - const zipResolver = new MetadataResolver(undefined, zipTree); - const zipComponents = zipResolver.getComponentsFromPath('.'); - let packageName = makeRandomId(6); - await new MetadataConverter().convert(zipComponents, 'source', { + let sfProject = await SfProject.resolve(retriveLocation.unzippedLocation); + let metadataConverter = new MetadataConverter(new RegistryAccess(undefined, sfProject.getPath())); + let componentSet = await ComponentSetBuilder.build({ + sourcepath: [path.resolve(retriveLocation.unzippedLocation)], + manifest: undefined, + metadata: undefined, + projectDir: sfProject.getPath(), + }); + await metadataConverter.convert(componentSet, 'source', { type: 'directory', - outputDirectory: path.join(retriveLocation.unzippedLocation, 'source'), - packageName: packageName + outputDirectory: path.join(retriveLocation.unzippedLocation,sfProject.getDefaultPackage().path), + genUniqueDir: false, }); - - //Write a force ignore file as its required for component set resolution - fs.writeFileSync(path.resolve(retriveLocation.unzippedLocation, 'source', '.forceignore'), '# .forceignore v2'); - let sourceBackedComponents = ComponentSet.fromSource(path.resolve(retriveLocation.unzippedLocation, 'source')); - - return {components:sourceBackedComponents,location:path.join(retriveLocation.unzippedLocation, 'source',packageName)} + return { + components: sourceBackedComponents, + location: path.join(retriveLocation.unzippedLocation, 'source'), + }; } - - } diff --git a/src/core/package/SfpPackage.ts b/src/core/package/SfpPackage.ts index 8b3f4fb6a..54620286a 100644 --- a/src/core/package/SfpPackage.ts +++ b/src/core/package/SfpPackage.ts @@ -53,7 +53,7 @@ class PackageInfo { export default class SfpPackage extends PackageInfo { public projectDirectory: string; - public workingDirectory: string; + public workingDirectory: string = ''; public mdapiDir: string; public destructiveChangesPath: string; public resolvedPackageDirectory: string; diff --git a/src/core/package/deploymentCustomizers/FHTEnabler.ts b/src/core/package/deploymentCustomizers/FHTEnabler.ts index a411fdbfb..843f8f172 100644 --- a/src/core/package/deploymentCustomizers/FHTEnabler.ts +++ b/src/core/package/deploymentCustomizers/FHTEnabler.ts @@ -92,7 +92,8 @@ export default class FHTEnabler extends MetdataDeploymentCustomizer { //Modify the component set //Parsing is risky due to various encoding, so do an inplace replacement - for (const sourceComponent of fetchedCustomFields.components.getSourceComponents()) { + let sourceComponents = fetchedCustomFields.components.getSourceComponents().toArray(); + for (const sourceComponent of sourceComponents) { let metadataOfComponent = fs.readFileSync(sourceComponent.xml).toString(); metadataOfComponent = metadataOfComponent.replace(