Skip to content

Commit

Permalink
feat(ts-transform-paths): added exclude and for options to config, #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Marty Mcfly committed Feb 9, 2019
1 parent a54901e commit 5da42e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
23 changes: 22 additions & 1 deletion packages/ts-transform-paths/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ my-lib/tsconfig.json:
"my-lib/*": ["src/*"]
},
"plugins": [
{ "transform": "@zerollup/ts-transform-paths" }
{
"transform": "@zerollup/ts-transform-paths",
"exclude": ["*"]
}
]
}
}
Expand Down Expand Up @@ -50,6 +53,24 @@ export * from './some';

For more examples see [zerollup demo lib](https://github.com/zerkalica/zerollup-demo/tree/master/packages/lib1).

## Plugin options

```ts
interface Config {
/**
Add a browser mode -- meaning that path resolution includes
determining exact FILE being imported (with extension) as this
is required by browsers when not using browserfy or rollup or any of the other packaging tools
*/
for?: string | void

/**
Disable plugin path resolving for given paths keys
*/
exclude?: string[] | void
}
```

## Limitations

Only first element in paths substitutions array used.
Expand Down
21 changes: 17 additions & 4 deletions packages/ts-transform-paths/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ function createFixNode(sf: ts.SourceFile): FixNode {
}

interface Config {
for: string
/**
Add a browser mode -- meaning that path resolution includes
determining exact FILE being imported (with extension) as this
is required by browsers when not using browserfy or rollup or any of the other packaging tools
*/
for?: string | void

/**
Disable plugin path resolving for given paths keys
*/
exclude?: string[] | void
}

interface ImportPathVisitorContext {
Expand Down Expand Up @@ -173,9 +183,12 @@ export default function transformPaths(program?: ts.Program, config?: Config) {
before(
transformationContext: ts.TransformationContext
): ts.Transformer<ts.SourceFile> {
const resolver = new ImportPathsResolver(
transformationContext.getCompilerOptions()
)
const options = transformationContext.getCompilerOptions()
const resolver = new ImportPathsResolver({
paths: options.paths,
baseUrl: options.baseUrl,
exclude: config && config.exclude,
})

return (sf: ts.SourceFile) => {
const ctx: ImportPathVisitorContext = {
Expand Down

0 comments on commit 5da42e1

Please sign in to comment.