fix: improve missing typings

This commit is contained in:
e-cloud 2016-12-03 16:01:09 +08:00
parent 822f53a17b
commit f9387518fa
2 changed files with 55 additions and 9 deletions

View File

@ -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;

View File

@ -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');