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 TS module resolution paths on Windows #373

Merged
merged 3 commits into from
Nov 14, 2016
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
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