Skip to content

Commit

Permalink
fix: guard against undefined file path in results (#659)
Browse files Browse the repository at this point in the history
* fix: guard against undefined file path in results

@W-12128219@

* fix: pass full path for target dir

@W-12134988@

* chore: remove rmdirSync in favor of rmSync

* chore: remove rmSync for rm

Co-authored-by: Willie Ruemmele <[email protected]>
  • Loading branch information
peternhale and WillieRuemmele authored Dec 1, 2022
1 parent c9f2991 commit 0262ea0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 59 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"main": "lib/index.js",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^1.18.0",
"@oclif/core": "^1.20.4",
"@oclif/plugin-help": "^3.3.1",
"@salesforce/apex-node": "^1.3.0",
"@salesforce/command": "^5.2.13",
"@salesforce/core": "^3.31.19",
"@salesforce/kit": "^1.7.1",
"@salesforce/source-deploy-retrieve": "^7.5.9",
"@salesforce/source-tracking": "^2.2.11",
"@salesforce/apex-node": "^1.4.0",
"@salesforce/command": "^5.2.27",
"@salesforce/core": "^3.32.4",
"@salesforce/kit": "^1.8.0",
"@salesforce/source-deploy-retrieve": "^7.5.13",
"@salesforce/source-tracking": "^2.2.14",
"chalk": "^4.1.2",
"got": "^11.8.3",
"jsforce": "^2.0.0-beta.19",
Expand Down
9 changes: 1 addition & 8 deletions src/commands/force/source/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,7 @@ export class Convert extends SourceCommand {
// SDR will build an output path like /output/directory/packageName/package.xml
// this was breaking from toolbelt, so to revert it we copy the directory up a level and delete the original
this.copyDir(this.convertResult.packagePath, outputDirectory);
try {
fs.rmSync(this.convertResult.packagePath, { recursive: true });
} catch (e) {
// rmdirSync is being deprecated and emits a warning
// but rmSync is introduced in node 14 so fall back to rmdirSync
fs.rmdirSync(this.convertResult.packagePath, { recursive: true });
}

fs.rmSync(this.convertResult.packagePath, { recursive: true });
this.convertResult.packagePath = outputDirectory;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/force/source/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Retrieve extends SourceCommand {
const mdapiRetrieve = await this.componentSet.retrieve({
usernameOrConnection: this.org.getUsername(),
merge: true,
output: this.getFlag<string>('retrievetargetdir') || this.project.getDefaultPackage().fullPath,
output: this.resolvedTargetDir || this.project.getDefaultPackage().fullPath,
packageOptions: this.getFlag<string[]>('packagenames'),
});

Expand Down Expand Up @@ -281,9 +281,9 @@ export class Retrieve extends SourceCommand {
// move contents of 'main/default' to 'retrievetargetdir'
await promisesQueue([join(this.resolvedTargetDir, 'main', 'default')], mv, 5, true);
// remove 'main/default'
await fs.promises.rmdir(join(this.flags.retrievetargetdir as string, 'main'), { recursive: true });
await fs.promises.rm(join(this.flags.retrievetargetdir as string, 'main'), { recursive: true });
this.retrieveResult.getFileResponses().forEach((fileResponse) => {
fileResponse.filePath = fileResponse.filePath.replace(join('main', 'default'), '');
fileResponse.filePath = fileResponse.filePath?.replace(join('main', 'default'), '');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/commands/source/retrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { join } from 'path';
import * as path from 'path';
import * as sinon from 'sinon';
import { expect } from 'chai';
import {
Expand Down Expand Up @@ -181,7 +182,7 @@ describe('force:source:retrieve', () => {
metadataEntries: ['ApexClass:MyClass'],
},
});
ensureRetrieveArgs({ output: sourcepath[0] });
ensureRetrieveArgs({ output: path.resolve(sourcepath[0]) });
ensureHookArgs();
});

Expand Down
2 changes: 1 addition & 1 deletion test/nuts/territory2.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('territories', () => {

it('retrieve without local metadata', async () => {
// delete and recreate an empty dir
await fs.promises.rmdir(path.join(session.project.dir, 'force-app'), { recursive: true });
await fs.promises.rm(path.join(session.project.dir, 'force-app'), { recursive: true });
await fs.promises.mkdir(path.join(session.project.dir, 'force-app'));
const retrieveResults = execCmd<RetrieveCommandResult>('force:source:retrieve -x package.xml --json', {
ensureExitCode: 0,
Expand Down
2 changes: 1 addition & 1 deletion test/nuts/translation.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('translations', () => {

it('retrieve without local metadata', async () => {
// delete and recreate an empty dir
await fs.promises.rmdir(path.join(session.project.dir, 'force-app'), { recursive: true });
await fs.promises.rm(path.join(session.project.dir, 'force-app'), { recursive: true });
await fs.promises.mkdir(path.join(session.project.dir, 'force-app'));
const retrieveResults = execCmd<RetrieveCommandResult>('force:source:retrieve -x package.xml --json', {
ensureExitCode: 0,
Expand Down
76 changes: 38 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
is-wsl "^2.1.1"
tslib "^2.3.1"

"@oclif/core@^1.12.0", "@oclif/core@^1.18.0", "@oclif/core@^1.20.0", "@oclif/core@^1.20.3", "@oclif/core@^1.20.4", "@oclif/core@^1.9.9":
"@oclif/core@^1.12.0", "@oclif/core@^1.20.0", "@oclif/core@^1.20.3", "@oclif/core@^1.20.4", "@oclif/core@^1.9.9":
version "1.20.4"
resolved "https://registry.npmjs.org/@oclif/core/-/core-1.20.4.tgz#7378b52e1f1b502e383ffb07f95dffc9fd8588ff"
integrity sha512-giug32M4YhSYNYKQwE1L57/+k5gp1+Bq3/0vKNQmzAY1tizFGhvBJc6GIRZasHjU+xtZLutQvrVrJo7chX3hxg==
Expand Down Expand Up @@ -934,13 +934,13 @@
resolved "https://registry.npmjs.org/@oclif/screen/-/screen-3.0.3.tgz#e679ad10535e31d333f809f7a71335cc9aef1e55"
integrity sha512-KX8gMYA9ujBPOd1HFsV9e0iEx7Uoj8AG/3YsW4TtWQTg4lJvr82qNm7o/cFQfYRIt+jw7Ew/4oL4A22zOT+IRA==

"@oclif/test@^2.2.10":
version "2.2.10"
resolved "https://registry.npmjs.org/@oclif/test/-/test-2.2.10.tgz#51b873df300bb7a4d2f24a30e3395cea7db95507"
integrity sha512-tz6tH79F0Kw1kWv/8BgTov+WtIeFDdq1PNUkW43U0Rh4HOA1SafPbXCpzhM9A6O7YXS+tq8ayuZdkyOXXJY6Ww==
"@oclif/test@^2.2.12":
version "2.2.12"
resolved "https://registry.yarnpkg.com/@oclif/test/-/test-2.2.12.tgz#bb97a8c678b349e0e323013be67d68f619e6aaf2"
integrity sha512-6s1XwvBTXHdVjVZY/qDgMl74NVvoy8MQoknqT/YfR9K3P/6fPW4xeZqemtvrvU4heM5kzSShta5sk0I28MXHMg==
dependencies:
"@oclif/core" "^1.20.3"
fancy-test "^2.0.6"
"@oclif/core" "^1.20.4"
fancy-test "^2.0.7"

"@octokit/auth-token@^2.4.4":
version "2.5.0"
Expand Down Expand Up @@ -1043,9 +1043,9 @@
dependencies:
"@octokit/openapi-types" "^12.11.0"

"@salesforce/apex-node@^1.3.0":
"@salesforce/apex-node@^1.4.0":
version "1.4.0"
resolved "https://registry.npmjs.org/@salesforce/apex-node/-/apex-node-1.4.0.tgz#27f88e4cc0d5265186f404dd027ffc96b0d35c23"
resolved "https://registry.yarnpkg.com/@salesforce/apex-node/-/apex-node-1.4.0.tgz#27f88e4cc0d5265186f404dd027ffc96b0d35c23"
integrity sha512-JA5+45RFqXaxKLfuns6uZc7nFKFznTGUmnqP5LfT3jgLopHOpru5j/Lcxamv5m4BK6O3QJzE+BwtAz6xu603sQ==
dependencies:
"@commitlint/config-conventional" "^17.2.0"
Expand Down Expand Up @@ -1085,29 +1085,29 @@
strip-ansi "6.0.1"
ts-retry-promise "^0.7.0"

"@salesforce/command@^5.2.1", "@salesforce/command@^5.2.13", "@salesforce/command@^5.2.15", "@salesforce/command@^5.2.16", "@salesforce/command@^5.2.23":
version "5.2.24"
resolved "https://registry.npmjs.org/@salesforce/command/-/command-5.2.24.tgz#17c25676f6737ef89ba5576e09db454853d21fd6"
integrity sha512-jpfETEIrBmg88GoznQw5fSl2Bck+m9kfqhPzrDj64aDwDughc1uUuQ5WX9MsgXW+auyBHpYpb5PIn74nLuDJqg==
"@salesforce/command@^5.2.1", "@salesforce/command@^5.2.15", "@salesforce/command@^5.2.16", "@salesforce/command@^5.2.23", "@salesforce/command@^5.2.27":
version "5.2.27"
resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-5.2.27.tgz#6440102fb5213a456a3722b8f8ad6bc4ce890efa"
integrity sha512-Mjp+8YfKRcQEf2DpBa1AXuyNkW9eUwiwd37eNdxR/tyksc71EiJ1Ex3hWcN4rHHLecjoAIyjhm4juCn/vXw+Bg==
dependencies:
"@oclif/core" "^1.20.4"
"@oclif/test" "^2.2.10"
"@salesforce/core" "^3.31.17"
"@oclif/test" "^2.2.12"
"@salesforce/core" "^3.32.1"
"@salesforce/kit" "^1.8.0"
"@salesforce/ts-types" "^1.7.1"
chalk "^2.4.2"

"@salesforce/core@^3.23.9", "@salesforce/core@^3.24.0", "@salesforce/core@^3.25.1", "@salesforce/core@^3.30.12", "@salesforce/core@^3.31.10", "@salesforce/core@^3.31.16", "@salesforce/core@^3.31.17", "@salesforce/core@^3.31.18", "@salesforce/core@^3.31.19", "@salesforce/core@^3.32.1":
version "3.32.1"
resolved "https://registry.npmjs.org/@salesforce/core/-/core-3.32.1.tgz#1a338a1985c58c1be819f99c6b33b24b32817cbe"
integrity sha512-hVcweKGy1CS3t0duS+0jxGVou5ZoQMXRZPQmcz1FyW31Oef5U07rhs3wTrwJqhCPHL817R/gm5V9wSRNcYdDtA==
"@salesforce/core@^3.23.9", "@salesforce/core@^3.24.0", "@salesforce/core@^3.25.1", "@salesforce/core@^3.30.12", "@salesforce/core@^3.31.10", "@salesforce/core@^3.31.17", "@salesforce/core@^3.31.18", "@salesforce/core@^3.31.19", "@salesforce/core@^3.32.1", "@salesforce/core@^3.32.4":
version "3.32.4"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.32.4.tgz#a0da998f2d2d19728071fdb2d3fa3e99df9f3072"
integrity sha512-owESbxDJUQX6mN8dYfSBug08C0t3RitlB9Y9Ev4AABDYoo7KyJj3XE8uPk6ffEI6OoyiMQFjuR5Z1yQDBfnV2A==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.8.0"
"@salesforce/schemas" "^1.1.0"
"@salesforce/schemas" "^1.4.0"
"@salesforce/ts-types" "^1.5.21"
"@types/graceful-fs" "^4.1.5"
"@types/semver" "^7.3.9"
"@types/semver" "^7.3.13"
ajv "^8.11.0"
archiver "^5.3.0"
change-case "^4.1.2"
Expand Down Expand Up @@ -1245,7 +1245,7 @@
resolved "https://registry.npmjs.org/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc"
integrity sha512-KExM355BLbxCW6siGBV7oUOotXvvVp0tAWERgzUkM2FcMb9fWrjwXDrIHc8V0UdDlA3UXtFltDWgN+Yqi+BA/g==

"@salesforce/schemas@^1.1.0":
"@salesforce/schemas@^1.4.0":
version "1.4.0"
resolved "https://registry.npmjs.org/@salesforce/schemas/-/schemas-1.4.0.tgz#7dff427c8059895d8108176047aee600703c82d6"
integrity sha512-BJ25uphssN42Zy6kksheFHMTLiR98AAHe/Wxnv0T4dYxtrEbUjSXVAGKZqfewJPFXA4xB5gxC+rQZtfz6xKCFg==
Expand All @@ -1262,12 +1262,12 @@
chalk "^4"
inquirer "^8.2.5"

"@salesforce/source-deploy-retrieve@^7.0.1", "@salesforce/source-deploy-retrieve@^7.5.2", "@salesforce/source-deploy-retrieve@^7.5.9":
version "7.5.9"
resolved "https://registry.npmjs.org/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-7.5.9.tgz#8919f186d434bee0a406db59bd0aae0a597c733f"
integrity sha512-NFB2ogQvwdpzjf3+c0MewXDgmY4B6uA1DRsf/fwIriNYsN3f96WI/BG5cf72HeHrhndaZ8/eBZp7yEPNLJTjjA==
"@salesforce/source-deploy-retrieve@^7.5.12", "@salesforce/source-deploy-retrieve@^7.5.13", "@salesforce/source-deploy-retrieve@^7.5.2":
version "7.5.13"
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-7.5.13.tgz#986b657d6965005441adb910df084e287621d375"
integrity sha512-Ug1XQGUewYCDgrNeiI6g/wYdmCs+kB2UDC6ocMqim2zoZ2dYXmZEI9tDqb+if/2WwAhM+PHedGOnUh+ks85LEw==
dependencies:
"@salesforce/core" "^3.31.17"
"@salesforce/core" "^3.32.1"
"@salesforce/kit" "^1.8.0"
"@salesforce/ts-types" "^1.7.1"
archiver "^5.3.1"
Expand Down Expand Up @@ -1298,15 +1298,15 @@
sinon "^10.0.0"
strip-ansi "^7.0.1"

"@salesforce/source-tracking@^2.2.11":
version "2.2.12"
resolved "https://registry.npmjs.org/@salesforce/source-tracking/-/source-tracking-2.2.12.tgz#c44e2c03e32d6ebb38ec69a83e06fb00066807a0"
integrity sha512-Clff5+mzkhwvz0cZYP8BNW4j0w6q1z7DzdTgwlSXedxBznTNgBPgsKn6ZGw7eOQOci5O2RknX+VedAcZKcRnUg==
"@salesforce/source-tracking@^2.2.14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-2.2.14.tgz#e6558ded979260181197070c513fdcd93514f03b"
integrity sha512-2EtQA2k4H1myTjWfm+PVtGqbfXgssAIdNiJdnqqsL2ViGACcG+Nv988qx2MevpQGeiy/MoMxowPkdkp6bmqBcw==
dependencies:
"@salesforce/core" "^3.31.16"
"@salesforce/kit" "^1.6.1"
"@salesforce/source-deploy-retrieve" "^7.0.1"
graceful-fs "^4.2.9"
"@salesforce/core" "^3.31.19"
"@salesforce/kit" "^1.8.0"
"@salesforce/source-deploy-retrieve" "^7.5.12"
graceful-fs "^4.2.10"
isomorphic-git "1.17.0"
ts-retry-promise "^0.7.0"

Expand Down Expand Up @@ -1703,7 +1703,7 @@
dependencies:
"@types/node" "*"

"@types/semver@^7.3.12", "@types/semver@^7.3.9":
"@types/semver@^7.3.12", "@types/semver@^7.3.13":
version "7.3.13"
resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91"
integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==
Expand Down Expand Up @@ -3786,9 +3786,9 @@ extract-stack@^2.0.0:
resolved "https://registry.npmjs.org/extract-stack/-/extract-stack-2.0.0.tgz#11367bc865bfcd9bc0db3123e5edb57786f11f9b"
integrity sha512-AEo4zm+TenK7zQorGK1f9mJ8L14hnTDi2ZQPR+Mub1NX8zimka1mXpV5LpH8x9HoUmFSHZCfLHqWvp0Y4FxxzQ==

fancy-test@^2.0.6:
fancy-test@^2.0.7:
version "2.0.7"
resolved "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.7.tgz#a5e8e23113384c5550914da4f429d10822622521"
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-2.0.7.tgz#a5e8e23113384c5550914da4f429d10822622521"
integrity sha512-E9qiHMi/Wf3y0PLwoRbgr8SRTcvQY+6gx9d/qaVNT6N5AQ79iZr08ftY2Ki5KRC5LS02GoVD/CYT4t/KwwC/Pw==
dependencies:
"@types/chai" "*"
Expand Down

0 comments on commit 0262ea0

Please sign in to comment.