Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple --exclude arguments #905

Closed
balupton opened this issue Nov 21, 2018 · 10 comments
Closed

Support multiple --exclude arguments #905

balupton opened this issue Nov 21, 2018 · 10 comments
Labels
enhancement Improved functionality help wanted Contributions are especially encouraged

Comments

@balupton
Copy link

Via the API, exclude supports an array #170 (comment)

However, via the CLI, it only supports a single usage instead of multiple. It would be nice if the CLI concatenated multiple --exclude values into an array, so we can do:

typedoc --exclude '**/*test*' --exclude '**/node_modules/** --exclude '**/test/**

as unfortunately, this workaround does not work for the above:

typedoc --exclude '**/{*test*,{node_modules|test}/**}'
@aciccarello aciccarello added enhancement Improved functionality help wanted Contributions are especially encouraged labels Nov 21, 2018
@aciccarello
Copy link
Collaborator

Thanks for the suggestion! I agree this would be a helpful. If anyone would like to implement this, please reach out for discussion!

@balupton
Copy link
Author

balupton commented Nov 21, 2018

I took a look to try and find where this is defined, but seems more complicated than a first glance offers.

Perhaps it would make sense to use https://github.com/cacjs/cac (personal favourite in that space) instead of what appears to be a custom built solution.

cac already supports the --exclude foo --exclude bar use case: cacjs/cac#24

@aciccarello
Copy link
Collaborator

@balupton For your use case, wouldn't the following work? Essentially you are passing a list of globs wrapped in curly brackets.

typedoc --exclude '{**/*test*,**/node_modules/**,**/test/**}'

@9oelM
Copy link
Contributor

9oelM commented Jan 11, 2019

Perhaps we need to set up a simple test against that to verify.

@aciccarello
Copy link
Collaborator

Yeah, we should test that. I seem to recall bracket syntax didn't work well.

@9oelM
Copy link
Contributor

9oelM commented Jan 12, 2019

May be relevant. Just taking notes for reference

const exclude = this.exclude
? createMinimatch(this.exclude)
: [];
function isExcluded(fileName: string): boolean {
return exclude.some(mm => mm.match(fileName));
}
function add(dirname: string) {
FS.readdirSync(dirname).forEach((file) => {
const realpath = Path.join(dirname, file);
if (FS.statSync(realpath).isDirectory()) {
add(realpath);
} else if (/\.tsx?$/.test(realpath)) {
if (isExcluded(realpath.replace(/\\/g, '/'))) {
return;
}
files.push(realpath);
}
});
}
inputFiles.forEach((file) => {
file = Path.resolve(file);
if (FS.statSync(file).isDirectory()) {
add(file);
} else if (!isExcluded(file)) {
files.push(file);
}
});

private compile(context: Context): ReadonlyArray<ts.Diagnostic> {
const program = context.program;
const exclude = createMinimatch(this.application.exclude || []);
const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName));
const includedSourceFiles = program.getSourceFiles()
.filter(file => !isExcluded(file));
const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file);
includedSourceFiles.forEach((sourceFile) => {
this.convertNode(context, sourceFile);
});

/**
* Convert array of glob patterns to array of minimatch instances.
*
* Handle a few Windows-Unix path gotchas.
*/
export function createMinimatch(patterns: string[]): IMinimatch[] {
return patterns.map((pattern: string): IMinimatch => {
// Ensure correct pathing on unix, by transforming `\` to `/` and removing any `X:/` from the path
if (unix) { pattern = pattern.replace(/[\\]/g, '/').replace(/^\w:/, ''); }
// pattern paths not starting with '**' are resolved even if it is an
// absolute path, to ensure correct format for the current OS
if (pattern.substr(0, 2) !== '**') {
pattern = Path.resolve(pattern);
}
// On Windows we transform `\` to `/` to unify the way paths are intepreted
if (!unix) { pattern = pattern.replace(/[\\]/g, '/'); }
// Unify the path slashes before creating the minimatch, for more reliable matching
return new Minimatch(pattern, { dot: true });
});
}

@Downchuck
Copy link

@aciccarello That glob syntax has strange semantics -- I can't tell what it's actually doing -- if I remove the first test clause, it no longer filters node_modules. If I change test to spec, it's not actually filtering out spec files.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 9, 2019

@Downchuck that's because TypeDoc currently splits the glob on , before matching it (I know, I know...) once resolved, it should behave as expected.

@Downchuck
Copy link

@Gerrit0 No idea how to math that in my brain pan - but this is working '{**/*spec*,**/*.spec.ts,**/node_modules/**,**/*spec.ts}' though no idea why. As you said, something to do with the comma - as when I take out the first or last item my spec or node_modules are no longer filtered.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 15, 2020

As of 0.16, this is supported.

@Gerrit0 Gerrit0 closed this as completed Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality help wanted Contributions are especially encouraged
Projects
None yet
Development

No branches or pull requests

5 participants