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

Add an additional check for js files before reusing isExternalLibaryImport (#620) #622

Merged
merged 5 commits into from
Sep 6, 2017
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 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' }
]
}
}