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

refactor(is-file): Convert to TypeScript #23093

Merged
merged 11 commits into from
Jun 30, 2020
Merged

Conversation

chooban
Copy link
Contributor

@chooban chooban commented Apr 14, 2020

Description

Converts src/schema/infer/is-file.js to TypeScript.

Related Issues

References #21995

Unfortunately, no tests. I would be happy to add some, even do a prequel PR in JS, if someone could point me at a similar one which creates a NodeStore.

Turns out there is test coverage, just not a unit test. If I run the full test suite then the file has good coverage from somewhere!

The order of functions in the file has change as the linter was complaining about declaration order. I guess that's a new check in TS compared to JS.

I redid the conversion with the functions in the same order in the hope that it would show as a diff rather than delete and add, but no such luck.

I've put a few comments in-line in the PR to outline a few issues.

@chooban chooban requested a review from a team as a code owner April 14, 2020 11:00
? Array.isArray(relativePath)
? relativePath.map(withDir)
: withDir(relativePath)
: null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this check is relevant anymore, possibly ever. getAbsolutePath is called from getFilePath, and the relativePath parameter is a value return from slash in gatsby-core-utils which is defined as returning a string. As such, I think that Array.isArray will always return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at some test coverage data for the original JS file suggests that if it is possible to be an array, it's at least untested.

Screenshot 2020-04-17 at 08 31 35

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right. Let's try not to make any more semantic changes in TS convert PR's than we have to. Then in a followup diff refactor the code because it looks to me like this file can use a little cleanup and modernization.

@chooban chooban marked this pull request as draft April 14, 2020 18:34
@chooban chooban marked this pull request as ready for review April 17, 2020 15:03
@chooban chooban force-pushed the ts-migrate/is-file branch 2 times, most recently from 5618f8e to b005f0e Compare April 23, 2020 16:17
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

I hope I caught everything correctly. In particular, please look into Node vs IGatsbyNode. I think we want to use the latter for everything in this PR.

If you rebase past master you won't have to worry about Loki anymore, either. Thanks!

packages/gatsby/src/schema/infer/is-file.ts Outdated Show resolved Hide resolved
packages/gatsby/src/schema/infer/is-file.ts Outdated Show resolved Hide resolved
packages/gatsby/src/schema/infer/is-file.ts Outdated Show resolved Hide resolved
packages/gatsby/src/schema/infer/is-file.ts Outdated Show resolved Hide resolved
packages/gatsby/src/schema/infer/is-file.ts Outdated Show resolved Hide resolved
@chooban chooban force-pushed the ts-migrate/is-file branch from b005f0e to d806beb Compare May 8, 2020 16:31
@chooban
Copy link
Contributor Author

chooban commented May 8, 2020

Rebased and updated. I put the while loop changes into their own commit.

@chooban chooban requested a review from pvdz June 26, 2020 21:51
@chooban
Copy link
Contributor Author

chooban commented Jun 26, 2020

Apologies, this dropped off of my todo list to keep it updated. Remerged up-to-date after your recent changes.

Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

Yeah this looks good.

Do you want to make the ?. ?? change or leave it like this?

packages/gatsby/src/schema/infer/is-file.ts Show resolved Hide resolved
? Array.isArray(relativePath)
? relativePath.map(withDir)
: withDir(relativePath)
: null
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right. Let's try not to make any more semantic changes in TS convert PR's than we have to. Then in a followup diff refactor the code because it looks to me like this file can use a little cleanup and modernization.

@pvdz pvdz merged commit c2f4b4e into gatsbyjs:master Jun 30, 2020
@pvdz
Copy link
Contributor

pvdz commented Jun 30, 2020

@chooban Thank you! 💜

@chooban chooban deleted the ts-migrate/is-file branch June 30, 2020 16:02
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.

3 participants