Skip to content

Commit

Permalink
Fix TS module resolution paths on Windows (#373)
Browse files Browse the repository at this point in the history
* Add test for issue #372

* Normalize TS module resolution paths
Fixes #372

* Add TS 2.1 expected output for issue372 test
  • Loading branch information
smphhh authored and johnnyreilly committed Nov 14, 2016
1 parent a438869 commit 734f536
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/servicesHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,30 @@ function makeServicesHost(
let resolvedModules: interfaces.ResolvedModule[] = [];

for (let moduleName of moduleNames) {
let resolvedFileName: string;
let resolutionResult: any;
let resolutionResult: interfaces.ResolvedModule;

try {
resolvedFileName = resolver.resolveSync(path.normalize(path.dirname(containingFile)), moduleName);
let resolvedFileName: string = resolver.resolveSync(path.normalize(path.dirname(containingFile)), moduleName);
resolvedFileName = utils.appendTsSuffixIfMatch(appendTsSuffixTo, resolvedFileName);

if (!resolvedFileName.match(scriptRegex)) {
resolvedFileName = null;
} else {
if (resolvedFileName.match(scriptRegex)) {
resolutionResult = { resolvedFileName };
}
} catch (e) { resolvedFileName = null; }
} catch (e) {}

const tsResolution = compiler.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost);

if (tsResolution.resolvedModule) {
if (resolvedFileName) {
if (resolvedFileName === tsResolution.resolvedModule.resolvedFileName) {
resolutionResult.isExternalLibraryImport = tsResolution.resolvedModule.isExternalLibraryImport;
let tsResolutionResult: interfaces.ResolvedModule = {
resolvedFileName: path.normalize(tsResolution.resolvedModule.resolvedFileName),
isExternalLibraryImport: tsResolution.resolvedModule.isExternalLibraryImport
};
if (resolutionResult) {
if (resolutionResult.resolvedFileName === tsResolutionResult.resolvedFileName) {
resolutionResult.isExternalLibraryImport = tsResolutionResult.isExternalLibraryImport;
}
} else {
resolutionResult = tsResolution.resolvedModule;
resolutionResult = tsResolutionResult;
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/comparison-tests/issue372/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {IFoo, s} from './foo'

var foo: IFoo;
foo.bar = 'foobar' + s;
69 changes: 69 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.0/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/******/ (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";
var foo_1 = __webpack_require__(1);
var foo;
foo.bar = 'foobar' + foo_1.s;


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

"use strict";
var sString = __webpack_require__(2);
exports.s = sString;


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

module.exports = 'a';

/***/ }
/******/ ]);
6 changes: 6 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.0/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.73 kB 0 [emitted] main
chunk {0} bundle.js (main) 167 bytes [rendered]
[0] ./.test/issue372/app.ts 83 bytes {0} [built]
[1] ./.test/issue372/foo.ts 63 bytes {0} [built]
[2] ./.test/issue372/~/a/index.js 21 bytes {0} [built]
69 changes: 69 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.0/patch0/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/******/ (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";
var foo_1 = __webpack_require__(1);
var foo;
foo.bar = 'foobar_patch0' + foo_1.s;


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

"use strict";
var sString = __webpack_require__(2);
exports.s = sString;


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

module.exports = 'a';

/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.74 kB 0 [emitted] main
chunk {0} bundle.js (main) 174 bytes [rendered]
[0] ./.test/issue372/app.ts 90 bytes {0} [built]
[1] ./.test/issue372/foo.ts 63 bytes {0}
[2] ./.test/issue372/~/a/index.js 21 bytes {0}
69 changes: 69 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.1/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/******/ (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";
var foo_1 = __webpack_require__(1);
var foo;
foo.bar = 'foobar' + foo_1.s;


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

"use strict";
var sString = __webpack_require__(2);
exports.s = sString;


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

module.exports = 'a';

/***/ }
/******/ ]);
6 changes: 6 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.1/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.73 kB 0 [emitted] main
chunk {0} bundle.js (main) 167 bytes [rendered]
[0] ./.test/issue372/app.ts 83 bytes {0} [built]
[1] ./.test/issue372/foo.ts 63 bytes {0} [built]
[2] ./.test/issue372/~/a/index.js 21 bytes {0} [built]
69 changes: 69 additions & 0 deletions test/comparison-tests/issue372/expectedOutput-2.1/patch0/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/******/ (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";
var foo_1 = __webpack_require__(1);
var foo;
foo.bar = 'foobar_patch0' + foo_1.s;


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

"use strict";
var sString = __webpack_require__(2);
exports.s = sString;


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

module.exports = 'a';

/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.74 kB 0 [emitted] main
chunk {0} bundle.js (main) 174 bytes [rendered]
[0] ./.test/issue372/app.ts 90 bytes {0} [built]
[1] ./.test/issue372/foo.ts 63 bytes {0}
[2] ./.test/issue372/~/a/index.js 21 bytes {0}
7 changes: 7 additions & 0 deletions test/comparison-tests/issue372/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as sString from 'a';

export interface IFoo {
bar: string;
}

export var s = sString;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/comparison-tests/issue372/node_modules/a/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/comparison-tests/issue372/node_modules/a/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/comparison-tests/issue372/patch0/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {IFoo, s} from './foo'

var foo: IFoo;
foo.bar = 'foobar_patch0' + s;
Loading

0 comments on commit 734f536

Please sign in to comment.