From 94a112f846ff911638ab8878de6d93368b60f42a Mon Sep 17 00:00:00 2001 From: Einat Bertenthal Date: Tue, 8 Mar 2022 15:49:26 +0200 Subject: [PATCH 1/4] Bug fix: support webpack 5 in ts-loader Error when running ts-loader with webpack 5 : "times is not iterable" --- src/watch-run.ts | 56 +++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/watch-run.ts b/src/watch-run.ts index 34acaed57..566365dd3 100644 --- a/src/watch-run.ts +++ b/src/watch-run.ts @@ -29,36 +29,38 @@ export function makeWatchRun( if (instance.loaderOptions.transpileOnly) { instance.reportTranspileErrors = true; } else { - const times = compiler.fileTimestamps; + compiler.hooks.compilation.tap('ts-loader', compiliation => { + compiliation.fileSystemInfo._fileTimestamps.stack.forEach(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) + ); + } + } + }) + }) } // Update all the watched files from solution builder From 641cfe79c00a86038c7595a9611d40ca790ce171 Mon Sep 17 00:00:00 2001 From: Einat Bertenthal Date: Thu, 10 Mar 2022 12:52:23 +0200 Subject: [PATCH 2/4] fix: guard compiler.fileTimestamps --- src/watch-run.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/watch-run.ts b/src/watch-run.ts index 566365dd3..1b5498d07 100644 --- a/src/watch-run.ts +++ b/src/watch-run.ts @@ -29,8 +29,8 @@ export function makeWatchRun( if (instance.loaderOptions.transpileOnly) { instance.reportTranspileErrors = true; } else { - compiler.hooks.compilation.tap('ts-loader', compiliation => { - compiliation.fileSystemInfo._fileTimestamps.stack.forEach(times => { + const times = compiler.fileTimestamps; + if (times) { for (const [filePath, date] of times) { const key = instance.filePathKeyMapper(filePath); const lastTime = lastTimes.get(key) || startTime; @@ -58,9 +58,8 @@ export function makeWatchRun( updateFile(instance, key, fileName, loader, loaderIndex) ); } - } - }) - }) + } + } } // Update all the watched files from solution builder From c73fe3863e2c6a156e05c4c05245b415f141c320 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Thu, 10 Mar 2022 19:21:33 +0000 Subject: [PATCH 3/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 3378f1103272f5a865410929942f7fc7b13ef58e Mon Sep 17 00:00:00 2001 From: John Reilly Date: Thu, 10 Mar 2022 19:23:40 +0000 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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