Zipper-Inc / zipper-functions

The code for zipper.dev and zipper.run. Write and run typescript functions in your browser without having to write any auth, FE, API code.
https://zipper.dev
MIT License
6 stars 2 forks source link

Parse external types #744

Closed miguel-nascimento closed 9 months ago

miguel-nascimento commented 9 months ago

This PR enable us to import types and use they in the handler function, creating UI using those imported types.

TODO: merge the base PR 😁 #748 Due to the Issue 1 and a bit of Issue 4, this PR only works with external imports types inside zipper.dev.

How? The parse function now takes a context: the Project from ts-morph With this context, we can navigate around, filling holes with type definition from other files.

This context persist after the parser, we're creating the Project once per project

The major issue is the remote imports, we need them in our context too. We're adding those remote modules when we can't find the module in the local context, then, we check if the import is an external one, if so, we fetch the bundle using the /api/editor/ts/bundle/x?=<specifier> endpoint. [1] [2]

With the remote module in our context, we can proceed to use the compiler to get the definition.

[1] Issue: The import specifier is the raw specifier. The bundle/x endpoint returns specifiers with version, which may be different from the original import specifier, due to the rewrite specifier rules. ❓

[2] Possible issue: We're adding external modules to the Project, but we're not removing the unneeded modules. (not planning to fix it rn)

[3] Issue: External types solving only triggers on the second parse execution, after a keystroke on the editor

[4] Issue: We're not parsing interface A extends B. We can do this later, improving the parse type (concrete, resolved typescript type, and not type node)

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
zipper-run βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jan 31, 2024 5:10pm