Skip to content

Commit e64bd7a

Browse files
browser: remove some uses of fs-extra (#4230)
2 parents 4f9e41a + 8ac2973 commit e64bd7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+419
-359
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,13 @@ module.exports = {
115115
{ lineEndings: 'unix' },
116116
],
117117
'aws-toolkits/no-only-in-tests': 'error',
118+
// The following will place an error on the `fs-extra` import since we do not want it to be used for browser compatibility reasons.
119+
// "no-restricted-imports": [
120+
// "error",
121+
// {
122+
// "name": "fs-extra",
123+
// "message": "Avoid fs-extra, use FileSystemCommon. Notify the Toolkit team if your required functionality is not available."
124+
// }
125+
// ],
118126
},
119127
}

src/amazonqFeatureDev/util/files.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Uri } from 'vscode'
1212
import { GitIgnoreFilter } from './gitignore'
1313

1414
import AdmZip from 'adm-zip'
15-
import { FileSystemCommon } from '../../srcShared/fs'
15+
import { fsCommon } from '../../srcShared/fs'
1616
import { TelemetryHelper } from './telemetryHelper'
1717
import { PrepareRepoFailedError } from '../errors'
1818
import { getLogger } from '../../shared/logger/logger'
@@ -133,6 +133,5 @@ export async function prepareRepoData(
133133

134134
export async function getSourceCodePath(workspaceRoot: string, projectRoot: string) {
135135
const srcRoot = path.join(workspaceRoot, projectRoot)
136-
const srcFound = await FileSystemCommon.instance.stat(srcRoot)
137-
return srcFound !== undefined ? srcRoot : workspaceRoot
136+
return (await fsCommon.existsDir(srcRoot)) ? srcRoot : workspaceRoot
138137
}

src/auth/providers/sharedCredentialsProviderFactory.ts

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

6-
import * as fs from 'fs-extra'
6+
import { fsCommon } from '../../srcShared/fs'
77
import { getLogger, Logger } from '../../shared/logger'
88
import { loadSharedCredentialsSections, updateAwsSdkLoadConfigEnvVar } from '../credentials/sharedCredentials'
99
import { CredentialsProviderType } from './credentials'
@@ -80,9 +80,8 @@ export class SharedCredentialsProviderFactory extends BaseCredentialsProviderFac
8080

8181
private async getLastModifiedMillis(filepath: string): Promise<number | undefined> {
8282
try {
83-
const stat = await fs.stat(filepath)
84-
85-
return stat.mtimeMs
83+
const stat = await fsCommon.stat(filepath)
84+
return stat.mtime
8685
} catch (err) {
8786
return undefined
8887
}

src/cloudWatchLogs/commands/saveCurrentLogDataContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const localize = nls.loadMessageBundle()
1010
import { SystemUtilities } from '../../shared/systemUtilities'
1111
import { isLogStreamUri, parseCloudWatchLogsUri } from '../cloudWatchLogsUtils'
1212
import { telemetry, CloudWatchResourceType, Result } from '../../shared/telemetry/telemetry'
13-
import { FileSystemCommon } from '../../srcShared/fs'
13+
import { fsCommon } from '../../srcShared/fs'
1414

1515
/** Prompts the user to select a file location to save the currently visible "aws-cwl:" document to. */
1616
export async function saveCurrentLogDataContent(): Promise<void> {
@@ -45,7 +45,7 @@ export async function saveCurrentLogDataContent(): Promise<void> {
4545

4646
if (selectedUri && content) {
4747
try {
48-
await FileSystemCommon.instance.writeFile(selectedUri, content)
48+
await fsCommon.writeFile(selectedUri, content)
4949
} catch (e) {
5050
result = 'Failed'
5151
const err = e as Error

src/codewhisperer/commands/basicCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from '../util/customizationUtil'
2929
import { applyPatch } from 'diff'
3030
import { closeSecurityIssueWebview, showSecurityIssueWebview } from '../views/securityIssue/securityIssueWebview'
31-
import { FileSystemCommon } from '../../srcShared/fs'
31+
import { fsCommon } from '../../srcShared/fs'
3232
import { Mutable } from '../../shared/utilities/tsUtils'
3333
import { CodeWhispererSource } from './types'
3434
import { showManageConnections } from '../../auth/ui/vue/show'
@@ -315,7 +315,7 @@ export const applySecurityFix = Commands.declare(
315315
}
316316

317317
// writing the patch applied version of document into the file
318-
await FileSystemCommon.instance.writeFile(filePath, updatedContent)
318+
await fsCommon.writeFile(filePath, updatedContent)
319319
void vscode.window
320320
.showInformationMessage(CodeWhispererConstants.codeFixAppliedSuccessMessage, {
321321
title: CodeWhispererConstants.runSecurityScanButtonTitle,

src/codewhisperer/vue/backend.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { VueWebview } from '../../webviews/main'
1111
import { isCloud9 } from '../../shared/extensionUtilities'
1212
import globals from '../../shared/extensionGlobals'
1313
import { telemetry, CodewhispererLanguage, CodewhispererGettingStartedTask } from '../../shared/telemetry/telemetry'
14-
import { FileSystemCommon } from '../../srcShared/fs'
14+
import { fsCommon } from '../../srcShared/fs'
1515
import { getLogger } from '../../shared/logger'
1616
import { PromptSettings } from '../../shared/settings'
1717
import { CodeWhispererSource } from '../commands/types'
@@ -39,7 +39,7 @@ export class CodeWhispererWebview extends VueWebview {
3939
const fileContent = name[1]
4040

4141
const localFilePath = this.getLocalFilePath(fileName)
42-
if ((await FileSystemCommon.instance.fileExists(localFilePath)) && this.isFileSaved) {
42+
if ((await fsCommon.existsFile(localFilePath)) && this.isFileSaved) {
4343
const fileUri = vscode.Uri.file(localFilePath)
4444
await vscode.workspace.openTextDocument(fileUri).then(async doc => {
4545
await vscode.window.showTextDocument(doc, vscode.ViewColumn.Active).then(editor => {
@@ -58,7 +58,7 @@ export class CodeWhispererWebview extends VueWebview {
5858
// This function saves and open the file in the editor.
5959
private async saveFileLocally(localFilePath: string, fileContent: string): Promise<void> {
6060
try {
61-
await FileSystemCommon.instance.writeFile(localFilePath, fileContent)
61+
await fsCommon.writeFile(localFilePath, fileContent)
6262
this.isFileSaved = true
6363
// Opening the text document
6464
await vscode.workspace.openTextDocument(localFilePath).then(async doc => {

src/dynamicResources/awsResourceManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class AwsResourceManager {
157157
await this.initialize()
158158

159159
const normalizedTypeName = getNormalizedTypeName(typeName)
160-
const filename = getNonexistentFilename(
160+
const filename = await getNonexistentFilename(
161161
this.folder!,
162162
encodeURIComponent(identifier),
163163
`.${normalizedTypeName}.awsResource.json`

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
initializeComputeRegion,
2828
isCloud9,
2929
isSageMaker,
30-
showQuickStartWebview,
3130
showWelcomeMessage,
3231
} from './shared/extensionUtilities'
3332
import { getLogger, Logger } from './shared/logger/logger'
@@ -78,6 +77,7 @@ import { ChildProcess } from './shared/utilities/childProcess'
7877
import { initializeNetworkAgent } from './codewhisperer/client/agent'
7978
import { Timeout } from './shared/utilities/timeoutUtils'
8079
import { submitFeedback } from './feedback/vue/submitFeedback'
80+
import { showQuickStartWebview } from './shared/extensionStartup'
8181

8282
let localize: nls.LocalizeFunc
8383

src/lambda/wizards/samInitWizard.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
} from '../models/samTemplates'
2929
import * as semver from 'semver'
3030
import { minSamCliVersionForArmSupport, minSamCliVersionForImageSupport } from '../../shared/sam/cli/samCliValidator'
31-
import * as fsutil from '../../shared/filesystemUtilities'
3231
import { Wizard } from '../../shared/wizards/wizard'
3332
import { createFolderPrompt } from '../../shared/ui/common/location'
3433
import { createInputBox, InputBoxPrompter } from '../../shared/ui/inputPrompter'
@@ -37,6 +36,7 @@ import { createRegionPrompter } from '../../shared/ui/common/region'
3736
import { Region } from '../../shared/regions/endpoints'
3837
import { createCommonButtons } from '../../shared/ui/buttons'
3938
import { createExitPrompter } from '../../shared/ui/common/exitPrompter'
39+
import { getNonexistentFilenameSync } from '../../shared/filesystemUtilities'
4040

4141
const localize = nls.loadMessageBundle()
4242

@@ -274,12 +274,7 @@ export class CreateNewSamAppWizard extends Wizard<CreateNewSamAppWizardForm> {
274274

275275
this.form.name.bindPrompter(state =>
276276
createNamePrompter(
277-
fsutil.getNonexistentFilename(
278-
state.location!.fsPath,
279-
`lambda-${state.runtimeAndPackage!.runtime}`,
280-
'',
281-
99
282-
)
277+
getNonexistentFilenameSync(state.location!.fsPath, `lambda-${state.runtimeAndPackage!.runtime}`, '', 99)
283278
)
284279
)
285280
}

src/s3/commands/downloadFileAs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function downloadFileAsCommand(node: S3FileNode, outputChannel = gl
110110
const sourcePath = readablePath(node)
111111

112112
await telemetry.s3_downloadObject.run(async () => {
113-
const downloadPath = getDefaultDownloadPath()
113+
const downloadPath = await getDefaultDownloadPath()
114114

115115
const saveLocation = await promptForSaveLocation(file.name, downloadPath)
116116
if (!saveLocation) {

0 commit comments

Comments
 (0)