-
-
Notifications
You must be signed in to change notification settings - Fork 738
General correction of glob patterns and config file locating #742
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ed379ea
Add paths util
668d104
Add general minimatch function to `externalPattern`
cd7970d
Add general minimatch function to `exclude`
3c80f10
Fix typedoc.js(on) options file finding
ac777fc
Optimize tsconfig.json file finding
7728227
Update dependencies
4227851
Add unit tests for matching paths
4b9ca6c
style tweaks
aciccarello a6bb62d
add file name back into tsconfig load error
aciccarello b9d45ef
Revert "Update dependencies"
28c5e22
Force 4 spaces as indent for the TS Lint
f98996b
createMinimatch fixed
a234012
updated @types/mocha to match current mocha version
bc3b235
Merge branch 'master' into fix/paths
aciccarello 2a6557f
CreateMinimatch always assumes array of strings + single star paths a…
91bc957
Correct createMinimatch unit test
2cf1f5f
Correct posix pathing
34b7a4c
Merge branch 'master' into pr/742
Gerrit0 e5ed318
Resolve build errors
Gerrit0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,23 @@ | ||
import * as Path from 'path'; | ||
import { Minimatch, IMinimatch } from 'minimatch'; | ||
|
||
const unix = Path.sep === '/'; | ||
|
||
export function createMinimatch(patterns: string[]): IMinimatch[] { | ||
return patterns.map((pattern: string): IMinimatch => { | ||
// Ensure correct pathing on unix, by transforming `\` to `/` and remvoing any `X:/` fromt he 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 relyable matching | ||
return new Minimatch(pattern, { dot: true }); | ||
}); | ||
} |
This file contains hidden or 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,62 @@ | ||
import * as Path from 'path'; | ||
import { Minimatch } from 'minimatch'; | ||
|
||
import isEqual = require('lodash/isEqual'); | ||
import Assert = require('assert'); | ||
|
||
import { createMinimatch } from '..'; | ||
|
||
// Used to ensure uniform path cross OS | ||
const absolutePath = (path: string) => Path.resolve(path.replace(/^\w:/, '')).replace(/[\\]/g, '/'); | ||
|
||
describe('Paths', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for writing tests! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure thing |
||
describe('createMinimatch', () => { | ||
it('Converts an array of paths to an array of Minimatch expressions', () => { | ||
const mms = createMinimatch(['/some/path/**', '**/another/path/**', './relative/**/path']); | ||
Assert(Array.isArray(mms), 'Didn\'t return an array'); | ||
|
||
const allAreMm = mms.every((mm) => mm instanceof Minimatch); | ||
Assert(allAreMm, 'Not all paths are coverted to Minimatch'); | ||
}); | ||
|
||
it('Minimatch can match absolute paths expressions', () => { | ||
const paths = ['/unix/absolute/**/path', '\\windows\\alternative\\absolute\\path', 'C:\\Windows\\absolute\\*\\path', '**/arbitrary/path/**']; | ||
const mms = createMinimatch(paths); | ||
const patterns = mms.map(({ pattern }) => pattern); | ||
const comparePaths = [ | ||
absolutePath('/unix/absolute/**/path'), | ||
absolutePath('/windows/alternative/absolute/path'), | ||
absolutePath('/Windows/absolute/*/path'), | ||
'**/arbitrary/path/**' | ||
]; | ||
|
||
Assert(isEqual(patterns, comparePaths), `Patterns have been altered:\nMMS: ${patterns}\nPaths: ${comparePaths}`); | ||
|
||
Assert(mms[0].match(absolutePath('/unix/absolute/some/sub/dir/path')), 'Din\'t match unix path'); | ||
Assert(mms[1].match(absolutePath('/windows/alternative/absolute/path')), 'Din\'t match windows alternative path'); | ||
Assert(mms[2].match(absolutePath('/Windows/absolute/test/path')), 'Din\'t match windows path'); | ||
Assert(mms[3].match(absolutePath('/some/deep/arbitrary/path/leading/nowhere')), 'Din\'t match arbitrary path'); | ||
}); | ||
|
||
it('Minimatch can match relative to the project root', () => { | ||
const paths = ['./relative/**/path', '../parent/*/path', 'no/dot/relative/**/path/*', '*/subdir/**/path/*', '.dot/relative/**/path/*']; | ||
const absPaths = paths.map((path) => absolutePath(path)); | ||
const mms = createMinimatch(paths); | ||
const patterns = mms.map(({ pattern }) => pattern); | ||
|
||
Assert(isEqual(patterns, absPaths), `Project root have not been added to paths:\nMMS: ${patterns}\nPaths: ${absPaths}`); | ||
|
||
Assert(mms[0].match(Path.resolve('relative/some/sub/dir/path')), 'Din\'t match relative path'); | ||
Assert(mms[1].match(Path.resolve('../parent/dir/path')), 'Din\'t match parent path'); | ||
Assert(mms[2].match(Path.resolve('no/dot/relative/some/sub/dir/path/test')), 'Din\'t match no dot path'); | ||
Assert(mms[3].match(Path.resolve('some/subdir/path/here')), 'Din\'t match single star path'); | ||
Assert(mms[4].match(Path.resolve('.dot/relative/some/sub/dir/path/test')), 'Din\'t match dot path'); | ||
}); | ||
|
||
it('Minimatch matches dot files', () => { | ||
const mm = createMinimatch(['/some/path/**'])[0]; | ||
Assert(mm.match(absolutePath('/some/path/.dot/dir')), 'Didn\'t match .dot path'); | ||
Assert(mm.match(absolutePath('/some/path/normal/dir')), 'Didn\'t match normal path'); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this line is responsible for making typedoc 0.14 a breaking change for my projects.
The path that I use for my config file is something like
node_modules/my-config-project/config/typedoc.config.json
This worked fine in 0.13 but breaks in 0.14.
I now need to update the path on 60+ projects..