Skip to content

Commit

Permalink
Fixed generating cache for loading options to handle objects (#1317)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
timocov committed May 18, 2021
1 parent 94480fb commit a8597e3
Show file tree
Hide file tree
Showing 80 changed files with 398 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v9.2.0

* [Fixed impossibility to have several instances of ts-loader with different compiler options](https://github.com/TypeStrong/ts-loader/issues/1316) - thanks @timocov

## v9.1.2

* [Fix removed files handling in watch mode](https://github.com/TypeStrong/ts-loader/pull/1293) - thanks @gasnier
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "9.1.2",
"version": "9.2.0",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Expand Up @@ -161,8 +161,10 @@ function getOptionsHash(loaderOptions: LoaderOptions) {
const hash = crypto.createHash('sha256');
Object.keys(loaderOptions).forEach(key => {
const value = loaderOptions[key];
if (value) {
hash.update(key + value.toString());
if (value !== undefined) {
const valueString =
typeof value === 'function' ? value.toString() : JSON.stringify(value);
hash.update(key + valueString);
}
});
return hash.digest('hex').substring(0, 16);
Expand Down
Expand Up @@ -6,12 +6,12 @@ ERROR in app.ts
./app.ts 1:29-53
[tsl] ERROR in app.ts(1,30)
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

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

webpack compiled with 2 errors
Expand Up @@ -6,12 +6,12 @@ ERROR in app.ts
./app.ts 1:29-53
[tsl] ERROR in app.ts(1,30)
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

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

webpack compiled with 2 errors
Expand Up @@ -7,7 +7,7 @@ ERROR in src/error2.js
./src/error2.js 4:9-12
[tsl] ERROR in src/error2.js(4,10)
 TS2339: Property 'bar' does not exist on type 'Class2'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3
@ ./src/index.js 4:15-34

webpack compiled with 1 error
Expand Up @@ -6,6 +6,6 @@ ERROR in app.ts
./app.ts 3:12-24
[tsl] ERROR in app.ts(3,13)
 TS2551: Property 'doSomething2' does not exist on type 'typeof externalLib'. Did you mean 'doSomething'?
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
2 changes: 1 addition & 1 deletion test/comparison-tests/colors/expectedOutput-4.2/output.txt
Expand Up @@ -14,6 +14,6 @@ ERROR in app.ts
./app.ts 1:6-8
[tsl] ERROR in app.ts(1,7)
TS1005: ',' expected.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_dda4fd88600de236

webpack compiled with 2 errors
Expand Up @@ -5,7 +5,7 @@ ERROR in app.ts
./app.ts 1:6-8
[tsl] ERROR in app.ts(1,7)
TS1005: ',' expected.
ts-loader-default_66eeaf8be3a46130
ts-loader-default_94b2ce3d1ca5f363

ERROR in ./app.ts 2:1
Module parse failed: Unexpected token (2:1)
Expand Down
Expand Up @@ -5,6 +5,6 @@ ERROR in app.ts
./app.ts 2:6-11
[tsl] ERROR in app.ts(2,7)
 TS2339: Property 'sayHi' does not exist on type 'typeof Hello'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
Expand Up @@ -6,13 +6,13 @@ ERROR in app.ts
./app.ts 5:6-17
[tsl] ERROR in app.ts(5,7)
 TS2339: Property 'doSomething' does not exist on type 'typeof Thing'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

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

webpack compiled with 2 errors
Expand Up @@ -7,12 +7,12 @@ ERROR in app.ts
./app.ts 4:5-7
[tsl] ERROR in app.ts(4,6)
 TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

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

webpack compiled with 2 errors
Expand Up @@ -7,6 +7,6 @@ ERROR in app.ts
./app.ts 5:5-7
[tsl] ERROR in app.ts(5,6)
 TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
Expand Up @@ -5,11 +5,11 @@ asset bundle.js 2.6 KiB [emitted] (name: main)
ERROR in app.ts
./app.ts 1:29-53
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
ts-loader-default_6241146af0584e95
ts-loader-default_85b0565984bbe8dd

ERROR in app.ts
./app.ts 2:30-55
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
ts-loader-default_6241146af0584e95
ts-loader-default_85b0565984bbe8dd

webpack compiled with 2 errors
2 changes: 1 addition & 1 deletion test/comparison-tests/errors/expectedOutput-4.2/output.txt
Expand Up @@ -14,6 +14,6 @@ ERROR in app.ts
./app.ts 1:6-8
[tsl] ERROR in app.ts(1,7)
 TS1005: ',' expected.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 2 errors
Expand Up @@ -5,7 +5,7 @@ ERROR in app.ts
./app.ts 1:6-8
[tsl] ERROR in app.ts(1,7)
 TS1005: ',' expected.
ts-loader-default_66eeaf8be3a46130
ts-loader-default_de8929d96064b0d0

ERROR in ./app.ts 2:1
Module parse failed: Unexpected token (2:1)
Expand Down
2 changes: 1 addition & 1 deletion test/comparison-tests/es3/expectedOutput-4.2/output.txt
Expand Up @@ -5,6 +5,6 @@ ERROR in app.ts
./app.ts 1:6-7
[tsl] ERROR in app.ts(1,7)
 TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
Expand Up @@ -5,6 +5,6 @@ ERROR in app.ts
./app.ts 9:4-5
[tsl] ERROR in app.ts(9,5)
 TS2322: Type 'string' is not assignable to type 'Number'.
ts-loader-default_cf939062d980a567
ts-loader-default_2830fdd0bda34e31

webpack compiled with 1 error
Expand Up @@ -5,6 +5,6 @@ ERROR in app.ts
./app.ts 4:0-7
[tsl] ERROR in app.ts(4,1)
 TS2322: Type 'string' is not assignable to type 'boolean'.
ts-loader-default_b02295d909a3e7cf
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
2 changes: 2 additions & 0 deletions test/comparison-tests/loaderOptionsCaching/app.ts
@@ -0,0 +1,2 @@
import './submodule-es5';
import './submodule-es6';
@@ -0,0 +1,118 @@
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ "./app.ts":
/*!****************!*\
!*** ./app.ts ***!
\****************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

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

/***/ }),

/***/ "./submodule-es6/index.ts":
/*!********************************!*\
!*** ./submodule-es6/index.ts ***!
\********************************/
/***/ (() => {

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

/***/ }),

/***/ "./submodule-es5/index.ts":
/*!********************************!*\
!*** ./submodule-es5/index.ts ***!
\********************************/
/***/ (() => {

eval("var string = 'Hello from es5 file';\r\nconsole.log(string);\r\n\n\n//# sourceURL=webpack:///./submodule-es5/index.ts?");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./app.ts");
/******/
/******/ })()
;
@@ -0,0 +1,7 @@
asset bundle.js 5.1 KiB [emitted] (name: main)
runtime modules 937 bytes 4 modules
cacheable modules 256 bytes
./app.ts 52 bytes [built] [code generated]
./submodule-es5/index.ts 59 bytes [built] [code generated]
./submodule-es6/index.ts 145 bytes [built] [code generated]
webpack compiled successfully

0 comments on commit a8597e3

Please sign in to comment.