Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stash: mdx-bundler fork #2120

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/fern-docs/mdx-bundler/.depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ignores": ["@fern-platform/configs", "@types/node", "vite", "@types/react"],
"ignore-patterns": ["dist"]
}
1 change: 1 addition & 0 deletions packages/fern-docs/mdx-bundler/.stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": ["../../../shared/stylelintrc.shared.json"] }
58 changes: 58 additions & 0 deletions packages/fern-docs/mdx-bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@fern-docs/auth",
"version": "0.0.0",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern-platform.git",
"directory": "packages/fern-docs/auth"
},
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist"
],
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
"depcheck": "depcheck",
"dev": "tsc --watch",
"docs:dev": "pnpm dev",
"format": "prettier --write --ignore-unknown \"**\"",
"format:check": "prettier --check --ignore-unknown \"**\"",
"lint:eslint": "eslint --max-warnings 0 .",
"lint:eslint:fix": "pnpm lint:eslint --fix",
"lint:style": "stylelint 'src/**/*.scss' --allow-empty-input --max-warnings 0",
"lint:style:fix": "pnpm lint:style --fix",
"test": "vitest --run --passWithNoTests --globals"
},
"dependencies": {
"@esbuild-plugins/node-resolve": "^0.2.2",
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
"@mdx-js/esbuild": "^3.1.0",
"esbuild": "0.24.2",
"gray-matter": "^4.0.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"remark-frontmatter": "^5.0.0",
"remark-mdx-frontmatter": "^5.0.0",
"uuid": "^9.0.0",
"vfile": "^6.0.3"
},
"devDependencies": {
"@fern-platform/configs": "workspace:*",
"@types/node": "^18.7.18",
"depcheck": "^1.4.7",
"eslint": "^9",
"prettier": "^3.4.2",
"stylelint": "^16.1.0",
"typescript": "^5",
"vitest": "^2.1.4"
}
}
35 changes: 35 additions & 0 deletions packages/fern-docs/mdx-bundler/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import * as _jsx_runtime from "react/jsx-runtime";

/**
* @typedef {import('./types').MDXContentProps} MDXContentProps
*/

/**
*
* @param {string} code - The string of code you got from bundleMDX
* @param {Record<string, unknown>} [globals] - Any variables your MDX needs to have accessible when it runs
* @return {React.FunctionComponent<MDXContentProps>}
*/
function getMDXComponent(code, globals) {
const mdxExport = getMDXExport(code, globals);
return mdxExport.default;
}

/**
* @template ExportedObject
* @template Frontmatter
* @type {import('./types').MDXExportFunction<ExportedObject, Frontmatter>}
* @param {string} code - The string of code you got from bundleMDX
* @param {Record<string, unknown>} [globals] - Any variables your MDX needs to have accessible when it runs
*
*/
function getMDXExport(code, globals) {
const scope = { React, ReactDOM, _jsx_runtime, ...globals };
// eslint-disable-next-line
const fn = new Function(...Object.keys(scope), code);
return fn(...Object.values(scope));
}

export { getMDXComponent, getMDXExport };
Loading
Loading