Skip to content

Commit 8436ea8

Browse files
committed
Merge pull request #22 from NickHeiner/silence
Adding an option to suppress log messages.
2 parents ee7b9a4 + 36f64d6 commit 8436ea8

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Most TypeScript-related options should be set using a
4343
file. There are a few loader-specific options you can set although in general
4444
you should not need to.
4545

46+
##### silent *(boolean) (default='false')*
47+
If true, no console.log messages will be emitted.
48+
4649
##### compiler *(string) (default='typescript')*
4750

4851
Allows use of TypeScript compilers other than the official one. Should be

index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface Dependency {
2121
}
2222

2323
interface Options {
24+
silent: boolean;
2425
instance: string;
2526
compiler: string;
2627
configFileName: string;
@@ -86,6 +87,12 @@ function findConfigFile(compiler: typeof typescript, searchPath: string, configF
8687

8788
function ensureTypeScriptInstance(options: Options, loader: any): TSInstance {
8889

90+
function log(...messages: string[]): void {
91+
if (!options.silent) {
92+
console.log.apply(console, messages);
93+
}
94+
}
95+
8996
var compiler = require(options.compiler);
9097
var files = <TSFiles>{};
9198

@@ -100,7 +107,7 @@ function ensureTypeScriptInstance(options: Options, loader: any): TSInstance {
100107
var filesToLoad = [];
101108
var configFilePath = findConfigFile(compiler, path.dirname(loader.resourcePath), options.configFileName);
102109
if (configFilePath) {
103-
console.log('Using config file at '.green + configFilePath.blue);
110+
log('Using config file at '.green + configFilePath.blue);
104111
var configFile = compiler.readConfigFile(configFilePath);
105112
// TODO: when 1.5 stable comes out, this will never be undefined. Instead it will
106113
// have an 'error' property
@@ -166,7 +173,7 @@ function ensureTypeScriptInstance(options: Options, loader: any): TSInstance {
166173
getCompilationSettings: () => compilerOptions,
167174
getDefaultLibFileName: options => libFileName,
168175
getNewLine: () => { return os.EOL },
169-
log: message => console.log(message)
176+
log: log
170177
};
171178

172179
var languageService = compiler.createLanguageService(servicesHost, compiler.createDocumentRegistry())
@@ -280,4 +287,4 @@ function loader(contents) {
280287
callback(null, contents, sourceMap)
281288
}
282289

283-
export = loader;
290+
export = loader;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "0.4.4",
3+
"version": "0.4.5",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)