Skip to content

Commit 836f897

Browse files
authored
README.md: assorted tweaks (#287)
1. fix badge URLs 2. Minor Markdown tweaks
1 parent 3a3d694 commit 836f897

1 file changed

Lines changed: 35 additions & 27 deletions

File tree

README.md

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Use this to load modules whose location is specified in the `paths` section of `tsconfig.json` or `jsconfig.json`. Both loading at run-time and via API are supported.
1010

11-
Typescript by default mimics the Node.js runtime resolution strategy of modules. But it also allows the use of [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html) which allows arbitrary module paths (that doesn't start with "/" or ".") to be specified and mapped to physical paths in the filesystem. The typescript compiler can resolve these paths from `tsconfig` so it will compile OK. But if you then try to execute the compiled files with node (or ts-node), it will only look in the `node_modules` folders all the way up to the root of the filesystem and thus will not find the modules specified by `paths` in `tsconfig`.
11+
TypeScript by default mimics the Node.js runtime resolution strategy of modules. But it also allows the use of [path mapping](https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution) which allows arbitrary module paths (that doesn't start with "/" or ".") to be specified and mapped to physical paths in the filesystem. The TypeScript compiler can resolve these paths from `tsconfig` so it will compile OK. But if you then try to execute the compiled files with node (or ts-node), it will only look in the `node_modules` folders all the way up to the root of the filesystem and thus will not find the modules specified by `paths` in `tsconfig`.
1212

1313
If you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` or `jsconfig.json` and convert node's module loading calls to physical file paths that node can load.
1414

@@ -26,25 +26,31 @@ bun install --dev tsconfig-paths
2626

2727
### With node
2828

29-
`node -r tsconfig-paths/register main.js`
29+
```bash
30+
node -r tsconfig-paths/register main.js
31+
```
3032

31-
If `process.env.TS_NODE_BASEURL` is set it will override the value of `baseUrl` in tsconfig.json:
33+
If `process.env.TS_NODE_BASEURL` is set it will override the value of `baseUrl` in `tsconfig.json`:
3234

33-
`TS_NODE_BASEURL=./dist node -r tsconfig-paths/register main.js`
35+
```bash
36+
TS_NODE_BASEURL=./dist node -r tsconfig-paths/register main.js
37+
```
3438

3539
### With ts-node
3640

37-
`ts-node -r tsconfig-paths/register main.ts`
41+
```bash
42+
ts-node -r tsconfig-paths/register main.ts
43+
```
3844

39-
If `process.env.TS_NODE_PROJECT` is set it will be used to resolved tsconfig.json
45+
If `process.env.TS_NODE_PROJECT` is set it will be used to resolved `tsconfig.json`
4046

41-
### With webpack
47+
### With Webpack
4248

43-
For webpack please use the [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin).
49+
For Webpack please use the [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin).
4450

4551
### With mocha and ts-node
4652

47-
As of Mocha >= 4.0.0 the `--compiler` was [deprecated](https://github.com/mochajs/mocha/wiki/compilers-deprecation). Instead `--require` should be used. You also have to specify a glob that includes `.ts` files because mocha looks after files with `.js` extension by default.
53+
As of Mocha >= 4.0.0 the `--compiler` was [deprecated](https://mochajs.org/explainers/compilers-deprecation/). Instead `--require` should be used. You also have to specify a glob that includes `.ts` files because mocha looks after files with `.js` extension by default.
4854

4955
```bash
5056
mocha -r ts-node/register -r tsconfig-paths/register "test/**/*.ts"
@@ -58,7 +64,7 @@ As long as the command has something similar to a `--require` option that can lo
5864

5965
The following is an example configuration for the `.vscode/launch.json`.
6066

61-
```js
67+
```jsonc
6268
{
6369
"version": "0.2.0",
6470
"configurations": [
@@ -91,7 +97,7 @@ If you want more granular control over tsconfig-paths you can bootstrap it. This
9197

9298
For example, create a wrapper script called `tsconfig-paths-bootstrap.js` with the contents below:
9399

94-
```javascript
100+
```js
95101
const tsConfig = require("./tsconfig.json");
96102
const tsConfigPaths = require("tsconfig-paths");
97103

@@ -107,7 +113,9 @@ cleanup();
107113

108114
Then run with:
109115

110-
`node -r ./tsconfig-paths-bootstrap.js main.js`
116+
```bash
117+
node -r ./tsconfig-paths-bootstrap.js main.js
118+
```
111119

112120
## Configuration Options
113121

@@ -125,18 +133,18 @@ _Environment variable denoted in parentheses._
125133

126134
## Config loading process
127135

128-
1. Use explicit params passed to register
129-
2. Use `process.env.TS_NODE_PROJECT` to resolve tsConfig.json and the specified baseUrl and paths.
130-
3. Resolves tsconfig.json from current working directory and the specified baseUrl and paths.
136+
1. Use explicit params passed to register
137+
2. Use `process.env.TS_NODE_PROJECT` to resolve `tsConfig.json` and the specified `baseUrl` and paths.
138+
3. Resolves `tsconfig.json` from current working directory and the specified `baseUrl` and paths.
131139

132140
## Programmatic use
133141

134142
The public API consists of these functions:
135143

136144
- [register](#register)
137-
- [loadConfig](#loadConfig)
138-
- [createMatchPath](#createMatchPath) / [createMatchPathAsync](#createMatchPathAsync)
139-
- [matchFromAbsolutePaths](#matchFromAbsolutePaths) / [matchFromAbsolutePathsAsync](#matchFromAbsolutePathsAsync)
145+
- [loadConfig](#loadconfig)
146+
- [createMatchPath](#creatematchpath) / [createMatchPathAsync](#creatematchpathasync)
147+
- [matchFromAbsolutePaths](#matchfromabsolutepaths) / [matchFromAbsolutePathsAsync](#matchfromabsolutepathsasync)
140148

141149
### register
142150

@@ -249,19 +257,19 @@ This is the async version of `matchFromAbsolutePaths`. It has the same signature
249257
250258
## How to publish
251259
252-
```
260+
```bash
253261
yarn version --patch
254262
yarn version --minor
255263
yarn version --major
256264
```
257265
258-
[version-image]: https://img.shields.io/npm/v/tsconfig-paths.svg?style=flat
266+
[version-image]: https://img.shields.io/npm/v/tsconfig-paths?logo=npm&logoColor=fff
259267
[version-url]: https://www.npmjs.com/package/tsconfig-paths
260-
[build-image]: https://github.com/dividab/tsconfig-paths/workflows/CI/badge.svg
261-
[build-url]: https://github.com/dividab/tsconfig-paths/actions/workflows/ci.yml?query=branch%3Amaster
262-
[codecov-image]: https://codecov.io/gh/dividab/tsconfig-paths/branch/master/graph/badge.svg
263-
[codecov-url]: https://codecov.io/gh/dividab/tsconfig-paths
264-
[license-image]: https://img.shields.io/github/license/dividab/tsconfig-paths.svg?style=flat
265-
[license-url]: https://opensource.org/licenses/MIT
266-
[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
268+
[build-image]: https://img.shields.io/github/actions/workflow/status/jonaskello/tsconfig-paths/ci.yml?branch=master&label=CI&logo=github
269+
[build-url]: https://github.com/jonaskello/tsconfig-paths/actions/workflows/ci.yml?query=branch%3Amaster
270+
[codecov-image]: https://img.shields.io/codecov/c/github/dividab/tsconfig-paths?branch=master&label=codecov&logo=codecov&logoColor=fff
271+
[codecov-url]: https://app.codecov.io/gh/dividab/tsconfig-paths/tree/master
272+
[license-image]: https://img.shields.io/github/license/jonaskello/tsconfig-paths
273+
[license-url]: https://opensource.org/license/MIT
274+
[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4
267275
[prettier-url]: https://github.com/prettier/prettier

0 commit comments

Comments
 (0)