Skip to content

Commit

Permalink
Fix 2 issues with experimentalWatchApi (#1159)
Browse files Browse the repository at this point in the history
* 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 <johnny_reilly@hotmail.com>
  • Loading branch information
appzuka and johnnyreilly committed Aug 1, 2020
1 parent a77470f commit 2f6cbe8
Show file tree
Hide file tree
Showing 27 changed files with 366 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v8.0.2

* [Fix 2 issues with experimentalWatchApi](https://github.com/TypeStrong/ts-loader/pull/1159) - thanks @appzuka

## v8.0.1

* [Fix webpack deprecations](https://github.com/TypeStrong/ts-loader/pull/1135) - thanks @g-plane
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.0.1",
"version": "8.0.2",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -383,6 +383,11 @@ function updateFileInCache(
}
}

// Added in case the files were already updated by the watch API
if (instance.modifiedFiles && instance.modifiedFiles.get(key)) {
fileWatcherEventKind = instance.compiler.FileWatcherEventKind.Changed;
}

if (instance.watchHost !== undefined && fileWatcherEventKind !== undefined) {
instance.hasUnaccountedModifiedFiles =
instance.watchHost.invokeFileWatcher(filePath, fileWatcherEventKind) ||
Expand Down
7 changes: 4 additions & 3 deletions src/instances.ts
Expand Up @@ -689,15 +689,16 @@ export function getEmitFromWatchHost(instance: TSInstance, filePath?: string) {
if (!result) {
break;
}
if ((result.affected as typescript.SourceFile).fileName) {

// Only put the output file in the cache if the source came from webpack and
// was processed by the loaders
if (result.affected === sourceFile) {
instance.watchHost!.outputFiles.set(
instance.filePathKeyMapper(
(result.affected as typescript.SourceFile).fileName
),
outputFiles.slice()
);
}
if (result.affected === sourceFile) {
return outputFiles;
}
}
Expand Down
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

Expand Down
@@ -1,7 +1,8 @@
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.85 KiB main [emitted] main
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.97 KiB main [emitted] main
tsconfig.tsbuildinfo 1.72 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 131 bytes {main} [built]
[./app.ts] 215 bytes {main} [built]
[./lib/helper.ts] 138 bytes {main}
[./lib/index.ts] 224 bytes {main}
@@ -0,0 +1,63 @@
{
"program": {
"fileInfos": {
"../../node_modules/typescript/lib/lib.d.ts": {
"version": "-10496480823",
"signature": "-10496480823",
"affectsGlobalScope": false
},
"../../node_modules/typescript/lib/lib.es5.d.ts": {
"version": "-218882352090",
"signature": "-218882352090",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.dom.d.ts": {
"version": "300634082611",
"signature": "300634082611",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts": {
"version": "-24714112149",
"signature": "-24714112149",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.scripthost.d.ts": {
"version": "204309182321",
"signature": "204309182321",
"affectsGlobalScope": true
},
"./lib/index.d.ts": {
"version": "11215156582",
"signature": "11215156582",
"affectsGlobalScope": false
},
"./lib/helper.d.ts": {
"version": "7897218607",
"signature": "7897218607",
"affectsGlobalScope": false
},
"./app.ts": {
"version": "-12553192154",
"signature": "-3531856636",
"affectsGlobalScope": false
}
},
"options": {
"types": [],
"composite": true,
"newLine": 1,
"configFilePath": "./tsconfig.json",
"skipLibCheck": true,
"suppressOutputPathCheck": true
},
"referencedMap": {
"./app.ts": [
"./lib/helper.d.ts",
"./lib/index.d.ts"
]
},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": []
},
"version": "3.9.3"
}
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

Expand Down
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

Expand Down
@@ -1,7 +1,8 @@
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.83 KiB main [emitted] main
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.95 KiB main [emitted] main
tsconfig.tsbuildinfo 1.72 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 131 bytes {main} [built]
[./app.ts] 215 bytes {main} [built]
[./lib/helper.ts] 138 bytes {main}
[./lib/index.ts] 211 bytes {main}
@@ -0,0 +1,63 @@
{
"program": {
"fileInfos": {
"../../node_modules/typescript/lib/lib.d.ts": {
"version": "-10496480823",
"signature": "-10496480823",
"affectsGlobalScope": false
},
"../../node_modules/typescript/lib/lib.es5.d.ts": {
"version": "-218882352090",
"signature": "-218882352090",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.dom.d.ts": {
"version": "300634082611",
"signature": "300634082611",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts": {
"version": "-24714112149",
"signature": "-24714112149",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.scripthost.d.ts": {
"version": "204309182321",
"signature": "204309182321",
"affectsGlobalScope": true
},
"./lib/index.d.ts": {
"version": "12503634626",
"signature": "12503634626",
"affectsGlobalScope": false
},
"./lib/helper.d.ts": {
"version": "7897218607",
"signature": "7897218607",
"affectsGlobalScope": false
},
"./app.ts": {
"version": "-12553192154",
"signature": "-3531856636",
"affectsGlobalScope": false
}
},
"options": {
"types": [],
"composite": true,
"newLine": 1,
"configFilePath": "./tsconfig.json",
"skipLibCheck": true,
"suppressOutputPathCheck": true
},
"referencedMap": {
"./app.ts": [
"./lib/helper.d.ts",
"./lib/index.d.ts"
]
},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": []
},
"version": "3.9.3"
}
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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?");

/***/ }),

Expand Down
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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, lib_1.lib.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");

/***/ }),

Expand Down
@@ -1,6 +1,7 @@
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.33 KiB main [emitted] main
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.37 KiB main [emitted] main
tsconfig.tsbuildinfo 1.56 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 131 bytes {main} [built]
[./app.ts] 169 bytes {main} [built]
[./lib/index.ts] 150 bytes {main}
@@ -0,0 +1,57 @@
{
"program": {
"fileInfos": {
"../../node_modules/typescript/lib/lib.d.ts": {
"version": "-10496480823",
"signature": "-10496480823",
"affectsGlobalScope": false
},
"../../node_modules/typescript/lib/lib.es5.d.ts": {
"version": "-218882352090",
"signature": "-218882352090",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.dom.d.ts": {
"version": "300634082611",
"signature": "300634082611",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts": {
"version": "-24714112149",
"signature": "-24714112149",
"affectsGlobalScope": true
},
"../../node_modules/typescript/lib/lib.scripthost.d.ts": {
"version": "204309182321",
"signature": "204309182321",
"affectsGlobalScope": true
},
"./lib/index.d.ts": {
"version": "11215156582",
"signature": "11215156582",
"affectsGlobalScope": false
},
"./app.ts": {
"version": "-16299197056",
"signature": "-3531856636",
"affectsGlobalScope": false
}
},
"options": {
"types": [],
"composite": true,
"newLine": 1,
"configFilePath": "./tsconfig.json",
"skipLibCheck": true,
"suppressOutputPathCheck": true
},
"referencedMap": {
"./app.ts": [
"./lib/index.d.ts"
]
},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": []
},
"version": "3.9.3"
}
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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?");
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, lib_1.lib.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");

/***/ }),

Expand Down
Expand Up @@ -94,7 +94,7 @@
/***/ (function(module, exports, __webpack_require__) {

"use strict";
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, lib_1.lib.four); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");
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, lib_1.lib.four, lib_1.lib.ffive); // consume new number\n\n\n//# sourceURL=webpack:///./app.ts?");

/***/ }),

Expand All @@ -106,7 +106,7 @@ eval("\nexports.__esModule = true;\nvar lib_1 = __webpack_require__(/*! ./lib */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\r\nexports.__esModule = true;\r\nexports.lib = void 0;\r\nexports.lib = {\r\n one: 1,\r\n two: 2,\r\n three: 3,\r\n four: 4,\r\n five: 5\r\n};\r\n\n\n//# sourceURL=webpack:///./lib/index.ts?");
eval("\nexports.__esModule = true;\nexports.lib = void 0;\nexports.lib = {\n one: 1,\n two: 2,\n three: 3,\n four: 4,\n five: 5\n};\n\n\n//# sourceURL=webpack:///./lib/index.ts?");

/***/ })

Expand Down
@@ -1,6 +1,12 @@
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.37 KiB main [emitted] main
Asset Size Chunks Chunk Names
app.d.ts 11 bytes [emitted]
bundle.js 4.38 KiB main [emitted] main
tsconfig.tsbuildinfo 1.56 KiB [emitted]
Entrypoint main = bundle.js
[./app.ts] 169 bytes {main} [built]
[./lib/index.ts] 145 bytes {main}
[./app.ts] 186 bytes {main} [built] [1 error]
[./lib/index.ts] 145 bytes {main}

ERROR in app.ts
./app.ts
[tsl] ERROR in app.ts(3,56)
 TS2551: Property 'ffive' does not exist on type '{ one: number; two: number; three: number; four: number; five: number; }'. Did you mean 'five'?

0 comments on commit 2f6cbe8

Please sign in to comment.