Skip to content

Commit ddbbfb8

Browse files
committed
feat: well-knownSPDXids are bundle-able and tree-shakable
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent ea8aa34 commit ddbbfb8

9 files changed

Lines changed: 952 additions & 17 deletions

File tree

src/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spdx_specenum.ts linguist-generated

src/spdx.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,24 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1919

2020
import spdxExpressionParse from 'spdx-expression-parse'
2121

22-
/* @ts-expect-error: TS6059 -- this works as long as the file/path is available in dist-package. */
23-
import { enum as _spdxSpecEnum } from '../res/schema/spdx.SNAPSHOT.schema.json' with { type: 'json' }
22+
import { LIST as spdxSpecEnum } from './spdx_specenum'
2423

2524
/**
26-
* One of the known SPDX licence identifiers.
25+
* One of the known SPDX license identifiers.
2726
*
2827
* @see {@link http://cyclonedx.org/schema/spdx | SPDX schema}
2928
* @see {@link isSupportedSpdxId}
3029
* @see {@link fixupSpdxId}
3130
*/
3231
export type SpdxId = string
3332

34-
const spdxIds: ReadonlySet<SpdxId> = new Set(_spdxSpecEnum)
35-
3633
const spdxLowerToActual: Readonly<Record<string, SpdxId>> = Object.freeze(Object.fromEntries(
37-
_spdxSpecEnum.map(spdxId => [spdxId.toLowerCase(), spdxId])
34+
spdxSpecEnum.map(spdxId => [spdxId.toLowerCase(), spdxId])
3835
))
3936

4037
export function isSupportedSpdxId (value: SpdxId | any): value is SpdxId {
41-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
42-
return spdxIds.has(value)
38+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- ack */
39+
return spdxSpecEnum.includes(value)
4340
}
4441

4542
/** Try to convert a `string`-like to a valid/known {@link SpdxId}. */

0 commit comments

Comments
 (0)