-
Notifications
You must be signed in to change notification settings - Fork 71
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
Is protobuf-es compatible with Deno? #293
Comments
Hey Taras, we are all very excited about Deno. Generally, our runtime should work fine with Deno because we only use a few standard APIs. But currently, there are a couple of complications:
As a concrete example, we generate this: import {Message} from "@bufbuild/protobuf";
import {Foo} from "./foo.js"; As far as I'm aware, points 1 and 2 can be worked around by the user with an import map, but point 3 is a bit more tricky. We do have some ideas to tackle it in a generic way, but we'd love to get some feedback from actual Deno users. Let's say we would generate the following: import {Message} from "https://cdn.skypack.dev/@bufbuild/protobuf";
import {Foo} from "./foo.ts"; Would that be sufficient to run in Deno? I'd be also very curious how you run a plugin with Deno. Would you need an equivalent to this script specific to Deno, or are there ways to invoke an npm package "bin"? |
Sweet!
@cowboyd how do you think this should work based on what we've been doing with Deno and lessons learned from GraphQL? |
@timostamm On point (3), it might be a non-issue? That's because importing plain JavaScript sources in Deno "just works." In fact, the entire reason Deno requires the file extension is so that it know whether to invoke the TypeScript compiler or not. As you said, (1) and (2) can be worked around using import maps, but most Our approach is to write the source code in Deno itself because its such a great developer experience (it is very similar to go-lang) and then build the Npm package as a downstream artifact. |
@cowboyd, I think I never tried it with generated Yup, it works fine, just with an import map. I can make a request to our demo service with a connect-web client. Will this still properly lint (including typical IDE setups)? Do you think there are any other problematic areas? |
This seems to be working well for me. I've hacked together a Deno task here that:
The result gives code that I'm able to use directly in Deno. 🎉 (And later I'm going to see if this allows me to also use dnt to also publish this client as an npm package.) Minor feature requests along the way:
Instead of itemType: {
value: Post;
case: "post";
} | {
value: Profile;
case: "profile";
} | {
value: Comment;
case: "comment";
} | { case: undefined; value?: undefined } = { case: undefined }; Wouldn't you still get the same type safety with this? itemType: {
post: Post;
} | {
profile: Profile;
} | {
comment: Comment;
} | {} = {}; |
Ah yes, one more oddity to point out: Here, I discovered that the code tries to access an environment variable named |
Crossing my fingers, would be awesome if this works! |
No. type exampleOneof = {
foo: string;
} | {
bar: number;
} | {
baz: boolean;
} | {};
declare var example: exampleOneof;
// Can set excess properties
example = { excess: 'property' }; // no error
// Can set INCORRECT values 😱
example = { foo: 1 }; // no error
// Can set MULTIPLE fields 😱
example = { foo: 'both are set', bar: 1 }; // no error
// Can't check which is set using property access
if (example.foo) {}
// ^ Property 'foo' does not exist on type 'exampleOneof'.
// Property 'foo' does not exist on type '{}'.(2339)
if (typeof example.foo !== 'undefined') {}
// ^ Property 'foo' does not exist on type 'exampleOneof'.
// Property 'foo' does not exist on type '{}'.(2339)
// Using `hasOwnProperty()` doesn't refine
if (example.hasOwnProperty('foo')) { example.foo }
// ^ Property 'foo' does not exist on type 'exampleOneof'.
// Property 'foo' does not exist on type '{}'.(2339) |
For those interested, I got this working "in Deno", here: The "in Deno" is in quotes because I'm currently temporarily using npm to install protobuf-es into a local directory, then use that with @jcready -- thanks for the example. I forgot how lax |
Adding here for posterity also. When Deno support is added, we should support allowing See #483 for the original issue requesting this. |
Deno v2 supports importing from npm packages with the "npm:" specifier. We're updating the plugin option Deno expects the extension |
I came across protobuf-es announcement and it looks great. The analysis was excellent as well. Since you have native ES support, have you tried it Deno? Thank you, keep up the great work.
The text was updated successfully, but these errors were encountered: