Skip to content

Commit dcc6e91

Browse files
authored
Merge pull request #249 from code-hike/typescript-module-resolution
Fix typescript module resolution
2 parents 6584ea2 + 1f1c8a2 commit dcc6e91

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ yarn-error.log
1111
storybook-static
1212
packages/playground/out
1313
packages/starter
14+
packages/mdx/components.d.ts
1415

1516
# Contentlayer
1617
.contentlayer

packages/mdx/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
"name": "@code-hike/mdx",
33
"version": "0.7.2",
44
"files": [
5-
"dist"
5+
"dist",
6+
"components.d.ts"
67
],
78
"main": "./dist/index.cjs.js",
89
"module": "./dist/index.esm.mjs",
910
"types": "./dist/index.d.ts",
1011
"exports": {
1112
".": {
13+
"types": "./dist/index.d.ts",
1214
"import": "./dist/index.esm.mjs",
1315
"require": "./dist/index.cjs.js",
1416
"style": "./dist/index.css"
1517
},
1618
"./components": {
19+
"types": "./dist/components.d.ts",
1720
"import": "./dist/components.esm.mjs",
1821
"require": "./dist/components.cjs.js",
1922
"default": "./dist/components.cjs.js"
@@ -23,6 +26,7 @@
2326
"./styles.css": "./dist/index.css",
2427
"./dist/index.css": "./dist/index.css",
2528
"./dist/components.cjs.js": {
29+
"types": "./dist/components.d.ts",
2630
"import": "./dist/components.esm.mjs",
2731
"require": "./dist/components.cjs.js",
2832
"default": "./dist/components.cjs.js"

packages/mdx/rollup.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export default function makeConfig(commandOptions) {
136136
input: `src/components.tsx`,
137137
output: [
138138
{ file: `./dist/components.d.ts`, format: "es" },
139+
// because of typescript not following package.json exports sometimes
140+
{ file: `./components.d.ts`, format: "es" },
139141
],
140142
external: clientExternal,
141143
plugins: [dts()],

packages/mdx/src/components.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "./mdx-client/annotations"
1515
import { Preview } from "./mdx-client/preview"
1616
import { InlineCode } from "./mdx-client/inline-code"
17+
import type { MDXComponents } from "mdx/types"
1718

1819
export {
1920
Code,
@@ -31,7 +32,7 @@ export {
3132
PreviewSlot,
3233
}
3334

34-
export const CH = {
35+
export const CH: MDXComponents = {
3536
Code,
3637
Section,
3738
SectionLink,

packages/mdx/src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { transform as remarkCodeHike } from "./remark/transform"
1+
export { attacher as remarkCodeHike } from "./remark/transform"
22

33
export { highlight } from "./highlighter"

packages/mdx/src/mdx-client/annotations.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { CodeAnnotation } from "../smooth-code"
33
import { getColor, transparent, ColorName } from "../utils"
44

55
export function Annotation() {
6-
return "error: code hike remark plugin not running or annotation isn't at the right place"
6+
return (
7+
<div>
8+
"error: code hike remark plugin not running or
9+
annotation isn't at the right place"
10+
</div>
11+
)
712
}
813

914
export const annotationsMap: Record<

packages/mdx/src/remark/transform.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { valueToEstree } from "./to-estree"
1010
import { CH_CODE_CONFIG_VAR_NAME } from "./unist-utils"
1111
import { JsxNode, SuperNode, visit } from "./nodes"
1212
import { addConfigDefaults, CodeHikeConfig } from "./config"
13+
import { Attacher } from "unified"
1314

1415
const transforms = [
1516
transformPreviews,
@@ -20,7 +21,9 @@ const transforms = [
2021
transformInlineCodes,
2122
transformCodes,
2223
]
23-
export function transform(unsafeConfig: CodeHikeConfig) {
24+
export const attacher: Attacher<
25+
[CodeHikeConfig?]
26+
> = unsafeConfig => {
2427
return async (tree: SuperNode, file: any) => {
2528
const config = addConfigDefaults(
2629
unsafeConfig,

0 commit comments

Comments
 (0)