One-time Setup
Quick Start
Testing
Debugging
Linking the Source-Deploy-Retrieve Library
Running Commands
Useful Yarn Commands
- Install NodeJS. If you need to work with multiple versions of Node, you
might consider using nvm.
Suggestion: use the current LTS version of node. - Install yarn to manage node dependencies.
Suggestion: install yarn globally usingnpm install --global yarn
- Clone this repository from git. E.g., (ssh):
git clone git@github.com:salesforcecli/plugin-deploy-retrieve.git
- Configure git commit signing.
cd
into theplugin-deploy-retrieve
directory- Checkout the main branch:
git checkout main
- Get all latest changes:
git pull
- Download NPM dependencies:
yarn install
. If it's been a while since you last did this you may want to runyarn clean-all
before this step. - Build and lint the code:
yarn build
- Create a branch off main for new work:
git checkout -b <branch_name>
Suggestion: use branch_name format of initials/work-title. For external contributors, please fork the main branch of the repo instead and PR the fork to the main branch. - Make code changes and build:
yarn build
- Run changed commands:
./bin/dev.js project:deploy:start --help
- Write tests and run:
yarn test
(unit) and/oryarn test:nuts
(NUTs) - Show all changed files:
git status
- Add all files to staging:
git add .
- Commit staged files with helpful commit message:
git commit
- Push commit(s) to remote:
git push -u origin <branch_name>
- Create a pull request (PR) using the GitHub UI here.
All changes must have associated tests. This plugin uses a combination of unit testing and NUTs (non-unit tests).
Unit tests are run with yarn test
and use the mocha test framework. Tests are located in the test directory and are named with the pattern, <test-file>.test.ts
. E.g., start.test.ts. Reference the existing unit tests when writing and testing code changes.
Non-unit tests are run with yarn test:nuts
and use the cli-plugin-testkit framework. These tests run using the default devhub in your environment. NUTs are a way to test the library code in a real environment versus a unit test environment where many things are stubbed.
If you need to debug plugin code or tests you should refer to the excellent documentation on this topic in the Plugin Developer Guide.
When you want to use a local branch of a dependency, you'll need to link them together, to do so, follow these instructions:
- With the library changes built (e.g.,
yarn build
), link the library by runningyarn link
. cd
back toplugin-deploy-retrieve
and runyarn clean-all
.- Download NPM dependencies:
yarn install
. - Use the linked SDR library:
yarn link "@salesforce/source-deploy-retrieve"
. (this command will be printed after running theyarn link
command from step 1) - Build and lint the code:
yarn build
. If you get TypeScript module conflict errors during this step, see section below on TypeScript module conflicts.
During TypeScript compilation, you may see errors such as:
error TS2322: Type 'import(".../plugin-deploy-retrieve/node_modules/@salesforce/core/lib/org/connection").Connection' is not assignable to type 'import(".../source-deploy-retrieve/node_modules/@salesforce/core/lib/org/connection").Connection'.
This means the Connection
interface in the core library used by the plugin-deploy-retrieve is different from the Connection
interface in the core library used by the source-deploy-retrieve library, most likely because the core library dependencies are different versions.
To fix this we need to tell the TypeScript compiler to use 1 version of that library. To do this, temporarily modify the tsconfig.json file with the following lines inside the compilerOptions
section and recompile:
"baseUrl": ".",
"paths": {
"@salesforce/core": ["node_modules/@salesforce/core"]
}
If there are conflict errors in the tests then we need to make a similar modification to the test/tsconfig.json file. Note that the baseUrl
property for this modification points to the directory above:
"baseUrl": "..",
"paths": {
"@salesforce/core": ["node_modules/@salesforce/core"]
}
Note that these are temporary changes for linked compilation and should not be committed.
To run your modified plugin commands locally, use ./bin/dev.js
or ./bin/dev.cmd
file, which uses ts-node to execute the plugin's TypeScript commands.
# Run using local dev file.
./bin/dev project deploy start --help
There should be no differences when running via the Salesforce CLI or using the local scripts. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.
# Link your plugin to the sf cli
sf plugins:link .
# To verify
sf plugins
# To run
sf project deploy start --help
This downloads all NPM dependencies into the node_modules directory.
This compiles the typescript to javascript.
This lints all the typescript using eslint.
This compiles and lints all the typescript (e.g., yarn compile && yarn lint
).
This cleans all generated files and directories. Run yarn clean-all
to also clean up the node_module directories.
This runs unit tests (mocha) for the project using ts-node.
This runs NUTs (non-unit tests) for the project using ts-node.