Skip to content

Move to TypeScript - #1750

Merged
fregante merged 117 commits into
refined-github:masterfrom
nickytonline:typescript-migration
Feb 8, 2019
Merged

fregante merged 117 commits into
refined-github:masterfrom
nickytonline:typescript-migration

Conversation

@nickytonline

Copy link
Copy Markdown
Contributor

I'm just opening the PR right away @sindresorhus, so that I can get back any feedback from you as I move along.

Comment thread source/globals.d.ts Resolved
Comment thread source/globals.d.ts Resolved
Comment thread source/globals.d.ts Resolved
Comment thread source/libs/api.ts Resolved
Comment thread source/libs/api.ts Resolved
Comment thread source/globals.d.ts Resolved
@nickytonline

Copy link
Copy Markdown
Contributor Author

I'll work on this some more tomorrow evening and probably the weekend. 👋 for now.

@nickytonline

Copy link
Copy Markdown
Contributor Author

This WIP PR implements #1735.

Comment thread source/libs/api.ts Resolved
Comment thread package.json Resolved
Comment thread source/globals.d.ts Resolved
Comment thread source/libs/api.ts Resolved
Comment thread source/libs/api.ts Resolved
Comment thread source/types/browser.d.ts Resolved
Comment thread source/types/globals.d.ts Resolved
Comment thread source/types/globals.d.ts Resolved
Comment thread source/features/add-co-authored-by.tsx Resolved
Comment thread source/features/bypass-checks.tsx Resolved
Comment thread source/libs/cache.ts Resolved
for (const comment of comments) {
const timestampEl = select('relative-time', comment);
const timestamp = timestampEl.attributes.datetime.value;
const timestamp = timestampEl.attributes['datetime'].value; // eslint-disable-line dot-notation

@nickytonline nickytonline Feb 2, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I disabled the dot-notation rule here because the type checking fails otherwise. I know it works in JS land, but the types are strict, so it's required to use [] notation because in the generic sense, not every element has an attributes.datetime property.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the correct way would be to cast select<HTMLTimeElement> or whatever element GitHub’s relative-time extends

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should cast it to the correct element instead, after the “select” call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I feel silly for not knowing there was a time element, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tim. Will cast accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like even when it is cast to HTMLTimeElement, it still complains.

image

It's actually the <relative-time /> web component from github.com/github/time-elements that they're using, so you have no choice but to access it via attributes with the [] notation.

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe the issue is that time actually has a dateTime attribute: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement (camelcase)

const timestampEl = select<HTMLTimeElement>('relative-time', comment);
const timestamp = timestampEl.attributes.dateTime.value;

Does that work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It works in the browser but not in TS land.

image

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread source/libs/utils.js Resolved
@nickytonline

Copy link
Copy Markdown
Contributor Author

Made some good progress today. Only one file left to convert in source/libs and then four more in the root of the source folder. There's two tests that I broke that I'll fix as well.

After that I'll enable strict mode and see what still breaks. Hopefully not too much at this point ;)

Do you want your webpack config converted to TypeScript as well? All it requires is the ts-node package and webpack will be able to transpile the config before building.

Comment thread source/libs/page-detect.ts Resolved
@fregante

fregante commented Feb 2, 2019

Copy link
Copy Markdown
Member

As for the strict mode, if it requires a lot more changes I’d probably suggest to settle this PR first. Making the repo strict could come in a separate round. What do you think?

Also I found some solutions in the other PR to be slightly more simple, especially where you use the TailArgs here 😬

@fregante

fregante commented Feb 2, 2019

Copy link
Copy Markdown
Member

I think webpack’s config can stay JavaScript

@nickytonline

Copy link
Copy Markdown
Contributor Author

Sounds good for strict coming in another round.

Comment thread source/features/commented-menu-item.tsx Resolved
Comment thread source/libs/utils.ts Resolved
for (const comment of comments) {
const timestampEl = select('relative-time', comment);
const timestamp = timestampEl.attributes.datetime.value;
const timestamp = timestampEl.attributes['datetime'].value; // eslint-disable-line dot-notation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I feel silly for not knowing there was a time element, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tim. Will cast accordingly.

for (const comment of comments) {
const timestampEl = select('relative-time', comment);
const timestamp = timestampEl.attributes.datetime.value;
const timestamp = timestampEl.attributes['datetime'].value; // eslint-disable-line dot-notation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like even when it is cast to HTMLTimeElement, it still complains.

image

It's actually the <relative-time /> web component from github.com/github/time-elements that they're using, so you have no choice but to access it via attributes with the [] notation.

image

@fregante
fregante force-pushed the typescript-migration branch from 02469bb to e4262e6 Compare February 6, 2019 06:32
@fregante

fregante commented Feb 6, 2019

Copy link
Copy Markdown
Member

I don't know either. I tried something and it failed, even if I reset the changes and then rename the files: 5c41a72

@nickytonline

Copy link
Copy Markdown
Contributor Author

Hmm. I have to get some ZZZs, but I'll pick the brains of a few colleagues tomorrow to see if they might know what's up.

@nickytonline

Copy link
Copy Markdown
Contributor Author

Tried again a little differently, but same result. It renames the file properly, I commit it and push and I see it's renamed in the PR, but as soon as the next commit comes in that boom, same thing.

This time I checked out the file at the exact place where rename fiasco happened

git rev-list -n 1 HEAD -- source/libs/icons.js # gives 5ea00a3923adaee0bbd1114a74be21c8ab5c1726
git checkout 5ea00a3923adaee0bbd1114a74be21c8ab5c1726^ -- source/libs/icons.js
# delete source/libs/icons.tsx and commit.
git mv source/libs/icons.js source/libs/icons.tsx
# file is committed and is shown as a rename.

# modify contents of icons.tsx in a new commit and we're back to square one.

ahhh! 😅

@nickytonline

Copy link
Copy Markdown
Contributor Author

@sindresorhus just curious if you have any ideas as to why we're unable to rename the files properly. From all accounts, I'm doing things correctly which is why I'm a little perplexed.

@fregante

fregante commented Feb 7, 2019 •

Copy link
Copy Markdown
Member

I think the solution is to just merge as two commits.

  1. Make this PR include all the changes, except the renames of the three files
  2. After merging the PR, commit the file rename directly on master.

This way GitHub won't try to squash/merge the two commits incorrectly.


So let's review this the final time and then:

  1. I'll undo the renames
  2. Merge the PR
  3. Commit the renames

@nickytonline

Copy link
Copy Markdown
Contributor Author

OK, sounds good. Thanks for all the help.

The only thing that is missing is we need the latest webext-options-sync as well in here. It works right now, but it'd be good to get that in as well. What do you think?

@nickytonline

nickytonline commented Feb 7, 2019 •

Copy link
Copy Markdown
Contributor Author

It needs the updated package-lock.json. I can push that if you want.

@JesseKPhillips

Copy link
Copy Markdown

Git does not have a rename, make a commit without file modification but includes both the add and delete on the file. Git will use horistics to determine the files are the same.

@nickytonline

Copy link
Copy Markdown
Contributor Author

@fregante

fregante commented Feb 7, 2019

Copy link
Copy Markdown
Member

I read that before that “git does not have renames” but it’s kinda wrong considering that a rename can be --followed by git log and rm+add can’t. Right? There’s a difference between the two operations, even if ”technically” git just uses rm+add

@JesseKPhillips

Copy link
Copy Markdown

Nope no difference, their is no meta data to indicate a rename. As you said, git mv just uses add+remove. I recently had a collegue hit the opposite problem, he had added a new file, copied content from another and deleted the old. Git saw it as a rename but he didn't expect that because that wasn't the operation done.

@fregante
fregante merged commit 9f9d178 into refined-github:master Feb 8, 2019
@fregante

fregante commented Feb 8, 2019 •

Copy link
Copy Markdown
Member

9f9d178 merged with file changes
c11d1f7 committed with the renames

Now use something like Follow for Github or git log --follow and you'll see this:

screenshot 2019-02-08 at 22 57 14

It turns out you git does have the concept of renames, you just have to keep the changes and the renames in separate commits.

@fregante

fregante commented Feb 8, 2019

Copy link
Copy Markdown
Member

Thanks @nickytonline for the hard work! 🎈

all typescript

I merged this to allow other PRs to start following the new rules. Further adjustments can be made in a separate PR.

And just like that... 1000 commits! 🎂

1000 commits

@JesseKPhillips

Copy link
Copy Markdown

Git does have a concept of rename with file modifications, it is just harder which is why I specified to have them separate, and when I looked at the history they were.

https://www.quora.com/What-is-the-heuristic-of-Git-for-managing-renamed-files

@nickytonline
nickytonline deleted the typescript-migration branch February 8, 2019 15:49
@trddddd

trddddd commented Oct 2, 2019

Copy link
Copy Markdown

you can rewrite history where this file was mentioned

  1. git filter-branch -f --tree-filter 'if [ -f old_file ]; then mkdir -p new_dir && mv old_file new_file; fi'
  2. mv old_file new_file
  3. gaa && gcmsg 'perfect'

https://gist.github.com/trddddd/69f1f134499b4e1aaf84166911a2830c

@raineorshine

Copy link
Copy Markdown
Contributor

For those wanting to understand better why git intentionally does not track renames:

https://git.wiki.kernel.org/index.php/GitFaq#Why_does_Git_not_.22track.22_renames.3F

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

8 participants