diff --git a/enhanced-resolve/enhanced-resolve-tests.ts b/enhanced-resolve/enhanced-resolve-tests.ts index d456872bfa..dfd5087be4 100644 --- a/enhanced-resolve/enhanced-resolve-tests.ts +++ b/enhanced-resolve/enhanced-resolve-tests.ts @@ -1,5 +1,5 @@ import resolve = require('enhanced-resolve'); -import { ResolveResult } from 'enhanced-resolve/lib/common-types' +import { ResolveResult, AbstractInputFileSystem } from 'enhanced-resolve/lib/common-types' import Resolver = require('enhanced-resolve/lib/Resolver') resolve('lib', 'string', function (err) { }); @@ -13,15 +13,12 @@ resolve(context, 'path', 'string', function () { }); let resolver: Resolver resolver = resolve.ResolverFactory.createResolver({ extensions: ['.js'], - fileSystem: {} as resolve.CachedInputFileSystem + fileSystem: {} as AbstractInputFileSystem }); const nfs = new resolve.NodeJsInputFileSystem(); -const snfs = new resolve.SyncNodeJsInputFileSystem(); - const cfs = new resolve.CachedInputFileSystem(nfs, 4); -const cfs2 = new resolve.CachedInputFileSystem(snfs, 4); let result: ResolveResult diff --git a/enhanced-resolve/index.d.ts b/enhanced-resolve/index.d.ts index 06ccd64604..d773f52b16 100644 --- a/enhanced-resolve/index.d.ts +++ b/enhanced-resolve/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for enhanced-resolve v2.3.0 +// Type definitions for enhanced-resolve v3.0.0 // Project: http://github.com/webpack/enhanced-resolve.git // Definitions by: e-cloud // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -10,14 +10,13 @@ import fs = require('fs'); import { ResolveResult, LoggingCallbackWrapper, - CommonFileSystemMethod, ResolverRequest, ResolveContext, AbstractInputFileSystem } from './lib/common-types' import { Dictionary } from './lib/concord' import Resolver = require('./lib/Resolver'); -import Tapable = require('tapable') +import Tapable = require('tapable'); declare namespace Resolve { function sync(path: string, request: string): ResolveResult; @@ -66,6 +65,7 @@ declare namespace Resolve { resolveToContext?: boolean; symlinks?: string[] | boolean; unsafeCache?: boolean | Dictionary; + useSyncFileSystemCalls?: boolean; } interface AliasItem { alias: string; @@ -76,12 +76,9 @@ declare namespace Resolve { } class NodeJsInputFileSystem { - isSync(): boolean; - - readdir(path: string, callback: (err: Error, files: string[]) => void): void; - stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: fs.Stats) => any): void; + readdir(path: string, callback: (err: Error, files: string[]) => void): void readFile( filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void @@ -100,32 +97,25 @@ declare namespace Resolve { readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; - } - class SyncNodeJsInputFileSystem { - isSync(): boolean; + statSync(path: string | Buffer): fs.Stats; - stat: CommonFileSystemMethod; - readdir: CommonFileSystemMethod; + readdirSync(path: string): string[]; - readFile( - filename: string, encoding: string, - callback: (err: NodeJS.ErrnoException, data: string) => void - ): void; - readFile( + readFileSync(filename: string, encoding: string): string; + readFileSync( filename: string, options: { encoding: string; flag?: string; - }, callback: (err: NodeJS.ErrnoException, data: string) => void - ): void; - readFile( - filename: string, options: { + } + ): string; + readFileSync( + filename: string, options?: { flag?: string; - }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void - ): void; - readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + } + ): Buffer; - readlink: CommonFileSystemMethod; + readlinkSync(path: string | Buffer): string; } class CachedInputFileSystem { @@ -133,19 +123,27 @@ declare namespace Resolve { constructor(fileSystem: AbstractInputFileSystem, duration: number); - isSync(): boolean; + stat?(path: string, callback: (err: NodeJS.ErrnoException, stats: fs.Stats) => void): void; + + readdir?(path: string, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; + + readFile?(path: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + + readJson?(path: string, callback: (err: NodeJS.ErrnoException, data: any) => void): void; + + readlink?(path: string, callback: (err: NodeJS.ErrnoException, linkString: string) => void): void; + + statSync?(path: string | Buffer): fs.Stats; + + readdirSync?(path: string): string[]; + + readFileSync?(filename: string, options?: { flag?: string; }): Buffer; + + readlinkSync?(path: string | Buffer): string; + + readJsonSync?(path: string): any; purge(what?: string | string[]): void; - - readdir(path: string, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; - - readFile(path: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; - - readJson(path: string, callback: (err: NodeJS.ErrnoException, data: any) => void): void; - - readlink(path: string, callback: (err: NodeJS.ErrnoException, linkString: string) => void): void; - - stat(path: string, callback: (err: NodeJS.ErrnoException, stats: fs.Stats) => void): void; } } diff --git a/enhanced-resolve/lib/Storage.d.ts b/enhanced-resolve/lib/Storage.d.ts index cc4790d200..b9512825fa 100644 --- a/enhanced-resolve/lib/Storage.d.ts +++ b/enhanced-resolve/lib/Storage.d.ts @@ -1,26 +1,29 @@ /// -import { CommonFileSystemMethod } from './common-types'; -import { Dictionary } from './concord'; - +import { CommonFileSystemMethod } from './common-types' +import { Dictionary } from './concord' declare class Storage { - duration: number; - running: Dictionary; - data: Dictionary; - levels: string[][]; count: number; + data: Dictionary; + duration: number; interval: NodeJS.Timer | null; + levels: string[][]; needTickCheck: boolean; nextTick: number | null; passive: boolean; + running: Dictionary; constructor(duration: number); ensureTick(): void; - finished(name: string): void; + finished(name: string, err: NodeJS.ErrnoException | null, result: any): void; + + finishedSync(name: string, err: NodeJS.ErrnoException | null, result?: any): void; provide(name: string, provider: CommonFileSystemMethod, callback: (...args: any[]) => any): any; + provideSync(name: string, provider: (name: string) => any): any; + tick(): true | undefined; checkTicks(): void; diff --git a/enhanced-resolve/lib/SyncAsyncFileSystemDecorator.d.ts b/enhanced-resolve/lib/SyncAsyncFileSystemDecorator.d.ts new file mode 100644 index 0000000000..f7956dcead --- /dev/null +++ b/enhanced-resolve/lib/SyncAsyncFileSystemDecorator.d.ts @@ -0,0 +1,21 @@ +/// +import fs = require('fs'); +import { AbstractInputFileSystem } from './common-types'; + +declare class SyncAsyncFileSystemDecorator { + fs: AbstractInputFileSystem; + + readdir?(path: string, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void; + + readFile?(filename: string, callback: (err: NodeJS.ErrnoException | null, data?: Buffer) => void): void; + + readJson?(path: string, callback: (err: NodeJS.ErrnoException | null, data?: any) => void): void; + + readlink?(path: string, callback: (err: NodeJS.ErrnoException | null, linkString?: string) => void): void; + + stat?(path: string, callback: (err: NodeJS.ErrnoException | null, stats?: fs.Stats) => void): void; + + constructor(fs: AbstractInputFileSystem); +} + +export = SyncAsyncFileSystemDecorator; diff --git a/enhanced-resolve/lib/common-types.d.ts b/enhanced-resolve/lib/common-types.d.ts index ff764ad67d..6607dee64f 100644 --- a/enhanced-resolve/lib/common-types.d.ts +++ b/enhanced-resolve/lib/common-types.d.ts @@ -39,6 +39,9 @@ export interface ResolverRequest { query?: string; relativePath?: string; request: string; + __innerRequest?: string; + __innerRequest_request?: string; + __innerRequest_relativePath?: string; } export interface LoggingCallbackTools { @@ -58,13 +61,29 @@ export interface ErrorCallback { } export interface AbstractInputFileSystem { - isSync(): boolean; purge?(what?: string | string[]): void; readdir(path: string, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; + readdirSync?(path: string): string[]; + readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + readFile( + filename: string, options: { + encoding: string; + flag?: string; + }, callback: (err: NodeJS.ErrnoException, data: string) => void + ): void; + readFile( + filename: string, options: { + flag?: string; + }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void + ): void; readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + readFileSync?(filename: string): Buffer; readJson?(path: string, callback: (err: NodeJS.ErrnoException, data: any) => void): void; + readJsonSync?(path: string): any; readlink(path: string, callback: (err: NodeJS.ErrnoException, linkString: string) => void): void; + readlinkSync?(path: string): string; stat(path: string, callback: (err: NodeJS.ErrnoException, stats: fs.Stats) => void): void; + statSync?(path: string): fs.Stats; } export interface CommonFileSystemMethod {