Skip to content

Commit 43252c8

Browse files
committed
fix(scripts): harden Windows native opus install
1 parent efd88dc commit 43252c8

7 files changed

Lines changed: 108 additions & 30 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Docs: https://docs.openclaw.ai
88

99
### Fixes
1010

11+
- Scripts: run the optional Discord native opus installer through the shared pnpm launcher and Windows CI coverage so native Windows installs avoid shell-mode package-manager shims.
1112
- Agents/MCP: bound bundled MCP `tools/list` catalog discovery so hung MCP servers do not block session tool materialization. (#85063) Thanks @nxmxbbd.
1213
- Scripts: run generated-module formatting through the shared pnpm launcher and Windows CI coverage so native Windows generator checks avoid shell-mode package-manager shims.
1314
- Channels/iMessage: advance the startup catchup cursor from live-handled rows after a completed catchup pass, including rows received while catchup is still running, so restarts do not replay them. (#85475) Thanks @TurboTheTurtle.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@
17651765
"test:unit:fast:audit": "node scripts/test-unit-fast-audit.mjs",
17661766
"test:voicecall:closedloop": "node scripts/test-voicecall-closedloop.mjs",
17671767
"test:watch": "node scripts/test-projects.mjs --watch",
1768-
"test:windows:ci": "node scripts/test-projects.mjs src/shared/runtime-import.test.ts src/plugins/import-specifier.test.ts src/process/exec.windows.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts extensions/lobster/src/lobster-runner.test.ts test/scripts/format-generated-module.test.ts test/scripts/npm-runner.test.ts test/scripts/pnpm-runner.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
1768+
"test:windows:ci": "node scripts/test-projects.mjs src/shared/runtime-import.test.ts src/plugins/import-specifier.test.ts src/process/exec.windows.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts extensions/lobster/src/lobster-runner.test.ts test/scripts/format-generated-module.test.ts test/scripts/install-discord-native-opus.test.ts test/scripts/npm-runner.test.ts test/scripts/pnpm-runner.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
17691769
"tool-display:check": "node --import tsx scripts/tool-display.ts --check",
17701770
"tool-display:write": "node --import tsx scripts/tool-display.ts --write",
17711771
"ts-topology": "node --import tsx scripts/ts-topology.ts",

‎scripts/ci-changed-scope.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const ANDROID_NATIVE_RE = /^(apps\/android\/|apps\/shared\/)/;
3636
const NODE_SCOPE_RE =
3737
/^(src\/|test\/|extensions\/|packages\/|scripts\/|ui\/|\.github\/|openclaw\.mjs$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|tsconfig.*\.json$|vitest.*\.ts$|tsdown\.config\.ts$|\.oxlintrc\.json$|\.oxfmtrc\.jsonc$)/;
3838
const WINDOWS_SCOPE_RE =
39-
/^(src\/process\/|src\/infra\/windows-install-roots\.ts$|src\/plugins\/import-specifier(?:\.test)?\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|scripts\/(?:install\.ps1|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|js)|lib\/format-generated-module\.mjs)$|test\/scripts\/(?:format-generated-module|install-ps1|npm-runner|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/ci\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
39+
/^(src\/process\/|src\/infra\/windows-install-roots\.ts$|src\/plugins\/import-specifier(?:\.test)?\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|scripts\/(?:install\.ps1|install-discord-native-opus\.mjs|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|js)|lib\/format-generated-module\.mjs)$|test\/scripts\/(?:format-generated-module|install-discord-native-opus|install-ps1|npm-runner|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/ci\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
4040
const WINDOWS_TEST_SCOPE_RE =
41-
/^(src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/windows-install-roots\.test\.ts$|src\/plugins\/import-specifier\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|test\/scripts\/(?:format-generated-module|npm-runner|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
41+
/^(src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/windows-install-roots\.test\.ts$|src\/plugins\/import-specifier\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|test\/scripts\/(?:format-generated-module|install-discord-native-opus|npm-runner|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
4242
const TEST_ONLY_PATH_RE =
4343
/(^test\/|\/test\/|\/tests\/|(?:^|\/)[^/]+\.(?:test|spec|test-utils|test-support|test-harness|e2e-harness)\.[cm]?[jt]sx?$)/;
4444
const CONTROL_UI_I18N_SCOPE_RE =

‎scripts/install-discord-native-opus.mjs‎

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,70 @@ import { spawnSync } from "node:child_process";
22
import { existsSync } from "node:fs";
33
import path from "node:path";
44
import { fileURLToPath } from "node:url";
5+
import { resolvePnpmRunner } from "./pnpm-runner.mjs";
56

67
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
78
const opusDir = path.join(root, "node_modules", "@discordjs", "opus");
89

9-
if (!existsSync(path.join(opusDir, "package.json"))) {
10-
console.error(
11-
"Missing node_modules/@discordjs/opus. Run pnpm install first, then retry this opt-in installer.",
12-
);
13-
process.exit(1);
10+
export function resolveNativeOpusInstallCommand(params = {}) {
11+
return resolvePnpmRunner({
12+
comSpec: params.comSpec,
13+
nodeExecPath: params.nodeExecPath,
14+
npmExecPath: params.npmExecPath,
15+
platform: params.platform,
16+
pnpmArgs: [
17+
"--dir",
18+
params.opusDir,
19+
"exec",
20+
"node-pre-gyp",
21+
"install",
22+
"--fallback-to-build",
23+
],
24+
});
1425
}
1526

16-
const install = spawnSync(
17-
"pnpm",
18-
["--dir", opusDir, "exec", "node-pre-gyp", "install", "--fallback-to-build"],
19-
{
27+
function isDirectRun(metaUrl = import.meta.url, argvPath = process.argv[1]) {
28+
return Boolean(argvPath) && path.resolve(argvPath) === fileURLToPath(metaUrl);
29+
}
30+
31+
export function main() {
32+
if (!existsSync(path.join(opusDir, "package.json"))) {
33+
console.error(
34+
"Missing node_modules/@discordjs/opus. Run pnpm install first, then retry this opt-in installer.",
35+
);
36+
process.exit(1);
37+
}
38+
39+
const install = resolveNativeOpusInstallCommand({ opusDir });
40+
const installResult = spawnSync(install.command, install.args, {
41+
cwd: root,
42+
env: install.env ?? process.env,
43+
stdio: "inherit",
44+
shell: install.shell,
45+
windowsVerbatimArguments: install.windowsVerbatimArguments,
46+
});
47+
48+
if (installResult.status !== 0) {
49+
console.error(
50+
"Failed to install @discordjs/opus for the active Node runtime. Use Node 22 for the upstream macOS arm64 prebuild, or install a node-gyp toolchain for source builds.",
51+
);
52+
process.exit(installResult.status ?? 1);
53+
}
54+
55+
const verify = spawnSync(process.execPath, ["-e", 'require("@discordjs/opus")'], {
2056
cwd: root,
2157
env: process.env,
2258
stdio: "inherit",
23-
},
24-
);
25-
26-
if (install.status !== 0) {
27-
console.error(
28-
"Failed to install @discordjs/opus for the active Node runtime. Use Node 22 for the upstream macOS arm64 prebuild, or install a node-gyp toolchain for source builds.",
29-
);
30-
process.exit(install.status ?? 1);
31-
}
59+
});
3260

33-
const verify = spawnSync(process.execPath, ["-e", 'require("@discordjs/opus")'], {
34-
cwd: root,
35-
env: process.env,
36-
stdio: "inherit",
37-
});
61+
if (verify.status !== 0) {
62+
console.error("@discordjs/opus installed, but the active Node runtime still cannot load it.");
63+
process.exit(verify.status ?? 1);
64+
}
3865

39-
if (verify.status !== 0) {
40-
console.error("@discordjs/opus installed, but the active Node runtime still cannot load it.");
41-
process.exit(verify.status ?? 1);
66+
console.log("native opus ok");
4267
}
4368

44-
console.log("native opus ok");
69+
if (isDirectRun()) {
70+
main();
71+
}

‎src/scripts/ci-changed-scope.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ describe("detectChangedScope", () => {
318318
runChangedSmoke: false,
319319
runControlUiI18n: false,
320320
});
321+
expect(detectChangedScope(["scripts/install-discord-native-opus.mjs"])).toEqual({
322+
runNode: true,
323+
runMacos: false,
324+
runAndroid: false,
325+
runWindows: true,
326+
runSkillsPython: false,
327+
runChangedSmoke: false,
328+
runControlUiI18n: false,
329+
});
330+
expect(detectChangedScope(["test/scripts/install-discord-native-opus.test.ts"])).toEqual({
331+
runNode: true,
332+
runMacos: false,
333+
runAndroid: false,
334+
runWindows: true,
335+
runSkillsPython: false,
336+
runChangedSmoke: false,
337+
runControlUiI18n: false,
338+
});
321339
expect(detectChangedScope(["scripts/install.ps1"])).toEqual({
322340
runNode: true,
323341
runMacos: false,

‎test/package-scripts.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ describe("package scripts", () => {
107107
"test/scripts/format-generated-module.test.ts",
108108
);
109109
});
110+
111+
it("runs native opus installer coverage in Windows CI", () => {
112+
expect(readPackageJson().scripts["test:windows:ci"]).toContain(
113+
"test/scripts/install-discord-native-opus.test.ts",
114+
);
115+
});
110116
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from "vitest";
2+
import { resolveNativeOpusInstallCommand } from "../../scripts/install-discord-native-opus.mjs";
3+
4+
describe("resolveNativeOpusInstallCommand", () => {
5+
it("wraps Windows pnpm.cmd without shell mode", () => {
6+
expect(
7+
resolveNativeOpusInstallCommand({
8+
comSpec: "C:\\Windows\\System32\\cmd.exe",
9+
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
10+
npmExecPath: "C:\\Program Files\\nodejs\\pnpm.cmd",
11+
opusDir: "C:\\repo\\node_modules\\@discordjs\\opus",
12+
platform: "win32",
13+
}),
14+
).toEqual({
15+
command: "C:\\Windows\\System32\\cmd.exe",
16+
args: [
17+
"/d",
18+
"/s",
19+
"/c",
20+
'""C:\\Program Files\\nodejs\\pnpm.cmd" --dir C:\\repo\\node_modules\\@discordjs\\opus exec node-pre-gyp install --fallback-to-build"',
21+
],
22+
shell: false,
23+
windowsVerbatimArguments: true,
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)