Skip to content

Commit b93b1c3

Browse files
authored
refactor: structuredClonePolyfill to helpers (#1250)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 3d7f8e1 commit b93b1c3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/_helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import { readFileSync, writeSync } from 'fs'
2121
import { extname, parse } from 'path'
2222

23+
export const structuredClonePolyfill: <T>(value: T) => T = typeof structuredClone === 'function'
24+
? structuredClone
25+
: function (value) { return JSON.parse(JSON.stringify(value)) }
26+
2327
export function loadJsonFile (path: string): any {
2428
return JSON.parse(readFileSync(path, 'utf8'))
2529
// may be replaced by `require(f, { with: { type: "json" } })`

src/builders.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ import * as normalizePackageData from 'normalize-package-data'
2323
import * as path from 'path'
2424
import { join } from 'path'
2525

26-
import { getMimeForLicenseFile, isString, loadJsonFile, tryRemoveSecretsFromUrl } from './_helpers'
26+
import {
27+
getMimeForLicenseFile,
28+
isString,
29+
loadJsonFile,
30+
structuredClonePolyfill,
31+
tryRemoveSecretsFromUrl
32+
} from './_helpers'
2733
import { makeNpmRunner, type runFunc } from './npmRunner'
2834
import { PropertyNames, PropertyValueBool } from './properties'
2935
import { versionCompare } from './versionCompare'
@@ -714,7 +720,3 @@ export class TreeBuilder {
714720
}
715721
}
716722
}
717-
718-
const structuredClonePolyfill: <T>(value: T) => T = typeof structuredClone === 'function'
719-
? structuredClone
720-
: function (value) { return JSON.parse(JSON.stringify(value)) }

0 commit comments

Comments
 (0)