Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native dependencies are not built when using yarn workspaces in 24.0.0-alpha.1 #7212

Closed
gzdunek opened this issue Oct 25, 2022 · 6 comments · Fixed by #7215
Closed

Native dependencies are not built when using yarn workspaces in 24.0.0-alpha.1 #7212

gzdunek opened this issue Oct 25, 2022 · 6 comments · Fixed by #7215
Assignees

Comments

@gzdunek
Copy link

gzdunek commented Oct 25, 2022

  • Electron-Builder Version: 24.0.0-alpha.1
  • Node Version: 16.18.0
  • Electron Version: 21.2.0
  • Electron Type (current, beta, nightly): current
  • Target: macOS, Windows, Linux

Project structure: monorepo (yarn workspaces).
It seems that after migrating to electron-rebuild the native dependencies are no longer rebuilt. electron-builder install-app-deps only looks for modules in node_modules of the workspace, but of course it doesn't find any (because they are kept in the root node_modules).
CLI command electron-rebuild handles this situation by providing projectRootPath to rebuild(). If this option is not passed, the search for modules stops at the directory where the app package.json is located.
It would be great if electron-builder could populate this field using a function similar to getProjectRootPath().

As a workaround, nohoist option can be used in yarn workspaces to prevent some dependencies from being hoisted to the project's root.

@mmaietta mmaietta self-assigned this Oct 25, 2022
@mmaietta
Copy link
Collaborator

Hmmm I had a feeling the alpha version incorporating electron-rebuild would have a few issues arise. It worked with some of my local projects, but they're more simple in configuration.
I'll take a look at this asap

@mmaietta
Copy link
Collaborator

Would you mind generating an electron-quick-start monorepo project utilizing a yarn workspace such that I can repro this with?

@mmaietta
Copy link
Collaborator

Can you try this patch? Curious if it'll do the trick

diff --git a/node_modules/app-builder-lib/out/util/yarn.js b/node_modules/app-builder-lib/out/util/yarn.js
index 41fde4d..f278239 100644
--- a/node_modules/app-builder-lib/out/util/yarn.js
+++ b/node_modules/app-builder-lib/out/util/yarn.js
@@ -5,8 +5,9 @@ const builder_util_1 = require("builder-util");
 const fs_extra_1 = require("fs-extra");
 const os_1 = require("os");
 const path = require("path");
-const electronRebuild = require("electron-rebuild");
 const electronVersion_1 = require("../electron/electronVersion");
+const electronRebuild = require("electron-rebuild");
+const searchModule = require("electron-rebuild/lib/src/search-module");
 async function installOrRebuild(config, appDir, options, forceInstall = false) {
     let isDependenciesInstalled = false;
     for (const fileOrDir of ["node_modules", ".pnp.js"]) {
@@ -104,7 +105,7 @@ function installDependencies(appDir, options) {
     });
 }
 async function nodeGypRebuild(arch) {
-    return rebuild(process.cwd(), false, arch);
+    return rebuild(await searchModule.getProjectRootPath(process.cwd()), false, arch);
 }
 exports.nodeGypRebuild = nodeGypRebuild;
 function getPackageToolPath() {

@gzdunek
Copy link
Author

gzdunek commented Oct 26, 2022

Thanks for your response!
I tried the patch, but it doesn't help :(

Here is the project using yarn workspaces https://github.com/gzdunek/electron-quick-start-monorepo.

When you run yarn build-electron-app-native-deps the output is:

$ electron-builder install-app-deps
  • electron-builder  version=24.0.0-alpha.1
  • executing electron-rebuild  appDir=/Users/grzegorz/code/electron-quick-start-monorepo/packages/electron-app arch=arm64
✨  Done in 0.60s.

but is should be:
(I provided projectRootPath: '/Users/grzegorz/code/electron-quick-start-monorepo/' manually in yarn.js)

$ electron-builder install-app-deps
  • electron-builder  version=24.0.0-alpha.1
  • executing electron-rebuild  appDir=/Users/grzegorz/code/electron-quick-start-monorepo/packages/electron-app arch=arm64
  CXX(target) Release/obj.target/pty/src/unix/pty.o
  SOLINK_MODULE(target) Release/pty.node
✨  Done in 1.39s.

Let me know if you need anything else.

@mmaietta
Copy link
Collaborator

Thanks for the sample repo! Was able to get it working locally. Please try v24.0.0-alpha.2

@gzdunek
Copy link
Author

gzdunek commented Oct 28, 2022

Thanks, v24.0.0-alpha.2 solved the issue!

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 a pull request may close this issue.

2 participants