package-yaml
Version:
Reversible YAML parsing for package.json
66 lines (65 loc) • 2.54 kB
TypeScript
/// <reference path="types/yaml.d.ts" />
import yaml from 'yaml';
import { Diff } from 'deep-diff';
import 'reflect-metadata';
declare type PickTypedPropNames<T, U> = NonNullable<{
[k in keyof T]: T[k] extends U ? k : never;
}[keyof T]>;
declare type PickTypedProps<T, U> = Pick<T, PickTypedPropNames<T, U>>;
declare type SimplePropNames<T> = PickTypedPropNames<T, string | boolean | number>;
declare type SimpleProps<T> = PickTypedProps<T, string | boolean | number>;
declare enum ConflictResolution {
ask = "ask",
useJson = "use-json",
useYaml = "use-yaml",
useLatest = "use-latest"
}
declare class Config {
readonly debug: boolean;
readonly writeBackups: boolean;
readonly backupPath: string;
readonly timestampFuzz: number;
readonly conflicts: ConflictResolution;
readonly tryMerge: boolean;
readonly defaultExtension: "yaml" | "yml";
_lockedProps: {
-readonly [k in keyof Config]?: boolean;
};
constructor(loadConfigFiles?: boolean);
loadSystemConfig(): void;
static isValid<P extends keyof Config>(prop: P, value: any): value is Config[P];
validate(values: any): Partial<SimpleProps<Config>>;
update(values: Partial<SimpleProps<Config>>): Partial<SimpleProps<Config>>;
lock(props: SimplePropNames<Config>[]): void;
updateAndLock(values: Partial<SimpleProps<Config>>): Partial<SimpleProps<Config>>;
loadConfigFile(path: string, rootElement?: string): Partial<SimpleProps<Config>> | null;
}
export declare class Project {
readonly projectDir: string;
yamlExtension: string | null;
readonly config: Config;
readonly jsonName: string;
readonly yamlName: string;
projectPath(localPath: string): string;
readonly jsonPath: string;
readonly yamlPath: string;
readonly jsonExists: boolean;
readonly yamlExists: boolean;
yamlModified: boolean;
jsonModified: boolean;
private _jsonContents?;
private _yamlDocument?;
jsonContents: object;
yamlDocument: yaml.ast.Document;
readonly yamlContents: object;
backupPath(filename: string): string;
constructor(projectDir: string);
writeBackups(): boolean;
writePackageFiles(): boolean;
patchYaml(diff: Diff<any, any>[] | null | undefined): yaml.ast.Document;
patchJson(diff: Diff<any, any>[] | null | undefined): any;
sync(conflictStrategy?: ConflictResolution): boolean | ConflictResolution.ask;
}
export declare function _npm_autoload(npm: NPM.Static, command: string): void;
export {};