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

--force flag doesn't work with Vite template #3783

Open
3 tasks done
erickzhao opened this issue Dec 11, 2024 · 1 comment
Open
3 tasks done

--force flag doesn't work with Vite template #3783

erickzhao opened this issue Dec 11, 2024 · 1 comment

Comments

@erickzhao
Copy link
Member

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.6.0

Electron version

33.0.0

Operating system

macOS 14.7.1

Last known working Electron Forge version

No response

Expected behavior

See the webpack plugin's behaviour for expected behaviour:

npx create-electron-app@latest my-vue-app --template=webpack --force
✔ Locating custom template: "webpack"
✔ Initializing directory
  › ⚠ The specified path "/Users/erick.zhao/Developer/dump/my-vue-app" is not empty. "force" was set to true, so
    proceeding to initialize. Files may be overwritten
✔ Preparing template
✔ Initializing template
✔ Installing template dependencies

Actual behavior

npx create-electron-app@latest my-vue-app --template=vite --force
✔ Locating custom template: "vite"
✔ Initializing directory
  › ⚠ The specified path "/Users/erick.zhao/Developer/dump/my-vue-app" is not empty. "force" was set to true, so
    proceeding to initialize. Files may be overwritten
✔ Preparing template
❯ Initializing template
  ✔ Copying starter files
  ✔ Initializing package.json
  ✔ Setting up Forge configuration
  ✖ dest already exists.
◼ Installing template dependencies

An unhandled rejection has occurred inside Forge:
Error: dest already exists.
at doRename (/Users/erick.zhao/.npm/_npx/35c48adf706267bc/node_modules/fs-extra/lib/move/move-sync.js:32:34)
    at Object.moveSync (/Users/erick.zhao/.npm/_npx/35c48adf706267bc/node_modules/fs-extra/lib/move/move-sync.js:17:10)
    at _Task.task [as taskFn] (/Users/erick.zhao/.npm/_npx/35c48adf706267bc/node_modules/@electron-forge/template-vite/dist/ViteTemplate.js:43:40)
    at async _Task.run (/Users/erick.zhao/.npm/_npx/35c48adf706267bc/node_modules/listr2/dist/index.cjs:2063:11)

Steps to reproduce

Run create-electron-app with the --force flag and --template=vite

Additional information

No response

@arbrsts
Copy link

arbrsts commented Dec 24, 2024

In forge/packages/template/vite/src/ViteTemplate.ts line 44 is causing the issue:

fs.moveSync(path.join(directory, 'src', 'index.html'), path.join(directory, 'index.html'));

We can work-around by adding overwrite option:

fs.moveSync(path.join(directory, 'src', 'index.html'), path.join(directory, 'index.html'), { overwrite: true });

Or do we need a more structured solution, e.g. adding force flag to InitTemplateOptions to make overwrite behavior configurable?

export interface InitTemplateOptions {
 copyCIFiles?: boolean;
 force?: boolean; 
}

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

No branches or pull requests

2 participants