/** * @file SPDX license parsing and analysis utilities. */ import type { LicenseNode } from './types.js'; 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; 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 | undefined) => boolean | undefined; BinaryOperation?: (node: InternalBinaryOperationNode, parent?: InternalAstNode | undefined) => boolean | undefined; } /** * Collect licenses that are incompatible (copyleft). * * @example * ;```typescript * const nodes = [{ license: 'MIT' }, { license: 'GPL-3.0' }] * const incompatible = collectIncompatibleLicenses(nodes) * // incompatible contains only the GPL-3.0 node * ``` */ export declare function collectIncompatibleLicenses(licenseNodes: LicenseNode[]): LicenseNode[]; /** * Collect warnings from license nodes. * * @example * ;```typescript * const nodes = [{ license: 'UNLICENSED' }] * collectLicenseWarnings(nodes) // ['Package is unlicensed'] * ``` */ export declare function collectLicenseWarnings(licenseNodes: LicenseNode[]): string[]; /** * Create an AST node from a raw node. * * @example * ;```typescript * const raw = { license: 'MIT' } * const node = createAstNode(raw) * // node.type === 'License' * ``` */ export declare function createAstNode(rawNode: SpdxAstNode): InternalAstNode; /** * Create a binary operation AST node. * * @example * ;```typescript * const raw = { * left: { license: 'MIT' }, * conjunction: 'OR' as const, * right: { license: 'Apache-2.0' }, * } * const node = createBinaryOperationNode(raw) * // node.type === 'BinaryOperation' * ``` */ export declare function createBinaryOperationNode(rawNodeParam: SpdxBinaryOperationNode): InternalBinaryOperationNode; /** * Create a license AST node. * * @example * ;```typescript * const node = createLicenseNode({ license: 'MIT' }) * // node.type === 'License' && node.license === 'MIT' * ``` */ export declare function createLicenseNode(rawNode: SpdxLicenseNode): InternalLicenseNode; /** * Parse an SPDX license expression into an AST. * * @example * ;```typescript * const ast = parseSpdxExp('MIT OR Apache-2.0') * // ast is a BinaryOperation node with MIT and Apache-2.0 leaves * ``` */ export declare function parseSpdxExp(spdxExp: string): SpdxAstNode | undefined; /** * Parse package license field into structured license nodes. * * @example * ;```typescript * const nodes = resolvePackageLicenses('MIT', '/tmp/my-project') * // [{ license: 'MIT' }] * ``` */ export declare function resolvePackageLicenses(licenseFieldValue: string, where: string): LicenseNode[]; /** * Traverse SPDX license AST and invoke visitor callbacks for each node. * * @example * ;```typescript * const ast = parseSpdxExp('MIT OR Apache-2.0') * const licenses: string[] = [] * if (ast) { * visitLicenses(ast, { * License(node) { * licenses.push(node.license) * }, * }) * } * // licenses === ['MIT', 'Apache-2.0'] * ``` */ export declare function visitLicenses(ast: SpdxAstNode, visitor: LicenseVisitor): void;