diff --git a/HISTORY.md b/HISTORY.md index 416719dc4..6b6c86fc8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file. +* Added + * Publish sub-namespace types `OptionalFeature` (via [#1535]) + +[#1535]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1535 + ## 10.4.0 -- 2026-11-03 * Added diff --git a/package.json b/package.json index aa17026c5..f8dbbe765 100644 --- a/package.json +++ b/package.json @@ -163,6 +163,9 @@ "default": "./dist.node/index.node.js" }, "./package.json": "./package.json", + "./OptionalFeature": { + "types": "./dist.d/optionalFeature.d.ts" + }, "./Enums": { "types": "./dist.d/enums/index.d.ts", "default": "./dist.node/enums/index.js" diff --git a/src/_optPlug.node/cannot.ts b/src/_optPlug.node/cannot.ts index 04251ded4..73b74b9ba 100644 --- a/src/_optPlug.node/cannot.ts +++ b/src/_optPlug.node/cannot.ts @@ -17,7 +17,7 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ -import type { Cannot } from '../_opt' +import type { Cannot } from '../optionalFeature' import { isWillThrow } from './_wrapper' /** diff --git a/src/index.common.ts b/src/index.common.ts index 4fc31c771..6117218bb 100644 --- a/src/index.common.ts +++ b/src/index.common.ts @@ -17,10 +17,13 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ +import type * as OptionalFeature from './optionalFeature' + export * as Enums from './enums' export * as Models from './models' export * as SPDX from './spdx' export * as Spec from './spec' export * as Types from './types' +export type { OptionalFeature } // do not export the _helpers, they are for internal use only diff --git a/src/_opt.ts b/src/optionalFeature.ts similarity index 97% rename from src/_opt.ts rename to src/optionalFeature.ts index 84957f1bd..9372469ff 100644 --- a/src/_opt.ts +++ b/src/optionalFeature.ts @@ -20,7 +20,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved. /** * Describes why an optional feature cannot act. */ -interface Blocker { +export interface Blocker { readonly message: string } diff --git a/src/serialize/jsonSerializer.ts b/src/serialize/jsonSerializer.ts index 27389fe66..7f124dab8 100644 --- a/src/serialize/jsonSerializer.ts +++ b/src/serialize/jsonSerializer.ts @@ -17,8 +17,8 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ -import type * as OptionalFeature from '../_opt' import type { Bom } from '../models/bom' +import type * as OptionalFeature from '../optionalFeature' import { Format } from '../spec/enums' import { UnsupportedFormatError } from '../spec/errors' import { BaseSerializer } from './baseSerializer' diff --git a/src/serialize/xmlSerializer.node.ts b/src/serialize/xmlSerializer.node.ts index 11bf46a0d..ba096003c 100644 --- a/src/serialize/xmlSerializer.node.ts +++ b/src/serialize/xmlSerializer.node.ts @@ -17,9 +17,9 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ -import type * as OptionalFeature from '../_opt' import cannotOf from '../_optPlug.node/cannot' import stringify from '../_optPlug.node/xmlStringify' +import type * as OptionalFeature from '../optionalFeature' import { MissingOptionalDependencyError } from './errors' import type { SerializerOptions } from './types' import type { SimpleXml } from './xml/types' diff --git a/src/serialize/xmlSerializer.web.ts b/src/serialize/xmlSerializer.web.ts index b0f16bccf..89e79d33b 100644 --- a/src/serialize/xmlSerializer.web.ts +++ b/src/serialize/xmlSerializer.web.ts @@ -18,7 +18,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved. */ import { isNotUndefined } from '../_helpers/notUndefined' -import type * as OptionalFeature from '../_opt' +import type * as OptionalFeature from '../optionalFeature' import type { SerializerOptions } from './types' import type { SimpleXml } from './xml/types' import { XmlBaseSerializer } from './xmlBaseSerializer' diff --git a/src/validation/jsonValidator.node.ts b/src/validation/jsonValidator.node.ts index 157c585d5..c4e99d6f1 100644 --- a/src/validation/jsonValidator.node.ts +++ b/src/validation/jsonValidator.node.ts @@ -17,9 +17,9 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ -import type * as OptionalFeature from '../_opt' import cannotOf from '../_optPlug.node/cannot' import makeValidator, { type Validator } from '../_optPlug.node/jsonValidator' +import type * as OptionalFeature from '../optionalFeature' import { FILES } from '../resources.node' import { BaseValidator } from './baseValidator' import { MissingOptionalDependencyError, NotImplementedError } from './errors' diff --git a/src/validation/xmlValidator.node.ts b/src/validation/xmlValidator.node.ts index 9de2ef314..e9c2b715e 100644 --- a/src/validation/xmlValidator.node.ts +++ b/src/validation/xmlValidator.node.ts @@ -17,9 +17,9 @@ SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ -import type * as OptionalFeature from '../_opt' import cannotOf from '../_optPlug.node/cannot' import makeValidator, { type Validator } from '../_optPlug.node/xmlValidator' +import type * as OptionalFeature from '../optionalFeature' import { FILES } from '../resources.node' import { BaseValidator } from './baseValidator' import { MissingOptionalDependencyError, NotImplementedError } from './errors' diff --git a/tests/functional/packageManifestExports.node.spec.js b/tests/functional/packageManifestExports.node.spec.js index 34deefcd5..098ed5266 100644 --- a/tests/functional/packageManifestExports.node.spec.js +++ b/tests/functional/packageManifestExports.node.spec.js @@ -33,6 +33,13 @@ suite('functional: packageManifest:exports', () => { /** @type {Set} */ const pjRelExported = new Set( Object.keys(pjExports) + .filter(e => { + const ed = pjExports[e] + const edT = typeof ed + if (edT === 'string') return true + if (edT !== 'object') throw new RangeError(`unexpected export definition type for ${e}`) + return Object.hasOwn(ed, 'node') || Object.hasOwn(ed, 'default') + }) .filter(e => e.startsWith('./')) .map(e => e.substring(2)) ) @@ -61,7 +68,7 @@ suite('functional: packageManifest:exports', () => { } }) - suite('does not export internal sobmodules', () => { + suite('does not export internal submodules', () => { for (const [cdxModName, cdxMod] of Object.entries(CDX)) { if (!cdxModName.startsWith('_')) { continue // skip non-internal