Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/codemod-source-line-endings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fluentui-react-native/codemods': patch
---

Preserve source line endings when printing codemod results instead of using the host platform's default.
5 changes: 5 additions & 0 deletions .changeset/windows-tooling-command-spawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fluentui-react-native/desktop-test': patch
---

Launch Windows command shims with escaped arguments without deprecated shell-backed spawn calls.
11 changes: 11 additions & 0 deletions .yarn/patches/lage-npm-2.14.19-5dcab627c8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/dist/runners/NpmScriptRunner.js b/dist/runners/NpmScriptRunner.js
index 4c4b0fd6a7877dbb5fbc65208276efb0ec912031..47c607f8324933ccc898d15f0ed04f4f55727ffb 100644
--- a/dist/runners/NpmScriptRunner.js
+++ b/dist/runners/NpmScriptRunner.js
@@ -1,4 +1,4 @@
-"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}
-`),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}
+"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}
+`),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}
`);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}};
//# sourceMappingURL=NpmScriptRunner.js.map
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ packageExtensions:
iconv-lite@*:
dependencies:
iconv-lite: "*"
# The Lage patch uses cross-spawn for Windows command shims without DEP0190.
lage@2.14.19:
dependencies:
cross-spawn: "7.0.6"
react-native-svg-transformer@*:
peerDependencies:
"@react-native/metro-babel-transformer": "*"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"esbuild@npm:~0.25.0": "^0.28.0",
"fast-uri@npm:^3.0.1": "3.1.9",
"fast-xml-parser@npm:^4.4.1": "5.11.0",
"lage": "patch:lage@npm%3A2.14.19#~/.yarn/patches/lage-npm-2.14.19-5dcab627c8.patch",
"launch-editor@npm:^2.9.1": "2.14.2",
"lodash": "^4.18.1",
"moment@npm:^2.24.0": "2.31.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/agentic/desktop-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
"@rnx-kit/reporter": "catalog:",
"@wdio/reporter": "catalog:",
"commander": "^14.0.2",
"cross-spawn": "7.0.6",
"import-meta-resolve": "4.2.0"
},
"devDependencies": {
"@fluentui-react-native/scripts": "workspace:*",
"@types/cross-spawn": "6.0.6",
"@wdio/cli": "catalog:",
"@wdio/jasmine-framework": "catalog:",
"@wdio/local-runner": "catalog:",
Expand Down
4 changes: 4 additions & 0 deletions packages/agentic/desktop-test/references/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Cleanup drains worker reporting and stdio, closes sessions, releases owned
input, and stops exact owned process trees in reverse service order. An
externally owned app is preserved.

Commands keep their arguments as separate values. Windows executable lookup and
command-shim escaping use `cross-spawn`, without Node's deprecated
`spawn` argument array plus `shell: true` combination.

Interactive runs acquire a per-user `interactive.lock`; concurrent workloads
fail closed. If a crash leaves a lock, inspect its recorded owner and verify
that process and its resources have stopped before removing that exact lock.
Expand Down
11 changes: 6 additions & 5 deletions packages/agentic/desktop-test/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process';
import { spawn as spawnNative } from 'node:child_process';
import spawn from 'cross-spawn';
import fs from 'node:fs';
import path from 'node:path';
import { randomUUID } from 'node:crypto';
Expand Down Expand Up @@ -101,11 +102,11 @@ export class NodeDesktopCommandRunner implements DesktopCommandRunner {
command.context,
);
emit({ kind: 'artifact', payload: { path: relativeLog, description: command.label ?? command.command } }, id, command.context);
const child = spawn(command.command, [...command.args], {
const spawnCommand = needsWindowsCommandShim(command.command) ? spawn : spawnNative;
const child = spawnCommand(command.command, [...command.args], {
cwd: command.cwd,
env: { ...process.env, ...command.env, ...this.options.environment, [DESKTOP_REPORT_SCOPE]: id },
detached: process.platform !== 'win32',
shell: windowsShell(command.command),
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
});
Expand Down Expand Up @@ -252,7 +253,7 @@ export class NodeDesktopCommandRunner implements DesktopCommandRunner {
}
}

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

async function stopProcessTree(pid: number, completed: Promise<number>, timeoutMs: number): Promise<void> {
if (process.platform === 'win32') {
const killer = spawn('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
const killer = spawnNative('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
let diagnostic = '';
killer.stdout.on('data', (data: Buffer) => {
diagnostic += data.toString();
Expand Down
28 changes: 28 additions & 0 deletions packages/agentic/desktop-test/src/contracts.contract.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,34 @@ async function main() {
.slice(out.text().indexOf('::group::one'), out.text().indexOf('::endgroup::', out.text().indexOf('::group::one')));
assert(groupOne.includes('::stop-commands::'));
assert(!groupOne.includes('::warning::two'));
} else if (mode === 'command-arguments') {
const run = reporter({ kind: 'lifecycle' });
const runner = new NodeDesktopCommandRunner({ reporter: run });
const bin = path.join(root, 'command shims (test)');
fs.mkdirSync(bin);
const fixture = path.join(bin, 'argv.cjs');
fs.writeFileSync(fixture, "require('node:fs').writeFileSync(process.argv[2], JSON.stringify(process.argv.slice(3)));");
const output = path.join(root, 'arguments.json');
const values = ['', 'with spaces', 'a&b|(c)<d>^e', '"quoted"', 'trailing\\', '%COMMAND_TEST_VALUE%'];
let prepared = {
command: process.execPath,
args: [fixture, output, ...values],
cwd: root,
env: { COMMAND_TEST_VALUE: 'must not expand' },
};
if (process.platform === 'win32') {
fs.writeFileSync(path.join(bin, 'argv-fixture.cmd'), '@"%COMMAND_TEST_NODE%" "%~dp0argv.cjs" %*\r\n');
prepared = {
...prepared,
command: 'argv-fixture',
args: [output, ...values],
env: { ...prepared.env, COMMAND_TEST_NODE: process.execPath, PATH: `${bin}${path.delimiter}${process.env.PATH}` },
};
}
await runner.run(prepared);
assert.deepEqual(JSON.parse(fs.readFileSync(output, 'utf8')), values);
const result = await run.finish();
assert.equal(result.status, 'passed');
} else if (mode === 'transport') {
const { startReportTransport } = await import(lib('reporting/transport.js'));
const run = reporter({ kind: 'lifecycle' });
Expand Down
5 changes: 4 additions & 1 deletion packages/agentic/desktop-test/src/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('neutral desktop harness contracts', () => {
'adapters',
'reporting',
'commands',
'command-arguments',
'transport',
'delegated-cli',
'services',
Expand All @@ -31,7 +32,9 @@ describe('neutral desktop harness contracts', () => {

function runContract(mode: string): Promise<unknown> {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [path.join(__dirname, 'contracts.contract.cjs'), mode], { stdio: ['ignore', 'pipe', 'pipe'] });
const child = spawn(process.execPath, ['--throw-deprecation', path.join(__dirname, 'contracts.contract.cjs'), mode], {
stdio: ['ignore', 'pipe', 'pipe'],
});
const stdout: Buffer[] = [];
const stderr: Buffer[] = [];
child.stdout.on('data', (chunk: Buffer) => stdout.push(chunk));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { defineTest } from 'jscodeshift/dist/testUtils';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { applyTransform, defineTest } from 'jscodeshift/dist/testUtils';
import transform from '../button-v0-to-v1';

jest.autoMockOff();

describe('button-v0-to-v1', () => {
defineTest(__dirname, 'button-v0-to-v1', null, 'button-v0-to-v1', { parser: 'tsx' });

test('preserves CRLF source line endings', () => {
const fixture = (kind: string) =>
readFileSync(path.join(__dirname, '..', '__testfixtures__', `button-v0-to-v1.${kind}.tsx`), 'utf8')
.replaceAll('\r\n', '\n')
.replaceAll('\n', '\r\n');
expect(applyTransform(transform, {}, { source: fixture('input') }, { parser: 'tsx' })).toBe(fixture('output').trim());
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { defineTest } from 'jscodeshift/dist/testUtils';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { applyTransform, defineTest } from 'jscodeshift/dist/testUtils';
import transform from '../deprecate-exports';

jest.autoMockOff();

describe('deprecate-exports', () => {
defineTest(__dirname, 'deprecate-exports', null, 'deprecate-exports', { parser: 'tsx' });

test('preserves CRLF source line endings', () => {
const fixture = (kind: string) =>
readFileSync(path.join(__dirname, '..', '__testfixtures__', `deprecate-exports.${kind}.tsx`), 'utf8')
.replaceAll('\r\n', '\n')
.replaceAll('\n', '\r\n');
expect(applyTransform(transform, {}, { source: fixture('input') }, { parser: 'tsx' })).toBe(fixture('output').trim());
});
});
1 change: 1 addition & 0 deletions packages/codemods/src/transforms/button-v0-to-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const transform: Transform = (fileInfo: FileInfo, api: API, options: Opti
const j: JSCodeshift = api.jscodeshift;

const printOptions = options.printOptions || {
lineTerminator: fileInfo.source.includes('\r\n') ? '\r\n' : '\n',
printWidth: 140,
quote: 'single',
tabWidth: 2,
Expand Down
1 change: 1 addition & 0 deletions packages/codemods/src/transforms/deprecate-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const transform: Transform = (fileInfo: FileInfo, api: API, options: Opti
const j: JSCodeshift = api.jscodeshift;

const printOptions = options.printOptions || {
lineTerminator: fileInfo.source.includes('\r\n') ? '\r\n' : '\n',
printWidth: 140,
quote: 'single',
tabWidth: 2,
Expand Down
3 changes: 3 additions & 0 deletions references/agents/repository/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Set up a clone with `yarn` to install dependencies, then `yarn build`.
| `yarn change` / `change:check` | Create or validate changesets; see [release](release.md) |

Lage caches task outputs in `node_modules/.cache/lage`. Iterate with cached runs, and add `--verbose` for detail.
The repository patches Lage 2.14.19's task runner to use `cross-spawn` instead of spawning argument arrays with
`shell: true` on Windows. The root resolution and matching `.yarnrc.yml` package extension must stay together;
remove both once the upstream runner supports Windows command shims without DEP0190.
`--no-cache` bypasses the cache for one run but leaves earlier entries in place, so a later cached run can still reuse
results for tasks the uncached run never reached. For final validation, clear the cache instead (R-VALID-003). Before committing moved or renamed files, run
`yarn lage test-links` and update stale links.
Expand Down
4 changes: 3 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"bundlesize": "bundlesize --debug",
"format": "node ./src/cli.ts format",
"lint": "node ./src/cli.ts lint",
"test": "node --test src/tasks/agentInstructions.test.ts src/tasks/clean.test.mjs src/utils/jestSelection.test.ts"
"test": "node --test src/tasks/agentInstructions.test.ts src/tasks/clean.test.mjs src/utils/jestSelection.test.ts src/utils/runScript.test.ts"
},
"dependencies": {
"@babel/core": "catalog:",
Expand All @@ -53,6 +53,7 @@
"@rnx-kit/tsconfig": "catalog:",
"@rnx-kit/types-kit-config": "catalog:",
"babel-jest": "^29.0.0",
"cross-spawn": "7.0.6",
"oxlint": "1.76.0"
},
"devDependencies": {
Expand All @@ -72,6 +73,7 @@
"@rnx-kit/tsconfig": "catalog:",
"@rnx-kit/types-kit-config": "catalog:",
"@rnx-kit/types-node": "catalog:",
"@types/cross-spawn": "6.0.6",
"@types/micromatch": "^4.0.9",
"@types/node": "catalog:",
"@yarnpkg/types": "^4.0.1",
Expand Down
7 changes: 5 additions & 2 deletions scripts/src/tasks/checkPackageContentsTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, readFileSync } from 'node:fs';
import path from 'node:path';

import { Command } from 'clipanion';
import spawn from 'cross-spawn';
import micromatch from 'micromatch';
import { findGitRoot } from 'workspace-tools';

Expand Down Expand Up @@ -87,14 +88,16 @@ export class CheckPackageContentsCommand extends Command {

let locations: Set<string>;
try {
const output = execFileSync('yarn', ['pack', '--dry-run', '--json'], {
const result = spawn.sync('yarn', ['pack', '--dry-run', '--json'], {
cwd: packageRoot,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
maxBuffer: 64 * 1024 * 1024,
});
if (result.error) throw result.error;
if (result.status !== 0) throw new Error(result.stderr || `Yarn exited with ${result.status ?? result.signal}`);
locations = new Set(
output
result.stdout
.split(/\r?\n/)
.filter(Boolean)
.map((line) => JSON.parse(line) as { location?: string })
Expand Down
19 changes: 19 additions & 0 deletions scripts/src/utils/runScript.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import assert from 'node:assert/strict';
import { it } from 'node:test';

import { captureScript, runYarn } from './runScript.ts';

it('launches Yarn without relying on a shell-backed spawn', async () => {
assert.equal(await runYarn('--version'), 0);
});

it('preserves a nonzero Yarn command exit status', async () => {
assert.equal(await runYarn('node', '-e', 'process.exit(7)'), 7);
});

it('captures a package binary output and preserves argument boundaries', async () => {
const pattern = 'test with spaces & (parentheses) "quotes"';
const result = await captureScript('jest', ['--showConfig', '--testNamePattern', pattern]);
assert.equal(result.code, 0);
assert.equal(JSON.parse(result.stdout).globalConfig.testNamePattern, pattern);
});
24 changes: 14 additions & 10 deletions scripts/src/utils/runScript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, type SpawnOptions } from 'node:child_process';
import type { SpawnOptions } from 'node:child_process';
import spawn from 'cross-spawn';
import { PackageContext } from '../pkgContext.ts';
import os from 'node:os';

Expand All @@ -24,7 +25,6 @@ function resolveScript(command: string, args: string[], options?: SpawnOptions):
const spawnOptions: SpawnOptions = {
cwd: process.cwd(),
stdio: 'inherit',
shell: verb.endsWith('.cmd') || verb.endsWith('.bat') ? true : undefined,
...options,
};
return [verb, spawnArgs, spawnOptions];
Expand All @@ -33,10 +33,12 @@ function resolveScript(command: string, args: string[], options?: SpawnOptions):
export async function runScript(command: string, args: string[], options?: SpawnOptions): Promise<number> {
const [verb, spawnArgs, spawnOptions] = resolveScript(command, args, options);

return new Promise((resolve) => {
spawn(verb, spawnArgs, spawnOptions).on('close', (code) => {
resolve(code ?? -1);
});
return new Promise((resolve, reject) => {
spawn(verb, spawnArgs, spawnOptions)
.on('error', reject)
.on('close', (code) => {
resolve(code ?? -1);
});
});
}

Expand All @@ -63,12 +65,14 @@ export async function captureScript(command: string, args: string[], options?: S
export async function runYarn(command: string, ...args: string[]): Promise<number> {
const verb = yarnVerb;
const spawnArgs = [command, ...args];
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
spawn(verb, spawnArgs, {
cwd: process.cwd(),
stdio: 'inherit',
}).on('close', (code) => {
resolve(code ?? -1);
});
})
.on('error', reject)
.on('close', (code) => {
resolve(code ?? -1);
});
});
}
Loading
Loading