diff --git a/.gitignore b/.gitignore index 7726c297..0e9bd5c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /coverage -/src/client/shared -/src/node/shared +/src/client/shared.ts +/src/node/shared.ts *.log .DS_Store .vite_opt_cache diff --git a/package.json b/package.json index 40a86f95..631b9b5a 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "dependencies": { "@docsearch/css": "^1.0.0-alpha.28", "@docsearch/js": "^1.0.0-alpha.28", + "@types/markdown-it": "^12.0.1", "@vitejs/plugin-vue": "^1.2.3", "@vue/compiler-sfc": "^3.1.1", "@vue/server-renderer": "^3.1.1", @@ -97,7 +98,6 @@ "@types/koa": "^2.13.1", "@types/koa-static": "^4.0.1", "@types/lru-cache": "^5.1.0", - "@types/markdown-it": "^12.0.1", "@types/node": "^15.6.1", "@types/postcss-load-config": "^3.0.1", "chokidar": "^3.5.1", diff --git a/scripts/copyShared.js b/scripts/copyShared.js index af10bc26..89c5d350 100644 --- a/scripts/copyShared.js +++ b/scripts/copyShared.js @@ -2,6 +2,6 @@ const fs = require('fs-extra') const glob = require('globby') glob.sync('src/shared/**/*.ts').forEach((file) => { - fs.copy(file, file.replace(/^src\//, 'src/node/')) - fs.copy(file, file.replace(/^src\//, 'src/client/')) + fs.copy(file, file.replace(/^src\/shared\//, 'src/node/')) + fs.copy(file, file.replace(/^src\/shared\//, 'src/client/')) }) diff --git a/scripts/watchAndCopy.js b/scripts/watchAndCopy.js index d88a1567..806b41cd 100644 --- a/scripts/watchAndCopy.js +++ b/scripts/watchAndCopy.js @@ -3,11 +3,11 @@ const chokidar = require('chokidar') function toClientAndNode(method, file) { if (method === 'copy') { - fs.copy(file, file.replace(/^src\//, 'src/node/')) - fs.copy(file, file.replace(/^src\//, 'src/client/')) + fs.copy(file, file.replace(/^src\/shared\//, 'src/node/')) + fs.copy(file, file.replace(/^src\/shared\//, 'src/client/')) } else if (method === 'remove') { - fs.remove(file.replace(/^src\//, 'src/node/')) - fs.remove(file.replace(/^src\//, 'src/client/')) + fs.remove(file.replace(/^src\/shared\//, 'src/node/')) + fs.remove(file.replace(/^src\/shared\//, 'src/client/')) } } diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index c4ef6201..8fde0403 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -1,5 +1,5 @@ import { watchEffect, Ref } from 'vue' -import { HeadConfig, SiteData } from '../../../../types/shared' +import { HeadConfig, SiteData } from '../../shared' import { Route } from '../router' export function useUpdateHead(route: Route, siteDataByRouteRef: Ref) { diff --git a/src/client/app/data.ts b/src/client/app/data.ts index 682e5e32..836d719c 100644 --- a/src/client/app/data.ts +++ b/src/client/app/data.ts @@ -1,8 +1,7 @@ import { InjectionKey, Ref, ref, readonly, computed, inject } from 'vue' import { Route } from './router' -import { PageData, SiteData } from '/@types/shared' import serializedSiteData from '@siteData' -import { resolveSiteDataByRoute } from '../shared/config' +import { resolveSiteDataByRoute, PageData, SiteData } from '../shared' import { withBase } from './utils' export const dataSymbol: InjectionKey = Symbol() diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 7be4d609..52febae2 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -1,6 +1,6 @@ import { reactive, inject, markRaw, nextTick, readonly } from 'vue' import type { Component, InjectionKey } from 'vue' -import { PageData } from '../../../types/shared' +import { PageData } from '../shared' import { inBrowser } from './utils' export interface Route { diff --git a/src/client/app/theme.ts b/src/client/app/theme.ts index 09e4ae3b..bb25f0ab 100644 --- a/src/client/app/theme.ts +++ b/src/client/app/theme.ts @@ -1,6 +1,6 @@ import { App, Ref, Component } from 'vue' import { Router } from './router' -import { SiteData } from '../../../types/shared' +import { SiteData } from '../shared' export interface EnhanceAppContext { app: App diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 6e316d5a..f6438cc1 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -1,5 +1,5 @@ import { siteDataRef } from './data' -import { inBrowser } from '/@shared/config' +import { inBrowser } from '../shared' export { inBrowser } diff --git a/src/client/theme-default/components/SideBarLink.ts b/src/client/theme-default/components/SideBarLink.ts index 755f526d..42ba5012 100644 --- a/src/client/theme-default/components/SideBarLink.ts +++ b/src/client/theme-default/components/SideBarLink.ts @@ -1,6 +1,6 @@ import { FunctionalComponent, h, VNode } from 'vue' import { useRoute, useData } from 'vitepress' -import { Header } from '/@types/shared' +import { Header } from '../../shared' import { DefaultTheme } from '../config' import { joinUrl, isActive } from '../utils' diff --git a/src/client/theme-default/composables/sideBar.ts b/src/client/theme-default/composables/sideBar.ts index efe9d243..7781c5c6 100644 --- a/src/client/theme-default/composables/sideBar.ts +++ b/src/client/theme-default/composables/sideBar.ts @@ -1,6 +1,6 @@ import { computed } from 'vue' import { useRoute, useData } from 'vitepress' -import { Header } from '/@types/shared' +import { Header } from '../../shared' import { useActiveSidebarLinks } from '../composables/activeSidebarLink' import { getSideBarConfig } from '../support/sideBar' import { DefaultTheme } from '../config' diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json index ac1d79d0..f7f086aa 100644 --- a/src/client/tsconfig.json +++ b/src/client/tsconfig.json @@ -8,8 +8,6 @@ "lib": ["ESNext", "DOM"], "types": ["vite/client"], "paths": { - "/@shared/*": ["shared/*"], - "/@types/*": ["../../types/*"], "/@theme/*": ["theme-default/*"], "vitepress": ["index.ts"] } diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 59d3bb36..5bffa3d0 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -1,7 +1,7 @@ import path from 'path' import fs from 'fs-extra' import { SiteConfig, resolveSiteDataByRoute } from '../config' -import { HeadConfig } from '../../../types/shared' +import { HeadConfig } from '../shared' import { normalizePath } from 'vite' import { RollupOutput, OutputChunk, OutputAsset } from 'rollup' diff --git a/src/node/config.ts b/src/node/config.ts index 9e4831de..3434f467 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -4,11 +4,12 @@ import chalk from 'chalk' import globby from 'globby' import { AliasOptions } from 'vite' import { Options as VuePluginOptions } from '@vitejs/plugin-vue' -import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared' -export { resolveSiteDataByRoute } from './shared/config' +import { SiteData, HeadConfig, LocaleConfig } from './shared' import { resolveAliases, APP_PATH, DEFAULT_THEME_PATH } from './alias' import { MarkdownOptions } from './markdown/markdown' +export { resolveSiteDataByRoute } from './shared' + const debug = require('debug')('vitepress:config') export interface UserConfig { @@ -58,7 +59,10 @@ export async function resolveConfig( root, site, themeDir, - pages: await globby(['**.md'], { cwd: root, ignore: ['**/node_modules', ...userConfig.exclude || [] ] }), + pages: await globby(['**.md'], { + cwd: root, + ignore: ['**/node_modules', ...(userConfig.exclude || [])] + }), configPath: resolve(root, 'config.js'), outDir: resolve(root, 'dist'), tempDir: path.resolve(APP_PATH, 'temp'), diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 6270babe..06f5de40 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -11,7 +11,7 @@ import { hoistPlugin } from './plugins/hoist' import { preWrapperPlugin } from './plugins/preWrapper' import { linkPlugin } from './plugins/link' import { extractHeaderPlugin } from './plugins/header' -import { Header } from '../../../types/shared' +import { Header } from '../shared' const emoji = require('markdown-it-emoji') const anchor = require('markdown-it-anchor') diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 2c5722c9..b5ca425a 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -4,7 +4,7 @@ import matter from 'gray-matter' import LRUCache from 'lru-cache' import { createMarkdownRenderer, MarkdownOptions } from './markdown/markdown' import { deeplyParseHeader } from './utils/parseHeader' -import { PageData, HeadConfig } from '../../types/shared' +import { PageData, HeadConfig } from './shared' import { slash } from './utils/slash' import chalk from 'chalk' diff --git a/src/node/tsconfig.json b/src/node/tsconfig.json index 9f111473..ffcd3f4f 100644 --- a/src/node/tsconfig.json +++ b/src/node/tsconfig.json @@ -6,10 +6,7 @@ "outDir": "../../dist/node", "module": "commonjs", "lib": ["ESNext", "DOM"], - "sourceMap": true, - "paths": { - "/@types/*": ["../../types/*"] - } + "sourceMap": true }, "include": [".", "../../types/shared.d.ts"] } diff --git a/src/shared/config.ts b/src/shared/shared.ts similarity index 89% rename from src/shared/config.ts rename to src/shared/shared.ts index 7ca9b796..c7ce172c 100644 --- a/src/shared/config.ts +++ b/src/shared/shared.ts @@ -1,4 +1,12 @@ -import { SiteData } from '/@types/shared' +import { SiteData } from '../../types/shared' + +export type { + SiteData, + PageData, + HeadConfig, + LocaleConfig, + Header +} from '../../types/shared' export const inBrowser = typeof window !== 'undefined' @@ -14,7 +22,7 @@ function findMatchRoot(route: string, roots: string[]) { }) for (const r of roots) { - if (route.startsWith(r)) return r + if (route.startsWith(r)) return } return undefined } diff --git a/src/shared/tsconfig.json b/src/shared/tsconfig.json index eb70f6b6..5dd8a6db 100644 --- a/src/shared/tsconfig.json +++ b/src/shared/tsconfig.json @@ -1,10 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": ".", - "paths": { - "/@types/*": ["../../types/*"] - } + "baseUrl": "." }, "include": [".", "../../types/shared.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 7f68a9bc..708fe748 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ "shared/*": ["src/shared/*"], "tests/*": ["__tests__/*"], "/@shared/*": ["src/client/shared/*"], - "/@types/*": ["types/*"], "vitepress": ["src/client/index.ts"] } },