From 57a40bab50375e5adfd17cc44dcf95a135fbaed2 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 6 Oct 2016 23:18:06 +0200 Subject: [PATCH] Add typings for sass-graph (#11801) --- sass-graph/sass-graph-tests.ts | 8 ++++ sass-graph/sass-graph.d.ts | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 sass-graph/sass-graph-tests.ts create mode 100644 sass-graph/sass-graph.d.ts diff --git a/sass-graph/sass-graph-tests.ts b/sass-graph/sass-graph-tests.ts new file mode 100644 index 0000000000..1e9c65470d --- /dev/null +++ b/sass-graph/sass-graph-tests.ts @@ -0,0 +1,8 @@ +/// + +import { parseFile, parseDir, Graph } from "sass-graph"; + +// Example copied from readme: +// https://github.com/xzyfer/sass-graph/blob/master/readme.md +const graph1: Graph = parseFile("test/fixtures/main.scss"); +const graph2: Graph = parseDir("test/fixtures"); diff --git a/sass-graph/sass-graph.d.ts b/sass-graph/sass-graph.d.ts new file mode 100644 index 0000000000..ccc5b45995 --- /dev/null +++ b/sass-graph/sass-graph.d.ts @@ -0,0 +1,81 @@ +// Type definitions for sass-graph v2.1.2 +// Project: https://github.com/xzyfer/sass-graph +// Definitions by: Marvin Hagemeister +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace SassGraph { + + export interface Options { + loadPath?: string[]; + extensions?: string[]; + } + + type Node = { + [filepath: string]: { + imports: string[]; + importedBy: string[]; + modified: string; + } + } + + /** + * @class Graph + */ + export interface Graph { + dir: string; + loadPaths: string[]; + extensions: string[]; + index: Node; + + /** + * Add a sass file to the graph + * @param {string} filepath Path to the file to visit + * @param {string} [parent] Parent filepath + */ + addFile(filepath: string, parent?: string): void; + + /** + * visits all files that are ancestors of the provided file + * @param {string} filepath Path to the file to visit + * @param {Function} callback Called when a node is visited + */ + visitAncestors(filepath: string, callback: (edge: string, node: Node) => any): void; + + /** + * Visits all files that are descendents of the provided file + * @param {string} filepath Path to the file to visit + * @param {Function} callback Called when a node is visited + */ + visitDescendents(filepath: string, callback: (edge: string, node: Node) => any): void; + + /** + * A generic visitor that uses an edgeCallback to find the edges to traverse + * for a node + * @param {string} filepath Path to the file to visit + * @param {Function} callback Called when a node is visited + * @param {Function} edgeCallback Called when we reach an edge + * @param {string[]} [visited] Visited edges + */ + visit(filepath: string, callback: (edge: string, node: Node) => any, edgeCallback: (errorMsg: string, node: Node) => any, visited?: string[]): void; + } + + /** + * @function {parseFile} Get the dependency tree of a single file + * @param {string} filepath Path to file which should be parsed + * @param {Object} [options] Parsing options + * @return {Graph} + */ + export function parseFile(filepath: string, options?: Options): Graph; + + /** + * @function {parseDir} Get the dependency tree of all sass files in a folder + * @param {string} dirpath Folder which should be parsed + * @param {Object} [options] Parsing options + * @return {Graph} + */ + export function parseDir(dirpath: string, options?: Options): Graph; +} + +declare module "sass-graph" { + export = SassGraph; +}