├── src ├── baseDir.ts ├── CompilationResult.ts ├── index.ts ├── Dependencies.ts ├── util │ ├── trace.ts │ └── traced.ts ├── CompilationRequest.ts ├── Diagnostics.ts ├── compile.ts ├── OptionsBuilder.ts ├── LanguageServiceHost.ts └── loadTypeScript.ts ├── .gitignore ├── .npmignore ├── typings ├── loader-utils.d.ts └── node │ └── node.d.ts ├── tsconfig.json ├── package.json ├── LICENSE └── README.md /src/baseDir.ts: -------------------------------------------------------------------------------- 1 | const baseDir = process.cwd(); 2 | 3 | export default baseDir; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | node_modules 3 | *.sublime-project 4 | *.sublime-workspace 5 | .vscode 6 | .idea 7 | *.iml 8 | -------------------------------------------------------------------------------- /src/CompilationResult.ts: -------------------------------------------------------------------------------- 1 | export default class CompilationResult { 2 | output: string; 3 | sourceMap: any; 4 | } 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | typings 3 | tsconfig.json 4 | *.sublime-project 5 | *.sublime-workspace 6 | .vscode 7 | .idea 8 | *.iml 9 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import loadTypeScript from './loadTypeScript'; 2 | 3 | module.exports = function (content: string) { 4 | loadTypeScript(this, content); 5 | }; 6 | -------------------------------------------------------------------------------- /typings/loader-utils.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'loader-utils' { 2 | export function parseQuery(query: string): any; 3 | export function getRemainingRequest(loaderContext: any): any; 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "noImplicitAny": true, 6 | "noEmitOnError": true, 7 | "newLine": "LF", 8 | "experimentalDecorators": true, 9 | "outDir": "lib" 10 | }, 11 | "exclude": [ 12 | "node_modules" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /src/Dependencies.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as path from 'path'; 4 | import baseDir from './baseDir' 5 | 6 | export default class Dependencies { 7 | private dependencies: { [filePath: string]: boolean } = {}; 8 | 9 | add(filePath: string) { 10 | this.dependencies[path.resolve(baseDir, filePath)] = true; 11 | } 12 | 13 | forEach(callback: (filePath: string) => void) { 14 | Object.keys(this.dependencies).forEach(filePath => callback(filePath)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/util/trace.ts: -------------------------------------------------------------------------------- 1 | const KEY = 'webpackTypeScript'.toUpperCase(); 2 | 3 | const enabled = new RegExp('\\b' + KEY + '\\b', 'i').test(process.env.NODE_DEBUG || ''); 4 | 5 | let indent = ''; 6 | 7 | interface ITrace { 8 | (message: string): void; 9 | enabled?: boolean; 10 | increaseIndent?(): void; 11 | decreaseIndent?(): void; 12 | } 13 | 14 | const trace: ITrace = enabled ? (message: string) => { 15 | console.error(KEY + ' ' + process.pid + ': ' + message.replace(/^/g, indent)); 16 | } : () => {}; 17 | 18 | trace.enabled = enabled; 19 | 20 | trace.increaseIndent = () => { 21 | indent += '\t'; 22 | } 23 | 24 | trace.decreaseIndent = () => { 25 | if (indent === '') { 26 | throw new Error("can't decrease zero indent"); 27 | } 28 | indent = indent.slice(0, -1); 29 | } 30 | 31 | export default trace; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-typescript", 3 | "version": "0.5.6", 4 | "author": "Denis Nedelyaev", 5 | "license": "MIT", 6 | "description": "Lightweight, cleanly designed TypeScript Loader for webpack.", 7 | "keywords": [ 8 | "typescript-loader", 9 | "ts-loader", 10 | "webpack-loader", 11 | "typescript", 12 | "loader", 13 | "webpack", 14 | "ts", 15 | "tsx", 16 | "jsx" 17 | ], 18 | "homepage": "https://github.com/denvned/webpack-typescript", 19 | "bugs": "https://github.com/denvned/webpack-typescript/issues", 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/denvned/webpack-typescript.git" 23 | }, 24 | "main": "lib/index.js", 25 | "dependencies": { 26 | "loader-utils": "^0.2.11" 27 | }, 28 | "peerDependencies": { 29 | "typescript": "^1.5.3 || >1.7.0-dev || >1.8.0-dev" 30 | }, 31 | "devDependencies": { 32 | "typescript": "^1.6.2" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CompilationRequest.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as ts from 'typescript'; 4 | import * as path from 'path'; 5 | import * as os from 'os'; 6 | 7 | export default class CompilationRequest { 8 | inputFileName: string; 9 | options: ts.CompilerOptions; 10 | newLine: string; 11 | 12 | constructor(inputFileName: string, public input: string, options: ts.CompilerOptions) { 13 | this.inputFileName = path.normalize(inputFileName); 14 | this.options = options; 15 | 16 | if (options.newLine === ts.NewLineKind.CarriageReturnLineFeed) { 17 | this.newLine = '\r\n'; 18 | } else if (options.newLine === ts.NewLineKind.LineFeed) { 19 | this.newLine = '\n' 20 | } else { 21 | this.newLine = os.EOL; 22 | } 23 | } 24 | 25 | isInputFile(fileName: string) { 26 | return path.normalize(fileName) === this.inputFileName; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Diagnostics.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript'; 2 | 3 | export default class Diagnostics { 4 | private diagnostics: ts.Diagnostic[] = []; 5 | 6 | get isEmpty() { 7 | return this.diagnostics.length === 0; 8 | } 9 | 10 | add(diagnostics: ts.Diagnostic[]) { 11 | this.diagnostics = this.diagnostics.concat(diagnostics); 12 | } 13 | 14 | toString() { 15 | let text = ''; 16 | 17 | this.diagnostics.forEach(diagnostic => { 18 | if (diagnostic.file) { 19 | const loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); 20 | text += `${diagnostic.file.fileName}(${loc.line + 1},${loc.character + 1}): `; 21 | } 22 | const category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); 23 | text += `${category} TS${diagnostic.code}: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}\n`; 24 | }); 25 | return text; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Denis Nedelyaev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/compile.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as ts from 'typescript'; 4 | import * as path from 'path'; 5 | import LanguageServiceHost from './LanguageServiceHost'; 6 | import CompilationRequest from './CompilationRequest'; 7 | import CompilationResult from './CompilationResult'; 8 | import Dependencies from './Dependencies'; 9 | import Diagnostics from './Diagnostics'; 10 | 11 | const languageServiceHost = new LanguageServiceHost(); 12 | const languageService = ts.createLanguageService(languageServiceHost); 13 | 14 | export default function compile(request: CompilationRequest, dependencies: Dependencies, diagnostics: Diagnostics) { 15 | languageServiceHost.setCompilationRequest(request, dependencies); 16 | const program = languageService.getProgram(); 17 | const result = new CompilationResult(); 18 | 19 | const emitResult = request.options.noEmit ? null : emit(); 20 | 21 | collectDiagnostics(); 22 | 23 | return result; 24 | 25 | function emit() { 26 | const emitResult = program.emit(void 0, (fileName, data) => { 27 | if (fileName.slice(-4) === '.map') { 28 | result.sourceMap = JSON.parse(data); 29 | } else { 30 | result.output = data; 31 | } 32 | }); 33 | 34 | if (!result.output || emitResult.emitSkipped) { 35 | result.output = null; 36 | result.sourceMap = null; 37 | } else if (result.sourceMap) { 38 | result.output = result.output.slice(0, result.output.lastIndexOf('//# sourceMappingURL=')); 39 | } 40 | return emitResult; 41 | } 42 | 43 | function collectDiagnostics() { 44 | // We are trying to mimic output of tsc 45 | 46 | diagnostics.add(program.getSyntacticDiagnostics()); 47 | 48 | if (diagnostics.isEmpty) { 49 | if (program.getOptionsDiagnostics) { // New in TypeScript 1.6 50 | diagnostics.add(program.getOptionsDiagnostics()); 51 | } 52 | diagnostics.add(program.getGlobalDiagnostics()); 53 | 54 | if (diagnostics.isEmpty) { 55 | diagnostics.add(program.getSemanticDiagnostics()); 56 | } 57 | } 58 | if (emitResult) { 59 | diagnostics.add(emitResult.diagnostics); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/util/traced.ts: -------------------------------------------------------------------------------- 1 | import trace from './trace'; 2 | 3 | const COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; 4 | const FN_NAME = /^\s*function\s*([^\s\(]*)/m; 5 | const FN_ARGS = /\(([^\)]*)\)/m; 6 | 7 | function getFunctionText(fn: Function) { 8 | return fn.toString().replace(COMMENTS, ''); 9 | } 10 | 11 | function getFunctionName(fn: Function) { 12 | return getFunctionText(fn).match(FN_NAME)[1]; 13 | } 14 | 15 | function getFunctionArgNames(fn: Function) { 16 | const args = getFunctionText(fn).match(FN_ARGS)[1].trim(); 17 | return args ? args.split(',').map(arg => arg.trim()) : []; 18 | } 19 | 20 | function stringify(value: any) { 21 | return JSON.stringify(value, null, '\t'); 22 | } 23 | 24 | interface ITracedMethodOptions { 25 | return: boolean; 26 | } 27 | 28 | const tracedMethod = trace.enabled ? (options?: ITracedMethodOptions): MethodDecorator => { 29 | const skipReturn = options && options.return === false; 30 | return ( 31 | target: Object, 32 | propertyKey: string | symbol, 33 | descriptor: TypedPropertyDescriptor 34 | ) => { 35 | const methodName = getFunctionName(target.constructor) + '#' + propertyKey.toString(); 36 | const method = descriptor.value; 37 | 38 | if (typeof method !== 'function') { 39 | throw new TypeError(`@traceMethod: ${methodName} is not a method`); 40 | } 41 | const argNames = getFunctionArgNames(method); 42 | 43 | descriptor.value = function (...args: any[]) { 44 | trace('CALL: ' + methodName); 45 | 46 | trace.increaseIndent(); 47 | 48 | for (let i = 0; i < Math.max(argNames.length, args.length); i++) { 49 | trace('ARG ' + argNames[i] + ': ' + stringify(args[i])); 50 | } 51 | try { 52 | const result = method.apply(this, args); 53 | 54 | if (!skipReturn) { 55 | trace('RETURN: ' + stringify(result)); 56 | } 57 | return result; 58 | } catch (err) { 59 | trace('THROW: ' + stringify(err)); 60 | 61 | throw err; 62 | } finally { 63 | trace.decreaseIndent(); 64 | 65 | trace('EXIT: ' + methodName); 66 | } 67 | }; 68 | } 69 | } : (): MethodDecorator => () => {}; 70 | 71 | export {tracedMethod}; 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TypeScript Loader for *webpack* ![unmaintained](http://img.shields.io/badge/status-unmaintained-red.png) 2 | =============================== 3 | 4 | *webpack-typescript* is a lightweight, cleanly designed TypeScript loader for *webpack* allowing you to pack multiple modules written in TypeScript into a bundle. It supports TypeScript 1.5, 1.6, and experimentally supports [nightly builds](http://blogs.msdn.com/b/typescript/archive/2015/07/27/introducing-typescript-nightlies.aspx) of upcoming TypeScript 1.7 and 1.8. 5 | 6 | Installation 7 | ------------ 8 | 9 | To install *webpack-typescript* run the following command in your project directory: 10 | 11 | npm install webpack-typescript --save-dev 12 | 13 | And if you want to use a nightly build of TypeScript, also install *typescript@next* before or after installing *webpack-typescript*: 14 | 15 | npm install typescript@next --save-dev 16 | 17 | Configuration 18 | ------------- 19 | 20 | Here is a sample *webpack.config.js* file featuring *webpack-typescript* loader: 21 | 22 | ```javascript 23 | module.exports = { 24 | entry: './index', 25 | output: { 26 | path: __dirname + '/dist', 27 | filename: 'bundle.js' 28 | }, 29 | resolve: { 30 | extensions: ['', '.js', '.ts', '.tsx'] 31 | }, 32 | devtool: 'source-map', // if we want a source map 33 | module: { 34 | loaders: [ 35 | { 36 | test: /\.tsx?$/, 37 | loader: 'webpack-typescript?target=ES5&jsx=react' 38 | } 39 | ] 40 | } 41 | } 42 | ``` 43 | 44 | [Here](http://webpack.github.io/docs/configuration.html) you can find more about configuring *webpack*. 45 | 46 | ### Compiler Options 47 | 48 | TypeScript [compiler options](https://github.com/Microsoft/TypeScript/wiki/Compiler-Options) can be supplied as loader query parameters (like in the sample *webpack.config.js* above), and by a standard [tsconfig.json](https://github.com/Microsoft/TypeScript/wiki/tsconfig.json) file. Note that the `"files"` and `"exclude"` sections in *tsconfig.json* are ignored, because now *webpack* decides what to compile. Likewise, the loader ignores the compiler options `"out"`, `"outFile"`, `"outDir"`, `"rootDir"`, `"sourceRoot"`, and `"mapRoot"`. 49 | 50 | *webpack-typescript* uses the same algorithm to find a *tsconfig.json* as TypeScript compiler uses itself, i.e. first look in the current working directory, then in ancestor directories until it is found. 51 | 52 | **If you have a question, a bug report, or a feature request, please don't hesitate to post an issue in [the issue tracker](https://github.com/denvned/webpack-typescript/issues).** 53 | -------------------------------------------------------------------------------- /src/OptionsBuilder.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as ts from 'typescript'; 4 | import * as path from 'path' 5 | import Diagnostics from './Diagnostics'; 6 | 7 | export default class OptionsBuilder { 8 | private options: ts.CompilerOptions = {}; 9 | 10 | constructor(public diagnostics: Diagnostics) {} 11 | 12 | addConfigFileText(filePath: string, content: string) { 13 | const result = (ts.parseConfigFileText || (ts).parseConfigFileTextToJson)(filePath, content); 14 | if (result.error) { 15 | this.diagnostics.add([result.error]); 16 | } else { 17 | this.addConfig(result.config, path.dirname(filePath)); 18 | } 19 | return this; 20 | } 21 | 22 | addConfig(config: any, basePath: string) { 23 | const options = parseOptions.call(this); 24 | 25 | if (options) { 26 | addOptions.call(this); 27 | } 28 | return this; 29 | 30 | function parseOptions() { 31 | config.files = []; 32 | const result = (ts.parseConfigFile || (ts).parseJsonConfigFileContent)(config, ts.sys, basePath); 33 | 34 | if (result.errors.length > 0) { 35 | this.diagnostics.add(result.errors); 36 | return null; 37 | } else { 38 | return result.options; 39 | } 40 | } 41 | 42 | function addOptions() { 43 | for (const key in options) { 44 | if (options.hasOwnProperty(key)) { 45 | this.options[key] = options[key]; 46 | } 47 | } 48 | } 49 | } 50 | 51 | build(sourceMap: boolean) { 52 | const options = this.options; 53 | this.options = {}; 54 | 55 | adjustOptions(); 56 | 57 | return Object.freeze(options); 58 | 59 | function adjustOptions() { 60 | delete options.out; 61 | delete options.outFile; 62 | delete options.declaration; 63 | delete options.emitBOM; 64 | 65 | if (sourceMap) { 66 | if (options.inlineSourceMap) { 67 | delete options.inlineSourceMap; 68 | options.sourceMap = true; 69 | } 70 | if (typeof options.sourceMap === 'undefined') { 71 | options.sourceMap = true; 72 | } 73 | if (options.sourceMap) { 74 | options.inlineSources = true; 75 | } 76 | } else { 77 | delete options.sourceMap; 78 | delete options.inlineSourceMap; 79 | delete options.inlineSources; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/LanguageServiceHost.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as ts from 'typescript'; 4 | import * as path from 'path'; 5 | import * as fs from 'fs'; 6 | import CompilationRequest from './CompilationRequest'; 7 | import Dependencies from './Dependencies'; 8 | import baseDir from './baseDir' 9 | import {tracedMethod} from './util/traced'; 10 | import trace from './util/trace'; 11 | 12 | export default class LanguageServiceHost implements ts.LanguageServiceHost { 13 | private projectVersion: number = 0; 14 | private request: CompilationRequest; 15 | private dependencies: Dependencies; 16 | 17 | @tracedMethod() 18 | setCompilationRequest(request: CompilationRequest, dependencies: Dependencies) { 19 | if (!Object.isFrozen(request)) { 20 | throw new TypeError('request should be frozen'); 21 | } 22 | if (!Object.isFrozen(request.options)) { 23 | throw new TypeError('request.options should be frozen'); 24 | } 25 | this.request = request; 26 | this.dependencies = dependencies; 27 | this.projectVersion++; 28 | } 29 | 30 | @tracedMethod() 31 | getProjectVersion() { 32 | return this.projectVersion.toString(); 33 | } 34 | 35 | @tracedMethod() 36 | getCompilationSettings() { 37 | return this.request.options; 38 | } 39 | 40 | @tracedMethod() 41 | getCurrentDirectory() { 42 | return baseDir; 43 | } 44 | 45 | @tracedMethod() 46 | getScriptFileNames() { 47 | return [path.relative(baseDir, this.request.inputFileName)]; 48 | } 49 | 50 | @tracedMethod({ return: false }) 51 | getScriptSnapshot(fileName: string) { 52 | const filePath = path.resolve(baseDir, fileName); 53 | 54 | // Add to dependencies every path that TypeScript tries, 55 | // even if the file does not exist, because it may become available later 56 | this.dependencies.add(filePath); 57 | 58 | let source: string; 59 | if (this.request.isInputFile(filePath)) { 60 | trace('Using input'); 61 | source = this.request.input; 62 | } else { 63 | try { 64 | trace('Reading file: ' + filePath); 65 | source = fs.readFileSync(filePath, 'utf8'); 66 | } catch (err) { 67 | trace('Failed to read file'); 68 | return void 0; 69 | } 70 | } 71 | return ts.ScriptSnapshot.fromString(source); 72 | } 73 | 74 | @tracedMethod() 75 | getScriptVersion(fileName: string) { 76 | const filePath = path.resolve(baseDir, fileName); 77 | 78 | // Add to dependencies every path that TypeScript tries, 79 | // even if the file does not exist, because it may become available later 80 | this.dependencies.add(filePath); 81 | 82 | try { 83 | return fs.statSync(filePath).mtime.toISOString(); 84 | } catch (err) { 85 | return void 0; 86 | } 87 | } 88 | 89 | @tracedMethod() 90 | getDefaultLibFileName() { 91 | return path.resolve(path.dirname(ts.sys.getExecutingFilePath()), ts.getDefaultLibFileName(this.request.options)); // HACK: ts understands absolute path only 92 | } 93 | 94 | @tracedMethod() 95 | getNewLine() { 96 | return this.request.newLine; 97 | } 98 | 99 | /* HACK: we can't call async resolve, and resolveSync works only with enhanced-require, not with webpack 100 | @tracedMethod() 101 | resolveModuleNames(moduleNames: string[], containingFile: string) { 102 | const dir = path.dirname(containingFile); 103 | 104 | return moduleNames.map(moduleName => { 105 | try { 106 | return this.request.resolveFn(dir, moduleName); 107 | } catch (err) { 108 | return void 0; 109 | } 110 | }); 111 | } 112 | */ 113 | } 114 | -------------------------------------------------------------------------------- /src/loadTypeScript.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import * as ts from 'typescript'; 5 | import * as loaderUtils from 'loader-utils'; 6 | import * as path from 'path'; 7 | import * as fs from 'fs'; 8 | import Diagnostics from './Diagnostics'; 9 | import Dependencies from './Dependencies'; 10 | import OptionsBuilder from './OptionsBuilder'; 11 | import compile from './compile'; 12 | import CompilationRequest from './CompilationRequest'; 13 | import CompilationResult from './CompilationResult'; 14 | import baseDir from './baseDir' 15 | import trace from './util/trace'; 16 | 17 | export default function loadTypeScript(loaderContext: any, input: string) { 18 | const diagnostics = new Diagnostics(); 19 | const dependencies = new Dependencies(); 20 | 21 | trace('LOAD: ' + loaderContext.resourcePath); 22 | 23 | setupLoader(); 24 | 25 | const query = loaderUtils.parseQuery(loaderContext.query); 26 | 27 | const configFile = readConfigFile(); 28 | 29 | const options = prepareOptions(); 30 | 31 | const result = diagnostics.isEmpty ? compileInput() : {}; 32 | 33 | stateDependencies(); 34 | 35 | sendResult(); 36 | 37 | function setupLoader() { 38 | loaderContext.cacheable(); 39 | } 40 | 41 | function readConfigFile() { 42 | const result = { 43 | path: null, 44 | content: null 45 | }; 46 | 47 | let dir = baseDir; 48 | while (true) { 49 | const filePath = path.resolve(dir, 'tsconfig.json'); 50 | 51 | // Add every tried path to the dependencies, because even if the file currently doesn't exist, it may become available later. 52 | dependencies.add(filePath); 53 | 54 | try { 55 | result.content = fs.readFileSync(filePath, 'utf8'); 56 | result.path = path.relative(baseDir, filePath); 57 | break; 58 | } catch (err) {} 59 | 60 | const parent = path.dirname(dir); 61 | if (parent === dir) { 62 | break; 63 | } 64 | dir = parent; 65 | } 66 | return result; 67 | } 68 | 69 | function prepareOptions() { 70 | const optionsBuilder = new OptionsBuilder(diagnostics); 71 | if (configFile.content) { 72 | trace('CONFIG FILE: ' + configFile.path); 73 | 74 | optionsBuilder.addConfigFileText(configFile.path, configFile.content); 75 | } else { 76 | trace('CONFIG FILE WAS NOT FOUND'); 77 | } 78 | optionsBuilder.addConfig({ compilerOptions: query }, baseDir); 79 | 80 | return optionsBuilder.build(loaderContext.sourceMap); 81 | } 82 | 83 | function compileInput() { 84 | const request = Object.freeze(new CompilationRequest( 85 | loaderContext.resourcePath, 86 | input, 87 | options 88 | )); 89 | const result = compile(request, dependencies, diagnostics); 90 | if (result.sourceMap) { 91 | result.sourceMap.sources = [loaderUtils.getRemainingRequest(loaderContext)]; 92 | } 93 | return result; 94 | } 95 | 96 | function stateDependencies() { 97 | dependencies.forEach(filePath => { 98 | trace('DEPENDENCY: ' + filePath); 99 | 100 | loaderContext.dependency(filePath); 101 | }); 102 | } 103 | 104 | function sendResult() { 105 | const messages = diagnostics.toString(); 106 | 107 | if (typeof result.output === 'string') { 108 | process.stdout.write(messages); 109 | 110 | loaderContext.callback(null, result.output, result.sourceMap); 111 | } else if (messages) { 112 | loaderContext.callback(new Error('TypeScript compilation failed:\n' + messages)); 113 | } // noEmit 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /typings/node/node.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Node.js v0.12.0 2 | // Project: http://nodejs.org/ 3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /************************************************ 7 | * * 8 | * Node.js v0.12.0 API * 9 | * * 10 | ************************************************/ 11 | 12 | // compat for TypeScript 1.5.3 13 | // if you use with --target es3 or --target es5 and use below definitions, 14 | // use the lib.es6.d.ts that is bundled with TypeScript 1.5.3. 15 | interface MapConstructor {} 16 | interface WeakMapConstructor {} 17 | interface SetConstructor {} 18 | interface WeakSetConstructor {} 19 | 20 | /************************************************ 21 | * * 22 | * GLOBAL * 23 | * * 24 | ************************************************/ 25 | declare var process: NodeJS.Process; 26 | declare var global: NodeJS.Global; 27 | 28 | declare var __filename: string; 29 | declare var __dirname: string; 30 | 31 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 32 | declare function clearTimeout(timeoutId: NodeJS.Timer): void; 33 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 34 | declare function clearInterval(intervalId: NodeJS.Timer): void; 35 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; 36 | declare function clearImmediate(immediateId: any): void; 37 | 38 | interface NodeRequireFunction { 39 | (id: string): any; 40 | } 41 | 42 | interface NodeRequire extends NodeRequireFunction { 43 | resolve(id:string): string; 44 | cache: any; 45 | extensions: any; 46 | main: any; 47 | } 48 | 49 | declare var require: NodeRequire; 50 | 51 | interface NodeModule { 52 | exports: any; 53 | require: NodeRequireFunction; 54 | id: string; 55 | filename: string; 56 | loaded: boolean; 57 | parent: any; 58 | children: any[]; 59 | } 60 | 61 | declare var module: NodeModule; 62 | 63 | // Same as module.exports 64 | declare var exports: any; 65 | declare var SlowBuffer: { 66 | new (str: string, encoding?: string): Buffer; 67 | new (size: number): Buffer; 68 | new (size: Uint8Array): Buffer; 69 | new (array: any[]): Buffer; 70 | prototype: Buffer; 71 | isBuffer(obj: any): boolean; 72 | byteLength(string: string, encoding?: string): number; 73 | concat(list: Buffer[], totalLength?: number): Buffer; 74 | }; 75 | 76 | 77 | // Buffer class 78 | interface Buffer extends NodeBuffer {} 79 | 80 | /** 81 | * Raw data is stored in instances of the Buffer class. 82 | * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. 83 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 84 | */ 85 | declare var Buffer: { 86 | /** 87 | * Allocates a new buffer containing the given {str}. 88 | * 89 | * @param str String to store in buffer. 90 | * @param encoding encoding to use, optional. Default is 'utf8' 91 | */ 92 | new (str: string, encoding?: string): Buffer; 93 | /** 94 | * Allocates a new buffer of {size} octets. 95 | * 96 | * @param size count of octets to allocate. 97 | */ 98 | new (size: number): Buffer; 99 | /** 100 | * Allocates a new buffer containing the given {array} of octets. 101 | * 102 | * @param array The octets to store. 103 | */ 104 | new (array: Uint8Array): Buffer; 105 | /** 106 | * Allocates a new buffer containing the given {array} of octets. 107 | * 108 | * @param array The octets to store. 109 | */ 110 | new (array: any[]): Buffer; 111 | prototype: Buffer; 112 | /** 113 | * Returns true if {obj} is a Buffer 114 | * 115 | * @param obj object to test. 116 | */ 117 | isBuffer(obj: any): boolean; 118 | /** 119 | * Returns true if {encoding} is a valid encoding argument. 120 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 121 | * 122 | * @param encoding string to test. 123 | */ 124 | isEncoding(encoding: string): boolean; 125 | /** 126 | * Gives the actual byte length of a string. encoding defaults to 'utf8'. 127 | * This is not the same as String.prototype.length since that returns the number of characters in a string. 128 | * 129 | * @param string string to test. 130 | * @param encoding encoding used to evaluate (defaults to 'utf8') 131 | */ 132 | byteLength(string: string, encoding?: string): number; 133 | /** 134 | * Returns a buffer which is the result of concatenating all the buffers in the list together. 135 | * 136 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 137 | * If the list has exactly one item, then the first item of the list is returned. 138 | * If the list has more than one item, then a new Buffer is created. 139 | * 140 | * @param list An array of Buffer objects to concatenate 141 | * @param totalLength Total length of the buffers when concatenated. 142 | * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. 143 | */ 144 | concat(list: Buffer[], totalLength?: number): Buffer; 145 | /** 146 | * The same as buf1.compare(buf2). 147 | */ 148 | compare(buf1: Buffer, buf2: Buffer): number; 149 | }; 150 | 151 | /************************************************ 152 | * * 153 | * GLOBAL INTERFACES * 154 | * * 155 | ************************************************/ 156 | declare module NodeJS { 157 | export interface ErrnoException extends Error { 158 | errno?: number; 159 | code?: string; 160 | path?: string; 161 | syscall?: string; 162 | stack?: string; 163 | } 164 | 165 | export interface EventEmitter { 166 | addListener(event: string, listener: Function): EventEmitter; 167 | on(event: string, listener: Function): EventEmitter; 168 | once(event: string, listener: Function): EventEmitter; 169 | removeListener(event: string, listener: Function): EventEmitter; 170 | removeAllListeners(event?: string): EventEmitter; 171 | setMaxListeners(n: number): void; 172 | listeners(event: string): Function[]; 173 | emit(event: string, ...args: any[]): boolean; 174 | } 175 | 176 | export interface ReadableStream extends EventEmitter { 177 | readable: boolean; 178 | read(size?: number): string|Buffer; 179 | setEncoding(encoding: string): void; 180 | pause(): void; 181 | resume(): void; 182 | pipe(destination: T, options?: { end?: boolean; }): T; 183 | unpipe(destination?: T): void; 184 | unshift(chunk: string): void; 185 | unshift(chunk: Buffer): void; 186 | wrap(oldStream: ReadableStream): ReadableStream; 187 | } 188 | 189 | export interface WritableStream extends EventEmitter { 190 | writable: boolean; 191 | write(buffer: Buffer, cb?: Function): boolean; 192 | write(str: string, cb?: Function): boolean; 193 | write(str: string, encoding?: string, cb?: Function): boolean; 194 | end(): void; 195 | end(buffer: Buffer, cb?: Function): void; 196 | end(str: string, cb?: Function): void; 197 | end(str: string, encoding?: string, cb?: Function): void; 198 | } 199 | 200 | export interface ReadWriteStream extends ReadableStream, WritableStream {} 201 | 202 | export interface Process extends EventEmitter { 203 | stdout: WritableStream; 204 | stderr: WritableStream; 205 | stdin: ReadableStream; 206 | argv: string[]; 207 | execPath: string; 208 | abort(): void; 209 | chdir(directory: string): void; 210 | cwd(): string; 211 | env: any; 212 | exit(code?: number): void; 213 | getgid(): number; 214 | setgid(id: number): void; 215 | setgid(id: string): void; 216 | getuid(): number; 217 | setuid(id: number): void; 218 | setuid(id: string): void; 219 | version: string; 220 | versions: { 221 | http_parser: string; 222 | node: string; 223 | v8: string; 224 | ares: string; 225 | uv: string; 226 | zlib: string; 227 | openssl: string; 228 | }; 229 | config: { 230 | target_defaults: { 231 | cflags: any[]; 232 | default_configuration: string; 233 | defines: string[]; 234 | include_dirs: string[]; 235 | libraries: string[]; 236 | }; 237 | variables: { 238 | clang: number; 239 | host_arch: string; 240 | node_install_npm: boolean; 241 | node_install_waf: boolean; 242 | node_prefix: string; 243 | node_shared_openssl: boolean; 244 | node_shared_v8: boolean; 245 | node_shared_zlib: boolean; 246 | node_use_dtrace: boolean; 247 | node_use_etw: boolean; 248 | node_use_openssl: boolean; 249 | target_arch: string; 250 | v8_no_strict_aliasing: number; 251 | v8_use_snapshot: boolean; 252 | visibility: string; 253 | }; 254 | }; 255 | kill(pid: number, signal?: string): void; 256 | pid: number; 257 | title: string; 258 | arch: string; 259 | platform: string; 260 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; 261 | nextTick(callback: Function): void; 262 | umask(mask?: number): number; 263 | uptime(): number; 264 | hrtime(time?:number[]): number[]; 265 | 266 | // Worker 267 | send?(message: any, sendHandle?: any): void; 268 | } 269 | 270 | export interface Global { 271 | Array: typeof Array; 272 | ArrayBuffer: typeof ArrayBuffer; 273 | Boolean: typeof Boolean; 274 | Buffer: typeof Buffer; 275 | DataView: typeof DataView; 276 | Date: typeof Date; 277 | Error: typeof Error; 278 | EvalError: typeof EvalError; 279 | Float32Array: typeof Float32Array; 280 | Float64Array: typeof Float64Array; 281 | Function: typeof Function; 282 | GLOBAL: Global; 283 | Infinity: typeof Infinity; 284 | Int16Array: typeof Int16Array; 285 | Int32Array: typeof Int32Array; 286 | Int8Array: typeof Int8Array; 287 | Intl: typeof Intl; 288 | JSON: typeof JSON; 289 | Map: MapConstructor; 290 | Math: typeof Math; 291 | NaN: typeof NaN; 292 | Number: typeof Number; 293 | Object: typeof Object; 294 | Promise: Function; 295 | RangeError: typeof RangeError; 296 | ReferenceError: typeof ReferenceError; 297 | RegExp: typeof RegExp; 298 | Set: SetConstructor; 299 | String: typeof String; 300 | Symbol: Function; 301 | SyntaxError: typeof SyntaxError; 302 | TypeError: typeof TypeError; 303 | URIError: typeof URIError; 304 | Uint16Array: typeof Uint16Array; 305 | Uint32Array: typeof Uint32Array; 306 | Uint8Array: typeof Uint8Array; 307 | Uint8ClampedArray: Function; 308 | WeakMap: WeakMapConstructor; 309 | WeakSet: WeakSetConstructor; 310 | clearImmediate: (immediateId: any) => void; 311 | clearInterval: (intervalId: NodeJS.Timer) => void; 312 | clearTimeout: (timeoutId: NodeJS.Timer) => void; 313 | console: typeof console; 314 | decodeURI: typeof decodeURI; 315 | decodeURIComponent: typeof decodeURIComponent; 316 | encodeURI: typeof encodeURI; 317 | encodeURIComponent: typeof encodeURIComponent; 318 | escape: (str: string) => string; 319 | eval: typeof eval; 320 | global: Global; 321 | isFinite: typeof isFinite; 322 | isNaN: typeof isNaN; 323 | parseFloat: typeof parseFloat; 324 | parseInt: typeof parseInt; 325 | process: Process; 326 | root: Global; 327 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; 328 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 329 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 330 | undefined: typeof undefined; 331 | unescape: (str: string) => string; 332 | gc: () => void; 333 | } 334 | 335 | export interface Timer { 336 | ref() : void; 337 | unref() : void; 338 | } 339 | } 340 | 341 | /** 342 | * @deprecated 343 | */ 344 | interface NodeBuffer { 345 | [index: number]: number; 346 | write(string: string, offset?: number, length?: number, encoding?: string): number; 347 | toString(encoding?: string, start?: number, end?: number): string; 348 | toJSON(): any; 349 | length: number; 350 | equals(otherBuffer: Buffer): boolean; 351 | compare(otherBuffer: Buffer): number; 352 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 353 | slice(start?: number, end?: number): Buffer; 354 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 355 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 356 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 357 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 358 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 359 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 360 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 361 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 362 | readUInt8(offset: number, noAsset?: boolean): number; 363 | readUInt16LE(offset: number, noAssert?: boolean): number; 364 | readUInt16BE(offset: number, noAssert?: boolean): number; 365 | readUInt32LE(offset: number, noAssert?: boolean): number; 366 | readUInt32BE(offset: number, noAssert?: boolean): number; 367 | readInt8(offset: number, noAssert?: boolean): number; 368 | readInt16LE(offset: number, noAssert?: boolean): number; 369 | readInt16BE(offset: number, noAssert?: boolean): number; 370 | readInt32LE(offset: number, noAssert?: boolean): number; 371 | readInt32BE(offset: number, noAssert?: boolean): number; 372 | readFloatLE(offset: number, noAssert?: boolean): number; 373 | readFloatBE(offset: number, noAssert?: boolean): number; 374 | readDoubleLE(offset: number, noAssert?: boolean): number; 375 | readDoubleBE(offset: number, noAssert?: boolean): number; 376 | writeUInt8(value: number, offset: number, noAssert?: boolean): void; 377 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; 378 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; 379 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; 380 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; 381 | writeInt8(value: number, offset: number, noAssert?: boolean): void; 382 | writeInt16LE(value: number, offset: number, noAssert?: boolean): void; 383 | writeInt16BE(value: number, offset: number, noAssert?: boolean): void; 384 | writeInt32LE(value: number, offset: number, noAssert?: boolean): void; 385 | writeInt32BE(value: number, offset: number, noAssert?: boolean): void; 386 | writeFloatLE(value: number, offset: number, noAssert?: boolean): void; 387 | writeFloatBE(value: number, offset: number, noAssert?: boolean): void; 388 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; 389 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; 390 | fill(value: any, offset?: number, end?: number): void; 391 | } 392 | 393 | /************************************************ 394 | * * 395 | * MODULES * 396 | * * 397 | ************************************************/ 398 | declare module "buffer" { 399 | export var INSPECT_MAX_BYTES: number; 400 | } 401 | 402 | declare module "querystring" { 403 | export function stringify(obj: any, sep?: string, eq?: string): string; 404 | export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; 405 | export function escape(str: string): string; 406 | export function unescape(str: string): string; 407 | } 408 | 409 | declare module "events" { 410 | export class EventEmitter implements NodeJS.EventEmitter { 411 | static listenerCount(emitter: EventEmitter, event: string): number; 412 | 413 | addListener(event: string, listener: Function): EventEmitter; 414 | on(event: string, listener: Function): EventEmitter; 415 | once(event: string, listener: Function): EventEmitter; 416 | removeListener(event: string, listener: Function): EventEmitter; 417 | removeAllListeners(event?: string): EventEmitter; 418 | setMaxListeners(n: number): void; 419 | listeners(event: string): Function[]; 420 | emit(event: string, ...args: any[]): boolean; 421 | } 422 | } 423 | 424 | declare module "http" { 425 | import * as events from "events"; 426 | import * as net from "net"; 427 | import * as stream from "stream"; 428 | 429 | export interface Server extends events.EventEmitter { 430 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 431 | listen(port: number, hostname?: string, callback?: Function): Server; 432 | listen(path: string, callback?: Function): Server; 433 | listen(handle: any, listeningListener?: Function): Server; 434 | close(cb?: any): Server; 435 | address(): { port: number; family: string; address: string; }; 436 | maxHeadersCount: number; 437 | } 438 | /** 439 | * @deprecated Use IncomingMessage 440 | */ 441 | export interface ServerRequest extends IncomingMessage { 442 | connection: net.Socket; 443 | } 444 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 445 | // Extended base methods 446 | write(buffer: Buffer): boolean; 447 | write(buffer: Buffer, cb?: Function): boolean; 448 | write(str: string, cb?: Function): boolean; 449 | write(str: string, encoding?: string, cb?: Function): boolean; 450 | write(str: string, encoding?: string, fd?: string): boolean; 451 | 452 | writeContinue(): void; 453 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 454 | writeHead(statusCode: number, headers?: any): void; 455 | statusCode: number; 456 | statusMessage: string; 457 | setHeader(name: string, value: string): void; 458 | sendDate: boolean; 459 | getHeader(name: string): string; 460 | removeHeader(name: string): void; 461 | write(chunk: any, encoding?: string): any; 462 | addTrailers(headers: any): void; 463 | 464 | // Extended base methods 465 | end(): void; 466 | end(buffer: Buffer, cb?: Function): void; 467 | end(str: string, cb?: Function): void; 468 | end(str: string, encoding?: string, cb?: Function): void; 469 | end(data?: any, encoding?: string): void; 470 | } 471 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 472 | // Extended base methods 473 | write(buffer: Buffer): boolean; 474 | write(buffer: Buffer, cb?: Function): boolean; 475 | write(str: string, cb?: Function): boolean; 476 | write(str: string, encoding?: string, cb?: Function): boolean; 477 | write(str: string, encoding?: string, fd?: string): boolean; 478 | 479 | write(chunk: any, encoding?: string): void; 480 | abort(): void; 481 | setTimeout(timeout: number, callback?: Function): void; 482 | setNoDelay(noDelay?: boolean): void; 483 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 484 | 485 | // Extended base methods 486 | end(): void; 487 | end(buffer: Buffer, cb?: Function): void; 488 | end(str: string, cb?: Function): void; 489 | end(str: string, encoding?: string, cb?: Function): void; 490 | end(data?: any, encoding?: string): void; 491 | } 492 | export interface IncomingMessage extends events.EventEmitter, stream.Readable { 493 | httpVersion: string; 494 | headers: any; 495 | rawHeaders: string[]; 496 | trailers: any; 497 | rawTrailers: any; 498 | setTimeout(msecs: number, callback: Function): NodeJS.Timer; 499 | /** 500 | * Only valid for request obtained from http.Server. 501 | */ 502 | method?: string; 503 | /** 504 | * Only valid for request obtained from http.Server. 505 | */ 506 | url?: string; 507 | /** 508 | * Only valid for response obtained from http.ClientRequest. 509 | */ 510 | statusCode?: number; 511 | /** 512 | * Only valid for response obtained from http.ClientRequest. 513 | */ 514 | statusMessage?: string; 515 | socket: net.Socket; 516 | } 517 | /** 518 | * @deprecated Use IncomingMessage 519 | */ 520 | export interface ClientResponse extends IncomingMessage { } 521 | 522 | export interface AgentOptions { 523 | /** 524 | * Keep sockets around in a pool to be used by other requests in the future. Default = false 525 | */ 526 | keepAlive?: boolean; 527 | /** 528 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. 529 | * Only relevant if keepAlive is set to true. 530 | */ 531 | keepAliveMsecs?: number; 532 | /** 533 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity 534 | */ 535 | maxSockets?: number; 536 | /** 537 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. 538 | */ 539 | maxFreeSockets?: number; 540 | } 541 | 542 | export class Agent { 543 | maxSockets: number; 544 | sockets: any; 545 | requests: any; 546 | 547 | constructor(opts?: AgentOptions); 548 | 549 | /** 550 | * Destroy any sockets that are currently in use by the agent. 551 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, 552 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, 553 | * sockets may hang open for quite a long time before the server terminates them. 554 | */ 555 | destroy(): void; 556 | } 557 | 558 | export var METHODS: string[]; 559 | 560 | export var STATUS_CODES: { 561 | [errorCode: number]: string; 562 | [errorCode: string]: string; 563 | }; 564 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; 565 | export function createClient(port?: number, host?: string): any; 566 | export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 567 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 568 | export var globalAgent: Agent; 569 | } 570 | 571 | declare module "cluster" { 572 | import * as child from "child_process"; 573 | import * as events from "events"; 574 | 575 | export interface ClusterSettings { 576 | exec?: string; 577 | args?: string[]; 578 | silent?: boolean; 579 | } 580 | 581 | export class Worker extends events.EventEmitter { 582 | id: string; 583 | process: child.ChildProcess; 584 | suicide: boolean; 585 | send(message: any, sendHandle?: any): void; 586 | kill(signal?: string): void; 587 | destroy(signal?: string): void; 588 | disconnect(): void; 589 | } 590 | 591 | export var settings: ClusterSettings; 592 | export var isMaster: boolean; 593 | export var isWorker: boolean; 594 | export function setupMaster(settings?: ClusterSettings): void; 595 | export function fork(env?: any): Worker; 596 | export function disconnect(callback?: Function): void; 597 | export var worker: Worker; 598 | export var workers: Worker[]; 599 | 600 | // Event emitter 601 | export function addListener(event: string, listener: Function): void; 602 | export function on(event: string, listener: Function): any; 603 | export function once(event: string, listener: Function): void; 604 | export function removeListener(event: string, listener: Function): void; 605 | export function removeAllListeners(event?: string): void; 606 | export function setMaxListeners(n: number): void; 607 | export function listeners(event: string): Function[]; 608 | export function emit(event: string, ...args: any[]): boolean; 609 | } 610 | 611 | declare module "zlib" { 612 | import * as stream from "stream"; 613 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 614 | 615 | export interface Gzip extends stream.Transform { } 616 | export interface Gunzip extends stream.Transform { } 617 | export interface Deflate extends stream.Transform { } 618 | export interface Inflate extends stream.Transform { } 619 | export interface DeflateRaw extends stream.Transform { } 620 | export interface InflateRaw extends stream.Transform { } 621 | export interface Unzip extends stream.Transform { } 622 | 623 | export function createGzip(options?: ZlibOptions): Gzip; 624 | export function createGunzip(options?: ZlibOptions): Gunzip; 625 | export function createDeflate(options?: ZlibOptions): Deflate; 626 | export function createInflate(options?: ZlibOptions): Inflate; 627 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 628 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 629 | export function createUnzip(options?: ZlibOptions): Unzip; 630 | 631 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 632 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any; 633 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 634 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; 635 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 636 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any; 637 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 638 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; 639 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 640 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any; 641 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 642 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; 643 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 644 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any; 645 | 646 | // Constants 647 | export var Z_NO_FLUSH: number; 648 | export var Z_PARTIAL_FLUSH: number; 649 | export var Z_SYNC_FLUSH: number; 650 | export var Z_FULL_FLUSH: number; 651 | export var Z_FINISH: number; 652 | export var Z_BLOCK: number; 653 | export var Z_TREES: number; 654 | export var Z_OK: number; 655 | export var Z_STREAM_END: number; 656 | export var Z_NEED_DICT: number; 657 | export var Z_ERRNO: number; 658 | export var Z_STREAM_ERROR: number; 659 | export var Z_DATA_ERROR: number; 660 | export var Z_MEM_ERROR: number; 661 | export var Z_BUF_ERROR: number; 662 | export var Z_VERSION_ERROR: number; 663 | export var Z_NO_COMPRESSION: number; 664 | export var Z_BEST_SPEED: number; 665 | export var Z_BEST_COMPRESSION: number; 666 | export var Z_DEFAULT_COMPRESSION: number; 667 | export var Z_FILTERED: number; 668 | export var Z_HUFFMAN_ONLY: number; 669 | export var Z_RLE: number; 670 | export var Z_FIXED: number; 671 | export var Z_DEFAULT_STRATEGY: number; 672 | export var Z_BINARY: number; 673 | export var Z_TEXT: number; 674 | export var Z_ASCII: number; 675 | export var Z_UNKNOWN: number; 676 | export var Z_DEFLATED: number; 677 | export var Z_NULL: number; 678 | } 679 | 680 | declare module "os" { 681 | export function tmpdir(): string; 682 | export function hostname(): string; 683 | export function type(): string; 684 | export function platform(): string; 685 | export function arch(): string; 686 | export function release(): string; 687 | export function uptime(): number; 688 | export function loadavg(): number[]; 689 | export function totalmem(): number; 690 | export function freemem(): number; 691 | export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; 692 | export function networkInterfaces(): any; 693 | export var EOL: string; 694 | } 695 | 696 | declare module "https" { 697 | import * as tls from "tls"; 698 | import * as events from "events"; 699 | import * as http from "http"; 700 | 701 | export interface ServerOptions { 702 | pfx?: any; 703 | key?: any; 704 | passphrase?: string; 705 | cert?: any; 706 | ca?: any; 707 | crl?: any; 708 | ciphers?: string; 709 | honorCipherOrder?: boolean; 710 | requestCert?: boolean; 711 | rejectUnauthorized?: boolean; 712 | NPNProtocols?: any; 713 | SNICallback?: (servername: string) => any; 714 | } 715 | 716 | export interface RequestOptions { 717 | host?: string; 718 | hostname?: string; 719 | port?: number; 720 | path?: string; 721 | method?: string; 722 | headers?: any; 723 | auth?: string; 724 | agent?: any; 725 | pfx?: any; 726 | key?: any; 727 | passphrase?: string; 728 | cert?: any; 729 | ca?: any; 730 | ciphers?: string; 731 | rejectUnauthorized?: boolean; 732 | } 733 | 734 | export interface Agent { 735 | maxSockets: number; 736 | sockets: any; 737 | requests: any; 738 | } 739 | export var Agent: { 740 | new (options?: RequestOptions): Agent; 741 | }; 742 | export interface Server extends tls.Server { } 743 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 744 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 745 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 746 | export var globalAgent: Agent; 747 | } 748 | 749 | declare module "punycode" { 750 | export function decode(string: string): string; 751 | export function encode(string: string): string; 752 | export function toUnicode(domain: string): string; 753 | export function toASCII(domain: string): string; 754 | export var ucs2: ucs2; 755 | interface ucs2 { 756 | decode(string: string): string; 757 | encode(codePoints: number[]): string; 758 | } 759 | export var version: any; 760 | } 761 | 762 | declare module "repl" { 763 | import * as stream from "stream"; 764 | import * as events from "events"; 765 | 766 | export interface ReplOptions { 767 | prompt?: string; 768 | input?: NodeJS.ReadableStream; 769 | output?: NodeJS.WritableStream; 770 | terminal?: boolean; 771 | eval?: Function; 772 | useColors?: boolean; 773 | useGlobal?: boolean; 774 | ignoreUndefined?: boolean; 775 | writer?: Function; 776 | } 777 | export function start(options: ReplOptions): events.EventEmitter; 778 | } 779 | 780 | declare module "readline" { 781 | import * as events from "events"; 782 | import * as stream from "stream"; 783 | 784 | export interface ReadLine extends events.EventEmitter { 785 | setPrompt(prompt: string): void; 786 | prompt(preserveCursor?: boolean): void; 787 | question(query: string, callback: Function): void; 788 | pause(): void; 789 | resume(): void; 790 | close(): void; 791 | write(data: any, key?: any): void; 792 | } 793 | export interface ReadLineOptions { 794 | input: NodeJS.ReadableStream; 795 | output: NodeJS.WritableStream; 796 | completer?: Function; 797 | terminal?: boolean; 798 | } 799 | export function createInterface(options: ReadLineOptions): ReadLine; 800 | } 801 | 802 | declare module "vm" { 803 | export interface Context { } 804 | export interface Script { 805 | runInThisContext(): void; 806 | runInNewContext(sandbox?: Context): void; 807 | } 808 | export function runInThisContext(code: string, filename?: string): void; 809 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 810 | export function runInContext(code: string, context: Context, filename?: string): void; 811 | export function createContext(initSandbox?: Context): Context; 812 | export function createScript(code: string, filename?: string): Script; 813 | } 814 | 815 | declare module "child_process" { 816 | import * as events from "events"; 817 | import * as stream from "stream"; 818 | 819 | export interface ChildProcess extends events.EventEmitter { 820 | stdin: stream.Writable; 821 | stdout: stream.Readable; 822 | stderr: stream.Readable; 823 | pid: number; 824 | kill(signal?: string): void; 825 | send(message: any, sendHandle?: any): void; 826 | disconnect(): void; 827 | unref(): void; 828 | } 829 | 830 | export function spawn(command: string, args?: string[], options?: { 831 | cwd?: string; 832 | stdio?: any; 833 | custom?: any; 834 | env?: any; 835 | detached?: boolean; 836 | }): ChildProcess; 837 | export function exec(command: string, options: { 838 | cwd?: string; 839 | stdio?: any; 840 | customFds?: any; 841 | env?: any; 842 | encoding?: string; 843 | timeout?: number; 844 | maxBuffer?: number; 845 | killSignal?: string; 846 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 847 | export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 848 | export function execFile(file: string, 849 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 850 | export function execFile(file: string, args?: string[], 851 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 852 | export function execFile(file: string, args?: string[], options?: { 853 | cwd?: string; 854 | stdio?: any; 855 | customFds?: any; 856 | env?: any; 857 | encoding?: string; 858 | timeout?: number; 859 | maxBuffer?: string; 860 | killSignal?: string; 861 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 862 | export function fork(modulePath: string, args?: string[], options?: { 863 | cwd?: string; 864 | env?: any; 865 | encoding?: string; 866 | }): ChildProcess; 867 | export function execSync(command: string, options?: { 868 | cwd?: string; 869 | input?: string|Buffer; 870 | stdio?: any; 871 | env?: any; 872 | uid?: number; 873 | gid?: number; 874 | timeout?: number; 875 | maxBuffer?: number; 876 | killSignal?: string; 877 | encoding?: string; 878 | }): ChildProcess; 879 | export function execFileSync(command: string, args?: string[], options?: { 880 | cwd?: string; 881 | input?: string|Buffer; 882 | stdio?: any; 883 | env?: any; 884 | uid?: number; 885 | gid?: number; 886 | timeout?: number; 887 | maxBuffer?: number; 888 | killSignal?: string; 889 | encoding?: string; 890 | }): ChildProcess; 891 | } 892 | 893 | declare module "url" { 894 | export interface Url { 895 | href: string; 896 | protocol: string; 897 | auth: string; 898 | hostname: string; 899 | port: string; 900 | host: string; 901 | pathname: string; 902 | search: string; 903 | query: any; // string | Object 904 | slashes: boolean; 905 | hash?: string; 906 | path?: string; 907 | } 908 | 909 | export interface UrlOptions { 910 | protocol?: string; 911 | auth?: string; 912 | hostname?: string; 913 | port?: string; 914 | host?: string; 915 | pathname?: string; 916 | search?: string; 917 | query?: any; 918 | hash?: string; 919 | path?: string; 920 | } 921 | 922 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 923 | export function format(url: UrlOptions): string; 924 | export function resolve(from: string, to: string): string; 925 | } 926 | 927 | declare module "dns" { 928 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 929 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 930 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 931 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 932 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 933 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 934 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 935 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 936 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 937 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 938 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 939 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 940 | } 941 | 942 | declare module "net" { 943 | import * as stream from "stream"; 944 | 945 | export interface Socket extends stream.Duplex { 946 | // Extended base methods 947 | write(buffer: Buffer): boolean; 948 | write(buffer: Buffer, cb?: Function): boolean; 949 | write(str: string, cb?: Function): boolean; 950 | write(str: string, encoding?: string, cb?: Function): boolean; 951 | write(str: string, encoding?: string, fd?: string): boolean; 952 | 953 | connect(port: number, host?: string, connectionListener?: Function): void; 954 | connect(path: string, connectionListener?: Function): void; 955 | bufferSize: number; 956 | setEncoding(encoding?: string): void; 957 | write(data: any, encoding?: string, callback?: Function): void; 958 | destroy(): void; 959 | pause(): void; 960 | resume(): void; 961 | setTimeout(timeout: number, callback?: Function): void; 962 | setNoDelay(noDelay?: boolean): void; 963 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 964 | address(): { port: number; family: string; address: string; }; 965 | unref(): void; 966 | ref(): void; 967 | 968 | remoteAddress: string; 969 | remoteFamily: string; 970 | remotePort: number; 971 | localAddress: string; 972 | localPort: number; 973 | bytesRead: number; 974 | bytesWritten: number; 975 | 976 | // Extended base methods 977 | end(): void; 978 | end(buffer: Buffer, cb?: Function): void; 979 | end(str: string, cb?: Function): void; 980 | end(str: string, encoding?: string, cb?: Function): void; 981 | end(data?: any, encoding?: string): void; 982 | } 983 | 984 | export var Socket: { 985 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 986 | }; 987 | 988 | export interface Server extends Socket { 989 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 990 | listen(path: string, listeningListener?: Function): Server; 991 | listen(handle: any, listeningListener?: Function): Server; 992 | close(callback?: Function): Server; 993 | address(): { port: number; family: string; address: string; }; 994 | maxConnections: number; 995 | connections: number; 996 | } 997 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server; 998 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; 999 | export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1000 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 1001 | export function connect(path: string, connectionListener?: Function): Socket; 1002 | export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1003 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 1004 | export function createConnection(path: string, connectionListener?: Function): Socket; 1005 | export function isIP(input: string): number; 1006 | export function isIPv4(input: string): boolean; 1007 | export function isIPv6(input: string): boolean; 1008 | } 1009 | 1010 | declare module "dgram" { 1011 | import * as events from "events"; 1012 | 1013 | interface RemoteInfo { 1014 | address: string; 1015 | port: number; 1016 | size: number; 1017 | } 1018 | 1019 | interface AddressInfo { 1020 | address: string; 1021 | family: string; 1022 | port: number; 1023 | } 1024 | 1025 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 1026 | 1027 | interface Socket extends events.EventEmitter { 1028 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 1029 | bind(port: number, address?: string, callback?: () => void): void; 1030 | close(): void; 1031 | address(): AddressInfo; 1032 | setBroadcast(flag: boolean): void; 1033 | setMulticastTTL(ttl: number): void; 1034 | setMulticastLoopback(flag: boolean): void; 1035 | addMembership(multicastAddress: string, multicastInterface?: string): void; 1036 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 1037 | } 1038 | } 1039 | 1040 | declare module "fs" { 1041 | import * as stream from "stream"; 1042 | import * as events from "events"; 1043 | 1044 | interface Stats { 1045 | isFile(): boolean; 1046 | isDirectory(): boolean; 1047 | isBlockDevice(): boolean; 1048 | isCharacterDevice(): boolean; 1049 | isSymbolicLink(): boolean; 1050 | isFIFO(): boolean; 1051 | isSocket(): boolean; 1052 | dev: number; 1053 | ino: number; 1054 | mode: number; 1055 | nlink: number; 1056 | uid: number; 1057 | gid: number; 1058 | rdev: number; 1059 | size: number; 1060 | blksize: number; 1061 | blocks: number; 1062 | atime: Date; 1063 | mtime: Date; 1064 | ctime: Date; 1065 | } 1066 | 1067 | interface FSWatcher extends events.EventEmitter { 1068 | close(): void; 1069 | } 1070 | 1071 | export interface ReadStream extends stream.Readable { 1072 | close(): void; 1073 | } 1074 | export interface WriteStream extends stream.Writable { 1075 | close(): void; 1076 | bytesWritten: number; 1077 | } 1078 | 1079 | /** 1080 | * Asynchronous rename. 1081 | * @param oldPath 1082 | * @param newPath 1083 | * @param callback No arguments other than a possible exception are given to the completion callback. 1084 | */ 1085 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1086 | /** 1087 | * Synchronous rename 1088 | * @param oldPath 1089 | * @param newPath 1090 | */ 1091 | export function renameSync(oldPath: string, newPath: string): void; 1092 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1093 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1094 | export function truncateSync(path: string, len?: number): void; 1095 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1096 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1097 | export function ftruncateSync(fd: number, len?: number): void; 1098 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1099 | export function chownSync(path: string, uid: number, gid: number): void; 1100 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1101 | export function fchownSync(fd: number, uid: number, gid: number): void; 1102 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1103 | export function lchownSync(path: string, uid: number, gid: number): void; 1104 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1105 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1106 | export function chmodSync(path: string, mode: number): void; 1107 | export function chmodSync(path: string, mode: string): void; 1108 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1109 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1110 | export function fchmodSync(fd: number, mode: number): void; 1111 | export function fchmodSync(fd: number, mode: string): void; 1112 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1113 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1114 | export function lchmodSync(path: string, mode: number): void; 1115 | export function lchmodSync(path: string, mode: string): void; 1116 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1117 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1118 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1119 | export function statSync(path: string): Stats; 1120 | export function lstatSync(path: string): Stats; 1121 | export function fstatSync(fd: number): Stats; 1122 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1123 | export function linkSync(srcpath: string, dstpath: string): void; 1124 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1125 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 1126 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 1127 | export function readlinkSync(path: string): string; 1128 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1129 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; 1130 | export function realpathSync(path: string, cache?: { [path: string]: string }): string; 1131 | /* 1132 | * Asynchronous unlink - deletes the file specified in {path} 1133 | * 1134 | * @param path 1135 | * @param callback No arguments other than a possible exception are given to the completion callback. 1136 | */ 1137 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1138 | /* 1139 | * Synchronous unlink - deletes the file specified in {path} 1140 | * 1141 | * @param path 1142 | */ 1143 | export function unlinkSync(path: string): void; 1144 | /* 1145 | * Asynchronous rmdir - removes the directory specified in {path} 1146 | * 1147 | * @param path 1148 | * @param callback No arguments other than a possible exception are given to the completion callback. 1149 | */ 1150 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1151 | /* 1152 | * Synchronous rmdir - removes the directory specified in {path} 1153 | * 1154 | * @param path 1155 | */ 1156 | export function rmdirSync(path: string): void; 1157 | /* 1158 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1159 | * 1160 | * @param path 1161 | * @param callback No arguments other than a possible exception are given to the completion callback. 1162 | */ 1163 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1164 | /* 1165 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1166 | * 1167 | * @param path 1168 | * @param mode 1169 | * @param callback No arguments other than a possible exception are given to the completion callback. 1170 | */ 1171 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1172 | /* 1173 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1174 | * 1175 | * @param path 1176 | * @param mode 1177 | * @param callback No arguments other than a possible exception are given to the completion callback. 1178 | */ 1179 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1180 | /* 1181 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1182 | * 1183 | * @param path 1184 | * @param mode 1185 | * @param callback No arguments other than a possible exception are given to the completion callback. 1186 | */ 1187 | export function mkdirSync(path: string, mode?: number): void; 1188 | /* 1189 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1190 | * 1191 | * @param path 1192 | * @param mode 1193 | * @param callback No arguments other than a possible exception are given to the completion callback. 1194 | */ 1195 | export function mkdirSync(path: string, mode?: string): void; 1196 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 1197 | export function readdirSync(path: string): string[]; 1198 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1199 | export function closeSync(fd: number): void; 1200 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1201 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1202 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1203 | export function openSync(path: string, flags: string, mode?: number): number; 1204 | export function openSync(path: string, flags: string, mode?: string): number; 1205 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1206 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1207 | export function utimesSync(path: string, atime: number, mtime: number): void; 1208 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 1209 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1210 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1211 | export function futimesSync(fd: number, atime: number, mtime: number): void; 1212 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 1213 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1214 | export function fsyncSync(fd: number): void; 1215 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1216 | export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1217 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1218 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 1219 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1220 | /* 1221 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1222 | * 1223 | * @param fileName 1224 | * @param encoding 1225 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1226 | */ 1227 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1228 | /* 1229 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1230 | * 1231 | * @param fileName 1232 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1233 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1234 | */ 1235 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1236 | /* 1237 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1238 | * 1239 | * @param fileName 1240 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1241 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1242 | */ 1243 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1244 | /* 1245 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1246 | * 1247 | * @param fileName 1248 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1249 | */ 1250 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1251 | /* 1252 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1253 | * 1254 | * @param fileName 1255 | * @param encoding 1256 | */ 1257 | export function readFileSync(filename: string, encoding: string): string; 1258 | /* 1259 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1260 | * 1261 | * @param fileName 1262 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1263 | */ 1264 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 1265 | /* 1266 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1267 | * 1268 | * @param fileName 1269 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1270 | */ 1271 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 1272 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1273 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1274 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1275 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1276 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1277 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1278 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1279 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1280 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1281 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1282 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 1283 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 1284 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 1285 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 1286 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 1287 | export function exists(path: string, callback?: (exists: boolean) => void): void; 1288 | export function existsSync(path: string): boolean; 1289 | /** Constant for fs.access(). File is visible to the calling process. */ 1290 | export var F_OK: number; 1291 | /** Constant for fs.access(). File can be read by the calling process. */ 1292 | export var R_OK: number; 1293 | /** Constant for fs.access(). File can be written by the calling process. */ 1294 | export var W_OK: number; 1295 | /** Constant for fs.access(). File can be executed by the calling process. */ 1296 | export var X_OK: number; 1297 | /** Tests a user's permissions for the file specified by path. */ 1298 | export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; 1299 | export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; 1300 | /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ 1301 | export function accessSync(path: string, mode ?: number): void; 1302 | export function createReadStream(path: string, options?: { 1303 | flags?: string; 1304 | encoding?: string; 1305 | fd?: string; 1306 | mode?: number; 1307 | bufferSize?: number; 1308 | }): ReadStream; 1309 | export function createReadStream(path: string, options?: { 1310 | flags?: string; 1311 | encoding?: string; 1312 | fd?: string; 1313 | mode?: string; 1314 | bufferSize?: number; 1315 | }): ReadStream; 1316 | export function createWriteStream(path: string, options?: { 1317 | flags?: string; 1318 | encoding?: string; 1319 | string?: string; 1320 | }): WriteStream; 1321 | } 1322 | 1323 | declare module "path" { 1324 | 1325 | /** 1326 | * A parsed path object generated by path.parse() or consumed by path.format(). 1327 | */ 1328 | export interface ParsedPath { 1329 | /** 1330 | * The root of the path such as '/' or 'c:\' 1331 | */ 1332 | root: string; 1333 | /** 1334 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 1335 | */ 1336 | dir: string; 1337 | /** 1338 | * The file name including extension (if any) such as 'index.html' 1339 | */ 1340 | base: string; 1341 | /** 1342 | * The file extension (if any) such as '.html' 1343 | */ 1344 | ext: string; 1345 | /** 1346 | * The file name without extension (if any) such as 'index' 1347 | */ 1348 | name: string; 1349 | } 1350 | 1351 | /** 1352 | * Normalize a string path, reducing '..' and '.' parts. 1353 | * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. 1354 | * 1355 | * @param p string path to normalize. 1356 | */ 1357 | export function normalize(p: string): string; 1358 | /** 1359 | * Join all arguments together and normalize the resulting path. 1360 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1361 | * 1362 | * @param paths string paths to join. 1363 | */ 1364 | export function join(...paths: any[]): string; 1365 | /** 1366 | * Join all arguments together and normalize the resulting path. 1367 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1368 | * 1369 | * @param paths string paths to join. 1370 | */ 1371 | export function join(...paths: string[]): string; 1372 | /** 1373 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. 1374 | * 1375 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path. 1376 | * 1377 | * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. 1378 | * 1379 | * @param pathSegments string paths to join. Non-string arguments are ignored. 1380 | */ 1381 | export function resolve(...pathSegments: any[]): string; 1382 | /** 1383 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. 1384 | * 1385 | * @param path path to test. 1386 | */ 1387 | export function isAbsolute(path: string): boolean; 1388 | /** 1389 | * Solve the relative path from {from} to {to}. 1390 | * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. 1391 | * 1392 | * @param from 1393 | * @param to 1394 | */ 1395 | export function relative(from: string, to: string): string; 1396 | /** 1397 | * Return the directory name of a path. Similar to the Unix dirname command. 1398 | * 1399 | * @param p the path to evaluate. 1400 | */ 1401 | export function dirname(p: string): string; 1402 | /** 1403 | * Return the last portion of a path. Similar to the Unix basename command. 1404 | * Often used to extract the file name from a fully qualified path. 1405 | * 1406 | * @param p the path to evaluate. 1407 | * @param ext optionally, an extension to remove from the result. 1408 | */ 1409 | export function basename(p: string, ext?: string): string; 1410 | /** 1411 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path. 1412 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string 1413 | * 1414 | * @param p the path to evaluate. 1415 | */ 1416 | export function extname(p: string): string; 1417 | /** 1418 | * The platform-specific file separator. '\\' or '/'. 1419 | */ 1420 | export var sep: string; 1421 | /** 1422 | * The platform-specific file delimiter. ';' or ':'. 1423 | */ 1424 | export var delimiter: string; 1425 | /** 1426 | * Returns an object from a path string - the opposite of format(). 1427 | * 1428 | * @param pathString path to evaluate. 1429 | */ 1430 | export function parse(pathString: string): ParsedPath; 1431 | /** 1432 | * Returns a path string from an object - the opposite of parse(). 1433 | * 1434 | * @param pathString path to evaluate. 1435 | */ 1436 | export function format(pathObject: ParsedPath): string; 1437 | 1438 | export module posix { 1439 | export function normalize(p: string): string; 1440 | export function join(...paths: any[]): string; 1441 | export function resolve(...pathSegments: any[]): string; 1442 | export function isAbsolute(p: string): boolean; 1443 | export function relative(from: string, to: string): string; 1444 | export function dirname(p: string): string; 1445 | export function basename(p: string, ext?: string): string; 1446 | export function extname(p: string): string; 1447 | export var sep: string; 1448 | export var delimiter: string; 1449 | export function parse(p: string): ParsedPath; 1450 | export function format(pP: ParsedPath): string; 1451 | } 1452 | 1453 | export module win32 { 1454 | export function normalize(p: string): string; 1455 | export function join(...paths: any[]): string; 1456 | export function resolve(...pathSegments: any[]): string; 1457 | export function isAbsolute(p: string): boolean; 1458 | export function relative(from: string, to: string): string; 1459 | export function dirname(p: string): string; 1460 | export function basename(p: string, ext?: string): string; 1461 | export function extname(p: string): string; 1462 | export var sep: string; 1463 | export var delimiter: string; 1464 | export function parse(p: string): ParsedPath; 1465 | export function format(pP: ParsedPath): string; 1466 | } 1467 | } 1468 | 1469 | declare module "string_decoder" { 1470 | export interface NodeStringDecoder { 1471 | write(buffer: Buffer): string; 1472 | detectIncompleteChar(buffer: Buffer): number; 1473 | } 1474 | export var StringDecoder: { 1475 | new (encoding: string): NodeStringDecoder; 1476 | }; 1477 | } 1478 | 1479 | declare module "tls" { 1480 | import * as crypto from "crypto"; 1481 | import * as net from "net"; 1482 | import * as stream from "stream"; 1483 | 1484 | var CLIENT_RENEG_LIMIT: number; 1485 | var CLIENT_RENEG_WINDOW: number; 1486 | 1487 | export interface TlsOptions { 1488 | pfx?: any; //string or buffer 1489 | key?: any; //string or buffer 1490 | passphrase?: string; 1491 | cert?: any; 1492 | ca?: any; //string or buffer 1493 | crl?: any; //string or string array 1494 | ciphers?: string; 1495 | honorCipherOrder?: any; 1496 | requestCert?: boolean; 1497 | rejectUnauthorized?: boolean; 1498 | NPNProtocols?: any; //array or Buffer; 1499 | SNICallback?: (servername: string) => any; 1500 | } 1501 | 1502 | export interface ConnectionOptions { 1503 | host?: string; 1504 | port?: number; 1505 | socket?: net.Socket; 1506 | pfx?: any; //string | Buffer 1507 | key?: any; //string | Buffer 1508 | passphrase?: string; 1509 | cert?: any; //string | Buffer 1510 | ca?: any; //Array of string | Buffer 1511 | rejectUnauthorized?: boolean; 1512 | NPNProtocols?: any; //Array of string | Buffer 1513 | servername?: string; 1514 | } 1515 | 1516 | export interface Server extends net.Server { 1517 | // Extended base methods 1518 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 1519 | listen(path: string, listeningListener?: Function): Server; 1520 | listen(handle: any, listeningListener?: Function): Server; 1521 | 1522 | listen(port: number, host?: string, callback?: Function): Server; 1523 | close(): Server; 1524 | address(): { port: number; family: string; address: string; }; 1525 | addContext(hostName: string, credentials: { 1526 | key: string; 1527 | cert: string; 1528 | ca: string; 1529 | }): void; 1530 | maxConnections: number; 1531 | connections: number; 1532 | } 1533 | 1534 | export interface ClearTextStream extends stream.Duplex { 1535 | authorized: boolean; 1536 | authorizationError: Error; 1537 | getPeerCertificate(): any; 1538 | getCipher: { 1539 | name: string; 1540 | version: string; 1541 | }; 1542 | address: { 1543 | port: number; 1544 | family: string; 1545 | address: string; 1546 | }; 1547 | remoteAddress: string; 1548 | remotePort: number; 1549 | } 1550 | 1551 | export interface SecurePair { 1552 | encrypted: any; 1553 | cleartext: any; 1554 | } 1555 | 1556 | export interface SecureContextOptions { 1557 | pfx?: any; //string | buffer 1558 | key?: any; //string | buffer 1559 | passphrase?: string; 1560 | cert?: any; // string | buffer 1561 | ca?: any; // string | buffer 1562 | crl?: any; // string | string[] 1563 | ciphers?: string; 1564 | honorCipherOrder?: boolean; 1565 | } 1566 | 1567 | export interface SecureContext { 1568 | context: any; 1569 | } 1570 | 1571 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 1572 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 1573 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1574 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1575 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1576 | export function createSecureContext(details: SecureContextOptions): SecureContext; 1577 | } 1578 | 1579 | declare module "crypto" { 1580 | export interface CredentialDetails { 1581 | pfx: string; 1582 | key: string; 1583 | passphrase: string; 1584 | cert: string; 1585 | ca: any; //string | string array 1586 | crl: any; //string | string array 1587 | ciphers: string; 1588 | } 1589 | export interface Credentials { context?: any; } 1590 | export function createCredentials(details: CredentialDetails): Credentials; 1591 | export function createHash(algorithm: string): Hash; 1592 | export function createHmac(algorithm: string, key: string): Hmac; 1593 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1594 | interface Hash { 1595 | update(data: any, input_encoding?: string): Hash; 1596 | digest(encoding: 'buffer'): Buffer; 1597 | digest(encoding: string): any; 1598 | digest(): Buffer; 1599 | } 1600 | interface Hmac { 1601 | update(data: any, input_encoding?: string): Hmac; 1602 | digest(encoding: 'buffer'): Buffer; 1603 | digest(encoding: string): any; 1604 | digest(): Buffer; 1605 | } 1606 | export function createCipher(algorithm: string, password: any): Cipher; 1607 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1608 | interface Cipher { 1609 | update(data: Buffer): Buffer; 1610 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1611 | final(): Buffer; 1612 | final(output_encoding: string): string; 1613 | setAutoPadding(auto_padding: boolean): void; 1614 | } 1615 | export function createDecipher(algorithm: string, password: any): Decipher; 1616 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1617 | interface Decipher { 1618 | update(data: Buffer): Buffer; 1619 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1620 | final(): Buffer; 1621 | final(output_encoding: string): string; 1622 | setAutoPadding(auto_padding: boolean): void; 1623 | } 1624 | export function createSign(algorithm: string): Signer; 1625 | interface Signer extends NodeJS.WritableStream { 1626 | update(data: any): void; 1627 | sign(private_key: string, output_format: string): string; 1628 | } 1629 | export function createVerify(algorith: string): Verify; 1630 | interface Verify extends NodeJS.WritableStream { 1631 | update(data: any): void; 1632 | verify(object: string, signature: string, signature_format?: string): boolean; 1633 | } 1634 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1635 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1636 | interface DiffieHellman { 1637 | generateKeys(encoding?: string): string; 1638 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1639 | getPrime(encoding?: string): string; 1640 | getGenerator(encoding: string): string; 1641 | getPublicKey(encoding?: string): string; 1642 | getPrivateKey(encoding?: string): string; 1643 | setPublicKey(public_key: string, encoding?: string): void; 1644 | setPrivateKey(public_key: string, encoding?: string): void; 1645 | } 1646 | export function getDiffieHellman(group_name: string): DiffieHellman; 1647 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1648 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; 1649 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; 1650 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number, digest: string) : Buffer; 1651 | export function randomBytes(size: number): Buffer; 1652 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1653 | export function pseudoRandomBytes(size: number): Buffer; 1654 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1655 | } 1656 | 1657 | declare module "stream" { 1658 | import * as events from "events"; 1659 | 1660 | export interface Stream extends events.EventEmitter { 1661 | pipe(destination: T, options?: { end?: boolean; }): T; 1662 | } 1663 | 1664 | export interface ReadableOptions { 1665 | highWaterMark?: number; 1666 | encoding?: string; 1667 | objectMode?: boolean; 1668 | } 1669 | 1670 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1671 | readable: boolean; 1672 | constructor(opts?: ReadableOptions); 1673 | _read(size: number): void; 1674 | read(size?: number): string|Buffer; 1675 | setEncoding(encoding: string): void; 1676 | pause(): void; 1677 | resume(): void; 1678 | pipe(destination: T, options?: { end?: boolean; }): T; 1679 | unpipe(destination?: T): void; 1680 | unshift(chunk: string): void; 1681 | unshift(chunk: Buffer): void; 1682 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1683 | push(chunk: any, encoding?: string): boolean; 1684 | } 1685 | 1686 | export interface WritableOptions { 1687 | highWaterMark?: number; 1688 | decodeStrings?: boolean; 1689 | } 1690 | 1691 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1692 | writable: boolean; 1693 | constructor(opts?: WritableOptions); 1694 | _write(data: Buffer, encoding: string, callback: Function): void; 1695 | _write(data: string, encoding: string, callback: Function): void; 1696 | write(buffer: Buffer, cb?: Function): boolean; 1697 | write(str: string, cb?: Function): boolean; 1698 | write(str: string, encoding?: string, cb?: Function): boolean; 1699 | end(): void; 1700 | end(buffer: Buffer, cb?: Function): void; 1701 | end(str: string, cb?: Function): void; 1702 | end(str: string, encoding?: string, cb?: Function): void; 1703 | } 1704 | 1705 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1706 | allowHalfOpen?: boolean; 1707 | } 1708 | 1709 | // Note: Duplex extends both Readable and Writable. 1710 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1711 | writable: boolean; 1712 | constructor(opts?: DuplexOptions); 1713 | _write(data: Buffer, encoding: string, callback: Function): void; 1714 | _write(data: string, encoding: string, callback: Function): void; 1715 | write(buffer: Buffer, cb?: Function): boolean; 1716 | write(str: string, cb?: Function): boolean; 1717 | write(str: string, encoding?: string, cb?: Function): boolean; 1718 | end(): void; 1719 | end(buffer: Buffer, cb?: Function): void; 1720 | end(str: string, cb?: Function): void; 1721 | end(str: string, encoding?: string, cb?: Function): void; 1722 | } 1723 | 1724 | export interface TransformOptions extends ReadableOptions, WritableOptions {} 1725 | 1726 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1727 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1728 | readable: boolean; 1729 | writable: boolean; 1730 | constructor(opts?: TransformOptions); 1731 | _transform(chunk: Buffer, encoding: string, callback: Function): void; 1732 | _transform(chunk: string, encoding: string, callback: Function): void; 1733 | _flush(callback: Function): void; 1734 | read(size?: number): any; 1735 | setEncoding(encoding: string): void; 1736 | pause(): void; 1737 | resume(): void; 1738 | pipe(destination: T, options?: { end?: boolean; }): T; 1739 | unpipe(destination?: T): void; 1740 | unshift(chunk: string): void; 1741 | unshift(chunk: Buffer): void; 1742 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1743 | push(chunk: any, encoding?: string): boolean; 1744 | write(buffer: Buffer, cb?: Function): boolean; 1745 | write(str: string, cb?: Function): boolean; 1746 | write(str: string, encoding?: string, cb?: Function): boolean; 1747 | end(): void; 1748 | end(buffer: Buffer, cb?: Function): void; 1749 | end(str: string, cb?: Function): void; 1750 | end(str: string, encoding?: string, cb?: Function): void; 1751 | } 1752 | 1753 | export class PassThrough extends Transform {} 1754 | } 1755 | 1756 | declare module "util" { 1757 | export interface InspectOptions { 1758 | showHidden?: boolean; 1759 | depth?: number; 1760 | colors?: boolean; 1761 | customInspect?: boolean; 1762 | } 1763 | 1764 | export function format(format: any, ...param: any[]): string; 1765 | export function debug(string: string): void; 1766 | export function error(...param: any[]): void; 1767 | export function puts(...param: any[]): void; 1768 | export function print(...param: any[]): void; 1769 | export function log(string: string): void; 1770 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 1771 | export function inspect(object: any, options: InspectOptions): string; 1772 | export function isArray(object: any): boolean; 1773 | export function isRegExp(object: any): boolean; 1774 | export function isDate(object: any): boolean; 1775 | export function isError(object: any): boolean; 1776 | export function inherits(constructor: any, superConstructor: any): void; 1777 | } 1778 | 1779 | declare module "assert" { 1780 | function internal (value: any, message?: string): void; 1781 | module internal { 1782 | export class AssertionError implements Error { 1783 | name: string; 1784 | message: string; 1785 | actual: any; 1786 | expected: any; 1787 | operator: string; 1788 | generatedMessage: boolean; 1789 | 1790 | constructor(options?: {message?: string; actual?: any; expected?: any; 1791 | operator?: string; stackStartFunction?: Function}); 1792 | } 1793 | 1794 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 1795 | export function ok(value: any, message?: string): void; 1796 | export function equal(actual: any, expected: any, message?: string): void; 1797 | export function notEqual(actual: any, expected: any, message?: string): void; 1798 | export function deepEqual(actual: any, expected: any, message?: string): void; 1799 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 1800 | export function strictEqual(actual: any, expected: any, message?: string): void; 1801 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 1802 | export var throws: { 1803 | (block: Function, message?: string): void; 1804 | (block: Function, error: Function, message?: string): void; 1805 | (block: Function, error: RegExp, message?: string): void; 1806 | (block: Function, error: (err: any) => boolean, message?: string): void; 1807 | }; 1808 | 1809 | export var doesNotThrow: { 1810 | (block: Function, message?: string): void; 1811 | (block: Function, error: Function, message?: string): void; 1812 | (block: Function, error: RegExp, message?: string): void; 1813 | (block: Function, error: (err: any) => boolean, message?: string): void; 1814 | }; 1815 | 1816 | export function ifError(value: any): void; 1817 | } 1818 | 1819 | export = internal; 1820 | } 1821 | 1822 | declare module "tty" { 1823 | import * as net from "net"; 1824 | 1825 | export function isatty(fd: number): boolean; 1826 | export interface ReadStream extends net.Socket { 1827 | isRaw: boolean; 1828 | setRawMode(mode: boolean): void; 1829 | } 1830 | export interface WriteStream extends net.Socket { 1831 | columns: number; 1832 | rows: number; 1833 | } 1834 | } 1835 | 1836 | declare module "domain" { 1837 | import * as events from "events"; 1838 | 1839 | export class Domain extends events.EventEmitter { 1840 | run(fn: Function): void; 1841 | add(emitter: events.EventEmitter): void; 1842 | remove(emitter: events.EventEmitter): void; 1843 | bind(cb: (err: Error, data: any) => any): any; 1844 | intercept(cb: (data: any) => any): any; 1845 | dispose(): void; 1846 | 1847 | addListener(event: string, listener: Function): Domain; 1848 | on(event: string, listener: Function): Domain; 1849 | once(event: string, listener: Function): Domain; 1850 | removeListener(event: string, listener: Function): Domain; 1851 | removeAllListeners(event?: string): Domain; 1852 | } 1853 | 1854 | export function create(): Domain; 1855 | } 1856 | 1857 | declare module "constants" { 1858 | export var E2BIG: number; 1859 | export var EACCES: number; 1860 | export var EADDRINUSE: number; 1861 | export var EADDRNOTAVAIL: number; 1862 | export var EAFNOSUPPORT: number; 1863 | export var EAGAIN: number; 1864 | export var EALREADY: number; 1865 | export var EBADF: number; 1866 | export var EBADMSG: number; 1867 | export var EBUSY: number; 1868 | export var ECANCELED: number; 1869 | export var ECHILD: number; 1870 | export var ECONNABORTED: number; 1871 | export var ECONNREFUSED: number; 1872 | export var ECONNRESET: number; 1873 | export var EDEADLK: number; 1874 | export var EDESTADDRREQ: number; 1875 | export var EDOM: number; 1876 | export var EEXIST: number; 1877 | export var EFAULT: number; 1878 | export var EFBIG: number; 1879 | export var EHOSTUNREACH: number; 1880 | export var EIDRM: number; 1881 | export var EILSEQ: number; 1882 | export var EINPROGRESS: number; 1883 | export var EINTR: number; 1884 | export var EINVAL: number; 1885 | export var EIO: number; 1886 | export var EISCONN: number; 1887 | export var EISDIR: number; 1888 | export var ELOOP: number; 1889 | export var EMFILE: number; 1890 | export var EMLINK: number; 1891 | export var EMSGSIZE: number; 1892 | export var ENAMETOOLONG: number; 1893 | export var ENETDOWN: number; 1894 | export var ENETRESET: number; 1895 | export var ENETUNREACH: number; 1896 | export var ENFILE: number; 1897 | export var ENOBUFS: number; 1898 | export var ENODATA: number; 1899 | export var ENODEV: number; 1900 | export var ENOENT: number; 1901 | export var ENOEXEC: number; 1902 | export var ENOLCK: number; 1903 | export var ENOLINK: number; 1904 | export var ENOMEM: number; 1905 | export var ENOMSG: number; 1906 | export var ENOPROTOOPT: number; 1907 | export var ENOSPC: number; 1908 | export var ENOSR: number; 1909 | export var ENOSTR: number; 1910 | export var ENOSYS: number; 1911 | export var ENOTCONN: number; 1912 | export var ENOTDIR: number; 1913 | export var ENOTEMPTY: number; 1914 | export var ENOTSOCK: number; 1915 | export var ENOTSUP: number; 1916 | export var ENOTTY: number; 1917 | export var ENXIO: number; 1918 | export var EOPNOTSUPP: number; 1919 | export var EOVERFLOW: number; 1920 | export var EPERM: number; 1921 | export var EPIPE: number; 1922 | export var EPROTO: number; 1923 | export var EPROTONOSUPPORT: number; 1924 | export var EPROTOTYPE: number; 1925 | export var ERANGE: number; 1926 | export var EROFS: number; 1927 | export var ESPIPE: number; 1928 | export var ESRCH: number; 1929 | export var ETIME: number; 1930 | export var ETIMEDOUT: number; 1931 | export var ETXTBSY: number; 1932 | export var EWOULDBLOCK: number; 1933 | export var EXDEV: number; 1934 | export var WSAEINTR: number; 1935 | export var WSAEBADF: number; 1936 | export var WSAEACCES: number; 1937 | export var WSAEFAULT: number; 1938 | export var WSAEINVAL: number; 1939 | export var WSAEMFILE: number; 1940 | export var WSAEWOULDBLOCK: number; 1941 | export var WSAEINPROGRESS: number; 1942 | export var WSAEALREADY: number; 1943 | export var WSAENOTSOCK: number; 1944 | export var WSAEDESTADDRREQ: number; 1945 | export var WSAEMSGSIZE: number; 1946 | export var WSAEPROTOTYPE: number; 1947 | export var WSAENOPROTOOPT: number; 1948 | export var WSAEPROTONOSUPPORT: number; 1949 | export var WSAESOCKTNOSUPPORT: number; 1950 | export var WSAEOPNOTSUPP: number; 1951 | export var WSAEPFNOSUPPORT: number; 1952 | export var WSAEAFNOSUPPORT: number; 1953 | export var WSAEADDRINUSE: number; 1954 | export var WSAEADDRNOTAVAIL: number; 1955 | export var WSAENETDOWN: number; 1956 | export var WSAENETUNREACH: number; 1957 | export var WSAENETRESET: number; 1958 | export var WSAECONNABORTED: number; 1959 | export var WSAECONNRESET: number; 1960 | export var WSAENOBUFS: number; 1961 | export var WSAEISCONN: number; 1962 | export var WSAENOTCONN: number; 1963 | export var WSAESHUTDOWN: number; 1964 | export var WSAETOOMANYREFS: number; 1965 | export var WSAETIMEDOUT: number; 1966 | export var WSAECONNREFUSED: number; 1967 | export var WSAELOOP: number; 1968 | export var WSAENAMETOOLONG: number; 1969 | export var WSAEHOSTDOWN: number; 1970 | export var WSAEHOSTUNREACH: number; 1971 | export var WSAENOTEMPTY: number; 1972 | export var WSAEPROCLIM: number; 1973 | export var WSAEUSERS: number; 1974 | export var WSAEDQUOT: number; 1975 | export var WSAESTALE: number; 1976 | export var WSAEREMOTE: number; 1977 | export var WSASYSNOTREADY: number; 1978 | export var WSAVERNOTSUPPORTED: number; 1979 | export var WSANOTINITIALISED: number; 1980 | export var WSAEDISCON: number; 1981 | export var WSAENOMORE: number; 1982 | export var WSAECANCELLED: number; 1983 | export var WSAEINVALIDPROCTABLE: number; 1984 | export var WSAEINVALIDPROVIDER: number; 1985 | export var WSAEPROVIDERFAILEDINIT: number; 1986 | export var WSASYSCALLFAILURE: number; 1987 | export var WSASERVICE_NOT_FOUND: number; 1988 | export var WSATYPE_NOT_FOUND: number; 1989 | export var WSA_E_NO_MORE: number; 1990 | export var WSA_E_CANCELLED: number; 1991 | export var WSAEREFUSED: number; 1992 | export var SIGHUP: number; 1993 | export var SIGINT: number; 1994 | export var SIGILL: number; 1995 | export var SIGABRT: number; 1996 | export var SIGFPE: number; 1997 | export var SIGKILL: number; 1998 | export var SIGSEGV: number; 1999 | export var SIGTERM: number; 2000 | export var SIGBREAK: number; 2001 | export var SIGWINCH: number; 2002 | export var SSL_OP_ALL: number; 2003 | export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; 2004 | export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; 2005 | export var SSL_OP_CISCO_ANYCONNECT: number; 2006 | export var SSL_OP_COOKIE_EXCHANGE: number; 2007 | export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; 2008 | export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; 2009 | export var SSL_OP_EPHEMERAL_RSA: number; 2010 | export var SSL_OP_LEGACY_SERVER_CONNECT: number; 2011 | export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; 2012 | export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; 2013 | export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; 2014 | export var SSL_OP_NETSCAPE_CA_DN_BUG: number; 2015 | export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; 2016 | export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; 2017 | export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; 2018 | export var SSL_OP_NO_COMPRESSION: number; 2019 | export var SSL_OP_NO_QUERY_MTU: number; 2020 | export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; 2021 | export var SSL_OP_NO_SSLv2: number; 2022 | export var SSL_OP_NO_SSLv3: number; 2023 | export var SSL_OP_NO_TICKET: number; 2024 | export var SSL_OP_NO_TLSv1: number; 2025 | export var SSL_OP_NO_TLSv1_1: number; 2026 | export var SSL_OP_NO_TLSv1_2: number; 2027 | export var SSL_OP_PKCS1_CHECK_1: number; 2028 | export var SSL_OP_PKCS1_CHECK_2: number; 2029 | export var SSL_OP_SINGLE_DH_USE: number; 2030 | export var SSL_OP_SINGLE_ECDH_USE: number; 2031 | export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; 2032 | export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; 2033 | export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; 2034 | export var SSL_OP_TLS_D5_BUG: number; 2035 | export var SSL_OP_TLS_ROLLBACK_BUG: number; 2036 | export var ENGINE_METHOD_DSA: number; 2037 | export var ENGINE_METHOD_DH: number; 2038 | export var ENGINE_METHOD_RAND: number; 2039 | export var ENGINE_METHOD_ECDH: number; 2040 | export var ENGINE_METHOD_ECDSA: number; 2041 | export var ENGINE_METHOD_CIPHERS: number; 2042 | export var ENGINE_METHOD_DIGESTS: number; 2043 | export var ENGINE_METHOD_STORE: number; 2044 | export var ENGINE_METHOD_PKEY_METHS: number; 2045 | export var ENGINE_METHOD_PKEY_ASN1_METHS: number; 2046 | export var ENGINE_METHOD_ALL: number; 2047 | export var ENGINE_METHOD_NONE: number; 2048 | export var DH_CHECK_P_NOT_SAFE_PRIME: number; 2049 | export var DH_CHECK_P_NOT_PRIME: number; 2050 | export var DH_UNABLE_TO_CHECK_GENERATOR: number; 2051 | export var DH_NOT_SUITABLE_GENERATOR: number; 2052 | export var NPN_ENABLED: number; 2053 | export var RSA_PKCS1_PADDING: number; 2054 | export var RSA_SSLV23_PADDING: number; 2055 | export var RSA_NO_PADDING: number; 2056 | export var RSA_PKCS1_OAEP_PADDING: number; 2057 | export var RSA_X931_PADDING: number; 2058 | export var RSA_PKCS1_PSS_PADDING: number; 2059 | export var POINT_CONVERSION_COMPRESSED: number; 2060 | export var POINT_CONVERSION_UNCOMPRESSED: number; 2061 | export var POINT_CONVERSION_HYBRID: number; 2062 | export var O_RDONLY: number; 2063 | export var O_WRONLY: number; 2064 | export var O_RDWR: number; 2065 | export var S_IFMT: number; 2066 | export var S_IFREG: number; 2067 | export var S_IFDIR: number; 2068 | export var S_IFCHR: number; 2069 | export var S_IFLNK: number; 2070 | export var O_CREAT: number; 2071 | export var O_EXCL: number; 2072 | export var O_TRUNC: number; 2073 | export var O_APPEND: number; 2074 | export var F_OK: number; 2075 | export var R_OK: number; 2076 | export var W_OK: number; 2077 | export var X_OK: number; 2078 | export var UV_UDP_REUSEADDR: number; 2079 | } 2080 | --------------------------------------------------------------------------------