-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Expose adapter init
& render
types for Adapter Authors
#2249
Comments
Would be good to see all Adapter entrypoint types exported as well. For instance In jthegedus/svelte-adapter-firebase#123 I extracted the parsing of Headers into it's own function, and typed the return type as |
I haven't really delved into adapters and its implementation, so your knowledge and other adapter authors are really appreciated here. Rephrasing one of my comment from our previous discussion -- Authors and users shouldn't need to reference anything outside the ones exposed publicly from This hasn't been a problem previously, why now and why does an adapter need access to Again, I don't know much about adapters other than the fact that they have access to This is also a good time to start finalizing, or at least stabilizing the adapter API, so there should be as little breaking changes as possible. I'm thinking a dedicated |
This issue has always existed, it just hasn't been raised because most people reviewing and contributing to the current adapters are the Kit core because most of the adapters live in the Kit monorepo.
All adapters have some line like this in their // TODO hardcoding the relative location makes this brittle
import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved I would like to apply a type to these imports to ensure what I write in my adapter conforms to these APIs. Thus far I have relied upon copying what is in Vercel adapter and external contributors.
I would like to get type errors when updating my Kit dependency when Kit introduces a breaking change. I check most PRs going through Kit, but would like help should I miss something and would say the types would help.
App would be better, yes. However, how do I apply the type to How would I type this usage of const rendered = await render(toSvelteKitRequest(request));
Sounds fine to me, though I would still argue |
I put together a PR for this: #2259 |
Thanks. Just need to figure out a way to get JSDoc to correctly apply the type to import { init, render } from '../output/server/app.js'; Update 1: typing like this works, but is not ideal: // @ts-expect-error
import * as App from '../output/server/app.js';
/** @type {import('@sveltejs/kit/types/internal').App} */
const app = App;
app.init(); Update 2: JSDoc types do not flow through functions, so exposing the export default async function svelteKit(request, response) {
// this call to app.render() should show a type error but does not
const rendered = await app.render(toSvelteKitRequest(request));
...
}
/**
* Return not typed to allow bad type to be returned.
* @param {import('firebase-functions').https.Request} request
*/
export function toSvelteKitRequest(request) {
...
return {
wrong: 'type'
}
} |
I believe that I was able to do it yesterday with something like this:
|
Thanks for the new release 🙏 I know it is off-topic and user machine specific, but I am seeing mixed results with typing this code. Typing on reassignment always works with func completions working and hover tooltips resolving the types properly: // @ts-expect-error
import * as App from '../output/server/app.js';
/** @type {import('@sveltejs/kit/types/internal').App} */
const app = App; Typing the import as you suggest gives me no func autocomplete, typing when applying braces, and then no types on hover after completely written. And finally, de-sctructuring at import just gives me /** @type {import('@sveltejs/kit/types/internal').App} */
import {init, render} from '../output/server/app.js';
// init and render show as "any" Anyway, thanks for exposing these more easily. |
Exporting // @ts-expect-error
import * as App from '../output/server/app.js';
/** @type {import('@sveltejs/kit').App} */
const app = App; I'll try to open a draft for proxying the import app from '@sveltejs/kit/adapter';
// or alternatively
// import { init, render } from '@sveltejs/kit/adapter'; But, there's also a lot to do with the current adapter implementations as well, so reopening to keep track of this for now. |
kit/packages/kit/src/core/build/index.js Line 317 in aaea5cf
Nevermind. That won't work because as an adapter author the app hasn't been built yet |
That might be a good idea, but I'm hoping we could also resolve this TODO while we're at it kit/packages/adapter-node/src/index.js Lines 1 to 2 in aaea5cf
|
I guess this is now related to #625 |
Potentially there'd be some way to do this by refactoring so that instead of the whole app being written at build-time it's already provided like any typical module. Then we could pass in the options and manifest (maybe to |
Interesting take, making it a module might be the way to go for providing the types. But, if we're still keeping some portion dynamically generated, what would be a way to get those generated chunks and pass them to the now modularized imports? We need some way to avoid imports like #2249 (comment) for getting the generated portions |
I filed #2569 to track fixing the relative path, which is the last piece needed. The discussion here was getting a bit long and encompassed a wider variety of stuff, so maybe cleaner to start with a fresh issue for that |
Describe the bug
Updating the Firebase adapter to the changes from #2215 was made easier by typing
render
, however finding the exact types for this was difficult. Once I found the type my refactoring was much easier and I even discovered a bug in my adapter for the Header types.Expose the types.
Not sure if this constitutes a bug or feature request. I went bug because I think this is expected but not the current case.
Reproduction
You can see I have had to reference internal types
@sveltejs/kit/types/internal
to type this function:https://github.com/jthegedus/svelte-adapter-firebase/blob/c9c355eed0b26225ca4c549f7966aa695bccba37/src/files/handler.js#L29
I am not even sure I got the correct type.
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
I believe exposing these types will make adapter development and refactoring more robust.
init
is probably not necessary, though I do not know if it takes params and what they may be, so perhaps for visibility sake.It would be good to just be able to force a type on
The text was updated successfully, but these errors were encountered: