Skip to content

A way to set the Config using the @electron-forge/core ForgeAPI #3510

@IIIMADDINIII

Description

@IIIMADDINIII

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 feature request that matches the one I want to file, without success.

Problem description

I integrated electron forge in to my custom build system and i use the ForgeAPI from the core module.
Because i wand to automatically generate the config by my build system i need to use nasty hacks to provide the configuration object to the ForgeAPI.

Proposed solution

My suggestion is, to extend the ForgeAPI Options (MakeOptions, StartOptions, etc.) with an optional config parameter.
This parameter would be used instead of trying to find it in the package.json or searching for a forge.config.js file.

Alternatives considered

Currently i monkeypatch fs-extra and hack in to the require cache.
A simplified version would be this:

import fs from 'fs-extra';
import * as module from "module";
import { api } from "@electron-forge/core";
import { resolve } from "path";
const require = module.createRequire(import.meta.url);

async function runPackage(config) {
  const origExists = fs.pathExists;
  const target = resolve(process.cwd(), "forge.config.js");
  fs.pathExists = function pathExists(file, cb) {
    if (file === target) {
      return Promise.resolve(true);
    }
    return origExists(file, cb);
  };
  require.cache[target] = { exports: config };
  module._pathCache[target + "\x00"] = target;
  await api.package({});
}

Serializing the config to disk is also no option for me, because i load the Plugins by my self (custom plugins bundled with the build tool) and only provide a reference to the instance.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions