Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ const outfile = compile
const buildTime = new Date().toISOString()
const version = dev ? getDevVersion(pkg.version) : pkg.version

mkdirSync(dirname(outfile), { recursive: true })
try {
mkdirSync(dirname(outfile), { recursive: true })
} catch (e: unknown) {
if ((e as NodeJS.ErrnoException).code !== 'EEXIST') {
throw e
}
}
Comment on lines +122 to +128
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Does Bun's mkdirSync throw EEXIST error when recursive option is true and directory exists?

💡 Result:

No, Bun's mkdirSync does not throw an EEXIST error when the recursive option is true and the directory already exists. This matches Node.js behavior, where recursive: true causes mkdirSync to succeed silently if the target directory exists (returning undefined), while recursive: false throws EEXIST.

Citations:


Remove the unnecessary try/catch block; Bun's mkdirSync behavior with recursive: true is identical to Node.js.

The try/catch workaround appears to be based on an incorrect assumption. According to official Bun documentation and GitHub discussions, Bun's mkdirSync does not throw EEXIST when recursive: true is set and the directory exists—this matches Node.js behavior exactly. Both implementations succeed silently in this scenario.

The code can be simplified to:

-try {
-  mkdirSync(dirname(outfile), { recursive: true })
-} catch (e: unknown) {
-  if ((e as NodeJS.ErrnoException).code !== 'EEXIST') {
-    throw e
-  }
-}
+mkdirSync(dirname(outfile), { recursive: true })

If the try/catch was added to address a specific edge case or version-specific behavior, that should be clarified. Otherwise, this wrapper should be removed to keep the intent clear and avoid masking genuine filesystem errors.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/build.ts` around lines 122 - 128, Remove the unnecessary try/catch
wrapper around the directory creation: eliminate the try/catch block and call
mkdirSync(dirname(outfile), { recursive: true }) directly (keeping the existing
dirname and outfile symbols). Ensure no special EEXIST handling remains so real
filesystem errors surface normally; if the try/catch was guarding an edge-case,
add a clarifying comment instead of swallowing errors.


const externals = [
'@ant/*',
Expand Down