Skip to content

Commit b9adef0

Browse files
authored
Merge branch 'master' into feat/default-cdx1.6
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
2 parents ff99911 + 3b6e7d7 commit b9adef0

File tree

17 files changed

+3842
-16
lines changed

17 files changed

+3842
-16
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This will install process automatically build the project from source.
1818
## Build from source
1919

2020
```shell
21-
npm run build
21+
npm run build-dev
2222
```
2323

2424
## Testing

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ All notable changes to this project will be documented in this file.
88

99
* BREAKING changes
1010
* Option `specVersion` defaults to `"1.6"`, was `"1.4"` ([#1329] via [#1333])
11+
* Fixed
12+
* Properly detect license evidences like `LICEN[CS]E.{Apache,BSD,GPL,MIT}` ([#1337] via [#1339])
1113

1214
[#1329]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/issues/1329
1315
[#1333]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/pull/1333
16+
[#1337]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/issues/1337
17+
[#1339]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/pull/1339
1418

1519
## 3.15.0 - 2024-10-19
1620

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cyclonedx/webpack-plugin",
3-
"version": "3.15.0",
3+
"version": "3.15.1",
44
"description": "Creates CycloneDX Software Bill of Materials (SBoM) from webpack projects",
55
"license": "Apache-2.0",
66
"copyright": "Copyright OWASP Foundation",
@@ -96,9 +96,9 @@
9696
"prepublish": "npm run build",
9797
"prepublishOnly": "run-s -lc build setup-tests test",
9898
"lint": "tsc --noEmit",
99-
"build": "run-p --aggregate-output -l 'build:*'",
100-
"prebuild:node": "node -r fs -e 'fs.rmSync(\"dist\",{recursive:true,force:true})'",
101-
"build:node": "tsc -b ./tsconfig.json",
99+
"prebuild": "node -r fs -e 'fs.rmSync(\"dist\",{recursive:true,force:true})'",
100+
"build": "tsc -b ./tsconfig.json",
101+
"build-dev": "npm run -- build --sourceMap",
102102
"setup-tests": "node tests/integration/setup.js",
103103
"test": "run-p --aggregate-output -lc 'test:*'",
104104
"test:jest": "c8 jest",

src/_helpers.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

2020
import { existsSync, readFileSync } from 'fs'
21-
import { dirname, extname, isAbsolute, join, sep } from 'path'
21+
import { dirname, extname, isAbsolute, join, parse, sep } from 'path'
2222

2323
export function isNonNullable<T> (value: T): value is NonNullable<T> {
2424
// NonNullable: not null and not undefined
@@ -92,18 +92,41 @@ export function loadJsonFile (path: string): any {
9292

9393
export type MimeType = string
9494

95+
const MIME_TEXT_PLAIN: MimeType = 'text/plain'
96+
9597
const MAP_TEXT_EXTENSION_MIME: Readonly<Record<string, MimeType>> = {
96-
'': 'text/plain',
97-
'.license': 'text/plain',
98-
'.licence': 'text/plain',
98+
'': MIME_TEXT_PLAIN,
99+
// https://www.iana.org/assignments/media-types/media-types.xhtml
100+
'.csv': 'text/csv',
101+
'.htm': 'text/html',
102+
'.html': 'text/html',
99103
'.md': 'text/markdown',
104+
'.txt': MIME_TEXT_PLAIN,
100105
'.rst': 'text/prs.fallenstein.rst',
101-
'.txt': 'text/plain',
102-
'.xml': 'text/xml' // not `application/xml` -- our scope is text!
106+
'.xml': 'text/xml', // not `application/xml` -- our scope is text!
107+
// add more mime types above this line. pull-requests welcome!
108+
// license-specific files
109+
'.license': MIME_TEXT_PLAIN,
110+
'.licence': MIME_TEXT_PLAIN
103111
} as const
104112

105113
export function getMimeForTextFile (filename: string): MimeType | undefined {
106114
return MAP_TEXT_EXTENSION_MIME[extname(filename).toLowerCase()]
107115
}
108116

117+
const LICENSE_FILENAME_BASE = new Set(['licence', 'license'])
118+
const LICENSE_FILENAME_EXT = new Set([
119+
'.apache',
120+
'.bsd',
121+
'.gpl',
122+
'.mit'
123+
])
124+
125+
export function getMimeForLicenseFile (filename: string): MimeType | undefined {
126+
const { name, ext } = parse(filename.toLowerCase())
127+
return LICENSE_FILENAME_BASE.has(name) && LICENSE_FILENAME_EXT.has(ext)
128+
? MIME_TEXT_PLAIN
129+
: MAP_TEXT_EXTENSION_MIME[ext]
130+
}
131+
109132
// endregion MIME

src/extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as normalizePackageJson from 'normalize-package-data'
2323
import { dirname, join } from 'path'
2424
import type { Compilation, Module } from 'webpack'
2525

26-
import { getMimeForTextFile, getPackageDescription, isNonNullable, type PackageDescription, structuredClonePolyfill } from './_helpers'
26+
import { getMimeForLicenseFile, getPackageDescription, isNonNullable, type PackageDescription, structuredClonePolyfill } from './_helpers'
2727

2828
type WebpackLogger = Compilation['logger']
2929

@@ -148,7 +148,7 @@ export class Extractor {
148148
continue
149149
}
150150

151-
const contentType = getMimeForTextFile(pci.name)
151+
const contentType = getMimeForLicenseFile(pci.name)
152152
if (contentType === undefined) {
153153
continue
154154
}

0 commit comments

Comments
 (0)