Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tsc: use version from node_modules

Tags:

typescript

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.

like image 530
Borek Bernard Avatar asked Nov 28 '25 17:11

Borek Bernard


1 Answers

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"
  },
like image 50
httpete Avatar answered Nov 30 '25 10:11

httpete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!