Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Add extensions option for TypeScript support and other extensions in the future #9

Closed
wants to merge 10 commits into from

Conversation

huan
Copy link

@huan huan commented Nov 21, 2016

@sindresorhus
Copy link
Member

There are more places here where .js is hardcoded. Also see my comment here: #4 (comment)

We also need to decide whether extension should replace .js or be an addition.

@huan
Copy link
Author

huan commented Nov 21, 2016

Ah, got it.

I just did a check, and list the following parts need to add extensions support too:

  • defaultIncludePatterns()
  • mixedPatterns
  • isTest()
    • path.extname(filePath)
    • recursivePatterns
  • getChokidarPatterns()
  • handlePaths()

About whether extensions should replace .js or be an addition, my idea is replace. That's because I believe extensions should include .js in it, and without hardcoded .js, the code can be cleaner for support extensions.

Which one do you prefer, replace or additional?

@sindresorhus
Copy link
Member

Thinking about it more, replacing makes the most sense here. Why would you even use .js if you have a TypeScript project, and if you have that edge-case, it's still possible to manually specify it.

@huan
Copy link
Author

huan commented Nov 21, 2016

Ok, so both of us agree to use replace.

I'll try to modify the code later, get rid of all part of the hard coded .js, and start using extensions to rewrite current related codes.

@sindresorhus sindresorhus changed the title Add new parameter: extensions for TypeScript Support(and other extension names in the future) Addextensions option for TypeScript support and other extensions in the future Nov 22, 2016
@sindresorhus sindresorhus changed the title Addextensions option for TypeScript support and other extensions in the future Add extensions option for TypeScript support and other extensions in the future Nov 22, 2016

if (process.platform === 'win32') {
// Always use / in patterns, harmonizing matching across platforms.
pattern = slash(pattern);
// pattern = slash(pattern);
patternList = patternList.map(function (p) {
Copy link

Choose a reason for hiding this comment

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

This should be the same as patternList.map(slash); no?

Copy link
Author

Choose a reason for hiding this comment

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

yes, you are right, it's the same. thanks!

'test.js',
'test-*.js',
function defaultIncludePatterns(extensions) {
var patternList = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Imo it could just be patterns.

Copy link
Author

Choose a reason for hiding this comment

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

done.

@@ -241,14 +266,20 @@ function handlePaths(files, excludePatterns, globOptions) {

searchedParents[file] = true;

var pattern = path.join(file, '**', '*.js');
// var pattern = path.join(file, '**', '*.js');
var patternList = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

patterns too?

Copy link
Author

Choose a reason for hiding this comment

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

done too.

// var pattern = path.join(file, '**', '*.js');
var patternList = [];
globOptions.extensions.forEach(function (ext) {
patternList.push(path.join(file, '**', '*.' + ext));
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistency between https://github.com/avajs/ava-files/pull/9/files#diff-168726dbe96b3ce427e7fedce31bb0bcR187. path.join() is used here, unlike in that other place. I think it should be used in both places.

Copy link
Contributor

Choose a reason for hiding this comment

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

Although, since we are using slash(), path.join() is not necessary.

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -269,6 +300,16 @@ function handlePaths(files, excludePatterns, globOptions) {
});
}

function validFileName(file, extensions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isValidFileName would be better.

Copy link
Author

Choose a reason for hiding this comment

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

done


const files = await avaFiles.findTestFiles();
const expected = [
'typescript.ts'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be on the same line.

Copy link
Author

Choose a reason for hiding this comment

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

done

const files = await avaFiles.findTestFiles();
const expected = [
'typescript.ts'
].map(function (file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be an arrow function.

Copy link
Author

Choose a reason for hiding this comment

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

done

@huan
Copy link
Author

huan commented Nov 28, 2016

Hey @vdemedes ,

Thanks for the review, I had followed your suggestions and made a new push.

@sindresorhus
Copy link
Member

I would be more confident in this change if it had more tests.

@sindresorhus
Copy link
Member

There's lot of commented code left in there. Please always review the diff before pushing changes.

@huan
Copy link
Author

huan commented Nov 29, 2016

Sorry for the commented code because I use them to compare the code at first, and forgot to clean them. Just cleaned them all.

About the tests, I added a new test with empty extensions option, which should get nothing from ava-files.

What kind of tests do you think we need to add more? I can follow you, but now I can only think about test extensions parameter, which could be a ['ts'] or [].

@novemberborn
Copy link
Member

@zixia this might prove quite useful for RFC001! However we've decided to move this code back into AVA core. I'm closing this PR since it won't land here, but I'll make sure to remember it for when we need this functionality.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants