Skip to content

Commit 2f6cbe8

Browse files
Fix 2 issues with experimentalWatchApi (#1159)
* Detect if files already updated by watchAPI * Only put files in cache if processed by loaders * Update comparison tests * Remove npm command for debugging tests * Remove package-lock.json * Update version & Changelog Co-authored-by: John Reilly <[email protected]>
1 parent a77470f commit 2f6cbe8

File tree

27 files changed

+366
-44
lines changed

27 files changed

+366
-44
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v8.0.2
4+
5+
* [Fix 2 issues with experimentalWatchApi](https://github.com/TypeStrong/ts-loader/pull/1159) - thanks @appzuka
6+
37
## v8.0.1
48

59
* [Fix webpack deprecations](https://github.com/TypeStrong/ts-loader/pull/1135) - thanks @g-plane

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.1",
3+
"version": "8.0.2",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ function updateFileInCache(
383383
}
384384
}
385385

386+
// Added in case the files were already updated by the watch API
387+
if (instance.modifiedFiles && instance.modifiedFiles.get(key)) {
388+
fileWatcherEventKind = instance.compiler.FileWatcherEventKind.Changed;
389+
}
390+
386391
if (instance.watchHost !== undefined && fileWatcherEventKind !== undefined) {
387392
instance.hasUnaccountedModifiedFiles =
388393
instance.watchHost.invokeFileWatcher(filePath, fileWatcherEventKind) ||

src/instances.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,16 @@ export function getEmitFromWatchHost(instance: TSInstance, filePath?: string) {
689689
if (!result) {
690690
break;
691691
}
692-
if ((result.affected as typescript.SourceFile).fileName) {
692+
693+
// Only put the output file in the cache if the source came from webpack and
694+
// was processed by the loaders
695+
if (result.affected === sourceFile) {
693696
instance.watchHost!.outputFiles.set(
694697
instance.filePathKeyMapper(
695698
(result.affected as typescript.SourceFile).fileName
696699
),
697700
outputFiles.slice()
698701
);
699-
}
700-
if (result.affected === sourceFile) {
701702
return outputFiles;
702703
}
703704
}

test/comparison-tests/projectReferencesWatchRefWithTwoFilesAlreadyBuilt_Composite_WatchApi/expectedOutput-3.9/patch2/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
/***/ (function(module, exports, __webpack_require__) {
9595

9696
"use strict";
97-
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\n\n\n//# sourceURL=webpack:///./app.ts?");
97+
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nvar helper_1 = __webpack_require__(/*! ./lib/helper */ \"./lib/helper.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three, helper_1.helper.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
9898

9999
/***/ }),
100100

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Asset Size Chunks Chunk Names
2-
app.d.ts 11 bytes [emitted]
3-
bundle.js 4.85 KiB main [emitted] main
1+
Asset Size Chunks Chunk Names
2+
app.d.ts 11 bytes [emitted]
3+
bundle.js 4.97 KiB main [emitted] main
4+
tsconfig.tsbuildinfo 1.72 KiB [emitted]
45
Entrypoint main = bundle.js
5-
[./app.ts] 131 bytes {main} [built]
6+
[./app.ts] 215 bytes {main} [built]
67
[./lib/helper.ts] 138 bytes {main}
78
[./lib/index.ts] 224 bytes {main}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"program": {
3+
"fileInfos": {
4+
"../../node_modules/typescript/lib/lib.d.ts": {
5+
"version": "-10496480823",
6+
"signature": "-10496480823",
7+
"affectsGlobalScope": false
8+
},
9+
"../../node_modules/typescript/lib/lib.es5.d.ts": {
10+
"version": "-218882352090",
11+
"signature": "-218882352090",
12+
"affectsGlobalScope": true
13+
},
14+
"../../node_modules/typescript/lib/lib.dom.d.ts": {
15+
"version": "300634082611",
16+
"signature": "300634082611",
17+
"affectsGlobalScope": true
18+
},
19+
"../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts": {
20+
"version": "-24714112149",
21+
"signature": "-24714112149",
22+
"affectsGlobalScope": true
23+
},
24+
"../../node_modules/typescript/lib/lib.scripthost.d.ts": {
25+
"version": "204309182321",
26+
"signature": "204309182321",
27+
"affectsGlobalScope": true
28+
},
29+
"./lib/index.d.ts": {
30+
"version": "11215156582",
31+
"signature": "11215156582",
32+
"affectsGlobalScope": false
33+
},
34+
"./lib/helper.d.ts": {
35+
"version": "7897218607",
36+
"signature": "7897218607",
37+
"affectsGlobalScope": false
38+
},
39+
"./app.ts": {
40+
"version": "-12553192154",
41+
"signature": "-3531856636",
42+
"affectsGlobalScope": false
43+
}
44+
},
45+
"options": {
46+
"types": [],
47+
"composite": true,
48+
"newLine": 1,
49+
"configFilePath": "./tsconfig.json",
50+
"skipLibCheck": true,
51+
"suppressOutputPathCheck": true
52+
},
53+
"referencedMap": {
54+
"./app.ts": [
55+
"./lib/helper.d.ts",
56+
"./lib/index.d.ts"
57+
]
58+
},
59+
"exportedModulesMap": {},
60+
"semanticDiagnosticsPerFile": []
61+
},
62+
"version": "3.9.3"
63+
}

test/comparison-tests/projectReferencesWatchRefWithTwoFilesAlreadyBuilt_WatchApi/expectedOutput-3.9/patch2/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
/***/ (function(module, exports, __webpack_require__) {
9595

9696
"use strict";
97-
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\n\n\n//# sourceURL=webpack:///./app.ts?");
97+
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nvar helper_1 = __webpack_require__(/*! ./lib/helper */ \"./lib/helper.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three, helper_1.helper.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
9898

9999
/***/ }),
100100

test/comparison-tests/projectReferencesWatchRefWithTwoFiles_Composite_WatchApi/expectedOutput-3.9/patch1/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
/***/ (function(module, exports, __webpack_require__) {
9595

9696
"use strict";
97-
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\n\n\n//# sourceURL=webpack:///./app.ts?");
97+
eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nvar helper_1 = __webpack_require__(/*! ./lib/helper */ \"./lib/helper.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three, helper_1.helper.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
9898

9999
/***/ }),
100100

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
Asset Size Chunks Chunk Names
2-
app.d.ts 11 bytes [emitted]
3-
bundle.js 4.83 KiB main [emitted] main
1+
Asset Size Chunks Chunk Names
2+
app.d.ts 11 bytes [emitted]
3+
bundle.js 4.95 KiB main [emitted] main
4+
tsconfig.tsbuildinfo 1.72 KiB [emitted]
45
Entrypoint main = bundle.js
5-
[./app.ts] 131 bytes {main} [built]
6+
[./app.ts] 215 bytes {main} [built]
67
[./lib/helper.ts] 138 bytes {main}
78
[./lib/index.ts] 211 bytes {main}

0 commit comments

Comments
 (0)