From 12f4ffe738abcdb2ad7f18d6f6724d89d8cc1cfc Mon Sep 17 00:00:00 2001 From: Einat Bertenthal Date: Thu, 10 Mar 2022 22:40:49 +0200 Subject: [PATCH] Bug fix: support webpack 5 in ts-loader (#1439) * 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 --- CHANGELOG.md | 6 +++++- package.json | 2 +- src/watch-run.ts | 51 ++++++++++++++++++++++++------------------------ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdeb5b584..128fa057f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index 2e13d4e78..29f01fc3b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/watch-run.ts b/src/watch-run.ts index 34acaed57..1b5498d07 100644 --- a/src/watch-run.ts +++ b/src/watch-run.ts @@ -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) + ); + } + } } }