Home > Mobile >  How to dynmically load path in tsconfig.json file?
How to dynmically load path in tsconfig.json file?

Time:09-14

I would like to use dynamic import in my playwright scripts to load a certain data file depending on the environment parameter.
Something like this:

let data: Promise<username: string, password: string>;
data = import("@test-data/user_data.json");

test("my env test", async => {
   (await data).username;
})

I think @test-data/user_data.json should be defined in the tsconfig.json file like this:

{
    "compilerOptions": {
        "target": "es6",
        "strict": true,
        "module": "commonjs",
        "sourceMap": true,
        "resolveJsonModule": true,
        "baseUrl": ".",
        "paths": {
            "@test-data/*": [
                "stage/users/*"
            ]
        }
    }
}  

Is there a way I can dynamically specify here the stage in the path stage/users/* based on my environment (which I could read from the process.env variable specified while running the test)?
Thanks!

CodePudding user response:

I don't think you can. The only thing I think it could work is setting a placeholder into the dynamic field and create a specific bash/node/wathever script that fill the field according to the environment or an inline variable.

Could be nice put it as postinstall script into the package.json to run it each time you install the dependencies.

CodePudding user response:

I have created an article about this here https://www.codeproject.com/Tips/5341374/How-to-Parse-External-Classes-and-js-in-react-nati

You simple convert dynamic JS files

  • Related