From 9b367091bda0ed1302f8684c5911fa2777e0adf5 Mon Sep 17 00:00:00 2001 From: e-cloud Date: Fri, 2 Dec 2016 11:36:32 +0800 Subject: [PATCH 1/3] fix: add files field in tsconfig.json for expected publishment --- enhanced-resolve/tsconfig.json | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/enhanced-resolve/tsconfig.json b/enhanced-resolve/tsconfig.json index 96a70f3bf2..ffa80fe4b2 100644 --- a/enhanced-resolve/tsconfig.json +++ b/enhanced-resolve/tsconfig.json @@ -12,9 +12,41 @@ "noEmit": true, "forceConsistentCasingInFileNames": true }, - "include": [ + "files": [ "index.d.ts", "enhanced-resolve-tests.ts", - "lib/*.ts" + "./lib/AliasFieldPlugin.d.ts", + "./lib/AliasPlugin.d.ts", + "./lib/AppendPlugin.d.ts", + "./lib/CloneBasenamePlugin.d.ts", + "./lib/common-types.d.ts", + "./lib/concord.d.ts", + "./lib/ConcordExtensionsPlugin.d.ts", + "./lib/ConcordMainPlugin.d.ts", + "./lib/ConcordModulesPlugin.d.ts", + "./lib/DescriptionFilePlugin.d.ts", + "./lib/DescriptionFileUtils.d.ts", + "./lib/DirectoryExistsPlugin.d.ts", + "./lib/FileExistsPlugin.d.ts", + "./lib/FileKindPlugin.d.ts", + "./lib/getPaths.d.ts", + "./lib/globToRegExp.d.ts", + "./lib/JoinRequestPlugin.d.ts", + "./lib/lib-tests.ts", + "./lib/LogInfoPlugin.d.ts", + "./lib/MainFieldPlugin.d.ts", + "./lib/ModuleAppendPlugin.d.ts", + "./lib/ModuleKindPlugin.d.ts", + "./lib/ModulesInHierachicDirectoriesPlugin.d.ts", + "./lib/ModulesInRootPlugin.d.ts", + "./lib/NextPlugin.d.ts", + "./lib/ParsePlugin.d.ts", + "./lib/Resolver.d.ts", + "./lib/ResultPlugin.d.ts", + "./lib/Storage.d.ts", + "./lib/SymlinkPlugin.d.ts", + "./lib/TryNextPlugin.d.ts", + "./lib/UnsafeCachePlugin.d.ts", + "./lib/UseFilePlugin.d.ts" ] } From 9e6214dde6cd92a31c7f96f5a18dc056542cdf7e Mon Sep 17 00:00:00 2001 From: e-cloud Date: Sun, 4 Dec 2016 17:43:12 +0800 Subject: [PATCH 2/3] fix: improve most missing typings --- enhanced-resolve/enhanced-resolve-tests.ts | 7 +- enhanced-resolve/index.d.ts | 138 +++++++++++------- enhanced-resolve/lib/AliasFieldPlugin.d.ts | 2 +- enhanced-resolve/lib/AliasPlugin.d.ts | 10 +- enhanced-resolve/lib/AppendPlugin.d.ts | 2 +- .../lib/ConcordExtensionsPlugin.d.ts | 6 +- enhanced-resolve/lib/ConcordMainPlugin.d.ts | 6 +- .../lib/ConcordModulesPlugin.d.ts | 6 +- .../lib/DescriptionFilePlugin.d.ts | 4 +- .../lib/DescriptionFileUtils.d.ts | 22 ++- .../ModulesInHierachicDirectoriesPlugin.d.ts | 2 +- enhanced-resolve/lib/ModulesInRootPlugin.d.ts | 2 +- enhanced-resolve/lib/Resolver.d.ts | 20 ++- enhanced-resolve/lib/Storage.d.ts | 9 +- enhanced-resolve/lib/UnsafeCachePlugin.d.ts | 13 +- enhanced-resolve/lib/common-types.d.ts | 59 ++++---- enhanced-resolve/lib/concord.d.ts | 54 ++++--- enhanced-resolve/lib/lib-tests.ts | 12 +- 18 files changed, 228 insertions(+), 146 deletions(-) diff --git a/enhanced-resolve/enhanced-resolve-tests.ts b/enhanced-resolve/enhanced-resolve-tests.ts index 6588bb125b..d456872bfa 100644 --- a/enhanced-resolve/enhanced-resolve-tests.ts +++ b/enhanced-resolve/enhanced-resolve-tests.ts @@ -1,12 +1,11 @@ import resolve = require('enhanced-resolve'); -import { Context } from 'enhanced-resolve/lib/concord'; import { ResolveResult } from 'enhanced-resolve/lib/common-types' import Resolver = require('enhanced-resolve/lib/Resolver') resolve('lib', 'string', function (err) { }); -let context: Context = { - referrer: 'hi' +let context = { + issuer: 'hi' }; resolve(context, 'path', 'string', function () { }); @@ -14,7 +13,7 @@ resolve(context, 'path', 'string', function () { }); let resolver: Resolver resolver = resolve.ResolverFactory.createResolver({ extensions: ['.js'], - fileSystem: {} + fileSystem: {} as resolve.CachedInputFileSystem }); const nfs = new resolve.NodeJsInputFileSystem(); diff --git a/enhanced-resolve/index.d.ts b/enhanced-resolve/index.d.ts index 142e644bd1..06ccd64604 100644 --- a/enhanced-resolve/index.d.ts +++ b/enhanced-resolve/index.d.ts @@ -10,79 +10,94 @@ import fs = require('fs'); import { ResolveResult, LoggingCallbackWrapper, - ErrorCallback, CommonFileSystemMethod, - BaseFileSystem, - ResolverRequest -} from './lib/common-types'; -import { Context } from './lib/concord'; + ResolverRequest, + ResolveContext, + AbstractInputFileSystem +} from './lib/common-types' +import { Dictionary } from './lib/concord' import Resolver = require('./lib/Resolver'); +import Tapable = require('tapable') declare namespace Resolve { function sync(path: string, request: string): ResolveResult; - function sync(context: Context, path: string, request: string): ResolveResult; + function sync(context: ResolveContext, path: string, request: string): ResolveResult; function context(path: string, request: string, callback: LoggingCallbackWrapper): void; - function context(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void; + function context(context: ResolveContext, path: string, request: string, callback: LoggingCallbackWrapper): void; namespace context { function sync(path: string, request: string): ResolveResult; - function sync(context: Context, path: string, request: string): ResolveResult; + function sync(context: ResolveContext, path: string, request: string): ResolveResult; } function loader(path: string, request: string, callback: LoggingCallbackWrapper): void; - function loader(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void; + function loader(context: ResolveContext, path: string, request: string, callback: LoggingCallbackWrapper): void; namespace context { function sync(path: string, request: string): ResolveResult; - function sync(context: Context, path: string, request: string): ResolveResult; + function sync(context: ResolveContext, path: string, request: string): ResolveResult; } function create(path: string, request: string, callback: LoggingCallbackWrapper): void; - function create(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void; + function create(context: ResolveContext, path: string, request: string, callback: LoggingCallbackWrapper): void; export namespace create { function sync(path: string, request: string): ResolveResult; - function sync(context: Context, path: string, request: string): ResolveResult; + function sync(context: ResolveContext, path: string, request: string): ResolveResult; } export namespace ResolverFactory { interface ResolverOption { - modules?: string[]; - descriptionFiles?: string[]; - plugins?: any[]; - mainFields?: string[]; + alias?: AliasItem[] | Dictionary; aliasFields?: string[]; - mainFiles?: string[]; - extensions: string[]; - enforceExtension?: boolean; - moduleExtensions?: string[]; - enforceModuleExtension?: boolean; - alias?: AliasItem[] | {}; - symlinks?: string[] | boolean; - resolveToContext?: boolean; - unsafeCache?: boolean | {}; cachePredicate?: (val: ResolverRequest) => boolean; - fileSystem: any; + descriptionFiles?: string[]; + enforceExtension?: boolean; + enforceModuleExtension?: boolean; + extensions: string[]; + fileSystem: AbstractInputFileSystem; + mainFields?: string[]; + mainFiles?: string[]; + moduleExtensions?: string[]; + modules?: string[]; + plugins?: Tapable.Plugin[]; resolver?: Resolver; + resolveToContext?: boolean; + symlinks?: string[] | boolean; + unsafeCache?: boolean | Dictionary; } interface AliasItem { - name: string; alias: string; + name: string; onlyModule: boolean; } function createResolver(options: ResolverOption): Resolver; } class NodeJsInputFileSystem { - readdir(path: string, callback: (err: Error, files: string[]) => void): void; - isSync(): boolean; + readdir(path: string, callback: (err: Error, files: string[]) => void): void; + stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: fs.Stats) => any): void; - readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + 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; readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; } @@ -92,43 +107,54 @@ declare namespace Resolve { stat: CommonFileSystemMethod; readdir: CommonFileSystemMethod; - readFile(path: string, encoding?: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void; - readFile(path: string, callback?: (err: NodeJS.ErrnoException, result: Buffer) => void): void; + + 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; + readlink: CommonFileSystemMethod; } class CachedInputFileSystem { - fileSystem: BaseFileSystem; - _statStorage: Storage; - _readdirStorage: Storage; - _readFileStorage: Storage; - _readJsonStorage: Storage; - _readlinkStorage: Storage; - _stat: CommonFileSystemMethod; - _readdir: CommonFileSystemMethod; - _readFile: CommonFileSystemMethod; - _readJson: CommonFileSystemMethod; - _readlink: CommonFileSystemMethod; + fileSystem: AbstractInputFileSystem; - constructor(fileSystem: BaseFileSystem, duration: number); + constructor(fileSystem: AbstractInputFileSystem, duration: number); isSync(): boolean; - stat(path: string, callback: ErrorCallback): void; - - readdir(path: string, callback: ErrorCallback): void; - - readFile(path: string, callback: ErrorCallback): void; - - readJson(path: string, callback: ErrorCallback): void; - - readlink(path: string, callback: ErrorCallback): void; - 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; } } declare function Resolve(path: string, request: string, callback: LoggingCallbackWrapper): void; -declare function Resolve(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): void; +declare function Resolve( + context: ResolveContext, + path: string, + request: string, + callback: LoggingCallbackWrapper +): void; export = Resolve; diff --git a/enhanced-resolve/lib/AliasFieldPlugin.d.ts b/enhanced-resolve/lib/AliasFieldPlugin.d.ts index d49ba745b8..14ff6c0777 100644 --- a/enhanced-resolve/lib/AliasFieldPlugin.d.ts +++ b/enhanced-resolve/lib/AliasFieldPlugin.d.ts @@ -1,7 +1,7 @@ import Resolver = require('./Resolver'); declare class AliasFieldPlugin { - source: string; field: string; + source: string; target: string; constructor(source: string, field: string, target: string); diff --git a/enhanced-resolve/lib/AliasPlugin.d.ts b/enhanced-resolve/lib/AliasPlugin.d.ts index 4d9635f1c5..982760f16e 100644 --- a/enhanced-resolve/lib/AliasPlugin.d.ts +++ b/enhanced-resolve/lib/AliasPlugin.d.ts @@ -1,13 +1,13 @@ import Resolver = require('./Resolver'); -import Resolve = require('../'); +import Resolve = require('enhanced-resolve'); declare class AliasPlugin { - source: string; - options: Resolve.ResolverFactory.AliasItem; - target: string; - name: string; alias: string; + name: string; onlyModule: boolean; + options: Resolve.ResolverFactory.AliasItem; + source: string; + target: string; constructor(source: string, options: Resolve.ResolverFactory.AliasItem, target: string); diff --git a/enhanced-resolve/lib/AppendPlugin.d.ts b/enhanced-resolve/lib/AppendPlugin.d.ts index 7a5f7e1a62..eb5a8a486d 100644 --- a/enhanced-resolve/lib/AppendPlugin.d.ts +++ b/enhanced-resolve/lib/AppendPlugin.d.ts @@ -1,7 +1,7 @@ import Resolver = require('./Resolver'); declare class AppendPlugin { - source: string; appending: string; + source: string; target: string; constructor(source: string, appending: string, target: string); diff --git a/enhanced-resolve/lib/ConcordExtensionsPlugin.d.ts b/enhanced-resolve/lib/ConcordExtensionsPlugin.d.ts index 89d0880350..27309410a2 100644 --- a/enhanced-resolve/lib/ConcordExtensionsPlugin.d.ts +++ b/enhanced-resolve/lib/ConcordExtensionsPlugin.d.ts @@ -1,10 +1,12 @@ import Resolver = require('./Resolver'); +import { Dictionary } from './concord'; + declare class ConcordExtensionsPlugin { + options: Dictionary; source: string; - options: {}; target: string; - constructor(source: string, options: {}, target: string); + constructor(source: string, options: Dictionary, target: string); apply(resolver: Resolver): void; } diff --git a/enhanced-resolve/lib/ConcordMainPlugin.d.ts b/enhanced-resolve/lib/ConcordMainPlugin.d.ts index 9d2fdf3d44..d413eb0d7a 100644 --- a/enhanced-resolve/lib/ConcordMainPlugin.d.ts +++ b/enhanced-resolve/lib/ConcordMainPlugin.d.ts @@ -1,10 +1,12 @@ import Resolver = require('./Resolver'); +import { Dictionary } from './concord'; + declare class ConcordMainPlugin { + options: Dictionary; source: string; - options: {}; target: string; - constructor(source: string, options: {}, target: string); + constructor(source: string, options: Dictionary, target: string); apply(resolver: Resolver): void; } diff --git a/enhanced-resolve/lib/ConcordModulesPlugin.d.ts b/enhanced-resolve/lib/ConcordModulesPlugin.d.ts index 3afbd32a9c..094ed343b9 100644 --- a/enhanced-resolve/lib/ConcordModulesPlugin.d.ts +++ b/enhanced-resolve/lib/ConcordModulesPlugin.d.ts @@ -1,10 +1,12 @@ import Resolver = require('./Resolver'); +import { Dictionary } from './concord'; + declare class ConcordModulesPlugin { + options: Dictionary; source: string; - options: {}; target: string; - constructor(source: string, options: {}, target: string); + constructor(source: string, options: Dictionary, target: string); apply(resolver: Resolver): void; } diff --git a/enhanced-resolve/lib/DescriptionFilePlugin.d.ts b/enhanced-resolve/lib/DescriptionFilePlugin.d.ts index f9f560de46..d753ae3ef6 100644 --- a/enhanced-resolve/lib/DescriptionFilePlugin.d.ts +++ b/enhanced-resolve/lib/DescriptionFilePlugin.d.ts @@ -1,11 +1,13 @@ import Resolver = require('./Resolver'); + declare class DescriptionFilePlugin { + filenames: string[]; source: string; target: string; - filenames: string[]; constructor(source: string, filenames: string[] | string, target: string); apply(resolver: Resolver): void; } + export = DescriptionFilePlugin; diff --git a/enhanced-resolve/lib/DescriptionFileUtils.d.ts b/enhanced-resolve/lib/DescriptionFileUtils.d.ts index db7cd77723..a630e4a03b 100644 --- a/enhanced-resolve/lib/DescriptionFileUtils.d.ts +++ b/enhanced-resolve/lib/DescriptionFileUtils.d.ts @@ -1,8 +1,24 @@ import Resolver = require('./Resolver'); +import { Dictionary, Concord } from './concord'; + +export interface DescriptionFileData { + concord?: Concord; + browser?: Dictionary; +} + +export interface LoadDescriptionFileResult { + content: DescriptionFileData + directory: string + path: string +} + declare function loadDescriptionFile( - resolver: Resolver, directory: string, filenames: string[], - callback: (...args: any[]) => any + resolver: Resolver, + directory: string, + filenames: string[], + callback: (err?: Error | null, result?: LoadDescriptionFileResult) => any ): void; -declare function getField(content: any, field: string): any; + +declare function getField(content: Dictionary | null, field: string): any; declare function cdUp(directory: string): string | null; export { loadDescriptionFile, getField, cdUp }; diff --git a/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.d.ts b/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.d.ts index d744870022..449ef7cf31 100644 --- a/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.d.ts +++ b/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.d.ts @@ -1,8 +1,8 @@ import Resolver = require('./Resolver'); declare class ModulesInHierachicDirectoriesPlugin { + directories: string[]; source: string; target: string; - directories: string[]; constructor(source: string, directories: string[], target: string); diff --git a/enhanced-resolve/lib/ModulesInRootPlugin.d.ts b/enhanced-resolve/lib/ModulesInRootPlugin.d.ts index 87654ce919..fe171dcb0b 100644 --- a/enhanced-resolve/lib/ModulesInRootPlugin.d.ts +++ b/enhanced-resolve/lib/ModulesInRootPlugin.d.ts @@ -1,7 +1,7 @@ import Resolver = require('./Resolver'); declare class ModulesInRootPlugin { - source: string; path: string; + source: string; target: string; constructor(source: string, path: string, target: string); diff --git a/enhanced-resolve/lib/Resolver.d.ts b/enhanced-resolve/lib/Resolver.d.ts index 4d2f3ee477..20fc1c0914 100644 --- a/enhanced-resolve/lib/Resolver.d.ts +++ b/enhanced-resolve/lib/Resolver.d.ts @@ -1,15 +1,22 @@ /// import Tapable = require('tapable'); -import { ResolveParseResult, ResolverRequest, LoggingCallbackWrapper, BaseFileSystem } from './common-types'; -import { Context } from './concord'; +import { + ResolveParseResult, + ResolveResult, + ResolverRequest, + LoggingCallbackWrapper, + AbstractInputFileSystem, + ResolveContext +} from './common-types'; + declare class Resolver extends Tapable { - fileSystem: BaseFileSystem; + fileSystem: AbstractInputFileSystem; - constructor(fileSystem: BaseFileSystem); + constructor(fileSystem: AbstractInputFileSystem); - resolveSync(context: Context, path: string, request: string): null; + resolveSync(context: ResolveContext, path: string, request: string): ResolveResult; - resolve(context: Context, path: string, request: string, callback: LoggingCallbackWrapper): any; + resolve(context: ResolveContext, path: string, request: string, callback: LoggingCallbackWrapper): any; doResolve(type: string, request: ResolverRequest, message: string | null, callback: LoggingCallbackWrapper): any; @@ -23,4 +30,5 @@ declare class Resolver extends Tapable { normalize(path: string): string; } + export = Resolver; diff --git a/enhanced-resolve/lib/Storage.d.ts b/enhanced-resolve/lib/Storage.d.ts index 4260b42ee7..cc4790d200 100644 --- a/enhanced-resolve/lib/Storage.d.ts +++ b/enhanced-resolve/lib/Storage.d.ts @@ -1,14 +1,11 @@ /// import { CommonFileSystemMethod } from './common-types'; +import { Dictionary } from './concord'; declare class Storage { duration: number; - running: { - [name: string]: ((...args: any[]) => any)[] - }; - data: { - [name: string]: any[] - }; + running: Dictionary; + data: Dictionary; levels: string[][]; count: number; interval: NodeJS.Timer | null; diff --git a/enhanced-resolve/lib/UnsafeCachePlugin.d.ts b/enhanced-resolve/lib/UnsafeCachePlugin.d.ts index 8b8c8f5f09..9ce470e8f8 100644 --- a/enhanced-resolve/lib/UnsafeCachePlugin.d.ts +++ b/enhanced-resolve/lib/UnsafeCachePlugin.d.ts @@ -1,12 +1,19 @@ import Resolver = require('./Resolver'); import { ResolverRequest } from './common-types'; +import { Dictionary } from './concord'; + declare class UnsafeCachePlugin { source: string; - filterPredicate: (str: ResolverRequest) => boolean; - cache: {}; + filterPredicate: (request: ResolverRequest) => boolean; + cache: Dictionary; target: string; - constructor(source: string, filterPredicate: (str: ResolverRequest) => boolean, cache: {}, target: string); + constructor( + source: string, + filterPredicate: (request: ResolverRequest) => boolean, + cache: Dictionary, + target: string + ); apply(resolver: Resolver): void; } diff --git a/enhanced-resolve/lib/common-types.d.ts b/enhanced-resolve/lib/common-types.d.ts index 30c39d1210..ff764ad67d 100644 --- a/enhanced-resolve/lib/common-types.d.ts +++ b/enhanced-resolve/lib/common-types.d.ts @@ -1,5 +1,10 @@ -import { Context } from './concord'; +/// +import { DescriptionFileData } from './DescriptionFileUtils'; +import fs = require('fs'); +/** + * Created by cloud on 16-11-4. + */ export interface ResolveError extends Error { details: string; missing: string[]; @@ -7,11 +12,15 @@ export interface ResolveError extends Error { } export interface ResolveParseResult { - request: string; - query: string; - module: boolean; directory: boolean; file: boolean; + module: boolean; + query: string; + request: string; +} + +export interface ResolveContext { + issuer?: string; } export interface ResolveResult { @@ -20,21 +29,21 @@ export interface ResolveResult { } export interface ResolverRequest { - request: string; - relativePath?: string; - descriptionFileData?: any; - descriptionFileRoot?: string; + context: ResolveContext; + descriptionFileData?: DescriptionFileData; descriptionFilePath?: string; - context: Context; - path: string; - query?: string; + descriptionFileRoot?: string; directory?: boolean; module?: boolean; + path: string; + query?: string; + relativePath?: string; + request: string; } export interface LoggingCallbackTools { log?(msg: string): void; - stack?: string[]; + stack?: string[] | undefined; missing?: string[] | { push: (item: string) => void; }; @@ -44,20 +53,20 @@ export interface LoggingCallbackWrapper extends LoggingCallbackTools { (err?: Error | null, ...args: any[]): any; } -export interface ErrorCallback { - (err: Error | null, ...args: any[]): any; +export interface ErrorCallback { + (err: T | null, ...args: any[]): any; +} + +export interface AbstractInputFileSystem { + isSync(): boolean; + purge?(what?: string | string[]): void; + readdir(path: string, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void; + readFile(filename: 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; } export interface CommonFileSystemMethod { - (name: string, callback: (err: Error | null, ...args: any[]) => void): void; -} - -export interface BaseFileSystem { - stat: CommonFileSystemMethod; - readdir?: CommonFileSystemMethod; - readFile?(path: string, encoding: string, callback: ErrorCallback): void; - readFile?(path: string, callback: ErrorCallback): void; - readJson?: CommonFileSystemMethod; - readlink?: CommonFileSystemMethod; - isSync: () => boolean; + (name: string, callback: (err: NodeJS.ErrnoException | null, ...args: any[]) => void): void; } diff --git a/enhanced-resolve/lib/concord.d.ts b/enhanced-resolve/lib/concord.d.ts index d11f1047df..e0c9efe8ed 100644 --- a/enhanced-resolve/lib/concord.d.ts +++ b/enhanced-resolve/lib/concord.d.ts @@ -1,38 +1,50 @@ +export interface Dictionary { + [key: string]: T; +} + +export interface Concord { + '[server] main': string; + extensions: string[]; + main: string; + modules: Dictionary; + types: Dictionary; +} + export interface Type { type: string | null | undefined; features: string[]; } -export interface Context { - supportedResourceTypes?: string[]; +export interface ConcordContext { environments?: string[]; - referrer: string; + referrer?: string; + supportedResourceTypes?: string[]; } declare function parseType(type: string): Type; declare function isTypeMatched(baseType: string | Type, testedType: string | Type): boolean; -declare function isResourceTypeSupported(context: Context, type: string): boolean | undefined; -declare function isEnvironment(context: Context, env: string | Type): boolean | undefined; +declare function isResourceTypeSupported(context: ConcordContext, type: string): boolean; +declare function isEnvironment(context: ConcordContext, env: string | Type): boolean; declare function isGlobMatched(glob: string, relativePath: string): boolean; -declare function isConditionMatched(context: Context, condition: string): boolean; -declare function isKeyMatched(context: Context, key: string): string | boolean; -declare function getField(context: Context, configuration: any, field: string): undefined; -declare function getMain(context: Context, configuration: any): undefined; -declare function getExtensions(context: Context, configuration: any): undefined; -declare function matchModule(context: Context, configuration: any, request: string): any; -declare function matchType(context: Context, configuration: any, relativePath: string): undefined; +declare function isConditionMatched(context: ConcordContext, condition: string): boolean; +declare function isKeyMatched(context: ConcordContext, key: string): string | boolean; +declare function getField(context: ConcordContext, configuration: Concord, field: string): any; +declare function getMain(context: ConcordContext, configuration: Concord): any; +declare function getExtensions(context: ConcordContext, configuration: Concord): any; +declare function matchModule(context: ConcordContext, configuration: Concord, request: string): any; +declare function matchType(context: ConcordContext, configuration: Concord, relativePath: string): string | undefined; export { - parseType, - isTypeMatched, - isResourceTypeSupported, - isEnvironment, - isGlobMatched, - isConditionMatched, - isKeyMatched, + getExtensions, getField, getMain, - getExtensions, + isConditionMatched, + isEnvironment, + isGlobMatched, + isKeyMatched, + isResourceTypeSupported, + isTypeMatched, matchModule, - matchType + matchType, + parseType }; diff --git a/enhanced-resolve/lib/lib-tests.ts b/enhanced-resolve/lib/lib-tests.ts index a41e5d9aeb..b5b0d9a266 100644 --- a/enhanced-resolve/lib/lib-tests.ts +++ b/enhanced-resolve/lib/lib-tests.ts @@ -26,6 +26,10 @@ import getPaths, { basename } from 'enhanced-resolve/lib/getPaths'; import { globToRegExp } from 'enhanced-resolve/lib/globToRegExp'; +import Storage from 'enhanced-resolve/lib/Storage'; + +import { AbstractInputFileSystem } from 'enhanced-resolve/lib/common-types'; + import JoinRequestPlugin = require('enhanced-resolve/lib/JoinRequestPlugin'); import LogInfoPlugin = require('enhanced-resolve/lib/LogInfoPlugin'); @@ -48,8 +52,6 @@ import Resolver = require('enhanced-resolve/lib/Resolver'); import ResultPlugin = require('enhanced-resolve/lib/ResultPlugin'); -import Storage from 'enhanced-resolve/lib/Storage' - import SymlinkPlugin = require('enhanced-resolve/lib/SymlinkPlugin'); import TryNextPlugin = require('enhanced-resolve/lib/TryNextPlugin'); @@ -60,8 +62,6 @@ import UseFilePlugin = require('enhanced-resolve/lib/UseFilePlugin'); import resolve = require('../'); -import { BaseFileSystem } from 'enhanced-resolve/lib/common-types' - const aplugin = new AliasFieldPlugin('a', 'b', 'c'); const aplugin2 = new AliasPlugin('a', { @@ -95,7 +95,7 @@ DescriptionFileUtils.cdUp('./lib'); DescriptionFileUtils.getField({}, 'hi'); DescriptionFileUtils.loadDescriptionFile(resolve.ResolverFactory.createResolver({ extensions: [''], - fileSystem: {} + fileSystem: {} as AbstractInputFileSystem }), './lib', ['file'], function () { }); const dplugin1 = new DirectoryExistsPlugin('string', 'string'); @@ -131,7 +131,7 @@ const nplugin = new NextPlugin('string', 'ap'); const pplugin = new ParsePlugin('string', 'ap'); -const resolver = new Resolver({} as BaseFileSystem); +const resolver = new Resolver({} as AbstractInputFileSystem); const rplugin = new ResultPlugin('string'); From cfd7b3fa220368b215a58a2b428a3b46a7d2a353 Mon Sep 17 00:00:00 2001 From: e-cloud Date: Thu, 8 Dec 2016 21:03:41 +0800 Subject: [PATCH 3/3] feat: upgrade to v3.0.0 --- enhanced-resolve/enhanced-resolve-tests.ts | 7 +- enhanced-resolve/index.d.ts | 70 +++++++++---------- enhanced-resolve/lib/Storage.d.ts | 19 ++--- .../lib/SyncAsyncFileSystemDecorator.d.ts | 21 ++++++ enhanced-resolve/lib/common-types.d.ts | 21 +++++- 5 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 enhanced-resolve/lib/SyncAsyncFileSystemDecorator.d.ts 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 {