forge icon indicating copy to clipboard operation
forge copied to clipboard

afterPrune executed only with DEBUG=electron-packager

Open tommyblue opened this issue 5 months ago • 3 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.4.0

Electron version

v31.3.1

Operating system

macOS 14.6.1

Last known working Electron Forge version

No response

Expected behavior

afterPrune should be executed when running npx electron-forge package --arch=arm64 --platform=linux ./electron

Actual behavior

the hook is only executed with DEBUG=electron-packager npx electron-forge package --arch=arm64 --platform=linux ./electron

Steps to reproduce

I have a react app in the main folder project and electron files into ./electron.

This is the forge.config.js file:

const { FusesPlugin } = require("@electron-forge/plugin-fuses")
const { FuseV1Options, FuseVersion } = require("@electron/fuses")


module.exports = {
    packagerConfig: {
        prune: true,
        afterPrune: [
            async (buildPath, electronVersion, platform, arch) => {
                throw new Error("This is a test error")
            },
        ],
    },
    rebuildConfig:{},
    makers: [
        {
            name: "@electron-forge/maker-zip",
            platforms: ["linux", "darwin"],
        },
    ],
    plugins: [
        new FusesPlugin({
            version: FuseVersion.V1,
            [FuseV1Options.RunAsNode]: false,
            [FuseV1Options.EnableCookieEncryption]: true,
            [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
            [FuseV1Options.EnableNodeCliInspectArguments]: false,
            [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
            [FuseV1Options.OnlyLoadAppFromAsar]: true,
        }),
    ],
}

the error is not thrown unless you use DEBUG=electron-packager

Additional information

$ npx electron-forge package --arch=arm64 --platform=linux ./electron
✔ Checking your system
✔ Preparing to package application
✔ Running packaging hooks
  ✔ Running generateAssets hook
  ✔ Running prePackage hook
❯ Packaging application
  › Determining targets...
  ❯ Packaging for arm64 on linux
    ✔ Copying files
    ✔ Preparing native dependencies [5s]
    ⠸ Finalizing package
◼ Running postPackage hook
$ DEBUG=electron-packager npx electron-forge package --arch=arm64 --platform=linux ./electron
✔ Checking your system
❯ Preparing to package application
✔ Preparing to package application
❯ Running packaging hooks
❯ Running generateAssets hook
✔ Running generateAssets hook
❯ Running prePackage hook
✔ Running prePackage hook
✔ Running packaging hooks
❯ Packaging application
› Determining targets...
  electron-packager Electron Packager 18.3.4
  electron-packager Node v20.17.0
  electron-packager Host Operating system: darwin 23.6.0 (arm64) +0ms
  electron-packager Packager Options: {"asar":false,"overwrite":true,"ignore":[{}],"prune":true,"afterPrune":[null],"quiet":true,"dir":"<PATH>/frontend","arch":"arm64","platform":"linux","afterFinalizePackageTargets":[null],"afterComplete":[null],"afterCopy":[null],"afterExtract":[null],"out":"<PATH>/frontend/out","electronVersion":"31.3.1"} +1ms
  electron-packager Target Platforms: linux +0ms
  electron-packager Target Architectures: arm64 +0ms
  electron-packager Inferring application name from name in <PATH>/frontend/package.json +2ms
  electron-packager Inferring appVersion from version in <PATH>/frontend/package.json +0ms
  electron-packager Application name: myName +0ms
  electron-packager Target Electron version: 31.3.1 +0ms
  electron-packager Ignored path regular expressions: [
  /^\/out\//g,
  '/package-lock\\.json$',
  '/yarn\\.lock$',
  '/\\.git($|/)',
  '/node_modules/\\.bin($|/)',
  '\\.o(bj)?$',
  '/node_gyp_bins($|/)'
] +0ms
❯ Packaging for arm64 on linux
❯ Copying files
❯ Preparing native dependencies
❯ Finalizing package
  electron-packager Downloading Electron with options {"platform":"linux","arch":"arm64","version":"31.3.1","artifactName":"electron"} +521ms
  electron-packager Creating /var/folders/sh/yv5pz62x5c95fp81cq72cqlr0000gn/T/electron-packager/linux-arm64-template-hvxaJe +766ms
  electron-packager Extracting /Users/tommyblue/Library/Caches/electron/b87e5a986f1e10f6b1c405feb225bb1c8d2a6bcdf6509ea3217a07cb7f6bd118/electron-v31.3.1-linux-arm64.zip to /var/folders/sh/yv5pz62x5c95fp81cq72cqlr0000gn/T/electron-packager/linux-arm64-template-hvxaJe +1ms
  electron-packager Initializing app in /var/folders/sh/yv5pz62x5c95fp81cq72cqlr0000gn/T/electron-packager/tmp-GLizFU from /var/folders/sh/yv5pz62x5c95fp81cq72cqlr0000gn/T/electron-packager/linux-arm64-template-hvxaJe template +1s
  electron-packager Ignored paths based on the out param: [ '<PATH>/frontend/out' ] +1ms
✔ Copying files
✔ Preparing native dependencies

An unhandled rejection has occurred inside Forge:
Error: This is a test error
at module.exports.packagerConfig.afterPrune (<PATH>/frontend/forge.config.js:40:23)
    at node:internal/util:432:7
    at new Promise (<anonymous>)
    at node:internal/util:418:12
    at AsyncFunction.<anonymous> (<PATH>/frontend/node_modules/@electron-forge/core/dist/api/package.js:44:54)
    at node:internal/util:432:7
    at new Promise (<anonymous>)
    at AsyncFunction.<anonymous> (node:internal/util:418:12)
    at <PATH>/frontend/node_modules/@electron/packager/dist/hooks.js:9:73
    at Array.map (<anonymous>)
    at promisifyHooks (<PATH>/frontend/node_modules/@electron/packager/dist/hooks.js:9:29)
    at LinuxApp.copyTemplate (<PATH>/frontend/node_modules/@electron/packager/dist/platform.js:137:46)
    at async LinuxApp.buildApp (<PATH>/frontend/node_modules/@electron/packager/dist/platform.js:125:9)
    at async LinuxApp.initialize (<PATH>/frontend/node_modules/@electron/packager/dist/platform.js:120:13)
    at async LinuxApp.create (<PATH>/frontend/node_modules/@electron/packager/dist/linux.js:14:9)
    at async Promise.all (index 0)

tommyblue avatar Sep 10 '24 14:09 tommyblue