Skip to content

Commit e45741d

Browse files
refactor: Removed dynamic imports in NodeJS-specific XML serializer lookup (#1018)
This should improve compatibility with linkers and bundlers. --------- Signed-off-by: Augustus Kling <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Jan Kowalleck <[email protected]>
1 parent c6cfd6f commit e45741d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

HISTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
* Refactor
8+
* Removed dynamic imports in _Node.js_-specific XML serializer lookup ([#1017] via [#1018])
9+
This should improve compatibility with linkers and bundlers.
710
* Build
811
* Use _webpack_ `v5.90.3` now, was `v5.89.0` (via [#1008], [#1013], [#1015])
912

1013
[#1008]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1008
1114
[#1013]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1013
1215
[#1015]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1015
16+
[#1017]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1017
17+
[#1018]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1018
18+
1319

1420
## 6.3.1 -- 2023-12-11
1521

libs/universal-node-xml/index.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,30 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20+
/* eslint-disable jsdoc/valid-types --
21+
JSDoc is still missing support for tuples - https://github.com/jsdoc/jsdoc/issues/1703
22+
*/
23+
/**
24+
* Prioritized list of possible implementations.
25+
* @type {[string, function():(Function|*)][]}
26+
*/
2027
const possibleStringifiers = [
21-
// prioritized list of possible implementations
22-
'xmlbuilder2'
28+
['xmlbuilder2', () => require('./stringifiers/xmlbuilder2')]
2329
]
30+
/* eslint-enable jsdoc/valid-types */
2431

2532
module.exports.stringify = function () {
2633
throw new Error(
2734
'No stringifier available.' +
2835
' Please install any of the optional dependencies: ' +
29-
possibleStringifiers.join(', ')
36+
possibleStringifiers.map(kv => kv[0]).join(', ')
3037
)
3138
}
3239
module.exports.stringify.fails = true
3340

34-
for (const file of possibleStringifiers) {
41+
for (const [, getStringifier] of possibleStringifiers) {
3542
try {
36-
const possibleStringifier = require(`./stringifiers/${file}`)
43+
const possibleStringifier = getStringifier()
3744
if (typeof possibleStringifier === 'function') {
3845
module.exports.stringify = possibleStringifier
3946
break

0 commit comments

Comments
 (0)