Skip to content

chore: use node.fs in scripts#953

Open
huang-julien wants to merge 1 commit intomainfrom
chore/windows_issue
Open

chore: use node.fs in scripts#953
huang-julien wants to merge 1 commit intomainfrom
chore/windows_issue

Conversation

@huang-julien
Copy link
Member

🔗 Linked issue

📚 Description

I'm just a windows user 🥹, cp doesn't exists

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

The build:client script in packages/devtools/package.json was modified to replace a shell-based file copy command with a Node.js-based equivalent. The original cp -r client/.output/public/ dist/client/ command was replaced with node -e "require('fs').cpSync('client/.output/public','dist/client',{recursive:true})". This change maintains the same functionality—copying the public directory contents recursively—while using Node.js built-in APIs instead of shell commands.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing shell commands with Node.js fs API in build scripts.
Description check ✅ Passed The description clearly explains the motivation (Windows compatibility) and the core issue (cp command unavailability), which directly relates to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/windows_issue
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.

OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/devtools/package.json`:
- Line 36: The npm script "build:client" uses node -e
"require('fs').cpSync('client/.output/public','dist/client',{recursive:true})"
which copies into dist/client without removing prior contents; update the script
to remove/clear the destination first (e.g., call
require('fs').rmSync('dist/client',{recursive:true,force:true}) or equivalent)
before invoking cpSync so stale files are removed and the output is
deterministic; ensure the removal runs only for that path and still preserves
error/exit behavior of the script.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a096cff-7c20-4e37-9096-12692935842b

📥 Commits

Reviewing files that changed from the base of the PR and between f82457d and f0beb96.

📒 Files selected for processing (1)
  • packages/devtools/package.json

"scripts": {
"build": "pnpm dev:prepare && pnpm build:module && pnpm build:discovery && pnpm build:client",
"build:client": "nuxi generate client && cp -r client/.output/public/ dist/client/",
"build:client": "nuxi generate client && node -e \"require('fs').cpSync('client/.output/public','dist/client',{recursive:true})\"",
Copy link
Contributor

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:

In Node.js, for fs.cpSync(src, dest, { recursive: true }), if destalready exists, are files indestthat are absent fromsrc removed or left in place?

💡 Result:

Files in dest that are absent from src are left in place. fs.cpSync(src, dest, { recursive: true }) copies the contents of src into dest (creating dest if it doesn't exist), overwriting files that exist in both, but does not delete files or directories in dest that are not present in src. This matches the behavior of the Unix cp -r src dest/ command, which the Node.js documentation explicitly compares it to: "behavior is similar to cp dir1/ dir2/". Standard cp -r (or cp -a) merges directories without removing extra files in the destination.

Citations:


Clear dist/client before copying to prevent stale cached artifacts.

The fs.cpSync() call copies files into dist/client without removing prior contents. Since removed files in the source are not deleted from the destination, and Turbo caches dist/** across builds, missing files can persist in the output, making builds non-deterministic.

Proposed fix
-    "build:client": "nuxi generate client && node -e \"require('fs').cpSync('client/.output/public','dist/client',{recursive:true})\"",
+    "build:client": "nuxi generate client && node -e \"const fs=require('fs');fs.rmSync('dist/client',{recursive:true,force:true});fs.cpSync('client/.output/public','dist/client',{recursive:true})\"",
📝 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
"build:client": "nuxi generate client && node -e \"require('fs').cpSync('client/.output/public','dist/client',{recursive:true})\"",
"build:client": "nuxi generate client && node -e \"const fs=require('fs');fs.rmSync('dist/client',{recursive:true,force:true});fs.cpSync('client/.output/public','dist/client',{recursive:true})\"",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/devtools/package.json` at line 36, The npm script "build:client"
uses node -e
"require('fs').cpSync('client/.output/public','dist/client',{recursive:true})"
which copies into dist/client without removing prior contents; update the script
to remove/clear the destination first (e.g., call
require('fs').rmSync('dist/client',{recursive:true,force:true}) or equivalent)
before invoking cpSync so stale files are removed and the output is
deterministic; ensure the removal runs only for that path and still preserves
error/exit behavior of the script.

@antfu
Copy link
Member

antfu commented Mar 18, 2026

Should we write a script for that? I am worried this would be hard to maintain over time

@huang-julien
Copy link
Member Author

sure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants