Borek Bernard
Borek Bernard

Reputation: 53342

tsc: use version from node_modules

I've got TypeScript installed globally and if I do tsc -v, it prints out Version 2.0.3. I also have TypeScript as a dependency of my project so the compiler is also available as MyProject/node_modules/.bin/tsc which is version 2.0.6.

Is it possible to configure global tsc to use the local version if in a project which has node_modules? The global tsc would basically become just a launcher of the local tsc.

Upvotes: 3

Views: 4095

Answers (2)

lony
lony

Reputation: 7809

You could just run ./node_modules/typescript/bin/tsc -v to run the node version

Upvotes: 1

httpete
httpete

Reputation: 2993

I do it using grunt-exec, but the pattern could be done a variety of ways. This cwd's down to the lib dir and then executes the command there.

This is my grunt-exec task, although I am trying to do it with better-npm-run now.

"ts-dev": { cwd: 'node_modules/typescript/lib', cmd: "node tsc -p ../../../../../ -pretty"}

Here is how I did it in better-npm-run see the task dev-compile.

      "scripts": {
    "build:dist": "better-npm-run build:dist",
    "build:prod": "better-npm-run build:prod",
    "dev-start": "bnr dev:start",
    "dev-compile": "bnr dev:compile"
  },
  "betterScripts": {
    "dev:start": "node ./serve https://opm-int.nane.netapp.com 9000",
    "dev:compile": "node ./node_modules/typescript/lib/tsc -p ../../../../../ -pretty"
  },

Upvotes: 1

Related Questions