Skip to content

Commit 334dfbf

Browse files
committed
revert changes on some files
1 parent ea0d151 commit 334dfbf

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

packages/amazonq/scripts/build/copyFiles.ts

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

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

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

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

packages/core/scripts/build/copyFiles.ts

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

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

910
// Moves all dependencies into `dist`
1011

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

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

packages/core/scripts/build/generateServiceClient.ts

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

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

1011
const repoRoot = path.join(process.cwd(), '../../') // root/packages/toolkit -> root/
1112
/**
@@ -32,17 +33,17 @@ async function generateServiceClients(serviceClientDefinitions: ServiceClientDef
3233
}
3334

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

3940
return packageLock['packages']['node_modules/aws-sdk']['version']
4041
}
4142

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

112113
// Copy the Service Json into the JS SDK for generation
113114
const jsSdkServiceJsonPath = path.join(
114115
jsSdkPath,
115116
'apis',
116117
`${serviceClientDefinition.serviceName.toLowerCase()}-${apiVersion}.normal.json`
117118
)
118-
await fs.copy(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
119-
}
119+
fs.copyFileSync(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
120+
})
120121

121122
const apiMetadataPath = path.join(jsSdkPath, 'apis', 'metadata.json')
122123
await patchServicesIntoApiMetadata(
@@ -131,8 +132,8 @@ interface ServiceJsonSchema {
131132
}
132133
}
133134

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

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

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

154155
serviceNames.forEach((serviceName) => {
155156
apiMetadata[serviceName.toLowerCase()] = { name: serviceName }
156157
})
157158

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

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

198199
console.log(`Integrating ${typingsFilename} ...`)
199200

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

202203
await sanitizeServiceClient(destinationClientPath)
203204
}
@@ -208,7 +209,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
208209
async function sanitizeServiceClient(generatedClientPath: string): Promise<void> {
209210
console.log('Altering Service Client to fit the codebase...')
210211

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

213214
// Add a header stating the file is autogenerated
214215
fileContents = `
@@ -222,7 +223,7 @@ ${fileContents}
222223

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

225-
await fs.writeFile(generatedClientPath, fileContents)
226+
fs.writeFileSync(generatedClientPath, fileContents)
226227
}
227228

228229
// ---------------------------------------------------------------------------------------------------------------------

packages/toolkit/scripts/build/copyFiles.ts

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

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

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

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

scripts/generateIcons.ts

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

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

1110
const fontId = 'aws-toolkit-icons'
1211
const projectDir = process.cwd() // root/packages/toolkit
1312
const rootDir = path.join(projectDir, '../..') // root/
1413
const iconsDir = path.join(projectDir, 'resources', 'icons')
1514
const fontsDir = path.join(projectDir, 'resources', 'fonts')
1615
const stylesheetsDir = path.join(projectDir, 'resources', 'css')
17-
const packageJson = JSON.parse(nodefs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
16+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
1817
const iconSources = [
1918
// Paths relative to packages/toolkit
2019
`resources/icons/**/*.svg`,
@@ -83,14 +82,14 @@ async function generateCloud9Icons(targets: { name: string; path: string }[], de
8382
console.log('Generating icons for Cloud9')
8483

8584
async function replaceColor(file: string, color: string, dst: string): Promise<void> {
86-
const contents = await fs.readFileText(file)
85+
const contents = await fs.readFile(file, 'utf-8')
8786
const replaced = contents.replace(/currentColor/g, color)
8887
await fs.writeFile(dst, replaced)
8988
}
9089

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

173-
await fs.mkdir(fontsDir)
174-
if (result.woff) {
175-
await fs.writeFile(dest, result.woff)
176-
}
172+
await fs.mkdirp(fontsDir)
173+
await fs.writeFile(dest, result.woff)
177174
await fs.writeFile(stylesheetPath, template)
178175
await updatePackage(
179176
`./${relativeDest}`,
@@ -198,14 +195,14 @@ class GeneratedFilesManifest {
198195
public async emit(dir: string): Promise<void> {
199196
const dest = path.join(dir, 'generated.buildinfo')
200197
const data = JSON.stringify(this.files, undefined, 4)
201-
await fs.mkdir(dir)
198+
await fs.mkdirp(dir)
202199
await fs.writeFile(dest, data)
203200
}
204201
}
205202

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

0 commit comments

Comments
 (0)