Skip to content

Commit 05cb8e7

Browse files
authored
Fix webpack externals parcel (#884)
* example parcel Signed-off-by: Jan Kowalleck <[email protected]> * example parcel Signed-off-by: Jan Kowalleck <[email protected]> --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 09e264e commit 05cb8e7

File tree

12 files changed

+124
-10
lines changed

12 files changed

+124
-10
lines changed

Diff for: .eslintignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
/dist/**
66
/dist.*/**
77
/docs/api/**
8-
/examples/node-typescript/dist/**
9-
/examples/web/dist/**
8+
/examples/**/dist/**
109

1110

1211
!/src/**

Diff for: .github/workflows/nodejs.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,16 @@ jobs:
328328

329329
examples-Web:
330330
needs: [ 'build' ]
331-
name: example Web
331+
name: example Web ${{ matrix.packer }}
332332
runs-on: ubuntu-latest
333+
strategy:
334+
fail-fast: false
335+
matrix:
336+
packer:
337+
- parcel
338+
- webpack
333339
env:
334-
EXAMPLE_DIR: examples/web
340+
EXAMPLE_DIR: examples/web-${{ matrix.packer }}
335341
steps:
336342
- name: Checkout
337343
# see https://github.com/actions/checkout
@@ -348,9 +354,7 @@ jobs:
348354
name: dist.web
349355
path: dist.web
350356
- name: setup library
351-
run: |
352-
set -ex
353-
npm ci --ignore-scripts --omit=dev --include=optional --loglevel=silly
357+
run: npm ci --ignore-scripts --omit=dev --include=optional --loglevel=silly
354358
- name: setup example project
355359
run: npm i --no-save --loglevel=silly
356360
working-directory: ${{ env.EXAMPLE_DIR }}

Diff for: HISTORY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file.
1111
* Fixed
1212
* Properly exclude external packages when preparing this library for web browsers ([#883] via [#880])
1313
* Examples
14-
* Adjusted example for usage in web browsers ([#883] via [#880])
14+
* Adjusted and extended examples for usage in web browsers ([#883] via [#880])
1515
* Added examples for usage of `CDX.Factories.PackageUrlFactory` (via [#882])
1616
* Build
1717
* Use _TypeScript_ `v5.1.6` now, was `v5.1.5` (via [#866])

Diff for: examples/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
* `node-typescript` showcases the usage in Node.js TypeScript
99
* [`example.cjs`](node-typescript/example.cjs) targets JavaScript, "commonjs" style - from TypeScript `^3.8 || ^4 || ^5`.
1010
* [`example.mjs`](node-typescript/example.cjs) targets JavaScript, "module" style - from TypeScript `^3.8 || ^4 || ^5`.
11-
* `web` showcases the usage in web browser JavaScript
11+
* `web-parcel` showcases the usage in web browser when compiled by [_Parcel_](https://parceljs.org/):
12+
* [`src/index.html`](web/src/index.js) will be compiled to
13+
[`dist/index.html`](web/dist/index.html) and runs in any web browser.
14+
* `web-webpack` showcases the usage in web browser when compiled by [_Webpack_](https://webpack.js.org/):
1215
* [`src/index.js`](web/src/index.js) will be compiled, to that it can be embedded by
13-
[`dist/index.html`](web/dist/index.html) and run in any web browser.
16+
[`dist/index.html`](web/dist/index.html) and runs in any web browser.
1417

1518
## Data models
1619

Diff for: examples/web-parcel/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!/.gitignore
3+
!/package.json
4+
!/src
5+
!/src/**

Diff for: examples/web-parcel/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"name": "example",
4+
"license": "Apache-2.0",
5+
"source": "src/index.html",
6+
"dependencies": {
7+
"@cyclonedx/cyclonedx-library": "file:../.."
8+
},
9+
"devDependencies": {
10+
"parcel": "^2"
11+
},
12+
"scripts": {
13+
"build": "parcel build --detailed-report",
14+
"example": "parcel"
15+
}
16+
}
File renamed without changes.

Diff for: examples/web-parcel/src/index.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<!--
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
-->
20+
<html lang="en">
21+
<head>
22+
<title>example</title>
23+
</head>
24+
<body>
25+
<script type="module" src="app.js"></script>
26+
<p>see JavaScript Console output for result.</p>
27+
</body>
28+
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: examples/web-webpack/src/index.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
/** Example how to serialize a Bom to JSON / XML. */
21+
22+
const CDX = require('@cyclonedx/cyclonedx-library')
23+
// full Library is available as `CDX`, now
24+
25+
const lFac = new CDX.Factories.LicenseFactory()
26+
const purlFac = new CDX.Factories.PackageUrlFactory('npm')
27+
28+
const bom = new CDX.Models.Bom()
29+
bom.metadata.component = new CDX.Models.Component(
30+
CDX.Enums.ComponentType.Application,
31+
'MyProject'
32+
)
33+
bom.metadata.component.licenses.add(lFac.makeFromString('MIT OR Apache-2.0'))
34+
35+
const componentA = new CDX.Models.Component(
36+
CDX.Enums.ComponentType.Library,
37+
'myComponentA',
38+
{
39+
group: 'acme',
40+
version: '1.33.7'
41+
}
42+
)
43+
componentA.licenses.add(lFac.makeFromString('Apache-2.0'))
44+
componentA.purl = purlFac.makeFromComponent(componentA)
45+
46+
bom.components.add(componentA)
47+
bom.metadata.component.dependencies.add(componentA.bomRef)
48+
49+
const serializeSpec = CDX.Spec.Spec1dot5
50+
51+
const jsonSerializer = new CDX.Serialize.JsonSerializer(
52+
new CDX.Serialize.JSON.Normalize.Factory(serializeSpec))
53+
const serializedJson = jsonSerializer.serialize(bom)
54+
console.log(serializedJson)
55+
56+
const xmlSerializer = new CDX.Serialize.XmlSerializer(
57+
new CDX.Serialize.XML.Normalize.Factory(serializeSpec))
58+
const serializedXML = xmlSerializer.serialize(bom)
59+
console.log(serializedXML)

0 commit comments

Comments
 (0)