Skip to content
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

fix: copyTemplate failed if tmpdir set to false #1657

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/platform.ts
Expand Up @@ -153,10 +153,27 @@ export class App {
async copyTemplate() {
await promisifyHooks(this.opts.beforeCopy, this.hookArgsWithOriginalResourcesAppDir);

await fs.copy(this.opts.dir, this.originalResourcesAppDir, {
filter: userPathFilter(this.opts),
dereference: this.opts.derefSymlinks,
});
if (this.opts.tmpdir === false) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

const filter = userPathFilter(this.opts);
const items = await fs.readdir(this.opts.dir);
await Promise.all(items.map(async item => {
const srcItem = path.join(this.opts.dir, item);
const destItem = path.join(this.originalResourcesAppDir, item);

const include = await filter(srcItem, destItem);
if (!include) return;

return fs.copy(srcItem, destItem, {
filter,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
filter,

Since the judgment has already been made before, there is no need to let fs.copy execute the judgment again.

dereference: this.opts.derefSymlinks ?? true,
});
}));
} else {
await fs.copy(this.opts.dir, this.originalResourcesAppDir, {
filter: userPathFilter(this.opts),
dereference: this.opts.derefSymlinks ?? true,
});
}
await promisifyHooks(this.opts.afterCopy, this.hookArgsWithOriginalResourcesAppDir);
if (this.opts.prune) {
await promisifyHooks(this.opts.afterPrune, this.hookArgsWithOriginalResourcesAppDir);
Expand Down