Skip to content

Commit d9ed642

Browse files
authored
feat: use parking-orbit newer core/sdr (#77)
* feat: use parking-orbit newer core/sdr * chore: bump testkit dependency * chore: bump ts * chore: bump open pr deps * chore: handle null type from shelljs types update
1 parent 75455e5 commit d9ed642

File tree

5 files changed

+710
-615
lines changed

5 files changed

+710
-615
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/source-testkit",
33
"description": "testkit for running NUTs for source related commands",
4-
"version": "0.0.18",
4+
"version": "1.0.0",
55
"author": "Salesforce",
66
"license": "BSD-3-Clause",
77
"main": "lib/index.js",
@@ -30,26 +30,26 @@
3030
"!lib/**/*.map"
3131
],
3232
"dependencies": {
33-
"@salesforce/cli-plugins-testkit": "^1.2.0",
34-
"@salesforce/core": "^2.20.11",
33+
"@salesforce/cli-plugins-testkit": "^2.0.0",
34+
"@salesforce/core": "^3.19.1",
3535
"@salesforce/kit": "^1.4.5",
36-
"@salesforce/source-deploy-retrieve": "^4.0.2",
36+
"@salesforce/source-deploy-retrieve": "^6.0.2",
3737
"@salesforce/ts-types": "^1.5.5",
3838
"archiver": "^5.2.0",
3939
"chai-each": "^0.0.1",
4040
"debug": "^4.3.1",
4141
"shelljs": "^0.8.4",
4242
"sinon": "^10.0.0",
43-
"strip-ansi": "^6.0.0"
43+
"strip-ansi": "^7.0.1"
4444
},
4545
"devDependencies": {
4646
"@salesforce/dev-config": "^3.0.0",
47-
"@salesforce/dev-scripts": "^2.0.0",
47+
"@salesforce/dev-scripts": "^2.0.2",
4848
"@salesforce/prettier-config": "^0.0.2",
4949
"@salesforce/ts-sinon": "^1.3.5",
5050
"@types/archiver": "^5.1.0",
5151
"@types/debug": "^4.1.5",
52-
"@types/shelljs": "^0.8.8",
52+
"@types/shelljs": "^0.8.11",
5353
"@typescript-eslint/eslint-plugin": "^4.15.2",
5454
"@typescript-eslint/parser": "^4.15.2",
5555
"chai": "^4.3.0",
@@ -59,7 +59,7 @@
5959
"eslint-config-prettier": "^8.1.0",
6060
"eslint-config-salesforce": "^0.1.6",
6161
"eslint-config-salesforce-license": "^0.1.6",
62-
"eslint-config-salesforce-typescript": "^0.2.7",
62+
"eslint-config-salesforce-typescript": "^0.2.8",
6363
"eslint-plugin-header": "^3.1.1",
6464
"eslint-plugin-import": "^2.22.1",
6565
"eslint-plugin-jsdoc": "^32.2.0",
@@ -71,7 +71,7 @@
7171
"pretty-quick": "^3.1.0",
7272
"sinon": "^10.0.0",
7373
"ts-node": "^10.0.0",
74-
"typescript": "^4.1.3"
74+
"typescript": "^4.7.2"
7575
},
7676
"config": {
7777
"commitizen": {

src/assertions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
7+
import * as fs from 'fs';
88
import * as path from 'path';
99
import { expect, use } from 'chai';
1010
import * as chaiEach from 'chai-each';
1111
import { JsonMap, Nullable } from '@salesforce/ts-types';
1212
import * as fg from 'fast-glob';
13-
import { Connection, fs } from '@salesforce/core';
13+
import { Connection } from '@salesforce/core';
1414
import { FileResponse, MetadataResolver } from '@salesforce/source-deploy-retrieve';
1515
import { debug, Debugger } from 'debug';
1616
import { ApexClass, ApexTestResult, Commands, Context, SourceMember, SourceState, StatusResult } from './types';
@@ -157,7 +157,7 @@ export class Assertions {
157157
*/
158158
public async fileToExist(file: string): Promise<void> {
159159
const fullPath = file.startsWith(this.projectDir) ? file : path.join(this.projectDir, file);
160-
const fileExists = await fs.fileExists(fullPath);
160+
const fileExists = fs.existsSync(fullPath);
161161
expect(fileExists, `${fullPath} to exist`).to.be.true;
162162
}
163163

@@ -197,7 +197,7 @@ export class Assertions {
197197
public async filesToNotContainString(glob: string, ...strings: string[]): Promise<void> {
198198
const files = await this.doGlob([glob]);
199199
for (const file of files) {
200-
const contents = await fs.readFile(file, 'UTF-8');
200+
const contents = await fs.promises.readFile(file, 'utf-8');
201201
for (const str of strings) {
202202
expect(contents, `expect ${file} to not include ${str}`).to.not.include(str);
203203
}
@@ -210,7 +210,7 @@ export class Assertions {
210210
public async filesToContainString(glob: string, ...strings: string[]): Promise<void> {
211211
const files = await this.doGlob([glob]);
212212
for (const file of files) {
213-
const contents = await fs.readFile(file, 'UTF-8');
213+
const contents = await fs.promises.readFile(file, 'utf-8');
214214
for (const str of strings) {
215215
expect(contents, `expect ${file} to not include ${str}`).to.include(str);
216216
}

src/fileTracker.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
7+
import * as fs from 'fs';
88
import * as path from 'path';
9-
import { fs } from '@salesforce/core';
9+
import * as crypto from 'crypto';
1010
import { Nullable } from '@salesforce/ts-types';
1111
import { Context } from './types';
1212

@@ -82,10 +82,12 @@ export class FileTracker {
8282
private async getContentHash(file: string): Promise<Nullable<string>> {
8383
const filePath = this.getFullPath(file);
8484
try {
85-
const filestat = await fs.stat(filePath);
85+
const filestat = await fs.promises.stat(filePath);
8686
const isDirectory = filestat.isDirectory();
87-
const contents = isDirectory ? (await fs.readdir(filePath)).toString() : await fs.readFile(filePath);
88-
return fs.getContentHash(contents);
87+
const contents = isDirectory
88+
? (await fs.promises.readdir(filePath)).toString()
89+
: await fs.promises.readFile(filePath);
90+
return crypto.createHash('sha1').update(contents).digest('hex');
8991
} catch {
9092
return null;
9193
}
@@ -109,7 +111,7 @@ export namespace FileTracker {
109111
* Returns all files in directory that match the filter
110112
*/
111113
export async function traverseForFiles(dirPath: string, regexFilter = /./, allFiles: string[] = []): Promise<string[]> {
112-
const files = await fs.readdir(dirPath);
114+
const files = await fs.promises.readdir(dirPath);
113115

114116
for (const file of files) {
115117
const filePath = path.join(dirPath, file);

src/testkit.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
import * as path from 'path';
1111
import * as os from 'os';
12+
import * as fs from 'fs';
1213
import * as fg from 'fast-glob';
1314
import { exec, find, mv, rm, which } from 'shelljs';
1415
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
15-
import { AsyncCreatable, Env, set } from '@salesforce/kit';
16+
import { AsyncCreatable, Env, set, parseJsonMap } from '@salesforce/kit';
1617
import { AnyJson, Dictionary, ensureString, get, JsonMap, Nullable } from '@salesforce/ts-types';
17-
import { AuthInfo, Config, Connection, fs, NamedPackageDir, SfdxProject } from '@salesforce/core';
18+
import { AuthInfo, SfdxPropertyKeys, Connection, NamedPackageDir, SfdxProject } from '@salesforce/core';
1819
import { debug, Debugger } from 'debug';
1920
import { MetadataResolver } from '@salesforce/source-deploy-retrieve';
2021
import { Commands, Result, StatusResult } from './types';
@@ -74,7 +75,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
7475

7576
public constructor(options: SourceTestkit.Options) {
7677
super(options);
77-
this.executable = options.executable || which('sfdx').stdout;
78+
this.executable = options.executable ?? which('sfdx')?.stdout ?? 'sfdx';
7879
this.repository = options.repository;
7980
this.orgless = !!options.orgless;
8081
this.setupCommands = options.setupCommands || [];
@@ -209,7 +210,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
209210
const files = await this.doGlob(globs);
210211
const returnValue: Dictionary<string> = {};
211212
for (const file of files) {
212-
returnValue[file] = await fs.readFile(file, 'UTF-8');
213+
returnValue[file] = await fs.promises.readFile(file, 'utf8');
213214
}
214215
return returnValue;
215216
}
@@ -219,30 +220,30 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
219220
*/
220221
public async readSourcePathInfos(): Promise<AnyJson> {
221222
const sourcePathInfosPath = path.join(this.projectDir, '.sfdx', 'orgs', this.username, 'sourcePathInfos.json');
222-
return fs.readJson(sourcePathInfosPath);
223+
return JSON.parse(await fs.promises.readFile(sourcePathInfosPath, 'utf8')) as AnyJson;
223224
}
224225

225226
/**
226227
* Read the org's maxRevision.json
227228
*/
228229
public async readMaxRevision(): Promise<{ sourceMembers: JsonMap }> {
229230
const maxRevisionPath = path.join(this.projectDir, '.sfdx', 'orgs', this.username, 'maxRevision.json');
230-
return fs.readJson(maxRevisionPath) as unknown as { sourceMembers: JsonMap };
231+
return JSON.parse(await fs.promises.readFile(maxRevisionPath, 'utf8')) as { sourceMembers: JsonMap };
231232
}
232233

233234
/**
234235
* Write the org's maxRevision.json
235236
*/
236237
public async writeMaxRevision(contents: JsonMap): Promise<void> {
237238
const maxRevisionPath = path.join(this.projectDir, '.sfdx', 'orgs', this.username, 'maxRevision.json');
238-
return fs.writeJson(maxRevisionPath, contents);
239+
return fs.promises.writeFile(maxRevisionPath, JSON.stringify(contents));
239240
}
240241

241242
/**
242243
* Write file
243244
*/
244245
public async writeFile(filename: string, contents: string): Promise<void> {
245-
return fs.writeFile(filename, contents);
246+
return fs.promises.writeFile(filename, contents);
246247
}
247248

248249
/**
@@ -256,7 +257,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
256257
</Package>
257258
`;
258259
const packageXmlPath = path.join(this.projectDir, 'package.xml');
259-
await fs.writeFile(packageXmlPath, packageXml);
260+
await fs.promises.writeFile(packageXmlPath, packageXml);
260261
return packageXmlPath;
261262
}
262263

@@ -265,15 +266,15 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
265266
*/
266267
public async deleteSourcePathInfos(): Promise<void> {
267268
const sourcePathInfosPath = path.join(this.projectDir, '.sfdx', 'orgs', this.username, 'sourcePathInfos.json');
268-
return fs.unlink(sourcePathInfosPath);
269+
return fs.promises.unlink(sourcePathInfosPath);
269270
}
270271

271272
/**
272273
* Delete the org's maxRevision.json
273274
*/
274275
public async deleteMaxRevision(): Promise<void> {
275276
const maxRevisionPath = path.join(this.projectDir, '.sfdx', 'orgs', this.username, 'maxRevision.json');
276-
return fs.unlink(maxRevisionPath);
277+
return fs.promises.unlink(maxRevisionPath);
277278
}
278279

279280
/**
@@ -282,7 +283,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
282283
public async deleteGlobs(globs: string[]): Promise<void> {
283284
const files = await this.doGlob(globs);
284285
for (const file of files) {
285-
await fs.unlink(file);
286+
await fs.promises.unlink(file);
286287
}
287288
}
288289

@@ -291,8 +292,8 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
291292
*/
292293
public async deleteAllSourceFiles(): Promise<void> {
293294
for (const pkg of this.packagePaths) {
294-
await fs.rmdir(pkg, { recursive: true });
295-
await fs.mkdirp(pkg);
295+
await fs.promises.rm(pkg, { recursive: true });
296+
await fs.promises.mkdir(pkg, { recursive: true });
296297
}
297298
}
298299

@@ -312,9 +313,9 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
312313
*/
313314
public async modifyLocalFile(file: string, append = os.EOL): Promise<void> {
314315
const fullPath = file.startsWith(this.projectDir) ? file : path.join(this.projectDir, file);
315-
let contents = await fs.readFile(fullPath, 'UTF-8');
316+
let contents = await fs.promises.readFile(fullPath, 'utf-8');
316317
contents += append;
317-
await fs.writeFile(fullPath, contents);
318+
await fs.promises.writeFile(fullPath, contents);
318319
await this.fileTracker.update(fullPath, 'modified file');
319320
}
320321

@@ -330,7 +331,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
330331
.sobject('QuickActionDefinition')
331332
.find({ DeveloperName: 'NutAction' }, ['ID']))!;
332333
const updateRequest = {
333-
Id: result[0].Id,
334+
Id: result[0].Id as string,
334335
Description: 'updated description',
335336
};
336337
await this.connection?.tooling.sobject('QuickActionDefinition').update(updateRequest);
@@ -348,7 +349,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
348349
try {
349350
fs.copyFileSync(src, dest);
350351
} catch {
351-
await fs.mkdirp(path.dirname(dest));
352+
await fs.promises.mkdir(path.dirname(dest), { recursive: true });
352353
fs.copyFileSync(src, dest);
353354
}
354355
}
@@ -488,7 +489,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
488489
.replace(SourceTestkit.LocalProdPath, '')
489490
.replace(SourceTestkit.LocalDevPath, '');
490491
const pkgJsonPath = path.join(npmPackagePath, 'package.json');
491-
const pkgJson = (await fs.readJsonMap(pkgJsonPath)) as { oclif: { bin: string } };
492+
const pkgJson = parseJsonMap<{ oclif: { bin: string } }>(await fs.promises.readFile(pkgJsonPath, 'utf8'));
492493
return pkgJson.oclif.bin as Executable;
493494
} else {
494495
return path.basename(this.executable) as Executable;
@@ -536,7 +537,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
536537
}
537538

538539
private async getDefaultUsername(): Promise<string> {
539-
const configVar = this.executableName === Executable.SF ? 'target-org' : Config.DEFAULT_USERNAME;
540+
const configVar = this.executableName === Executable.SF ? 'target-org' : SfdxPropertyKeys.DEFAULT_USERNAME;
540541
const configResult = execCmd(`config:get ${configVar} --json`).jsonOutput!;
541542
const results = get(configResult, 'result', configResult) as Array<{ key?: string; name?: string; value: string }>;
542543
const username = results.find((r) => r.key === configVar || r.name === configVar)!.value;

0 commit comments

Comments
 (0)