Skip to content

Commit c1e244d

Browse files
committed
feat: first commit
0 parents  commit c1e244d

36 files changed

+30883
-0
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", { "targets": "maintained node versions" }],
4+
"@babel/preset-typescript"
5+
]
6+
}

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "react-app"
3+
}

.github/workflows/release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- alpha
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-18.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 'lts/*'
22+
23+
- name: Upgrade NPM
24+
run: npm install -g npm@latest
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Lint
30+
run: npm run lint
31+
32+
- name: Run tests
33+
run: npm t -- --coverage
34+
35+
- name: Upload coverage to Codecov
36+
uses: codecov/codecov-action@v2
37+
38+
- name: Release
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
run: npx semantic-release

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test
2+
on:
3+
- push
4+
5+
jobs:
6+
release:
7+
name: Test
8+
runs-on: ubuntu-18.04
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: 'lts/*'
19+
20+
- name: Upgrade NPM
21+
run: npm install -g npm@latest
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Lint
27+
run: npm run lint
28+
29+
- name: Run tests
30+
run: npm t -- --coverage
31+
32+
- name: Upload coverage to Codecov
33+
uses: codecov/codecov-action@v2

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
/coverage
4+
/dist
5+
/examples/**/dist

.npmignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.github
2+
.DS_Store
3+
coverage
4+
examples
5+
node_modules
6+
scripts
7+
src
8+
.babelrc
9+
.eslintrc
10+
.gitignore
11+
.npmignore
12+
.releaserc.json
13+
jest.config.js
14+
package-lock.json
15+
renovate.json
16+
tsconfig-build.json
17+
tsconfig.json

.releaserc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"branches": ["main", { "name": "alpha", "prerelease": true }]
3+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Rico Kahler
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# babel-plugin-tsconfig-paths-module-resolver
2+
3+
[![npm](https://badgen.net/npm/v/babel-plugin-tsconfig-paths-module-resolver)](https://www.npmjs.com/package/babel-plugin-tsconfig-paths-module-resolver) [![Github Actions](https://badgen.net/github/checks/ricokahler/babel-plugin-tsconfig-paths-module-resolver)](https://github.com/ricokahler/babel-plugin-tsconfig-paths-module-resolver/actions) [![codecov](https://codecov.io/gh/ricokahler/babel-plugin-tsconfig-paths-module-resolver/branch/main/graph/badge.svg?token=2cQuXwu8Gq)](https://codecov.io/gh/ricokahler/babel-plugin-tsconfig-paths-module-resolver) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
4+
5+
> Combines [`babel-plugin-module-resolver`][0] and [`tsconfig-paths`][1] to make a babel plugin that resolves [tsconfig paths][2].
6+
7+
This library is a re-export of [`babel-plugin-module-resolver`](https://github.com/tleunen/babel-plugin-module-resolver) pre-configured with [tsconfig paths][2] support via the package [`tsconfig-paths`][1].
8+
9+
It aims to be stable by relying on these already widely-used packages to power the heavy logic:
10+
11+
| dependency | weekly downloads |
12+
| ----------------------------------- | -------------------------------------------------------- |
13+
| [`babel-plugin-module-resolver`][0] | [![babel plugin module resolver weekly downloads][3]][4] |
14+
| [`tsconfig-paths`][1] | [![tsconfig-paths weekly downloads][5]][6] |
15+
16+
These dependencies are automatically updated via [renovate bot](https://github.com/renovatebot/renovate) and [semantic release](https://github.com/semantic-release/semantic-release).
17+
18+
## Installation
19+
20+
```
21+
npm install --save-dev babel-plugin-tsconfig-paths-module-resolver
22+
```
23+
24+
or
25+
26+
```
27+
yarn add --dev babel-plugin-tsconfig-paths-module-resolver
28+
```
29+
30+
Specify the plugin in your `.babelrc` (or [equivalent configuration file](https://babeljs.io/docs/en/config-files#configuration-file-types)).
31+
32+
```js
33+
{
34+
"presets": [
35+
// ...
36+
"@babel/preset-typescript",
37+
// ...
38+
],
39+
"plugins": [
40+
// add this to your babel config file in `plugins`
41+
// 👇👇👇
42+
"tsconfig-paths-module-resolver"
43+
// 👆👆👆
44+
// ...
45+
]
46+
}
47+
```
48+
49+
## Advanced usage
50+
51+
`babel-plugin-tsconfig-paths-module-resolver` accepts the same options as [`babel-plugin-module-resolver`](https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md).
52+
53+
You can supply those extra options in your babel configuration file like so:
54+
55+
```js
56+
{
57+
"presets": [
58+
// ...
59+
"@babel/preset-typescript",
60+
// ...
61+
],
62+
"plugins": [
63+
// ...
64+
[
65+
"tsconfig-paths-module-resolver",
66+
// add extra options here
67+
// 👇👇👇
68+
{
69+
// see here:
70+
// https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md
71+
}
72+
// 👆👆👆
73+
]
74+
]
75+
};
76+
```
77+
78+
### `resolvePath` and `createResolvePath`
79+
80+
[`babel-plugin-module-resolver`][0] includes [a configuration option](https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#resolvepath) to allow you to programmatically resolve your imports.
81+
82+
This plugin provides a `resolvePath` implementation powered by [`tsconfig-paths`][1]. If you'd like to implement your own `resolvePath` implementation while still utilizing this plugin's default implementation, you can separately import `createResolvePath` that returns a `resolvePath` implementation.
83+
84+
```js
85+
const createResolvePath = require('babel-plugin-tsconfig-paths-module-resolver/create-resolve-path');
86+
const defaultResolvePath = createResolvePath();
87+
88+
/**
89+
* @param sourceFile {string} the input source path
90+
* @param currentFile {string} the absolute path of the current file
91+
* @param opts {any} the options as passed to the Babel config
92+
* @return {string}
93+
*/
94+
function customResolvePath(sourceFile, currentFile, opts) {
95+
// ...
96+
const result = defaultResolvePath(sourceFile, currentFile, opts);
97+
// ...
98+
99+
return result;
100+
}
101+
102+
// .babelrc.js
103+
module.exports = {
104+
presets: [
105+
// ...
106+
'@babel/preset-typescript',
107+
// ...
108+
],
109+
plugins: [
110+
// ...
111+
[
112+
'tsconfig-paths-module-resolver',
113+
{
114+
// 👇👇👇
115+
resolvePath: customResolvePath,
116+
// 👆👆👆
117+
},
118+
],
119+
],
120+
};
121+
```
122+
123+
[0]: https://github.com/tleunen/babel-plugin-module-resolver
124+
[1]: https://github.com/dividab/tsconfig-paths
125+
[2]: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
126+
[3]: https://badgen.net/npm/dw/babel-plugin-module-resolver
127+
[4]: https://www.npmjs.com/package/babel-plugin-module-resolver
128+
[5]: https://badgen.net/npm/dw/tsconfig-paths
129+
[6]: https://www.npmjs.com/package/tsconfig-paths

create-resolve.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { createResolvePath } from './dist';
2+
export = createResolvePath;

0 commit comments

Comments
 (0)