Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"homepage": "https://github.com/TypeStrong/ts-loader",
"dependencies": {
"chalk": "^4.1.0",
"chalk": "^5.0.0",
"picomatch": "^4.0.0",
"source-map": "^0.7.4"
},
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Chalk } from 'chalk';
import type { ChalkInstance } from 'chalk';
import * as path from 'path';
import type typescript from 'typescript';
import type * as webpack from 'webpack';
Expand All @@ -15,7 +15,7 @@ interface ConfigFile {

export function getConfigFile(
compiler: typeof typescript,
colors: Chalk,
colors: ChalkInstance,
loader: webpack.LoaderContext<LoaderOptions>,
loaderOptions: LoaderOptions,
compilerCompatible: boolean,
Expand Down
7 changes: 4 additions & 3 deletions src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from './utils';
import { makeWatchRun } from './watch-run';
import { isWebpack5 } from './loaderUtils';
import { supportsColor, Chalk } from 'chalk';

const instancesBySolutionBuilderConfigs = new Map<FilePathKey, TSInstance>();

Expand All @@ -60,8 +61,8 @@ export function getTypeScriptInstance(
}

const level =
loaderOptions.colors && chalk.supportsColor ? chalk.supportsColor.level : 0;
const colors = new chalk.Instance({ level });
loaderOptions.colors && supportsColor ? supportsColor.level : 0;
const colors = new Chalk({ level });
const log = logger.makeLogger(loaderOptions, colors);
const compiler = getCompiler(loaderOptions, log);

Expand Down Expand Up @@ -122,7 +123,7 @@ function successfulTypeScriptInstance(
loaderOptions: LoaderOptions,
loader: webpack.LoaderContext<LoaderOptions>,
log: logger.Logger,
colors: chalk.Chalk,
colors: chalk.ChalkInstance,
compiler: typeof typescript,
compilerCompatible: boolean,
compilerDetailsLogMessage: string
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type typescript from 'typescript';

import type { Chalk } from 'chalk';
import type { ChalkInstance } from 'chalk';
import type * as logger from './logger';

export interface ErrorInfo {
Expand Down Expand Up @@ -196,7 +196,7 @@ export interface TSInstance {
dependencyGraph: DependencyGraph;
filesWithErrors?: TSFiles;
transformers: typescript.CustomTransformers;
colors: Chalk;
colors: ChalkInstance;

otherFiles: TSFiles;
watchHost?: WatchHost;
Expand Down Expand Up @@ -260,7 +260,7 @@ export interface LoaderOptions {
transpileOnly: boolean;
ignoreDiagnostics: number[];
reportFiles: string[];
errorFormatter: (message: ErrorInfo, colors: Chalk) => string;
errorFormatter: (message: ErrorInfo, colors: ChalkInstance) => string;
onlyCompileBundledFiles: boolean;
colors: boolean;
compilerOptions: typescript.CompilerOptions;
Expand Down
10 changes: 5 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Chalk } from 'chalk';
import type { ChalkInstance } from 'chalk';
import { Console } from 'console';
import type { LoaderOptions } from './interfaces';

Expand Down Expand Up @@ -42,7 +42,7 @@ const makeExternalLogger = (
const makeLogInfo = (
loaderOptions: LoaderOptions,
logger: InternalLoggerFunc,
green: Chalk
green: ChalkInstance
) =>
LogLevel[loaderOptions.logLevel] <= LogLevel.INFO
? (message: string) =>
Expand All @@ -55,7 +55,7 @@ const makeLogInfo = (
const makeLogError = (
loaderOptions: LoaderOptions,
logger: InternalLoggerFunc,
red: Chalk
red: ChalkInstance
) =>
LogLevel[loaderOptions.logLevel] <= LogLevel.ERROR
? (message: string) => logger(stderrConsole, red(message))
Expand All @@ -64,15 +64,15 @@ const makeLogError = (
const makeLogWarning = (
loaderOptions: LoaderOptions,
logger: InternalLoggerFunc,
yellow: Chalk
yellow: ChalkInstance
) =>
LogLevel[loaderOptions.logLevel] <= LogLevel.WARN
? (message: string) => logger(stderrConsole, yellow(message))
: doNothingLogger;

export function makeLogger(
loaderOptions: LoaderOptions,
colors: Chalk
colors: ChalkInstance
): Logger {
const logger = makeLoggerFunc(loaderOptions);
return {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Chalk } from 'chalk';
import type { ChalkInstance } from 'chalk';
import * as fs from 'fs';
import picomatch from 'picomatch';
import * as path from 'path';
Expand All @@ -22,7 +22,7 @@ import { isWebpack5 } from './loaderUtils';
/**
* The default error formatter.
*/
function defaultErrorFormatter(error: ErrorInfo, colors: Chalk) {
function defaultErrorFormatter(error: ErrorInfo, colors: ChalkInstance) {
const messageColor =
error.severity === 'warning' ? colors.bold.yellow : colors.bold.red;

Expand Down Expand Up @@ -79,7 +79,7 @@ function makeReportFilesMatcher(
export function formatErrors(
diagnostics: ReadonlyArray<typescript.Diagnostic> | undefined,
loaderOptions: LoaderOptions,
colors: Chalk,
colors: ChalkInstance,
compiler: typeof typescript,
merge: { file?: string; module?: webpack.Module },
context: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk, { Chalk } from 'chalk';
import chalk, { ChalkInstance } from 'chalk';
import { Exception } from './Exception.cjs';
import { Messages } from './Messages.js';
import { ProjectName } from './ProjectName.mjs';
Expand Down Expand Up @@ -31,7 +31,7 @@ export class Logger {
/**
* Gets a component for formatting messages.
*/
public get Chalk(): Chalk {
public get Chalk(): ChalkInstance {
return chalk;
}

Expand Down
20 changes: 5 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

ansi-styles@^4.0.0, ansi-styles@^4.1.0:
ansi-styles@^4.0.0:
version "4.3.0"
resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz"
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
Expand Down Expand Up @@ -1409,13 +1409,10 @@ chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz"
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chalk@^5.0.0:
version "5.6.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.6.2.tgz#b1238b6e23ea337af71c7f8a295db5af0c158aea"
integrity sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==

chokidar@^3.5.1:
version "3.5.3"
Expand Down Expand Up @@ -4630,13 +4627,6 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

supports-color@^7.1.0:
version "7.2.0"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz"
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
dependencies:
has-flag "^4.0.0"

supports-color@^8.0.0:
version "8.1.1"
resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz"
Expand Down