From f9387518fad9906cf2ec0c0ff67408317a4aca0e Mon Sep 17 00:00:00 2001 From: e-cloud Date: Sat, 3 Dec 2016 16:01:09 +0800 Subject: [PATCH] fix: improve missing typings --- loader-runner/index.d.ts | 49 ++++++++++++++++++++++++---- loader-runner/loader-runner-tests.ts | 15 +++++++-- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/loader-runner/index.d.ts b/loader-runner/index.d.ts index f0b34ec600..826fcdcb2a 100644 --- a/loader-runner/index.d.ts +++ b/loader-runner/index.d.ts @@ -10,26 +10,63 @@ export interface Loader { query: string; request: string; options: any; - normal: any; - pitch: any; + normal: null | ((request: string) => string); + pitch: null | ((request: string) => string); raw: string; data: any; pitchExecuted: boolean; normalExecuted: boolean; } -export function getContext(resource: string): string; - export interface RunLoaderOption { resource: string; loaders: any[]; context: any; - readResource: (filename: string, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void) => void; + readResource: ( + filename: string, + callback: (err: NodeJS.ErrnoException | null, data: Buffer | null) => void + ) => void; } +export interface RunLoaderResult { + result?: (Buffer | null)[]; + resourceBuffer?: Buffer | null; + cacheable: boolean; + fileDependencies: string[]; + contextDependencies: string[]; +} + +export interface ExtendedLoaderContext { + context: string | null; + loaderIndex: number; + loaders: Loader[]; + resourcePath: string | undefined; + resourceQuery: string | undefined; + async: (() => (() => void) | undefined) | null; + callback: (() => void) | null; + cacheable: (flag: boolean) => void; + dependency: (file: string) => void; + addDependency: (file: string) => void; + addContextDependency: (context: string) => void; + getDependencies: () => string[]; + getContextDependencies: () => string[]; + clearDependencies: () => void; + resource: string; + request: string; + remainingRequest: string; + currentRequest: string; + previousRequest: string; + query: { + [key: string]: any; + } | string; + data: any; +} + +export function getContext(resource: string): string; + export function runLoaders( options: RunLoaderOption, - callback: (err: NodeJS.ErrnoException | null, result: any) => any + callback: (err: NodeJS.ErrnoException | null, result: RunLoaderResult) => any ): void; diff --git a/loader-runner/loader-runner-tests.ts b/loader-runner/loader-runner-tests.ts index 38661b60ec..3157b44aa2 100644 --- a/loader-runner/loader-runner-tests.ts +++ b/loader-runner/loader-runner-tests.ts @@ -1,10 +1,19 @@ -import { runLoaders, getContext, Loader, RunLoaderOption } from 'loader-runner'; +import { runLoaders, getContext } from 'loader-runner'; -const option = {} as RunLoaderOption; +const option = { + resource: 'test.js', + loaders: [{ + request: 'test.js' + }], + context: './lib/', + readResource: function () { + } +}; runLoaders(option, function (err, result) { - if(err) + if (err) { console.log(err, result); + } }); getContext('sdlfkjaldfjiojsdf');