Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with TypeScript paths with allowJs #470

Merged
merged 4 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ 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 }));
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: [".ts", ".tsx", ".js"] }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: [".ts", ".tsx", ".js"] }));
resolvePlugins.push(new TsconfigPathsPlugin({ silent: true, extensions: SUPPORTED_EXTENSIONS }));

The docs mention that these should be the same.

Perhaps this should look for allowJs option before assigning the extensions.

If you're using allowJs in tsconfig.json, or allow other non-TS extensions in webpack, make sure you set extensions option in sync with your webpack config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@styfle I believe I addressed both your suggestions, I did it in two steps, let me know if you want to keep the check against the tsconfig.json


const tsconfig = tsconfigPaths.loadConfig();
if (tsconfig.resultType === "success") {
Expand Down
3 changes: 3 additions & 0 deletions test/unit/tsconfig-paths-allowjs/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import module from '@module';

console.log(module);
1 change: 1 addition & 0 deletions test/unit/tsconfig-paths-allowjs/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
86 changes: 86 additions & 0 deletions test/unit/tsconfig-paths-allowjs/output-coverage.js
Original file line number Diff line number Diff line change
@@ -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 });
/******/ };
/******/ }();
/******/
/******/ }
);
66 changes: 66 additions & 0 deletions test/unit/tsconfig-paths-allowjs/output.js
Original file line number Diff line number Diff line change
@@ -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"]);


/***/ })

/******/ });
11 changes: 11 additions & 0 deletions test/unit/tsconfig-paths-allowjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@*": ["./*"]
},
"allowJs": true
}
}