fix: copyTemplate failed if tmpdir set to false#1657
fix: copyTemplate failed if tmpdir set to false#1657ianho wants to merge 1 commit intoelectron:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1657 +/- ##
==========================================
- Coverage 92.03% 91.90% -0.13%
==========================================
Files 16 16
Lines 854 865 +11
Branches 167 171 +4
==========================================
+ Hits 786 795 +9
- Misses 51 52 +1
- Partials 17 18 +1 ☔ View full report in Codecov by Sentry. |
BlackHole1
left a comment
There was a problem hiding this comment.
Thank you for your PR!
It would be better if you could explain in detail in the PR why this issue occurred. From the existing PR description and code changes, it is difficult for me to understand the reason behind them. I only understood the reason after reviewing the source code of fs.copy (because the condition is checked before the filter).
| if (!include) return; | ||
|
|
||
| return fs.copy(srcItem, destItem, { | ||
| filter, |
There was a problem hiding this comment.
| filter, |
Since the judgment has already been made before, there is no need to let fs.copy execute the judgment again.
| filter: userPathFilter(this.opts), | ||
| dereference: this.opts.derefSymlinks, | ||
| }); | ||
| if (this.opts.tmpdir === false) { |
There was a problem hiding this comment.
Hey @ianho, we discussed this in an Ecosystem WG meeting and I think this PR is the best solution for https://github.com/electron/forge/issues/3475 as well since it resolves the problem upstream.
Two blockers here:
- Can we add a comment explaining why this is necessary about line 156?
- We should add a test for this code so it doesn't regress in the future.
Summarize your changes:
if tmpdir set to false,
fs-extra copyapi will throw a error thatCannot copy 'xxx' to a subdirectory of itself, 'xxx/out/xxx'.so we cant call
fs.copyin this case, traverse first-level directories to callfs.copyinstead