1.8.10 • Published 12 months ago

tsc-alias v1.8.10

Weekly downloads
36,471
License
MIT
Repository
github
Last release
12 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@infinitebrahmanuniverse/nolb-tscmrkreszmapbox-vue3timesheeter@everything-registry/sub-chunk-2980smart-contract-detection@vtal/componentstest-ykmangaland-scrapernivoda-dsm@yoruapi/core@rgame/shared2tauri-api-adapterwtt-pkgstory-book-hasindur-400story-book-test-digital400story-book-test-packagestory-book-test-package-bitbucket-v1story-book-test-package-github_digital400_vtest-yorkie-uiverace.js@clutch-sh/tools@commercetools-connect/sdk@dev-extralabs/web3@devell/di@devell/web-extractor@bunny-ts/cli@by-the-way/endpoints-discoverer@candlerip/shared2@candleface/shared@candlerip/shared@candlerip/shared1@permaweb/libs@powerfulyang/lintitptit-test-generatorkaravan-designejamaikd-graphkasdaklsdajldjalk-fe-plugin-build-umdkhambaktaro-community-cliksv741-react-scriptsktaro-clisgysldz-clitest-yorkie-v1sgys-clinfe-golerpsitecore-jss-rule-engineturbo-searchtimetablev2token-countertsmr@bitcashp/bch-ts@cardano-sdk/projection@cardano-sdk/projection-typeorm@ckenx/node@abu-taksi/ums-client@codrjs/mongo@coffic/juice-editor@bem-react/pack@devops-premade/ms-common@dicetable/plugin-shell@darkobits/tsxwtscycw-monitoryaml-react-componentzeusapivetechxtsc@fastify-dev-toolkit/backend@fastify-dev-toolkit/plugin@feedmepos/mf-report@fenriliuguang/mm-cli@guoyunhe/bundle-dts@harsh-js/express-ts-app@harsh-js/express-ts-boilerplate@hk-artificial-intelligence-association/weibo-api@ice/pkg@flstk/pg-react@egiftify/fe_ts_module@elumeo/jfs-core@elliemae/pui-cli@ego-js/core@ego-js/utils@event-inc/cli@gliff-ai/upload@go1d/mine@lancejpollard/color-splat.js@lancejpollard/gematria.js@liveart/injectables@llius/jsonbin-db@luckedcoronet/lcbuild@lesnoypudge/builder@leonzalion/configs@madbbb/core@madebymondo/mondo@lyn4ed/strapi-admin@lynched-test/strapi-admin
1.8.10

12 months ago

1.8.9

12 months ago

1.8.8

2 years ago

1.8.7

2 years ago

1.8.6

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.3

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.6.11

3 years ago

1.6.10

3 years ago

1.7.0

3 years ago

1.6.9

3 years ago

1.6.8

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.5

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

4 years ago

1.3.10

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago