Skip to content

Commit f5d5411

Browse files
committed
fix: build error blocked by cjs
1 parent 01c2bfa commit f5d5411

File tree

4 files changed

+840
-559
lines changed

4 files changed

+840
-559
lines changed

.vitepress/rewrite-title/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const path = require('path')
2-
const fsp = require('fs').promises
3-
const matterService = require('../utils/frontmatter-service')
1+
import path from 'node:path'
2+
import fsp from 'node:fs/promises'
3+
import matterService from '../utils/frontmatter-service.js'
4+
import { fileURLToPath } from 'node:url'
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
46
const workspacePath = path.resolve(__dirname, '..', '..')
57

68
const h1MdRegExp = /^#\s+(.+)\s+(\{#([\w-]+)\})$/
@@ -41,4 +43,4 @@ const ergodicDirectory = async (dirPath) => {
4143
}
4244
}
4345

44-
module.exports = () => ergodicDirectory(workspacePath)
46+
export default () => ergodicDirectory(workspacePath)

.vitepress/utils/frontmatter-service.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const fs = require('fs')
2-
const matter = require('gray-matter')
3-
const { extend, isEmpty: _isEmpty } = require('lodash')
1+
import fs from 'node:fs'
2+
import matter from 'gray-matter'
3+
import _ from 'lodash'
4+
45
// gray-matter is a dep for vitepress,
56
// no need to specify that in package.json
67

@@ -21,7 +22,7 @@ class FrontMatterService {
2122
}
2223

2324
isEmpty() {
24-
return _isEmpty(this.matter.data)
25+
return _._isEmpty(this.matter.data)
2526
}
2627

2728
/** @param{(data: string) => void} callback */
@@ -48,7 +49,7 @@ class FrontMatterService {
4849

4950
/** @param {Record<string, any>} src */
5051
extend(src) {
51-
extend(this.matter.data, src)
52+
_.extend(this.matter.data, src)
5253
return this
5354
}
5455

@@ -63,4 +64,4 @@ class FrontMatterService {
6364
}
6465
}
6566

66-
module.exports = new FrontMatterService()
67+
export default new FrontMatterService()

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"version": "1.0.0",
44
"description": "Vite.js documentation Chinese translation.",
55
"repository": "https://github.com/vitejs/docs-cn",
6+
"type": "module",
67
"author": "Evan You",
78
"private": true,
89
"license": "CC BY-NC-SA 4.0",
910
"devDependencies": {
10-
"chalk": "^4.1.0",
11+
"chalk": "^4.1.2",
1112
"gray-matter": "^4.0.3",
1213
"lodash": "^4.17.21",
13-
"vite": "^2.9.12",
14-
"vitepress": "^1.0.0-alpha.43",
14+
"vite": "^4.5.0",
15+
"vitepress": "^1.0.0-rc.29",
1516
"yorkie": "^2.0.0"
1617
},
1718
"scripts": {

0 commit comments

Comments
 (0)