Skip to content

Conversation

@bodinsamuel
Copy link
Contributor

Closes #401
Contributes #372

📦 What's inside ?

  • Use official list of @types, preloaded like jsDelivr
    We should probably just restart the script on heroku once a day, until we code something to handle the cache automatically.
  • Check dependencies and devDependencies to see if package use typescript
    It's a super light check and I'm almost sure all packages that are using typescript must have them listed as deps.
    Example: in the snapshot we solved atomic-package.tab.d.ts that was listed as possible
  • Remove support for "possible: true", it's likely to be triggered by 99% of package whereas the check of dependencies should already cover 99% of package using Typescript (Super arbitrary assumption I may be wrong).
    That also mean we no longer use unpkg for the moment, that will help going faster.

@bodinsamuel bodinsamuel requested a review from Haroenv August 12, 2019 20:09
@bodinsamuel bodinsamuel self-assigned this Aug 12, 2019
@Haroenv
Copy link
Collaborator

Haroenv commented Aug 13, 2019

.d.ts can en added to projects that don’t use typescript themselves. I think “got” is an example for a package like that

@bodinsamuel
Copy link
Contributor Author

.d.ts can en added to projects that don’t use typescript themselves. I think “got” is an example for a package like that

Got is made in typescript (at least now), I will try to find npm package with this pattern, but I'm not sure it's worth slowing down the script that much for the real potential it brings.

@Haroenv
Copy link
Collaborator

Haroenv commented Aug 13, 2019

@bodinsamuel
Copy link
Contributor Author

bodinsamuel commented Aug 13, 2019

I'm not saying your point is bad, but like I said this cover almost every package. I will add a check on the files prop.

@bodinsamuel
Copy link
Contributor Author

@Haroenv I have removed the check for dependencies as it was not as certain as I thought.
With everything I put before, I now check jsDelivr:

  • typescript:
    • if any file match d.ts, it's marked as include
    • if no match, nothing more is done
  • changelogs:
    • if any file match, we no longer do a HEAD call,
    • if no match, rollback to the HEAD call if no match (some packages do not bundle CHANGELOG.md 😠)

I would recommend checking only b4b98ef (without whitespace diff)

Copy link
Collaborator

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I think we're almost ready here

pkgs.map((pkg, index) => {
const fromFS = checkChangelogFromFilesList(pkg, filesLists[index]);
if (fromFS) {
return fromFS;
Copy link
Collaborator

Choose a reason for hiding this comment

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

hope this will have a nice impact! probably not too much since GitHub is fast, but less request is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has less impact than I initially anticipated because some packages does not bundle the changelog (most of them do though, because npm auto add this file), and we always rollback to slower method if not found.

// t = @types/<name>
body.forEach(type => {
type.m.forEach(m => {
typesCache[m] = type.t;
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does this deal with @reach/router -> @types/reach__router?

Copy link
Contributor Author

@bodinsamuel bodinsamuel Aug 19, 2019

Choose a reason for hiding this comment

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

It will work (if you look here it's already correctly name)
Your example made me found out that not all packages has a property m in the json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example mapbox__polyline does not contain the correct package name, reach__router seems to have the same issue. I was expecting to have the correct package name in m but it seems not consistant.
(maybe @sandersn has an idea)
If no solution I will unescape the name probably to transform the __ into a /

Choose a reason for hiding this comment

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

I'm pretty sure that the module name is supposed to be the DT-mangled name, eg mapbox__polyline instead of @mapbox/polyline. Do you see unmangled package names too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example: @mapbox/geojson-area or arangodb appear as-is in the m property.
I'm really not sure what should or should not be mangled

@bodinsamuel
Copy link
Contributor Author

I added an unmangle function to fix this #407 (comment)

}

function unmangle(name) {
return name.replace('__', '/').replace('@', '');
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add a test for this? Shouldn't we add an @ instead of removing it?

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 can not add an @ because the index created by typescript also contain "fake module" like lodash/add (I'm not 100% sure I need to add those in the list)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah that's confusing

@bodinsamuel
Copy link
Contributor Author

@Haroenv Do you feel okay merging this? and #413 ?

@sindresorhus
Copy link

sindresorhus commented Feb 10, 2020

I didn't check whether it's handled, but don't forget to handle the case where a package has a index.d.ts file in root, but not a types field in package.json. That's a common occurrence and it's allowed by TypeScript to omit the types field if the definition file uses the name index.d.ts.

Context: sindresorhus/type-fest#67 (comment)

@Haroenv
Copy link
Collaborator

Haroenv commented Feb 11, 2020

good call @sindresorhus, I think that's not checked for now, if the main field isn't given. With this refactor that would indeed not be fixed

@jimaek
Copy link

jimaek commented May 27, 2021

Hey I was wondering on the status of this. Maybe it's good to get merged? It has some interesting features

@bodinsamuel
Copy link
Contributor Author

@jimaek hey, thanks for pinging.
I have been too ambitious with this PR, I need to take some time to split the changes in a more reviewable/safe way.
It's been 2 years, a bit shameful for me 🙇🏻

I'll try to allocate some times to this in the coming weeks

@bodinsamuel
Copy link
Contributor Author

Everything has been ported 🙇🏻

@bodinsamuel bodinsamuel closed this Jul 6, 2021
@bodinsamuel bodinsamuel deleted the feat/use-typescript-to-check branch July 19, 2021 17:52
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.

Use list of @types instead of doing one query per package

7 participants