Skip to content

Move to ESM#1599

Merged
hovancik merged 32 commits intotrunkfrom
esm
Jul 17, 2025
Merged

Move to ESM#1599
hovancik merged 32 commits intotrunkfrom
esm

Conversation

@hovancik
Copy link
Owner

@hovancik hovancik commented May 1, 2025

No description provided.

This comment was marked as outdated.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the app to ESM modules, replacing CommonJS require/module.exports with import/export, updating IPC channels via contextBridge, and loading renderer scripts as ES modules.

  • Added <script type="module"> tags and new *-renderer.js files for ESM-based preload/renderer logic
  • Converted core files (main.js, breaksPlanner.js, utilities) from CommonJS to ESM syntax
  • Updated IPC handlers, channel names, and contextBridge exposure in preload scripts

Reviewed Changes

Copilot reviewed 57 out of 57 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
app/preferences.html Added module-based renderer script
app/preferences-renderer.js New ESM renderer, dark-mode image handling logic
app/main.js Converted to ESM imports/exports, refactored IPC
app/platform.js Updated to use window.process APIs
app/microbreak-renderer.js ESM-based microbreak renderer
app/break-renderer.js ESM-based long-break renderer

const imagesWithDarkVersion = document.querySelectorAll('[data-has-dark-version]')
imagesWithDarkVersion.forEach(image => {
// replace last occurance https://github.com/electron-userland/electron-builder/issues/5152
const newSource = image.src.replace(/.([^.]*)$/, '-dark.' + '$1')
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex uses . (any character) instead of \. to match a literal dot. It should be /\.([^.]*)$/ to correctly replace the file extension.

Suggested change
const newSource = image.src.replace(/.([^.]*)$/, '-dark.' + '$1')
const newSource = image.src.replace(/\.([^.]*)$/, '-dark.' + '$1')

Copilot uses AI. Check for mistakes.
const imagesWithDarkVersion = document.querySelectorAll('[data-has-dark-version]')
if (event.matches) {
imagesWithDarkVersion.forEach(image => {
const newSource = image.src.replace(/.([^.]*)$/, '-dark.' + '$1')
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: escape the dot in the regex (/\.([^.]*)$/) to avoid matching unexpected characters before the extension.

Suggested change
const newSource = image.src.replace(/.([^.]*)$/, '-dark.' + '$1')
const newSource = image.src.replace(/\.([^.]*)$/, '-dark.' + '$1')

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented May 17, 2025

Codecov Report

Attention: Patch coverage is 1.43885% with 685 lines in your changes missing coverage. Please review.

Project coverage is 13.48%. Comparing base (5d8f3cb) to head (d4f9cef).
Report is 29 commits behind head on trunk.

Files with missing lines Patch % Lines
app/preferences-renderer.js 0.00% 188 Missing ⚠️
app/main.js 0.00% 169 Missing ⚠️
app/utils/context-bridge-exposers.js 0.00% 60 Missing ⚠️
app/welcome-renderer.js 0.00% 54 Missing ⚠️
app/contributor-preferences-renderer.js 0.00% 44 Missing ⚠️
app/break-renderer.js 0.00% 33 Missing ⚠️
app/microbreak-renderer.js 0.00% 32 Missing ⚠️
app/process-renderer.js 0.00% 28 Missing ⚠️
app/utils/dndManager.js 7.69% 24 Missing ⚠️
app/utils/statusMessages.js 0.00% 9 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1599      +/-   ##
==========================================
- Coverage   14.94%   13.48%   -1.47%     
==========================================
  Files          30       34       +4     
  Lines        1974     1958      -16     
==========================================
- Hits          295      264      -31     
- Misses       1679     1694      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Repository owner deleted a comment from Copilot AI May 29, 2025
@hovancik hovancik requested a review from Copilot May 29, 2025 16:42

This comment was marked as outdated.

@hovancik hovancik requested a review from Copilot June 9, 2025 10:31

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@hovancik hovancik requested a review from Copilot July 16, 2025 10:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the codebase from CommonJS to ES modules, updating imports/exports, tests, preload scripts, and package metadata to fully adopt ESM.

  • Convert require/module.exports to import/export across all .js files and update preload scripts
  • Update tests to supply new dependencies (humanize-duration, semver) and switch built‐in imports to the node: specifier
  • Update package.json to "type": "module", bump Node engine, and refresh dependencies

Reviewed Changes

Copilot reviewed 111 out of 112 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/utils.js Updated tests to pass humanize-duration & semver to formatters
app/utils/utils.js Converted helpers to ESM, adjusted signatures, exports
app/utils/htmlTranslate.js Made translate async and removed @electron/remote
app/main.js Switched to ESM imports, revamped IPC handlers & channels
package.json Set ESM type, bumped Node version & deps
app/utils/context-bridge-exposers.js Consolidated and updated context-bridge exposers for ESM
Comments suppressed due to low confidence (6)

test/utils.js:71

  • [nitpick] The description 'Others' is ambiguous. Rename this block to clarify what is being tested, for example describe('shouldShowNotificationTitle').
describe('Others', () => {

app/utils/utils.js:71

  • The shouldShowNotificationTitle function is defined but not exported here. This will break consumers (e.g., the context bridge). Please include shouldShowNotificationTitle in the export.
}

app/main.js:205

  • EventEmitter.setMaxListeners is not a valid static method. To change the default max listeners, set EventEmitter.defaultMaxListeners = 200 or call setMaxListeners on a specific emitter instance.
  EventEmitter.setMaxListeners(200) // for watching Store changes

app/utils/htmlTranslate.js:7

  • [nitpick] Using an async callback inside forEach will not be awaited by the outer method. Consider using a for...of loop to await each translation in sequence or Promise.all on a .map.
    this.document.querySelectorAll('[data-i18next]').forEach(async function (element) {

package.json:8

  • [nitpick] Pinning the Node engine to a single version can introduce install issues. Consider specifying a range (e.g., ">=22.17.0") unless an exact version is strictly required.
    "node": "22.17.0"

app/breaksPlanner.js:2

  • [nitpick] Imports of core modules are using 'events' here but 'node:events' elsewhere. For consistency, consider using the node: specifier for all built-in imports.
import EventEmitter from 'events'

@devtobi
Copy link

devtobi commented Jul 16, 2025

@hovancik Any updates on when this refactoring will be finished? Since this looks like a major rewrite do you plan to release a new major version?

@hovancik
Copy link
Owner Author

@devtobi it changes a lot of things, but it's mostly migration from require to import, related changes and some things I catched in between related to new electron version and such.

So user will not see any changes. (hopefully)

I am pretty happy with current state, so I think I will merge it in coming days and see. I am trying to run trunk where I can so hopefully there won't be any regression I am not catching

@hovancik hovancik changed the title WIP move to ESM Move to ESM Jul 17, 2025
@hovancik hovancik merged commit d639144 into trunk Jul 17, 2025
9 checks passed
@hovancik hovancik deleted the esm branch July 17, 2025 06:57
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

Successfully merging this pull request may close these issues.

3 participants