Skip to content

Commit

Permalink
chore: use throttledPromise from kit, remove UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed May 23, 2023
1 parent 2fdb274 commit 56b603c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 118 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.8.2",
"@oclif/core": "^2.8.5",
"@salesforce/apex-node": "^1.6.0",
"@salesforce/core": "^3.36.1",
"@salesforce/kit": "^1.9.2",
"@salesforce/core": "^3.36.2",
"@salesforce/kit": "^3.0.1",
"@salesforce/sf-plugins-core": "^2.4.2",
"@salesforce/source-deploy-retrieve": "^8.4.0",
"@salesforce/source-tracking": "^3.1.5",
Expand Down
36 changes: 21 additions & 15 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
import { getString } from '@salesforce/ts-types';
import { SourceTracking, SourceConflictError } from '@salesforce/source-tracking';
import { Duration } from '@salesforce/kit';
import { Duration, ThrottledPromiseAll } from '@salesforce/kit';
import { Interfaces } from '@oclif/core';

import { DEFAULT_ZIP_FILE_NAME, ensuredDirFlag, zipFileFlag } from '../../../utils/flags';
Expand All @@ -30,7 +30,6 @@ import { MetadataRetrieveResultFormatter } from '../../../formatters/metadataRet
import { getPackageDirs } from '../../../utils/project';
import { RetrieveResultJson } from '../../../utils/types';
import { writeConflictTable } from '../../../utils/conflicts';
import { promisesQueue } from '../../../utils/promiseQueue';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'retrieve.start');
Expand Down Expand Up @@ -243,7 +242,8 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
}

private async moveResultsForRetrieveTargetDir(targetDir: string, resolvedTargetDir: string): Promise<void> {
async function mv(src: string): Promise<string[]> {
async function mv(s: unknown): Promise<string[]> {
const src = s as string;
let directories: string[] = [];
let files: string[] = [];
const srcStat = await fs.promises.stat(src);
Expand All @@ -265,26 +265,32 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
} else {
files.push(src);
}
await promisesQueue(
files,
async (file: string): Promise<string> => {
const dest = join(src.replace(join('main', 'default'), ''), file);
const destDir = dirname(dest);
await fs.promises.mkdir(destDir, { recursive: true });
await fs.promises.rename(join(src, file), dest);
return dest;
},
50
);
const throttled = new ThrottledPromiseAll({ concurrency: 50 });
throttled.add(files, async (file: unknown): Promise<string> => {
// the method type expects (arg: unknown) but we know it's a string
const f = file as string;
const dest = join(src.replace(join('main', 'default'), ''), f);
const destDir = dirname(dest);
await fs.promises.mkdir(destDir, { recursive: true });
await fs.promises.rename(join(src, f), dest);
return dest;
});
await throttled.all();
return directories;
}
// getFileResponses fails once the files have been moved, calculate where they're moved to, and then move them
this.retrieveResult.getFileResponses().forEach((fileResponse) => {
fileResponse.filePath = fileResponse.filePath?.replace(join('main', 'default'), '');
});
// move contents of 'main/default' to 'retrievetargetdir'
await promisesQueue([join(resolvedTargetDir, 'main', 'default')], mv, 5, true);
const throttled = new ThrottledPromiseAll({ concurrency: 50 });
throttled.add([join(resolvedTargetDir, 'main', 'default')], mv);
await throttled.all();
// remove 'main/default'

//

// please clear cache
await fs.promises.rm(join(targetDir, 'main'), { recursive: true });
}
}
Expand Down
38 changes: 0 additions & 38 deletions src/utils/promiseQueue.ts

This file was deleted.

5 changes: 5 additions & 0 deletions test/utils/errorCodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import { expect } from 'chai';
import { DEPLOY_STATUS_CODES_DESCRIPTIONS, DEPLOY_STATUS_CODES } from '../../src/utils/errorCodes';

//

//

// refact
describe('error codes', () => {
describe('help descriptions DEPLOY_STATUS_CODES_DESCRIPTIONS', () => {
it('creates an object with every status code as a key', () => {
Expand Down
62 changes: 0 additions & 62 deletions test/utils/promiseQueue.test.ts

This file was deleted.

67 changes: 67 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,27 @@
jsonwebtoken "9.0.0"
ts-retry-promise "^0.7.0"

"@salesforce/core@^3.36.2":
version "3.36.2"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.36.2.tgz#135fa2fb858da6245b9ecff1e7819aeaeead5150"
integrity sha512-IS1rR6Y0tMJYx/+TOAUQ9Gs+Vtum0MHLGfodT7ZJMQZQHEp1S4o0BJ8676uq5sASAnVL64GA+Et/LWCCOWWEuw==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.9.2"
"@salesforce/schemas" "^1.5.1"
"@salesforce/ts-types" "^1.7.2"
"@types/semver" "^7.3.13"
ajv "^8.12.0"
archiver "^5.3.0"
change-case "^4.1.2"
debug "^3.2.7"
faye "^1.4.0"
form-data "^4.0.0"
js2xmlparser "^4.0.1"
jsforce "^2.0.0-beta.23"
jsonwebtoken "9.0.0"
ts-retry-promise "^0.7.0"

"@salesforce/dev-config@^3.0.0", "@salesforce/dev-config@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@salesforce/dev-config/-/dev-config-3.1.0.tgz#8eb5b35860ff60d1c1dc3fd9329b01a28475d5b9"
Expand Down Expand Up @@ -1157,6 +1178,14 @@
shx "^0.3.3"
tslib "^2.5.0"

"@salesforce/kit@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-3.0.1.tgz#2375e96b0b22445b52069ca59474652febe8fd2e"
integrity sha512-pH0o7zNKRSjHOBPJeV2nUXrmYD9NsFfxxoVBaa66V7wXQH7OSBlO0/VvEAs1rKZ+MJELgSlpf6h9TajYqTYRrA==
dependencies:
"@salesforce/ts-types" "^2.0.1"
tslib "^2.5.2"

"@salesforce/plugin-command-reference@^2.4.4":
version "2.4.5"
resolved "https://registry.yarnpkg.com/@salesforce/plugin-command-reference/-/plugin-command-reference-2.4.5.tgz#2b9440306a1e11dce90638a05066378b5caff7ea"
Expand Down Expand Up @@ -1383,6 +1412,13 @@
dependencies:
tslib "^2.5.0"

"@salesforce/ts-types@^2.0.1":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@salesforce/ts-types/-/ts-types-2.0.2.tgz#44c2ab3a765b57a9a285f2be31a661ac5b373ac3"
integrity sha512-FxQnTtdn9mcnGpc6qxQbpP+0CnDY1OcMNM+QL+TgC5uSyxnzo6vBrK7OenrK9jdgfvJZAKH1PjeAj2QahbpBwQ==
dependencies:
tslib "^2.5.2"

"@sindresorhus/is@^4.0.0":
version "4.6.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f"
Expand Down Expand Up @@ -5448,6 +5484,32 @@ jsforce@^2.0.0-beta.21:
strip-ansi "^6.0.0"
xml2js "^0.5.0"

jsforce@^2.0.0-beta.23:
version "2.0.0-beta.23"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.23.tgz#5eeb1a2635498ee77f0726ababe089cc12113551"
integrity sha512-lfeLHbCJ40ela1JPu4VqgK1GtIzR0NQOMZ/Rxesv9Ty3PyxK18o01AQ4E+JqGAWDDQhwyUp2A/9V+uOqU3w7Rw==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/runtime-corejs3" "^7.12.5"
"@types/node" "^12.19.9"
abort-controller "^3.0.0"
base64url "^3.0.1"
commander "^4.0.1"
core-js "^3.6.4"
csv-parse "^4.8.2"
csv-stringify "^5.3.4"
faye "^1.4.0"
form-data "^4.0.0"
fs-extra "^8.1.0"
https-proxy-agent "^5.0.0"
inquirer "^7.0.0"
multistream "^3.1.0"
node-fetch "^2.6.1"
open "^7.0.0"
regenerator-runtime "^0.13.3"
strip-ansi "^6.0.0"
xml2js "^0.5.0"

[email protected]:
version "3.0.1"
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13"
Expand Down Expand Up @@ -8502,6 +8564,11 @@ tslib@^2, tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1,
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tslib@^2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.2.tgz#1b6f07185c881557b0ffa84b111a0106989e8338"
integrity sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
Expand Down

0 comments on commit 56b603c

Please sign in to comment.