pull/666/head
Anthony Fu 3 years ago
parent 8bc14e6366
commit a7688c85f2

@ -1,10 +1,11 @@
import path from 'path'
import {defineConfig} from 'vite'
export default {
export default defineConfig({
resolve: {
alias: {
node: path.resolve(__dirname, '../src/node'),
client: path.resolve(__dirname, '../src/client')
}
}
}
})

@ -1,53 +0,0 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": "./src/client",
"mainEntryPointFilePath": "./dist/temp/index.d.ts",
"dtsRollup": {
"enabled": true,
"publicTrimmedFilePath": "./dist/client/index.d.ts"
},
"apiReport": {
"enabled": false
},
"docModel": {
"enabled": false
},
"tsdocMetadata": {
"enabled": false
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},
"ae-missing-release-tag": {
"logLevel": "none"
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
},
"tsdoc-undefined-tag": {
"logLevel": "none"
}
}
}
}

@ -1,53 +0,0 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": "./src/node",
"mainEntryPointFilePath": "./dist/temp/index.d.ts",
"dtsRollup": {
"enabled": true,
"publicTrimmedFilePath": "./dist/node/index.d.ts"
},
"apiReport": {
"enabled": false
},
"docModel": {
"enabled": false
},
"tsdocMetadata": {
"enabled": false
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},
"ae-missing-release-tag": {
"logLevel": "none"
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
},
"tsdoc-undefined-tag": {
"logLevel": "none"
}
}
}
}

@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../dist/node/cli')
import('../dist/node/cli.js')

@ -1,10 +1,17 @@
{
"name": "vitepress",
"version": "1.0.0-draft.4",
"type": "module",
"packageManager": "pnpm@7.0.1",
"description": "Vite & Vue powered static site generator",
"main": "dist/node/index.js",
"typings": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/node/index.js"
}
},
"bin": {
"vitepress": "bin/vitepress.js"
},
@ -34,19 +41,16 @@
"node": ">=14.0.0"
},
"scripts": {
"dev": "run-s dev-shared dev-start",
"dev": "rimraf dist && run-s dev-shared dev-start",
"dev-start": "run-p dev-client dev-node dev-watch",
"dev-client": "tsc -w -p src/client",
"dev-node": "tsc -w -p src/node",
"dev-node": "pnpm run build-node -w",
"dev-shared": "node scripts/copyShared",
"dev-watch": "node scripts/watchAndCopy",
"build": "run-s build-prepare build-client build-node build-types",
"build-prepare": "rimraf -rf dist && node scripts/copyShared",
"build": "run-s build-prepare build-client build-node",
"build-prepare": "rimraf dist && node scripts/copyShared",
"build-client": "tsc -p src/client && node scripts/copyClient",
"build-node": "rollup -c scripts/rollup.config.js",
"build-types": "run-s build-types-client build-types-node",
"build-types-client": "tsc -p src/client --declaration --emitDeclarationOnly --outDir dist/temp && api-extractor run -c api-extractor.client.json && rimraf dist/temp",
"build-types-node": "tsc -p src/node --declaration --emitDeclarationOnly --outDir dist/temp && api-extractor run -c api-extractor.node.json && rimraf dist/temp",
"build-node": "rollup --config rollup.config.ts --configPlugin esbuild",
"lint": "run-s lint:js lint:ts",
"lint:js": "prettier --check --write \"{bin,docs,scripts,src}/**/*.js\"",
"lint:ts": "prettier --check --write --parser typescript \"{__tests__,src,docs,types}/**/*.ts\"",
@ -84,7 +88,6 @@
"vue": "3.2.33"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.23.1",
"@rollup/plugin-alias": "^3.1.5",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-json": "^4.1.0",
@ -133,6 +136,7 @@
"prettier": "^2.3.0",
"rimraf": "^3.0.2",
"rollup": "^2.56.3",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-esbuild": "^4.8.2",
"semver": "^7.3.5",
"sirv": "^1.0.12",

@ -59,6 +59,7 @@ importers:
prismjs: ^1.25.0
rimraf: ^3.0.2
rollup: ^2.56.3
rollup-plugin-dts: ^4.2.2
rollup-plugin-esbuild: ^4.8.2
semver: ^7.3.5
sirv: ^1.0.12
@ -126,6 +127,7 @@ importers:
prettier: 2.4.1
rimraf: 3.0.2
rollup: 2.57.0
rollup-plugin-dts: 4.2.2_uqij4qbui2sihvymklsku23n6q
rollup-plugin-esbuild: 4.8.2_ofyf2sflbd3x5kuhhv7zkdsvfy
semver: 7.3.5
sirv: 1.0.17
@ -256,6 +258,15 @@ packages:
'@babel/highlight': 7.14.5
dev: true
/@babel/code-frame/7.16.7:
resolution: {integrity: sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==}
engines: {node: '>=6.9.0'}
requiresBuild: true
dependencies:
'@babel/highlight': 7.17.12
dev: true
optional: true
/@babel/helper-validator-identifier/7.16.7:
resolution: {integrity: sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==}
engines: {node: '>=6.9.0'}
@ -269,6 +280,16 @@ packages:
js-tokens: 4.0.0
dev: true
/@babel/highlight/7.17.12:
resolution: {integrity: sha512-7yykMVF3hfZY2jsHZEEgLc+3x4o1O+fYyULu11GynEUQNwB6lua+IIQn1FiJxNucd5UlyJryrwsOh8PL9Sn8Qg==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/helper-validator-identifier': 7.16.7
chalk: 2.4.2
js-tokens: 4.0.0
dev: true
optional: true
/@babel/parser/7.16.4:
resolution: {integrity: sha512-6V0qdPUaiVHH3RtZeLIsc+6pDhbYzHR8ogA8w+f+Wc77DuXto19g2QUwveINoS34Uw+W8/hQDGJCx+i4n7xcng==}
engines: {node: '>=6.0.0'}
@ -2720,6 +2741,13 @@ packages:
dependencies:
sourcemap-codec: 1.4.8
/magic-string/0.26.2:
resolution: {integrity: sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==}
engines: {node: '>=12'}
dependencies:
sourcemap-codec: 1.4.8
dev: true
/map-obj/1.0.1:
resolution: {integrity: sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=}
engines: {node: '>=0.10.0'}
@ -3352,6 +3380,20 @@ packages:
glob: 7.2.0
dev: true
/rollup-plugin-dts/4.2.2_uqij4qbui2sihvymklsku23n6q:
resolution: {integrity: sha512-A3g6Rogyko/PXeKoUlkjxkP++8UDVpgA7C+Tdl77Xj4fgEaIjPSnxRmR53EzvoYy97VMVwLAOcWJudaVAuxneQ==}
engines: {node: '>=v12.22.11'}
peerDependencies:
rollup: ^2.55
typescript: ^4.1
dependencies:
magic-string: 0.26.2
rollup: 2.57.0
typescript: 4.6.4
optionalDependencies:
'@babel/code-frame': 7.16.7
dev: true
/rollup-plugin-esbuild/4.8.2_ofyf2sflbd3x5kuhhv7zkdsvfy:
resolution: {integrity: sha512-wsaYNOjzTb6dN1qCIZsMZ7Q0LWiPJklYs2TDI8vJA2LUbvtPUY+17TC8C0vSat3jPMInfR9XWKdA7ttuwkjsGQ==}
engines: {node: '>=12'}

@ -0,0 +1,70 @@
import { defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'
import json from '@rollup/plugin-json'
import dts from 'rollup-plugin-dts'
import alias from '@rollup/plugin-alias'
import { resolve } from 'path'
import { fileURLToPath } from 'url'
import pkg from './package.json'
const ROOT = fileURLToPath(import.meta.url)
const r = (p:string) => resolve(ROOT, '..', p)
const external =[
...Object.keys(pkg.dependencies),
'buffer',
'punycode',
'prismjs/components/index.js'
]
export default defineConfig([
{
input: [r('src/node/index.ts'), r('src/node/cli.ts')],
output: {
format: 'esm',
dir: r('dist/node')
},
external,
plugins: [
alias({
entries: {
'readable-stream': 'stream'
}
}),
commonjs(),
nodeResolve(),
esbuild({
target: 'node14'
}),
json()
],
onwarn(warning, warn) {
if (warning.code !== 'EVAL') warn(warning)
}
}, {
input: r('src/node/index.ts'),
output: {
format: 'esm',
file: 'dist/node/index.d.ts'
},
plugins: [
dts()
]
},
{
input: r('src/client/index.ts'),
output: {
format: 'esm',
file: 'dist/client/index.d.ts'
},
plugins: [
dts({
compilerOptions: {
"skipLibCheck": true,
}
})
]
}
])

@ -1,11 +1,12 @@
const fs = require('fs-extra')
const glob = require('globby')
import { copy } from 'fs-extra'
import { sync } from 'globby'
function toDest(file) {
return file.replace(/^src\//, 'dist/')
}
glob.sync('src/client/**').forEach((file) => {
if (/(\.ts|tsconfig\.json)$/.test(file)) return
fs.copy(file, toDest(file))
sync('src/client/**').forEach((file) => {
if (/(\.ts|tsconfig\.json)$/.test(file))
return
copy(file, toDest(file))
})

@ -1,7 +1,8 @@
const fs = require('fs-extra')
const glob = require('globby')
import { copy } from 'fs-extra'
import { sync } from 'globby'
glob.sync('src/shared/**/*.ts').forEach((file) => {
fs.copy(file, file.replace(/^src\/shared\//, 'src/node/'))
fs.copy(file, file.replace(/^src\/shared\//, 'src/client/'))
sync('src/shared/**/*.ts')
.map(async (file) => {
await copy(file, file.replace(/^src\/shared\//, 'src/node/'))
await copy(file, file.replace(/^src\/shared\//, 'src/client/'))
})

@ -1,17 +1,16 @@
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const semver = require('semver')
const { prompt } = require('enquirer')
const execa = require('execa')
const currentVersion = require('../package.json').version
import { readFileSync, writeFileSync } from 'fs'
import { resolve } from 'path'
import { cyan } from 'chalk'
import { inc as _inc, valid } from 'semver'
import { prompt } from 'enquirer'
import execa from 'execa'
import { version as currentVersion } from '../package.json'
const versionIncrements = ['patch', 'minor', 'major']
const inc = (i) => semver.inc(currentVersion, i)
const run = (bin, args, opts = {}) =>
execa(bin, args, { stdio: 'inherit', ...opts })
const step = (msg) => console.log(chalk.cyan(msg))
const inc = (i) => _inc(currentVersion, i)
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts })
const step = (msg) => console.log(cyan(msg))
async function main() {
let targetVersion
@ -36,7 +35,7 @@ async function main() {
targetVersion = release.match(/\((.*)\)/)[1]
}
if (!semver.valid(targetVersion)) {
if (!valid(targetVersion)) {
throw new Error(`Invalid target version: ${targetVersion}`)
}
@ -90,12 +89,12 @@ async function main() {
}
function updatePackage(version) {
const pkgPath = path.resolve(path.resolve(__dirname, '..'), 'package.json')
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
const pkgPath = resolve(resolve(__dirname, '..'), 'package.json')
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
pkg.version = version
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
}
main().catch((err) => console.error(err))

@ -1,35 +0,0 @@
import { defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import { resolve } from 'path'
const r = (p) => resolve(__dirname, '../', p)
const pkg = require('../package.json')
export default defineConfig({
input: [r('src/node/index.ts'), r('src/node/cli.ts')],
output: {
format: 'cjs',
dir: r('dist/node')
},
external: [...Object.keys(pkg.dependencies), 'buffer', 'punycode'],
plugins: [
alias({
entries: {
'readable-stream': 'stream'
}
}),
commonjs(),
nodeResolve(),
esbuild({
target: 'node12'
}),
json()
],
onwarn(warning, warn) {
if (warning.code !== 'EVAL') warn(warning)
}
})

@ -1,15 +1,15 @@
const fs = require('fs-extra')
const chokidar = require('chokidar')
const { normalizePath } = require('vite')
import { copy, remove } from 'fs-extra'
import { watch } from 'chokidar'
import { normalizePath } from 'vite'
function toClientAndNode(method, file) {
file = normalizePath(file)
if (method === 'copy') {
fs.copy(file, file.replace(/^src\/shared\//, 'src/node/'))
fs.copy(file, file.replace(/^src\/shared\//, 'src/client/'))
copy(file, file.replace(/^src\/shared\//, 'src/node/'))
copy(file, file.replace(/^src\/shared\//, 'src/client/'))
} else if (method === 'remove') {
fs.remove(file.replace(/^src\/shared\//, 'src/node/'))
fs.remove(file.replace(/^src\/shared\//, 'src/client/'))
remove(file.replace(/^src\/shared\//, 'src/node/'))
remove(file.replace(/^src\/shared\//, 'src/client/'))
}
}
@ -18,16 +18,14 @@ function toDist(file) {
}
// copy shared files to the client and node directory whenever they change.
chokidar
.watch('src/shared/**/*.ts')
watch('src/shared/**/*.ts')
.on('change', (file) => toClientAndNode('copy', file))
.on('add', (file) => toClientAndNode('copy', file))
.on('unlink', (file) => toClientAndNode('remove', file))
// copy non ts files, such as an html or css, to the dist directory whenever
// they change.
chokidar
.watch('src/client/**/!(*.ts|tsconfig.json)')
.on('change', (file) => fs.copy(file, toDist(file)))
.on('add', (file) => fs.copy(file, toDist(file)))
.on('unlink', (file) => fs.remove(toDist(file)))
watch('src/client/**/!(*.ts|tsconfig.json)')
.on('change', (file) => copy(file, toDist(file)))
.on('add', (file) => copy(file, toDist(file)))
.on('unlink', (file) => remove(toDist(file)))

@ -116,7 +116,7 @@ function newRouter(): Router {
// SSR: sync require
// @ts-ignore
return require(pageFilePath)
return import(pageFilePath)
}, NotFound)
}

@ -25,7 +25,5 @@ export { inBrowser, withBase } from './app/utils'
// components
export { Content } from './app/components/Content'
import { ComponentOptions } from 'vue'
import _Debug from './app/components/Debug.vue'
const Debug = _Debug as ComponentOptions
export { Debug }
export const Debug = _Debug as import('vue').ComponentOptions

@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "../../dist/client",

@ -1,11 +1,14 @@
import path from 'path'
import { createRequire } from 'module'
import {resolve, join} from 'path'
import { fileURLToPath } from 'url'
import { Alias, AliasOptions } from 'vite'
const PKG_ROOT = path.join(__dirname, '../../')
export const DIST_CLIENT_PATH = path.join(__dirname, '../client')
export const APP_PATH = path.join(DIST_CLIENT_PATH, 'app')
export const SHARED_PATH = path.join(DIST_CLIENT_PATH, 'shared')
export const DEFAULT_THEME_PATH = path.join(DIST_CLIENT_PATH, 'theme-default')
const require = createRequire(import.meta.url)
const PKG_ROOT = resolve(fileURLToPath(import.meta.url), '../../../')
export const DIST_CLIENT_PATH = resolve(PKG_ROOT, 'client')
export const APP_PATH = join(DIST_CLIENT_PATH, 'app')
export const SHARED_PATH = join(DIST_CLIENT_PATH, 'shared')
export const DEFAULT_THEME_PATH = join(DIST_CLIENT_PATH, 'theme-default')
// special virtual file
// we can't directly import '/@siteData' because
@ -39,11 +42,11 @@ export function resolveAliases(root: string, themeDir: string): AliasOptions {
})),
{
find: /^vitepress$/,
replacement: path.join(__dirname, '../client/index')
replacement: join(DIST_CLIENT_PATH, '/index')
},
{
find: /^vitepress\/theme$/,
replacement: path.join(__dirname, '../client/theme-default/index')
replacement: join(DIST_CLIENT_PATH, '/theme-default/index')
},
// alias for local linked development
{ find: /^vitepress\//, replacement: PKG_ROOT + '/' },

@ -41,11 +41,11 @@ export async function bundle(
// resolve options to pass to vite
const { rollupOptions } = options
const resolveViteConfig = (ssr: boolean): ViteUserConfig => ({
const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => ({
root: srcDir,
base: config.site.base,
logLevel: 'warn',
plugins: createVitePressPlugin(
plugins: await createVitePressPlugin(
root,
config,
ssr,
@ -108,8 +108,8 @@ export async function bundle(
spinner.start('building client + server bundles...')
try {
;[clientResult, serverResult] = await (Promise.all([
config.mpa ? null : build(resolveViteConfig(false)),
build(resolveViteConfig(true))
config.mpa ? null : build(await resolveViteConfig(false)),
build(await resolveViteConfig(true))
]) as Promise<[RollupOutput, RollupOutput]>)
} catch (e) {
spinner.stopAndPersist({

@ -6,6 +6,9 @@ import { normalizePath, transformWithEsbuild } from 'vite'
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup'
import { slash } from '../utils/slash'
import escape from 'escape-html'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
export async function renderPage(
config: SiteConfig,
@ -16,7 +19,7 @@ export async function renderPage(
pageToHashMap: Record<string, string>,
hashMapString: string
) {
const { createApp } = require(path.join(config.tempDir, `app.js`))
const { createApp } = await import(path.join(config.tempDir, `app.js`))
const { app, router } = createApp()
const routePath = `/${page.replace(/\.md$/, '')}`
const siteData = resolveSiteDataByRoute(config.site, routePath)
@ -34,7 +37,7 @@ export async function renderPage(
}
// render page
const content = await require(rendererPath).renderToString(app)
const content = await import(rendererPath).then(r=>r.renderToString(app))
const pageName = page.replace(/\//g, '_')
// server build doesn't need hash
@ -45,7 +48,7 @@ export async function renderPage(
const pageClientJsFileName = `assets/${pageName}.${pageHash}.lean.js`
// resolve page data so we can render head tags
const { __pageData } = require(path.join(
const { __pageData } = await import(path.join(
config.tempDir,
pageServerJsFileName
))

@ -1,10 +1,11 @@
import chalk from 'chalk'
import minimist from 'minimist'
import { createServer, build, serve } from '.'
import {version} from '../../package.json'
const argv: any = minimist(process.argv.slice(2))
console.log(chalk.cyan(`vitepress v${require('../../package.json').version}`))
console.log(chalk.cyan(`vitepress v${version}`))
const command = argv._[0]
const root = argv._[command ? 1 : 0]

@ -23,7 +23,6 @@ import { MarkdownOptions } from './markdown/markdown'
import _debug from 'debug'
export { resolveSiteDataByRoute } from './shared'
export type { MarkdownOptions }
const debug = _debug('vitepress:config')

@ -1,9 +1,8 @@
import chalk from 'chalk'
import escapeHtml from 'escape-html'
import prism from 'prismjs'
// prism is listed as actual dep so it's ok to require
const loadLanguages = require('prismjs/components/index')
// @ts-expect-error
import loadLanguages from 'prismjs/components/index.js'
// required to make embedded highlighting work...
loadLanguages(['markup', 'css', 'javascript'])

@ -28,7 +28,7 @@ const isPageChunk = (
chunk.facadeModuleId.endsWith('.md')
)
export function createVitePressPlugin(
export async function createVitePressPlugin(
root: string,
siteConfig: SiteConfig,
ssr = false,
@ -49,10 +49,10 @@ export function createVitePressPlugin(
let markdownToVue: ReturnType<typeof createMarkdownToVueRenderFn>
// lazy require plugin-vue to respect NODE_ENV in @vue/compiler-x
const vuePlugin = require('@vitejs/plugin-vue')({
const vuePlugin = await import('@vitejs/plugin-vue').then(r=>r.default({
include: [/\.vue$/, /\.md$/],
...userVuePluginOptions
})
}))
const processClientJS = (code: string, id: string) => {
return scriptClientRE.test(code)

@ -12,7 +12,7 @@ export async function createServer(
root: config.srcDir,
base: config.site.base,
// logLevel: 'warn',
plugins: createVitePressPlugin(root, config),
plugins: await createVitePressPlugin(root, config),
server: serverOptions
})
}

@ -1,10 +1,10 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2019",
"target": "es2020",
"baseUrl": ".",
"outDir": "../../dist/node",
"module": "commonjs",
"module": "esnext",
"types": ["node"],
"sourceMap": true
},

@ -14,7 +14,7 @@ import emojiData from 'markdown-it-emoji/lib/data/full.json'
const parseEmojis = (str: string) => {
return str.replace(
/:(.+?):/g,
(placeholder, key) => emojiData[key] || placeholder
(placeholder, key) => (emojiData as any)[key] || placeholder
)
}

@ -1,12 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"esModuleInterop": true,
"lib": ["ESNext"]
"resolveJsonModule": true,
"lib": ["ESNext", "DOM"],
},
"include": ["../types/shared.d.ts"]
"exclude": [
"node_modules",
"dist"
]
}
Loading…
Cancel
Save