1.8.8 • Published 7 months ago

tsc-alias v1.8.8

Weekly downloads
36,471
License
MIT
Repository
github
Last release
7 months ago

tsc-alias

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.

npm version License Donate

Comparison to tsconfig-paths

+ Compile time (no runtime dependencies)

Getting Started

First, install tsc-alias as devDependency using npm.

npm install -g tsc-alias
npm install --save-dev tsc-alias

Add it to your build scripts in package.json

"scripts": {
  "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}

================ OR ===================

"scripts": {
  "build": "tsc && tsc-alias",
  "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")"
}

Issues

If you have an issue, please create one. But, before:

  • try to check the FAQ.
  • try to check if there exits alike issues.
  • try to run with --debug and check if config is correctly loaded and all sourcefiles are found.

API

Installation

npm install tsc-alias

Usage

import { replaceTscAliasPaths } from 'tsc-alias';

replaceTscAliasPaths(options?);

Here are all the available options:

Configuration via tsconfig.json Example

{
  "compilerOptions": {
    ...
  },
  "tsc-alias": {
    "verbose": false,
    "resolveFullPaths": true,
    "replacers": {
      "exampleReplacer": {
        "enabled": true,
        "file": "./exampleReplacer.js"
      },
      "otherReplacer": {
        "enabled": true,
        "file": "./otherReplacer.js"
      }
    },
    "fileExtensions": {
      "inputGlob": "{js,jsx,mjs}",
      "outputCheck": ["js", "json", "jsx", "mjs"]
    }
  }
}

Single file replacer

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.

import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias';

const runFile: SingleFileReplacer = await prepareSingleFileReplaceTscAliasPaths(options?);

function treatFile(filePath: string) {
  const fileContents = fs.readFileSync(filePath, 'utf8');
  const newContents = runFile({fileContents, filePath});
  // do stuff with newContents
}
@esportsplus/rspack@toptal/davinci-engine@infinitebrahmanuniverse/nolb-tscmrkreszmapbox-vue3timesheeter@everything-registry/sub-chunk-2980smart-contract-detection@vtal/componentstest-ykgs-clipboarditptit-test-generatorhuelgo-monadhuelgo-szgenshin-calculatork-fe-plugin-build-umdktaro-cliktaro-community-cliksv741-react-scriptsinfinity-forgelibrary-caiol.sousakd-graphlionconfigmarkdown-neteris-loggerfekx-clieah-bhf2c-servergatecflit-calcular-jornadapackage-json-analyzerpermaweb-sdkkiso-clikiso-formnivoda-dsmmrkresz-static-content-migratormwtscplisplasmongo-lock-nodemetamaker-human-for-threepovery-clipractice-calculatorpwntools.jsriverunes-jsreact-txt-editorrdjs-wheelrettlerollup-plugin-tsc-alias@devell/di@devell/web-extractor@dev-extralabs/web3buildablecargodispoapicarbon-js-sdkchk2globaltsmrcls-master-libcls-master-lib-testingturbo-searchstory-book-hasindur-400story-book-test-digital400story-book-test-packagestory-book-test-package-bitbucket-v1story-book-test-package-github_digital400_v@candleface/shared@by-the-way/endpoints-discovererautostack-uibase-h5sdk@ckenx/nodeasfg@bem-react/packtoken-countercloud-sendcodiedigitaltest-yorkie-uitest-yorkie-v1@darkobits/ts@marchyang/pack@playform/build@niamori/rollup-config@powerfulyang/lint@nickstracke/ponder-core@neon.id/cli@ninjalib/build@elliemae/pui-cli@elumeo/jfs-core@ego-js/core@ego-js/utils@egiftify/fe_ts_moduleyorkie-ui@fenriliuguang/mm-cli@risini_org/story-book-test-package-bitbucket-v1@rgame/shared2@scalar/build-toolingverace.jsculinary-portal-preview-componentdav-my-counterddd-node@mindedtech/tsconfig
1.8.8

7 months ago

1.8.7

10 months ago

1.8.6

1 year ago

1.8.5

1 year ago

1.8.4

1 year ago

1.8.3

1 year ago

1.8.2

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.7.1

1 year ago

1.6.11

2 years ago

1.6.10

2 years ago

1.7.0

2 years ago

1.6.9

2 years ago

1.6.8

2 years ago

1.6.7

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago