forge icon indicating copy to clipboard operation
forge copied to clipboard

A custom plugin's init and hook methods are invoked twice during make

Open cwellsx opened this issue 1 year ago • 0 comments

Pre-flight checklist

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

Electron Forge version

7.2.0

Electron version

28.1.0

Operating system

Windows 10

Last known working Electron Forge version

6.0.0

Expected behavior

I have a custom plugin named ResourcePlugin -- https://github.com/cwellsx/electron-forge-resource-plugin It's configured in forge.config.ts like this -- https://github.com/cwellsx/electron_forge_template/blob/dotnet/forge.config.ts

When I run electron-forge make then I expect its init function and its hook functions to be called once.

I observed this expected behaviour when I used 6.0.0 of Electron Forge.

Actual behavior

With v7.2.0 I see the init function and the hook functions (not the constructor) being called twice. The plugin therefore edits the extraResource property twice -- which causes a failure. Below is a debug log file also including log messages from my ResourcePlugin

C:\Users\Christopher\Source\Repos\electron_forge_template>npm run make

> [email protected] make
> set DEBUG=electron-forge&& electron-forge make

√ Checking your system
[STARTED] Loading configuration
ResourcePlugin: constructor
ResourcePlugin: init(C:\Users\Christopher\Source\Repos\electron_forge_template)
ResourcePlugin: getHooks()
ResourcePlugin: resolveForgeConfig
ResourcePlugin: setting extraResource=C:\Users\CHRIST~1\AppData\Local\Temp\electron-forge-resource-plugin\core
ResourcePlugin: addDefine - Added to Webpack configuration: {"CORE_EXE":"\"resources\\\\core\\\\Core.exe\""}
[SUCCESS] Loading configuration
[STARTED] Resolving make targets
[DATA] Making for the following targets:
[SUCCESS] Resolving make targets
[STARTED] Running package command
[STARTED] Preparing to package application
ResourcePlugin: init(C:\Users\Christopher\Source\Repos\electron_forge_template)
ResourcePlugin: resolveForgeConfig
ResourcePlugin: setting extraResource=C:\Users\CHRIST~1\AppData\Local\Temp\electron-forge-resource-plugin\core,C:\Users\CHRIST~1\AppData\Local\Temp\electron-forge-resource-plugin\core
ResourcePlugin: addDefine - Added to Webpack configuration: {"CORE_EXE":"\"resources\\\\core\\\\Core.exe\""}
[SUCCESS] Preparing to package application
[STARTED] Running packaging hooks
... etc ...

I'll edit the plugin to correct this -- i.e. to not edit the property twice -- but this bug report is FYI in case your running a plugin's methods twice isn't what you wanted to be doing -- I don't think that you documented this as new or breaking behaviour in the release notes, nor as expected behaviour in https://www.electronforge.io/advanced/extending-electron-forge/writing-plugins

Steps to reproduce

  • git clone https://github.com/cwellsx/electron_forge_template.git
  • git checkout 2c53c88246c92e44709d8490e954e72bddf32331
  • npm run make

Additional information

No response

cwellsx avatar Dec 24 '23 17:12 cwellsx