Skip to content

Commit 5cbe42b

Browse files
authored
refactor(fs): use node:fs, drop fs-extra in copyFiles.ts #5761
## Problem Eliminate fs-extra from the codebase. ## Solution We can use `fs.cp` since node v16.7.0+. Note that `overwrite` is now `force` based on https://nodejs.org/api/fs.html#fscpsyncsrc-dest-options Bump the dependency @types/node to avoid casting (fs as any).
1 parent 6fa3a9e commit 5cbe42b

File tree

7 files changed

+50
-33
lines changed

7 files changed

+50
-33
lines changed

buildspec/shared/linux-pre_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ if [ "$TOOLKITS_CODEARTIFACT_DOMAIN" ] && [ "$TOOLKITS_CODEARTIFACT_REPO" ] && [
2222
fi
2323

2424
# TODO: move this to the "install" phase?
25-
export NODE_OPTIONS=--max-old-space-size=8192
25+
export NODE_OPTIONS='--max-old-space-size=8192'
2626
npm 2>&1 ci | run_and_report 2 'npm WARN deprecated' 'Deprecated dependencies must be updated.'

package-lock.json

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"webpack-merge": "^5.10.0"
7070
},
7171
"dependencies": {
72+
"@types/node": "^22.7.5",
7273
"vscode-nls": "^5.2.0",
7374
"vscode-nls-dev": "^4.0.4"
7475
}

packages/amazonq/scripts/build/copyFiles.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
7+
import fs from 'fs'
88
import * as path from 'path'
99

1010
// Moves all dependencies into `dist`
@@ -73,33 +73,35 @@ const tasks: CopyTask[] = [
7373
},
7474
]
7575

76-
async function copy(task: CopyTask): Promise<void> {
76+
function copy(task: CopyTask): void {
7777
const src = path.resolve(projectRoot, task.target)
7878
const dst = path.resolve(outRoot, task.destination ?? task.target)
7979

8080
try {
81-
await fs.copy(src, dst, {
81+
fs.cpSync(src, dst, {
8282
recursive: true,
83-
overwrite: true,
83+
force: true,
8484
errorOnExist: false,
8585
})
8686
} catch (error) {
8787
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
8888
}
8989
}
9090

91-
void (async () => {
92-
const args = process.argv.slice(2)
93-
if (args.includes('--vueHr')) {
94-
vueHr = true
95-
console.log('Using Vue Hot Reload webpacks from core/')
96-
}
91+
const args = process.argv.slice(2)
92+
if (args.includes('--vueHr')) {
93+
vueHr = true
94+
console.log('Using Vue Hot Reload webpacks from core/')
95+
}
9796

97+
function main() {
9898
try {
99-
await Promise.all(tasks.map(copy))
99+
tasks.map(copy)
100100
} catch (error) {
101101
console.error('`copyFiles.ts` failed')
102102
console.error(error)
103103
process.exit(1)
104104
}
105-
})()
105+
}
106+
107+
void main()

packages/amazonq/test/e2e/amazonq/framework/jsdomInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ export function injectJSDOM() {
3434
})
3535

3636
// jsdom doesn't have support for structuredClone. See https://github.com/jsdom/jsdom/issues/3363
37-
global.structuredClone = (val) => JSON.parse(JSON.stringify(val))
37+
global.structuredClone = (val: any) => JSON.parse(JSON.stringify(val))
3838
}

packages/core/scripts/build/copyFiles.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
7+
import fs from 'fs'
88
import * as path from 'path'
99

1010
// Moves all dependencies into `dist`
@@ -46,27 +46,28 @@ const tasks: CopyTask[] = [
4646
},
4747
]
4848

49-
async function copy(task: CopyTask): Promise<void> {
49+
function copy(task: CopyTask): void {
5050
const src = path.resolve(projectRoot, task.target)
5151
const dst = path.resolve(outRoot, task.destination ?? task.target)
5252

5353
try {
54-
await fs.copy(src, dst, {
54+
fs.cpSync(src, dst, {
5555
recursive: true,
56-
overwrite: true,
56+
force: true,
5757
errorOnExist: false,
5858
})
5959
} catch (error) {
6060
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
6161
}
6262
}
63-
64-
void (async () => {
63+
function main() {
6564
try {
66-
await Promise.all(tasks.map(copy))
65+
tasks.map(copy)
6766
} catch (error) {
6867
console.error('`copyFiles.ts` failed')
6968
console.error(error)
7069
process.exit(1)
7170
}
72-
})()
71+
}
72+
73+
void main()

packages/toolkit/scripts/build/copyFiles.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/* eslint-disable no-restricted-imports */
7-
import * as fs from 'fs-extra'
7+
import fs from 'fs'
88
import * as path from 'path'
99

1010
// Copies various dependencies into "dist/".
@@ -100,27 +100,28 @@ const tasks: CopyTask[] = [
100100
},
101101
]
102102

103-
async function copy(task: CopyTask): Promise<void> {
103+
function copy(task: CopyTask): void {
104104
const src = path.resolve(projectRoot, task.target)
105105
const dst = path.resolve(outRoot, task.destination ?? task.target)
106106

107107
try {
108-
await fs.copy(src, dst, {
108+
fs.cpSync(src, dst, {
109109
recursive: true,
110-
overwrite: true,
110+
force: true,
111111
errorOnExist: false,
112112
})
113113
} catch (error) {
114114
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
115115
}
116116
}
117-
118-
void (async () => {
117+
function main() {
119118
try {
120-
await Promise.all(tasks.map(copy))
119+
tasks.map(copy)
121120
} catch (error) {
122121
console.error('`copyFiles.ts` failed')
123122
console.error(error)
124123
process.exit(1)
125124
}
126-
})()
125+
}
126+
127+
void main()

0 commit comments

Comments
 (0)