FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Stricter type checking · mcjava-wiki/mcjava-wiki@f961deb · GitHub

Commit f961deb

Browse files
authored
Stricter type checking
Signed-off-by: GitHub <noreply@github.com>
1 parent 3509847 commit f961deb

16 files changed

Lines changed: 105 additions & 67 deletions

‎gatsby-config.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import type { GatsbyConfig } from "gatsby";
23

34
const visit = require('unist-util-visit')
45

@@ -13,7 +14,7 @@ function rehypeMetaAsAttributes() {
1314
}
1415
}
1516

16-
module.exports = {
17+
const config: GatsbyConfig = {
1718
pathPrefix: `${process.env.PATH_PREFIX}`,
1819
graphqlTypegen: true,
1920
siteMetadata: {
@@ -168,3 +169,5 @@ module.exports = {
168169
},
169170
],
170171
}
172+
173+
export default config;

‎gatsby-node.ts‎

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { CreateNodeArgs } from "gatsby";
2-
1+
import { CreateNodeArgs, GatsbyNode, PageProps } from "gatsby";
32
import fs from 'fs';
43
import path from 'path';
54
import { createFilePath } from 'gatsby-source-filesystem';
65
const { getSiteUrl } = require('./src/theme-options.ts')
76
import { tlds, sites, routes } from './src/util/constants';
8-
const config = require('./gatsby-config.ts')
9-
import cheerio from 'cheerio';
7+
import { load } from 'cheerio';
8+
9+
import config from './gatsby-config';
1010

11-
function createSchemaCustomization({ actions }) {
11+
export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] = ({ actions }) => {
1212
const { createTypes } = actions
1313
const typeDefs = `
1414
type NavItem {
@@ -52,7 +52,7 @@ function createDirectoryIfNotExists({ reporter }, pathname) {
5252
}
5353
}
5454

55-
async function onPreBootstrap(options) {
55+
export const onPreBootstrap: GatsbyNode["onPreBootstrap"] = async (options) => {
5656
// Create all required directories
5757
createDirectoryIfNotExists(options, 'pages')
5858
createDirectoryIfNotExists(options, 'pages/docs')
@@ -77,18 +77,20 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
7777
url.pathname = slug
7878

7979
function getGithubLink(tld: string, route: string) {
80+
const siteMetadata = config.siteMetadata;
81+
if (!siteMetadata) return '';
8082
const {
8183
baseDirectory = path.resolve(__dirname, './'),
82-
githubRepositoryURL = `https://${sites.GITHUB}.${tld}/${config.siteMetadata.githubRepository}`,
83-
githubDefaultBranch = config.siteMetadata.githubDefaultBranch,
84+
githubRepositoryURL = `https://${sites.GITHUB}.${tld}/${siteMetadata.githubRepository}`,
85+
githubDefaultBranch = siteMetadata.githubDefaultBranch,
8486
} = options
85-
const repositoryURL = githubRepositoryURL
86-
if (!baseDirectory || !repositoryURL) return ''
87+
const repositoryURL = githubRepositoryURL;
88+
if (!baseDirectory || !repositoryURL) return '';
8789
const relativePath = node.internal.contentFilePath.replace(
8890
baseDirectory,
8991
'',
9092
)
91-
return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}`
93+
return `${repositoryURL}${route}${githubDefaultBranch}${relativePath}`;
9294
}
9395

9496
const getData = async (url: URL | RequestInfo) => {
@@ -103,7 +105,7 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
103105

104106
const getContributors = async () => {
105107
const contributorsHtml = await getData(getGithubLink(tlds.COM, routes.CONTRIBUTORS_LIST));
106-
const $ = cheerio.load(contributorsHtml);
108+
const $ = load(contributorsHtml);
107109

108110
const contributors: Contributor[] = [];
109111
$(".avatar").each((_i: any, element: any) => {
@@ -198,21 +200,25 @@ async function onCreateMdxNode({ node, getNode, actions }, options) {
198200

199201
}
200202

201-
async function onCreateNode(...args: [CreateNodeArgs]) {
203+
export const onCreateNode: GatsbyNode["onCreateNode"] = async (...args: [CreateNodeArgs]) => {
202204
if (args[0].node.internal.type === 'Mdx') {
203205
await onCreateMdxNode(...args, {})
204206
}
205207
}
206208

207-
async function createPages({ graphql, actions, reporter }) {
208-
const { createPage, createRedirect } = actions
209+
export const createPages: GatsbyNode["createPages"] = async ({ graphql, actions, reporter }) => {
210+
const { createPage, createRedirect } = actions;
209211

210-
const { data, errors } = await graphql(`
212+
const allMdx: {
213+
errors?: any;
214+
data?: Queries.CreatePagesQuery;
215+
} = await graphql(`
211216
query CreatePages {
212217
allMdx {
213218
edges {
214219
node {
215220
id
221+
frontmatter
216222
fields {
217223
slug
218224
pageType
@@ -232,14 +238,20 @@ async function createPages({ graphql, actions, reporter }) {
232238
}
233239
`)
234240

235-
if (errors) {
241+
if (allMdx.errors) {
236242
reporter.panicOnBuild(`Error while running GraphQL query.`)
237-
console.log(errors)
243+
console.log(allMdx.errors)
238244
return
239245
}
240246

241-
const filteredEdges = data.allMdx.edges.filter((edge: { node: { parent: { sourceInstanceName: string; }; fields: { slug: any; }; }; }) => {
242-
if (edge.node.parent.sourceInstanceName === 'default-page') {
247+
const data = allMdx.data;
248+
if (!data) return;
249+
250+
const filteredEdges = data.allMdx.edges.filter((edge: Queries.CreatePagesQuery["allMdx"]["edges"][0]) => {
251+
const parent = edge.node.parent;
252+
if (!parent) return true;
253+
if (typeof parent === "object" && "sourceInstanceName" in parent && parent.sourceInstanceName === 'default-page') {
254+
if (!edge.node.fields) return true;
243255
const { slug } = edge.node.fields
244256
const hasCustom404 = data.allMdx.edges.find(
245257
(_edge: { node: any; }) => edge !== _edge && _edge.node.fields.slug === slug,
@@ -251,6 +263,7 @@ async function createPages({ graphql, actions, reporter }) {
251263

252264
// Create pages
253265
filteredEdges.forEach(({ node }) => {
266+
if (!node.fields || !node.fields.slug) return;
254267
if (node.fields.redirect) {
255268
createRedirect({
256269
fromPath: node.fields.slug,
@@ -275,7 +288,7 @@ async function createPages({ graphql, actions, reporter }) {
275288
})
276289
}
277290

278-
const pluginOptionsSchema = (/** @type {{ Joi: import('joi') }} */ { Joi }) => {
291+
export const pluginOptionsSchema: GatsbyNode["pluginOptionsSchema"] = (/** @type {{ Joi: import('joi') }} */ { Joi }) => {
279292
return Joi.object({
280293
// Validate that the anonymize option is defined by the user and is a boolean
281294
name: Joi.string().required(),

‎src/components/AppHeader.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function useLogo(logos) {
9696
}
9797

9898
export function AppHeader() {
99-
const data = useStaticQuery(AppHeaderQuery)
99+
const data: Queries.AppHeaderQuery = useStaticQuery(AppHeaderQuery)
100100
const logo = useLogo(data.logos.nodes)
101101

102102
return (
@@ -121,7 +121,7 @@ export function AppHeader() {
121121
px={2}
122122
height={32}
123123
src={logo.publicURL}
124-
alt={data.site.siteMetadata.title}
124+
alt={data?.site?.siteMetadata?.title}
125125
/>
126126
) : (
127127
<x.h2
@@ -132,12 +132,12 @@ export function AppHeader() {
132132
fontSize={18}
133133
m={0}
134134
>
135-
{data.site.siteMetadata.title}
135+
{data?.site?.siteMetadata?.title}
136136
</x.h2>
137137
)}
138138
</NavLink>
139139
</x.div>
140-
{data.site.siteMetadata.docSearch ? (
140+
{data?.site?.siteMetadata?.docSearch ? (
141141
<x.div col="auto" px={2} display={{ xs: 'none', md: 'block' }}>
142142
<DocSearch {...data.site.siteMetadata.docSearch} />
143143
</x.div>

‎src/components/AppNav.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const AppNavQuery = graphql`
1717
`
1818

1919
export function AppNav() {
20-
const data = useStaticQuery(AppNavQuery)
20+
const data: Queries.AppNavQuery = useStaticQuery(AppNavQuery)
2121
return (
2222
<Nav>
2323
<NavList>
@@ -27,7 +27,7 @@ export function AppNav() {
2727
<NavListItem>
2828
<NavLink
2929
as="a"
30-
href={`https://${sites.GITHUB}.${tlds.COM}/${data.site.siteMetadata.githubRepository}`}
30+
href={`https://${sites.GITHUB}.${tlds.COM}/${data?.site?.siteMetadata?.githubRepository}`}
3131
target="_blank"
3232
rel="noopener noreferrer"
3333
>
@@ -37,7 +37,7 @@ export function AppNav() {
3737
<NavListItem>
3838
<NavLink
3939
as="a"
40-
href={`https://${sites.DISCORD}.${tlds.GG}/${data.site.siteMetadata.discordInviteCode}`}
40+
href={`https://${sites.DISCORD}.${tlds.GG}/${data?.site?.siteMetadata?.discordInviteCode}`}
4141
target="_blank"
4242
rel="noopener noreferrer"
4343
>

‎src/components/Button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface ButtonProps {
7171
}
7272

7373
export const Button = React.forwardRef(
74-
({ variant = 'primary', children, ...props }: ButtonProps, ref: any) => {
74+
({ variant = 'primary', children, ...props }: ButtonProps, ref: React.Ref<HTMLButtonElement>) => {
7575
return (
7676
<AriakitButton ref={ref} data-variant={variant}>
7777
{(buttonProps) => (

‎src/components/ColorModeSwitcher.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function getInverseMode(mode: 'light' | 'dark') {
1111
return mode === 'light' ? 'dark' : 'light'
1212
}
1313

14-
export const ColorModeSwitcher = React.forwardRef((props, ref: any) => {
14+
export const ColorModeSwitcher = React.forwardRef((props, ref: React.Ref<HTMLButtonElement>) => {
1515
const [mode, setMode] = useColorMode() as ['light' | 'dark', (mode: 'light' | 'dark') => void]
1616
const Icon = modeIcons[mode]
1717
return (

‎src/components/DocLayout.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,19 @@ const DocSearchQuery = graphql`
145145

146146
function MobileSidebar({ children }) {
147147
const dialog = useDialogState({ animated: true })
148-
const data = useStaticQuery(DocSearchQuery)
148+
const data: Queries.DocSearchQuery = useStaticQuery(DocSearchQuery)
149+
if (!data.site || !data.site.siteMetadata) return null;
150+
const docSearch = data.site.siteMetadata.docSearch;
151+
if (!docSearch) return null;
149152
return (
150153
<>
151154
<Dialog state={dialog} as={SidebarDialog}>
152155
<div style={{paddingLeft: 20, paddingTop: 20}}>
153-
<DocSearch {...data.site.siteMetadata.docSearch} />
156+
<DocSearch
157+
apiKey={docSearch.apiKey}
158+
indexName={docSearch.indexName}
159+
appId={docSearch.appId}
160+
/>
154161
</div>
155162
{children}
156163
</Dialog>
@@ -198,7 +205,7 @@ function PrevNextLinks({ editLink, ...props }: { navGroups: any; } & { [x: strin
198205

199206
export function DocLayout({ children, tableOfContents, editLink, contributors, ...props }) {
200207
const upMd = useUp('md')
201-
const sideNav = useSideNavState()
208+
const sideNav: any = useSideNavState()
202209
return (
203210
<PageLayout title={undefined} {...props}>
204211
<ScreenContainer px={0}>

‎src/components/Feature.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const InnerFeature = styled.box`
1111
padding-right: 5 !important;
1212
`
1313

14-
export const Feature = React.forwardRef((props, ref: any) => (
14+
export const Feature = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => (
1515
<InnerFeature
1616
ref={ref}
1717
col={{ xs: 1, md: 1 / 4 }}
@@ -43,15 +43,15 @@ const InnerFeatureImage = styled.img`
4343
margin-top: 3;
4444
`
4545

46-
export const FeatureImage = React.forwardRef((props, ref: any) => (
46+
export const FeatureImage = React.forwardRef((props, ref: React.Ref<HTMLImageElement>) => (
4747
<InnerFeatureImage ref={ref} width={48} height={48} {...props} />
4848
))
4949

50-
export const FeatureList = React.forwardRef((props, ref: any) => (
50+
export const FeatureList = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => (
5151
<ScreenContainer ref={ref} row my={-4} px={3} {...props} />
5252
))
5353

54-
export const FeatureSection = React.forwardRef((props, ref: any) => (
54+
export const FeatureSection = React.forwardRef((props, ref: React.Ref<HTMLElement>) => (
5555
<x.section
5656
ref={ref}
5757
py={4}

‎src/components/Head.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { graphql, useStaticQuery } from 'gatsby'
2+
import { graphql, useStaticQuery } from 'gatsby'
33
import { Seo } from './Seo'
44

55
const HeadQuery = graphql`
@@ -13,13 +13,13 @@ const HeadQuery = graphql`
1313
`
1414

1515
export function Head({ title }) {
16-
const data = useStaticQuery(HeadQuery)
16+
const data: Queries.HeadQueryQuery = useStaticQuery(HeadQuery)
1717
return (
1818
<Seo
1919
title={
2020
title
21-
? `${title} - ${data.site.siteMetadata.title}`
22-
: data.site.siteMetadata.title
21+
? `${title} - ${data?.site?.siteMetadata?.title}`
22+
: data?.site?.siteMetadata?.title
2323
}
2424
/>
2525
)

‎src/components/Hero.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const InnerHero = styled(ScreenContainer)`
7272
`
7373

7474
export const Hero = React.forwardRef(
75-
({ backgroundImageURL, ...props }: { backgroundImageURL?: string }, ref: any) => {
75+
({ backgroundImageURL, ...props }: { backgroundImageURL?: string }, ref: React.Ref<HTMLDivElement>) => {
7676
if (typeof backgroundImageURL === 'undefined') {
7777
return <InnerHero ref={ref} {...props} />
7878
}
@@ -87,7 +87,7 @@ export const Hero = React.forwardRef(
8787
},
8888
)
8989

90-
export const HeroBody = React.forwardRef((props, ref: any) => {
90+
export const HeroBody = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => {
9191
return <x.div ref={ref} w={{ md: 0.5 }} {...props} />
9292
})
9393

@@ -97,7 +97,7 @@ export const HeroSection = styled.sectionBox`
9797
padding-bottom: 5;
9898
`
9999

100-
export const HeroActionList = React.forwardRef((props, ref: any) => {
100+
export const HeroActionList = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => {
101101
return (
102102
<x.div
103103
ref={ref}
@@ -109,6 +109,6 @@ export const HeroActionList = React.forwardRef((props, ref: any) => {
109109
)
110110
})
111111

112-
export const HeroAction = React.forwardRef((props, ref: any) => {
112+
export const HeroAction = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => {
113113
return <x.div ref={ref} col="auto" p={2} {...props} />
114114
})

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL