Guidance for AI coding agents working in this repository.
Electron Forge is a Yarn 4 + Lerna monorepo of TypeScript packages published as @electron-forge/* (plus create-electron-app). All packages share one version (lerna.json). Node version: .nvmrc.
This is Forge 8, and several things differ from Forge 7, which you may know better:
- Packages are ESM-only.
init/importlive increate-electron-app, not core.publishis renamedrelease(the old name remains as a deprecated alias).make --skip-packageis now--from-package, andrelease --from-dry-runis now--from-make.- The bundler plugins emit main and preload bundles as
.cjs. - PRs target
main.
yarn # install; postinstall regenerates the gitignored per-package tsconfig.json files and packages/tsconfig.json
yarn build # ~5s; tsc -b packages, then tools/test-dist checks that every package's entry point exists and imports
yarn build:watch
yarn lint # oxfmt --check, oxlint, markdownlint, lint of code blocks in markdown, markdown link check
yarn lint:fix # oxfmt --write + oxlint --fix
yarn constraints # yarn.config.cjs: a dependency must use the same range in every workspace (--fix to apply)
yarn knip # unused files/exports/deps
yarn test:fast [file] [-t "name"] # unit tests (*.spec.ts); the full suite takes ~25s
yarn test:slow [file] # *.slow.spec.ts: downloads Electron, real packaging/making, 240s timeouts
yarn test:verdaccio [file] # *.slow.verdaccio.spec.ts against a local registry holding the current build
yarn test:clear # remove temp dirs left behind by tests- Rebuild before testing across packages. A spec imports its own package from
../src. Every other@electron-forge/*import resolves throughpackage.jsonexportstodist/. After editing package A, runyarn build, or keepyarn build:watchrunning, before testing anything that imports A. - Default to
yarn test:fast <file>. Run the slow or Verdaccio specs only when touching packaging, making,initor templates. - Don't run bare
yarn test. It includes theslow-verdaccioproject without starting Verdaccio, so those specs install@electron-forge/*from the public registry and test the wrong code. test:fast,test:slowandtest:verdacciorun throughxvfb-maybe. On headless Linux without xvfb they exit with "Failed to find xvfb-run in PATH". Call vitest directly instead:yarn vitest run --project fast <file>, oryarn spawn-verdaccio yarn vitest run --project slow-verdaccio <file>.- Verdaccio specs need more setup. They publish the current
dist/, so build first. They also need network access, port 4873 free,pnpmon PATH, and npm >= 11.17 for install age-gating. - Specs are not type-checked.
tsconfig.base.jsonexcludesspec/, and vitest strips types. A green build doesn't prove spec types are right. - Try a change in a real app:
yarn build && LINK_FORGE_DEPENDENCIES_ON_INIT=1 node packages/external/create-electron-app/dist/index.js <dir> --package-manager pnpm. Then check that<dir>/node_modules/@electron-forge/cliresolves into this repo.- Only pnpm links reliably.
- With npm, the default when there's no TTY, linking reports success, but the install that follows replaces the links with published packages.
- Yarn works only if Corepack provides Yarn 4. Yarn 1's
yarn linkfails.
- Debug logging:
DEBUG=electron-forge:*traces CLI and core internals. - Parts of
CONTRIBUTING.mdare stale. Its "Running Forge locally" and test instructions mentionyarn link:prepare,yarn build:fastandyarn test, and it says the website docs live in a separate repo. Follow this file instead where they conflict.
The pre-commit hook runs lint-staged (oxfmt + oxlint) and yarn constraints. CI runs build, then yarn lint, yarn constraints and yarn knip, then the test suites on Windows, macOS and Linux. Changes that only touch docs/ skip the test jobs.
Package groups under packages/ (each is a Yarn workspace):
api/core: the programmatic API (src/api/{start,package,make,release}.ts) and shared internals insrc/util/.api/cli: a thincommanderwrapper. It dispatches to one executable per subcommand (electron-forge-<cmd>.ts), and each of those calls the core API.external/create-electron-app: project scaffolding (init.ts,import.ts,init-scripts/).maker/*,publisher/*,plugin/*: implementations ofMakerBase,PublisherBaseandPluginBasefrom the matching*/basepackage.- Most makers wrap a third-party installer module (
electron-installer-*,electron-winstaller, …), usually declared inoptionalDependencies.yarn constraintsskips only the names hard-coded inOPTIONAL_DEPSinyarn.config.cjs, so add a new installer there. publisher/base-staticis shared logic for object-storage publishers (S3, GCS).- Plugins provide lifecycle hooks and can take over
start(startLogic).viteandwebpackare the bundler plugins.
- Most makers wrap a third-party installer module (
template/*: templates used bycreate-electron-app.template/basehasBaseTemplateand the sharedtmpl/files, and the vite and webpack templates extend it.utils/*:shared-typeslives inutils/types. It definesForgeConfig, the hook signatures and the maker/publisher/plugin interfaces that every package codes against.core-utilscovers package manager detection, the@electron/rebuildwrapper and Electron version lookup.- Also:
multi-logger,tracer,test-utils.
Cross-cutting pieces in api/core/src/util/:
-
forge-config.tsloads the config.- Precedence: a config registered with
registerForgeConfigForDirectory()(used by tests), then apackage.jsonconfig.forgeobject, then the firstforge.config.{js,mjs,cjs,ts,mts,cts}found. Aconfig.forgepath string is used only when noforge.config.*file exists. - TS configs load through
jiti, JS configs throughimport(). - After the
resolveForgeConfighook runs, the config is wrapped in aProxy. Missing keys fall back toELECTRON_FORGE_<KEY>env vars, andfromBuildIdentifier()values resolve perbuildIdentifier.
- Precedence: a config registered with
-
import-search.tsresolves by name the makers, publishers and plugins in the config, pluspackagerConfighooks given as strings. It tries the bare specifier, then a path relative to the project, then the project'snode_modules, and uses only the module's default export. -
plugin-interface.ts+hook.tsrun the plugin lifecycle. There are three kinds of hook:- simple hooks (
runHook) - mutating hooks that thread a value through each plugin (
runMutatingHook) - hooks that return
listr2tasks (getHookListrTasks)
Commands are built as
listr2task lists. - simple hooks (
-
The commands chain together.
packagewraps@electron/packagerand injects Forge hooks into itsafterCopy/afterPrune/afterExtractcallbacks.makeruns package first unless given--from-package, andreleaseruns make first unless given--from-make.
Tests live in each package's spec/, and the filename suffix picks the vitest project (see the test commands above). Spec files run serially (fileParallelism: false) because many write into shared on-disk fixtures. Each file gets fresh module state, but registered configs and mocks persist between tests in the same file, so unregister them in afterEach. Core's fixture apps and configs are in packages/api/core/spec/fixture/.
- Coupled changes. A behavior change in a bundler plugin usually also needs updates to the templates'
tmpl/files (what users actually get) and todocs/config/plugins/. - Two sets of docs.
docs/is the user-facing docs site. New pages must be registered indocs/sidebars.ts. Every page is.mdx(MDX syntax:{/* */}comments, no HTML comments, escape stray{and<), and links between pages use the.mdxfile name. The Docusaurus site inwebsite/renders them and fails on broken links and anchors (cd website && yarn build, afteryarn tsc -b packagesand ayarninwebsite/).yarn lintruns markdownlint and the code block lint on the.mdxpages but not the link check, which leavesdocs/to the site build. markdownlint can't read inlinemarkdownlint-disablecomments in MDX, and a code block that isn't meant to lint gets@nolintin its info string. Each package'sREADME.mdis separate, hand-written, and published to npm. - Dependency install policy.
.yarnrc.ymlrejects versions published less than 7 days ago (npmMinimalAgeGate), except for pre-approved scopes, and disables install scripts, except those allowed independenciesMeta. CI installs with--immutable, so commityarn.lock. - Generated project references. Each package's
tsconfig.jsonis generated fromtsconfig.base.jsonand its workspace dependencies bytools/gen-tsconfigs.ts, so don't hand-edit it. After adding or removing an@electron-forge/*dependency, re-runyarn, ortsc -bfails. - Adding a package.
- Put it under an existing
workspacesglob. - Set its version to the one in
lerna.json, and depend on sibling packages withworkspace:*. - Run
yarn. - Add a workspace entry to
knip.json. - Check the
typedoc.jsoncentry points. - Copy the
exports,typingsandpublishConfigfields from a sibling package.tools/test-distfails without the entry point and typings.
- Put it under an existing
- Imports. Relative imports in
src/use.jsextensions. Some type-only re-exports use.ts, but.jsalso works there. Specs import../src/...without an extension; don't copy that style intosrc/. - Commit messages. Commits and PR titles use Conventional Commits (the
semanticworkflow checks PR titles), for examplefix(core): ...orfeat(plugin-vite)!: .... Lerna derives version bumps from them, so don't bump versions in PRs. - TSDoc style. Follow the rules in
CONTRIBUTING.md: the first line is imperative, capitalized and ends with a period.