Skip to content

Commit

Permalink
perf(types): trimmed down vendor types
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed May 20, 2020
1 parent a1f947b commit 6a52be8
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 268 deletions.
9 changes: 9 additions & 0 deletions src/shims/fibers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace fibers {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class Fiber {}
}

declare module "fibers" {
const fiber: fibers.Fiber;
export = fiber;
}
72 changes: 72 additions & 0 deletions src/shims/less.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
declare namespace less {
interface File {
contents?: string;
filename?: string;
}

class AbstractFileManager {
supportsSync(filename: string, basedir: string): boolean;
}

interface FileManager extends AbstractFileManager {
supports(filename: string, basedir: string): boolean;
loadFile(filename: string, basedir: string): Promise<File>;
}

class PluginManager {
constructor(less: Less);
addFileManager(fileManager: FileManager): void;
}

interface Plugin {
install: (less: Less, pluginManager: PluginManager) => void;
}

interface SourceMapOption {
sourceMapURL?: string;
sourceMapBasepath?: string;
sourceMapRootpath?: string;
outputSourceFiles?: boolean;
sourceMapFileInline?: boolean;
}

interface Options {
sourceMap?: SourceMapOption;
filename?: string;
paths?: string[];
lint?: boolean;
plugins?: Plugin[];
compress?: boolean;
strictImports?: boolean;
insecure?: boolean;
depends?: boolean;
maxLineLen?: number;
color?: boolean;
ieCompat?: boolean;
javascriptEnabled?: boolean;
dumpLineNumbers?: "comment" | string;
rootpath?: string;
math?: "always" | "strict" | "parens-division" | "parens" | "strict-legacy" | number;
silent?: boolean;
strictUnits?: boolean;
globalVars?: { [x: string]: string };
modifyVars?: { [x: string]: string };
syncImport?: boolean;
}

interface RenderOutput {
css: string;
map: string;
imports: string[];
}

interface Less {
AbstractFileManager: typeof AbstractFileManager;
render(input: string, options?: Options): Promise<RenderOutput>;
}
}

declare module "less" {
const less: less.Less;
export = less;
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
/* eslint-disable import/no-duplicates */
declare module "postcss-modules-values" {
import { Plugin } from "postcss";

export interface ValuesOptions {
createImportedName?: (name: string, path: string) => string;
}

export default function (options?: ValuesOptions): Plugin<unknown>;
export default function (options?: {}): Plugin<{}>;
}

declare module "postcss-modules-local-by-default" {
import { Plugin } from "postcss";

export interface LocalByDefaultOptions {
mode?: "local" | "global" | "pure";
rewriteUrl?: (global: boolean, value: string) => string;
}

export default function (options?: LocalByDefaultOptions): Plugin<unknown>;
export default function (options?: LocalByDefaultOptions): Plugin<LocalByDefaultOptions>;
}

declare module "postcss-modules-extract-imports" {
import { Plugin } from "postcss";

export interface ExtractImportsOptions {
failOnWrongOrder?: boolean;
createImportedName?: (name: string, file: string) => string;
}

export default function (options?: ExtractImportsOptions): Plugin<unknown>;
export default function (options?: ExtractImportsOptions): Plugin<ExtractImportsOptions>;
}

declare module "postcss-modules-scope" {
Expand All @@ -37,8 +30,7 @@ declare module "postcss-modules-scope" {
export interface ScopeOptions {
exportGlobals?: boolean;
generateScopedName?: (name: string, file: string, css: string) => string;
generateExportEntry?: (name: string, scopedName: string, file: string, css: string) => string;
}

export default function (options?: ScopeOptions): Plugin<unknown>;
export default function (options?: ScopeOptions): Plugin<ScopeOptions>;
}
57 changes: 57 additions & 0 deletions src/shims/sass.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/// <reference types="./fibers" />

declare namespace sass {
type Data = { file: string } | { contents: string } | Error | null;

type Importer = (url: string, prev: string, done: (data: Data) => void) => Data | void;

interface Options {
fiber?: fibers.Fiber;
file?: string;
data?: string;
importer?: Importer | Importer[];
includePaths?: string[];
indentedSyntax?: boolean;
indentType?: "space" | "tab";
indentWidth?: number;
linefeed?: "cr" | "crlf" | "lf" | "lfcr";
omitSourceMapUrl?: boolean;
outFile?: string;
outputStyle?: "compressed" | "expanded";
sourceMap?: boolean | string;
sourceMapContents?: boolean;
sourceMapEmbed?: boolean;
sourceMapRoot?: string;
}

interface Exception extends Error {
message: string;
formatted: string;
line: number;
column: number;
status: number;
file: string;
}

interface Result {
css: Uint8Array;
map?: Uint8Array;
stats: { includedFiles: string[] };
}

type Callback = (exception: Exception, result: Result) => void;

interface Sass {
render: (options: Options, callback: Callback) => void;
}
}

declare module "sass" {
const sass: sass.Sass;
export = sass;
}

declare module "node-sass" {
const sass: sass.Sass;
export = sass;
}
39 changes: 39 additions & 0 deletions src/shims/stylus.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
declare namespace stylus {
interface Options {
imports?: string[];
paths?: string[];
filename?: string;
sourcemap?: {
comment?: boolean;
inline?: boolean;
sourceRoot?: string;
basePath?: string;
};
}

type Callback = (err: Error, css: string, js: string) => void;

interface Renderer {
render(callback: Callback): void;
deps(): string[];
set<T extends keyof Options>(key: T, val: Options[T]): this;
sourcemap?: {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
};
}

interface Stylus {
(code: string, options?: Options): Renderer;
}
}

declare module "stylus" {
const stylus: stylus.Stylus;
export = stylus;
}
15 changes: 0 additions & 15 deletions src/typings/fibers.d.ts

This file was deleted.

138 changes: 0 additions & 138 deletions src/typings/less.d.ts

This file was deleted.

0 comments on commit 6a52be8

Please sign in to comment.