electron / electron/forge

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

Open
#3,452 0 comments 0 reactions 0 assignees View on GitHub
bug custom-addons make
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) 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

> my-new-app@1.0.0 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.