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

afterPrune executed only with DEBUG=electron-packager #3690

Open
3 tasks done
tommyblue opened this issue Sep 10, 2024 · 3 comments
Open
3 tasks done

afterPrune executed only with DEBUG=electron-packager #3690

tommyblue opened this issue Sep 10, 2024 · 3 comments

Comments

@tommyblue
Copy link

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.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)
@jeremypenner
Copy link

jeremypenner commented Oct 18, 2024

I'm seeing this behaviour (hang on "Finalizing package") with an afterPrune hook that literally does nothing; just an empty async function. With DEBUG=electron-packager, my build completes successfully in ~5 seconds.

If I modify the function to call the callback parameter, which the current electron-packager docs are kind of vague about the necessity of, then the build completes.

Electron Forge version: 7.5.0
Electron version: 32.0.1
OS: Windows 11 Enterprise 23H2

@MarshallOfSound
Copy link
Member

Use the packageAfterPrune hook instead, it supports a simple async function --> https://www.electronforge.io/config/hooks#packageafterprune

The packager hooks all stil use callback syntax, you can avoid that by using the forge hooks that map to them

@jeremypenner
Copy link

Ah, that is much nicer! Thank you.

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

No branches or pull requests

3 participants