Skip to content

feat(contrib): populate component tags from npm keywords - #1511

Open
CAOShurong wants to merge 2 commits into
CycloneDX:mainfrom
CAOShurong:codex/add-component-tags
Open

feat(contrib): populate component tags from npm keywords#1511
CAOShurong wants to merge 2 commits into
CycloneDX:mainfrom
CAOShurong:codex/add-component-tags

Conversation

@CAOShurong

@CAOShurong CAOShurong commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Closes #1055

Summary

Adds tags support to the Component model and populates it from array-form npm package.json keywords, serializing tags in both JSON and XML for CycloneDX 1.6 and later.

Changes

  • Component.tags is a Set<string> with an empty default and participates in component comparison.
  • Contrib.FromNodePackageJson.Builders.ComponentBuilder collects normalized array-form keywords through a dedicated generator, ignores non-array input, and filters non-string entries.
  • JSON and XML normalizers emit sorted tags for CycloneDX 1.6 and 1.7 only.
  • createComplexStructure covers tags and the JSON/XML normalization and serialization snapshots are updated for 1.6/1.7.
  • Builder and model tests cover empty/default tags, malformed keywords, and comparison behavior.
  • HISTORY.md records the model, serializer/normalizer, and contrib-builder capabilities separately.

The unrelated entity-address work remains split into #1513.

Verification

  • Full Node test suite: 4170 passing, 4 pending, 0 failing
  • npm run test:lint: passed
  • Full repository ESLint: passed
  • npm run build:node: passed
  • npm run build:web: passed
  • Type declaration build stage: passed (the existing Windows cpy post-script reports No files matched)

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: OpenAI Codex
    • LLMs and versions: GPT-5 family
    • Prompts: Asked Codex to implement component tags from normalized npm keywords, follow maintainer review on data shape, comparison, changelog and fixture snapshots, and verify the focused and full test/build paths.

Fills component.tags from the npm package.json keywords property in
ComponentBuilder, and serialises tags in both JSON and XML for CycloneDX
1.6 and later (tags were introduced in 1.6).

- Add optional tags to the Component model and JSON/XML serialisation
- Add supportsComponentTags to the spec protocol, gated to 1.6+

Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
@CAOShurong
CAOShurong requested a review from a team as a code owner August 21, 2026 21:14
@codacy-production

codacy-production Bot commented Aug 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -1 duplication

Metric Results
Complexity 0
Duplication -1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@read-the-docs-community

read-the-docs-community Bot commented Aug 21, 2026

Copy link
Copy Markdown

Documentation build overview

📚 CycloneDX JavaScript Library | 🛠️ Build #34260958 | 📁 Comparing f837fca against latest (ed03365)

  🔍 Preview build  

2 files changed
± changelog.html
± index.html

@jkowalleck
jkowalleck marked this pull request as draft August 24, 2026 12:47
@jkowalleck

This comment was marked as outdated.

@CAOShurong
CAOShurong marked this pull request as ready for review August 25, 2026 18:20
@CAOShurong

Copy link
Copy Markdown
Contributor Author

The AI Tool Disclosure section from the PR template is now filled in (OpenAI Codex CLI / GPT-5-Codex, with a summary of the prompts). Sorry for missing it — happy to adjust anything else.

@jkowalleck jkowalleck added the enhancement New feature or request label Aug 26, 2026
group,
licenses,
properties,
tags: typeof data.keywords === 'string'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better have this collection of tags separate - just like properties above.

Also, we dont care for any keywords that is not an array ....

As the doc string says:

Intended to run on normalized data structures

suggestion:

const tags = new Set(this.#makeTags(data.keywords))
* #makeTags (keywords: NodePackageJson['keywords']): Generator<string> {
  if (!Array.isArray(keywords)) continue;
  for (const kw of keywords) {
    if (typeof kw === 'string') {
      yield kw
    }
  }
}

Comment thread src/models/component.ts Outdated
purl?: string
scope?: ComponentScope
supplier?: OrganizationalEntity
tags?: string[]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better:

Suggested change
tags?: string[]
keywords?: Set<string>

and the new property is misisng in the compare function

@jkowalleck jkowalleck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are missing - please add the new capabilities to the createComplexStructure in file tests/_data/models.js and have the test running and snapshots updated.

see https://github.com/CycloneDX/cyclonedx-javascript-library/blob/main/tests/README.md

Comment thread HISTORY.md Outdated

<!-- add unreleased items here -->
* Added
* `Contrib.FromNodePackageJson.Builders.ComponentBuilder` populates component `tags` from the npm `keywords` property; `tags` are serialised in JSON and XML for CycloneDX 1.6 and later ([#1055])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split those new capabilities -and make them a post shorter, if possible, see the changelog from the past .
something like

Suggested change
* `Contrib.FromNodePackageJson.Builders.ComponentBuilder` populates component `tags` from the npm `keywords` property; `tags` are serialised in JSON and XML for CycloneDX 1.6 and later ([#1055])
* component model knownstags
* serializers and normalizers canemit component tags
* that contrib builder may populate tags ([#1055] via [#1511])

Comment thread HISTORY.md
* Added
* `Contrib.FromNodePackageJson.Builders.ComponentBuilder` populates component `tags` from the npm `keywords` property; `tags` are serialised in JSON and XML for CycloneDX 1.6 and later ([#1055])

[#1055]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1055

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[#1055]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1055
[#1055]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1055
[#1511]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1511

Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
@CAOShurong

Copy link
Copy Markdown
Contributor Author

Addressed all requested changes in f837fca:

  • tags are now a separate Set<string> and participate in Component.compare();
  • the contrib builder accepts only array-form keywords through #makeTags() and filters non-strings;
  • the changelog is split into the three shorter capability entries with the feat(contrib): populate component tags from npm keywords #1511 link;
  • createComplexStructure now includes unsorted tags, with updated sorted-normalizer and JSON/XML serialization snapshots for specs 1.6 and 1.7;
  • builder/model regressions cover non-array and malformed keywords, empty/default sets, and tag comparison.

Revalidated the pushed head: full Node suite 4170 passing / 4 pending, npm run test:lint passed, repository ESLint passed, and the Node/web/type-declaration build stages passed. The PR body now reflects the final data shape and verification.

@CAOShurong

Copy link
Copy Markdown
Contributor Author

@jkowalleck, the requested model/builder, changelog, and fixture changes are now in f837fca, and all current checks are green. When you have a chance, could you please re-review? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: ComponentBuilder populate tags based on keywords

2 participants