5

I have a tsconfig.json file containing

{
  "extends": "../../zlux-app-manager/virtual-desktop/plugin-config/tsconfig.base.json",
  "include": [
    "src/**/*.ts",
    "../../zlux-platform/interface/src/mvd-hosting.d.ts"
  ],
  "compilerOptions": {
    "skipLibCheck": true
  }
}

I want to replace ../../ with an environment variable. What are the possible solutions?

Swetank
  • 111
  • 2
  • 7

1 Answers1

1

tsconfig.json is a simple JSON document lacking any way to refer to environment variables. You can check all possible options in the tsconfig Schema.

This does not restrict your use-case though. You can use a data templating language such as Jsonnet. It is a 20% project that can generate dynamic json (or other notation formats). You can use it to generate secondary tsconfig.json file and pass it as arguments to tsc.

Or

Just use Python/JS/Any programming language. At the end of the day you need to produce a json file to tsc, generate it! The following Python code with the below script runs perfectly.

import os, json
r ={
  "extends": os.environ['FOO'] + "/zlux-app-manager/virtual-desktop/plugin-config/tsconfig.base.json",
  "include": [
    "src/**/*.ts",
    os.environ['FOO'] + "/zlux-platform/interface/src/mvd-hosting.d.ts"
  ],
  "compilerOptions": {
    "skipLibCheck": True
  }
}
print(json.dumps(r))

Bash Command

$ FOO=mydir python3 tsconfig.py > tsconfig.json && tsc tsconfig.json
frunkad
  • 2,433
  • 1
  • 23
  • 35
  • 1
    Side Note: If you wouldn't have been using env variable in `extends`, the other option with you was going ahead with splitting tsc command as mentioned here https://github.com/microsoft/TypeScript/issues/32323#issuecomment-510013098 – frunkad Feb 24 '20 at 17:59