Skip to content

Commit

Permalink
refactor: align vike-{react,vue,solid}
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 19, 2024
1 parent a244e11 commit 5dfd0fc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/vike-react-apollo/renderer/+config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from 'vike/types'
import type _ from 'vike-react/config' // Needed for declaration merging of Config
import 'vike-react/config' // Needed for declaration merging of Config
import type { ApolloClient } from '@apollo/client-react-streaming'

export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-react-query/renderer/+config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { QueryClientConfig } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import type { Config, ImportString } from 'vike/types'
import type _ from 'vike-react/config' // Needed for declaration merging of Config
import 'vike-react/config' // Needed for declaration merging of Config

export default {
name: 'vike-react-query',
Expand Down
13 changes: 8 additions & 5 deletions packages/vike-react/src/+config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export { config }

import type { Config } from 'vike/types'
import { isNotFalse } from './utils/isNotFalse.js'
import { ssrEffect } from './renderer/ssrEffect.js'
import { isNotFalse } from './utils/isNotFalse.js'

// This is required to make TypeScript load the global interfaces such as Vike.PageContext so that they're always loaded: we can assume that the user always imports this file over `import vikeReact from 'vike-react/config'`
import './types/index.js'

export default {
const config = {
name: 'vike-react',
require: {
vike: '>=0.4.182'
Expand Down Expand Up @@ -97,3 +96,7 @@ export default {
}
}
} satisfies Config

// This is required to make TypeScript load the global interfaces Vike.Config and Vike.PageContext so that they're always loaded: we can assume that the user always imports this file over `import vikeReact from 'vike-react/config'`
import './types/Config.js'
import './types/PageContext.js'
2 changes: 1 addition & 1 deletion packages/vike-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
console.warn(
"[vike-react][warning][deprecation] Replace `import vikeReact from 'vike-react'` with `import vikeReact from 'vike-react/config'` (typically in your /pages/+config.js)"
)
export { default } from './+config.js'
export { config as default } from './+config.js'
17 changes: 7 additions & 10 deletions packages/vike-react/src/types/Config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// https://vike.dev/meta#typescript
import type {
ImportString,
PageContextClient,
// Rename it to `PageContext_` to be able to reference it from within `namespace Vike`
// - https://stackoverflow.com/questions/46559021/typescript-use-of-global-type-inside-namespace-with-same-type
// - https://github.com/Microsoft/TypeScript/issues/983
PageContext as PageContext_,
PageContextServer
} from 'vike/types'
import type { ImportString, PageContextServer, PageContext, PageContextClient } from 'vike/types'
import type { TagAttributes } from '../utils/getTagAttributesString.js'
import type { Viewport } from '../renderer/onRenderHtml.js'
import type { ConfigsCumulative } from '../hooks/useConfig/configsCumulative.js'

// https://vike.dev/meta#typescript
declare global {
namespace Vike {
interface Config {
Expand Down Expand Up @@ -211,6 +203,11 @@ declare global {
}
}

// Be able to reference it from within `namespace Vike`
// - https://stackoverflow.com/questions/46559021/typescript-use-of-global-type-inside-namespace-with-same-type
// - https://github.com/Microsoft/TypeScript/issues/983
type PageContext_ = PageContext

export type Head = React.ReactNode | (() => React.ReactNode)
type Wrapper = (props: { children: React.ReactNode }) => React.ReactNode
type Layout = Wrapper
Expand Down
2 changes: 0 additions & 2 deletions packages/vike-react/src/types/index.ts

This file was deleted.

0 comments on commit 5dfd0fc

Please sign in to comment.