diff --git a/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json new file mode 100644 index 00000000000..8b4b930620c --- /dev/null +++ b/common/changes/@rushstack/package-deps-hash/avoid-getrepostate-to-crash_2024-01-11-09-03.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/package-deps-hash", + "comment": "Handle an edge case in `getRepoState` wherein it tries to asynchronously pipe data to `git hash-object` but the subprocess has already exited.", + "type": "patch" + } + ], + "packageName": "@rushstack/package-deps-hash" +} \ No newline at end of file diff --git a/libraries/package-deps-hash/package.json b/libraries/package-deps-hash/package.json index 0e6f0a6a136..9f5aefaa90b 100644 --- a/libraries/package-deps-hash/package.json +++ b/libraries/package-deps-hash/package.json @@ -17,7 +17,6 @@ }, "devDependencies": { "@rushstack/heft": "workspace:*", - "@rushstack/node-core-library": "workspace:*", "local-node-rig": "workspace:*" }, "dependencies": { diff --git a/libraries/package-deps-hash/src/getRepoState.ts b/libraries/package-deps-hash/src/getRepoState.ts index f28e723ce8b..7af4d11f5e9 100644 --- a/libraries/package-deps-hash/src/getRepoState.ts +++ b/libraries/package-deps-hash/src/getRepoState.ts @@ -3,7 +3,7 @@ import type * as child_process from 'child_process'; import { once } from 'events'; -import { Readable } from 'stream'; +import { Readable, pipeline } from 'stream'; import { Executable, FileSystem, type IExecutableSpawnOptions } from '@rushstack/node-core-library'; @@ -282,7 +282,12 @@ async function spawnGitAsync( }); if (stdin) { - stdin.pipe(proc.stdin!); + /** + * For `git hash-object` data is piped in asynchronously. In the event that one of the + * passed filenames cannot be hashed, subsequent writes to `proc.stdin` will error. + * Silence this error since it will be handled by the non-zero exit code of the process. + */ + pipeline(stdin, proc.stdin!, (err) => {}); } const [status] = await once(proc, 'exit');