import type { NextConfigComplete } from '../../server/config-shared'; import type { ExternalObject, RefCell, NapiTurboEngineOptions, NapiSourceDiagnostic, NapiProjectOptions, NapiPartialProjectOptions } from './generated-native'; export type { NapiTurboEngineOptions as TurboEngineOptions }; export type Lockfile = { __napiType: 'Lockfile'; }; export interface TurbopackProjectCallbacks { onBeforeDeferredEntries?: () => Promise; } export interface Binding { isWasm: boolean; turbo: { createProject(options: ProjectOptions, turboEngineOptions?: NapiTurboEngineOptions, callbacks?: TurbopackProjectCallbacks): Promise; startTurbopackTraceServer(traceFilePath: string, port: number | undefined): void; nextBuild?: any; }; mdx: { compile(src: string, options: any): any; compileSync(src: string, options: any): any; }; minify(src: string, options: any): Promise; minifySync(src: string, options: any): any; transform(src: string, options: any): Promise; transformSync(src: string, options: any): any; parse(src: string, options: any): Promise; getTargetTriple(): string | undefined; initCustomTraceSubscriber?(traceOutFilePath?: string): ExternalObject; teardownTraceSubscriber?(guardExternal: ExternalObject): void; css: { lightning: { transform(transformOptions: any): Promise; transformStyleAttr(transformAttrOptions: any): Promise; }; }; reactCompiler: { isReactCompilerRequired(filename: string): Promise; }; rspack: { getModuleNamedExports(resourcePath: string): Promise; warnForEdgeRuntime(source: string, isProduction: boolean): Promise; }; expandNextJsTemplate(content: Buffer, templatePath: string, nextPackageDirPath: string, replacements: Record<`VAR_${string}`, string>, injections: Record, imports: Record): string; lockfileTryAcquire(path: string, content?: string | null): Promise; lockfileTryAcquireSync(path: string, content?: string | null): Lockfile | null; lockfileUnlock(lockfile: Lockfile): Promise; lockfileUnlockSync(lockfile: Lockfile): void; } export type StyledString = { type: 'text'; value: string; } | { type: 'code'; value: string; } | { type: 'strong'; value: string; } | { type: 'stack'; value: StyledString[]; } | { type: 'line'; value: StyledString[]; }; export interface Issue { severity: string; stage: string; filePath: string; title: StyledString; description?: StyledString; detail?: StyledString; source?: { source: { ident: string; content?: string; }; range?: { start: { line: number; column: number; }; end: { line: number; column: number; }; }; }; documentationLink: string; importTraces?: PlainTraceItem[][]; } export interface PlainTraceItem { fsName: string; path: string; rootPath: string; layer?: string; } export interface Diagnostics { category: string; name: string; payload: unknown; } export type TurbopackResult = T & { issues: Issue[]; diagnostics: Diagnostics[]; }; export interface Middleware { endpoint: Endpoint; isProxy: boolean; } export interface Instrumentation { nodeJs: Endpoint; edge: Endpoint; } export interface RawEntrypoints { routes: Map; middleware?: Middleware; instrumentation?: Instrumentation; pagesDocumentEndpoint: Endpoint; pagesAppEndpoint: Endpoint; pagesErrorEndpoint: Endpoint; } interface BaseUpdate { resource: { headers: unknown; path: string; }; diagnostics: unknown[]; issues: Issue[]; } interface IssuesUpdate extends BaseUpdate { type: 'issues'; } interface EcmascriptMergedUpdate { type: 'EcmascriptMergedUpdate'; chunks: { [moduleName: string]: { type: 'partial'; }; }; entries: { [moduleName: string]: { code: string; map: string; url: string; }; }; } interface PartialUpdate extends BaseUpdate { type: 'partial'; instruction: { type: 'ChunkListUpdate'; merged: EcmascriptMergedUpdate[] | undefined; }; } export type Update = IssuesUpdate | PartialUpdate; /** * IMPORTANT: This type is duplicated in: * turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/hmr-types.d.ts * * The runtime file cannot import from this ES module without triggering module semantics, * so we maintain a copy there. Please keep both definitions in sync. */ export interface NodeJsPartialHmrUpdate extends BaseUpdate { type: 'partial'; instruction: { type: 'EcmascriptMergedUpdate'; entries: Record; chunks?: Record; }; } export type NodeJsHmrUpdate = IssuesUpdate | NodeJsPartialHmrUpdate; export interface HmrChunkNames { /** Relative paths to output chunks that can receive HMR updates (e.g., "server/chunks/ssr/..._.js") */ chunkNames: string[]; } /** @see https://github.com/vercel/next.js/blob/415cd74b9a220b6f50da64da68c13043e9b02995/crates/next-napi-bindings/src/next_api/project.rs#L824-L833 */ export interface TurbopackStackFrame { isServer: boolean; isInternal?: boolean; file: string; originalFile?: string; /** 1-indexed, unlike source map tokens */ line?: number; /** 1-indexed, unlike source map tokens */ column?: number; methodName?: string; } export type UpdateMessage = { updateType: 'start'; } | { updateType: 'end'; value: UpdateInfo; }; export type CompilationEvent = { typeName: string; message: string; severity: string; eventData: any; }; export interface UpdateInfo { duration: number; tasks: number; } export interface Project { update(options: Partial): Promise; writeAnalyzeData(appDirOnly: boolean): Promise>; writeAllEntrypointsToDisk(appDirOnly: boolean): Promise>>; entrypointsSubscribe(): AsyncIterableIterator>; hmrEvents(identifier: string, target: import('./index').HmrTarget.Client): AsyncIterableIterator>; hmrEvents(identifier: string, target: import('./index').HmrTarget.Server): AsyncIterableIterator>; hmrChunkNamesSubscribe(target: import('./index').HmrTarget): AsyncIterableIterator>; getSourceForAsset(filePath: string): Promise; getSourceMap(filePath: string): Promise; getSourceMapSync(filePath: string): string | null; traceSource(stackFrame: TurbopackStackFrame, currentDirectoryFileUrl: string): Promise; updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator>; compilationEventsSubscribe(eventTypes?: string[]): AsyncIterableIterator>; invalidateFileSystemCache(): Promise; shutdown(): Promise; onExit(): Promise; } export type Route = { type: 'conflict'; } | { type: 'app-page'; pages: { originalName: string; htmlEndpoint: Endpoint; rscEndpoint: Endpoint; }[]; } | { type: 'app-route'; originalName: string; endpoint: Endpoint; } | { type: 'page'; htmlEndpoint: Endpoint; dataEndpoint: Endpoint; } | { type: 'page-api'; endpoint: Endpoint; }; export interface Endpoint { /** Write files for the endpoint to disk. */ writeToDisk(): Promise>; /** * Listen to client-side changes to the endpoint. * After clientChanged() has been awaited it will listen to changes. * The async iterator will yield for each change. */ clientChanged(): Promise>; /** * Listen to server-side changes to the endpoint. * After serverChanged() has been awaited it will listen to changes. * The async iterator will yield for each change. */ serverChanged(includeIssues: boolean): Promise>; } interface EndpointConfig { dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'; dynamicParams?: boolean; revalidate?: 'never' | 'force-cache' | number; fetchCache?: 'auto' | 'default-cache' | 'only-cache' | 'force-cache' | 'default-no-store' | 'only-no-store' | 'force-no-store'; runtime?: 'nodejs' | 'edge'; preferredRegion?: string; } export type ServerPath = { path: string; contentHash: string; }; export type WrittenEndpoint = { type: 'nodejs'; /** The entry path for the endpoint. */ entryPath: string; /** All client paths that have been written for the endpoint. */ clientPaths: string[]; /** All server paths that have been written for the endpoint. */ serverPaths: ServerPath[]; config: EndpointConfig; } | { type: 'edge'; /** All client paths that have been written for the endpoint. */ clientPaths: string[]; /** All server paths that have been written for the endpoint. */ serverPaths: ServerPath[]; config: EndpointConfig; } | { type: 'none'; clientPaths: []; serverPaths: []; config: EndpointConfig; }; export interface ProjectOptions extends Omit { /** * The next.config.js contents. */ nextConfig: NextConfigComplete; /** * A map of environment variables to use when compiling code. */ env: Record; } export interface PartialProjectOptions extends Omit { rootPath: NapiProjectOptions['rootPath']; projectPath: NapiProjectOptions['projectPath']; /** * The next.config.js contents. */ nextConfig?: NextConfigComplete; /** * A map of environment variables to use when compiling code. */ env?: Record; } export interface DefineEnv { client: RustifiedOptionalEnv; edge: RustifiedOptionalEnv; nodejs: RustifiedOptionalEnv; } export type RustifiedEnv = { name: string; value: string; }[]; export type RustifiedOptionalEnv = { name: string; value: string | undefined; }[]; export interface GlobalEntrypoints { app: Endpoint | undefined; document: Endpoint | undefined; error: Endpoint | undefined; middleware: Middleware | undefined; instrumentation: Instrumentation | undefined; } export type PageRoute = { type: 'page'; htmlEndpoint: Endpoint; dataEndpoint: Endpoint; } | { type: 'page-api'; endpoint: Endpoint; }; export type AppRoute = { type: 'app-page'; htmlEndpoint: Endpoint; rscEndpoint: Endpoint; } | { type: 'app-route'; endpoint: Endpoint; }; export type PageEntrypoints = Map; export type AppEntrypoints = Map; export type Entrypoints = { global: GlobalEntrypoints; page: PageEntrypoints; app: AppEntrypoints; };