Skip to content

chore: v27 migration to ESM-only package (BREAKING)#9544

Open
mmaietta wants to merge 77 commits into
masterfrom
chore/esm-migration
Open

chore: v27 migration to ESM-only package (BREAKING)#9544
mmaietta wants to merge 77 commits into
masterfrom
chore/esm-migration

Conversation

@mmaietta
Copy link
Copy Markdown
Collaborator

@mmaietta mmaietta commented Jan 28, 2026

Resolves #9483!!

Summary

Migrates the build from tsc --build to tsup so every publishable package ships dual CJS + ESM with type declarations, and updates the test/tooling pipeline to match.

Compiler & packaging

  • Replaces tsc --build with tsup for all 8 publishable packages, producing CJS (.js), ESM (.mjs), and declarations (.d.ts / .d.mts) in dist/.
  • Conditional exports on every package (require → CJS, import → ESM, types → declarations) plus a dev-only ./src/* subpath so the monorepo's tests can import un-bundled source.
  • indexInternal.ts (./internal) entry per package for cross-package internal API access, replacing deep pkg/out/... paths.
  • Removes "type": "module" from electron-updater in favour of conditional exports.
  • New packages/tsconfig-tsup.json (no composite) used only by tsup's DTS worker to avoid TS6307.
  • tsconfig-base.json retargeted to ESNext + moduleResolution: "bundler", useDefineForClassFields: false (preserves pre-ES2022 class-field semantics).

Toolchain

  • ts-nodetsx for the vitest runner scripts (works with bundler resolution, no extra flags).
  • compile now runs pnpm -r ... build (per-package tsup) instead of tsc --build; typecheck retains tsc --build for whole-graph type validation.

Source fixes surfaced by the stricter ESM pipeline

  • Broke a real circular dependency: platformPackager.ts imported the ./index barrel (→ linuxPackagerextends PlatformPackager), which fails under ESM eager class-init. Made the barrel import type-only, sourced Platform from ./core, and replaced this instanceof LinuxPackager with a value-free "executableName" in this check.
  • Fixed stale imports left by the in-progress ESM migration: deepAssign.ts (./mapperbuilder-util-runtime), AppImageTarget.ts (deleted ./util/appBuilder → inline + builder-util-runtime#objectToArgs).
  • rollup-plugin-dts incompatibilities: import X = NS.Y namespace aliases → type X = NS.Y (builder-util/log.ts, electron-updater/{AppUpdater,MacUpdater,electronHttpExecutor}.ts).
  • import.meta.dirname (Node 21.2+ ESM-only) → bundle-safe __dirname + shims: true (app-builder-lib pathManager/rebuild/packageMetadata).
  • Misc: tar internal type path → public tar, readline/promisesnode:readline/promises, yargs cast in builder.ts/install-app-deps.ts.

Test infrastructure

  • vitest resolves workspace packages to source via resolve.alias in run-vitest.ts (each pkg / pkg/internal → its src/*.ts). Tests run against un-bundled source so vite handles CJS interop (e.g. fs-extra) and circular deps, and vi.mock can intercept individual modules.
  • Migrated all test deep-imports pkg/out/...pkg/src/...; cliTest mocks consolidated onto app-builder-lib/internal.
  • estree-walker@3.0.3 patch adds a require export condition (one-line patch) so tsx/Node 22 can load it via vitest's mocker.
  • test/tsconfig.json drops package project-references (resolves through exports instead, avoiding mixed out/dist/ type identities).

Script/config fixes

  • scripts/checkDeps.js: ignore dist/, skip the dynamically-imported @electron/universal and root-only tsup/tsx/is-ci/vitest.
  • eslint.config.mjs: ignore **/dist and **/tsup.config.ts; disable the curly/nonblock-statement-body-position conflict; relax require-await/unbound-method for test/src.
  • Root tsconfig.json no longer references test/website (built separately).

… `env: { COREPACK_ENABLE_STRICT: "0", ...process.env },` to allow `npm list` to work across environments. extract fallback node collector (Traversal) to separate class due to differing parsing logic from NPM collector
# Conflicts:
#	packages/app-builder-lib/package.json
#	packages/dmg-builder/package.json
#	packages/electron-builder-squirrel-windows/package.json
#	packages/electron-builder/package.json
…m-migration

# Conflicts:
#	packages/app-builder-lib/src/node-module-collector/bunNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/npmNodeModulesCollector.ts
#	packages/app-builder-lib/src/util/appFileCopier.ts
# Conflicts:
#	packages/app-builder-lib/package.json
#	packages/app-builder-lib/src/asar/asarUtil.ts
#	packages/app-builder-lib/src/binDownload.ts
#	packages/app-builder-lib/src/node-module-collector/bunNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/index.ts
#	packages/app-builder-lib/src/node-module-collector/moduleCache.ts
#	packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/npmNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/traversalNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/types.ts
#	packages/app-builder-lib/src/node-module-collector/yarnBerryNodeModulesCollector.ts
#	packages/app-builder-lib/src/node-module-collector/yarnNodeModulesCollector.ts
#	packages/app-builder-lib/src/publish/PublishManager.ts
#	packages/app-builder-lib/src/targets/FlatpakTarget.ts
#	packages/app-builder-lib/src/targets/archive.ts
#	packages/app-builder-lib/src/util/appFileCopier.ts
#	packages/dmg-builder/package.json
#	packages/dmg-builder/src/dmgUtil.ts
#	packages/electron-builder-squirrel-windows/package.json
#	packages/electron-builder/package.json
#	packages/electron-publish/package.json
#	packages/electron-updater/src/differentialDownloader/DataSplitter.ts
#	pnpm-lock.yaml
#	test/src/helpers/packTester.ts
#	test/src/updater/blackboxUpdateTest.ts
#	test/src/updater/differentialUpdateTest.ts
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 28, 2026

🦋 Changeset detected

Latest commit: 3f03227

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Jan 28, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​tsconfig/​node22@​22.0.51001007083100
Addedtsx@​4.22.31001008294100
Addedfs-extra@​11.3.510010010090100

View full report

@mmaietta mmaietta force-pushed the chore/esm-migration branch from 52191a7 to 3b38b0e Compare May 2, 2026 15:51
mmaietta added 4 commits May 2, 2026 16:32
…m-migration

# Conflicts:
#	packages/app-builder-lib/src/util/yarn.ts
#	test/src/HoistedNodeModuleTest.ts
@mmaietta mmaietta changed the base branch from release/v27 to master May 3, 2026 00:18
@mmaietta mmaietta changed the title chore: v27 migration to ESM [WIP] (BREAKING) chore: v27 migration to ESM-only package (BREAKING) May 4, 2026
mmaietta added 2 commits May 5, 2026 12:50
# Conflicts:
#	test/src/helpers/updaterTestUtil.ts
@mmaietta mmaietta marked this pull request as ready for review May 6, 2026 14:48
Comment thread packages/app-builder-lib/src/targets/AppImageTarget.ts Outdated
Comment thread packages/electron-updater/package.json Outdated
Comment thread packages/app-builder-lib/package.json Outdated
mmaietta added 5 commits June 3, 2026 05:40
# Conflicts:
#	package.json
#	packages/app-builder-lib/helpers/dynamic-import.js
#	packages/app-builder-lib/package.json
#	packages/app-builder-lib/src/asar/asarFileChecker.ts
#	packages/app-builder-lib/src/asar/asarUtil.ts
#	packages/app-builder-lib/src/binDownload.ts
#	packages/app-builder-lib/src/codeSign/codesign.ts
#	packages/app-builder-lib/src/codeSign/macCodeSign.ts
#	packages/app-builder-lib/src/codeSign/windowsSignToolManager.ts
#	packages/app-builder-lib/src/configuration.ts
#	packages/app-builder-lib/src/electron/ElectronFramework.ts
#	packages/app-builder-lib/src/electron/injectFFMPEG.ts
#	packages/app-builder-lib/src/fileTransformer.ts
#	packages/app-builder-lib/src/index.ts
#	packages/app-builder-lib/src/linuxPackager.ts
#	packages/app-builder-lib/src/macPackager.ts
#	packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts
#	packages/app-builder-lib/src/options/SnapOptions.ts
#	packages/app-builder-lib/src/packager.ts
#	packages/app-builder-lib/src/platformPackager.ts
#	packages/app-builder-lib/src/targets/AppxTarget.ts
#	packages/app-builder-lib/src/targets/FlatpakTarget.ts
#	packages/app-builder-lib/src/targets/FpmTarget.ts
#	packages/app-builder-lib/src/targets/LinuxTargetHelper.ts
#	packages/app-builder-lib/src/targets/MsiTarget.ts
#	packages/app-builder-lib/src/targets/appimage/AppImageTarget.ts
#	packages/app-builder-lib/src/targets/appimage/appImageUtil.ts
#	packages/app-builder-lib/src/targets/archive.ts
#	packages/app-builder-lib/src/targets/differentialUpdateInfoBuilder.ts
#	packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
#	packages/app-builder-lib/src/targets/nsis/nsisUtil.ts
#	packages/app-builder-lib/src/targets/snap.ts
#	packages/app-builder-lib/src/toolsets/linux.ts
#	packages/app-builder-lib/src/toolsets/windows.ts
#	packages/app-builder-lib/src/util/config/config.ts
#	packages/app-builder-lib/src/util/packageDependencies.ts
#	packages/app-builder-lib/src/util/resolve.ts
#	packages/app-builder-lib/src/util/yarn.ts
#	packages/app-builder-lib/src/winPackager.ts
#	packages/builder-util-runtime/package.json
#	packages/builder-util-runtime/src/index.ts
#	packages/builder-util/package.json
#	packages/builder-util/src/DebugLogger.ts
#	packages/builder-util/src/deepAssign.ts
#	packages/builder-util/src/util.ts
#	packages/dmg-builder/package.json
#	packages/dmg-builder/src/dmg.ts
#	packages/dmg-builder/src/dmgLicense.ts
#	packages/dmg-builder/src/dmgUtil.ts
#	packages/dmg-builder/src/licenseButtons.ts
#	packages/electron-builder-squirrel-windows/package.json
#	packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts
#	packages/electron-builder/package.json
#	packages/electron-builder/src/builder.ts
#	packages/electron-builder/src/cli/cli.ts
#	packages/electron-builder/src/cli/install-app-deps.ts
#	packages/electron-publish/package.json
#	packages/electron-publish/src/index.ts
#	packages/electron-publish/src/s3/baseS3Publisher.ts
#	packages/electron-publish/src/s3/s3Publisher.ts
#	packages/electron-publish/src/s3/spacesPublisher.ts
#	packages/electron-publish/src/snapStorePublisher.ts
#	packages/electron-updater/src/BaseUpdater.ts
#	pnpm-lock.yaml
#	scripts/fix-schema.js
#	scripts/renderer/src/typedoc2html.ts
#	test/package.json
#	test/snapshots/updater/blackboxUpdateTest.js.snap
#	test/src/ExtraBuildResourcesTest.ts
#	test/src/HoistedNodeModuleTest.ts
#	test/src/binDownloadTest.ts
#	test/src/helpers/downloadElectron.ts
#	test/src/helpers/launchAppCrossPlatform.ts
#	test/src/helpers/packTester.ts
#	test/src/linux/debTest.ts
#	test/src/linux/linuxPackagerTest.ts
#	test/src/linux/snapHeavyTest.ts
#	test/src/mac/macPackagerTest.ts
#	test/src/rebuilderTest.ts
#	test/src/updater/blackboxUpdateTest.ts
#	test/src/updater/differentialUpdateTest.ts
#	test/src/updater/linuxUpdaterTest.ts
#	test/src/windows/appxTest.ts
#	test/src/windows/assistedInstallerTest.ts
#	test/src/windows/msiTest.ts
#	test/src/windows/msiWrappedTest.ts
#	test/src/windows/portableTest.ts
#	test/src/windows/squirrelWindowsTest.ts
#	test/src/windows/webInstallerTest.ts
#	test/src/windows/winCodeSignTest.ts
#	test/src/windows/winPackagerTest.ts
#	test/tsconfig.json
#	test/vitest-scripts/cache.ts
#	test/vitest-scripts/file-discovery.ts
#	test/vitest-scripts/run-vitest.ts
#	test/vitest-scripts/smart-config.ts
#	test/vitest-scripts/smart-shard-count.ts
#	test/vitest-scripts/vitest-smart-sequencer.ts
Comment thread test/vitest-scripts/run-vitest.ts Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FYI/PSA: ESM-only + Node >22 engine upcoming in next major semver, v27

3 participants