Skip to content

Commit c9998e3

Browse files
authored
Fix Windows dev tooling failures and DEP0190 spawn warnings (#4400)
Launch Windows command shims through cross-spawn instead of shell-backed spawn in scripts, desktop-test, and Lage's script runner (via a Yarn patch). Preserve source line endings in codemod output so codemod tests pass on Windows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 28a50096-95f4-4c6d-a164-944f2784e51a
1 parent 6b4ca4a commit c9998e3

20 files changed

Lines changed: 181 additions & 33 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/codemods': patch
3+
---
4+
5+
Preserve source line endings when printing codemod results instead of using the host platform's default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/desktop-test': patch
3+
---
4+
5+
Launch Windows command shims with escaped arguments without deprecated shell-backed spawn calls.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/dist/runners/NpmScriptRunner.js b/dist/runners/NpmScriptRunner.js
2+
index 4c4b0fd6a7877dbb5fbc65208276efb0ec912031..47c607f8324933ccc898d15f0ed04f4f55727ffb 100644
3+
--- a/dist/runners/NpmScriptRunner.js
4+
+++ b/dist/runners/NpmScriptRunner.js
5+
@@ -1,4 +1,4 @@
6+
-"use strict";Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"NpmScriptRunner",{enumerable:!0,get:function(){return g}});var b=A(require("fs")),v=A(require("path")),x=require("child_process");function C(r,n,e){return n in r?Object.defineProperty(r,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[n]=e,r}function A(r){return r&&r.__esModule?r:{default:r}}var G=2500,g=class{getTargetTask(n){let e=n.options;return(e==null?void 0:e.script)??n.task}async shouldRun(n){var i;let e=this.getTargetTask(n),p=v.default.join(n.cwd,"package.json");return!!((i=JSON.parse(b.default.readFileSync(p,"utf8")).scripts)!=null&&i[e])&&(n.shouldRun??!0)}async run(n){var O,T;let{target:e,weight:p,abortSignal:s}=n,{nodeOptions:i,npmCmd:d,taskArgs:S}=this.runnerOptions,R=this.getTargetTask(e),t;if(s){if(s.aborted)return{exitCode:1};let u=()=>{if(s.removeEventListener("abort",u),t&&!t.killed){let l=t.pid;process.stdout.write(`Abort signal detected, attempting to killing process id ${l}
7+
-`),t.kill("SIGTERM");let o=setTimeout(()=>{t&&!t.killed&&t.kill("SIGKILL")},G);o.unref&&o.unref()}};s.addEventListener("abort",u)}let _=[...S,...((O=e.options)==null?void 0:O.taskArgs)??[]],c=["run",R,..._.length>0?["--",..._]:[]],k=[i,(T=e.options)==null?void 0:T.nodeOptions].filter(Boolean).join(" ");return await new Promise((u,l)=>{t=(0,x.spawn)(d,c,{cwd:e.cwd,stdio:["inherit","pipe","pipe"],...process.platform==="win32"&&{shell:!0},env:{...process.stdout.isTTY&&{FORCE_COLOR:"1"},...process.env,...k&&{NODE_OPTIONS:k},LAGE_PACKAGE_NAME:e.packageName,LAGE_TASK:e.task,LAGE_WEIGHT:String(p)}});let o=!1,a=f=>{var m,w,E;if(t==null||t.off("exit",a),t==null||t.off("error",a),!o){if(o=!0,(m=t==null?void 0:t.stdout)==null||m.destroy(),(w=t==null?void 0:t.stderr)==null||w.destroy(),(E=t==null?void 0:t.stdin)==null||E.destroy(),f===0)return u();l({exitCode:f,error:`NPM Script Runner: ${d} ${c.join(" ")} exited with code ${f}`})}},{pid:h}=t;process.stdout.write(`Running ${[d,...c].join(" ")}, pid: ${h}
8+
+"use strict";Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"NpmScriptRunner",{enumerable:!0,get:function(){return g}});var b=A(require("fs")),v=A(require("path")),x=require("cross-spawn");function C(r,n,e){return n in r?Object.defineProperty(r,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[n]=e,r}function A(r){return r&&r.__esModule?r:{default:r}}var G=2500,g=class{getTargetTask(n){let e=n.options;return(e==null?void 0:e.script)??n.task}async shouldRun(n){var i;let e=this.getTargetTask(n),p=v.default.join(n.cwd,"package.json");return!!((i=JSON.parse(b.default.readFileSync(p,"utf8")).scripts)!=null&&i[e])&&(n.shouldRun??!0)}async run(n){var O,T;let{target:e,weight:p,abortSignal:s}=n,{nodeOptions:i,npmCmd:d,taskArgs:S}=this.runnerOptions,R=this.getTargetTask(e),t;if(s){if(s.aborted)return{exitCode:1};let u=()=>{if(s.removeEventListener("abort",u),t&&!t.killed){let l=t.pid;process.stdout.write(`Abort signal detected, attempting to killing process id ${l}
9+
+`),t.kill("SIGTERM");let o=setTimeout(()=>{t&&!t.killed&&t.kill("SIGKILL")},G);o.unref&&o.unref()}};s.addEventListener("abort",u)}let _=[...S,...((O=e.options)==null?void 0:O.taskArgs)??[]],c=["run",R,..._.length>0?["--",..._]:[]],k=[i,(T=e.options)==null?void 0:T.nodeOptions].filter(Boolean).join(" ");return await new Promise((u,l)=>{t=(0,x.spawn)(d,c,{cwd:e.cwd,stdio:["inherit","pipe","pipe"],env:{...process.stdout.isTTY&&{FORCE_COLOR:"1"},...process.env,...k&&{NODE_OPTIONS:k},LAGE_PACKAGE_NAME:e.packageName,LAGE_TASK:e.task,LAGE_WEIGHT:String(p)}});let o=!1,a=f=>{var m,w,E;if(t==null||t.off("exit",a),t==null||t.off("error",a),!o){if(o=!0,(m=t==null?void 0:t.stdout)==null||m.destroy(),(w=t==null?void 0:t.stderr)==null||w.destroy(),(E=t==null?void 0:t.stdin)==null||E.destroy(),f===0)return u();l({exitCode:f,error:`NPM Script Runner: ${d} ${c.join(" ")} exited with code ${f}`})}},{pid:h}=t;process.stdout.write(`Running ${[d,...c].join(" ")}, pid: ${h}
10+
`);let y=t.stdout,L=t.stderr;y.pipe(process.stdout),L.pipe(process.stderr),t.on("exit",a),t.on("error",()=>a(1))})}constructor(n){C(this,"runnerOptions",void 0),this.runnerOptions=n}};
11+
//# sourceMappingURL=NpmScriptRunner.js.map

‎.yarnrc.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ packageExtensions:
9393
iconv-lite@*:
9494
dependencies:
9595
iconv-lite: "*"
96+
# The Lage patch uses cross-spawn for Windows command shims without DEP0190.
97+
lage@2.14.19:
98+
dependencies:
99+
cross-spawn: "7.0.6"
96100
react-native-svg-transformer@*:
97101
peerDependencies:
98102
"@react-native/metro-babel-transformer": "*"

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"esbuild@npm:~0.25.0": "^0.28.0",
8686
"fast-uri@npm:^3.0.1": "3.1.9",
8787
"fast-xml-parser@npm:^4.4.1": "5.11.0",
88+
"lage": "patch:lage@npm%3A2.14.19#~/.yarn/patches/lage-npm-2.14.19-5dcab627c8.patch",
8889
"launch-editor@npm:^2.9.1": "2.14.2",
8990
"lodash": "^4.18.1",
9091
"moment@npm:^2.24.0": "2.31.0",

‎packages/agentic/desktop-test/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@
6464
"@rnx-kit/reporter": "catalog:",
6565
"@wdio/reporter": "catalog:",
6666
"commander": "^14.0.2",
67+
"cross-spawn": "7.0.6",
6768
"import-meta-resolve": "4.2.0"
6869
},
6970
"devDependencies": {
7071
"@fluentui-react-native/scripts": "workspace:*",
72+
"@types/cross-spawn": "6.0.6",
7173
"@wdio/cli": "catalog:",
7274
"@wdio/jasmine-framework": "catalog:",
7375
"@wdio/local-runner": "catalog:",

‎packages/agentic/desktop-test/references/lifecycle.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Cleanup drains worker reporting and stdio, closes sessions, releases owned
1515
input, and stops exact owned process trees in reverse service order. An
1616
externally owned app is preserved.
1717

18+
Commands keep their arguments as separate values. Windows executable lookup and
19+
command-shim escaping use `cross-spawn`, without Node's deprecated
20+
`spawn` argument array plus `shell: true` combination.
21+
1822
Interactive runs acquire a per-user `interactive.lock`; concurrent workloads
1923
fail closed. If a crash leaves a lock, inspect its recorded owner and verify
2024
that process and its resources have stopped before removing that exact lock.

‎packages/agentic/desktop-test/src/commands.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { spawn } from 'node:child_process';
1+
import { spawn as spawnNative } from 'node:child_process';
2+
import spawn from 'cross-spawn';
23
import fs from 'node:fs';
34
import path from 'node:path';
45
import { randomUUID } from 'node:crypto';
@@ -101,11 +102,11 @@ export class NodeDesktopCommandRunner implements DesktopCommandRunner {
101102
command.context,
102103
);
103104
emit({ kind: 'artifact', payload: { path: relativeLog, description: command.label ?? command.command } }, id, command.context);
104-
const child = spawn(command.command, [...command.args], {
105+
const spawnCommand = needsWindowsCommandShim(command.command) ? spawn : spawnNative;
106+
const child = spawnCommand(command.command, [...command.args], {
105107
cwd: command.cwd,
106108
env: { ...process.env, ...command.env, ...this.options.environment, [DESKTOP_REPORT_SCOPE]: id },
107109
detached: process.platform !== 'win32',
108-
shell: windowsShell(command.command),
109110
stdio: ['ignore', 'pipe', 'pipe'],
110111
windowsHide: true,
111112
});
@@ -252,7 +253,7 @@ export class NodeDesktopCommandRunner implements DesktopCommandRunner {
252253
}
253254
}
254255

255-
function windowsShell(command: string): boolean {
256+
function needsWindowsCommandShim(command: string): boolean {
256257
return (
257258
process.platform === 'win32' &&
258259
!['.exe', '.com'].includes(path.extname(command).toLowerCase()) &&
@@ -262,7 +263,7 @@ function windowsShell(command: string): boolean {
262263

263264
async function stopProcessTree(pid: number, completed: Promise<number>, timeoutMs: number): Promise<void> {
264265
if (process.platform === 'win32') {
265-
const killer = spawn('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
266+
const killer = spawnNative('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
266267
let diagnostic = '';
267268
killer.stdout.on('data', (data: Buffer) => {
268269
diagnostic += data.toString();

‎packages/agentic/desktop-test/src/contracts.contract.cjs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,34 @@ async function main() {
323323
.slice(out.text().indexOf('::group::one'), out.text().indexOf('::endgroup::', out.text().indexOf('::group::one')));
324324
assert(groupOne.includes('::stop-commands::'));
325325
assert(!groupOne.includes('::warning::two'));
326+
} else if (mode === 'command-arguments') {
327+
const run = reporter({ kind: 'lifecycle' });
328+
const runner = new NodeDesktopCommandRunner({ reporter: run });
329+
const bin = path.join(root, 'command shims (test)');
330+
fs.mkdirSync(bin);
331+
const fixture = path.join(bin, 'argv.cjs');
332+
fs.writeFileSync(fixture, "require('node:fs').writeFileSync(process.argv[2], JSON.stringify(process.argv.slice(3)));");
333+
const output = path.join(root, 'arguments.json');
334+
const values = ['', 'with spaces', 'a&b|(c)<d>^e', '"quoted"', 'trailing\\', '%COMMAND_TEST_VALUE%'];
335+
let prepared = {
336+
command: process.execPath,
337+
args: [fixture, output, ...values],
338+
cwd: root,
339+
env: { COMMAND_TEST_VALUE: 'must not expand' },
340+
};
341+
if (process.platform === 'win32') {
342+
fs.writeFileSync(path.join(bin, 'argv-fixture.cmd'), '@"%COMMAND_TEST_NODE%" "%~dp0argv.cjs" %*\r\n');
343+
prepared = {
344+
...prepared,
345+
command: 'argv-fixture',
346+
args: [output, ...values],
347+
env: { ...prepared.env, COMMAND_TEST_NODE: process.execPath, PATH: `${bin}${path.delimiter}${process.env.PATH}` },
348+
};
349+
}
350+
await runner.run(prepared);
351+
assert.deepEqual(JSON.parse(fs.readFileSync(output, 'utf8')), values);
352+
const result = await run.finish();
353+
assert.equal(result.status, 'passed');
326354
} else if (mode === 'transport') {
327355
const { startReportTransport } = await import(lib('reporting/transport.js'));
328356
const run = reporter({ kind: 'lifecycle' });

‎packages/agentic/desktop-test/src/contracts.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('neutral desktop harness contracts', () => {
77
'adapters',
88
'reporting',
99
'commands',
10+
'command-arguments',
1011
'transport',
1112
'delegated-cli',
1213
'services',
@@ -31,7 +32,9 @@ describe('neutral desktop harness contracts', () => {
3132

3233
function runContract(mode: string): Promise<unknown> {
3334
return new Promise((resolve, reject) => {
34-
const child = spawn(process.execPath, [path.join(__dirname, 'contracts.contract.cjs'), mode], { stdio: ['ignore', 'pipe', 'pipe'] });
35+
const child = spawn(process.execPath, ['--throw-deprecation', path.join(__dirname, 'contracts.contract.cjs'), mode], {
36+
stdio: ['ignore', 'pipe', 'pipe'],
37+
});
3538
const stdout: Buffer[] = [];
3639
const stderr: Buffer[] = [];
3740
child.stdout.on('data', (chunk: Buffer) => stdout.push(chunk));

0 commit comments

Comments
 (0)