Skip to content

Commit d5b8c21

Browse files
committed
fully remove fs-extra
1 parent 65fac13 commit d5b8c21

File tree

10 files changed

+137
-138
lines changed

10 files changed

+137
-138
lines changed

packages/amazonq/scripts/build/copyFiles.ts

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

6-
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
6+
import { fs } from 'aws-core-vscode/shared'
87
import * as path from 'path'
98

109
// Moves all dependencies into `dist`
@@ -78,11 +77,7 @@ async function copy(task: CopyTask): Promise<void> {
7877
const dst = path.resolve(outRoot, task.destination ?? task.target)
7978

8079
try {
81-
await fs.copy(src, dst, {
82-
recursive: true,
83-
overwrite: true,
84-
errorOnExist: false,
85-
})
80+
await fs.copy(src, dst)
8681
} catch (error) {
8782
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
8883
}

packages/core/scripts/build/copyFiles.ts

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

6-
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
86
import * as path from 'path'
7+
import { fs } from '../../src/shared'
98

109
// Moves all dependencies into `dist`
1110

@@ -51,11 +50,7 @@ async function copy(task: CopyTask): Promise<void> {
5150
const dst = path.resolve(outRoot, task.destination ?? task.target)
5251

5352
try {
54-
await fs.copy(src, dst, {
55-
recursive: true,
56-
overwrite: true,
57-
errorOnExist: false,
58-
})
53+
await fs.copy(src, dst)
5954
} catch (error) {
6055
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
6156
}

packages/core/scripts/build/generateServiceClient.ts

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

6-
/* eslint-disable no-restricted-imports */
76
import * as proc from 'child_process'
8-
import * as fs from 'fs-extra'
97
import * as path from 'path'
8+
import { fs } from '../../src/shared'
109

1110
const repoRoot = path.join(process.cwd(), '../../') // root/packages/toolkit -> root/
1211
/**
@@ -33,17 +32,17 @@ async function generateServiceClients(serviceClientDefinitions: ServiceClientDef
3332
}
3433

3534
/** When cloning aws-sdk-js, we want to pull the version actually used in package-lock.json. */
36-
function getJsSdkVersion(): string {
37-
const json = fs.readFileSync(path.resolve(repoRoot, 'package-lock.json')).toString()
35+
async function getJsSdkVersion(): Promise<string> {
36+
const json = (await fs.readFileBytes(path.resolve(repoRoot, 'package-lock.json'))).toString()
3837
const packageLock = JSON.parse(json)
3938

4039
return packageLock['packages']['node_modules/aws-sdk']['version']
4140
}
4241

4342
async function cloneJsSdk(dir: string): Promise<void> {
4443
// Output stderr while it clones so it doesn't look frozen
45-
return new Promise<void>((resolve, reject) => {
46-
const sdkversion = getJsSdkVersion()
44+
return new Promise<void>(async (resolve, reject) => {
45+
const sdkversion = await getJsSdkVersion()
4746
if (!sdkversion) {
4847
throw new Error('failed to get sdk version from package-lock.json')
4948
}
@@ -107,17 +106,17 @@ async function insertServiceClientsIntoJsSdk(
107106
jsSdkPath: string,
108107
serviceClientDefinitions: ServiceClientDefinition[]
109108
): Promise<void> {
110-
serviceClientDefinitions.forEach((serviceClientDefinition) => {
111-
const apiVersion = getApiVersion(serviceClientDefinition.serviceJsonPath)
109+
for (const serviceClientDefinition of serviceClientDefinitions) {
110+
const apiVersion = await getApiVersion(serviceClientDefinition.serviceJsonPath)
112111

113112
// Copy the Service Json into the JS SDK for generation
114113
const jsSdkServiceJsonPath = path.join(
115114
jsSdkPath,
116115
'apis',
117116
`${serviceClientDefinition.serviceName.toLowerCase()}-${apiVersion}.normal.json`
118117
)
119-
fs.copyFileSync(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
120-
})
118+
await fs.copy(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
119+
}
121120

122121
const apiMetadataPath = path.join(jsSdkPath, 'apis', 'metadata.json')
123122
await patchServicesIntoApiMetadata(
@@ -132,8 +131,8 @@ interface ServiceJsonSchema {
132131
}
133132
}
134133

135-
function getApiVersion(serviceJsonPath: string): string {
136-
const json = fs.readFileSync(serviceJsonPath).toString()
134+
async function getApiVersion(serviceJsonPath: string): Promise<string> {
135+
const json = (await fs.readFileBytes(serviceJsonPath)).toString()
137136
const serviceJson = JSON.parse(json) as ServiceJsonSchema
138137

139138
return serviceJson.metadata.apiVersion
@@ -149,14 +148,14 @@ interface ApiMetadata {
149148
async function patchServicesIntoApiMetadata(apiMetadataPath: string, serviceNames: string[]): Promise<void> {
150149
console.log(`Patching services (${serviceNames.join(', ')}) into API Metadata...`)
151150

152-
const apiMetadataJson = fs.readFileSync(apiMetadataPath).toString()
151+
const apiMetadataJson = (await fs.readFileBytes(apiMetadataPath)).toString()
153152
const apiMetadata = JSON.parse(apiMetadataJson) as ApiMetadata
154153

155154
serviceNames.forEach((serviceName) => {
156155
apiMetadata[serviceName.toLowerCase()] = { name: serviceName }
157156
})
158157

159-
fs.writeFileSync(apiMetadataPath, JSON.stringify(apiMetadata, undefined, 4))
158+
await fs.writeFile(apiMetadataPath, JSON.stringify(apiMetadata, undefined, 4))
160159
}
161160

162161
/**
@@ -198,7 +197,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
198197

199198
console.log(`Integrating ${typingsFilename} ...`)
200199

201-
fs.copyFileSync(sourceClientPath, destinationClientPath)
200+
await fs.copy(sourceClientPath, destinationClientPath)
202201

203202
await sanitizeServiceClient(destinationClientPath)
204203
}
@@ -209,7 +208,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
209208
async function sanitizeServiceClient(generatedClientPath: string): Promise<void> {
210209
console.log('Altering Service Client to fit the codebase...')
211210

212-
let fileContents = fs.readFileSync(generatedClientPath).toString()
211+
let fileContents = (await fs.readFileBytes(generatedClientPath)).toString()
213212

214213
// Add a header stating the file is autogenerated
215214
fileContents = `
@@ -223,7 +222,7 @@ ${fileContents}
223222

224223
fileContents = fileContents.replace(/(import .* from.*)\.\.(.*)/g, '$1aws-sdk$2')
225224

226-
fs.writeFileSync(generatedClientPath, fileContents)
225+
await fs.writeFile(generatedClientPath, fileContents)
227226
}
228227

229228
// ---------------------------------------------------------------------------------------------------------------------

packages/toolkit/scripts/build/copyFiles.ts

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

6-
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
6+
import { fs } from 'aws-core-vscode/shared'
87
import * as path from 'path'
98

109
// Copies various dependencies into "dist/".
@@ -105,11 +104,7 @@ async function copy(task: CopyTask): Promise<void> {
105104
const dst = path.resolve(outRoot, task.destination ?? task.target)
106105

107106
try {
108-
await fs.copy(src, dst, {
109-
recursive: true,
110-
overwrite: true,
111-
errorOnExist: false,
112-
})
107+
await fs.copy(src, dst)
113108
} catch (error) {
114109
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
115110
}

scripts/createRelease.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,61 @@
88
//
99

1010
import * as child_process from 'child_process'
11-
import * as fs from 'fs-extra'
1211
import * as path from 'path'
12+
import { fs } from '../packages/core/src/shared'
13+
import { readdirSync } from 'fs'
1314

14-
// Must run from a subproject root folder, e.g packages/toolkit
15-
const cwd = process.cwd()
16-
const packageJson = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf-8' }))
17-
const changesDirectory = path.join(cwd, '.changes')
18-
const nextReleaseDirectory = path.join(changesDirectory, 'next-release')
19-
const changesFile = path.join(changesDirectory, `${packageJson.version}.json`)
15+
async function main() {
16+
// Must run from a subproject root folder, e.g packages/toolkit
17+
const cwd = process.cwd()
18+
const fileContents = await fs.readFileText('./package.json')
19+
const packageJson = JSON.parse(fileContents)
20+
const changesDirectory = path.join(cwd, '.changes')
21+
const nextReleaseDirectory = path.join(changesDirectory, 'next-release')
22+
const changesFile = path.join(changesDirectory, `${packageJson.version}.json`)
2023

21-
fs.mkdirpSync(nextReleaseDirectory)
24+
await fs.mkdir(nextReleaseDirectory)
2225

23-
const changeFiles = fs.readdirSync(nextReleaseDirectory)
24-
if (changeFiles.length === 0) {
25-
console.warn('no changes to release (missing .changes/ directory)')
26-
process.exit()
27-
}
28-
try {
29-
fs.accessSync(changesFile)
30-
console.log(`error: changelog data file already exists: ${changesFile}`)
31-
process.exit(-1)
32-
} catch (err) {
33-
// This is what we want to happen, the file should not exist
34-
}
26+
const changeFiles = readdirSync(nextReleaseDirectory)
27+
if (changeFiles.length === 0) {
28+
console.warn('no changes to release (missing .changes/ directory)')
29+
process.exit()
30+
}
31+
if (await fs.exists(changesFile)) {
32+
console.log(`error: changelog data file already exists: ${changesFile}`)
33+
process.exit(-1)
34+
}
3535

36-
const timestamp = new Date().toISOString().split('T')[0]
37-
const changelog: any = {
38-
date: timestamp,
39-
version: packageJson.version,
40-
entries: [],
41-
}
36+
const timestamp = new Date().toISOString().split('T')[0]
37+
const changelog: any = {
38+
date: timestamp,
39+
version: packageJson.version,
40+
entries: [],
41+
}
4242

43-
for (const changeFile of changeFiles) {
44-
const file = JSON.parse(fs.readFileSync(path.join(nextReleaseDirectory, changeFile)).toString())
45-
changelog.entries.push(file)
46-
}
43+
for (const changeFile of changeFiles) {
44+
const file = JSON.parse(fs.readFileBytes(path.join(nextReleaseDirectory, changeFile)).toString())
45+
changelog.entries.push(file)
46+
}
4747

48-
changelog.entries.sort((x: { type: string }, y: { type: string }) => x.type.localeCompare(y.type))
48+
changelog.entries.sort((x: { type: string }, y: { type: string }) => x.type.localeCompare(y.type))
4949

50-
// Write changelog file
51-
fs.writeFileSync(changesFile, JSON.stringify(changelog, undefined, '\t'))
52-
const fileData = fs.readFileSync(path.join(cwd, 'CHANGELOG.md'))
53-
let append = `## ${packageJson.version} ${timestamp}\n\n`
54-
for (const file of changelog.entries) {
55-
append += `- **${file.type}** ${file.description}\n`
56-
}
50+
// Write changelog file
51+
await fs.writeFile(changesFile, JSON.stringify(changelog, undefined, '\t'))
52+
const fileData = fs.readFileBytes(path.join(cwd, 'CHANGELOG.md'))
53+
let append = `## ${packageJson.version} ${timestamp}\n\n`
54+
for (const file of changelog.entries) {
55+
append += `- **${file.type}** ${file.description}\n`
56+
}
57+
58+
append += '\n' + fileData.toString()
59+
await fs.writeFile('CHANGELOG.md', append)
5760

58-
append += '\n' + fileData.toString()
59-
fs.writeFileSync('CHANGELOG.md', append)
61+
child_process.execSync(`git add ${changesDirectory}`)
62+
child_process.execSync(`git rm -rf ${nextReleaseDirectory}`)
63+
child_process.execSync('git add CHANGELOG.md')
6064

61-
child_process.execSync(`git add ${changesDirectory}`)
62-
child_process.execSync(`git rm -rf ${nextReleaseDirectory}`)
63-
child_process.execSync('git add CHANGELOG.md')
65+
console.log(changesFile)
66+
}
6467

65-
console.log(changesFile)
68+
void main()

scripts/generateIcons.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
import webfont from 'webfont'
77
import * as path from 'path'
8-
import * as fs from 'fs-extra'
8+
import * as nodefs from 'fs'
9+
import fs from '../packages/core/dist/src/shared/fs/fs'
910

1011
const fontId = 'aws-toolkit-icons'
1112
const projectDir = process.cwd() // root/packages/toolkit
1213
const rootDir = path.join(projectDir, '../..') // root/
1314
const iconsDir = path.join(projectDir, 'resources', 'icons')
1415
const fontsDir = path.join(projectDir, 'resources', 'fonts')
1516
const stylesheetsDir = path.join(projectDir, 'resources', 'css')
16-
const packageJson = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
17+
const packageJson = JSON.parse(nodefs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
1718
const iconSources = [
1819
// Paths relative to packages/toolkit
1920
`resources/icons/**/*.svg`,
@@ -82,14 +83,14 @@ async function generateCloud9Icons(targets: { name: string; path: string }[], de
8283
console.log('Generating icons for Cloud9')
8384

8485
async function replaceColor(file: string, color: string, dst: string): Promise<void> {
85-
const contents = await fs.readFile(file, 'utf-8')
86+
const contents = await fs.readFileText(file)
8687
const replaced = contents.replace(/currentColor/g, color)
8788
await fs.writeFile(dst, replaced)
8889
}
8990

9091
for (const [theme, color] of Object.entries(themes)) {
9192
const themeDest = path.join(destination, theme)
92-
await fs.mkdirp(themeDest)
93+
await fs.mkdir(themeDest)
9394
await Promise.all(targets.map((t) => replaceColor(t.path, color, path.join(themeDest, `${t.name}.svg`))))
9495
}
9596
}
@@ -169,8 +170,10 @@ ${result.template}
169170
const cloud9Dest = path.join(iconsDir, 'cloud9', 'generated')
170171
const isValidIcon = (i: (typeof icons)[number]): i is Required<typeof i> => i.data !== undefined
171172

172-
await fs.mkdirp(fontsDir)
173-
await fs.writeFile(dest, result.woff)
173+
await fs.mkdir(fontsDir)
174+
if (result.woff) {
175+
await fs.writeFile(dest, result.woff)
176+
}
174177
await fs.writeFile(stylesheetPath, template)
175178
await updatePackage(
176179
`./${relativeDest}`,
@@ -195,14 +198,14 @@ class GeneratedFilesManifest {
195198
public async emit(dir: string): Promise<void> {
196199
const dest = path.join(dir, 'generated.buildinfo')
197200
const data = JSON.stringify(this.files, undefined, 4)
198-
await fs.mkdirp(dir)
201+
await fs.mkdir(dir)
199202
await fs.writeFile(dest, data)
200203
}
201204
}
202205

203206
async function loadCodiconMappings(): Promise<Record<string, number | undefined>> {
204207
const codicons = path.join(rootDir, 'node_modules', '@vscode', 'codicons', 'src')
205-
const data = JSON.parse(await fs.readFile(path.join(codicons, 'template', 'mapping.json'), 'utf-8'))
208+
const data = JSON.parse(await fs.readFileText(path.join(codicons, 'template', 'mapping.json')))
206209
const mappings: Record<string, number | undefined> = {}
207210
for (const [k, v] of Object.entries(data)) {
208211
if (typeof k === 'string' && typeof v === 'number') {

0 commit comments

Comments
 (0)