Skip to content

Commit

Permalink
refactor: Use chalk instead of colors
Browse files Browse the repository at this point in the history
* to reduce dependency tree, because most of the modern packages uses chalk, not colors
* Doesn't extend String.prototype and https://github.com/chalk/chalk#highlights

Close #62
  • Loading branch information
develar committed Jul 6, 2017
1 parent 282e88a commit 1f78f9d
Show file tree
Hide file tree
Showing 9 changed files with 6,751 additions and 416 deletions.
2,797 changes: 2,429 additions & 368 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
},
"homepage": "https://github.com/TypeStrong/ts-loader",
"dependencies": {
"colors": "^1.0.3",
"chalk": "^2.0.1",
"enhanced-resolve": "^3.0.0",
"loader-utils": "^1.0.2",
"semver": "^5.0.1"
},
"devDependencies": {
"@types/chalk": "^0.4.31",
"babel": "^6.0.0",
"babel-core": "^6.0.0",
"babel-loader": "^7.0.0",
Expand Down
5 changes: 3 additions & 2 deletions src/compilerSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const semver = require('semver');
import interfaces = require('./interfaces');
import constants = require('./constants');
import logger = require('./logger');
§import { red, yellow } from 'chalk';

export function getCompiler(
loaderOptions: interfaces.LoaderOptions,
Expand All @@ -30,10 +31,10 @@ export function getCompiler(
// don't log yet in this case, if a tsconfig.json exists we want to combine the message
compilerCompatible = true;
} else {
log.logError(`${compilerDetailsLogMessage}. This version is incompatible with ts-loader. Please upgrade to the latest version of TypeScript.`.red);
log.logError(red(`${compilerDetailsLogMessage}. This version is incompatible with ts-loader. Please upgrade to the latest version of TypeScript.`));
}
} else {
log.logWarning(`${compilerDetailsLogMessage}. This version may or may not be compatible with ts-loader.`.yellow);
log.logWarning(yellow(`${compilerDetailsLogMessage}. This version may or may not be compatible with ts-loader.`));
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path = require('path');
import interfaces = require('./interfaces');
import logger = require('./logger');
import utils = require('./utils');
import { green } from 'chalk';

interface ConfigFile {
config?: any;
Expand All @@ -24,9 +25,9 @@ export function getConfigFile(

if (configFilePath) {
if (compilerCompatible) {
log.logInfo(`${compilerDetailsLogMessage} and ${configFilePath}`.green);
log.logInfo(green(`${compilerDetailsLogMessage} and ${configFilePath}`));
} else {
log.logInfo(`ts-loader: Using config file at ${configFilePath}`.green);
log.logInfo(green(`ts-loader: Using config file at ${configFilePath}`));
}

// HACK: relies on the fact that passing an extra argument won't break
Expand All @@ -40,7 +41,7 @@ export function getConfigFile(
configFileError = utils.formatErrors([configFile.error], loaderOptions, compiler, { file: configFilePath })[0];
}
} else {
if (compilerCompatible) { log.logInfo(compilerDetailsLogMessage.green); }
if (compilerCompatible) { log.logInfo(green(compilerDetailsLogMessage)); }

configFile = {
config: {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path = require('path');
import loaderUtils = require('loader-utils');
require('colors');

import instances = require('./instances');
import interfaces = require('./interfaces');
Expand Down
1 change: 0 additions & 1 deletion src/instances.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path = require('path');
import fs = require('fs');
require('colors');

import afterCompile = require('./after-compile');
import config = require('./config');
Expand Down
37 changes: 0 additions & 37 deletions src/typings/colors/colors.d.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typescript = require('typescript');
import path = require('path');
import fs = require('fs');
import { white, red, cyan } from 'chalk';

import constants = require('./constants');
import interfaces = require('./interfaces');
Expand Down Expand Up @@ -34,9 +35,9 @@ export function formatErrors(
let error: interfaces.WebpackError;
if (diagnostic.file) {
const lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
let errorMessage = `${'('.white}${(lineChar.line + 1).toString().cyan},${(lineChar.character + 1).toString().cyan}): ${messageText.red}`;
let errorMessage = `${white('(')}${cyan((lineChar.line + 1).toString())},${cyan((lineChar.character + 1).toString())}): ${red(messageText)}`;
if (loaderOptions.visualStudioErrorFormat) {
errorMessage = path.normalize(diagnostic.file.fileName).red + errorMessage;
errorMessage = red(path.normalize(diagnostic.file.fileName)) + errorMessage;
}
error = makeError({
message: errorMessage,
Expand Down Expand Up @@ -69,7 +70,7 @@ interface MakeError {
export function makeError({ rawMessage, message, location, file }: MakeError): interfaces.WebpackError {
const error = {
rawMessage,
message: message || `${rawMessage.red}`,
message: message || `${red(rawMessage)}`,
loaderSource: 'ts-loader'
};

Expand Down
Loading

0 comments on commit 1f78f9d

Please sign in to comment.