Skip to content

Fix bug with webpack resolution #102

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

Merged
merged 2 commits into from
Nov 10, 2015
Merged
Show file tree
Hide file tree
Changes from all 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 index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
let resolutionResult: any;

try {
resolvedFileName = resolver.resolveSync(containingFile, moduleName)
resolvedFileName = resolver.resolveSync(path.dirname(containingFile), moduleName)

if (!resolvedFileName.match(/\.tsx?$/)) resolvedFileName = null;
else resolutionResult = { resolvedFileName };
Expand Down
62 changes: 62 additions & 0 deletions test/es6resolveParent/expectedOutput/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = 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;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var BaseComponent = function BaseComponent() {
_classCallCheck(this, BaseComponent);
};

exports.BaseComponent = BaseComponent;

/***/ }
/******/ ]);
4 changes: 4 additions & 0 deletions test/es6resolveParent/expectedOutput/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.76 kB 0 [emitted] main
chunk {0} bundle.js (main) 365 bytes [rendered]
[0] ./.test/es6resolveParent/index.tsx 365 bytes {0} [built]
3 changes: 3 additions & 0 deletions test/es6resolveParent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import submodule from './submodule/index';

export class BaseComponent {}
5 changes: 5 additions & 0 deletions test/es6resolveParent/submodule/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BaseComponent } from '../index';

class Component extends BaseComponent {}

export default 'foo';
9 changes: 9 additions & 0 deletions test/es6resolveParent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es6",
"moduleResolution": "node",
"jsx": "react"
},
"files": [
]
}
19 changes: 19 additions & 0 deletions test/es6resolveParent/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var path = require('path')

module.exports = {
entry: './index',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.ts', '.tsx', '.js']
},
module: {
loaders: [
{ test: /\.tsx?$/, loader: 'babel-loader!ts-loader' }
]
}
}

// for test harness purposes only, you would not need this in a normal project
module.exports.resolveLoader = { alias: { 'ts-loader': require('path').join(__dirname, "../../index.js") } }
3 changes: 3 additions & 0 deletions test/issue92/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import submodule from './submodule/submodule';

export default submodule;
75 changes: 75 additions & 0 deletions test/issue92/expectedOutput/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = 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;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _submoduleSubmodule = __webpack_require__(1);

var _submoduleSubmodule2 = _interopRequireDefault(_submoduleSubmodule);

exports['default'] = _submoduleSubmodule2['default'];
module.exports = exports['default'];

/***/ },
/* 1 */
/***/ function(module, exports) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = "Hello from submodule";
module.exports = exports["default"];

/***/ }
/******/ ]);
5 changes: 5 additions & 0 deletions test/issue92/expectedOutput/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 2.03 kB 0 [emitted] main
chunk {0} bundle.js (main) 565 bytes [rendered]
[0] ./.test/issue92/app.ts 404 bytes {0} [built]
[1] ./.test/issue92/submodule/submodule.tsx 161 bytes {0} [built]
1 change: 1 addition & 0 deletions test/issue92/submodule/submodule.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "Hello from submodule"
7 changes: 7 additions & 0 deletions test/issue92/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "es6"
},
"files": [
]
}
19 changes: 19 additions & 0 deletions test/issue92/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var path = require('path')

module.exports = {
entry: './app',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.ts', '.tsx', '.js']
},
module: {
loaders: [
{ test: /\.tsx?$/, loader: 'babel-loader!ts-loader' }
]
}
}

// for test harness purposes only, you would not need this in a normal project
module.exports.resolveLoader = { alias: { 'ts-loader': require('path').join(__dirname, "../../index.js") } }