Skip to content

Commit ad9dec5

Browse files
committed
fix: again with the promises
1 parent 71bafcf commit ad9dec5

8 files changed

+37
-32
lines changed

src/shared/localShadowRepo.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
/* eslint-disable no-console */
88

99
import { join as pathJoin } from 'path';
10-
// what's fsp? well, we'd like to fs.promises but can't until we upgrade node beyond 12
11-
import { promises as fsp, existsSync } from 'fs';
1210
import * as fs from 'fs';
1311
import { AsyncCreatable } from '@salesforce/kit';
1412
import { NamedPackageDir, Logger } from '@salesforce/core';
@@ -65,7 +63,7 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
6563
this.logger = await Logger.child('ShadowRepo');
6664
this.logger.debug('options for constructor are', this.options);
6765
// initialize the shadow repo if it doesn't exist
68-
if (!existsSync(this.gitDir)) {
66+
if (!fs.existsSync(this.gitDir)) {
6967
this.logger.debug('initializing git repo');
7068
await this.gitInit();
7169
}
@@ -76,12 +74,12 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
7674
*
7775
*/
7876
public async gitInit(): Promise<void> {
79-
await fsp.mkdir(this.gitDir, { recursive: true });
77+
await fs.promises.mkdir(this.gitDir, { recursive: true });
8078
await git.init({ fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
8179
}
8280

8381
public async delete(): Promise<string> {
84-
await fsp.rm(this.gitDir, { recursive: true, force: true });
82+
await fs.promises.rm(this.gitDir, { recursive: true, force: true });
8583
return this.gitDir;
8684
}
8785
/**
@@ -211,14 +209,14 @@ export class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
211209
private async stashIgnoreFile(): Promise<void> {
212210
if (!this.stashed) {
213211
this.stashed = true;
214-
await fsp.rename(pathJoin(this.projectPath, '.gitignore'), pathJoin(this.projectPath, '.BAK.gitignore'));
212+
await fs.promises.rename(pathJoin(this.projectPath, '.gitignore'), pathJoin(this.projectPath, '.BAK.gitignore'));
215213
}
216214
}
217215

218216
private async unStashIgnoreFile(): Promise<void> {
219217
if (this.stashed) {
220218
this.stashed = false;
221-
await fsp.rename(pathJoin(this.projectPath, '.BAK.gitignore'), pathJoin(this.projectPath, '.gitignore'));
219+
await fs.promises.rename(pathJoin(this.projectPath, '.BAK.gitignore'), pathJoin(this.projectPath, '.gitignore'));
222220
}
223221
}
224222
}

src/shared/remoteSourceTrackingService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/* eslint-disable @typescript-eslint/member-ordering */
99

1010
import * as path from 'path';
11-
import { promises as fs, existsSync } from 'fs';
11+
import * as fs from 'fs';
1212
import { retryDecorator } from 'ts-retry-promise';
1313
import { ConfigFile, Logger, Org, SfdxError, Messages } from '@salesforce/core';
1414
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
@@ -132,8 +132,8 @@ export class RemoteSourceTrackingService extends ConfigFile<RemoteSourceTracking
132132
public static async delete(orgId: string): Promise<string> {
133133
const fileToDelete = RemoteSourceTrackingService.getFilePath(orgId);
134134
// the file might not exist, in which case we don't need to delete it
135-
if (existsSync(fileToDelete)) {
136-
await fs.rm(fileToDelete, { recursive: true });
135+
if (fs.existsSync(fileToDelete)) {
136+
await fs.promises.rm(fileToDelete, { recursive: true });
137137
}
138138
return path.isAbsolute(fileToDelete) ? fileToDelete : path.join(process.cwd(), fileToDelete);
139139
}

src/sourceTracking.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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-
import { promises as fs } from 'fs';
7+
import * as fs from 'fs';
88
import * as path from 'path';
99
import { NamedPackageDir, Logger, Org, SfdxProject } from '@salesforce/core';
1010
import { getString } from '@salesforce/ts-types';
@@ -210,7 +210,7 @@ export class SourceTracking extends AsyncCreatable {
210210
.map((change) => change.filenames as string[])
211211
.flat()
212212
.filter(Boolean);
213-
await Promise.all(filenames.map((filename) => fs.unlink(filename)));
213+
await Promise.all(filenames.map((filename) => fs.promises.unlink(filename)));
214214
await Promise.all([
215215
this.updateLocalTracking({ deletedFiles: filenames }),
216216
this.updateRemoteTracking(

test/nuts/commands/basics.nut.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/* eslint-disable no-console */
99

1010
import * as path from 'path';
11-
import { promises as fs } from 'fs';
11+
import * as fs from 'fs';
1212

1313
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
1414
import { Env } from '@salesforce/kit';
@@ -72,8 +72,8 @@ describe('end-to-end-test for tracking with an org (single packageDir)', () => {
7272
it('sees a local delete in local status', async () => {
7373
const classDir = path.join(session.project.dir, 'force-app', 'main', 'default', 'classes');
7474
await Promise.all([
75-
fs.rm(path.join(classDir, 'TestOrderController.cls')),
76-
fs.rm(path.join(classDir, 'TestOrderController.cls-meta.xml')),
75+
fs.promises.rm(path.join(classDir, 'TestOrderController.cls')),
76+
fs.promises.rm(path.join(classDir, 'TestOrderController.cls-meta.xml')),
7777
]);
7878
const result = execCmd<StatusResult[]>('force:source:status --json --local', { ensureExitCode: 0 }).jsonOutput
7979
.result;

test/nuts/commands/conflicts.nut.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
1111

1212
import * as path from 'path';
13-
import { promises as fs } from 'fs';
13+
import * as fs from 'fs';
1414
import { expect } from 'chai';
1515

1616
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
@@ -70,9 +70,9 @@ describe('conflict detection and resolution', () => {
7070
'applications',
7171
'Ebikes.app-meta.xml'
7272
);
73-
await fs.writeFile(
73+
await fs.promises.writeFile(
7474
filePath,
75-
(await fs.readFile(filePath, { encoding: 'utf-8' })).replace('Lightning App Builder', 'App Builder')
75+
(await fs.promises.readFile(filePath, { encoding: 'utf-8' })).replace('Lightning App Builder', 'App Builder')
7676
);
7777
});
7878
it('can see the conflict in status', () => {

test/nuts/commands/forceIgnore.nut.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
1212

1313
import * as path from 'path';
14-
import { promises as fs } from 'fs';
14+
import * as fs from 'fs';
1515
import { expect } from 'chai';
1616
import * as shell from 'shelljs';
1717

@@ -36,7 +36,7 @@ describe('forceignore changes', () => {
3636
`sfdx force:apex:class:create -n IgnoreTest --outputdir ${classdir}`,
3737
],
3838
});
39-
originalForceIgnore = await fs.readFile(path.join(session.project.dir, '.forceignore'), 'utf8');
39+
originalForceIgnore = await fs.promises.readFile(path.join(session.project.dir, '.forceignore'), 'utf8');
4040
conn = await Connection.create({
4141
authInfo: await AuthInfo.create({
4242
username: (session.setup[0] as { result: { username: string } }).result?.username,
@@ -53,7 +53,7 @@ describe('forceignore changes', () => {
5353
it('will not push a file that was created, then ignored', async () => {
5454
// setup a forceIgnore with some file
5555
const newForceIgnore = originalForceIgnore + '\n' + `${classdir}/IgnoreTest.cls`;
56-
await fs.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore);
56+
await fs.promises.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore);
5757
// nothing should push
5858
const output = execCmd<PushPullResponse[]>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput.result;
5959
expect(output).to.deep.equal([]);
@@ -63,7 +63,7 @@ describe('forceignore changes', () => {
6363
// setup a forceIgnore with some file
6464
const newForceIgnore =
6565
originalForceIgnore + '\n' + `${classdir}/UnIgnoreTest.cls` + '\n' + `${classdir}/IgnoreTest.cls`;
66-
await fs.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore);
66+
await fs.promises.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore);
6767

6868
// add a file in the local source
6969
shell.exec(`sfdx force:apex:class:create -n UnIgnoreTest --outputdir ${classdir}`, {
@@ -79,7 +79,7 @@ describe('forceignore changes', () => {
7979

8080
it('will push files that are now un-ignored', async () => {
8181
// un-ignore the file
82-
await fs.writeFile(path.join(session.project.dir, '.forceignore'), originalForceIgnore);
82+
await fs.promises.writeFile(path.join(session.project.dir, '.forceignore'), originalForceIgnore);
8383

8484
// verify file pushed in results
8585
const unIgnoredOutput = execCmd<PushPullResponse[]>('force:source:push --json', { ensureExitCode: 0 }).jsonOutput
@@ -105,7 +105,10 @@ describe('forceignore changes', () => {
105105

106106
it('will not pull a remote file added to the ignore AFTER it is being tracked', async () => {
107107
// add that type to the forceignore
108-
await fs.writeFile(path.join(session.project.dir, '.forceignore'), originalForceIgnore + '\n' + classdir);
108+
await fs.promises.writeFile(
109+
path.join(session.project.dir, '.forceignore'),
110+
originalForceIgnore + '\n' + classdir
111+
);
109112

110113
// gets file into source tracking
111114
const statusOutput = execCmd<StatusResult[]>('force:source:status --json --remote', { ensureExitCode: 0 })

test/nuts/commands/resetClear.nut.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* eslint-disable no-console */
1212

1313
import * as path from 'path';
14-
import { promises as fs, existsSync } from 'fs';
14+
import * as fs from 'fs';
1515

1616
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
1717
import { expect } from 'chai';
@@ -25,7 +25,9 @@ let trackingFileFolder: string;
2525
let conn: Connection;
2626

2727
const getRevisionsAsArray = async (): Promise<MemberRevision[]> => {
28-
const revisionFile = JSON.parse(await fs.readFile(path.join(trackingFileFolder, 'maxRevision.json'), 'utf8'));
28+
const revisionFile = JSON.parse(
29+
await fs.promises.readFile(path.join(trackingFileFolder, 'maxRevision.json'), 'utf8')
30+
);
2931
return Reflect.ownKeys(revisionFile.sourceMembers).map((key) => revisionFile.sourceMembers[key] as MemberRevision);
3032
};
3133

@@ -58,10 +60,10 @@ describe('reset and clear', () => {
5860
});
5961

6062
it('local tracking file exists', () => {
61-
expect(existsSync(path.join(trackingFileFolder, 'localSourceTracking'))).to.equal(true);
63+
expect(fs.existsSync(path.join(trackingFileFolder, 'localSourceTracking'))).to.equal(true);
6264
});
6365
it('remote tracking file exists', () => {
64-
expect(existsSync(path.join(trackingFileFolder, 'maxRevision.json'))).to.equal(true);
66+
expect(fs.existsSync(path.join(trackingFileFolder, 'maxRevision.json'))).to.equal(true);
6567
});
6668
it('runs clear', () => {
6769
const clearResult = execCmd<SourceTrackingClearResult>('force:source:tracking:clear --noprompt --json', {
@@ -70,10 +72,10 @@ describe('reset and clear', () => {
7072
expect(clearResult.clearedFiles.some((file) => file.includes('maxRevision.json'))).to.equal(true);
7173
});
7274
it('local tracking is gone', () => {
73-
expect(existsSync(path.join(trackingFileFolder, 'localSourceTracking'))).to.equal(false);
75+
expect(fs.existsSync(path.join(trackingFileFolder, 'localSourceTracking'))).to.equal(false);
7476
});
7577
it('remote tracking is gone', () => {
76-
expect(existsSync(path.join(trackingFileFolder, 'maxRevision.json'))).to.equal(false);
78+
expect(fs.existsSync(path.join(trackingFileFolder, 'maxRevision.json'))).to.equal(false);
7779
});
7880
});
7981

@@ -98,7 +100,9 @@ describe('reset and clear', () => {
98100
// gets tracking files from server
99101
execCmd('force:source:status --json --remote', { ensureExitCode: 0 });
100102
const revisions = await getRevisionsAsArray();
101-
const revisionFile = JSON.parse(await fs.readFile(path.join(trackingFileFolder, 'maxRevision.json'), 'utf8'));
103+
const revisionFile = JSON.parse(
104+
await fs.promises.readFile(path.join(trackingFileFolder, 'maxRevision.json'), 'utf8')
105+
);
102106
lowestRevision = revisions.reduce(
103107
(previousValue, revision) => Math.min(previousValue, revision.serverRevisionCounter),
104108
revisionFile.serverMaxRevisionCounter

test/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "@salesforce/dev-config/tsconfig-test",
3-
"include": ["./**/*.ts"],
3+
"include": ["./**/*.ts", "nuts/commands/aura.nut.ts.future"],
44
"compilerOptions": {
55
"skipLibCheck": true
66
}

0 commit comments

Comments
 (0)