Skip to content
Merged
34 changes: 16 additions & 18 deletions packages/amazonq/scripts/build/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* eslint-disable no-restricted-imports */
import * as fs from 'fs-extra'
import fs from 'fs'
import * as path from 'path'

// Moves all dependencies into `dist`
Expand Down Expand Up @@ -73,33 +73,31 @@ const tasks: CopyTask[] = [
},
]

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

try {
await fs.copy(src, dst, {
fs.cpSync(src, dst, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid the formal dependency on @types/node@22 by casting this to any. We normally wouldn't do that, but it may be fine in this case because it avoids confusion, since our packages/ depend on @types/node@16 (and that's intentional because vscode ships with node 16).

We can add a check to techdebt.test.ts to remind us to revisit this when we bump to node 18:

it('nodejs minimum version', async function () {
const minNodejs = env.getMinNodejsVersion()
// XXX: available since node 16, but not sure how much work this will be, yet.
assert.ok(
semver.lt(minNodejs, '18.0.0'),

Suggested change
fs.cpSync(src, dst, {
(fs as any).cpSync(src, dst, {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so once we update to 18, we will have @types/node@18 which should allow us to remove the any?

Also, tracking as a follow-up.

recursive: true,
overwrite: true,
force: true,
errorOnExist: false,
})
} catch (error) {
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
}
}

void (async () => {
const args = process.argv.slice(2)
if (args.includes('--vueHr')) {
vueHr = true
console.log('Using Vue Hot Reload webpacks from core/')
}
const args = process.argv.slice(2)
if (args.includes('--vueHr')) {
vueHr = true
console.log('Using Vue Hot Reload webpacks from core/')
}

try {
await Promise.all(tasks.map(copy))
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
})()
try {
tasks.map(copy)
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export function injectJSDOM() {
})

// jsdom doesn't have support for structuredClone. See https://github.com/jsdom/jsdom/issues/3363
global.structuredClone = (val) => JSON.parse(JSON.stringify(val))
global.structuredClone = (val: any) => JSON.parse(JSON.stringify(val))
}
24 changes: 11 additions & 13 deletions packages/core/scripts/build/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* eslint-disable no-restricted-imports */
import * as fs from 'fs-extra'
import fs from 'fs'
import * as path from 'path'

// Moves all dependencies into `dist`
Expand Down Expand Up @@ -46,27 +46,25 @@ const tasks: CopyTask[] = [
},
]

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

try {
await fs.copy(src, dst, {
fs.cpSync(src, dst, {
recursive: true,
overwrite: true,
force: true,
errorOnExist: false,
})
} catch (error) {
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
}
}

void (async () => {
try {
await Promise.all(tasks.map(copy))
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
})()
try {
tasks.map(copy)
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
24 changes: 11 additions & 13 deletions packages/toolkit/scripts/build/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* eslint-disable no-restricted-imports */
import * as fs from 'fs-extra'
import fs from 'fs'
import * as path from 'path'

// Copies various dependencies into "dist/".
Expand Down Expand Up @@ -100,27 +100,25 @@ const tasks: CopyTask[] = [
},
]

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

try {
await fs.copy(src, dst, {
fs.cpSync(src, dst, {
recursive: true,
overwrite: true,
force: true,
errorOnExist: false,
})
} catch (error) {
throw new Error(`Copy "${src}" to "${dst}" failed: ${error instanceof Error ? error.message : error}`)
}
}

void (async () => {
try {
await Promise.all(tasks.map(copy))
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
})()
try {
tasks.map(copy)
} catch (error) {
console.error('`copyFiles.ts` failed')
console.error(error)
process.exit(1)
}
Loading