import { CliConfig, Output, UserViteConfig } from "@sanity/cli-core/types";
import { WorkbenchExposes } from "@sanity/workbench-cli/build";
import { ConfigEnv, InlineConfig, Plugin } from "vite";
import { FSWatcher } from "chokidar";
interface CompareDependencyVersions {
  installed: string;
  pkg: string;
  remote: string;
}
interface UnresolvedPrerelease {
  pkg: string;
  version: string;
}
interface CompareDependencyVersionsResult {
  mismatched: Array<CompareDependencyVersions>;
  unresolvedPrerelease: Array<UnresolvedPrerelease>;
}
interface CompareDependencyVersionsOptions {
  /** When provided, uses the app-specific module endpoint instead of the default endpoint. */
  appId?: string;
}
/**
 * @internal
 *
 * Compares the versions of dependencies in the studio or app with their remote versions.
 *
 * This function reads the package.json file in the provided working directory, and compares the versions of the dependencies
 * specified in the `autoUpdatesImports` parameter with their remote versions. If the versions do not match, the dependency is
 * added to a list of failed dependencies, which is returned by the function.
 *
 * The failed dependencies are anything that does not strictly match the remote version.
 * This means that if a version is lower or greater by even a patch it will be marked as failed.
 *
 * @param packages - An array of packages with their name and version to compare against remote.
 * @param workDir - The path to the working directory containing the package.json file.
 * @param options - Optional configuration for version comparison.
 *
 * @returns A promise that resolves to an object containing `mismatched` (packages whose local and remote versions differ)
 * and `unresolvedPrerelease` (packages with prerelease versions that could not be resolved remotely).
 *
 * @throws Throws an error if the remote version of a non-prerelease package cannot be fetched, or if the local version
 * of a package cannot be parsed.
 */
declare function compareDependencyVersions(packages: {
  name: string;
  version: string;
}[], workDir: string, { appId }?: CompareDependencyVersionsOptions): Promise<CompareDependencyVersionsResult>;
type MessageFunc = ({ message }: {
  message: string;
}) => void;
interface BuildEventListener {
  onPreReleaseInInteractiveAutoUpdate(params: {
    prereleaseMessage: string;
  }): Promise<void>;
  onPreReleaseInNonInteractiveAutoUpdate: MessageFunc;
}
type BuildAppEventListener = BuildEventListener;
interface BuildOptions$1 {
  appId: string | undefined;
  appTitle: string | undefined;
  autoUpdatesEnabled: boolean;
  checkAppId: () => void;
  compareDependencyVersions: (packages: {
    name: string;
    version: string;
  }[]) => Promise<CompareDependencyVersionsResult>;
  determineBasePath: () => string;
  entry: string | undefined;
  eventListener: Partial<BuildAppEventListener>;
  isWorkbenchApp: boolean;
  minify: boolean;
  outDir: string | undefined;
  output: Output;
  reactCompiler: CliConfig['reactCompiler'];
  schemaExtraction: CliConfig['schemaExtraction'];
  sourceMap: boolean;
  stats: boolean;
  unattendedMode: boolean;
  vite: UserViteConfig | undefined;
  workDir: string;
  exposes?: WorkbenchExposes;
  /**
   * The build is running under Sanity Blueprints (invoked programmatically by
   * `@sanity/runtime-cli`), so emit the statically-imported resource-bindings
   * module Brett rewrites at deploy. Defaults to `false`, so a normal
   * `sanity build`/`dev`/`preview` never emits it.
   */
  isBlueprints?: boolean;
  /** The workbench app's bus identity (`__SANITY_APP_ID__`). */
  workbenchAppId?: string;
}
/**
 * Internal build app that avoids depending on flags for CLI config.
 * @param options - options for the build
 */
declare function buildApp(options: BuildOptions$1): Promise<void>;
interface VendorBuildConfig {
  /** Rolldown entry name -\> absolute path to the package entry file. */
  entries: Record<string, string>;
  /** Named exports each CommonJS entry must re-expose as ESM, keyed by chunk name. */
  namesByChunkName: Record<string, readonly string[]>;
  /** Rolldown entry chunk name -\> bare import specifier (e.g. `react`, `react-dom/client`). */
  specifiersByChunkName: Record<string, string>;
}
interface ResolveVendorBuildConfigOptions {
  cwd: string;
  isApp: boolean;
}
/**
 * Resolves vendor package entry points and metadata for a combined studio/app build.
 * Does not run a build — callers add `entries` to the main Vite/Rolldown input and
 * derive the import map from emitted vendor chunks after the single `vite.build`.
 *
 * @internal
 */
declare function resolveVendorBuildConfig({ cwd, isApp }: ResolveVendorBuildConfigOptions): Promise<VendorBuildConfig>;
/**
 * Everything the production build needs to produce an auto-updating studio/app.
 *
 * Auto-updating deployments load `sanity` (and friends) from Sanity's module
 * CDN via an import map, and load `react`/`react-dom`/`styled-components` from
 * hashed vendor chunks emitted by the build itself. These concerns always come
 * together: when auto-updates are disabled none of this applies and everything
 * is bundled as usual.
 *
 * @internal
 */
interface AutoUpdatesBuildConfig {
  /** Import map entries for the packages served from Sanity's module CDN. */
  imports: Record<string, string>;
  /** Vendor packages to emit as hashed browser-loadable ESM chunks. */
  vendor: VendorBuildConfig;
  /** Stylesheets served from the module CDN, loaded via `<link>` tags. */
  cssUrls?: string[];
}
interface ChunkModule {
  name: string;
  renderedLength: number;
}
interface ChunkStats {
  modules: ChunkModule[];
  name: string;
}
interface StaticBuildOptions {
  basePath: string;
  cwd: string;
  outputDir: string;
  appTitle?: string;
  autoUpdates?: AutoUpdatesBuildConfig;
  entry?: string;
  exposes?: WorkbenchExposes;
  isApp?: boolean;
  /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */
  isBlueprints?: boolean;
  /** Workbench app (opted in via `defineApplication`) — drives the federation build. */
  isWorkbenchApp?: boolean;
  minify?: boolean;
  profile?: boolean;
  reactCompiler?: CliConfig['reactCompiler'];
  schemaExtraction?: CliConfig['schemaExtraction'];
  sourceMap?: boolean;
  vite?: UserViteConfig;
  /** The workbench app's bus identity (`__SANITY_APP_ID__`). */
  workbenchAppId?: string;
}
/**
 * Builds static files
 *
 * @internal
 */
declare function buildStaticFiles(options: StaticBuildOptions): Promise<{
  chunks: ChunkStats[];
}>;
interface BuildStudioEventListener extends BuildEventListener {
  onBuildEnd: MessageFunc;
  onBuildFail: MessageFunc;
  onBuildStart: MessageFunc;
  onCleanOutputDirEnd: MessageFunc;
  onCleanOutputDirStart: MessageFunc;
  onIncompatibleDeclaredStyledComponentsVersionRange: MessageFunc;
  onIncompatibleInstalledStyledComponentsVersionRange: MessageFunc;
  onInteractiveNonDefaultOutputDir({ message }: {
    message: string;
  }): Promise<{
    shouldClean: boolean;
  }>;
  onInvalidStyledComponentsVersionRange: MessageFunc;
  onNoDeclaredStyledComponentsVersion: MessageFunc;
  onNoInstalledSanityVersion: MessageFunc;
  onNoInstalledStyledComponentsVersion: MessageFunc;
  onVersionMismatchInInteractiveAutoUpdate(params: {
    mismatched: CompareDependencyVersions[];
    versionMismatchWarning: string;
  }): Promise<{
    stopBuild: boolean;
  }>;
  onVersionMismatchInNonInteractiveAutoUpdate(params: {
    versionMismatchWarning: string;
  }): void;
}
interface BuildOptions {
  appId: string | undefined;
  autoUpdatesEnabled: boolean;
  checkAppId: () => void;
  compareDependencyVersions: (packages: {
    name: string;
    version: string;
  }[]) => Promise<CompareDependencyVersionsResult>;
  determineBasePath: () => string;
  eventListener: Partial<BuildStudioEventListener>;
  isApp: boolean;
  isWorkbenchApp: boolean;
  minify: boolean;
  outDir: string | undefined;
  output: Output;
  reactCompiler: boolean | CliConfig['reactCompiler'] | undefined;
  schemaExtraction: CliConfig['schemaExtraction'];
  sourceMap: boolean;
  stats: boolean;
  unattendedMode: boolean;
  vite: UserViteConfig | undefined;
  workDir: string;
  exposes?: WorkbenchExposes;
  /**
   * The build is running under Sanity Blueprints (invoked programmatically by
   * `@sanity/runtime-cli`), so emit the statically-imported resource-bindings
   * module Brett rewrites at deploy. Defaults to `false`, so a normal
   * `sanity build`/`dev`/`preview` never emits it.
   */
  isBlueprints?: boolean;
  /** The workbench app's bus identity (`__SANITY_APP_ID__`). */
  workbenchAppId?: string;
}
/**
 * Internal build studio that avoids depending on flags for CLI config.
 * @param options - options for the build
 */
declare function buildStudio(options: BuildOptions): Promise<void>;
interface CheckResult {
  installedSanityVersion: string;
}
interface CheckRequiredDependenciesOptions {
  isApp: boolean;
  workDir: string;
  onIncompatibleDeclaredStyledComponentsVersionRange?: BuildStudioEventListener['onIncompatibleDeclaredStyledComponentsVersionRange'];
  onIncompatibleInstalledStyledComponentsVersionRange?: BuildStudioEventListener['onIncompatibleInstalledStyledComponentsVersionRange'];
  onInvalidStyledComponentsVersionRange?: BuildStudioEventListener['onInvalidStyledComponentsVersionRange'];
  onNoDeclaredStyledComponentsVersion?: BuildStudioEventListener['onNoDeclaredStyledComponentsVersion'];
  onNoInstalledSanityVersion?: BuildStudioEventListener['onNoInstalledSanityVersion'];
  onNoInstalledStyledComponentsVersion?: BuildStudioEventListener['onNoInstalledStyledComponentsVersion'];
}
/**
 * Checks that the studio has declared and installed the required dependencies
 * needed by the Sanity modules. While we generally use regular, explicit
 * dependencies in modules, there are certain dependencies that are better
 * served being peer dependencies, such as react and styled-components.
 *
 * If these dependencies are not installed/declared, we report an error
 * and instruct the user to install them manually.
 *
 * Additionally, returns the version of the 'sanity' dependency from the package.json.
 */
declare function checkRequiredDependencies(options: CheckRequiredDependenciesOptions): Promise<CheckResult>;
interface TrackedPackage {
  deprecatedBelow: string | null;
  name: string;
  supported: string[];
}
declare function checkStudioDependencyVersions(workDir: string, output: Output, { packages }?: {
  packages?: TrackedPackage[];
}): Promise<void>;
interface ViteOptions {
  /**
   * Root path of the studio/sanity app
   */
  cwd: string;
  entries: {
    relativeConfigLocation: string | null;
    relativeEntry: string | null;
  };
  /**
   * Returns the environment variables to be injected into the config.
   */
  getEnvironmentVariables(): Record<string, string>;
  /**
   * Mode to run vite in - eg development or production
   */
  mode: 'development' | 'production';
  reactCompiler: CliConfig['reactCompiler'];
  /**
   * Additional plugins when configured, eg. typegen
   */
  additionalPlugins?: Plugin[];
  /**
   * Auto-updates configuration (production builds only). When set, vendor
   * packages are emitted as hashed ESM chunks by this build and the import map
   * in `index.html` is derived from the build output.
   */
  autoUpdates?: AutoUpdatesBuildConfig;
  /**
   * Base path (eg under where to serve the app - `/studio` or similar)
   * Will be normalized to ensure it starts and ends with a `/`
   */
  basePath?: string;
  exposes?: WorkbenchExposes;
  isApp?: boolean;
  /**
   * Blueprints build (invoked via `@sanity/runtime-cli`). When set, the
   * resource-bindings module is forced into its own unhashed chunk at the bundle
   * root; otherwise no such chunk is produced.
   */
  isBlueprints?: boolean;
  /**
   * Whether this is a workbench app (opted in via `defineApplication`). Drives
   * the module-federation build.
   */
  isWorkbenchApp?: boolean;
  /**
   * Whether or not to minify the output (only used in `mode: 'production'`)
   */
  minify?: boolean;
  /**
   * Output directory (eg where to place the built files, if any)
   */
  outputDir?: string;
  /**
   * Schema extraction configuration
   */
  schemaExtraction?: CliConfig['schemaExtraction'];
  /**
   * HTTP development server configuration
   */
  server?: {
    host?: string;
    port?: number;
  };
  /**
   * Whether or not to enable source maps
   */
  sourceMap?: boolean;
  /**
   * The workbench app's bus identity, stamped into its modules as
   * `__SANITY_APP_ID__` for `@sanity/runtime`. Only read for workbench apps.
   */
  workbenchAppId?: string;
}
/**
 * Get a configuration object for Vite based on the passed options
 *
 * @internal Only meant for consumption inside of Sanity modules, do not depend on this externally
 */
declare function getViteConfig(options: ViteOptions): Promise<InlineConfig>;
/**
 * Merge user-provided Vite configuration object or function
 *
 * @param defaultConfig - Default configuration object
 * @param userConfig - User-provided configuration object or function
 * @returns Merged configuration
 * @internal
 */
declare function extendViteConfigWithUserConfig(env: ConfigEnv, defaultConfig: InlineConfig, userConfig: UserViteConfig): Promise<InlineConfig>;
interface RuntimeOptions {
  cwd: string;
  reactStrictMode: boolean | undefined;
  watch: boolean;
  appTitle?: string;
  basePath?: string;
  entry?: string;
  isApp?: boolean;
  /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */
  isBlueprints?: boolean;
  isWorkbenchApp?: boolean;
}
/**
 * Generates the `.sanity/runtime` directory, and optionally watches for custom
 * document files, rebuilding when they change
 *
 * @param options - Current working directory (Sanity root dir), and whether or not to watch
 * @returns A watcher instance if watch is enabled, undefined otherwise
 * @internal
 */
declare function writeSanityRuntime(options: RuntimeOptions): Promise<{
  entries: {
    relativeConfigLocation: string | null;
    relativeEntry: string | null;
  };
  watcher: FSWatcher | undefined;
}>;
/**
 * Root directory (relative to the project) used by Sanity tooling for
 * build-time artifacts and caches — Vite's `cacheDir` and the dev-time
 * manifest output. Lives under `node_modules/` so it's out of `dist` and
 * ignored by default in typical `.gitignore` files.
 */
declare const SANITY_CACHE_DIR = "node_modules/.sanity";
export { type BuildAppEventListener, type BuildStudioEventListener, type CompareDependencyVersions, type CompareDependencyVersionsResult, SANITY_CACHE_DIR, type UnresolvedPrerelease, buildApp, buildStaticFiles, buildStudio, checkRequiredDependencies, checkStudioDependencyVersions, compareDependencyVersions, extendViteConfigWithUserConfig, getViteConfig, resolveVendorBuildConfig, writeSanityRuntime };
//# sourceMappingURL=build.d.ts.map