Skip to content

Commit

Permalink
Bug fix: support webpack 5 in ts-loader (#1439)
Browse files Browse the repository at this point in the history
* Bug fix: support webpack 5 in ts-loader

Error when running ts-loader with webpack 5 : "times is not iterable"

* fix: guard compiler.fileTimestamps

* Update package.json

* Update CHANGELOG.md

Co-authored-by: John Reilly <johnny_reilly@hotmail.com>
  • Loading branch information
einatbar and johnnyreilly authored Mar 10, 2022
1 parent 65bb27c commit 12f4ffe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## v9.2.8

* [Bug fix: support webpack 5 in ts-loader](https://github.com/TypeStrong/ts-loader/pull/1439) [#1438] - thanks @einatbar

## v9.2.7

* [cater for change in resolveTypeReferenceDirective API in TypeScript 4.7](https://github.com/TypeStrong/ts-loader/pull/1422) [#1421] - thanks @johnny_reilly and @cspotcode for inspiration in ts-node work here: https://github.com/TypeStrong/ts-node/pull/1648
* [cater for change in resolveTypeReferenceDirective API in TypeScript 4.7](https://github.com/TypeStrong/ts-loader/pull/1422) [#1421] - thanks @johnny_reilly and @cspotcode for inspiration in ts-node work here: https://github.com/TypeStrong/ts-node/pull/1648

## v9.2.6

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": "9.2.7",
"version": "9.2.8",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
51 changes: 26 additions & 25 deletions src/watch-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,35 @@ export function makeWatchRun(
instance.reportTranspileErrors = true;
} else {
const times = compiler.fileTimestamps;
if (times) {
for (const [filePath, date] of times) {
const key = instance.filePathKeyMapper(filePath);
const lastTime = lastTimes.get(key) || startTime;

for (const [filePath, date] of times) {
const key = instance.filePathKeyMapper(filePath);
const lastTime = lastTimes.get(key) || startTime;
if (
!date ||
date === 'ignore' ||
(date.timestamp || date.safeTime) <= lastTime
) {
continue;
}

if (
!date ||
date === 'ignore' ||
(date.timestamp || date.safeTime) <= lastTime
) {
continue;
}

lastTimes.set(key, date.timestamp || date.safeTime);
promises.push(updateFile(instance, key, filePath, loader, loaderIndex));
}
lastTimes.set(key, date.timestamp || date.safeTime);
promises.push(updateFile(instance, key, filePath, loader, loaderIndex));
}

// On watch update add all known dts files expect the ones in node_modules
// (skip @types/* and modules with typings)
for (const [key, { fileName }] of instance.files.entries()) {
if (
fileName.match(constants.dtsDtsxOrDtsDtsxMapRegex) !== null &&
fileName.match(constants.nodeModules) === null
) {
promises.push(
updateFile(instance, key, fileName, loader, loaderIndex)
);
}
// On watch update add all known dts files expect the ones in node_modules
// (skip @types/* and modules with typings)
for (const [key, { fileName }] of instance.files.entries()) {
if (
fileName.match(constants.dtsDtsxOrDtsDtsxMapRegex) !== null &&
fileName.match(constants.nodeModules) === null
) {
promises.push(
updateFile(instance, key, fileName, loader, loaderIndex)
);
}
}
}
}

Expand Down

0 comments on commit 12f4ffe

Please sign in to comment.