UNPKG

@darkobits/ts

Version:

Vite-based toolchain for Node projects.

69 lines (68 loc) 2.29 kB
import type { NormalizedPackageJson } from 'read-package-up'; import type { UserConfig, ConfigEnv } from 'vite'; import type { InlineConfig } from 'vitest'; /** * Custom type we use for Vite configuration that has various properties * pre-defined to make updating the object in-place easier. */ export interface ViteConfigurationScaffold extends UserConfig { test?: InlineConfig; build: NonNullable<UserConfig['build']>; plugins: NonNullable<UserConfig['plugins']>; resolve: NonNullable<UserConfig['resolve']>; server: NonNullable<UserConfig['server']>; } /** * Object returned by `getPackageContext`. */ export interface PackageContext { /** * Inferred project root. Can be overridden by setting the VITE_ROOT * environment variable. * * @default process.cwd() */ root: string; /** * Sub-directory that contains the project's source files. Read from * "compilerOptions.baseUrl" in tsconfig.json. */ srcDir: string; /** * Sub-directory to which output files should be written. Read from * "compilerOptions.outDir" in tsconfig.json. */ outDir: string; /** * Path to the project's tsconfig.json file. */ tsConfigPath: string; /** * Parsed tsconfig.json file. */ tsConfig: any; /** * Parsed and normalized package.json file. */ packageJson: NormalizedPackageJson; /** * Glob patterns that may be used to match various file types in the project. */ patterns: { SOURCE_FILES: string; TEST_FILES: string; }; } /** * Context object that will be passed to user configuration functions. Extends * the default ConfigEnv provided by Vite with the values from PackageContext * above. */ export type ConfigurationContext = ConfigEnv & PackageContext & { config: ViteConfigurationScaffold; }; /** * Signature of configuration functions passed to a Vite configuration preset. */ export type CustomConfigurationFactory<C extends ConfigurationContext = ConfigurationContext> = (context: C) => void | UserConfig | Promise<void | UserConfig>; export type CustomUserConfigExport<C extends ConfigurationContext = ConfigurationContext> = UserConfig | Promise<UserConfig> | CustomConfigurationFactory<C>;