UNPKG

svelte-language-server

Version:
93 lines (92 loc) 3.61 kB
import { loadConfig as loadConfigFromDirectory } from '@sveltejs/load-config'; import { CompileOptions } from 'svelte/types/compiler/interfaces'; import { PreprocessorGroup } from 'svelte/types/compiler/preprocess'; import { fdir } from 'fdir'; import _path from 'path'; import _fs from 'fs'; export type InternalPreprocessorGroup = PreprocessorGroup & { /** * svelte-preprocess has this since 4.x */ defaultLanguages?: { markup?: string; script?: string; style?: string; }; }; export interface SvelteConfig { compilerOptions?: CompileOptions; preprocess?: InternalPreprocessorGroup | InternalPreprocessorGroup[]; loadConfigError?: any; isFallbackConfig?: boolean; configSource?: 'svelte' | 'vite'; kit?: any; } export interface ExplicitConfigScope { configPath: string; /** Directory of the initial tsconfig or svelte-check workspace */ rootDirectory: string; } type LoadConfigFromDirectoryFn = typeof loadConfigFromDirectory; /** * Loads vite.config.* and svelte.config.{js,ts,cjs,mjs,mts} files. Provides both * a synchronous and asynchronous interface to get a config file * because snapshots need access to it synchronously. * This means that another instance (the ts service host on startup) should make * sure that all config files are loaded before snapshots are retrieved. * Asynchronousity is needed because we use the dynamic `import()` statement. */ export declare class ConfigLoader { private globSync; private fs; private path; private loadFromDirectory; private configFiles; private configFilesAsync; private filePathToConfigPath; private disabled; private loadSvelteConfigTs; private explicitConfigScope?; constructor(globSync: typeof fdir, fs: Pick<typeof _fs, 'existsSync'>, path: Pick<typeof _path, 'dirname' | 'relative' | 'join'>, processFeatures: (typeof process)['features'] & { typescript?: false | 'transform'; }, loadFromDirectory: LoadConfigFromDirectoryFn); /** * Enable/disable loading of configs (for security reasons for example) */ setDisabled(disabled: boolean): void; /** * Use a specific config file path instead of searching for standard config filenames. * Only applies within `rootDirectory` (the initial tsconfig/workspace being checked). */ setExplicitConfigScope(scope: ExplicitConfigScope | undefined): void; private isInExplicitConfigScope; /** * Tries to load all `svelte.config.js` files below given directory * and the first one found inside/above that directory. * * @param directory Directory where to load the configs from */ loadConfigs(directory: string): Promise<void>; private addFallbackConfig; private searchConfigPathUpwards; private loadAndCacheConfig; private loadConfig; /** * Returns config associated to file. If no config is found, the file * was called in a context where no config file search was done before, * which can happen * - if TS intellisense is turned off and the search did not run on tsconfig init * - if the file was opened not through the TS service crawl, but through the LSP * * @param file */ getConfig(file: string): SvelteConfig | undefined; /** * Like `getConfig`, but will search for a config above if no config found. */ awaitConfig(file: string): Promise<SvelteConfig | undefined>; private tryGetConfigForDirectory; private useFallbackPreprocessor; } export declare const configLoader: ConfigLoader; export {};