From 5da42e13bc7c08bbffbb3fd58f377be44f402080 Mon Sep 17 00:00:00 2001 From: Marty Mcfly Date: Sat, 9 Feb 2019 13:09:20 +0300 Subject: [PATCH] feat(ts-transform-paths): added exclude and for options to config, #10 --- packages/ts-transform-paths/README.md | 23 ++++++++++++++++++++++- packages/ts-transform-paths/src/index.ts | 21 +++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/ts-transform-paths/README.md b/packages/ts-transform-paths/README.md index 0a6e87c..405e4f9 100644 --- a/packages/ts-transform-paths/README.md +++ b/packages/ts-transform-paths/README.md @@ -20,7 +20,10 @@ my-lib/tsconfig.json: "my-lib/*": ["src/*"] }, "plugins": [ - { "transform": "@zerollup/ts-transform-paths" } + { + "transform": "@zerollup/ts-transform-paths", + "exclude": ["*"] + } ] } } @@ -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. diff --git a/packages/ts-transform-paths/src/index.ts b/packages/ts-transform-paths/src/index.ts index 1b6436e..f99d937 100644 --- a/packages/ts-transform-paths/src/index.ts +++ b/packages/ts-transform-paths/src/index.ts @@ -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 { @@ -173,9 +183,12 @@ export default function transformPaths(program?: ts.Program, config?: Config) { before( transformationContext: ts.TransformationContext ): ts.Transformer { - 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 = {