Skip to content

Commit d124458

Browse files
authored
fix: 6.4.0 deprecated types (#1351)
- fixes #1350 ## Fixed * Type declarations for deprecated symbols support usage as types ## Refactor * Deprecated symbols turned from re-exports into re-declares Note: this change adds runtime overhead for the sake of documentation. docs preview: <https://cyclonedx-javascript-library--1351.org.readthedocs.build/en/1351/> --------- Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent ded3f6b commit d124458

27 files changed

+567
-114
lines changed

.github/workflows/nodejs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ jobs:
352352
- name: run example
353353
run: node -- 'example.${{ matrix.js-type }}'
354354
working-directory: ${{ env.EXAMPLE_DIR }}
355+
- name: run deprecated
356+
run: node -- 'deprecated.${{ matrix.js-type }}'
357+
working-directory: ${{ env.EXAMPLE_DIR }}
355358

356359
example-TS:
357360
needs: [ 'build' ]

HISTORY.md

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

77
<!-- add unreleased items here -->
88

9+
* Fixed
10+
* Type declarations for deprecated symbols support usage as types ([#1350] via [#1351])
11+
* Refactor
12+
* Deprecated symbols turned from re-exports into re-declares (via [#1351])
13+
Note: this change adds runtime overhead for the sake of documentation.
14+
15+
[#1350]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1350
16+
[#1351]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1351
17+
18+
## 9.4.0 -- 2025-12-02
19+
920
* Added
1021
* New entry points for `/Contrib` and known submodules (via [#1343])
1122
See `package.json::exports` for details.

examples/node/javascript/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
!/.gitignore
33
!/example.mjs
44
!/example.cjs
5+
!/deprecated.cjs
6+
!/deprecated.mjs
57
!/package.json
8+
!/jsconfig.json
69
!/.npmrc
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/**
21+
* Example showcasing the deprecated symbols still work.
22+
* @see https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1350
23+
*/
24+
25+
const fs = require('node:fs')
26+
const path = require('node:path')
27+
28+
const CDX = require('@cyclonedx/cyclonedx-library')
29+
// full Library is available as `CDX`, now
30+
31+
const dBU1 = CDX.Utils.BomUtility.randomSerialNumber()
32+
console.log(dBU1)
33+
34+
const dNU1 = CDX.Utils.NpmjsUtility.defaultRegistryMatcher.test('foo')
35+
const dNU2 = CDX.Utils.NpmjsUtility.parsePackageIntegrity('sha1-aSbRsZT7xze47tUTdW3i/Np+pAg=')
36+
console.log(dNU1, dNU2)
37+
38+
const dLU1 = new CDX.Utils.LicenseUtility.LicenseEvidenceGatherer({fs, path})
39+
console.log(dLU1)
40+
41+
/** @type {CDX.Types.NodePackageJson} */
42+
const dTnpj1 = {}
43+
// const dTnpj2 =CDX.Types.isNodePackageJson(dTnpj1)
44+
try { CDX.Types.assertNodePackageJson(dTnpj1) } catch { /* pass */ }
45+
console.log(dTnpj1)
46+
47+
const dF1 = new CDX.Factories.PackageUrlFactory('generic')
48+
const dF2 = new CDX.Factories.LicenseFactory()
49+
console.log(dF1, dF2)
50+
51+
const dFnpj3 = new CDX.Factories.FromNodePackageJson.PackageUrlFactory('npm')
52+
const dFnpj4 = new CDX.Factories.FromNodePackageJson.ExternalReferenceFactory()
53+
console.log(dFnpj3, dFnpj4)
54+
55+
const dBnpj1 = new CDX.Builders.FromNodePackageJson.ComponentBuilder(dFnpj4, dF2)
56+
const dBnpj2 = new CDX.Builders.FromNodePackageJson.ToolBuilder(dFnpj4)
57+
console.log(dBnpj1, dBnpj2)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/**
21+
* Example showcasing the deprecated symbols still work.
22+
* @see https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1350
23+
*/
24+
25+
import * as fs from 'node:fs'
26+
import * as path from 'node:path'
27+
28+
import * as CDX from '@cyclonedx/cyclonedx-library'
29+
// full Library is available as `CDX`, now
30+
31+
const dBU1 = CDX.Utils.BomUtility.randomSerialNumber()
32+
console.log(dBU1)
33+
34+
const dNU1 = CDX.Utils.NpmjsUtility.defaultRegistryMatcher.test('foo')
35+
const dNU2 = CDX.Utils.NpmjsUtility.parsePackageIntegrity('sha1-aSbRsZT7xze47tUTdW3i/Np+pAg=')
36+
console.log(dNU1, dNU2)
37+
38+
const dLU1 = new CDX.Utils.LicenseUtility.LicenseEvidenceGatherer({fs, path})
39+
console.log(dLU1)
40+
41+
/** @type {CDX.Types.NodePackageJson} */
42+
const dTnpj1 = {}
43+
// const dTnpj2 =CDX.Types.isNodePackageJson(dTnpj1)
44+
try { CDX.Types.assertNodePackageJson(dTnpj1) } catch { /* pass */ }
45+
console.log(dTnpj1)
46+
47+
const dF1 = new CDX.Factories.PackageUrlFactory('generic')
48+
const dF2 = new CDX.Factories.LicenseFactory()
49+
console.log(dF1, dF2)
50+
51+
const dFnpj3 = new CDX.Factories.FromNodePackageJson.PackageUrlFactory('npm')
52+
const dFnpj4 = new CDX.Factories.FromNodePackageJson.ExternalReferenceFactory()
53+
console.log(dFnpj3, dFnpj4)
54+
55+
const dBnpj1 = new CDX.Builders.FromNodePackageJson.ComponentBuilder(dFnpj4, dF2)
56+
const dBnpj2 = new CDX.Builders.FromNodePackageJson.ToolBuilder(dFnpj4)
57+
console.log(dBnpj1, dBnpj2)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"checkJs": true,
4+
"target": "ESNext",
5+
"module": "NodeNext",
6+
"moduleResolution": "NodeNext",
7+
"types": ["node"],
8+
"lib": ["esnext"],
9+
"strict": true
10+
},
11+
"exclude": ["node_modules"]
12+
}

examples/node/javascript/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
"private": true,
33
"name": "@cyclonedx/cyclonedx-library-examples-node-javascript",
44
"license": "Apache-2.0",
5+
"type": "module",
56
"engines": {
67
"node": ">=20.18.0"
78
},
89
"dependencies": {
9-
"@cyclonedx/cyclonedx-library": "../../..",
10+
"@cyclonedx/cyclonedx-library": "file:../../..",
1011
"xmlbuilder2": "^3.0.2||^4.0.0"
1112
},
1213
"optionalDependencies": {
1314
"ajv": "^8.12.0",
1415
"ajv-formats": "^3.0.1",
1516
"ajv-formats-draft2019": "^1.6.1",
1617
"libxmljs2": "^0.35||^0.37"
18+
},
19+
"devDependencies": {
20+
"@types/node": ">=20.18.0"
1721
}
1822
}

examples/node/typescript/example.cjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
"scripts": {
2424
"prebuild": "tsc -b --clean",
2525
"build": "tsc -b",
26-
"example": "node dist/example.js"
26+
"example": "node dist/example.js && node dist/deprecated.js"
2727
}
2828
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/**
21+
* Example showcasing the deprecated symbols still work.
22+
* @see https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1350
23+
*/
24+
25+
import * as fs from 'node:fs'
26+
import * as path from 'node:path'
27+
28+
import * as CDX from '@cyclonedx/cyclonedx-library'
29+
// full Library is available as `CDX`, now
30+
31+
const dBU1 = CDX.Utils.BomUtility.randomSerialNumber()
32+
console.log(dBU1)
33+
34+
const dNU1 = CDX.Utils.NpmjsUtility.defaultRegistryMatcher.test('foo')
35+
const dNU2 = CDX.Utils.NpmjsUtility.parsePackageIntegrity('sha1-aSbRsZT7xze47tUTdW3i/Np+pAg=')
36+
console.log(dNU1, dNU2)
37+
38+
type dLU1_T = CDX.Utils.LicenseUtility.LicenseEvidenceGatherer
39+
const fsU: CDX.Utils.LicenseUtility.FsUtils<string> = fs
40+
const pathU: CDX.Utils.LicenseUtility.PathUtils<string> = path
41+
const dLU1: dLU1_T = new CDX.Utils.LicenseUtility.LicenseEvidenceGatherer({fs: fsU, path: pathU})
42+
console.log(dLU1)
43+
44+
const dTnpj1: CDX.Types.NodePackageJson = {}
45+
// const dTnpj2 =CDX.Types.isNodePackageJson(dTnpj1)
46+
try { CDX.Types.assertNodePackageJson(dTnpj1) } catch { /* pass */ }
47+
console.log(dTnpj1)
48+
49+
type dF1_T = CDX.Factories.PackageUrlFactory
50+
type dF2_T = CDX.Factories.LicenseFactory
51+
const dF1: dF1_T = new CDX.Factories.PackageUrlFactory('generic')
52+
const dF2: dF2_T = new CDX.Factories.LicenseFactory()
53+
console.log(dF1, dF2)
54+
55+
type dFnpj3_T = CDX.Factories.FromNodePackageJson.PackageUrlFactory
56+
const dFnpj3: dFnpj3_T = new CDX.Factories.FromNodePackageJson.PackageUrlFactory('npm')
57+
type dFnpj4_T = CDX.Factories.FromNodePackageJson.ExternalReferenceFactory
58+
const dFnpj4: dFnpj4_T = new CDX.Factories.FromNodePackageJson.ExternalReferenceFactory()
59+
console.log(dFnpj3, dFnpj4)
60+
61+
type dBnpj1_T = CDX.Builders.FromNodePackageJson.ComponentBuilder
62+
const dBnpj1: dBnpj1_T = new CDX.Builders.FromNodePackageJson.ComponentBuilder(dFnpj4, dF2)
63+
type dBnpj2_T = CDX.Builders.FromNodePackageJson.ToolBuilder
64+
const dBnpj2: dBnpj2_T = new CDX.Builders.FromNodePackageJson.ToolBuilder(dFnpj4)
65+
console.log(dBnpj1, dBnpj2)

examples/node/typescript/example.cjs/tsconfig.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"compilerOptions": {
44
"target": "ES2016",
55
"module": "CommonJS",
6+
"moduleResolution": "node",
7+
"types": ["node"],
8+
"lib": ["esnext"],
9+
"sourceMap": true,
610
"outDir": "./dist",
711
"strict": true,
812
"forceConsistentCasingInFileNames": true,
913
"disableSourceOfProjectReferenceRedirect": false,
1014
"rootDir": "src"
11-
},
12-
"files": [
13-
"./src/example.ts"
14-
]
15+
}
1516
}

0 commit comments

Comments
 (0)