Skip to content

fix: update electron-builder installOrRebuild usage for v26 compatibility#321

Open
a4xrbj1 wants to merge 191 commits intowojtkowiak:masterfrom
Meteor-Community-Packages:master
Open

fix: update electron-builder installOrRebuild usage for v26 compatibility#321
a4xrbj1 wants to merge 191 commits intowojtkowiak:masterfrom
Meteor-Community-Packages:master

Conversation

@a4xrbj1
Copy link
Copy Markdown

@a4xrbj1 a4xrbj1 commented Feb 5, 2026

In electron-builder v26.x, the installOrRebuild function signature in yarn.ts changed. The second argument changed from appDir: string to { appDir, projectDir, workspaceRoot }: DirectoryPaths. This causes meteor-desktop to crash during the build process with "TypeError: The "path" argument must be of type string" because it passes a string, leaving projectDir undefined.

Additionally, Meteor 3.x's web.cordova architecture emits ES modules which use import.meta. However, meteor-desktop serves these scripts via index.html as classic scripts (without type="module"), leading to Uncaught SyntaxError: Cannot use 'import.meta' outside a module.

Finally, Electron 38 changed the electron module export behavior, causing electron.protocol to be undefined in
skeleton/app.js
, leading to a crash on startup.

This PR:

Updates the installOrRebuild call site to pass the expected object.
Updates updateDdpUrl in lib/meteorApp.js to inject type="module" into script tags in the generated index.html, while preserving
cordova.js
.
Updates
skeleton/app.js
to import protocol directly from electron.
Code Change 1: Electron Builder Compatibility
File: lib/electronBuilder.js

javascript
<<<<
async installOrRebuild(arch, platform = process.platform, install = false) {
this.log.debug(calling installOrRebuild from electron-builder for arch ${arch});
this.prepareLastRebuildObject(arch, platform);
await this.yarn.installOrRebuild(this.$.desktop.getSettings().builderOptions || {},
this.$.env.paths.electronApp.root, this.lastRebuild, install);
}

async installOrRebuild(arch, platform = process.platform, install = false) {
    this.log.debug(`calling installOrRebuild from electron-builder for arch ${arch}`);
    this.prepareLastRebuildObject(arch, platform);
    await this.yarn.installOrRebuild(this.$.desktop.getSettings().builderOptions || {},
        // Electron-builder v26+ expects an object with directory paths
        {
            appDir: this.$.env.paths.electronApp.root,
            projectDir: this.$.env.paths.electronApp.root,
            workspaceRoot: null
        },
        this.lastRebuild,
        install,
        process.env
    );
}

Code Change 2: Meteor 3.x ESM Support
File: lib/meteorApp.js

Method: updateDdpUrl

javascript
<<<<
runtimeConfig.ROOT_URL = this.$.env.options.ddpUrl;
runtimeConfig.DDP_DEFAULT_CONNECTION_URL = this.$.env.options.ddpUrl;
content = content.replace(
this.replacer, $1"${encodeURIComponent(JSON.stringify(runtimeConfig))}"$3
);

runtimeConfig.ROOT_URL = this.$.env.options.ddpUrl;
runtimeConfig.DDP_DEFAULT_CONNECTION_URL = this.$.env.options.ddpUrl;
// Inject type="module" for Meteor 3.x ESM support, excluding cordova.js
content = content.replace(/<script src="/g, '<script type="module" src="/');
content = content.replace(/<script type="module" src="\/cordova\.js"/g, '<script src="/cordova.js"');
content = content.replace(
    this.replacer, `$1"${encodeURIComponent(JSON.stringify(runtimeConfig))}"$3`
);

Code Change 3: Electron 38 Compatibility
File:
skeleton/app.js

Description: Electron v38 changed how the protocol module is exported or accessed. electron.protocol is undefined in the default export when using some transpilers. This change uses require('electron') to correctly access protocol.

javascript
<<<<
import electron from 'electron';
// ...
if (semver.lt(process.versions.electron, '5.0.0-beta.0')) {
electron.protocol.registerStandardSchemes(['meteor'], { secure: true });
} else {
electron.protocol.registerSchemesAsPrivileged([
{ scheme: 'meteor', privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true } }
]);
}

// import electron from 'electron';
let electron;
try {
electron = require('electron');
} catch (e) { }
if (typeof electron !== 'object') {
// If require returned a string (path), it means we got the npm package.
// We need the internal module.
try {
electron = module.constructor._load('electron', module, true);
} catch(e) { }
}
const { protocol } = electron;
// ...
if (semver.lt(process.versions.electron, '5.0.0-beta.0')) {
protocol.registerStandardSchemes(['meteor'], { secure: true });
} else {
protocol.registerSchemesAsPrivileged([
{ scheme: 'meteor', privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true } }
]);
}

Code Change 4: User Project Fix
File:
package.json

Description: The electron package must be in devDependencies, not dependencies. If checking frontend dependency lists, ensure electron is moved. This prevents electron from being bundled into the app logic where it shadows the runtime's internal electron module.

json
// In package.json
"devDependencies": {
"electron": "^38.0.0",
...
}

KoenLav and others added 30 commits November 23, 2020 11:14
fix/meteor 2.6 for #6, changes to publish to npm/atmosphere under new org
Need to migrate off Travis
StorytellerCZ and others added 23 commits April 1, 2025 13:39
Bumps [electron](https://github.com/electron/electron) from 35.1.5 to 38.0.0.
- [Release notes](https://github.com/electron/electron/releases)
- [Changelog](https://github.com/electron/electron/blob/main/docs/breaking-changes.md)
- [Commits](electron/electron@v35.1.5...v38.0.0)

---
updated-dependencies:
- dependency-name: electron
  dependency-version: 38.0.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…and_yarn/electron-38.0.0

Bump electron from 35.1.5 to 38.0.0
Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 5.1.0 to 6.0.6.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/v6.0.6/CHANGELOG.md)
- [Commits](moxystudio/node-cross-spawn@5.1.0...v6.0.6)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-version: 6.0.6
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [brace-expansion](https://github.com/juliangruber/brace-expansion) from 1.1.11 to 1.1.12.
- [Release notes](https://github.com/juliangruber/brace-expansion/releases)
- [Commits](juliangruber/brace-expansion@1.1.11...v1.1.12)

---
updated-dependencies:
- dependency-name: brace-expansion
  dependency-version: 1.1.12
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@babel/helpers](https://github.com/babel/babel/tree/HEAD/packages/babel-helpers) from 7.25.0 to 7.28.4.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.28.4/packages/babel-helpers)

---
updated-dependencies:
- dependency-name: "@babel/helpers"
  dependency-version: 7.28.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@babel/runtime](https://github.com/babel/babel/tree/HEAD/packages/babel-runtime) from 7.25.0 to 7.26.10.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.10/packages/babel-runtime)

---
updated-dependencies:
- dependency-name: "@babel/runtime"
  dependency-version: 7.26.10
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
…and_yarn/babel/runtime-7.26.10

Bump @babel/runtime from 7.25.0 to 7.26.10
…and_yarn/babel/helpers-7.28.4

Bump @babel/helpers from 7.25.0 to 7.28.4
…and_yarn/brace-expansion-1.1.12

Bump brace-expansion from 1.1.11 to 1.1.12
…and_yarn/cross-spawn-6.0.6

Bump cross-spawn from 5.1.0 to 6.0.6
Bumps [send](https://github.com/pillarjs/send) and [serve-static](https://github.com/expressjs/serve-static). These dependencies needed to be updated together.

Updates `send` from 0.18.0 to 1.2.0
- [Release notes](https://github.com/pillarjs/send/releases)
- [Changelog](https://github.com/pillarjs/send/blob/master/HISTORY.md)
- [Commits](pillarjs/send@0.18.0...1.2.0)

Updates `serve-static` from 1.15.0 to 1.16.2
- [Release notes](https://github.com/expressjs/serve-static/releases)
- [Changelog](https://github.com/expressjs/serve-static/blob/v1.16.2/HISTORY.md)
- [Commits](expressjs/serve-static@v1.15.0...v1.16.2)

---
updated-dependencies:
- dependency-name: send
  dependency-version: 1.2.0
  dependency-type: direct:development
- dependency-name: serve-static
  dependency-version: 1.16.2
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
…and_yarn/multi-ffe807eeae

Bump send and serve-static
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.21 to 4.17.23.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.21...4.17.23)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.17.23
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
…and_yarn/lodash-4.17.23

Bump lodash from 4.17.21 to 4.17.23
Copilot AI review requested due to automatic review settings February 5, 2026 07:49
Copy link
Copy Markdown

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 pull request claims to fix electron-builder v26 compatibility by updating the installOrRebuild function signature, but the described fix is not included in the PR. Instead, the PR contains a large set of changes that appear to be a migration from the original meteor-desktop package to @meteor-community/meteor-desktop, including package renaming, dependency updates, test updates, and modernization of the Electron integration code.

Changes:

  • Package renamed from meteor-desktop to @meteor-community/meteor-desktop and Meteor packages renamed from omega:* to communitypackages:*
  • Updated dependencies including Electron (to v17), electron-builder (to v24), and various other packages
  • Modernized Electron integration code including single instance handling, contextBridge usage, and protocol registration
  • Updated test fixtures and test code for newer Meteor versions (2.6.1) and updated dependencies
  • Various code refactoring including async/await conversion and removal of deprecated devtron support

Reviewed changes

Copilot reviewed 49 out of 54 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
package.json Package renaming to @meteor-community scope, dependency version updates, critical bugs found
plugins/bundler/bundler.js Major refactoring with async/await, critical bugs in file processing logic
plugins/bundler/package.js Package renamed to communitypackages:meteor-desktop-bundler
plugins/watcher/package.js Package renamed to communitypackages:meteor-desktop-watcher
plugins/watcher/watcher.js Updated to reference renamed packages
skeleton/preload.js Added contextBridge support, critical bug in electron module exposure
skeleton/app.js Updated single instance handling API, protocol registration, and window management
skeleton/index.js Updated reify import to @meteorjs/reify
skeleton/modules/autoupdate.js Added desktopHCP setting check
lib/meteorApp.js Updated asar import and package references
lib/electronApp.js Updated asar API usage (promises instead of callbacks)
lib/defaultDependencies.js Updated default Electron and electron-builder versions
lib/skeletonDependencies.js Updated dependency versions
tests/* Multiple test updates for new Meteor version, package names, and API changes
README.md Updated documentation for package migration and repository changes
CHANGELOG.md Added changelog entries for versions 3.0.0-3.3.0
.github/* Added GitHub workflows, issue templates, and removed old CI configs
._package.json macOS metadata file that should not be committed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// const transformed = await babelCore.transformAsync(fileContents[file], {
// presets: [preset]
// });
const transformed = await babelCore.transformAsync(code, {
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

There's a bug in this code: the variable code is used on line 899, but code is not defined in this scope. The code should be using fileContents[file] instead. This will cause a ReferenceError when cache misses occur and the code tries to transform files from disk.

Suggested change
const transformed = await babelCore.transformAsync(code, {
const transformed = await babelCore.transformAsync(fileContents[file], {

Copilot uses AI. Check for mistakes.
Comment thread skeleton/preload.js
Comment on lines 321 to +325
exposedModules.forEach((module) => {
Desktop.electron[module] = require('electron')[module];
});

global.Desktop = Desktop;
// exposeInMainWorld support only plain object with methods declared on first level
contextBridge.exposeInMainWorld('Desktop', Desktop.asJSON());
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The asJSON() method returns a hardcoded stub for Desktop.electron (line 296), but the actual electron modules from exposedModules are populated into Desktop.electron after asJSON() is called (lines 321-323). This means that contextBridge.exposeInMainWorld('Desktop', Desktop.asJSON()) on line 325 will expose a Desktop object with only the stub electron object, missing the actual exposed electron modules. The Desktop.electron assignment on lines 321-323 happens after asJSON() is already called, so those modules won't be included in the exposed object.

Consider refactoring to ensure exposedModules are properly included in the returned JSON object, or call asJSON() after populating Desktop.electron.

Copilot uses AI. Check for mistakes.
shelljs.chmod('755', file);
}
});
shelljs.cp('-rf', desktopPath, desktopTmpPath);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Line 792 performs another shelljs.cp('-rf', desktopPath, desktopTmpPath) after all the manual copying logic from lines 747-791. This appears to be a mistake as it will overwrite the carefully constructed .desktop-staging directory with the original .desktop contents, undoing all the manual file-by-file copying, permission setting, and cleanup operations performed earlier. This line should be removed, or if it's intentional, the manual copying logic above it should be removed instead.

Suggested change
shelljs.cp('-rf', desktopPath, desktopTmpPath);

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +130
function versionDesktop(req, res, next) {
const parsedUrl = url.parse(req.url);
if (parsedUrl.pathname.endsWith('version.desktop.json')) {
const manifest = require(path.join(serverPath, 'manifest.json'))
res.end(JSON.stringify(manifest.version));
}
next();
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The versionDesktop middleware calls next() unconditionally on line 130, even after sending a response with res.end() on line 128. This will cause the request to continue being processed by subsequent middleware after the response has already been sent, which can lead to errors. The next() call should only be executed if the pathname does not end with 'version.desktop.json'. Consider wrapping next() in an else block or returning early after calling res.end().

Copilot uses AI. Check for mistakes.
Comment thread package.json
"shelljs": "0.8.2",
"lodash": "4.17.23",
"md5": "2.3.0",
"meteor-desktop": "^2.2.5",
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The package has a dependency on "meteor-desktop": "^2.2.5" (line 93), which is the old package name. This package is being renamed to "@meteor-community/meteor-desktop" as part of this PR. Having a dependency on the old package name in the new package creates a circular/conflicting dependency. This dependency should be removed.

Suggested change
"meteor-desktop": "^2.2.5",

Copilot uses AI. Check for mistakes.
Comment on lines +794 to 796
// del.sync([path.join(desktopTmpPath, '**', '*.test.js')]);
// this.stampPerformance('copy .desktop');

Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

There are commented-out lines 794-795 that appear to be duplicates of the operations performed earlier in the code (del.sync and stampPerformance). These commented lines should either be removed entirely if they're no longer needed, or the comment should explain why they're being kept for future reference.

Suggested change
// del.sync([path.join(desktopTmpPath, '**', '*.test.js')]);
// this.stampPerformance('copy .desktop');

Copilot uses AI. Check for mistakes.
function versionDesktop(req, res, next) {
const parsedUrl = url.parse(req.url);
if (parsedUrl.pathname.endsWith('version.desktop.json')) {
const manifest = require(path.join(serverPath, 'manifest.json'))
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Missing semicolon after the require statement on line 127. This will cause a syntax error when the code is executed.

Copilot uses AI. Check for mistakes.

// need for running test
import asar from 'asar'; // eslint-disable-line no-unused-vars
import asar from '@electron/asar'; // eslint-disable-line no-unused-vars
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Unused import asar.

Copilot uses AI. Check for mistakes.
dependabot bot and others added 4 commits February 21, 2026 20:55
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.12.6 to 6.14.0.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](ajv-validator/ajv@v6.12.6...v6.14.0)

---
updated-dependencies:
- dependency-name: ajv
  dependency-version: 6.14.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [minimatch](https://github.com/isaacs/minimatch) to 3.1.5 and updates ancestor dependencies [minimatch](https://github.com/isaacs/minimatch) and [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `minimatch` from 3.1.2 to 3.1.5
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.1.2...v3.1.5)

Updates `minimatch` from 5.1.6 to 5.1.9
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.1.2...v3.1.5)

Updates `minimatch` from 9.0.5 to 9.0.9
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.1.2...v3.1.5)

Updates `minimatch` from 10.0.1 to 10.2.4
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.1.2...v3.1.5)

Updates `minimatch` from 9.0.3 to 9.0.9
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.1.2...v3.1.5)

Updates `mocha` from 2.5.3 to 11.7.5
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/v11.7.5/CHANGELOG.md)
- [Commits](mochajs/mocha@v2.5.3...v11.7.5)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-version: 3.1.5
  dependency-type: indirect
- dependency-name: minimatch
  dependency-version: 5.1.9
  dependency-type: indirect
- dependency-name: minimatch
  dependency-version: 9.0.9
  dependency-type: indirect
- dependency-name: minimatch
  dependency-version: 10.2.4
  dependency-type: indirect
- dependency-name: minimatch
  dependency-version: 9.0.9
  dependency-type: indirect
- dependency-name: mocha
  dependency-version: 11.7.5
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
…and_yarn/multi-a3e1dfa7a0

Bump minimatch and mocha
…and_yarn/ajv-6.14.0

Bump ajv from 6.12.6 to 6.14.0
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.