Skip to content

Commit 9b72237

Browse files
authored
fix: properly create outpur dir if needed (#1377)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent ce6707c commit 9b72237

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
<!-- unreleased changes go here -->
88

9+
* Fixed
10+
* Create output dir properly if needed (via [#1377])
11+
12+
[#1377]: https://github.com/CycloneDX/cyclonedx-node-npm/pull/1377
13+
914
## 4.1.0 - 2025-10-29
1015

1116
* Added

src/cli.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,20 @@ export async function run(process_: NodeJS.Process): Promise<number> {
387387
}
388388
}
389389
}
390-
const directory = dirname(options.outputFile)
391-
if (!existsSync(directory)) {
392-
myConsole.info('INFO | creating directory', directory)
393-
mkdirSync(directory, {recursive: true})
390+
391+
let outputFD: number = process_.stdout.fd
392+
if (options.outputFile !== OutputStdOut) {
393+
const outputFPn = resolve(process_.cwd(), options.outputFile)
394+
myConsole.debug('DEBUG | outputFPn:', outputFPn)
395+
const outputFDir = dirname(outputFPn)
396+
if (!existsSync(outputFDir)) {
397+
myConsole.info('INFO | creating directory', outputFDir)
398+
mkdirSync(outputFDir, {recursive: true})
399+
}
400+
outputFD = openSync(outputFPn, 'w')
394401
}
395-
myConsole.log('LOG | writing BOM to', options.outputFile)
396-
const written = await writeAllSync(
397-
options.outputFile === OutputStdOut
398-
? process_.stdout.fd
399-
: openSync(resolve(process_.cwd(), options.outputFile), 'w'),
400-
serialized
401-
)
402+
myConsole.log('LOG | writing BOM to: %s', options.outputFile)
403+
const written = await writeAllSync(outputFD, serialized)
402404
myConsole.info('INFO | wrote %d bytes to %s', written, options.outputFile)
403405

404406
return written > 0

0 commit comments

Comments
 (0)