Skip to content

Commit 4ac8c52

Browse files
committed
feat: add support for targetting specific workspaces
Signed-off-by: MalickBurger <[email protected]>
1 parent 4c03947 commit 4ac8c52

File tree

4 files changed

+54
-38
lines changed

4 files changed

+54
-38
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ Please sign off your commits, to show that you agree to publish your changes und
4747
, and to indicate agreement with [Developer Certificate of Origin (DCO)](https://developercertificate.org/).
4848

4949
```shell
50-
git commit --signed-off ...
50+
git commit --signoff ...
5151
```

README.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,45 @@ Usage: cyclonedx-npm [options] [--] [<package-manifest>]
7474
Create CycloneDX Software Bill of Materials (SBOM) from Node.js NPM projects.
7575
7676
Arguments:
77-
<package-manifest> Path to project's manifest file.
78-
(default: "package.json" file in current working directory)
77+
<package-manifest> Path to project's manifest file.
78+
(default: "package.json" file in current working directory)
7979
8080
Options:
81-
--ignore-npm-errors Whether to ignore errors of NPM.
82-
This might be used, if "npm install" was run with "--force" or "--legacy-peer-deps".
83-
(default: false)
84-
--package-lock-only Whether to only use the lock file, ignoring "node_modules".
85-
This means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.
86-
(default: false)
87-
--omit <type...> Dependency types to omit from the installation tree.
88-
(can be set multiple times)
89-
(choices: "dev", "optional", "peer", default: "dev" if the NODE_ENV environment variable is set to "production", otherwise empty)
90-
--flatten-components Whether to flatten the components.
91-
This means the actual nesting of node packages is not represented in the SBOM result.
92-
(default: false)
93-
--short-PURLs Omit all qualifiers from PackageURLs.
94-
This causes information loss in trade-off shorter PURLs, which might improve ingesting these strings.
95-
(default: false)
96-
--spec-version <version> Which version of CycloneDX spec to use.
97-
(choices: "1.2", "1.3", "1.4", "1.5", "1.6", default: "1.4")
98-
--output-reproducible Whether to go the extra mile and make the output reproducible.
99-
This requires more resources, and might result in loss of time- and random-based-values.
100-
(env: BOM_REPRODUCIBLE)
101-
--output-format <format> Which output format to use.
102-
(choices: "JSON", "XML", default: "JSON")
103-
--output-file <file> Path to the output file.
104-
Set to "-" to write to STDOUT.
105-
(default: write to STDOUT)
106-
--validate Validate resulting BOM before outputting.
107-
Validation is skipped, if requirements not met. See the README.
108-
--no-validate Disable validation of resulting BOM.
109-
--mc-type <type> Type of the main component.
110-
(choices: "application", "firmware", "library", default: "application")
111-
-v, --verbose Increase the verbosity of messages.
112-
Use multiple times to increase the verbosity even more.
113-
-V, --version output the version number
114-
-h, --help display help for command
81+
--ignore-npm-errors Whether to ignore errors of NPM.
82+
This might be used, if "npm install" was run with "--force" or "--legacy-peer-deps".
83+
(default: false)
84+
--package-lock-only Whether to only use the lock file, ignoring "node_modules".
85+
This means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.
86+
(default: false)
87+
--omit <type...> Dependency types to omit from the installation tree.
88+
(can be set multiple times)
89+
(choices: "dev", "optional", "peer", default: "dev" if the NODE_ENV environment variable is set to "production", otherwise empty)
90+
--flatten-components Whether to flatten the components.
91+
This means the actual nesting of node packages is not represented in the SBOM result.
92+
(default: false)
93+
--short-PURLs Omit all qualifiers from PackageURLs.
94+
This causes information loss in trade-off shorter PURLs, which might improve ingesting these strings.
95+
(default: false)
96+
--spec-version <version> Which version of CycloneDX spec to use.
97+
(choices: "1.2", "1.3", "1.4", "1.5", "1.6", default: "1.4")
98+
--output-reproducible Whether to go the extra mile and make the output reproducible.
99+
This requires more resources, and might result in loss of time- and random-based-values.
100+
(env: BOM_REPRODUCIBLE)
101+
--output-format <format> Which output format to use.
102+
(choices: "JSON", "XML", default: "JSON")
103+
--output-file <file> Path to the output file.
104+
Set to "-" to write to STDOUT.
105+
(default: write to STDOUT)
106+
--validate Validate resulting BOM before outputting.
107+
Validation is skipped, if requirements not met. See the README.
108+
--no-validate Disable validation of resulting BOM.
109+
--mc-type <type> Type of the main component.
110+
(choices: "application", "firmware", "library", default: "application")
111+
--workspaces <workspace...> Whether to only include dependencies for specific workspaces. (can be set multiple times) (default: empty)
112+
-v, --verbose Increase the verbosity of messages.
113+
Use multiple times to increase the verbosity even more.
114+
-V, --version output the version number
115+
-h, --help display help for command
115116
```
116117

117118
## Demo

src/builders.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface BomBuilderOptions {
3838
reproducible?: BomBuilder['reproducible']
3939
flattenComponents?: BomBuilder['flattenComponents']
4040
shortPURLs?: BomBuilder['shortPURLs']
41+
workspaces?: BomBuilder['workspaces']
4142
}
4243

4344
type cPath = string
@@ -57,6 +58,7 @@ export class BomBuilder {
5758
reproducible: boolean
5859
flattenComponents: boolean
5960
shortPURLs: boolean
61+
workspaces: string[]
6062

6163
console: Console
6264

@@ -80,6 +82,7 @@ export class BomBuilder {
8082
this.reproducible = options.reproducible ?? false
8183
this.flattenComponents = options.flattenComponents ?? false
8284
this.shortPURLs = options.shortPURLs ?? false
85+
this.workspaces = options.workspaces ?? []
8386

8487
this.console = console_
8588
}
@@ -166,6 +169,10 @@ export class BomBuilder {
166169
}
167170
}
168171

172+
for (const workspace of this.workspaces) {
173+
args.push(`--workspace=${workspace}`)
174+
}
175+
169176
this.console.info('INFO | gathering dependency tree ...')
170177
this.console.debug('DEBUG | npm-ls: run npm with %j in %j', args, projectDir)
171178
let npmLsReturns: Buffer

src/cli.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface CommandOptions {
5151
outputFile: string
5252
validate: boolean | undefined
5353
mcType: Enums.ComponentType
54+
workspace: string[] | undefined
5455
verbose: number
5556
}
5657

@@ -166,6 +167,12 @@ function makeCommand (process: NodeJS.Process): Command {
166167
).default(
167168
Enums.ComponentType.Application
168169
)
170+
).addOption(
171+
new Option(
172+
'--workspaces <workspace...>',
173+
'Whether to only include dependencies for specific workspaces. ' +
174+
'(can be set multiple times)'
175+
).default([], 'empty')
169176
).addOption(
170177
new Option(
171178
'-v, --verbose',
@@ -249,7 +256,8 @@ export async function run (process: NodeJS.Process): Promise<number> {
249256
omitDependencyTypes: options.omit,
250257
reproducible: options.outputReproducible,
251258
flattenComponents: options.flattenComponents,
252-
shortPURLs: options.shortPURLs
259+
shortPURLs: options.shortPURLs,
260+
workspaces: options.workspace
253261
},
254262
myConsole
255263
).buildFromProjectDir(projectDir, process)

0 commit comments

Comments
 (0)