forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

Backslashes in comments in `.forceignore` produce warnings on `deploy`/`retrieve` #3127

Open AndrewStopchenko-SO opened 4 days ago

AndrewStopchenko-SO commented 4 days ago

Summary

When .forceignore file contains backslashes \ in the comments (for whatever reason...), sf project retrieve start and sf project deploy start commands add multiple warning messages as below:

Warning: Your .forceignore file incorrectly uses the backslash ("\") as a folder separator; it should use the slash ("/") instead. The ignore rules will not work as expected until you fix this.

Why backslashes occurred in your .forceignore file?

When some files are failing to deploy, we happened to add ignore pattern and included problem with filepath in the comment to that ignored pattern, and the filepath in the deploy failure messages was shown with backslashes (on Windows). 🙂

Steps To Reproduce

Expected result

Backslashes in comments should be ignored, the warning should only react to baskslashes used in the ignored path patterns.

Actual result

Warning is displayed (even multiple times in case of retrieve operation).
This is especially annoying when running sf project retrieve start in the project where many components exist, then these messages are flooding the terminal buffer.

System Information

CLI:
@salesforce/cli/2.67.7 win32-x64 node-v22.11.0

Plugin Version:
@oclif/plugin-autocomplete 3.2.8 (core)
@oclif/plugin-commands 4.1.8 (core)
@oclif/plugin-help 6.2.16 (core)
@oclif/plugin-not-found 3.2.25 (core)
@oclif/plugin-plugins 5.4.15 (core)
@oclif/plugin-search 1.2.14 (core)
@oclif/plugin-update 4.6.10 (core)
@oclif/plugin-version 2.2.15 (core)
@oclif/plugin-warn-if-update-available 3.1.21 (core)
@oclif/plugin-which 3.2.17 (core)
@salesforce/cli 2.67.7 (core)
apex 3.6.2 (core)
api 1.3.2 (core)
auth 3.6.73 (core)
data 3.11.3 (core)
deploy-retrieve 3.15.11 (core)
info 3.4.18 (core)
limits 3.3.39 (core)
marketplace 1.3.4 (core)
org 5.1.4 (core)
packaging 2.9.0 (core)
schema 3.3.40 (core)
settings 2.4.4 (core)
sobject 1.4.45 (core)
telemetry 3.6.20 (core)
templates 56.3.29 (core)
trust 3.7.41 (core)
user 3.6.2 (core)
@salesforce/sfdx-scanner 4.7.0 (user)
SF ENV. VARS.
SF_AUTOUPDATE_DISABLE,true
SF_BINPATH,C:\Users\USER_NAME\AppData\Local\sf\client\bin\sf
SF_DISABLE_AUTOUPDATE,true
SF_UPDATE_INSTRUCTIONS,Use "npm update --global @salesforce/cli" to update npm-based installations.
Windows: true
Shell: powershell
Channel: stable

Diagnostics

:white_check_mark: pass - salesforcedx plugin isn’t installed :white_check_mark: pass - you don't have any linked plugins :x: unknown - using latest or latest-rc CLI version :white_check_mark: pass - [@salesforce/plugin-deploy-retrieve] sourceApiVersion matches apiVersion :white_check_mark: pass - [@salesforce/plugin-deploy-retrieve] default target DevHub max apiVersion matches default target org max apiVersion :white_check_mark: pass - [@salesforce/plugin-deploy-retrieve] sourceApiVersion matches default target org max apiVersion :white_check_mark: pass - can access: https://test.salesforce.com :white_check_mark: pass - can access: https://appexchange.salesforce.com/services/data :white_check_mark: pass - can access: https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-win32-x64-buildmanifest

> sf version --verbose --json output:

{
  "architecture": "win32-x64",
  "cliVersion": "@salesforce/cli/2.67.7",
  "nodeVersion": "node-v22.11.0",
  "osVersion": "Windows_NT 10.0.19045",
  "rootPath": "C:\\Users\\USER_NAME\\AppData\\Local\\sf\\client\\2.67.7-3acb081",
  "shell": "powershell",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.2.8 (core)",
    "@oclif/plugin-commands 4.1.8 (core)",
    "@oclif/plugin-help 6.2.16 (core)",
    "@oclif/plugin-not-found 3.2.25 (core)",
    "@oclif/plugin-plugins 5.4.15 (core)",
    "@oclif/plugin-search 1.2.14 (core)",
    "@oclif/plugin-update 4.6.10 (core)",
    "@oclif/plugin-version 2.2.15 (core)",
    "@oclif/plugin-warn-if-update-available 3.1.21 (core)",
    "@oclif/plugin-which 3.2.17 (core)",
    "@salesforce/cli 2.67.7 (core)",
    "apex 3.6.2 (core)",
    "api 1.3.2 (core)",
    "auth 3.6.73 (core)",
    "data 3.11.3 (core)",
    "deploy-retrieve 3.15.11 (core)",
    "info 3.4.18 (core)",
    "limits 3.3.39 (core)",
    "marketplace 1.3.4 (core)",
    "org 5.1.4 (core)",
    "packaging 2.9.0 (core)",
    "schema 3.3.40 (core)",
    "settings 2.4.4 (core)",
    "sobject 1.4.45 (core)",
    "telemetry 3.6.20 (core)",
    "templates 56.3.29 (core)",
    "trust 3.7.41 (core)",
    "user 3.6.2 (core)",
    "@salesforce/sfdx-scanner 4.7.0 (user)"
  ]
}
WillieRuemmele commented 4 days ago

we probably just need to update the regex to exclude comments 💡

AndrewStopchenko-SO commented 4 days ago

we probably just need to update the regex to exclude comments 💡

I believe this is the place where it checks the whole .forceignore file's content for backslashes: https://github.com/forcedotcom/source-deploy-retrieve/blob/main/src/resolve/forceIgnore.ts#L28

I am curious though why the warning "spams" multiple times in the terminal during the sf project retrieve start CLI command (on some larger projects)...

WillieRuemmele commented 4 days ago

you're correct. I actually have that open and was modifying it now!!

it seems like every time the forceignore class is constructed, it scans the file for \, and emits the warning, during the deploy we check the file in different steps, so multiple warnings

I'm changing it so it goes line by line, and checks if it's a commented line # and includes \