Skip to content

Commit 88e1ef2

Browse files
committed
feat: public export of type PackageJson
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 1e335d8 commit 88e1ef2

File tree

5 files changed

+64
-33
lines changed

5 files changed

+64
-33
lines changed

src/_helpers/packageJson.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,3 @@ export function splitNameGroup (data: string): [string, string?] {
3333
: [data, undefined]
3434
}
3535

36-
/**
37-
* Intended to represent normalized data structures
38-
* based on [PackageJson spec](https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json)
39-
* and explained by [PackageJson description](https://docs.npmjs.com/cli/v9/configuring-npm/package-json).
40-
* Normalization should be done downstream, for example via [`normalize-package-data`](https://www.npmjs.com/package/normalize-package-data).
41-
*/
42-
export interface PackageJson {
43-
name?: string
44-
version?: string
45-
description?: string
46-
license?: string
47-
licenses?: Array<{
48-
type?: string
49-
url?: string
50-
}>
51-
author?: string | {
52-
name?: string
53-
email?: string
54-
}
55-
bugs?: string | {
56-
url?: string
57-
}
58-
homepage?: string
59-
repository?: string | {
60-
type?: string
61-
url?: string
62-
directory?: string
63-
}
64-
// ... to be continued
65-
dist?: any // see https://github.com/CycloneDX/cyclonedx-node-npm/issues/1300
66-
}

src/builders/fromNodePackageJson.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2626
* Normalization should be done downstream, for example via [`normalize-package-data`](https://www.npmjs.com/package/normalize-package-data).
2727
*/
2828

29-
import type { PackageJson } from '../_helpers/packageJson'
3029
import { splitNameGroup } from '../_helpers/packageJson'
3130
import { ComponentType } from '../enums/componentType'
3231
import type * as Factories from '../factories/index.node'
3332
import { Component } from '../models/component'
3433
import { ExternalReferenceRepository } from '../models/externalReference'
3534
import { LicenseRepository } from '../models/license'
3635
import { Tool } from '../models/tool'
36+
import type { PackageJson } from '../types/packageJson'
3737

3838
/**
3939
* Node-specific ToolBuilder.

src/factories/fromNodePackageJson.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import { PurlQualifierNames } from 'packageurl-js'
3131

3232
import { tryCanonicalizeGitUrl } from "../_helpers/gitUrl"
3333
import { isNotUndefined } from '../_helpers/notUndefined'
34-
import type { PackageJson } from '../_helpers/packageJson'
3534
import { ExternalReferenceType } from '../enums/externalReferenceType'
3635
import { HashAlgorithm } from "../enums/hashAlogorithm";
3736
import type { Component } from '../models/component'
3837
import { ExternalReference } from '../models/externalReference'
3938
import { HashDictionary } from '../models/hash'
39+
import type { PackageJson } from '../types/packageJson'
4040
import { defaultRegistryMatcher, parsePackageIntegrity } from '../utils/npmjsUtility.node'
4141
import { PackageUrlFactory as PlainPackageUrlFactory } from './packageUrl'
4242

src/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ export * from './cpe'
2121
export * from './cwe'
2222
export * from './integer'
2323
export * from './mimeType'
24+
25+
// yes, this is node-specific, but who cares - these are just types
26+
export type * from './packageJson'

src/types/packageJson.ts

Lines changed: 59 additions & 0 deletions
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+
/**
21+
* Intended to represent normalized data structures
22+
* based on [PackageJson spec](https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json)
23+
* and explained by [PackageJson description](https://docs.npmjs.com/cli/v9/configuring-npm/package-json).
24+
*
25+
* Normalization should be done downstream, for example
26+
* via [`normalize-package-data`](https://www.npmjs.com/package/normalize-package-data).
27+
*/
28+
export interface PackageJson {
29+
name?: string
30+
version?: string
31+
description?: string
32+
license?: string
33+
licenses?: Array<{
34+
type?: string
35+
url?: string
36+
}>
37+
author?: string | {
38+
name?: string
39+
email?: string
40+
}
41+
bugs?: string | {
42+
url?: string
43+
}
44+
homepage?: string
45+
repository?: string | {
46+
type?: string
47+
url?: string
48+
directory?: string
49+
}
50+
// ... to be continued
51+
dist?: any // see https://github.com/CycloneDX/cyclonedx-node-npm/issues/1300
52+
}
53+
54+
55+
/* TODO: write type assertion
56+
export function isPackageJsonNode (value: any): value is PackageJsonNode {
57+
return...
58+
}
59+
*/

0 commit comments

Comments
 (0)