import type { BuiltManifest } from './manifest-builder'; /** Publisher-owned package information, independent of component identities. */ export interface PackageInformation { key: string; name: string; type: 'managed' | 'unmanaged'; description?: string; } /** Package information and a reference to the project's source manifest. */ export interface PackageManifest { package: PackageInformation; version: string; manifest: Readonly; } /** Define package information around an existing manifest without compiling its sources. */ export function definePackageManifest(input: PackageManifest): Readonly { if (!/^[a-z][a-z0-9_]{0,99}$/.test(input.package.key)) throw new Error( 'Package key must start with a lowercase letter and contain only lowercase letters, digits, or underscores (maximum 100 characters).', ); if (input.package.key.includes('rippling')) throw new Error('Package key cannot contain the reserved name rippling.'); if (!input.package.name.trim()) throw new Error('Package name is required.'); if (input.package.type !== 'managed' && input.package.type !== 'unmanaged') throw new Error('Package type must be managed or unmanaged.'); if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(input.version)) throw new Error('Package version must be major.minor.patch.'); if (input.manifest.metadata == null || !Array.isArray(input.manifest.components)) throw new Error('Package manifest requires metadata and components.'); if (input.manifest.components_to_delete != null && input.manifest.components_to_delete.length > 0) throw new Error('Package snapshots cannot contain component deletions.'); return Object.freeze({ package: Object.freeze({ ...input.package }), version: input.version, manifest: input.manifest, }); }