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

Improve source pattern handling #730

Merged
merged 3 commits into from
Apr 12, 2016
Merged

Conversation

novemberborn
Copy link
Member

Bugfix where ..file.js sources were treated as being outside the current working directory. But the main change of this PR is that negated source patterns are now handled much better 💥

Fixes #614. Allow negated source patterns to be specified without unsetting the default negation patterns.

Allow source patterns to override the default negation patterns if they start with one of the ignored directories.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @sotojuan, @zhaozhiming and @forresst to be potential reviewers

@@ -858,17 +859,46 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
});

test('ignores dependencies outside of the current working directory', function (t) {
test('allows default exclusion patterns to be overriden', function (t) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we land the API refactor, I would like to move all the logic of building include/exclude patterns from the config into lib/ava-files, and rewrite many of these tests so they are just:

t.true(avaFiles.shouldWatch('some/path'));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea would be good to centralize the pattern matching logic.

@jamestalmage
Copy link
Contributor

Trying to understand what we are fixing here:

Seems like a few things:

  • Proper handling of relative paths that start with ../
  • Source patterns can specify node_modules/some_dir even though ignore patterns still have node_modules/**
  • Using a negation pattern in sources (!lib/somedir/**), will not override default ignores

@novemberborn
Copy link
Member Author

@jamestalmage yup, perfect score!

@jamestalmage
Copy link
Contributor

It just seems we have a whole lot of code manipulating glob patterns.

Ignoring for a moment our intent to refactor much of that to ava-files, is there a good reason we have made it so complicated?

The code looks good, just wondering if we need to rethink some of the design decisions that led us here.

@novemberborn
Copy link
Member Author

@jamestalmage different use cases I think. Chokidar needs to watch tests and sources, and exclude particular directories. But we also want it to not exclude certain directories. Then we need to see if a changed file was a source or a test which again has different logic… Let me know where it isn't clear and I can add some comments.

@novemberborn
Copy link
Member Author

Any further feedback aside from refactoring concerns?

You can configure patterns for the source files using the [`--source` CLI flag] or in the `ava` section of your `package.json` file. Note that if you specify a negative pattern the directories from [`ignore-by-default`] will no longer be ignored, so you may want to repeat these in your config.
You can configure patterns for the source files using the [`--source` CLI flag] or in the `ava` section of your `package.json` file.

You can specify patterns to match files in the folders that would otherwise be ignored, e.g. use `node_modules/some-dependency/*.js` to specify all `.js` files in `node_modules/some-dependency` as a source, even though normally all files in `node_modules` are ignored. Note that you need to specify an exact directory; `{.bower_components,node_modules}/**/*.js` won't work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.bower_components => bower_components

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@sindresorhus
Copy link
Member

LGTM when the nitpick inline feedback is resolved.

Make sure the path starts with ../ (after platform-specific slashes have been
corrected). Clarify existing test and add a case where the source starts with
two dots but is still in the current working directory.
Fixes #614. Allow negated source patterns to be specified without unsetting the
default negation patterns.

Allow source patterns to override the default negation patterns if they start
with one of the ignored directories.
@novemberborn novemberborn force-pushed the better-negated-source-patterns branch from 4ff70bd to 5c65590 Compare April 12, 2016 11:29
* Suggest `watch:test` as the npm script
* Document how to always enable watch mode using the ava section in package.json
* Recommend source patterns are configured through the ava section in package.json
* Suggest using the verbose reporter when debugging
@novemberborn novemberborn force-pushed the better-negated-source-patterns branch from 5c65590 to 919e5cf Compare April 12, 2016 11:30
@novemberborn
Copy link
Member Author

Addressed feedback. Made some other changes to the docs, see the last commit.

@sindresorhus
Copy link
Member

@jamestalmage :shipit:?

@jamestalmage jamestalmage merged commit a3565fd into master Apr 12, 2016
@jamestalmage jamestalmage deleted the better-negated-source-patterns branch April 12, 2016 21:52
@jamestalmage
Copy link
Contributor

🎉 Looks good @novemberborn

novemberborn added a commit that referenced this pull request Apr 13, 2016
Not caught earlier probably because #730 wasn't rebased.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve source pattern handling
4 participants