Skip to content

Fix: Adjust stub file paths for accurate resolution during rolldown build #2217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
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
14 changes: 10 additions & 4 deletions scripts/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,22 @@ export function createConfigsForPackage({
if (rawFile == null) {
return
}
const stub = stubs[rawFile]
const filename = path.basename(rawFile)
const stub = stubs[`dist/${filename}`]
if (!stub) {
return
}

const filename = path.basename(rawFile)
const contents = `export * from './${filename}'`

await fs.writeFile(stub, contents)
// console.log(`created stub ${pc.bold(path.join('packages', target, 'dist', path.basename(stub)))}`)
const fullpath = path.join(
'packages',
target,
'dist',
path.basename(stub)
)
await fs.writeFile(fullpath, contents)
console.log(`created stub ${pc.bold(fullpath)}`)
Comment on lines +334 to +341
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using absolute path resolution for better reliability.

The path construction uses relative paths which could fail if the script is executed from a different working directory. Since packagesDir is already defined (line 18), consider using it for more robust path resolution.

-            const fullpath = path.join(
-              'packages',
-              target,
-              'dist',
-              path.basename(stub)
-            )
+            const fullpath = path.join(
+              packagesDir,
+              target,
+              'dist',
+              path.basename(stub)
+            )

This ensures the stub files are written to the correct location regardless of the current working directory.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const fullpath = path.join(
'packages',
target,
'dist',
path.basename(stub)
)
await fs.writeFile(fullpath, contents)
console.log(`created stub ${pc.bold(fullpath)}`)
const fullpath = path.join(
packagesDir,
target,
'dist',
path.basename(stub)
)
await fs.writeFile(fullpath, contents)
console.log(`created stub ${pc.bold(fullpath)}`)
🤖 Prompt for AI Agents
In scripts/rolldown.ts around lines 334 to 341, the code constructs file paths
using relative paths which may cause issues if the script runs from different
working directories. To fix this, replace the relative path construction with an
absolute path by using the already defined packagesDir variable (from line 18)
as the base directory. Join packagesDir with target, 'dist', and the stub
basename to form the fullpath, ensuring the stub files are always written to the
correct location regardless of the current working directory.

}
}
],
Expand Down