From 84fbc95cce696cdc02dcf2d8d3bf585974adf5ef Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 16 Aug 2016 11:39:59 -0700 Subject: [PATCH] Fix #10311: make resolve and browser-resolve proper modules, and add tsconfig.json and correct type references --- browser-resolve/browser-resolve-tests.ts | 2 +- browser-resolve/browser-resolve.d.ts | 61 -------------- browser-resolve/index.d.ts | 59 +++++++++++++ browser-resolve/tsconfig.json | 19 +++++ resolve/index.d.ts | 100 ++++++++++++++++++++++ resolve/resolve-tests.ts | 2 +- resolve/resolve.d.ts | 102 ----------------------- resolve/tsconfig.json | 19 +++++ 8 files changed, 199 insertions(+), 165 deletions(-) delete mode 100644 browser-resolve/browser-resolve.d.ts create mode 100644 browser-resolve/index.d.ts create mode 100644 browser-resolve/tsconfig.json create mode 100644 resolve/index.d.ts delete mode 100644 resolve/resolve.d.ts create mode 100644 resolve/tsconfig.json diff --git a/browser-resolve/browser-resolve-tests.ts b/browser-resolve/browser-resolve-tests.ts index 071b17a1d2..2225f7754c 100644 --- a/browser-resolve/browser-resolve-tests.ts +++ b/browser-resolve/browser-resolve-tests.ts @@ -1,4 +1,4 @@ -/// +/// import * as browserResolve from 'browser-resolve'; diff --git a/browser-resolve/browser-resolve.d.ts b/browser-resolve/browser-resolve.d.ts deleted file mode 100644 index 8c1456c8f0..0000000000 --- a/browser-resolve/browser-resolve.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Type definitions for browser-resolve -// Project: https://github.com/defunctzombie/node-browser-resolve -// Definitions by: Mario Nebl -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -declare module 'browser-resolve' { - import * as resolve from 'resolve'; - - /** - * Callback invoked when resolving asynchronously - * - * @param error - * @param resolved Absolute path to resolved identifier - */ - type resolveCallback = (err?: Error, resolved?: string) => void; - - /** - * Resolve a module path and call cb(err, path [, pkg]) - * - * @param id Identifier to resolve - * @param callback - */ - function browserResolve(id: string, cb: resolveCallback): void; - - /** - * Resolve a module path and call cb(err, path [, pkg]) - * - * @param id Identifier to resolve - * @param options Options to use for resolving, optional. - * @param callback - */ - function browserResolve(id: string, opts: browserResolve.AsyncOpts, cb: resolveCallback): void; - - /** - * Returns a module path - * - * @param id Identifier to resolve - * @param options Options to use for resolving, optional. - */ - function browserResolveSync(id: string, opts?: browserResolve.SyncOpts): string; - - namespace browserResolve { - interface Opts { - // the 'browser' property to use from package.json (defaults to 'browser') - browser?: string; - // the calling filename where the require() call originated (in the source) - filename?: string; - // modules object with id to path mappings to consult before doing manual resolution (use to provide core modules) - modules?: any; - } - - export interface AsyncOpts extends resolve.AsyncOpts, Opts {} - export interface SyncOpts extends resolve.SyncOpts, Opts {} - - export var sync: typeof browserResolveSync; - } - - export = browserResolve -} diff --git a/browser-resolve/index.d.ts b/browser-resolve/index.d.ts new file mode 100644 index 0000000000..30f3875541 --- /dev/null +++ b/browser-resolve/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for browser-resolve +// Project: https://github.com/defunctzombie/node-browser-resolve +// Definitions by: Mario Nebl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as resolve from 'resolve'; + +/** + * Callback invoked when resolving asynchronously + * + * @param error + * @param resolved Absolute path to resolved identifier + */ +type resolveCallback = (err?: Error, resolved?: string) => void; + +/** + * Resolve a module path and call cb(err, path [, pkg]) + * + * @param id Identifier to resolve + * @param callback + */ +declare function browserResolve(id: string, cb: resolveCallback): void; + +/** + * Resolve a module path and call cb(err, path [, pkg]) + * + * @param id Identifier to resolve + * @param options Options to use for resolving, optional. + * @param callback + */ +declare function browserResolve(id: string, opts: browserResolve.AsyncOpts, cb: resolveCallback): void; + +/** + * Returns a module path + * + * @param id Identifier to resolve + * @param options Options to use for resolving, optional. + */ +declare function browserResolveSync(id: string, opts?: browserResolve.SyncOpts): string; + +declare namespace browserResolve { + interface Opts { + // the 'browser' property to use from package.json (defaults to 'browser') + browser?: string; + // the calling filename where the require() call originated (in the source) + filename?: string; + // modules object with id to path mappings to consult before doing manual resolution (use to provide core modules) + modules?: any; + } + + export interface AsyncOpts extends resolve.AsyncOpts, Opts { } + export interface SyncOpts extends resolve.SyncOpts, Opts { } + + export var sync: typeof browserResolveSync; +} + +export = browserResolve; diff --git a/browser-resolve/tsconfig.json b/browser-resolve/tsconfig.json new file mode 100644 index 0000000000..937a2406b8 --- /dev/null +++ b/browser-resolve/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "browser-resolve-tests.ts" + ] +} \ No newline at end of file diff --git a/resolve/index.d.ts b/resolve/index.d.ts new file mode 100644 index 0000000000..ed047af9c6 --- /dev/null +++ b/resolve/index.d.ts @@ -0,0 +1,100 @@ +// Type definitions for resolve +// Project: https://github.com/substack/node-resolve +// Definitions by: Mario Nebl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +/** + * Callback invoked when resolving asynchronously + * + * @param error + * @param resolved Absolute path to resolved identifier + */ +type resolveCallback = (err: Error, resolved?: string) => void; + +/** + * Callback invoked when checking if a file exists + * + * @param error + * @param isFile If the given file exists + */ +type isFileCallback = (err: Error, isFile?: boolean) => void; + +/** + * Callback invoked when reading a file + * + * @param error + * @param isFile If the given file exists + */ +type readFileCallback = (err: Error, file?: Buffer) => void; + +/** + * Asynchronously resolve the module path string id into cb(err, res [, pkg]), where pkg (if defined) is the data from package.json + * + * @param id Identifier to resolve + * @param callback + */ +declare function resolve(id: string, cb: resolveCallback): void; + +/** + * Asynchronously resolve the module path string id into cb(err, res [, pkg]), where pkg (if defined) is the data from package.json + * + * @param id Identifier to resolve + * @param options Options to use for resolving, optional. + * @param callback + */ +declare function resolve(id: string, opts: resolve.AsyncOpts, cb: resolveCallback): void; + +/** + * Synchronously resolve the module path string id, returning the result and throwing an error when id can't be resolved. + * + * @param id Identifier to resolve + * @param options Options to use for resolving, optional. + */ +declare function resolveSync(id: string, opts?: resolve.SyncOpts): string; + +/** + * Return whether a package is in core + * + * @param id + */ +declare function resolveIsCore(id: string): boolean; + +declare namespace resolve { + interface Opts { + // directory to begin resolving from (defaults to __dirname) + basedir?: string; + // package.json data applicable to the module being loaded + package?: any; + // array of file extensions to search in order (defaults to ['.js']) + extensions?: string | string[]; + // transform the parsed package.json contents before looking at the "main" field + packageFilter?: (pkg: any, pkgfile: string) => any; + // transform a path within a package + pathFilter?: (pkg: any, path: string, relativePath: string) => string; + // require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) + paths?: string | string[]; + // directory (or directories) in which to recursively look for modules. (default to 'node_modules') + moduleDirectory?: string | string[] + } + + export interface AsyncOpts extends Opts { + // how to read files asynchronously (defaults to fs.readFile) + readFile?: (file: string, cb: readFileCallback) => void; + // function to asynchronously test whether a file exists + isFile?: (file: string, cb: isFileCallback) => void; + } + + export interface SyncOpts extends Opts { + // how to read files synchronously (defaults to fs.readFileSync) + readFileSync?: (file: string) => Buffer; + // function to synchronously test whether a file exists + isFile?: (file: string) => boolean; + } + + export var sync: typeof resolveSync; + export var isCore: typeof resolveIsCore; +} + +export = resolve; diff --git a/resolve/resolve-tests.ts b/resolve/resolve-tests.ts index 5922f3f0a8..3cac830c58 100644 --- a/resolve/resolve-tests.ts +++ b/resolve/resolve-tests.ts @@ -1,4 +1,4 @@ -/// +/// import * as fs from 'fs'; import * as resolve from 'resolve'; diff --git a/resolve/resolve.d.ts b/resolve/resolve.d.ts deleted file mode 100644 index 83082d7006..0000000000 --- a/resolve/resolve.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -// Type definitions for resolve -// Project: https://github.com/substack/node-resolve -// Definitions by: Mario Nebl -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -declare module 'resolve' { - /** - * Callback invoked when resolving asynchronously - * - * @param error - * @param resolved Absolute path to resolved identifier - */ - type resolveCallback = (err: Error, resolved?: string) => void; - - /** - * Callback invoked when checking if a file exists - * - * @param error - * @param isFile If the given file exists - */ - type isFileCallback = (err: Error, isFile?: boolean) => void; - - /** - * Callback invoked when reading a file - * - * @param error - * @param isFile If the given file exists - */ - type readFileCallback = (err: Error, file?: Buffer) => void; - - /** - * Asynchronously resolve the module path string id into cb(err, res [, pkg]), where pkg (if defined) is the data from package.json - * - * @param id Identifier to resolve - * @param callback - */ - function resolve(id: string, cb: resolveCallback): void; - - /** - * Asynchronously resolve the module path string id into cb(err, res [, pkg]), where pkg (if defined) is the data from package.json - * - * @param id Identifier to resolve - * @param options Options to use for resolving, optional. - * @param callback - */ - function resolve(id: string, opts: resolve.AsyncOpts, cb: resolveCallback): void; - - /** - * Synchronously resolve the module path string id, returning the result and throwing an error when id can't be resolved. - * - * @param id Identifier to resolve - * @param options Options to use for resolving, optional. - */ - function resolveSync(id: string, opts?: resolve.SyncOpts): string; - - /** - * Return whether a package is in core - * - * @param id - */ - function resolveIsCore(id: string): boolean; - - namespace resolve { - interface Opts { - // directory to begin resolving from (defaults to __dirname) - basedir?: string; - // package.json data applicable to the module being loaded - package?: any; - // array of file extensions to search in order (defaults to ['.js']) - extensions?: string|string[]; - // transform the parsed package.json contents before looking at the "main" field - packageFilter?: (pkg: any, pkgfile: string) => any; - // transform a path within a package - pathFilter?: (pkg: any, path: string, relativePath: string) => string; - // require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this) - paths?: string|string[]; - // directory (or directories) in which to recursively look for modules. (default to 'node_modules') - moduleDirectory?: string|string[] - } - - export interface AsyncOpts extends Opts { - // how to read files asynchronously (defaults to fs.readFile) - readFile?: (file: string, cb: readFileCallback) => void; - // function to asynchronously test whether a file exists - isFile?: (file: string, cb: isFileCallback) => void; - } - - export interface SyncOpts extends Opts { - // how to read files synchronously (defaults to fs.readFileSync) - readFileSync?: (file: string) => Buffer; - // function to synchronously test whether a file exists - isFile?: (file: string) => boolean; - } - - export var sync: typeof resolveSync; - export var isCore: typeof resolveIsCore; - } - - export = resolve; -} diff --git a/resolve/tsconfig.json b/resolve/tsconfig.json new file mode 100644 index 0000000000..3327aff4ab --- /dev/null +++ b/resolve/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "resolve-tests.ts" + ] +} \ No newline at end of file