Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Make sure TSLint picks up the correct version of TypeScript
Browse files Browse the repository at this point in the history
Fixes #24

**Bug**
TSLint does `require('typescript')` to import typescript instead of taking typescript as value at runtime. Due to how node's module resolution works, this can cause TSLint to import a different typescript version than the version being used by the TS Server

This version mismatch can cause weird behavior as the ast and apis may not be compatible

**Fix**
Mock out `require('typescript')` to make sure we always return the typescript version from the server
  • Loading branch information
mjbvz committed Nov 27, 2018
1 parent 8bd44a8 commit ee48c7f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 55 deletions.
129 changes: 74 additions & 55 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
},
"dependencies": {
"minimatch": "^3.0.4",
"mock-require": "^3.0.2",
"vscode-languageserver": "^5.1.0"
},
"devDependencies": {
"@types/chai": "^4.1.6",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^5.2.5",
"@types/mock-require": "^2.0.0",
"@types/node": "^7.0.8",
"chai": "^4.2.0",
"mocha": "^5.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { TSLintPlugin } from './plugin';
import * as ts_module from 'typescript/lib/tsserverlibrary';
import { Logger } from './logger';
import { ConfigurationManager } from './settings';
import * as mockRequire from 'mock-require';

export = function init({ typescript }: { typescript: typeof ts_module }) {
const configManager = new ConfigurationManager(typescript);
let logger: Logger | undefined;

// Make sure TS Lint imports the correct version of TS
mockRequire('typescript', typescript);

return {
create(info: ts.server.PluginCreateInfo) {
logger = Logger.forPlugin(info);
Expand Down

0 comments on commit ee48c7f

Please sign in to comment.