Skip to content

Commit aab051e

Browse files
committed
move to our fs module
1 parent 9c9a89c commit aab051e

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

packages/core/src/amazonq/commons/diff.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { existsSync } from 'fs'
76
import * as vscode from 'vscode'
87
import { featureDevScheme } from '../../amazonqFeatureDev/constants'
8+
import { fs } from '../../shared'
99

1010
export async function openDiff(leftPath: string, rightPath: string, tabId: string) {
11-
const { left, right } = getFileDiffUris(leftPath, rightPath, tabId)
11+
const { left, right } = await getFileDiffUris(leftPath, rightPath, tabId)
1212
await vscode.commands.executeCommand('vscode.diff', left, right)
1313
}
1414

1515
export async function openDeletedDiff(filePath: string, name: string, tabId: string) {
16-
const fileUri = getOriginalFileUri(filePath, tabId)
16+
const fileUri = await getOriginalFileUri(filePath, tabId)
1717
await vscode.commands.executeCommand('vscode.open', fileUri, {}, `${name} (Deleted)`)
1818
}
1919

20-
export function getOriginalFileUri(fullPath: string, tabId: string) {
21-
return existsSync(fullPath) ? vscode.Uri.file(fullPath) : createAmazonQUri('empty', tabId)
20+
export async function getOriginalFileUri(fullPath: string, tabId: string) {
21+
return (await fs.exists(fullPath)) ? vscode.Uri.file(fullPath) : createAmazonQUri('empty', tabId)
2222
}
2323

24-
export function getFileDiffUris(leftPath: string, rightPath: string, tabId: string) {
25-
const left = getOriginalFileUri(leftPath, tabId)
24+
export async function getFileDiffUris(leftPath: string, rightPath: string, tabId: string) {
25+
const left = await getOriginalFileUri(leftPath, tabId)
2626
const right = createAmazonQUri(rightPath, tabId)
2727

2828
return { left, right }

packages/core/src/test/amazonq/common/diff.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as vscode from 'vscode'
1414
import fs from 'fs'
1515
import sinon from 'sinon'
1616
import { createAmazonQUri, getFileDiffUris, getOriginalFileUri, openDeletedDiff, openDiff } from '../../../amazonq'
17+
import { FileSystem } from '../../../shared/fs/fs'
1718

1819
describe('diff', () => {
1920
const filePath = path.join('/', 'foo', 'fi')
@@ -57,15 +58,15 @@ describe('diff', () => {
5758
const name = 'foo'
5859

5960
it('file exists locally', async () => {
60-
sandbox.stub(fs, 'existsSync').returns(true)
61+
sandbox.stub(FileSystem.prototype, 'exists').resolves(true)
6162
await openDeletedDiff(filePath, name, tabId)
6263

6364
const expectedPath = vscode.Uri.file(filePath)
6465
assert.ok(executeCommandSpy.calledWith('vscode.open', expectedPath, {}, `${name} (Deleted)`))
6566
})
6667

6768
it('file does not exists locally', async () => {
68-
sandbox.stub(fs, 'existsSync').returns(false)
69+
sandbox.stub(FileSystem.prototype, 'exists').resolves(false)
6970
await openDeletedDiff(filePath, name, tabId)
7071

7172
const expectedPath = createAmazonQUri('empty', tabId)
@@ -74,9 +75,9 @@ describe('diff', () => {
7475
})
7576

7677
describe('getOriginalFileUri', () => {
77-
it('file exists locally', () => {
78+
it('file exists locally', async () => {
7879
sandbox.stub(fs, 'existsSync').returns(true)
79-
assert.deepStrictEqual(getOriginalFileUri(filePath, tabId).fsPath, filePath)
80+
assert.deepStrictEqual((await getOriginalFileUri(filePath, tabId)).fsPath, filePath)
8081
})
8182

8283
it('file does not exists locally', () => {
@@ -87,10 +88,10 @@ describe('diff', () => {
8788
})
8889

8990
describe('getFileDiffUris', () => {
90-
it('file exists locally', () => {
91+
it('file exists locally', async () => {
9192
sandbox.stub(fs, 'existsSync').returns(true)
9293

93-
const { left, right } = getFileDiffUris(filePath, rightPath, tabId)
94+
const { left, right } = await getFileDiffUris(filePath, rightPath, tabId)
9495

9596
const leftExpected = vscode.Uri.file(filePath)
9697
assert.deepStrictEqual(left, leftExpected)
@@ -99,9 +100,9 @@ describe('diff', () => {
99100
assert.deepStrictEqual(right, rightExpected)
100101
})
101102

102-
it('file does not exists locally', () => {
103+
it('file does not exists locally', async () => {
103104
sandbox.stub(fs, 'existsSync').returns(false)
104-
const { left, right } = getFileDiffUris(filePath, rightPath, tabId)
105+
const { left, right } = await getFileDiffUris(filePath, rightPath, tabId)
105106

106107
const leftExpected = getOriginalFileUri(filePath, tabId)
107108
assert.deepStrictEqual(left, leftExpected)

0 commit comments

Comments
 (0)