From fbe8bcf535b52110bc1cc1030633dc9a418f346a Mon Sep 17 00:00:00 2001 From: Sri Pasumarthi Date: Tue, 24 Mar 2026 12:59:09 -0700 Subject: [PATCH] fix(build): handle EEXIST errors in cpSync during bundle and build on Node.js 25+ --- scripts/build_package.js | 5 ++++- scripts/copy_bundle_assets.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/build_package.js b/scripts/build_package.js index 279e46fa94..74233ac4fb 100644 --- a/scripts/build_package.js +++ b/scripts/build_package.js @@ -18,7 +18,7 @@ // limitations under the License. import { execSync } from 'node:child_process'; -import { writeFileSync, existsSync, cpSync } from 'node:fs'; +import { writeFileSync, existsSync, cpSync, rmSync } from 'node:fs'; import { join, basename } from 'node:path'; if (!process.cwd().includes('packages')) { @@ -48,6 +48,9 @@ if (packageName === 'core') { const docsSource = join(process.cwd(), '..', '..', 'docs'); const docsTarget = join(process.cwd(), 'dist', 'docs'); if (existsSync(docsSource)) { + if (existsSync(docsTarget)) { + rmSync(docsTarget, { recursive: true, force: true }); + } cpSync(docsSource, docsTarget, { recursive: true, dereference: true }); console.log('Copied documentation to dist/docs'); } diff --git a/scripts/copy_bundle_assets.js b/scripts/copy_bundle_assets.js index dea50101ef..27c1dc328f 100644 --- a/scripts/copy_bundle_assets.js +++ b/scripts/copy_bundle_assets.js @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { copyFileSync, existsSync, mkdirSync, cpSync } from 'node:fs'; +import { copyFileSync, existsSync, mkdirSync, cpSync, rmSync } from 'node:fs'; import { dirname, join, basename } from 'node:path'; import { fileURLToPath } from 'node:url'; import { glob } from 'glob'; @@ -58,6 +58,9 @@ console.log(`Copied ${policyFiles.length} policy files to bundle/policies/`); const docsSrc = join(root, 'docs'); const docsDest = join(bundleDir, 'docs'); if (existsSync(docsSrc)) { + if (existsSync(docsDest)) { + rmSync(docsDest, { recursive: true, force: true }); + } cpSync(docsSrc, docsDest, { recursive: true, dereference: true }); console.log('Copied docs to bundle/docs/'); } @@ -66,6 +69,9 @@ if (existsSync(docsSrc)) { const builtinSkillsSrc = join(root, 'packages/core/src/skills/builtin'); const builtinSkillsDest = join(bundleDir, 'builtin'); if (existsSync(builtinSkillsSrc)) { + if (existsSync(builtinSkillsDest)) { + rmSync(builtinSkillsDest, { recursive: true, force: true }); + } cpSync(builtinSkillsSrc, builtinSkillsDest, { recursive: true, dereference: true, @@ -83,8 +89,12 @@ const devtoolsDest = join( ); const devtoolsDistSrc = join(devtoolsSrc, 'dist'); if (existsSync(devtoolsDistSrc)) { + const targetDist = join(devtoolsDest, 'dist'); + if (existsSync(targetDist)) { + rmSync(targetDist, { recursive: true, force: true }); + } mkdirSync(devtoolsDest, { recursive: true }); - cpSync(devtoolsDistSrc, join(devtoolsDest, 'dist'), { + cpSync(devtoolsDistSrc, targetDist, { recursive: true, dereference: true, }); @@ -99,6 +109,9 @@ if (existsSync(devtoolsDistSrc)) { const bundleMcpSrc = join(root, 'packages/core/dist/bundled'); const bundleMcpDest = join(bundleDir, 'bundled'); if (existsSync(bundleMcpSrc)) { + if (existsSync(bundleMcpDest)) { + rmSync(bundleMcpDest, { recursive: true, force: true }); + } cpSync(bundleMcpSrc, bundleMcpDest, { recursive: true, dereference: true }); console.log('Copied bundled chrome-devtools-mcp to bundle/bundled/'); }