-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Refactor/types #11715
Refactor/types #11715
Conversation
🦋 Changeset detectedLatest commit: da94ba7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a major
changeset. A reviewer will merge this at the next release if approved.
@@ -131,7 +131,7 @@ export function glob(globOptions: GlobOptions): Loader { | |||
if (entryType.getRenderFunction) { | |||
let render = renderFunctionByContentType.get(entryType); | |||
if (!render) { | |||
render = await entryType.getRenderFunction(settings); | |||
render = await entryType.getRenderFunction(settings.config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only runtime change I did, the way it was setup, it was exposing AstroSettings
publicly, which isn't in line with what we typically do
@@ -0,0 +1,202 @@ | |||
// TODO: Should the types here really be public? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of things in this file feel like they shouldn't be public, but end up being for various reasons. The most concerning of which was RouteData, which is exposed on integrations hooks.
A lot of the SSR*** ones are also spooky, but they're used by renderers which is not too bad
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
declare namespace App { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface Locals {} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary, the default definition is already that. However, it was done in a .d.ts
file, which don't get sent to dist
so it never worked.
@@ -191,7 +185,6 @@ declare module '*.md' { | |||
file, | |||
url, | |||
getHeadings, | |||
getHeaders, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That method hasn't existed in a while.
jsxImportSource: 'astro', | ||
jsxTransformOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those options don't seem to exist anymore? There was a deprecated message on both of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm planning to remove the entire JSX handling here in a separate PR once I refactor the MDX intgeration stuff. Removing it here now is fine though.
|
||
/** Renders an endpoint request to completion, returning the body. */ | ||
export async function renderEndpoint( | ||
mod: EndpointHandler, | ||
mod: { | ||
[method: string]: APIRoute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type was fully internal to this line, figured there was no point to it being a separate type.
@@ -198,10 +197,6 @@ export async function runHookConfigSetup({ | |||
addWatchFile: (path) => { | |||
updatedSettings.watchFiles.push(path instanceof URL ? fileURLToPath(path) : path); | |||
}, | |||
addDevOverlayPlugin: (entrypoint) => { | |||
// TODO add a deprecation warning in Astro 5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO here is wrong, this API was unsupported and undocumented before the toolbar actually became stable, Astro 5 is prime time for fully removing it (the only app that uses it, Sentry, only uses it as a fallback)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope you used some sort of refactoring tool that made this journey less painful 😅 But anyways I stepped through each of them and it looks fine to me.
- Should we also update
Line 292 in 5e928f5
- `@types/`: TypeScript types. These are centralized to cut down on circular dependencies - In what case would we use the ts files in
types/*.ts
(not the public folder)? Should we place private shared types intypes/astro.ts
, or should we lean towards putting types inside each domains' file/folder instead? (for example, there's a lot oftypes.ts
file.
Yea, should definitely update that! I'm not sure! I think that it's fine for some very specific types that are used everywhere perhaps, but overall it seems like over time we've done more and more random |
I like to group them by domain, so the |
I'll add some documentation all around |
Changes
Back in 1997, when Astro was just getting started, someone created an innocent
@types/astro.ts
file, mostly intended for small types used throughout the codebase and types for untyped modules. With time, this file grew with a mix of internal, public, types from dependencies, unused types etc, to a total of 3000 lines of types.This PR attempt to untangle that file, only keeping public what should actually be public and going away from the easily confused with DefinitelyTyped's stuff
@types
to a normal folder called..types
. I also took this opportunity to split the types into multiple files, just so we don't have to scroll 3000 lines of types to find something. No big thoughts went into the splits, just put things where it seemed they'd belong.Throughout this journey, I discovered that more types than I thought were exposed as part of the public API, perhaps as a mistake.
Testing
It builds! We don't have a lot of tests regarding types, but the little we do have do pass too. Smoke tests will fail because of docs docgen script, which need to get adapted to this new structure.
Docs
withastro/docs#9109