Skip to content

Commit a8597e3

Browse files
authored
Fixed generating cache for loading options to handle objects (#1317)
* fix: Fixed generating cache for loading options to handle objects Fixes #1316 * fix: Updated ts-loader instance hash in tests * Added changelog and changed version in package.json
1 parent 94480fb commit a8597e3

File tree

80 files changed

+398
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+398
-84
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+
## v9.2.0
4+
5+
* [Fixed impossibility to have several instances of ts-loader with different compiler options](https://github.com/TypeStrong/ts-loader/issues/1316) - thanks @timocov
6+
37
## v9.1.2
48

59
* [Fix removed files handling in watch mode](https://github.com/TypeStrong/ts-loader/pull/1293) - thanks @gasnier

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": "9.1.2",
3+
"version": "9.2.0",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ function getOptionsHash(loaderOptions: LoaderOptions) {
161161
const hash = crypto.createHash('sha256');
162162
Object.keys(loaderOptions).forEach(key => {
163163
const value = loaderOptions[key];
164-
if (value) {
165-
hash.update(key + value.toString());
164+
if (value !== undefined) {
165+
const valueString =
166+
typeof value === 'function' ? value.toString() : JSON.stringify(value);
167+
hash.update(key + valueString);
166168
}
167169
});
168170
return hash.digest('hex').substring(0, 16);

test/comparison-tests/aliasResolution/expectedOutput-4.2/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ ERROR in app.ts
66
./app.ts 1:29-53
77
[tsl] ERROR in app.ts(1,30)
88
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
9-
ts-loader-default_b02295d909a3e7cf
9+
ts-loader-default_609318b4f68865d3
1010

1111
ERROR in app.ts
1212
./app.ts 2:30-55
1313
[tsl] ERROR in app.ts(2,31)
1414
 TS2307: Cannot find module 'components/myComponent2' or its corresponding type declarations.
15-
ts-loader-default_b02295d909a3e7cf
15+
ts-loader-default_609318b4f68865d3
1616

1717
webpack compiled with 2 errors

test/comparison-tests/aliasResolution/expectedOutput-4.2/patch0/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ ERROR in app.ts
66
./app.ts 1:29-53
77
[tsl] ERROR in app.ts(1,30)
88
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
9-
ts-loader-default_b02295d909a3e7cf
9+
ts-loader-default_609318b4f68865d3
1010

1111
ERROR in app.ts
1212
./app.ts 2:30-55
1313
[tsl] ERROR in app.ts(2,31)
1414
 TS2307: Cannot find module 'components/myComponent2' or its corresponding type declarations.
15-
ts-loader-default_b02295d909a3e7cf
15+
ts-loader-default_609318b4f68865d3
1616

1717
webpack compiled with 2 errors

test/comparison-tests/allowJs-ts-check/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ERROR in src/error2.js
77
./src/error2.js 4:9-12
88
[tsl] ERROR in src/error2.js(4,10)
99
 TS2339: Property 'bar' does not exist on type 'Class2'.
10-
ts-loader-default_b02295d909a3e7cf
10+
ts-loader-default_609318b4f68865d3
1111
@ ./src/index.js 4:15-34
1212

1313
webpack compiled with 1 error

test/comparison-tests/basic/expectedOutput-4.2/patch0/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ ERROR in app.ts
66
./app.ts 3:12-24
77
[tsl] ERROR in app.ts(3,13)
88
 TS2551: Property 'doSomething2' does not exist on type 'typeof externalLib'. Did you mean 'doSomething'?
9-
ts-loader-default_b02295d909a3e7cf
9+
ts-loader-default_609318b4f68865d3
1010

1111
webpack compiled with 1 error

test/comparison-tests/colors/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ ERROR in app.ts
1414
./app.ts 1:6-8
1515
[tsl] ERROR in app.ts(1,7)
1616
TS1005: ',' expected.
17-
ts-loader-default_b02295d909a3e7cf
17+
ts-loader-default_dda4fd88600de236
1818

1919
webpack compiled with 2 errors

test/comparison-tests/colors/expectedOutput-transpile-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ERROR in app.ts
55
./app.ts 1:6-8
66
[tsl] ERROR in app.ts(1,7)
77
TS1005: ',' expected.
8-
ts-loader-default_66eeaf8be3a46130
8+
ts-loader-default_94b2ce3d1ca5f363
99

1010
ERROR in ./app.ts 2:1
1111
Module parse failed: Unexpected token (2:1)

test/comparison-tests/declarationDeps/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ ERROR in app.ts
55
./app.ts 2:6-11
66
[tsl] ERROR in app.ts(2,7)
77
 TS2339: Property 'sayHi' does not exist on type 'typeof Hello'.
8-
ts-loader-default_b02295d909a3e7cf
8+
ts-loader-default_609318b4f68865d3
99

1010
webpack compiled with 1 error

test/comparison-tests/declarationWatch/expectedOutput-4.2/patch0/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ ERROR in app.ts
66
./app.ts 5:6-17
77
[tsl] ERROR in app.ts(5,7)
88
 TS2339: Property 'doSomething' does not exist on type 'typeof Thing'.
9-
ts-loader-default_b02295d909a3e7cf
9+
ts-loader-default_609318b4f68865d3
1010

1111
ERROR in dep.ts
1212
./dep.ts 1:6-17
1313
[tsl] ERROR in dep.ts(1,7)
1414
 TS2339: Property 'doSomething' does not exist on type 'typeof Thing'.
15-
ts-loader-default_b02295d909a3e7cf
15+
ts-loader-default_609318b4f68865d3
1616
@ ./app.ts 3:10-26
1717

1818
webpack compiled with 2 errors

test/comparison-tests/dependencyErrors/expectedOutput-4.2/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ ERROR in app.ts
77
./app.ts 4:5-7
88
[tsl] ERROR in app.ts(4,6)
99
 TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
10-
ts-loader-default_b02295d909a3e7cf
10+
ts-loader-default_609318b4f68865d3
1111

1212
ERROR in app.ts
1313
./app.ts 5:5-7
1414
[tsl] ERROR in app.ts(5,6)
1515
 TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
16-
ts-loader-default_b02295d909a3e7cf
16+
ts-loader-default_609318b4f68865d3
1717

1818
webpack compiled with 2 errors

test/comparison-tests/dependencyErrors/expectedOutput-4.2/patch0/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ ERROR in app.ts
77
./app.ts 5:5-7
88
[tsl] ERROR in app.ts(5,6)
99
 TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
10-
ts-loader-default_b02295d909a3e7cf
10+
ts-loader-default_609318b4f68865d3
1111

1212
webpack compiled with 1 error

test/comparison-tests/errorFormatter/expectedOutput-4.2/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ asset bundle.js 2.6 KiB [emitted] (name: main)
55
ERROR in app.ts
66
./app.ts 1:29-53
77
Does not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent' or its corresponding type declarations.,file: app.ts,line: 1,character: 30,context: .test/errorFormatter
8-
ts-loader-default_6241146af0584e95
8+
ts-loader-default_85b0565984bbe8dd
99

1010
ERROR in app.ts
1111
./app.ts 2:30-55
1212
Does not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent2' or its corresponding type declarations.,file: app.ts,line: 2,character: 31,context: .test/errorFormatter
13-
ts-loader-default_6241146af0584e95
13+
ts-loader-default_85b0565984bbe8dd
1414

1515
webpack compiled with 2 errors

test/comparison-tests/errors/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ ERROR in app.ts
1414
./app.ts 1:6-8
1515
[tsl] ERROR in app.ts(1,7)
1616
 TS1005: ',' expected.
17-
ts-loader-default_b02295d909a3e7cf
17+
ts-loader-default_609318b4f68865d3
1818

1919
webpack compiled with 2 errors

test/comparison-tests/errors/expectedOutput-transpile-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ERROR in app.ts
55
./app.ts 1:6-8
66
[tsl] ERROR in app.ts(1,7)
77
 TS1005: ',' expected.
8-
ts-loader-default_66eeaf8be3a46130
8+
ts-loader-default_de8929d96064b0d0
99

1010
ERROR in ./app.ts 2:1
1111
Module parse failed: Unexpected token (2:1)

test/comparison-tests/es3/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ ERROR in app.ts
55
./app.ts 1:6-7
66
[tsl] ERROR in app.ts(1,7)
77
 TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
8-
ts-loader-default_b02295d909a3e7cf
8+
ts-loader-default_609318b4f68865d3
99

1010
webpack compiled with 1 error

test/comparison-tests/ignoreDiagnostics/expectedOutput-4.2/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ ERROR in app.ts
55
./app.ts 9:4-5
66
[tsl] ERROR in app.ts(9,5)
77
 TS2322: Type 'string' is not assignable to type 'Number'.
8-
ts-loader-default_cf939062d980a567
8+
ts-loader-default_2830fdd0bda34e31
99

1010
webpack compiled with 1 error

test/comparison-tests/importsWatch/expectedOutput-4.2/patch1/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ ERROR in app.ts
55
./app.ts 4:0-7
66
[tsl] ERROR in app.ts(4,1)
77
 TS2322: Type 'string' is not assignable to type 'boolean'.
8-
ts-loader-default_b02295d909a3e7cf
8+
ts-loader-default_609318b4f68865d3
99

1010
webpack compiled with 1 error
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './submodule-es5';
2+
import './submodule-es6';
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
3+
* This devtool is neither made for production nor for readable output files.
4+
* It uses "eval()" calls to create a separate source file in the browser devtools.
5+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6+
* or disable the default devtool with "devtool: false".
7+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8+
*/
9+
/******/ (() => { // webpackBootstrap
10+
/******/ var __webpack_modules__ = ({
11+
12+
/***/ "./app.ts":
13+
/*!****************!*\
14+
!*** ./app.ts ***!
15+
\****************/
16+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
17+
18+
"use strict";
19+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./submodule-es5 */ \"./submodule-es5/index.ts\");\n/* harmony import */ var _submodule_es5__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_submodule_es5__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./submodule-es6 */ \"./submodule-es6/index.ts\");\n/* harmony import */ var _submodule_es6__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_submodule_es6__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\n\n//# sourceURL=webpack:///./app.ts?");
20+
21+
/***/ }),
22+
23+
/***/ "./submodule-es6/index.ts":
24+
/*!********************************!*\
25+
!*** ./submodule-es6/index.ts ***!
26+
\********************************/
27+
/***/ (() => {
28+
29+
eval("const set = new Set([42]);\r\nfor (const value of set) {\r\n console.log(value);\r\n}\r\nconst string = 'Hello from es6 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es6/index.ts?");
30+
31+
/***/ }),
32+
33+
/***/ "./submodule-es5/index.ts":
34+
/*!********************************!*\
35+
!*** ./submodule-es5/index.ts ***!
36+
\********************************/
37+
/***/ (() => {
38+
39+
eval("var string = 'Hello from es5 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es5/index.ts?");
40+
41+
/***/ })
42+
43+
/******/ });
44+
/************************************************************************/
45+
/******/ // The module cache
46+
/******/ var __webpack_module_cache__ = {};
47+
/******/
48+
/******/ // The require function
49+
/******/ function __webpack_require__(moduleId) {
50+
/******/ // Check if module is in cache
51+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
52+
/******/ if (cachedModule !== undefined) {
53+
/******/ return cachedModule.exports;
54+
/******/ }
55+
/******/ // Create a new module (and put it into the cache)
56+
/******/ var module = __webpack_module_cache__[moduleId] = {
57+
/******/ // no module.id needed
58+
/******/ // no module.loaded needed
59+
/******/ exports: {}
60+
/******/ };
61+
/******/
62+
/******/ // Execute the module function
63+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
64+
/******/
65+
/******/ // Return the exports of the module
66+
/******/ return module.exports;
67+
/******/ }
68+
/******/
69+
/************************************************************************/
70+
/******/ /* webpack/runtime/compat get default export */
71+
/******/ (() => {
72+
/******/ // getDefaultExport function for compatibility with non-harmony modules
73+
/******/ __webpack_require__.n = (module) => {
74+
/******/ var getter = module && module.__esModule ?
75+
/******/ () => (module['default']) :
76+
/******/ () => (module);
77+
/******/ __webpack_require__.d(getter, { a: getter });
78+
/******/ return getter;
79+
/******/ };
80+
/******/ })();
81+
/******/
82+
/******/ /* webpack/runtime/define property getters */
83+
/******/ (() => {
84+
/******/ // define getter functions for harmony exports
85+
/******/ __webpack_require__.d = (exports, definition) => {
86+
/******/ for(var key in definition) {
87+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
88+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
89+
/******/ }
90+
/******/ }
91+
/******/ };
92+
/******/ })();
93+
/******/
94+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
95+
/******/ (() => {
96+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
97+
/******/ })();
98+
/******/
99+
/******/ /* webpack/runtime/make namespace object */
100+
/******/ (() => {
101+
/******/ // define __esModule on exports
102+
/******/ __webpack_require__.r = (exports) => {
103+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
104+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
105+
/******/ }
106+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
107+
/******/ };
108+
/******/ })();
109+
/******/
110+
/************************************************************************/
111+
/******/
112+
/******/ // startup
113+
/******/ // Load entry module and return exports
114+
/******/ // This entry module can't be inlined because the eval devtool is used.
115+
/******/ var __webpack_exports__ = __webpack_require__("./app.ts");
116+
/******/
117+
/******/ })()
118+
;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
asset bundle.js 5.1 KiB [emitted] (name: main)
2+
runtime modules 937 bytes 4 modules
3+
cacheable modules 256 bytes
4+
./app.ts 52 bytes [built] [code generated]
5+
./submodule-es5/index.ts 59 bytes [built] [code generated]
6+
./submodule-es6/index.ts 145 bytes [built] [code generated]
7+
webpack compiled successfully

0 commit comments

Comments
 (0)