Skip to content

Commit

Permalink
Add an additional check for js files before reusing isExternalLibaryI…
Browse files Browse the repository at this point in the history
…mport (#620) (#622)

* Force typescript version to be 2.4.2

This should not be merged in but with new typescript updates there are type issues for a clean initial build.

* Add check if the resolvedModule is a js file before reusing isExternalLibraryImport

Passes all current tests. Still need to add a new one for this (works locally).

* Add test for change

* Update package.json
  • Loading branch information
WillMartin authored and johnnyreilly committed Sep 6, 2017
1 parent 3296ef7 commit 114e5b1
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"mkdirp": "^0.5.1",
"mocha": "^3.1.0",
"rimraf": "^2.4.2",
"typescript": "^2.4.0",
"typescript": "^2.4.2",
"typings": "^2.0.0",
"webpack": "^2.2.0"
}
Expand Down
10 changes: 9 additions & 1 deletion src/servicesHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ function resolveModuleNames(
return resolvedModules;
}

function isJsImplementationOfTypings(
resolvedModule: ResolvedModule,
tsResolution: ResolvedModule
) {
return resolvedModule.resolvedFileName.endsWith('js') &&
/node_modules(\\|\/).*\.d\.ts$/.test(tsResolution.resolvedFileName);
}

function resolveModuleName(
resolveSync: ResolveSync,
moduleResolutionHost: ModuleResolutionHost,
Expand Down Expand Up @@ -153,7 +161,7 @@ function resolveModuleName(
};
if (resolutionResult!) {
if (resolutionResult!.resolvedFileName === tsResolutionResult.resolvedFileName ||
/node_modules(\\|\/).*\.d\.ts$/.test(tsResolutionResult.resolvedFileName)) {
isJsImplementationOfTypings(resolutionResult!, tsResolutionResult)) {
resolutionResult!.isExternalLibraryImport = tsResolutionResult.isExternalLibraryImport;
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions test/comparison-tests/localTsImplementationOfTypings/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import myComponent = require('api');

console.log(myComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/******/ (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] = {
/******/ 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;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

exports.__esModule = true;
function sayHello(name) {
return "Hello, " + name + "!";
}
exports.sayHello = sayHello;


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

"use strict";

exports.__esModule = true;
var myComponent = __webpack_require__(0);
console.log(myComponent);


/***/ })
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 2.98 kB 0 [emitted] main
chunk {0} bundle.js (main) 234 bytes [entry] [rendered]
[0] ./.test/localTsImplementationOfTypings/fake.ts 133 bytes {0} [built]
[1] ./.test/localTsImplementationOfTypings/app.ts 101 bytes {0} [built]
3 changes: 3 additions & 0 deletions test/comparison-tests/localTsImplementationOfTypings/fake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sayHello(name: string): string {
return `Hello, ${name}!`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {

},
"include": [
"app.ts"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var path = require('path');

module.exports = {
entry: './app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
alias: {
api: path.resolve(__dirname, 'fake')
},
extensions: ['.ts', '.js']
},
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' }
]
}
}


0 comments on commit 114e5b1

Please sign in to comment.