Skip to content

Commit b5bb39e

Browse files
authored
fix: digest library as JavaScript module build by TypeScript (#596)
--------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 4ad222a commit b5bb39e

File tree

15 files changed

+210
-58
lines changed

15 files changed

+210
-58
lines changed

.github/workflows/nodejs.yml

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
name: dist.${{ matrix.target }}
5353
path: dist.${{ matrix.target }}
5454
if-no-files-found: error
55+
5556
test-standard:
5657
name: test standard
5758
runs-on: ubuntu-latest
@@ -91,6 +92,7 @@ jobs:
9192
name: ${{ env.STANDARD_REPORTS_ARTIFACT }}
9293
path: ${{ env.REPORTS_DIR }}
9394
if-no-files-found: error
95+
9496
test-node:
9597
needs: [ 'build' ]
9698
name: test node (${{ matrix.node-version }}, ${{ matrix.os }})
@@ -168,26 +170,65 @@ jobs:
168170
with:
169171
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
170172
coverage-reports: ${{ env.REPORTS_DIR }}/coverage/*/*
171-
test-declaration:
173+
174+
examples-JS:
172175
needs: [ 'build' ]
173-
name: digest declarations (TS${{ matrix.typescript-version }})
176+
name: example JS ${{ matrix.js-type }}
177+
runs-on: ubuntu-latest
178+
strategy:
179+
fail-fast: false
180+
matrix:
181+
js-type: [ 'cjs', 'mjs' ]
182+
env:
183+
EXAMPLE_DIR: examples/node-javascript
184+
steps:
185+
- name: Checkout
186+
# see https://github.com/actions/checkout
187+
uses: actions/checkout@v3
188+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
189+
# see https://github.com/actions/setup-node
190+
uses: actions/setup-node@v3
191+
with:
192+
node-version: ${{ env.NODE_ACTIVE_LTS }}
193+
- name: fetch build artifact 'node'
194+
# see https://github.com/actions/download-artifact
195+
uses: actions/download-artifact@v3
196+
with:
197+
name: dist.node
198+
path: dist.node
199+
- name: setup library
200+
run: npm i --ignore-scripts --omit=dev --include=optional
201+
- name: setup example project
202+
run: npm i --no-save
203+
working-directory: ${{ env.EXAMPLE_DIR }}
204+
- name: run example
205+
run: node -- 'example.${{ matrix.js-type }}'
206+
working-directory: ${{ env.EXAMPLE_DIR }}
207+
208+
example-typescript:
209+
needs: [ 'build' ]
210+
name: example TS${{ matrix.typescript-version }} ${{ matrix.js-type }}
174211
runs-on: ubuntu-latest
175212
strategy:
176213
fail-fast: false
177214
matrix:
178215
typescript-version:
179216
- '^5' # latest 5.X
180217
- '^4' # latest 4.X
181-
# - '~4.0' # some 4.0.x
182218
- '^3' # latest 3.X
219+
js-type: [ 'cjs', 'mjs' ]
183220
include:
184221
## some @types/node versions were incompatible or caused issues
185222
- typescript-version: '^3'
186223
nodeTypes-version: '^16'
187224
- typescript-version: '3.8.2' # lowest reasonable number that works
188-
nodeTypes-version: '^16'
225+
js-type: 'cjs'
226+
nodeTypes-version: '^14'
227+
exclude:
228+
- typescript-version: '^3'
229+
js-type: 'mjs'
189230
env:
190-
EXAMPLE_DIR: examples/node-typescript
231+
EXAMPLE_DIR: examples/node-typescript/example.${{ matrix.js-type }}
191232
timeout-minutes: 10
192233
steps:
193234
- name: Checkout
@@ -198,25 +239,33 @@ jobs:
198239
uses: actions/setup-node@v3
199240
with:
200241
node-version: ${{ env.NODE_ACTIVE_LTS }}
201-
- name: fetch build artifact
242+
- name: fetch build artifact 'd'
202243
# see https://github.com/actions/download-artifact
203244
uses: actions/download-artifact@v3
204245
with:
205246
name: dist.d
206247
path: dist.d
248+
- name: fetch build artifact 'node'
249+
# see https://github.com/actions/download-artifact
250+
uses: actions/download-artifact@v3
251+
with:
252+
name: dist.node
253+
path: dist.node
207254
- name: setup library
208-
run: npm i --ignore-scripts --omit=dev
255+
run: npm i --ignore-scripts --omit=dev --include=optional
209256
- name: setup example project
210257
run: >
211258
npm i --no-save
212259
'typescript@${{ matrix.typescript-version }}'
213260
'@types/node@${{ matrix.nodeTypes-version || env.NODE_ACTIVE_LTS }}'
214261
working-directory: ${{ env.EXAMPLE_DIR }}
215-
- run: npm ls
216-
working-directory: ${{ env.EXAMPLE_DIR }}
217-
- name: use type declarations
262+
- name: build example
218263
run: npm run build
219264
working-directory: ${{ env.EXAMPLE_DIR }}
265+
- name: run example
266+
run: npm run example
267+
working-directory: ${{ env.EXAMPLE_DIR }}
268+
220269
api-doc:
221270
name: api-doc ${{ matrix.target }}
222271
runs-on: "ubuntu-latest"

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
* Fixed
8+
* Digesting this library in TypeScript build with ECMA Script module results works as expected, now (via [#596])
79
* Docs
810
* Development-docs are no longer packed with releases (via [#572])
11+
* Misc
12+
* Added more integration tests in CI (via [#596])
913

1014
[#572]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/572
15+
[#596]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/596
1116

1217
## 1.12.1 - 2023-03-13
1318

examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* [`example.cjs`](node-javascript/example.cjs) targets JavaScript, "commonjs" style.
77
* [`example.mjs`](node-javascript/example.mjs) targets JavaScript, "module" style.
88
* `node-typescript` showcases the usage in Node.js TypeScript
9-
* [`example.ts`](node-typescript/example.ts) targets TypeScript `^3.8 || ^4`.
9+
* [`example.cjs`](node-typescript/example.cjs) targets JavaScript, "commonjs" style - from TypeScript `^3.8 || ^4 || ^5`.
10+
* [`example.mjs`](node-typescript/example.cjs) targets JavaScript, "module" style - from TypeScript `^3.8 || ^4 || ^5`.
1011
* `web` showcases the usage in web browser JavaScript
1112
* [`example.html`](web/example.html) targets any web-browser.
1213

examples/node-javascript/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"description": "",
44
"dependencies": {
5-
"@cyclonedx/cyclonedx-library": "file:../.."
5+
"@cyclonedx/cyclonedx-library": "file:../..",
6+
"xmlbuilder2": "^3.0.2"
67
}
78
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*
22
!/.gitignore
3-
!/example.ts
43
!/package.json
54
!/tsconfig.json
5+
!/src
6+
!/src/**
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"private": true,
33
"description": "",
4-
"scripts": {
5-
"prebuild": "tsc -b --clean",
6-
"build": "tsc -b"
7-
},
4+
"type": "commonjs",
85
"dependencies": {
9-
"@cyclonedx/cyclonedx-library": "file:../.."
6+
"@cyclonedx/cyclonedx-library": "file:../../..",
7+
"xmlbuilder2": "^3.0.2"
108
},
119
"devDependencies": {
1210
"@types/node": ">=14",
1311
"typescript": "^3.8 || ^4 || ^5"
12+
},
13+
"scripts": {
14+
"prebuild": "tsc -b --clean",
15+
"build": "tsc -b",
16+
"example": "node dist/example.js"
1417
}
1518
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"compilerOptions": {
4+
"target": "ES2016",
5+
"module": "CommonJS",
6+
"outDir": "./dist",
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"disableSourceOfProjectReferenceRedirect": false,
10+
"rootDir": "src"
11+
},
12+
"files": [
13+
"./src/example.ts"
14+
]
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!/.gitignore
3+
!/package.json
4+
!/tsconfig.json
5+
!/src
6+
!/src/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"private": true,
3+
"description": "",
4+
"type": "module",
5+
"engines": {
6+
"node": ">=16"
7+
},
8+
"dependencies": {
9+
"@cyclonedx/cyclonedx-library": "file:../../..",
10+
"xmlbuilder2": "^3.0.2"
11+
},
12+
"devDependencies": {
13+
"@types/node": ">=14",
14+
"typescript": "^3.8 || ^4 || ^5"
15+
},
16+
"scripts": {
17+
"prebuild": "tsc -b --clean",
18+
"build": "tsc -b",
19+
"example": "node dist/example.js"
20+
21+
}
22+
}

0 commit comments

Comments
 (0)