Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
add doc

fix path not found

remove yarn 3 pnp

bump 1.0.3
  • Loading branch information
frankleng committed Jan 25, 2022
1 parent aa5ab25 commit f054af9
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish to npm
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm i
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 100
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# esbuild-ts-paths
Transform TS path alias to absolute paths for esbuild

```javascript
const tsPaths = require("esbuild-ts-paths")
esbuild.build({
//...
plugins:[
tsPaths(
"./path/to/tsconfig.json" // optional, defaults to ./tsconfig.json
)
]
})
```
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { sync: glob } = require("fast-glob");
const path = require("path");

module.exports = (tsconfigPath = './tsconfig.json') => {
const { compilerOptions } = require(path.resolve(process.cwd(), tsconfigPath));
const pathKeys = Object.keys(compilerOptions.paths);
const re = new RegExp(`^(${pathKeys.join("|")})`);
return {
name: "esbuild-ts-paths",
setup(build) {
build.onResolve({ filter: re }, (args) => {
const pathKey = pathKeys.find((pkey) => new RegExp(`^${pkey}`).test(args.path));
const [pathDir] = pathKey.split("*");
const file = args.path.replace(pathDir, "");
for (const dir of compilerOptions.paths[pathKey]) {
const [matchedFile] = glob(`${path.resolve(process.cwd(), dir).replace("*", file)}.*`);
if (matchedFile) {
return { path: matchedFile };
}
}
return { path: args.path };
});
},
};
};
Loading

0 comments on commit f054af9

Please sign in to comment.