refactor: adjust shared utility/types build setup

fix non-existent imports in generated dts files
pull/317/head
Evan You 4 years ago
parent 2ef033c5c2
commit 55de7ab43c

4
.gitignore vendored

@ -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

@ -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",

@ -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/'))
})

@ -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/'))
}
}

@ -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<SiteData>) {

@ -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<VitePressData> = Symbol()

@ -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 {

@ -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

@ -1,5 +1,5 @@
import { siteDataRef } from './data'
import { inBrowser } from '/@shared/config'
import { inBrowser } from '../shared'
export { inBrowser }

@ -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'

@ -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'

@ -8,8 +8,6 @@
"lib": ["ESNext", "DOM"],
"types": ["vite/client"],
"paths": {
"/@shared/*": ["shared/*"],
"/@types/*": ["../../types/*"],
"/@theme/*": ["theme-default/*"],
"vitepress": ["index.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'

@ -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<ThemeConfig = any> {
@ -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'),

@ -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')

@ -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'

@ -6,10 +6,7 @@
"outDir": "../../dist/node",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"sourceMap": true,
"paths": {
"/@types/*": ["../../types/*"]
}
"sourceMap": true
},
"include": [".", "../../types/shared.d.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
}

@ -1,10 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"/@types/*": ["../../types/*"]
}
"baseUrl": "."
},
"include": [".", "../../types/shared.d.ts"]
}

@ -17,7 +17,6 @@
"shared/*": ["src/shared/*"],
"tests/*": ["__tests__/*"],
"/@shared/*": ["src/client/shared/*"],
"/@types/*": ["types/*"],
"vitepress": ["src/client/index.ts"]
}
},

Loading…
Cancel
Save