Skip to content

Commit

Permalink
fix type acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Oct 5, 2023
1 parent adc12ff commit d20ac0c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mdxts/components/client/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (isClient) {
fetch('/_next/static/mdxts/types.json').then(async (response) => {
const typeDeclarations = await response.json()

typeDeclarations.forEach(({ code, path }) => {
typeDeclarations.forEach(({ path, code }) => {
project.createSourceFile(path, code)
})
})
Expand Down
12 changes: 6 additions & 6 deletions mdxts/utils/get-type-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function fetchTypes(
resolve(
types.map(({ code, path }) => ({
code,
path: `file://${path.replace('@types/', '')}`,
path: path.replace('@types/', ''),
}))
)
},
Expand Down Expand Up @@ -60,16 +60,16 @@ function getAllDependencies(packageJson) {

async function findTypesPathFromTypeVersions(
packageJson,
parentPackage,
submodule
packageName,
packageExport
) {
if (!packageJson.typesVersions) return null

const typeVersionsField = packageJson.typesVersions['*']

if (!typeVersionsField) return null

const typesPathsFromTypeVersions = typeVersionsField[submodule]
const typesPathsFromTypeVersions = typeVersionsField[packageExport]

if (!typesPathsFromTypeVersions) return null

Expand All @@ -78,7 +78,7 @@ async function findTypesPathFromTypeVersions(
const typesPath = path.resolve(
process.cwd(),
'node_modules',
parentPackage,
packageName,
candidatePath
)

Expand Down Expand Up @@ -180,7 +180,7 @@ export async function getTypeDeclarations(packageName) {
return [
{
code: result.output[0].code,
path: `file:///node_modules/${packageName}/index.d.ts`,
path: `/node_modules/${packageName}/index.d.ts`,
},
]
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions site/docs/06.test.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
```tsx live
import { Navigation } from 'mdxts/components'

/**
* Say hello.
*
Expand Down
3 changes: 1 addition & 2 deletions site/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { createMDXTSPlugin } from 'mdxts/next'
const withMDXTS = createMDXTSPlugin({
theme: 'theme.json',
gitSource: 'https://github.com/souporserious/mdxts/tree/main',
types: ['react'],
types: ['react', 'mdxts/components'],
})

export default withMDXTS({
transpilePackages: ['mdxts'],
compiler: {
styledComponents: true,
},
Expand Down

1 comment on commit d20ac0c

@vercel
Copy link

@vercel vercel bot commented on d20ac0c Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.