Skip to content

Commit

Permalink
Fixed deprecation warnings on webpack@5. (#1195)
Browse files Browse the repository at this point in the history
* Fixed deprecation warnings on webpack@5.
Fixed #1194

* Removed redundant `!!` in `module.addError` checks

* Version update to 8.0.5
  • Loading branch information
sanex3339 authored Oct 13, 2020
1 parent cafc933 commit 6d8d601
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v8.0.5
* [Fixed deprecation warnings on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1194) - thanks @sanex3339

## v8.0.4
* [Uses existing instance if config file is same as already built solution](https://github.com/TypeStrong/ts-loader/pull/1177) - thanks @sheetalkamat

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.0.4",
"version": "8.0.5",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ function getTranspilationEmit(
reportDiagnostics: true,
fileName,
});
const module = loaderContext._module;

addDependenciesFromSolutionBuilder(instance, fileName, file =>
loaderContext.addDependency(path.resolve(file))
Expand All @@ -644,11 +645,19 @@ function getTranspilationEmit(
instance.loaderOptions,
instance.colors,
instance.compiler,
{ module: loaderContext._module },
{ module },
loaderContext.context
);

loaderContext._module.errors.push(...errors);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
errors.forEach(error => module.addError(error));
} else {
module.errors.push(...errors);
}
}

return { outputText, sourceMapText };
Expand Down
22 changes: 20 additions & 2 deletions src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function successfulTypeScriptInstance(
}
}

const module = loader._module;
const basePath = loaderOptions.context || path.dirname(configFilePath || '');
const configParseResult = getConfigParseResult(
compiler,
Expand All @@ -165,7 +166,15 @@ function successfulTypeScriptInstance(
loader.context
);

loader._module.errors.push(...errors);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
errors.forEach(error => module.addError(error));
} else {
module.errors.push(...errors);
}

return {
error: makeError(
Expand Down Expand Up @@ -415,6 +424,7 @@ export function reportTranspileErrors(
if (!instance.reportTranspileErrors) {
return;
}
const module = loader._module;
instance.reportTranspileErrors = false;
// happypack does not have _module.errors - see https://github.com/TypeStrong/ts-loader/issues/336
if (!instance.loaderOptions.happyPackMode) {
Expand All @@ -431,7 +441,15 @@ export function reportTranspileErrors(
{ file: instance.configFilePath || 'tsconfig.json' },
loader.context
);
loader._module.errors.push(...solutionErrors, ...errors);
/**
* Since webpack 5, the `errors` property is deprecated,
* so we can check if some methods for reporting errors exist.
*/
if (module.addError) {
[...solutionErrors, ...errors].forEach(error => module.addError(error));
} else {
module.errors.push(...solutionErrors, ...errors);
}
}
}

Expand Down

0 comments on commit 6d8d601

Please sign in to comment.