UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

69 lines (68 loc) 2.57 kB
import type { LicenseNode } from '../packages'; // Duplicated from spdx-expression-parse - AST node types. export interface SpdxLicenseNode { license: string; plus?: boolean | undefined; exception?: string | undefined; } export interface SpdxBinaryOperationNode { left: SpdxLicenseNode | SpdxBinaryOperationNode; conjunction: 'and' | 'or'; right: SpdxLicenseNode | SpdxBinaryOperationNode; } export type SpdxAstNode = SpdxLicenseNode | SpdxBinaryOperationNode; // Internal AST node types with type discriminator. export interface InternalLicenseNode extends SpdxLicenseNode { type: 'License'; } export interface InternalBinaryOperationNode { type: 'BinaryOperation'; left: InternalLicenseNode | InternalBinaryOperationNode; conjunction: 'and' | 'or'; right: InternalLicenseNode | InternalBinaryOperationNode; } export type InternalAstNode = InternalLicenseNode | InternalBinaryOperationNode; export interface LicenseVisitor { License?: (node: InternalLicenseNode, parent?: InternalAstNode) => boolean | undefined; BinaryOperation?: (node: InternalBinaryOperationNode, parent?: InternalAstNode) => boolean | undefined; } /** * Collect licenses that are incompatible (copyleft). */ /*@__NO_SIDE_EFFECTS__*/ export declare function collectIncompatibleLicenses(licenseNodes: LicenseNode[]): LicenseNode[]; /** * Collect warnings from license nodes. */ /*@__NO_SIDE_EFFECTS__*/ export declare function collectLicenseWarnings(licenseNodes: LicenseNode[]): string[]; /** * Create an AST node from a raw node. */ /*@__NO_SIDE_EFFECTS__*/ export declare function createAstNode(rawNode: SpdxAstNode): InternalAstNode; /** * Create a binary operation AST node. */ /*@__NO_SIDE_EFFECTS__*/ export declare function createBinaryOperationNode(rawNodeParam: SpdxBinaryOperationNode): InternalBinaryOperationNode; /** * Create a license AST node. */ /*@__NO_SIDE_EFFECTS__*/ export declare function createLicenseNode(rawNode: SpdxLicenseNode): InternalLicenseNode; /** * Parse an SPDX license expression into an AST. */ /*@__NO_SIDE_EFFECTS__*/ export declare function parseSpdxExp(spdxExp: string): SpdxAstNode | undefined; /** * Parse package license field into structured license nodes. */ /*@__NO_SIDE_EFFECTS__*/ export declare function resolvePackageLicenses(licenseFieldValue: string, where: string): LicenseNode[]; /** * Traverse SPDX license AST and invoke visitor callbacks for each node. */ /*@__NO_SIDE_EFFECTS__*/ export declare function visitLicenses(ast: SpdxAstNode, visitor: LicenseVisitor): void;