This package resolves non-relative imports to their relative path. This was possible with "tsc-resolve" by Dimitar Mazhlekov, but in his version it was not possible to do the following:
// tsconfig.json
"paths": {
"@util/*": [
"util/*"
]
}
// index.js
import * as someUtility from "@utils/someUtility";
With this package you can resolve further paths (e.g. "someUtility") after the non-relative path (e.g. "@util"). The old version only allowed for one non-relative path to resolve to one file/directory.
# Local package
$ npm i timephy/tsc-resolve-fix --save-dev
# Global CLI
$ npm i -g timephy/tsc-resolve-fix
$ npm i tsc-resolve --save-dev
"scripts": {
"compile": "tsc",
"build": "compile && tsc-resolve"
}
$ npm run build
$ npm i -g timephy/tsc-resolve-fix
$ ./node_module/.bin/tsc-resolve
$ tsc-resolve
$ tsc-resolve -p tsconfig.prod.json
$ tsc-resolve -p ./conf/tsconfig.dev.json
$ tsc-resolve -p ./conf/
$ tsc-resolve -p ../
import { tscResolve } from "tsc-resolve"
import * as path from "path"
// Simple ./tsconfig.json
const configPath = process.cwd();
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Specific tsconfig.json
const configPath = path.join(process.cwd(), "tsconfig.prod.json");
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Specific tsconfig.json in different folder
const configPath = path.resolve(process.cwd(), "../conf/tsconfig.dev.json");
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Async/Await
const configPath = process.cwd();
await tscResolve(configPath);
const tscResolver = require("tsc-resolve");
const path = require("path");
// Simple ./tsconfig.json
const configPath = process.cwd();
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Specific tsconfig.json
const configPath = path.join(process.cwd(), "tsconfig.prod.json");
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Specific tsconfig.json in different folder
const configPath = path.resolve(process.cwd(), "../conf/tsconfig.dev.json");
tscResolve(configPath)
.then(() => { /*DONE*/ });
// Async/Await
const configPath = process.cwd();
await tscResolve(configPath);