forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
953 stars 405 forks source link

String Replacement is not working with file saves or source push #4629

Closed tehnrd closed 1 year ago

tehnrd commented 1 year ago

Summary

The new string replacements functionality is not working when files are saved and deployed in VSCode, or when the command palette Push Source commands are run.

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_string_replace.htm

Steps To Reproduce:

Make sure the setting Salesforcedx-vscode-core › Push-or-deploy-on-save is enabled.

Setup a replacements config in sfdx-project.json file.

"replacements": [
    {
      "filename": "force-app/main/default/customMetadata/Settings.Org.md-meta.xml",
      "stringToReplace": "{{SECRET}}",
      "replaceWithEnv": "LANG"
    }
  ]

Save the file, or push the source with the command palette action.

Expected result

The values should be replaced when deployed to Salesforce.

Actual result

The values are not replaced, and the template strings are deployed instead.

Additional information

Salesforce Extension Version in VS Code: v56.14.0

SFDX CLI Version: sfdx-cli/7.182.1 darwin-x64 node-v18.12.1

OS and version: MacOS Monterey 12.3.1

AnanyaJha commented 1 year ago

@gbockus-sf If I'm understanding correctly, this is likely due to the following update ?

git2gus[bot] commented 1 year ago

This issue has been linked to a new work item: W-12446404

tehnrd commented 1 year ago

Just to be clear, sfdx cli used directly is working as expected, but trying to save a file in VSCode or push sources files in VSCode with the command palette is not replacing the secrets.

I was under the impression this string replacement code was added to SDR, and VSCode extension uses SDR, so the string replacement should work in VSCode as well.

RE: W-12446404, is this work item only to investigate? Or has this issue been confirmed as a bug?

gbockus-sf commented 1 year ago

Correct. The functionality was added to SDR. The WI is to update SDR to pick up the version that includes the change (and verify it behaves as expected when used in the VSCode context). We have to update the SF dependancies with care b/c it's a tangled web where an SDR upgrade likely comes with a @salesforce/core upgrade which means other deps that we have (like templates and apex) must also be the same version of core.

tehnrd commented 1 year ago

Got it, thanks for the insight!

pgonzaleznetwork commented 1 year ago

Sorry if this is not the right place, what is SDR?

gbockus-sf commented 1 year ago

@pgonzaleznetwork No worries...we love us some acronyms around here. SDR is just the short way of saying the source-deploy-retrieve library shared between sfdx and the Salesforce VSCode Extensions. https://github.com/forcedotcom/source-deploy-retrieve

tehnrd commented 5 days ago

UPDATE: upgraded global install of sf cli, restarted vscode, and appears to be working now. 👍🏻

It seems like it is still not working in VSCode.

Is there an ETA on updating the underlying SDR library?

For ISV's this is an incredibly helpful feature that we can't use.

gbockus-sf commented 3 days ago

HI @tehnrd The SDR library has been updated and should support this functionality in VSCode. The associated work item was closed back in June of 2023. If it's not working for you please let us know the current details

  1. How you setup your secret replace
  2. What CLI command is working
  3. What VSCode command is not working.

Thanks!

tehnrd commented 1 day ago

@gbockus-sf It is working. It was me not understanding how it works.

I was setting env vars in the CLI with export VAR=value but this was not being applied on deployment. This is because behind the scenes SDR spins up a new process/terminal which doesn't apply the values.

I modified my .zprofile file with the env vars, and it is working now. I also had to restart VSCode for the new values to get pulled in, but I need to do more testing on this part to confirm if VSCode restart is actually required.