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 4862b9f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
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 4862b9f

Please sign in to comment.