UNPKG

@netlify/build-info

Version:

Build info utility

100 lines (99 loc) 4.83 kB
import type { Client, NotifiableError } from '@bugsnag/js'; import type { PackageJson } from 'read-pkg'; import { SemVer } from 'semver'; import type { BuildSystem } from './build-systems/build-system.js'; import { EventEmitter } from './events.js'; import { FileSystem } from './file-system.js'; import { DetectedFramework } from './frameworks/framework.js'; import { Logger } from './logger.js'; import { Severity, report } from './metrics.js'; import { DetectPackageManagerOptions, PkgManagerFields } from './package-managers/detect-package-manager.js'; import { LangRuntime } from './runtime/runtime.js'; import { Settings } from './settings/get-build-settings.js'; import { WorkspaceInfo } from './workspaces/detect-workspace.js'; type Events = { detectPackageManager: (data: PkgManagerFields | null) => void; detectedWorkspaceGlobs: () => void; detectWorkspaces: (data: WorkspaceInfo | null) => void; detectBuildsystems: (data: BuildSystem[]) => void; detectFrameworks: (data: Map<string, DetectedFramework[]>) => void; detectSettings: (data: Settings[]) => void; detectRuntimes: (data: LangRuntime[]) => void; }; /** * The Project represents a Site in Netlify * The only configuration here needed is the path to the repository root and the optional baseDirectory */ export declare class Project { #private; fs: FileSystem; /** An optional repository root that tells us where to stop looking up */ root?: string; /** An absolute path */ baseDirectory: string; /** a relative base directory (like the path to workspace packages) */ relativeBaseDirectory?: string; /** the detected package manager (if null it's not a javascript project, undefined indicates that id did not run yet) */ packageManager: PkgManagerFields | null; /** an absolute path of the root directory for js workspaces where the most top package.json is located */ jsWorkspaceRoot: string; workspace: WorkspaceInfo | null; /** The detected build-systems */ buildSystems: BuildSystem[]; /** The combined build settings for a project, in a workspace there can be multiple settings per package */ settings: Settings[]; /** The detected frameworks for each path in a project */ frameworks: Map<string, DetectedFramework[]>; /** The detected language runtimes */ runtimes: LangRuntime[]; /** A bugsnag session */ bugsnag: Client; /** A logging instance */ logger: Logger; /** A function that is used to report errors */ reportFn: typeof report; events: EventEmitter<Events>; /** The current nodeVersion (can be set by node.js environments) */ private _nodeVersion; setNodeVersion(version: string): this; getCurrentNodeVersion(): Promise<SemVer | null>; isRedwoodProject(): Promise<boolean>; constructor(fs: FileSystem, baseDirectory?: string, root?: string); /** Set's the environment for the project */ setEnvironment(env: Record<string, string | undefined>): this; /** Sets the function that is used to report errors. Overrides the default bugsnag reporting for the project */ setReportFn(fn: typeof report): this; /** Sets a bugsnag client for the current session */ setBugsnag(client?: Client): this; /** retrieves an environment variable */ getEnv(key: string): string | undefined; /** Reports an error with additional metadata */ report(error: NotifiableError, config?: { metadata?: Record<string, any>; severity?: Severity; context?: string; }): void; /** Retrieve the run command for an npm script */ getNpmScriptCommand(npmScript: string): string; /** retrieves the root package.json file */ getRootPackageJSON(): Promise<Partial<PackageJson>>; /** Retrieves the package.json and if one found with it's pkgPath */ getPackageJSON(startDirectory?: string): Promise<Partial<PackageJson> & { pkgPath: string | null; }>; /** Resolves a path correctly with a package path, independent of run from the workspace root or from a package */ resolveFromPackage(packagePath: string, ...parts: string[]): string; /** Detects the used package Manager */ detectPackageManager(options?: DetectPackageManagerOptions): Promise<PkgManagerFields | null>; /** Detects the javascript workspace settings */ detectWorkspaces(): Promise<WorkspaceInfo | null>; /** Detects all used build systems */ detectBuildSystem(): Promise<BuildSystem[]>; /** Detects all used runtimes */ detectRuntime(): Promise<LangRuntime[]>; /** Detects all used frameworks */ detectFrameworks(): Promise<DetectedFramework[] | null>; detectFrameworksInPath(path?: string): Promise<DetectedFramework[]>; getBuildSettings(packagePath?: string): Promise<Settings[]>; } export {};