Skip to content

Commit

Permalink
Revert "fix: added flushFilePath() (#4240)"
Browse files Browse the repository at this point in the history
This reverts commit 6b563ec.
  • Loading branch information
gbockus-sf committed Jul 8, 2022
1 parent ddca4c9 commit c09c287
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 226 deletions.
31 changes: 9 additions & 22 deletions packages/salesforcedx-utils-vscode/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,19 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

export {
ensureDirectoryExists,
getTestResultsFolder,
getRelativeProjectPath,
fileExtensionsMatch
} from './paths';

export {
TraceFlags
} from './traceFlags';

export {
TraceFlagsRemover
} from './traceFlagsRemover';

export {
isNullOrUndefined,
extractJsonObject,
flushFilePath,
flushFilePaths
} from './utils';

export { isNullOrUndefined, extractJsonObject } from './utils';
export {
isAlphaNumString,
isInteger,
isIntegerInRange,
isAlphaNumSpaceString,
isRecordIdFormat
} from './validations';
export {
ensureDirectoryExists,
getTestResultsFolder,
getRelativeProjectPath,
fileExtensionsMatch
} from './paths';
export { TraceFlags } from './traceFlags';
export { TraceFlagsRemover } from './traceFlagsRemover';
25 changes: 1 addition & 24 deletions packages/salesforcedx-utils-vscode/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as fs from 'fs';

export function isNullOrUndefined(object: any): object is null | undefined {
if (object === null || object === undefined) {
return true;
Expand All @@ -16,32 +14,11 @@ export function isNullOrUndefined(object: any): object is null | undefined {
}

export function extractJsonObject(str: string): any {

const jsonString = str.substring(
str.indexOf('{'),
str.lastIndexOf('}') + 1
);

return JSON.parse(jsonString);
}

// There's a bug in VS Code where, after a file has been renamed,
// the URI that VS Code passes to the command is stale and is the
// original URI. See https://github.com/microsoft/vscode/issues/152993.
//
// To get around this, fs.realpathSync.native() is called to get the
// URI with the actual file name.
export function flushFilePath(filePath: string): string {
if (filePath === '') {
return filePath;
}

return fs.realpathSync.native(filePath);
}

export function flushFilePaths(filePaths: string[]): string[] {
for (let i = 0; i < filePaths.length; i++) {
filePaths[i] = flushFilePath(filePaths[i]);
}

return filePaths;
}
76 changes: 4 additions & 72 deletions packages/salesforcedx-utils-vscode/test/unit/helpers/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,20 @@
*/

import { expect } from 'chai';
import * as fs from 'fs';
import * as sinon from 'sinon';
import {
extractJsonObject,
flushFilePath,
flushFilePaths
} from '../../../src/helpers';
import { extractJsonObject } from '../../../src/helpers';

describe('getConfigSource', () => {

describe('extractJsonObject', () => {
it('should extract a JSON string from larger string and then return as an object', async () => {

const exampleJsonString = JSON.stringify({ name: 'exampleName', error: 'exampleError' });
const exampleString = `junk text <junk +text junk text ${exampleJsonString} junk text junk text junk text`;

const testParse = extractJsonObject(exampleString);

expect(testParse.name).to.equal('exampleName');
expect(testParse.error).to.equal('exampleError');
});
});

describe('flushFilePath', () => {
it('should call fs.realpathSync.native() to resolve a path', async () => {
const filePath = 'C:\\Users\\temp\\exampleFile.js';
const realpathSyncNativeStub = sinon.stub(
fs.realpathSync,
'native'
).returns(filePath);

const result = flushFilePath(filePath);

expect(realpathSyncNativeStub.called).to.equal(true);
expect(realpathSyncNativeStub.calledOnce).to.equal(true);
expect(realpathSyncNativeStub.args[0][0]).to.equal(filePath);

realpathSyncNativeStub.restore();
});

it('should return a path when a path is passed in', async () => {
const filePath = 'C:\\Users\\temp\\exampleFile.js';
const realpathSyncNativeStub = sinon.stub(
fs.realpathSync,
'native'
).returns(filePath);

const result = flushFilePath(filePath);

expect(result).to.equal(filePath);

realpathSyncNativeStub.restore();
});

it('should return an empty string when an empty sting is passed in', async () => {
const filePath = 'C:\\Users\\temp\\exampleFile.js';
const realpathSyncNativeStub = sinon.stub(
fs.realpathSync,
'native'
).returns('');

const result = flushFilePath(filePath);

expect(result).to.equal('');

realpathSyncNativeStub.restore();
});
});

describe('flushFilePaths', () => {
it('should return the same paths that are passed in', async () => {
const filePaths = [
'file.js',
'file.js',
'file.js'
];
const realpathSyncNativeStub = sinon.stub(
fs.realpathSync,
'native'
).returns(filePaths[0]);

const result = flushFilePaths(filePaths);

expect(result).to.equal(filePaths);

realpathSyncNativeStub.restore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import {
import {
notificationService
} from '@salesforce/salesforcedx-utils-vscode/out/src/commands';
import {
flushFilePath
} from '@salesforce/salesforcedx-utils-vscode/out/src/helpers';
import * as vscode from 'vscode';
import { nls } from '../messages';
import {
Expand Down Expand Up @@ -92,13 +89,7 @@ async function getApexTestClassName(sourceUri: vscode.Uri): Promise<string | und
}

await testOutlineProvider.refresh();
let testClassName = testOutlineProvider.getTestClassName(sourceUri);
// This is a little bizarre. Intellisense is reporting that getTestClassName() returns a string,
// but it actually it returns string | undefined. Well, regardless, since flushFilePath() takes
// a string (and guards against empty strings) using the Non-null assertion operator
// (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator)
// fixes the issue.
testClassName = flushFilePath(testClassName!);
const testClassName = testOutlineProvider.getTestClassName(sourceUri);

return testClassName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { testSetup } from '@salesforce/core/lib/testSetup';
import { SfdxCommandlet } from '@salesforce/salesforcedx-utils-vscode/out/src';
import { notificationService } from '@salesforce/salesforcedx-utils-vscode/out/src/commands';
import * as helpers from '@salesforce/salesforcedx-utils-vscode/out/src/helpers';
import { expect } from 'chai';
import { createSandbox, SinonSandbox } from 'sinon';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -85,9 +84,6 @@ describe('Force Launch Replay Debugger', () => {
sb.stub(ApexTestOutlineProvider.prototype, 'getTestClassName')
.returns(undefined);

sb.stub(helpers, 'flushFilePath')
.returns(undefined);

await forceLaunchApexReplayDebuggerWithCurrentFile();

expect(showErrorMessageStub.called).to.equal(true);
Expand Down Expand Up @@ -147,9 +143,6 @@ describe('Force Launch Replay Debugger', () => {
sb.stub(SfdxCommandlet.prototype, 'run')
.returns(undefined);

sb.stub(helpers, 'flushFilePath')
.returns('foo.cls');

const executeCommandSpy = sb.spy(vscode.commands, 'executeCommand');

await forceLaunchApexReplayDebuggerWithCurrentFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ import {
Command,
SfdxCommandBuilder
} from '@salesforce/salesforcedx-utils-vscode/out/src/cli';
import {
flushFilePath
} from '@salesforce/salesforcedx-utils-vscode/out/src/helpers';
import {
CancelResponse,
ContinueResponse,
ParametersGatherer,
PreconditionChecker
} from '@salesforce/salesforcedx-utils-vscode/out/src/types';
import * as vscode from 'vscode';
import { SfdxCommandlet, SfdxCommandletExecutor } from './util/sfdxCommandlet';

import { channelService } from '../channels';
import { nls } from '../messages';
import { notificationService } from '../notifications';
import { telemetryService } from '../telemetry';
import { getRootWorkspacePath, hasRootWorkspace } from '../util';
import { SfdxCommandlet, SfdxCommandletExecutor } from './util/sfdxCommandlet';

export class ForceSourceDeleteExecutor extends SfdxCommandletExecutor<{
filePath: string;
Expand All @@ -45,7 +43,7 @@ export class ManifestChecker implements PreconditionChecker {
private explorerPath: string;

public constructor(uri: vscode.Uri) {
this.explorerPath = flushFilePath(uri.fsPath);
this.explorerPath = uri.fsPath;
}

public check(): boolean {
Expand All @@ -72,7 +70,7 @@ export class ConfirmationAndSourcePathGatherer
private readonly CANCEL = nls.localize('cancel_delete_source_button_text');

public constructor(uri: vscode.Uri) {
this.explorerPath = flushFilePath(uri.fsPath);
this.explorerPath = uri.fsPath;
}

public async gather(): Promise<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class LibraryDeploySourcePathExecutor extends DeployExecutor<
}

export const forceSourceDeploySourcePaths = async (
sourceUri: vscode.Uri | vscode.Uri[] | undefined,
sourceUri: vscode.Uri | vscode.Uri[] |undefined,
uris: vscode.Uri[] | undefined
) => {
if (!sourceUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import {
SfdxCommandBuilder
} from '@salesforce/salesforcedx-utils-vscode/out/src/cli';
import { PostconditionChecker } from '@salesforce/salesforcedx-utils-vscode/out/src/types';
import {
CancelResponse,
ContinueResponse,
PostconditionChecker
ContinueResponse
} from '@salesforce/salesforcedx-utils-vscode/out/src/types';
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
import * as vscode from 'vscode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {
flushFilePaths
} from '@salesforce/salesforcedx-utils-vscode/out/src/helpers';
import {
ContinueResponse,
ParametersGatherer
Expand All @@ -15,18 +12,14 @@ import * as vscode from 'vscode';

export class LibraryPathsGatherer implements ParametersGatherer<string[]> {
private uris: vscode.Uri[];

public constructor(uris: vscode.Uri[]) {
this.uris = uris;
}

public async gather(): Promise<ContinueResponse<string[]>> {
const sourcePaths = this.uris.map(uri => uri.fsPath);
const flushedSourcePaths = flushFilePaths(sourcePaths);

return {
type: 'CONTINUE',
data: flushedSourcePaths
data: sourcePaths
};
}
}
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-core/src/messages/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* decorations, e.g., $(x) uses the https://octicons.github.com/ and should not
* be localized
*
* If omitted, we will assume _message.
* If ommitted, we will assume _message.
*/
export const messages = {
channel_name: 'Salesforce CLI',
Expand Down
Loading

0 comments on commit c09c287

Please sign in to comment.