`electron-builder install-app-deps` does not work with yarn PNP
See original GitHub issue- Version: 22.9.1
- Electron Version: 11.1.0
- Electron Type (current, beta, nightly): current
- Target: MacOS
The “install-app-deps” command does not work at all with yarn PNP due app-builder-bin
being unable to handle finding modules using the PNP api, and so no rebuilding for any modules are executed.
I’ve hacked together a script to use electron-rebuilder
and the pnp-api to rebuild the dependencies explicitly, as I don’t expect this to be resolved anytime soon.
const pnp = require(`pnpapi`);
const { rebuild } = require("electron-rebuild");
const {
dependencies,
devDependencies,
name: workspaceName,
} = require("./package.json");
const findDeps = (workspace, productionDeps, searchedDeps = []) => {
const seen = new Set();
const resolvedDeps = [];
const getKey = (locator) => JSON.stringify(locator);
const isPeerDependency = (pkg, parentPkg, name) =>
getKey(pkg.packageDependencies.get(name)) ===
getKey(parentPkg.packageDependencies.get(name));
const traverseDependencyTree = (locator, parentPkg = null) => {
// Prevent infinite recursion when A depends on B which depends on A
const key = getKey(locator);
if (seen.has(key)) return;
const { name: packageName } = locator;
const pkg = pnp.getPackageInformation(locator);
if (searchedDeps.includes(packageName)) {
resolvedDeps.push([packageName, pkg.packageLocation]);
}
console.assert(pkg, `The package information should be available`);
seen.add(key);
pkg.packageDependencies.forEach((referencish, name) => {
// Unmet peer dependencies
if (referencish === null) {
return;
}
// Avoid iterating on peer dependencies - very expensive
if (parentPkg !== null && isPeerDependency(pkg, parentPkg, name)) {
return;
}
// Skip non production deps for the workspace
if (parentPkg === null && !productionDeps[name]) {
return;
}
const childLocator = pnp.getLocator(name, referencish);
traverseDependencyTree(childLocator, pkg);
});
};
traverseDependencyTree(workspace);
return resolvedDeps;
};
(async () => {
// Set your list of modules which you are expecting to rebuild here
const REBUILD_MODULES = [];
const ELECTRON_VERSION = devDependencies.electron.replace("^", "");
console.log("Rebuilding native modules for electron");
const workspace = pnp
.getDependencyTreeRoots()
.find(({ name }) => name === workspaceName);
const modulesToBuild = findDeps(workspace, dependencies, REBUILD_MODULES);
const results = await Promise.all(
modulesToBuild.map(([name, folder]) => {
console.log(`Rebuilding ${name}...`);
return rebuild({
buildPath: folder,
electronVersion: ELECTRON_VERSION,
})
.then(() => ({ name }))
.catch((e) => ({ name, error: e }));
})
);
results.forEach(({ name, error }) => {
if (error) {
console.error(`Could not rebuild ${name}`, error);
}
});
if (results.some(({ error }) => error)) {
process.exit(1);
} else {
console.log("Native modules built");
}
})();
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
Using Electron with Yarn PnP - Electric UI
Yarn v2 requires packages to declare their dependencies explicitly and will error if a package does not. Some packages that are developed in...
Read more >electron-builder install-app-deps tries to include react-native ...
If I try yarn add react-native it does build but when I start the resulting app it opens but does nothing. I also...
Read more >electron-builder | Yarn - Package Manager
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out...
Read more >electron-builder
A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out...
Read more >electron-builder-bluebird - npm package - Snyk
Native application dependencies compilation (including Yarn support). · Development dependencies are never included. You don't need to ignore ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Still relevant
Still relevant.