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 HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.

<!-- unreleased changes go here -->

* Fixed
* Properly closing output file (via [#])

[#]:

## 5.0.0 - 2026-06-16

* BREAKING Changes
Expand Down
21 changes: 14 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/

import {existsSync, mkdirSync, openSync} from 'node:fs'
import {closeSync, existsSync, mkdirSync, openSync} from 'node:fs'
import {dirname, resolve} from 'node:path'

import { Builders as FromNodePackageJsonBuilders, Factories as FromNodePackageJsonFactories } from '@cyclonedx/cyclonedx-library/Contrib/FromNodePackageJson'
Expand Down Expand Up @@ -409,11 +409,18 @@ export async function run(process_: NodeJS.Process): Promise<number> {
}
outputFD = openSync(outputFPn, 'w')
}
myConsole.log('LOG | writing BOM to: %s', options.outputFile)
const written = await writeAllSync(outputFD, serialized)
myConsole.info('INFO | wrote %d bytes to %s', written, options.outputFile)

return written > 0
? ExitCode.SUCCESS
: ExitCode.FAILURE
try {
myConsole.log('LOG | writing BOM to: %s', options.outputFile)
const written = await writeAllSync(outputFD, serialized)
myConsole.info('INFO | wrote %d bytes to %s', written, options.outputFile)

return written > 0
? ExitCode.SUCCESS
: ExitCode.FAILURE
} finally {
if (outputFD !== process_.stdout.fd) {
closeSync(outputFD)
}
}
}
Loading