Skip to content

Commit 0d592e2

Browse files
authored
fix: add backward compatibility for dependency field is_resolved
Add support for legacy ScanCode dependency field `is_resolved` alongside the newer `is_pinned` field. This ensures compatibility with both older and newer ScanCode JSON outputs without breaking existing functionality.
1 parent 4811dac commit 0d592e2

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/services/importedJsonTypes.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export interface LicenseExpressionKey {
77
licensedb_url: string | null;
88
scancode_url: string | null;
99
}
10+
1011
export interface LicenseExpressionSpdxKey {
1112
key: string;
1213
spdx_url: string | null;
1314
}
15+
1416
export interface LicenseMatch {
1517
score: number;
1618
start_line: number;
@@ -20,7 +22,10 @@ export interface LicenseMatch {
2022
match_coverage: number;
2123
matcher: string;
2224
license_expression: string;
25+
26+
// Support both old and new ScanCode license fields
2327
spdx_license_expression?: string;
28+
2429
from_file?: string;
2530
rule_identifier: string;
2631
rule_relevance: number;
@@ -34,6 +39,7 @@ export interface LicenseMatch {
3439
// Legacy output version fields
3540
license_expression_spdx?: string;
3641
}
42+
3743
export type LicenseDetectionMatch = LicenseMatch;
3844
export type LicenseClueMatch = LicenseMatch;
3945

@@ -43,6 +49,7 @@ export interface LicenseFileRegion {
4349
end_line: number;
4450
from_package?: string;
4551
}
52+
4653
export interface LicenseClue {
4754
score: number;
4855
start_line: number;
@@ -62,8 +69,11 @@ export interface LicenseClue {
6269
fileClueIdx: number;
6370
matches?: LicenseClueMatch[];
6471
file_regions?: LicenseFileRegion[];
72+
73+
// Support both old and new fields
6574
license_expression_spdx?: string;
6675
}
76+
6777
export interface TopLevelLicenseDetection {
6878
identifier: string;
6979
license_expression: string;
@@ -73,12 +83,13 @@ export interface TopLevelLicenseDetection {
7383
reference_matches?: LicenseDetectionMatch[];
7484

7585
// Parser-added fields
76-
matches?: LicenseDetectionMatch[]; // Also part of legacy output
86+
matches?: LicenseDetectionMatch[];
7787

7888
// Legacy output version fields
7989
count?: number;
8090
sample_matches?: LicenseDetectionMatch[];
8191
}
92+
8293
export interface ResourceLicenseDetection {
8394
license_expression: string;
8495
matches: LicenseDetectionMatch[];
@@ -134,6 +145,7 @@ export interface Resource {
134145
is_media?: boolean;
135146
is_source?: boolean;
136147
is_script?: boolean;
148+
137149
package_data?: {
138150
type: string;
139151
namespace: string;
@@ -144,13 +156,15 @@ export interface Resource {
144156
primary_language: string | null;
145157
description: string;
146158
release_date: null;
159+
147160
parties: {
148161
type: string;
149162
role: string;
150163
name: string;
151164
email: string;
152165
url: string;
153166
}[];
167+
154168
keywords: string[];
155169
homepage_url: string;
156170
download_url: string;
@@ -164,56 +178,73 @@ export interface Resource {
164178
vcs_url: string;
165179
copyright: string;
166180
holder: string;
181+
167182
declared_license_expression: string;
168183
declared_license_expression_spdx: string;
184+
169185
license_detections?: ResourceLicenseDetection[];
186+
170187
other_license_expression: string;
171188
other_license_expression_spdx: string;
172189
other_license_detections?: ResourceLicenseDetection[];
190+
173191
extracted_license_statement: string;
174192
notice_text: string;
175193
source_packages: string[];
176194
file_references: unknown[];
177195
extra_data: unknown;
196+
178197
dependencies: {
179198
purl: string;
180199
extracted_requirement: null;
181200
scope: string | null;
182201
is_runtime: boolean;
183202
is_optional: boolean;
184-
is_pinned: boolean;
203+
204+
// ✅ FIX: Support both old and new ScanCode fields
205+
is_resolved?: boolean;
206+
is_pinned?: boolean;
207+
185208
resolved_package: unknown;
186209
extra_data: unknown;
187210
}[];
211+
188212
repository_homepage_url: string;
189213
repository_download_url: string;
190214
api_data_url: string;
191215
datasource_id: string;
192216
purl: string;
193217
}[];
218+
194219
for_packages?: string[];
195220
detected_license_expression?: string | null;
196221
detected_license_expression_spdx?: string | null;
197222
for_license_detections?: string[];
223+
198224
license_detections?: ResourceLicenseDetection[];
199225
license_clues?: LicenseClue[];
226+
200227
emails?: unknown[];
201228
urls?: unknown[];
229+
202230
copyrights?: {
203231
copyright: string;
204232
start_line: number;
205233
end_line: number;
206234
}[];
235+
207236
holders?: {
208237
holder: string;
209238
start_line: number;
210239
end_line: number;
211240
}[];
241+
212242
authors?: {
213243
author: string;
214244
start_line: number;
215245
end_line: number;
216246
}[];
247+
217248
percentage_of_license_text?: number;
218249
license_policy?: LicensePolicy[];
219250
scan_errors?: string[];

0 commit comments

Comments
 (0)