Skip to content

Commit 4703297

Browse files
authored
fix: use correct arch for x64/arm64 code-release (#2433)
1 parent 723cd17 commit 4703297

2 files changed

Lines changed: 46 additions & 17 deletions

File tree

.github/workflows/code-release.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ concurrency:
1111

1212
jobs:
1313
publish-macos:
14-
runs-on: macos-latest
1514
strategy:
1615
fail-fast: false
1716
matrix:
18-
arch: [arm64, x64]
17+
include:
18+
- arch: arm64
19+
runner: macos-15-arm64
20+
- arch: x64
21+
runner: macos-15-intel
22+
runs-on: ${{ matrix.runner }}
1923
permissions:
2024
id-token: write
2125
contents: write
@@ -134,7 +138,7 @@ jobs:
134138
env:
135139
APP_VERSION: ${{ steps.version.outputs.version }}
136140
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
137-
run: pnpm --filter code run publish -- --arch=${{ matrix.arch }}
141+
run: pnpm --filter code exec electron-forge publish --arch=${{ matrix.arch }} --platform=darwin
138142

139143
publish-windows:
140144
runs-on: windows-latest

apps/code/forge.config.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ const osxSignConfig =
9595
function copyNativeDependency(
9696
dependency: string,
9797
destinationRoot: string,
98-
): void {
98+
): boolean {
9999
const source = path.resolve("../../node_modules", dependency);
100100
if (!existsSync(source)) {
101101
// Fallback to local node_modules
102102
const localSource = path.resolve("node_modules", dependency);
103103
if (existsSync(localSource)) {
104104
copySync(dependency, destinationRoot, localSource);
105-
return;
105+
return true;
106106
}
107107

108108
console.warn(
109109
`[forge] Native dependency "${dependency}" not found, skipping copy`,
110110
);
111-
return;
111+
return false;
112112
}
113113

114114
const nodeModulesDir = path.join(destinationRoot, "node_modules");
@@ -123,6 +123,7 @@ function copyNativeDependency(
123123
destination,
124124
)}`,
125125
);
126+
return true;
126127
}
127128

128129
function copySync(dependency: string, destinationRoot: string, source: string) {
@@ -256,36 +257,50 @@ const config: ForgeConfig = {
256257
postStart: async (_forgeConfig, child) => {
257258
electronChild = child;
258259
},
259-
packageAfterCopy: async (_forgeConfig, buildPath) => {
260-
// Resolve the target arch (cross-builds set npm_config_arch); fall back
261-
// to the host so non-cross builds keep their existing behavior.
262-
const targetArch = process.env.npm_config_arch ?? process.arch;
263-
260+
packageAfterCopy: async (
261+
_forgeConfig,
262+
buildPath,
263+
_electronVersion,
264+
platform,
265+
targetArch,
266+
) => {
264267
copyNativeDependency("node-pty", buildPath);
265268
copyNativeDependency("node-addon-api", buildPath);
266269
copyNativeDependency("@parcel/watcher", buildPath);
267270

268271
// Platform-specific native dependencies
269-
if (process.platform === "darwin") {
272+
if (platform === "darwin") {
270273
const watcherPkg =
271274
targetArch === "x64"
272275
? "@parcel/watcher-darwin-x64"
273276
: "@parcel/watcher-darwin-arm64";
274-
copyNativeDependency(watcherPkg, buildPath);
277+
if (!copyNativeDependency(watcherPkg, buildPath)) {
278+
throw new Error(
279+
`[forge] Missing required native dependency "${watcherPkg}" for darwin-${targetArch}`,
280+
);
281+
}
275282
copyNativeDependency("file-icon", buildPath);
276283
copyNativeDependency("p-map", buildPath);
277-
} else if (process.platform === "win32") {
284+
} else if (platform === "win32") {
278285
const watcherPkg =
279286
targetArch === "arm64"
280287
? "@parcel/watcher-win32-arm64"
281288
: "@parcel/watcher-win32-x64";
282-
copyNativeDependency(watcherPkg, buildPath);
283-
} else if (process.platform === "linux") {
289+
if (!copyNativeDependency(watcherPkg, buildPath)) {
290+
throw new Error(
291+
`[forge] Missing required native dependency "${watcherPkg}" for win32-${targetArch}`,
292+
);
293+
}
294+
} else if (platform === "linux") {
284295
const watcherPkg =
285296
targetArch === "arm64"
286297
? "@parcel/watcher-linux-arm64-glibc"
287298
: "@parcel/watcher-linux-x64-glibc";
288-
copyNativeDependency(watcherPkg, buildPath);
299+
if (!copyNativeDependency(watcherPkg, buildPath)) {
300+
throw new Error(
301+
`[forge] Missing required native dependency "${watcherPkg}" for linux-${targetArch}`,
302+
);
303+
}
289304
}
290305

291306
// Copy @parcel/watcher's hoisted dependencies
@@ -304,6 +319,16 @@ const config: ForgeConfig = {
304319
copyNativeDependency("file-uri-to-path", buildPath);
305320
copyNativeDependency("prebuild-install", buildPath);
306321
},
322+
packageAfterPrune: async (_forgeConfig, buildPath) => {
323+
// @parcel/watcher tries @parcel/watcher-{platform}-{arch} first, then
324+
// falls back to build/Release/watcher.node. Remove that fallback from
325+
// release bundles so a host-compiled binary cannot shadow the required
326+
// target-specific optional dependency.
327+
rmSync(path.join(buildPath, "node_modules/@parcel/watcher/build"), {
328+
recursive: true,
329+
force: true,
330+
});
331+
},
307332
},
308333
publishers: [
309334
new PublisherGithub({

0 commit comments

Comments
 (0)