diff --git a/src/index.js b/src/index.js index 9c250b74..90627572 100644 --- a/src/index.js +++ b/src/index.js @@ -71,9 +71,15 @@ module.exports = ( // we need to catch here because the plugin will // error if there's no tsconfig in the working directory try { - resolvePlugins.push(new TsconfigPathsPlugin({ silent: true })); - const tsconfig = tsconfigPaths.loadConfig(); + const fullTsconfig = require(tsconfig.configFileAbsolutePath) + + const tsconfigPathsOptions = { silent: true } + if (fullTsconfig.compilerOptions.allowJs) { + tsconfigPathsOptions.extensions = SUPPORTED_EXTENSIONS + } + resolvePlugins.push(new TsconfigPathsPlugin(tsconfigPathsOptions)); + if (tsconfig.resultType === "success") { tsconfigMatchPath = tsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths); } diff --git a/test/unit/tsconfig-paths-allowjs/input.ts b/test/unit/tsconfig-paths-allowjs/input.ts new file mode 100644 index 00000000..02af28c5 --- /dev/null +++ b/test/unit/tsconfig-paths-allowjs/input.ts @@ -0,0 +1,3 @@ +import module from '@module'; + +console.log(module); diff --git a/test/unit/tsconfig-paths-allowjs/module.js b/test/unit/tsconfig-paths-allowjs/module.js new file mode 100644 index 00000000..ff8b4c56 --- /dev/null +++ b/test/unit/tsconfig-paths-allowjs/module.js @@ -0,0 +1 @@ +export default {}; diff --git a/test/unit/tsconfig-paths-allowjs/output-coverage.js b/test/unit/tsconfig-paths-allowjs/output-coverage.js new file mode 100644 index 00000000..431e4c2a --- /dev/null +++ b/test/unit/tsconfig-paths-allowjs/output-coverage.js @@ -0,0 +1,86 @@ +module.exports = +/******/ (function(modules, runtime) { // webpackBootstrap +/******/ "use strict"; +/******/ // 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; +/******/ } +/******/ +/******/ +/******/ __webpack_require__.ab = __dirname + "/"; +/******/ +/******/ // the startup function +/******/ function startup() { +/******/ // Load entry module and return exports +/******/ return __webpack_require__(439); +/******/ }; +/******/ // initialize runtime +/******/ runtime(__webpack_require__); +/******/ +/******/ // run startup +/******/ return startup(); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ 306: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony default export */ __webpack_exports__["default"] = ({}); + + +/***/ }), + +/***/ 439: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +exports.__esModule = true; +var _module_1 = __webpack_require__(306); +console.log(_module_1["default"]); + + +/***/ }) + +/******/ }, +/******/ function(__webpack_require__) { // webpackRuntimeModules +/******/ "use strict"; +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ !function() { +/******/ // 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 }); +/******/ }; +/******/ }(); +/******/ +/******/ } +); diff --git a/test/unit/tsconfig-paths-allowjs/output.js b/test/unit/tsconfig-paths-allowjs/output.js new file mode 100644 index 00000000..d1058d0d --- /dev/null +++ b/test/unit/tsconfig-paths-allowjs/output.js @@ -0,0 +1,66 @@ +module.exports = +/******/ (function(modules, runtime) { // webpackBootstrap +/******/ "use strict"; +/******/ // 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; +/******/ } +/******/ +/******/ +/******/ __webpack_require__.ab = __dirname + "/"; +/******/ +/******/ // the startup function +/******/ function startup() { +/******/ // Load entry module and return exports +/******/ return __webpack_require__(468); +/******/ }; +/******/ +/******/ // run startup +/******/ return startup(); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ 17: +/***/ (function() { + +eval("require")("@module"); + + +/***/ }), + +/***/ 468: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +exports.__esModule = true; +var _module_1 = __webpack_require__(17); +console.log(_module_1["default"]); + + +/***/ }) + +/******/ }); diff --git a/test/unit/tsconfig-paths-allowjs/tsconfig.json b/test/unit/tsconfig-paths-allowjs/tsconfig.json new file mode 100644 index 00000000..5a906978 --- /dev/null +++ b/test/unit/tsconfig-paths-allowjs/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "moduleResolution": "node", + "baseUrl": ".", + "paths": { + "@*": ["./*"] + }, + "allowJs": true + } +}