Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: structuredClonePolyfill to helpers #1250

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
import { readFileSync, writeSync } from 'fs'
import { extname, parse } from 'path'

export const structuredClonePolyfill: <T>(value: T) => T = typeof structuredClone === 'function'
? structuredClone
: function (value) { return JSON.parse(JSON.stringify(value)) }

export function loadJsonFile (path: string): any {
return JSON.parse(readFileSync(path, 'utf8'))
// may be replaced by `require(f, { with: { type: "json" } })`
Expand Down
12 changes: 7 additions & 5 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import * as normalizePackageData from 'normalize-package-data'
import * as path from 'path'
import { join } from 'path'

import { getMimeForLicenseFile, isString, loadJsonFile, tryRemoveSecretsFromUrl } from './_helpers'
import {
getMimeForLicenseFile,
isString,
loadJsonFile,
structuredClonePolyfill,
tryRemoveSecretsFromUrl
} from './_helpers'
import { makeNpmRunner, type runFunc } from './npmRunner'
import { PropertyNames, PropertyValueBool } from './properties'
import { versionCompare } from './versionCompare'
Expand Down Expand Up @@ -714,7 +720,3 @@ export class TreeBuilder {
}
}
}

const structuredClonePolyfill: <T>(value: T) => T = typeof structuredClone === 'function'
? structuredClone
: function (value) { return JSON.parse(JSON.stringify(value)) }
Loading