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

fix: remove long import #7

Merged
merged 1 commit into from Apr 29, 2021
Merged

Conversation

andreialecu
Copy link

@andreialecu andreialecu commented Jan 28, 2021

In the base repo the PR that added this was eventually reverted:
protobufjs#1166

@apollo/protobufjs package is only used by apollo-reporting-protobuf which explicitly forces only numbers to be used, and actually disables Long entirely (via --force-number):

https://github.com/apollographql/apollo-server/blob/fe7df736abdb6bcebf2353902f1b40bee2f9ea5c/packages/apollo-reporting-protobuf/package.json#L10
https://github.com/apollographql/apollo-server/blob/fe7df736abdb6bcebf2353902f1b40bee2f9ea5c/packages/apollo-reporting-protobuf/src/index.js#L4-L8

Without this change, Long is unnecessarily added as an import to the typescript definitions:
https://cdn.jsdelivr.net/npm/apollo-reporting-protobuf@0.6.2/dist/protobuf.d.ts

Note that if you search for long in the file, there are no mentions of it besides the first line/import.

Keeping the import there breaks stricter package managers, such as Yarn 2 in PnP mode:

../../.yarn/cache/apollo-reporting-protobuf-npm-0.6.2-87872b385d-6e00d36475.zip/node_modules/apollo-reporting-protobuf/dist/protobuf.d.ts(1,23): error TS2307: Cannot find module 'long' or its corresponding type declarations.

Requiring to work around it via packageExtensions

Long can be added back in the future to the .d.ts, if ever needed, via a cli argument (-i Long). As per:
https://github.com/apollographql/protobuf.js/blob/master/cli/pbts.js#L176-L179

This PR supersedes #6 which attempts to solve the same problem.

@apollo-cla
Copy link

@andreialecu: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@andreialecu
Copy link
Author

I signed the agreement, not sure if anything else needs to be done on my part.

@kiancross
Copy link

I think #6 is still needed, as the emitted code can still use the Long type:

("(m%s=util.Long.fromValue(%s)).unsigned=%j", prop, ref, isUnsigned)

I think a better solution is to conditionally add the long import to the .d.ts, but that is an issue for the base repo.

@andreialecu
Copy link
Author

@kiancross note that there's a normal dependency on long and its types already:

protobuf.js/package.json

Lines 55 to 56 in 757f6e3

"@types/node": "^10.1.0",
"long": "^4.0.0"

Adding it as a peer on top of that doesn't really do anything.

@andreialecu
Copy link
Author

Also, @apollo/protobuf.js is only used for its CLI to autogenerate the protobuf.js and protobuf.d.ts files, so the dependencies of it aren't really relevant for end users of apollo-reporting-protobuf.

@shadow-identity

This comment has been minimized.

@glasser
Copy link
Member

glasser commented Apr 29, 2021

Thanks! I didn't realize I wasn't watching this fork until now. Taking a look but I think this is basically what I want — I even added a TODO in apollo-server earlier this week to do something like that.

it can be added via a cli arg as `-i Long` instead, if needed
@glasser
Copy link
Member

glasser commented Apr 29, 2021

Force pushing to just have the real change and not some release stuff from master. Thanks!

@glasser glasser merged commit 81365e9 into apollographql:master Apr 29, 2021
glasser added a commit to apollographql/apollo-server that referenced this pull request Apr 29, 2021
See apollographql/protobuf.js#7

A future version could fully remove Long support from our fork but we
aren't quite there yet.
@glasser
Copy link
Member

glasser commented Apr 29, 2021

This doesn't quite work — once you run various build scripts it removes the import from the index.d.ts in this repo which then doesn't build. Gotta change how that file is generated or something.

@glasser
Copy link
Member

glasser commented Apr 29, 2021

OK, I think I got it working; this is out in 2.24.0-alpha.1.

apollographql/apollo-server#5136

@glasser
Copy link
Member

glasser commented Apr 30, 2021

Apollo Server 2.24.0 is out and should include this fix transitively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants