feat(core-utils): add subpath exports for individual modules#4315
Open
erickzhao wants to merge 2 commits into
Open
feat(core-utils): add subpath exports for individual modules#4315erickzhao wants to merge 2 commits into
erickzhao wants to merge 2 commits into
Conversation
Replace the single-string exports field with an explicit exports map. The root "." entry keeps pointing at the barrel for backwards compatibility; each public source module gains its own subpath so consumers can import just the helpers they need without evaluating the whole barrel (and its transitive semver/debug/graceful-fs/cross-spawn imports) at load time. The list is deliberately explicit rather than a "./*" wildcard: find-up and remote-rebuild are internal and stay unexported, and new modules become public API only by being added here. Types resolve from the sibling .d.ts files under node16 module resolution, so no types conditions are needed; the typings field stays for the root entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dfTZ7AecGYkxBjQ8DGT54
Migrate consumers that only use light helpers (fs, author-name, package-manager, install-dependencies, resolve-working-dir) off the core-utils barrel and onto the new subpath exports, so loading a small helper no longer evaluates every core-utils module and its transitive dependencies. api/core keeps importing the barrel: it uses the heavy modules (rebuild, electron-version) anyway, so splitting its imports would not change what gets loaded. Spec files that vi.mock'd the core-utils barrel now mock the specific submodule their subject imports, since vitest intercepts by module specifier. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dfTZ7AecGYkxBjQ8DGT54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summarize your changes:
@electron-forge/core-utilscurrently declares"exports": "./dist/index.js", so the only way to consume it is through the barrel — which evaluates every module and their transitive dependencies (semver,debug,graceful-fs,@malept/cross-spawn-promise, ~40ms per fresh Node process) even when a consumer only needs a tiny helper likepathExistsorresolveWorkingDir.Commit 1 replaces the single-string
exportswith an explicit exports map:"."still points at the barrel (fully backwards compatible), and each public source module gains its own subpath (/author-name,/electron-version,/fs,/install-dependencies,/package-manager,/rebuild,/resolve-working-dir). The list is deliberately explicit rather than a"./*"wildcard sofind-upandremote-rebuildstay internal (ERR_PACKAGE_PATH_NOT_EXPORTED) and new modules only become public API by being listed. Types resolve from the sibling.d.tsfiles undernode16module resolution; thetypingsfield is kept for the root entry. The dist layout is unchanged, sorebuild.ts'scp.forkofremote-rebuild.jsis unaffected, and@electron/rebuildstill only appears as a value import in the compiledremote-rebuild.js.Commit 2 migrates light consumers (makers, templates, publisher-snapcraft, plugin-vite, plugin-webpack, create-electron-app, CLI entry points) to subpath imports.
api/corekeeps importing the barrel since it uses the heavy modules anyway. Spec files thatvi.mock'd the barrel now mock the specific submodule their subject imports, since vitest intercepts by module specifier.This also unblocks #4210: its proposed
restart.tsevent-emitter module can ship as a leaf subpath that Vite config files load in build worker subprocesses without pulling in the whole barrel per worker.Verified locally:
yarn build(tsgo +tools/test-dist) passes, the fullfastvitest project passes (408 tests), every listed subpath resolves at runtime from a consumer package, and the root barrel import is unchanged.Generated by Claude Code