-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1e244d
Showing
36 changed files
with
30,883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { "targets": "maintained node versions" }], | ||
"@babel/preset-typescript" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "react-app" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- alpha | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 'lts/*' | ||
|
||
- name: Upgrade NPM | ||
run: npm install -g npm@latest | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Run tests | ||
run: npm t -- --coverage | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 | ||
|
||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test | ||
on: | ||
- push | ||
|
||
jobs: | ||
release: | ||
name: Test | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 'lts/*' | ||
|
||
- name: Upgrade NPM | ||
run: npm install -g npm@latest | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Run tests | ||
run: npm t -- --coverage | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
node_modules | ||
/coverage | ||
/dist | ||
/examples/**/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.github | ||
.DS_Store | ||
coverage | ||
examples | ||
node_modules | ||
scripts | ||
src | ||
.babelrc | ||
.eslintrc | ||
.gitignore | ||
.npmignore | ||
.releaserc.json | ||
jest.config.js | ||
package-lock.json | ||
renovate.json | ||
tsconfig-build.json | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"branches": ["main", { "name": "alpha", "prerelease": true }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Rico Kahler | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# babel-plugin-tsconfig-paths-module-resolver | ||
|
||
[![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) | ||
|
||
> Combines [`babel-plugin-module-resolver`][0] and [`tsconfig-paths`][1] to make a babel plugin that resolves [tsconfig paths][2]. | ||
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]. | ||
|
||
It aims to be stable by relying on these already widely-used packages to power the heavy logic: | ||
|
||
| dependency | weekly downloads | | ||
| ----------------------------------- | -------------------------------------------------------- | | ||
| [`babel-plugin-module-resolver`][0] | [![babel plugin module resolver weekly downloads][3]][4] | | ||
| [`tsconfig-paths`][1] | [![tsconfig-paths weekly downloads][5]][6] | | ||
|
||
These dependencies are automatically updated via [renovate bot](https://github.com/renovatebot/renovate) and [semantic release](https://github.com/semantic-release/semantic-release). | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save-dev babel-plugin-tsconfig-paths-module-resolver | ||
``` | ||
|
||
or | ||
|
||
``` | ||
yarn add --dev babel-plugin-tsconfig-paths-module-resolver | ||
``` | ||
|
||
Specify the plugin in your `.babelrc` (or [equivalent configuration file](https://babeljs.io/docs/en/config-files#configuration-file-types)). | ||
|
||
```js | ||
{ | ||
"presets": [ | ||
// ... | ||
"@babel/preset-typescript", | ||
// ... | ||
], | ||
"plugins": [ | ||
// add this to your babel config file in `plugins` | ||
// 👇👇👇 | ||
"tsconfig-paths-module-resolver" | ||
// 👆👆👆 | ||
// ... | ||
] | ||
} | ||
``` | ||
|
||
## Advanced usage | ||
|
||
`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). | ||
|
||
You can supply those extra options in your babel configuration file like so: | ||
|
||
```js | ||
{ | ||
"presets": [ | ||
// ... | ||
"@babel/preset-typescript", | ||
// ... | ||
], | ||
"plugins": [ | ||
// ... | ||
[ | ||
"tsconfig-paths-module-resolver", | ||
// add extra options here | ||
// 👇👇👇 | ||
{ | ||
// see here: | ||
// https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md | ||
} | ||
// 👆👆👆 | ||
] | ||
] | ||
}; | ||
``` | ||
|
||
### `resolvePath` and `createResolvePath` | ||
|
||
[`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. | ||
|
||
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. | ||
|
||
```js | ||
const createResolvePath = require('babel-plugin-tsconfig-paths-module-resolver/create-resolve-path'); | ||
const defaultResolvePath = createResolvePath(); | ||
|
||
/** | ||
* @param sourceFile {string} the input source path | ||
* @param currentFile {string} the absolute path of the current file | ||
* @param opts {any} the options as passed to the Babel config | ||
* @return {string} | ||
*/ | ||
function customResolvePath(sourceFile, currentFile, opts) { | ||
// ... | ||
const result = defaultResolvePath(sourceFile, currentFile, opts); | ||
// ... | ||
|
||
return result; | ||
} | ||
|
||
// .babelrc.js | ||
module.exports = { | ||
presets: [ | ||
// ... | ||
'@babel/preset-typescript', | ||
// ... | ||
], | ||
plugins: [ | ||
// ... | ||
[ | ||
'tsconfig-paths-module-resolver', | ||
{ | ||
// 👇👇👇 | ||
resolvePath: customResolvePath, | ||
// 👆👆👆 | ||
}, | ||
], | ||
], | ||
}; | ||
``` | ||
|
||
[0]: https://github.com/tleunen/babel-plugin-module-resolver | ||
[1]: https://github.com/dividab/tsconfig-paths | ||
[2]: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping | ||
[3]: https://badgen.net/npm/dw/babel-plugin-module-resolver | ||
[4]: https://www.npmjs.com/package/babel-plugin-module-resolver | ||
[5]: https://badgen.net/npm/dw/tsconfig-paths | ||
[6]: https://www.npmjs.com/package/tsconfig-paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { createResolvePath } from './dist'; | ||
export = createResolvePath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const { createResolvePath } = require('./dist'); | ||
module.exports = createResolvePath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
this folder was made to hold examples used primarily for testing. | ||
|
||
the `index.test.ts` file compiles each example and imports the finished result. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
|
||
const execute = promisify(exec); | ||
|
||
jest.setTimeout(30 * 1000); | ||
|
||
beforeAll(async () => { | ||
const build = await execute('npm run build'); | ||
if (build.stderr) console.error(build.stderr); | ||
|
||
const buildExamples = await execute('npm run build-examples'); | ||
if (buildExamples.stderr) console.error(buildExamples.stderr); | ||
}); | ||
|
||
describe('examples', () => { | ||
test('standard', () => { | ||
const standard = jest.requireActual( | ||
'@babel-plugin-tsconfig-paths-module-resolver/standard', | ||
).default; | ||
|
||
expect(standard).toMatchInlineSnapshot(` | ||
Array [ | ||
"from src/bar/a", | ||
"from src/foo/b", | ||
"from umbrella/baz/c", | ||
] | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
presets: [ | ||
'@babel/preset-typescript', | ||
['@babel/preset-env', { targets: { node: true } }], | ||
], | ||
plugins: [require.resolve('../..')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@babel-plugin-tsconfig-paths-module-resolver/standard", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"build": "babel -x .ts ./src --out-dir ./dist" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'from src/bar/a'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'from src/foo/b'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import a from '@/bar/a'; | ||
import b from '@/foo/b'; | ||
import c from '@/baz/c'; | ||
|
||
export default [a, b, c]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'from umbrella/baz/c'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"baseUrl": "./src", | ||
"paths": { | ||
"@/*": ["umbrella/*", "*"] | ||
} | ||
}, | ||
"include": ["./src/**/*.ts"], | ||
"exclude": ["**/node_modules"] | ||
} |
Oops, something went wrong.