Fix #10311: make resolve and browser-resolve proper modules, and add tsconfig.json and correct type references

This commit is contained in:
Mohamed Hegazy
2016-08-16 11:39:59 -07:00
parent 8ba335294f
commit 84fbc95cce
8 changed files with 199 additions and 165 deletions

View File

@@ -1,4 +1,4 @@
/// <reference path="./browser-resolve.d.ts" />
/// <reference types="browser-resolve" />
import * as browserResolve from 'browser-resolve';

View File

@@ -1,61 +0,0 @@
// Type definitions for browser-resolve
// Project: https://github.com/defunctzombie/node-browser-resolve
// Definitions by: Mario Nebl <https://github.com/marionebl/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../resolve/resolve.d.ts" />
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
}

59
browser-resolve/index.d.ts vendored Normal file
View File

@@ -0,0 +1,59 @@
// Type definitions for browser-resolve
// Project: https://github.com/defunctzombie/node-browser-resolve
// Definitions by: Mario Nebl <https://github.com/marionebl/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="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
*/
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;

View File

@@ -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"
]
}

100
resolve/index.d.ts vendored Normal file
View File

@@ -0,0 +1,100 @@
// Type definitions for resolve
// Project: https://github.com/substack/node-resolve
// Definitions by: Mario Nebl <https://github.com/marionebl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
/**
* 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;

View File

@@ -1,4 +1,4 @@
/// <reference path="resolve.d.ts" />
/// <reference types="resolve" />
import * as fs from 'fs';
import * as resolve from 'resolve';

102
resolve/resolve.d.ts vendored
View File

@@ -1,102 +0,0 @@
// Type definitions for resolve
// Project: https://github.com/substack/node-resolve
// Definitions by: Mario Nebl <https://github.com/marionebl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}

19
resolve/tsconfig.json Normal file
View File

@@ -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"
]
}