Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
fix: 修复版本及报错问题,后续将整体升级迁移最新vitepress及mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
ihupoo committed Feb 9, 2022
1 parent 8ce57e7 commit e3c49e5
Show file tree
Hide file tree
Showing 17 changed files with 5,242 additions and 40 deletions.
5,196 changes: 5,196 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"devDependencies": {
"@types/es-module-lexer": "^0.3.0",
"@types/fs-extra": "^9.0.8",
"@types/hast": "^2.3.1",
"@types/mdast": "^3.0.3",
"@types/hast": "2.3.1",
"@types/mdast": "3.0.3",
"@types/minimist": "^1.2.1",
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
Expand All @@ -81,36 +81,36 @@
"@mdx-js/mdx": "2.0.0-next.9",
"@mdx-js/react": "2.0.0-next.9",
"@vitejs/plugin-react-refresh": "^1.3.1",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"compression": "^1.7.4",
"copy-text-to-clipboard": "^3.0.1",
"esbuild": "^0.9.6",
"escape-html": "^1.0.3",
"fs-extra": "^9.1.0",
"globby": "^11.0.3",
"chalk": "4.1.0",
"chokidar": "3.5.1",
"compression": "1.7.4",
"copy-text-to-clipboard": "3.0.1",
"esbuild": "0.9.6",
"escape-html": "1.0.3",
"fs-extra": "9.1.0",
"globby": "11.0.3",
"hast-util-is-element": "1.1.0",
"mdast-util-from-markdown": "0.8.5",
"mdast-util-mdx": "0.1.1",
"micromark-extension-mdxjs": "0.3.0",
"minimist": "^1.2.5",
"ora": "^5.4.0",
"polka": "^0.5.2",
"prism-react-renderer": "^1.2.0",
"react-docgen-typescript": "^1.21.0",
"react-simple-code-editor": "^0.11.0",
"minimist": "1.2.5",
"ora": "5.4.0",
"polka": "0.5.2",
"prism-react-renderer": "1.2.0",
"react-docgen-typescript": "2.2.2",
"react-simple-code-editor": "0.11.0",
"remark-emoji": "2.1.0",
"remark-frontmatter": "3.0.0",
"remark-gfm": "1.0.0",
"remark-parse-yaml": "0.0.3",
"remark-slug": "6.0.0",
"sirv": "^1.0.11",
"slash": "^3.0.0",
"styled-components": "^5.2.1",
"typescript": "^4.2.4",
"sirv": "1.0.11",
"slash": "3.0.0",
"styled-components": "5.2.1",
"typescript": "4.2.4",
"unified": "9.2.1",
"unist-util-find": "1.0.2",
"unist-util-visit": "2.0.3",
"vite": "^2.3.0"
"vite": "2.7.13"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function LiveProvider({
scope,
local,
}
const errorCallback = async (err: Error) => {
const errorCallback = async (err: any) => {
setError(err.toString())
if (shadowRoot.current) {
const ReactDom_P = await getReactDom(local)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getReact, getReactDom, getStyleSheetManager } from './render'
import React from 'react'

export type ErrorCallback = (err: Error) => void
export type ErrorCallback = (err: any) => void

interface IErrorBoundary {
Element: React.ReactNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ITransform {
interface TransformReturnType {
result: string
imports: Record<string, any>
error?: Error
error?: any
cssText?: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/app/components/Reactlive/transpile/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ITransform {
interface TransformReturnType {
result: string
imports: Record<string, any>
error?: Error
error?: any
cssText?: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/app/hooks/useRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function useRoute(fallbackComponent?: ComponentType<any>, ssrHref?: strin
}, 200)
}
}
} catch (err) {
} catch (err: any) {
if (!err.message.match(/fetch/)) {
console.error(err)
}
Expand Down
4 changes: 3 additions & 1 deletion src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ if (root) {

if (!command || command === 'dev') {
createServer(root, argv)
.then((server) => server.listen())
.then((server) => {
server.listen()
console.log()
server.printUrls()
})
.catch((err) => {
console.error(chalk.red(`failed to start server. error:\n`), err)
Expand Down
1 change: 1 addition & 0 deletions src/node/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import type { Alias } from 'vite'
import type { UserConfig } from '@vitepress-rc/types'

export const DIST_CLIENT_PATH = path.join(__dirname, '../client')
export const APP_PATH = path.join(__dirname, '../client/app')
export const DEFAULT_THEME_PATH = path.join(__dirname, '../client/theme-default')

Expand Down
7 changes: 6 additions & 1 deletion src/node/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import reactRefresh from '@vitejs/plugin-react-refresh'
import { mdxTransform } from './transform'
import { APP_PATH, SPECIAL_IMPORT_CODE_SCOPE, SPECIAL_IMPORT_SITE_DATA } from './paths'
import { APP_PATH, DIST_CLIENT_PATH, SPECIAL_IMPORT_CODE_SCOPE, SPECIAL_IMPORT_SITE_DATA } from './paths'
import { resolveSiteData } from './config'
import slash from 'slash'
import { cacher } from './transform/utils/cache'
Expand Down Expand Up @@ -30,6 +30,11 @@ export function createVitePlugin(
resolve: {
alias,
},
server: {
fs: {
allow: [DIST_CLIENT_PATH, root, process.cwd()],
},
},
}
},
resolveId(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/transform/plugins/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function plugin({ id, alias, docgen: docgenOptions }: PluginProps
return (tree, vfile) => {
let filePaths: string[] = []

visit(tree, 'mdxJsxFlowElement', function visitor(node, i, parent) {
visit(tree, 'mdxJsxFlowElement', function visitor(node: any, i, parent) {
if (node.name === 'API') {
if (node.attributes) {
let attributes = node.attributes as Attributes[]
Expand Down
6 changes: 2 additions & 4 deletions src/node/transform/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import visit from 'unist-util-visit'
import type { IPluginTransformer } from '../index'
import type { Node } from 'unist'

type NodeWithChildren = Node & { children: NodeWithChildren[] }

type TYPE = 'tip' | 'warning' | 'danger'

// const reg = /^\s*:::\s*(\w+)(.*?)[\n\r]([\s\S]+?)\s*:::\s*?/
Expand All @@ -18,7 +16,7 @@ const TypeMap: Record<TYPE, string> = {
danger: 'WARNING',
}

function getChildrenNode({ type, title, children }: { type: TYPE; title: string; children: NodeWithChildren[] }) {
function getChildrenNode({ type, title, children }: { type: TYPE; title: string; children: any[] }) {
return {
type: 'container',
children: [
Expand Down Expand Up @@ -58,7 +56,7 @@ function getChildrenNode({ type, title, children }: { type: TYPE; title: string;

export default function plugin(): IPluginTransformer {
return (tree, vfile) => {
visit(tree, 'root', function visitor(node: NodeWithChildren) {
visit(tree, 'root', function visitor(node: any) {
if (node.children) {
let i = 0
while (i < node.children.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/transform/plugins/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { YAML } from 'mdast'

export default function plugin(): IPluginTransformer {
return (tree, vfile) => {
visit(tree, 'yaml', function visitor(node: YAML) {
visit(tree, 'yaml', function visitor(node: any) {
if (node.data && node.data.parsedValue) {
vfile.data.frontmatter = node.data.parsedValue as VFileData['frontmatter']
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/transform/plugins/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { Node } from 'unist'

export default function plugin(): IPluginTransformer {
return (tree, vfile) => {
visit(tree, 'heading', function visitor(node: Heading & Node) {
const textNode = find(node, { type: 'text' })
visit(tree, 'heading', function visitor(node: any) {
const textNode: any = find(node, { type: 'text' })

const headerId = (node.data && (node.data.id as string)) || ''

Expand Down
2 changes: 1 addition & 1 deletion src/node/transform/plugins/img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getAssetHashName(imgPath: string) {

export default function plugin({ id, root, siteData }: PluginProps): IPluginTransformer {
return (tree, vfile) => {
visit(tree, 'element', function visitor(node: Node & Element) {
visit(tree, 'element', function visitor(node: any) {
if (node.tagName === 'img') {
if (process.env.NODE_ENV === 'build') {
const src = node.properties!.src as string
Expand Down
2 changes: 1 addition & 1 deletion src/node/transform/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function normalizeHref(href: string) {

export default function plugin(): IPluginTransformer {
return (tree, vfile) => {
visit(tree, ['link', 'linkReference'], function visitor(node: Link & Node) {
visit(tree, ['link', 'linkReference'], function visitor(node: any) {
const url = node.url

let data = node.data || (node.data = {})
Expand Down
4 changes: 2 additions & 2 deletions src/node/transform/plugins/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { Root, Element, Comment, Text } from 'hast'

export default function plugin(): IPluginTransformer {
return (tree, vfile) => {
visit(tree, 'root', function visitor(node: Node & Root) {
node.children = node.children.reduce((result, item) => {
visit(tree, 'root', function visitor(node: any) {
node.children = node.children.reduce((result: any, item: any) => {
if (!result.length || result[result.length - 1]._previewer) {
result.push({
type: 'element',
Expand Down

0 comments on commit e3c49e5

Please sign in to comment.