1.8.10 • Published 1 year ago

tsc-alias v1.8.10

Weekly downloads
36,471
License
MIT
Repository
github
Last release
1 year 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@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-clihuelgo-monadhuelgo-szgulihj-cliharmony-ai-editorguoshou-intelligent-assistantlionconfiglibrary-caiol.sousalinkedunion-design-kitkiso-clikiso-formmarkdown-net@wizz-js/api@wizz-js/providers@wizz-js/types@wizz-js/utils@wvhulle/object@ugliest/app@tommy_baron/git-test-@toptal/davinci-engine@torque-labs/torque-ui@termsurf/task@triumph-arcade/triumph-node@tgtt/interface@treenity/build-utils@versatus/versatus-javascript@vifjs/task-runner@vecmat/kirinriki@vlayer/sdk@voiceflow/serverless-plugin-typescript@yeluyang95/api@zanixjs/cli@zanixjs/code-config@zeynui/react@termsurf/leaf@termsurf/mark@termsurf/mark.js@zodyac/cliagora-proctor-sdkadamo-typesarkham-investigator-dataasfg@go1d/mine@ckenx/node@clickon/package-utils@clutch-sh/tools@cluesurf/leaf@cluesurf/mark@harsh-js/express-ts-app@harsh-js/express-ts-boilerplate@guoyunhe/bundle-dts@abu-taksi/ums-client@ego-js/core@ego-js/utils@egiftify/fe_ts_module@coffic/juice-editor@codrjs/mongo@communityox/fx-utils@commercetools-connect/sdk@cometh/crosschain-sdk@cometh/keystore-sdk
1.8.10

1 year ago

1.8.9

1 year ago

1.8.8

2 years ago

1.8.7

2 years ago

1.8.6

2 years ago

1.8.5

3 years ago

1.8.4

3 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.1

3 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

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.2

4 years ago

1.4.1

4 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

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 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