fix(embedded-mpv): resolve upstream node-gyp instead of the electron fork

All six packaged build jobs failed on the previous commit with
`[embedded-mpv] Unable to resolve @electron/node-gyp.`

`build-embedded-mpv.js` scanned `node_modules/.pnpm` for an
`@electron+node-gyp@*` directory. That package was never declared here — it
was only in the tree as a transitive of `@electron/rebuild` 3. rebuild 4,
which electron-builder 26.15.3 pulls in, switched to upstream
`node-gyp@^12.2.0` and dropped the fork, so the scan found nothing.

Follow the same move: declare `node-gyp` as a devDependency and resolve its
bin with `require.resolve`. That also removes the pnpm store-layout scan, which
is what made a transitive dependency look like a build input in the first
place. The Electron target still comes from the `npm_config_*` env, not from
which node-gyp binary runs.

Verified by building the addon for real against Electron 41
(`IPTVNATOR_EMBEDDED_MPV_ALLOW_HOMEBREW=1 nx run
electron-backend:build-embedded-mpv` -> `gyp info ok`, `embedded_mpv.node`,
frame reader and helper all produced).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
4grayandClaude Opus 5 committed 2026-07-26 10:35:08 +02:00
1 parent 78004f8789
commit d55b5ee774
3 files changed
+29 -46

No files matched your search

+12 -33
View File
@@ -677,44 +677,23 @@ function copyGenericRuntimeToNativeBuild(runtime) {
return manifest;
}
function resolveElectronNodeGypBin() {
const pnpmRoot = path.join(workspaceRoot, 'node_modules', '.pnpm');
if (!fs.existsSync(pnpmRoot)) {
throw new Error('Unable to find node_modules/.pnpm.');
}
const packageDirs = fs
.readdirSync(pnpmRoot, { withFileTypes: true })
.filter(
(entry) =>
entry.isDirectory() &&
entry.name.startsWith('@electron+node-gyp@')
)
.map((entry) => entry.name)
.sort();
for (const packageDir of packageDirs) {
const candidate = path.join(
pnpmRoot,
packageDir,
'node_modules',
'@electron',
'node-gyp',
'bin',
'node-gyp.js'
// Upstream node-gyp, resolved as a declared devDependency. This used to scan
// node_modules/.pnpm for the `@electron/node-gyp` fork, which was only ever in
// the tree as a transitive of `@electron/rebuild` 3 — rebuild 4 moved to
// upstream `node-gyp` and the scan started throwing. The Electron target is
// selected through the npm_config_* env below, not by the binary.
function resolveNodeGypBin() {
try {
return require.resolve('node-gyp/bin/node-gyp.js');
} catch (error) {
throw new Error(
`Unable to resolve node-gyp. Is it installed? (${error.message})`
);
if (fs.existsSync(candidate)) {
return candidate;
}
}
throw new Error('Unable to resolve @electron/node-gyp.');
}
function runNodeGyp(command, env) {
const nodeGypBin = resolveElectronNodeGypBin();
const nodeGypBin = resolveNodeGypBin();
const result = spawnSync(
process.execPath,
[nodeGypBin, command, '--directory', addonRoot],
+1
View File
@@ -205,6 +205,7 @@
"jsonc-eslint-parser": "^2.1.0",
"material-design-icons-iconfont": "6.7.0",
"ng-mocks": "14.15.3",
"node-gyp": "12.2.0",
"nx": "22.7.1",
"nx-electron": "22.0.0",
"prettier": "^3.9.6",
+16 -13
View File
@@ -404,6 +404,9 @@ importers:
ng-mocks:
specifier: 14.15.3
version: 14.15.3(1918f1ef5f9f83bc2aab38921c00c721)
node-gyp:
specifier: 12.2.0
version: 12.2.0
nx:
specifier: 22.7.1
version: 22.7.1(@swc-node/register@1.12.1(@swc/core@1.15.46(@swc/helpers@0.5.23))(@swc/types@0.1.27)(typescript@5.9.3))(@swc/core@1.15.46(@swc/helpers@0.5.23))
@@ -15302,7 +15305,7 @@ snapshots:
'@npmcli/fs@5.0.0':
dependencies:
semver: 7.7.4
semver: 7.8.5
'@npmcli/git@7.0.1':
dependencies:
@@ -16762,7 +16765,7 @@ snapshots:
'@typescript-eslint/visitor-keys': 8.51.0
debug: 4.4.3
minimatch: 9.0.5
semver: 7.7.4
semver: 7.8.5
tinyglobby: 0.2.15
ts-api-utils: 2.4.0(typescript@5.9.3)
typescript: 5.9.3
@@ -18180,7 +18183,7 @@ snapshots:
postcss-modules-scope: 3.2.1(postcss@8.5.6)
postcss-modules-values: 4.0.0(postcss@8.5.6)
postcss-value-parser: 4.2.0
semver: 7.7.4
semver: 7.8.5
optionalDependencies:
'@rspack/core': 1.6.8(@swc/helpers@0.5.23)
webpack: 5.104.1(@swc/core@1.15.46(@swc/helpers@0.5.23))(esbuild@0.28.1)
@@ -19543,7 +19546,7 @@ snapshots:
es6-error: 4.1.1
matcher: 3.0.0
roarr: 2.15.4
semver: 7.7.4
semver: 7.8.5
serialize-error: 7.0.1
optional: true
@@ -20788,7 +20791,7 @@ snapshots:
jest-message-util: 30.2.0
jest-util: 30.2.0
pretty-format: 30.2.0
semver: 7.7.4
semver: 7.8.5
synckit: 0.11.11
transitivePeerDependencies:
- supports-color
@@ -20814,7 +20817,7 @@ snapshots:
jest-message-util: 30.4.1
jest-util: 30.4.1
pretty-format: 30.4.1
semver: 7.7.4
semver: 7.8.5
synckit: 0.11.11
transitivePeerDependencies:
- supports-color
@@ -21954,11 +21957,11 @@ snapshots:
node-abi@3.92.0:
dependencies:
semver: 7.7.4
semver: 7.8.5
node-abi@4.33.0:
dependencies:
semver: 7.7.4
semver: 7.8.5
node-abort-controller@3.1.1: {}
@@ -21970,7 +21973,7 @@ snapshots:
node-api-version@0.2.1:
dependencies:
semver: 7.7.4
semver: 7.8.5
node-fetch-native@1.6.7: {}
@@ -21995,7 +21998,7 @@ snapshots:
make-fetch-happen: 15.0.3
nopt: 9.0.0
proc-log: 6.1.0
semver: 7.7.4
semver: 7.8.5
tar: 7.5.9
tinyglobby: 0.2.15
which: 6.0.1
@@ -22030,7 +22033,7 @@ snapshots:
npm-install-checks@8.0.0:
dependencies:
semver: 7.7.4
semver: 7.8.5
npm-normalize-package-bin@5.0.0: {}
@@ -22692,7 +22695,7 @@ snapshots:
cosmiconfig: 9.0.0(typescript@5.9.3)
jiti: 2.6.1
postcss: 8.5.6
semver: 7.7.4
semver: 7.8.5
optionalDependencies:
'@rspack/core': 1.6.8(@swc/helpers@0.5.23)
webpack: 5.104.1(@swc/core@1.15.46(@swc/helpers@0.5.23))(esbuild@0.28.1)
@@ -22704,7 +22707,7 @@ snapshots:
cosmiconfig: 9.0.0(typescript@5.9.3)
jiti: 2.6.1
postcss: 8.5.6
semver: 7.7.4
semver: 7.8.5
optionalDependencies:
'@rspack/core': 1.6.8(@swc/helpers@0.5.23)
webpack: 5.104.1(@swc/core@1.15.46(@swc/helpers@0.5.23))(esbuild@0.28.1)