diff --git a/__tests__/vitest.config.js b/__tests__/vitest.config.js index cd9c2340..87b70c8c 100644 --- a/__tests__/vitest.config.js +++ b/__tests__/vitest.config.js @@ -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') } } -} +}) diff --git a/api-extractor.client.json b/api-extractor.client.json deleted file mode 100644 index 9540d6b4..00000000 --- a/api-extractor.client.json +++ /dev/null @@ -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" - } - } - } -} diff --git a/api-extractor.node.json b/api-extractor.node.json deleted file mode 100644 index 3d85f836..00000000 --- a/api-extractor.node.json +++ /dev/null @@ -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" - } - } - } -} diff --git a/bin/vitepress.js b/bin/vitepress.js index 0aafe1a3..7c50ec90 100755 --- a/bin/vitepress.js +++ b/bin/vitepress.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../dist/node/cli') +import('../dist/node/cli.js') diff --git a/package.json b/package.json index 51adb045..781bcfec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 555a2b16..48b1a66b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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'} diff --git a/rollup.config.ts b/rollup.config.ts new file mode 100644 index 00000000..fac34d03 --- /dev/null +++ b/rollup.config.ts @@ -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, + } + }) + ] + } +]) diff --git a/scripts/copyClient.js b/scripts/copyClient.js index 20553aea..3abd6067 100644 --- a/scripts/copyClient.js +++ b/scripts/copyClient.js @@ -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)) }) diff --git a/scripts/copyShared.js b/scripts/copyShared.js index 89c5d350..db4b810d 100644 --- a/scripts/copyShared.js +++ b/scripts/copyShared.js @@ -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/')) }) diff --git a/scripts/release.js b/scripts/release.js index 8e5cef88..075880fd 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -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)) diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js deleted file mode 100644 index 0c35907e..00000000 --- a/scripts/rollup.config.js +++ /dev/null @@ -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) - } -}) diff --git a/scripts/watchAndCopy.js b/scripts/watchAndCopy.js index ff9f3e79..58c3b421 100644 --- a/scripts/watchAndCopy.js +++ b/scripts/watchAndCopy.js @@ -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))) diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 96052d19..d22d123c 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -116,7 +116,7 @@ function newRouter(): Router { // SSR: sync require // @ts-ignore - return require(pageFilePath) + return import(pageFilePath) }, NotFound) } diff --git a/src/client/index.ts b/src/client/index.ts index 519a6054..96c628bf 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -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 diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json index 1220a29d..92a8af1c 100644 --- a/src/client/tsconfig.json +++ b/src/client/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.json", + "extends": "../../tsconfig.json", "compilerOptions": { "baseUrl": ".", "outDir": "../../dist/client", diff --git a/src/node/alias.ts b/src/node/alias.ts index 863e4f17..f863a46f 100644 --- a/src/node/alias.ts +++ b/src/node/alias.ts @@ -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 + '/' }, diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 7a5a46f1..26d608fb 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -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 => ({ 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({ diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 1a57d4c3..7e9d6989 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -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, 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 )) diff --git a/src/node/cli.ts b/src/node/cli.ts index 0a2cf4fb..308fc416 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -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] diff --git a/src/node/config.ts b/src/node/config.ts index b02bf083..0bd00bb5 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -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') diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts index aab5f996..4b9af8fd 100644 --- a/src/node/markdown/plugins/highlight.ts +++ b/src/node/markdown/plugins/highlight.ts @@ -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']) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 02ba4661..e2297e85 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -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 // 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) diff --git a/src/node/server.ts b/src/node/server.ts index f0b7bd57..4f81fef4 100644 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -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 }) } diff --git a/src/node/tsconfig.json b/src/node/tsconfig.json index 5681fb02..26db4671 100644 --- a/src/node/tsconfig.json +++ b/src/node/tsconfig.json @@ -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 }, diff --git a/src/node/utils/parseHeader.ts b/src/node/utils/parseHeader.ts index d1b40c80..b303e222 100644 --- a/src/node/utils/parseHeader.ts +++ b/src/node/utils/parseHeader.ts @@ -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 ) } diff --git a/src/tsconfig.json b/tsconfig.json similarity index 58% rename from src/tsconfig.json rename to tsconfig.json index 23959e09..62c23268 100644 --- a/src/tsconfig.json +++ b/tsconfig.json @@ -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" + ] }