Gathering detailed insights and metrics for tsc-alias
Gathering detailed insights and metrics for tsc-alias
Gathering detailed insights and metrics for tsc-alias
Gathering detailed insights and metrics for tsc-alias
Replace alias paths with relative paths after typescript compilation
npm install tsc-alias
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
910 Stars
231 Commits
62 Forks
5 Watching
3 Branches
31 Contributors
Updated on 19 Nov 2024
Minified
Minified + Gzipped
TypeScript (96.16%)
JavaScript (3.69%)
Shell (0.14%)
Cumulative downloads
Total Downloads
Last day
3.3%
133,552
Compared to previous day
Last week
4.1%
708,718
Compared to previous week
Last month
11.6%
2,906,683
Compared to previous month
Last year
83.1%
26,763,241
Compared to previous year
Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.
+ Compile time (no runtime dependencies)
First, install tsc-alias as devDependency using npm.
1npm install -g tsc-alias
npm install --save-dev tsc-alias
1"scripts": { 2 "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json", 3} 4 5================ OR =================== 6 7"scripts": { 8 "build": "tsc && tsc-alias", 9 "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")" 10}
If you have an issue, please create one. But, before:
--debug
and check if config is correctly loaded and all sourcefiles are found.1npm install tsc-alias
1import { replaceTscAliasPaths } from 'tsc-alias'; 2 3replaceTscAliasPaths(options?);
Here are all the available options:
Option | Description | Default Value |
---|---|---|
project, p | path to tsconfig.json | 'tsconfig.json' |
watch | Observe file changes | false |
outDir | Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig) | tsconfig.compilerOptions.outDir |
declarationDir | Works the same as outDir but for declarationDir | tsconfig.compilerOptions.declarationDir |
resolveFullPaths | Attempt to replace incomplete import paths (those not ending in .js ) with fully resolved paths (for ECMAScript Modules compatibility) | false |
resolveFullExtension | Allows you to specify the extension of incomplete import paths, works with resolveFullPaths | '.js' | '.mjs' | '.cjs' |
silent | Reduced terminal output. This is a deprecated option and no longer has any effect. | true |
verbose | Additional information is output to the terminal | false |
debug | Debug information is send to the terminal | false |
replacers | Files to import as extra replacers More info | [] |
output | The output object tsc-alias will send logs to. | new Output(options.verbose) |
fileExtensions | Overwrite file extensions tsc-alias will use to scan and resolve files. | undefined |
tsconfig.json
Example1{ 2 "compilerOptions": { 3 ... 4 }, 5 "tsc-alias": { 6 "verbose": false, 7 "resolveFullPaths": true, 8 "replacers": { 9 "exampleReplacer": { 10 "enabled": true, 11 "file": "./exampleReplacer.js" 12 }, 13 "otherReplacer": { 14 "enabled": true, 15 "file": "./otherReplacer.js" 16 } 17 }, 18 "fileExtensions": { 19 "inputGlob": "{js,jsx,mjs}", 20 "outputCheck": ["js", "json", "jsx", "mjs"] 21 } 22 } 23}
We can use tsc-alias in a single file, with a function that returns the modified contents.
We prepare the replacer with prepareSingleFileReplaceTscAliasPaths()
, passing the same options that we would pass to replaceTscAliasPaths()
. That will return a promise of a function that receives the file contents and path, and returns the transformed contents, synchronously.
1import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias'; 2 3const runFile: SingleFileReplacer = await prepareSingleFileReplaceTscAliasPaths(options?); 4 5function treatFile(filePath: string) { 6 const fileContents = fs.readFileSync(filePath, 'utf8'); 7 const newContents = runFile({fileContents, filePath}); 8 // do stuff with newContents 9}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More