Skip to content

Commit

Permalink
Backport #1317 to v8 (#1319)
Browse files Browse the repository at this point in the history
* Backport "Fixed impossibility to have several instances of ts-loader with different compiler options" #1317 to v8
* regen comparison tests
  • Loading branch information
timocov authored May 19, 2021
1 parent 6787a39 commit 3639cbd
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v8.3.0

* [Fixed impossibility to have several instances of ts-loader with different compiler options](https://github.com/TypeStrong/ts-loader/issues/1316) - thanks @timocov
* This is a backport from v9.2.0 for webpack 4 compatibility

## v8.2.0

* [Use caches for module resolution and type reference directives when using compiler default functions](https://github.com/TypeStrong/ts-loader/pull/1287) - thanks @sheetalkamat - uses: https://github.com/microsoft/TypeScript/pull/43700
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.2.0",
"version": "8.3.0",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions test/comparison-tests/loaderOptionsCaching/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './submodule-es5';
import './submodule-es6';
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./app.ts");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./app.ts":
/*!****************!*\
!*** ./app.ts ***!
\****************/
/*! no exports provided */
/***/ (function(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-es5/index.ts":
/*!********************************!*\
!*** ./submodule-es5/index.ts ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports) {

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

/***/ }),

/***/ "./submodule-es6/index.ts":
/*!********************************!*\
!*** ./submodule-es6/index.ts ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports) {

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

/***/ })

/******/ });
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 5.21 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 52 bytes {main} [built]
[./submodule-es5/index.ts] 59 bytes {main} [built]
[./submodule-es6/index.ts] 145 bytes {main} [built]
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./app.ts");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./app.ts":
/*!****************!*\
!*** ./app.ts ***!
\****************/
/*! no exports provided */
/***/ (function(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-es5/index.ts":
/*!********************************!*\
!*** ./submodule-es5/index.ts ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports) {

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

/***/ }),

/***/ "./submodule-es6/index.ts":
/*!********************************!*\
!*** ./submodule-es6/index.ts ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports) {

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

/***/ })

/******/ });
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 5.21 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 52 bytes {main} [built]
[./submodule-es5/index.ts] 59 bytes {main} [built]
[./submodule-es6/index.ts] 145 bytes {main} [built]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const string = 'Hello from es5 file';
console.log(string);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const set = new Set([42]);
for (const value of set) {
console.log(value);
}

const string = 'Hello from es6 file';
console.log(string);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es6"
}
}
5 changes: 5 additions & 0 deletions test/comparison-tests/loaderOptionsCaching/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es5"
}
}
32 changes: 32 additions & 0 deletions test/comparison-tests/loaderOptionsCaching/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
mode: 'development',
entry: './app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['.ts']
},
module: {
rules: [
{
test: /submodule-es6.*\.ts$/,
loader: 'ts-loader',
options: {
compilerOptions: {
target: 'es6',
},
},
},
{
test: /submodule-es5.*\.ts$/,
loader: 'ts-loader',
options: {
compilerOptions: {
target: 'es5',
},
},
}
]
}
}

0 comments on commit 3639cbd

Please sign in to comment.