feat: enhance packageAfterCopy hook to remove non-target prebuilt binaries
Some checks failed
Release Electron App / release-desktop (push) Failing after 29m53s
Some checks failed
Release Electron App / release-desktop (push) Failing after 29m53s
This commit is contained in:
@@ -35,7 +35,7 @@ const config: ForgeConfig = {
|
|||||||
},
|
},
|
||||||
rebuildConfig: {},
|
rebuildConfig: {},
|
||||||
hooks: {
|
hooks: {
|
||||||
packageAfterCopy: async (_forgeConfig, buildPath) => {
|
packageAfterCopy: async (_forgeConfig, buildPath, _electronVersion, platform, arch) => {
|
||||||
// The VitePlugin's ignore filter only copies .vite/ into the build.
|
// The VitePlugin's ignore filter only copies .vite/ into the build.
|
||||||
// Externalized packages need to be installed into node_modules here.
|
// Externalized packages need to be installed into node_modules here.
|
||||||
// At this point, only .vite/ exists. The VitePlugin writes package.json
|
// At this point, only .vite/ exists. The VitePlugin writes package.json
|
||||||
@@ -68,6 +68,37 @@ const config: ForgeConfig = {
|
|||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
env: { ...process.env, npm_config_nodedir: '' },
|
env: { ...process.env, npm_config_nodedir: '' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Remove cross-platform prebuilt binaries that don't match the target.
|
||||||
|
// Packages like @github/copilot ship prebuilds for all platforms;
|
||||||
|
// keeping foreign-arch .node files breaks rpmbuild's strip step.
|
||||||
|
const targetDir = `${platform}-${arch}`;
|
||||||
|
const nmPath = path.join(buildPath, 'node_modules');
|
||||||
|
const findPrebuilds = (dir: string): string[] => {
|
||||||
|
const results: string[] = [];
|
||||||
|
if (!fs.existsSync(dir)) return results;
|
||||||
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||||
|
const full = path.join(dir, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
if (entry.name === 'prebuilds') {
|
||||||
|
results.push(full);
|
||||||
|
} else {
|
||||||
|
results.push(...findPrebuilds(full));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const prebuildsDir of findPrebuilds(nmPath)) {
|
||||||
|
for (const entry of fs.readdirSync(prebuildsDir)) {
|
||||||
|
if (entry !== targetDir) {
|
||||||
|
const fullPath = path.join(prebuildsDir, entry);
|
||||||
|
fs.rmSync(fullPath, { recursive: true, force: true });
|
||||||
|
console.log(`[forge] Removed non-target prebuild: ${entry}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
makers: [
|
makers: [
|
||||||
|
|||||||
Reference in New Issue
Block a user