refactor: drop fs-extra and organize imports

triage
Divyansh Singh 2 months ago
parent 228eef187a
commit e6e90ed5a9

@ -1,4 +1,4 @@
import fs from 'fs-extra'
import fs from 'node:fs'
import getPort from 'get-port'
import { nanoid } from 'nanoid'
import path from 'node:path'
@ -33,12 +33,12 @@ const variations = themes.flatMap((theme) =>
afterAll(async () => {
await page.close()
await browser.close()
await fs.remove(tempDir)
await fs.promises.rm(tempDir, { recursive: true, force: true })
})
test.each(variations)('init %s', async (_, { theme, useTs }) => {
const root = getTempRoot()
await fs.remove(root)
await fs.promises.rm(root, { recursive: true, force: true })
scaffold({ root, theme, useTs, injectNpmScripts: false })
const port = await getPort()

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -329,7 +329,7 @@ The paths loader module is run in Node.js and only executed during build time. Y
Generating paths from local files:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -290,7 +290,7 @@ El módulo de carga de paths es ejecutado en Node.js y apenas durante el momento
Generando paths a partir de archivos locales:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -295,7 +295,7 @@ export default {
تولید مسیرها از فایل‌های محلی:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -304,7 +304,7 @@ export default {
ローカルファイルから生成する例:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -291,7 +291,7 @@ export default {
로컬 파일에서 경로 생성:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -290,7 +290,7 @@ O módulo de carregamento de caminhos é executado no Node.js e apenas durante o
Gerando caminhos a partir de arquivos locais:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -329,7 +329,7 @@ export default {
Генерация путей из локальных файлов:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
const require = createRequire(import.meta.url)

@ -291,7 +291,7 @@ export default {
从本地文件生成路径:
```js
import fs from 'fs'
import fs from 'node:fs'
export default {
paths() {

@ -135,7 +135,6 @@
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-replace": "^6.0.3",
"@types/cross-spawn": "^6.0.6",
"@types/fs-extra": "^11.0.4",
"@types/lodash.template": "^4.5.3",
"@types/mark.js": "^8.11.12",
"@types/markdown-it-attrs": "^4.1.3",
@ -150,7 +149,6 @@
"conventional-changelog-angular": "^8.3.1",
"cross-spawn": "^7.0.6",
"esbuild": "^0.27.7",
"fs-extra": "^11.3.5",
"get-port": "^7.2.0",
"gray-matter": "^4.0.3",
"lint-staged": "^16.4.0",

@ -137,9 +137,6 @@ importers:
'@types/cross-spawn':
specifier: ^6.0.6
version: 6.0.6
'@types/fs-extra':
specifier: ^11.0.4
version: 11.0.4
'@types/lodash.template':
specifier: ^4.5.3
version: 4.5.3
@ -182,9 +179,6 @@ importers:
esbuild:
specifier: ^0.27.7
version: 0.27.7
fs-extra:
specifier: ^11.3.5
version: 11.3.5
get-port:
specifier: ^7.2.0
version: 7.2.0
@ -1044,18 +1038,12 @@ packages:
'@types/estree@1.0.9':
resolution: {integrity: sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==}
'@types/fs-extra@11.0.4':
resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==}
'@types/hast@3.0.4':
resolution: {integrity: sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==}
'@types/jquery@4.0.1':
resolution: {integrity: sha512-9a59A/tycXgYuPABcp6/3spSShn0NT2UOM4EfHvMumjYi4lJWTsK5SZWjhx3yRm9IHGCeWXdV2YfNsrWrft/CA==}
'@types/jsonfile@6.1.4':
resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==}
'@types/linkify-it@5.0.0':
resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==}
@ -1728,10 +1716,6 @@ packages:
resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==}
engines: {node: '>=0.4.x'}
fs-extra@11.3.5:
resolution: {integrity: sha512-eKpRKAovdpZtR1WopLHxlBWvAgPny3c4gX1G5Jhwmmw4XJj0ifSD5qB5TOo8hmA0wlRKDAOAhEE1yVPgs6Fgcg==}
engines: {node: '>=14.14'}
fsevents@2.3.3:
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
@ -1775,9 +1759,6 @@ packages:
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
engines: {node: '>= 0.4'}
graceful-fs@4.2.11:
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
gray-matter@4.0.3:
resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==}
engines: {node: '>=6.0'}
@ -1917,9 +1898,6 @@ packages:
resolution: {integrity: sha512-ttBQIIQPDeLjpPOohtUdXuXUVoA2uIB6fEH9HyJ7234s5mBJ5wTx20njxplLZQgLaOfpmPQA7X2t5AX6tIPbog==}
hasBin: true
jsonfile@6.2.1:
resolution: {integrity: sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==}
juice@8.1.0:
resolution: {integrity: sha512-FLzurJrx5Iv1e7CfBSZH68dC04EEvXvvVvPYB7Vx1WAuhCp1ZPIMtqxc+WTWxVkpTIC2Ach/GAv0rQbtGf6YMA==}
engines: {node: '>=10.0.0'}
@ -2799,10 +2777,6 @@ packages:
unist-util-visit@5.1.0:
resolution: {integrity: sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==}
universalify@2.0.1:
resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==}
engines: {node: '>= 10.0.0'}
unplugin-utils@0.2.5:
resolution: {integrity: sha512-gwXJnPRewT4rT7sBi/IvxKTjsms7jX7QIDLOClApuZwR49SXbrB1z2NLUZ+vDHyqCj/n58OzRRqaW+B8OZi8vg==}
engines: {node: '>=18.12.0'}
@ -3551,21 +3525,12 @@ snapshots:
'@types/estree@1.0.9': {}
'@types/fs-extra@11.0.4':
dependencies:
'@types/jsonfile': 6.1.4
'@types/node': 25.9.4
'@types/hast@3.0.4':
dependencies:
'@types/unist': 3.0.3
'@types/jquery@4.0.1': {}
'@types/jsonfile@6.1.4':
dependencies:
'@types/node': 25.9.4
'@types/linkify-it@5.0.0': {}
'@types/lodash.template@4.5.3':
@ -4234,12 +4199,6 @@ snapshots:
format@0.2.2: {}
fs-extra@11.3.5:
dependencies:
graceful-fs: 4.2.11
jsonfile: 6.2.1
universalify: 2.0.1
fsevents@2.3.3:
optional: true
@ -4281,8 +4240,6 @@ snapshots:
gopd@1.2.0: {}
graceful-fs@4.2.11: {}
gray-matter@4.0.3:
dependencies:
js-yaml: 3.15.0
@ -4428,12 +4385,6 @@ snapshots:
argparse: 1.0.10
esprima: 4.0.1
jsonfile@6.2.1:
dependencies:
universalify: 2.0.1
optionalDependencies:
graceful-fs: 4.2.11
juice@8.1.0:
dependencies:
cheerio: 1.0.0-rc.10
@ -5437,8 +5388,6 @@ snapshots:
unist-util-is: 6.0.1
unist-util-visit-parents: 6.0.2
universalify@2.0.1: {}
unplugin-utils@0.2.5:
dependencies:
pathe: 2.0.3

@ -1,4 +1,4 @@
import { copy } from 'fs-extra'
import { cp } from 'node:fs/promises'
import { globSync } from 'tinyglobby'
function toDest(file) {
@ -7,5 +7,5 @@ function toDest(file) {
globSync(['src/client/**']).forEach((file) => {
if (/(\.ts|tsconfig\.json)$/.test(file)) return
copy(file, toDest(file))
cp(file, toDest(file))
})

@ -1,9 +1,9 @@
import { copy } from 'fs-extra'
import { cp } from 'node:fs/promises'
import { globSync } from 'tinyglobby'
globSync(['src/shared/**/*.ts']).forEach(async (file) => {
await Promise.all([
copy(file, file.replace(/^src\/shared\//, 'src/node/')),
copy(file, file.replace(/^src\/shared\//, 'src/client/'))
cp(file, file.replace(/^src\/shared\//, 'src/node/')),
cp(file, file.replace(/^src\/shared\//, 'src/client/'))
])
})

@ -1,8 +1,8 @@
import { spawn } from 'node:child_process'
import { readFileSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createRequire } from 'node:module'
import c from 'picocolors'
import prompts from 'prompts'
import semver from 'semver'

@ -1,15 +1,15 @@
import { watch } from 'chokidar'
import { copy, remove } from 'fs-extra'
import { cp, rm } from 'node:fs/promises'
import { normalizePath } from 'vite'
function toClientAndNode(method, file) {
file = normalizePath(file)
if (method === 'copy') {
copy(file, file.replace(/^src\/shared\//, 'src/node/'))
copy(file, file.replace(/^src\/shared\//, 'src/client/'))
cp(file, file.replace(/^src\/shared\//, 'src/node/'))
cp(file, file.replace(/^src\/shared\//, 'src/client/'))
} else if (method === 'remove') {
remove(file.replace(/^src\/shared\//, 'src/node/'))
remove(file.replace(/^src\/shared\//, 'src/client/'))
rm(file.replace(/^src\/shared\//, 'src/node/'), { force: true })
rm(file.replace(/^src\/shared\//, 'src/client/'), { force: true })
}
}
@ -31,6 +31,6 @@ watch('src/client', {
ignored: (path, stats) =>
stats?.isFile() && (path.endsWith('.ts') || path.endsWith('tsconfig.json'))
})
.on('change', (file) => copy(file, toDist(file)))
.on('add', (file) => copy(file, toDist(file)))
.on('unlink', (file) => remove(toDist(file)))
.on('change', (file) => cp(file, toDist(file)))
.on('add', (file) => cp(file, toDist(file)))
.on('unlink', (file) => rm(toDist(file), { force: true }))

@ -2,8 +2,8 @@
// so the user can do `import { useRoute, useData } from 'vitepress'`
// generic types
export type { VitePressData } from './shared'
export type { Route, Router } from './app/router'
export type { VitePressData } from './shared'
// theme types
export type { EnhanceAppContext, Theme } from './app/theme'

@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { normalizeLink } from '../support/utils'
import { EXTERNAL_URL_RE } from '../../shared'
import { normalizeLink } from '../support/utils'
interface Props {
tag?: string

@ -1,6 +1,6 @@
<script setup lang="ts">
import type { DefaultTheme } from 'vitepress/theme'
import { ref, watch, onMounted } from 'vue'
import { onMounted, ref, watch } from 'vue'
import { useAside } from '../composables/aside'
import { useData } from '../composables/data'

@ -1,7 +1,7 @@
<script setup lang="ts">
import { useData } from '../composables/data'
import VPDocAsideOutline from './VPDocAsideOutline.vue'
import VPDocAsideCarbonAds from './VPDocAsideCarbonAds.vue'
import VPDocAsideOutline from './VPDocAsideOutline.vue'
const { theme } = useData()
</script>

@ -1,6 +1,6 @@
<script setup lang="ts">
import { defineAsyncComponent } from 'vue'
import type { DefaultTheme } from 'vitepress/theme'
import { defineAsyncComponent } from 'vue'
defineProps<{
carbonAds: DefaultTheme.CarbonAdsOptions

@ -1,9 +1,9 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useData } from '../composables/data'
import { useLayout } from '../composables/layout'
import { resolveTitle, useActiveAnchor } from '../composables/outline'
import VPDocOutlineItem from './VPDocOutlineItem.vue'
import { useLayout } from '../composables/layout'
const { theme } = useData()

@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Sponsors } from './VPSponsors.vue'
import type { Sponsor } from './VPSponsorsGrid.vue'
import VPSponsors from './VPSponsors.vue'
import type { Sponsor } from './VPSponsorsGrid.vue'
defineProps<{
tier?: string

@ -3,8 +3,8 @@ import { computed } from 'vue'
import { useData } from '../composables/data'
import { useEditLink } from '../composables/edit-link'
import { usePrevNext } from '../composables/prev-next'
import VPLink from './VPLink.vue'
import VPDocFooterLastUpdated from './VPDocFooterLastUpdated.vue'
import VPLink from './VPLink.vue'
const { theme, page, frontmatter } = useData()

@ -1,8 +1,8 @@
<script setup lang="ts">
import VPHomeHero from './VPHomeHero.vue'
import VPHomeFeatures from './VPHomeFeatures.vue'
import VPHomeContent from './VPHomeContent.vue'
import { useData } from '../composables/data'
import VPHomeContent from './VPHomeContent.vue'
import VPHomeFeatures from './VPHomeFeatures.vue'
import VPHomeHero from './VPHomeHero.vue'
const { frontmatter, theme } = useData()
</script>

@ -1,8 +1,8 @@
<script lang="ts" setup generic="T extends DefaultTheme.NavItemWithLink">
import type { DefaultTheme } from 'vitepress/theme'
import { computed } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { useData } from '../composables/data'
import VPLink from './VPLink.vue'
const props = defineProps<{

@ -1,11 +1,11 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { useData } from '../composables/data'
import { useLangs } from '../composables/langs'
import VPFlyout from './VPFlyout.vue'
import VPMenuLink from './VPMenuLink.vue'
import VPSwitchAppearance from './VPSwitchAppearance.vue'
import VPSocialLinks from './VPSocialLinks.vue'
import { useData } from '../composables/data'
import { useLangs } from '../composables/langs'
import VPSwitchAppearance from './VPSwitchAppearance.vue'
const { site, theme } = useData()
const { localeLinks, currentLang } = useLangs({ correspondingLink: true })

@ -1,7 +1,7 @@
<script lang="ts" setup>
import { useData } from '../composables/data'
import VPNavBarMenuLink from './VPNavBarMenuLink.vue'
import VPNavBarMenuGroup from './VPNavBarMenuGroup.vue'
import VPNavBarMenuLink from './VPNavBarMenuLink.vue'
const { theme } = useData()
</script>

@ -1,8 +1,8 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { computed } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { useData } from '../composables/data'
import VPFlyout from './VPFlyout.vue'
const props = defineProps<{

@ -1,8 +1,8 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { computed } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { useData } from '../composables/data'
import VPLink from './VPLink.vue'
const props = defineProps<{

@ -1,8 +1,8 @@
<script lang="ts" setup>
import VPFlyout from './VPFlyout.vue'
import VPMenuLink from './VPMenuLink.vue'
import { useData } from '../composables/data'
import { useLangs } from '../composables/langs'
import VPFlyout from './VPFlyout.vue'
import VPMenuLink from './VPMenuLink.vue'
const { theme } = useData()
const { localeLinks, currentLang } = useLangs({ correspondingLink: true })

@ -1,7 +1,7 @@
<script lang="ts" setup>
import { useData } from '../composables/data'
import VPNavScreenMenuLink from './VPNavScreenMenuLink.vue'
import VPNavScreenMenuGroup from './VPNavScreenMenuGroup.vue'
import VPNavScreenMenuLink from './VPNavScreenMenuLink.vue'
const { theme } = useData()
</script>

@ -1,8 +1,8 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { computed, inject } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { useData } from '../composables/data'
import { navInjectionKey } from '../composables/nav'
import VPLink from './VPLink.vue'

@ -1,8 +1,8 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { computed, inject } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { useData } from '../composables/data'
import { navInjectionKey } from '../composables/nav'
import VPLink from './VPLink.vue'

@ -1,6 +1,6 @@
<script lang="ts" setup>
import { ref, watch } from 'vue'
import { useRoute } from 'vitepress'
import { ref, watch } from 'vue'
import { useData } from '../composables/data'
const { theme } = useData()

@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { GridSize } from '../composables/sponsor-grid'
import type { Sponsor } from './VPSponsorsGrid.vue'
import { computed } from 'vue'
import VPSponsorsGrid from './VPSponsorsGrid.vue'
export interface Sponsors {

@ -1,6 +1,6 @@
<script setup lang="ts">
import type { GridSize } from '../composables/sponsor-grid'
import { ref } from 'vue'
import type { GridSize } from '../composables/sponsor-grid'
import { useSponsorsGrid } from '../composables/sponsor-grid'
export interface Sponsor {

@ -1,6 +1,6 @@
import { getIconsCSS } from '@iconify/utils'
import fs from 'fs-extra'
import { createHash } from 'node:crypto'
import fs from 'node:fs'
import { createRequire } from 'node:module'
import path from 'node:path'
import pMap from 'p-map'
@ -154,9 +154,9 @@ export async function build(
// emit page hash map for the case where a user session is open
// when the site got redeployed (which invalidates current hash map)
fs.writeJSONSync(
fs.writeFileSync(
path.join(siteConfig.outDir, 'hashmap.json'),
pageToHashMap
JSON.stringify(pageToHashMap)
)
} finally {
unlinkVue()
@ -185,7 +185,8 @@ function linkVue() {
// if user did not install vue by themselves, link VitePress' version
if (!fs.existsSync(dest)) {
const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
fs.ensureSymlinkSync(src, dest, 'junction')
fs.mkdirSync(path.dirname(dest), { recursive: true })
fs.symlinkSync(src, dest, 'junction')
return () => {
fs.unlinkSync(dest)
}
@ -233,7 +234,7 @@ function generateMetadataScript(
const resolvedMetadataFile = path.join(config.outDir, metadataFile)
const metadataFileURL = slash(`${config.site.base}${metadataFile}`)
fs.ensureDirSync(path.dirname(resolvedMetadataFile))
fs.mkdirSync(path.dirname(resolvedMetadataFile), { recursive: true })
fs.writeFileSync(resolvedMetadataFile, metadataContent)
return {

@ -1,4 +1,4 @@
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import {
@ -202,14 +202,19 @@ export async function bundle(
if (!chunk.fileName.endsWith('.js')) {
const tempPath = path.resolve(config.tempDir, chunk.fileName)
const outPath = path.resolve(config.outDir, chunk.fileName)
await fs.copy(tempPath, outPath)
await fs.promises.cp(tempPath, outPath)
}
})
)
// also copy over public dir
const publicDir = path.resolve(config.srcDir, 'public')
if (fs.existsSync(publicDir)) {
await fs.copy(publicDir, config.outDir)
// dereference symlinks like vite's own publicDir copy does, and so that
// copying over an existing symlinked file does not fail with EEXIST
await fs.promises.cp(publicDir, config.outDir, {
recursive: true,
dereference: true
})
}
// build <script client> bundle
if (Object.keys(clientJSMap).length) {

@ -1,5 +1,5 @@
import fs from 'fs-extra'
import matter from 'gray-matter'
import fs from 'node:fs'
import path from 'node:path'
import {
SitemapStream,

@ -1,5 +1,5 @@
import { isBooleanAttr } from '@vue/shared'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import { minify, normalizePath, type Rolldown } from 'vite'
import { version } from '../../../package.json'
@ -146,7 +146,9 @@ export async function renderPage(
if (matchingChunk) {
if (!matchingChunk.code.includes('import')) {
inlinedScript = `<script type="module">${matchingChunk.code}</script>`
fs.removeSync(path.resolve(config.outDir, matchingChunk.fileName))
fs.rmSync(path.resolve(config.outDir, matchingChunk.fileName), {
force: true
})
} else {
inlinedScript = `<script type="module" src="${siteData.base}${matchingChunk.fileName}"></script>`
}
@ -189,7 +191,7 @@ export async function renderPage(
</html>`
const htmlFileName = path.join(config.outDir, page.replace(/\.md$/, '.html'))
await fs.ensureDir(path.dirname(htmlFileName))
await fs.promises.mkdir(path.dirname(htmlFileName), { recursive: true })
const transformedHtml = await config.transformHtml?.(html, htmlFileName, {
page,
siteConfig: config,
@ -201,7 +203,7 @@ export async function renderPage(
content,
assets
})
await fs.writeFile(htmlFileName, transformedHtml || html)
await fs.promises.writeFile(htmlFileName, transformedHtml || html)
}
function resolvePageImports(

@ -1,6 +1,6 @@
import { createDebug } from 'obug'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import { createDebug } from 'obug'
import c from 'picocolors'
import {
createLogger,
@ -12,6 +12,7 @@ import {
} from 'vite'
import { DEFAULT_THEME_PATH } from './alias'
import type { DefaultTheme } from './defaultTheme'
import type { MarkdownOptions } from './markdown/markdown'
import { resolvePages } from './plugins/dynamicRoutesPlugin'
import {
APPEARANCE_KEY,
@ -23,7 +24,6 @@ import {
type HeadConfig,
type SiteData
} from './shared'
import type { MarkdownOptions } from './markdown/markdown'
import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig'
import { glob } from './utils/glob'
@ -124,7 +124,7 @@ export async function resolveConfig(
// resolve theme path
const userThemeDir = resolve(root, 'theme')
const themeDir = (await fs.pathExists(userThemeDir))
const themeDir = fs.existsSync(userThemeDir)
? userThemeDir
: DEFAULT_THEME_PATH
@ -240,7 +240,7 @@ export async function resolveUserConfig(
resolve(root, `config/index.${ext}`),
resolve(root, `config.${ext}`)
])
.find(fs.pathExistsSync)
.find(fs.existsSync)
let userConfig: RawConfigExports = {}
let configDeps: string[] = []

@ -1,5 +1,5 @@
import fs from 'fs-extra'
import matter from 'gray-matter'
import fs from 'node:fs'
import path from 'node:path'
import pMap from 'p-map'
import { normalizePath } from 'vite'

@ -7,8 +7,8 @@ import {
select,
text
} from '@clack/prompts'
import fs from 'fs-extra'
import template from 'lodash.template'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import c from 'picocolors'
@ -200,7 +200,8 @@ export function scaffold({
const content = fs.readFileSync(filePath, 'utf-8')
const compiled = template(content)(data)
fs.outputFileSync(targetPath, compiled)
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
fs.writeFileSync(targetPath, compiled)
}
const filesToScaffold = [

@ -1,6 +1,6 @@
import fs from 'fs-extra'
import type { MarkdownItAsync } from 'markdown-it-async'
import type { RuleBlock } from 'markdown-it/lib/parser_block.mjs'
import fs from 'node:fs'
import path from 'node:path'
import type { MarkdownEnv } from '../../shared'

@ -1,8 +1,8 @@
import { resolveTitleFromToken } from '@mdit-vue/shared'
import { createDebug } from 'obug'
import fs from 'fs-extra'
import { LRUCache } from 'lru-cache'
import fs from 'node:fs'
import path from 'node:path'
import { createDebug } from 'obug'
import type { SiteConfig } from './config'
import {
createMarkdownRenderer,

@ -1,4 +1,4 @@
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import c from 'picocolors'
import pm from 'picomatch'

@ -1,7 +1,7 @@
import { createDebug } from 'obug'
import fs from 'fs-extra'
import MiniSearch from 'minisearch'
import fs from 'node:fs'
import path from 'node:path'
import { createDebug } from 'obug'
import type { Plugin, ViteDevServer } from 'vite'
import type { SiteConfig } from '../config'
import type { DefaultTheme } from '../defaultTheme'

@ -1,5 +1,5 @@
import compression from '@polka/compression'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import polka, { type IOptions } from 'polka'
import sirv from 'sirv'

@ -2,6 +2,10 @@ import type { Options as VuePluginOptions } from '@vitejs/plugin-vue'
import type { UseDarkOptions } from '@vueuse/core'
import type { SitemapStreamOptions } from 'sitemap'
import type { Logger, UserConfig as ViteConfig } from 'vite'
import type {
AdditionalConfigDict,
AdditionalConfigLoader
} from '../../types/shared'
import type { SitemapItem } from './build/generateSitemap'
import type { MarkdownOptions } from './markdown/markdown'
import type { ResolvedRouteConfig } from './plugins/dynamicRoutesPlugin'
@ -14,10 +18,6 @@ import type {
SSGContext,
SiteData
} from './shared'
import type {
AdditionalConfigDict,
AdditionalConfigLoader
} from '../../types/shared'
export type RawConfigExports<ThemeConfig = any> =
| Awaitable<UserConfig<ThemeConfig>>

@ -1,8 +1,8 @@
import { spawn, sync } from 'cross-spawn'
import { createDebug } from 'obug'
import fs from 'node:fs'
import path from 'node:path'
import { Transform, type TransformCallback } from 'node:stream'
import { createDebug } from 'obug'
import { slash } from '../shared'
const debug = createDebug('vitepress:git')

@ -6,6 +6,9 @@ import type {
} from '../../types/shared'
export type {
AdditionalConfig,
AdditionalConfigDict,
AdditionalConfigLoader,
Awaitable,
DefaultTheme,
HeadConfig,
@ -16,11 +19,8 @@ export type {
PageData,
PageDataPayload,
SiteData,
VitePressData,
SSGContext,
AdditionalConfig,
AdditionalConfigDict,
AdditionalConfigLoader
VitePressData
} from '../../types/shared'
export const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i

Loading…
Cancel
Save