strip changes from #3385

pull/3386/head
Yuxuan Zhang 2 years ago
parent 5493202cb2
commit 1dd35b2226
No known key found for this signature in database
GPG Key ID: 6910B04F3351EF7D

@ -138,7 +138,6 @@
"@types/debug": "^4.1.12", "@types/debug": "^4.1.12",
"@types/escape-html": "^1.0.4", "@types/escape-html": "^1.0.4",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/humanize-duration": "^3.27.3",
"@types/jsdom": "^21.1.6", "@types/jsdom": "^21.1.6",
"@types/lodash.template": "^4.5.3", "@types/lodash.template": "^4.5.3",
"@types/mark.js": "^8.11.12", "@types/mark.js": "^8.11.12",
@ -164,7 +163,6 @@
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"get-port": "^7.0.0", "get-port": "^7.0.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"humanize-duration": "^3.31.0",
"lint-staged": "^15.2.0", "lint-staged": "^15.2.0",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"lru-cache": "^10.1.0", "lru-cache": "^10.1.0",

@ -114,9 +114,6 @@ importers:
'@types/fs-extra': '@types/fs-extra':
specifier: ^11.0.4 specifier: ^11.0.4
version: 11.0.4 version: 11.0.4
'@types/humanize-duration':
specifier: ^3.27.3
version: 3.27.3
'@types/jsdom': '@types/jsdom':
specifier: ^21.1.6 specifier: ^21.1.6
version: 21.1.6 version: 21.1.6
@ -192,9 +189,6 @@ importers:
gray-matter: gray-matter:
specifier: ^4.0.3 specifier: ^4.0.3
version: 4.0.3 version: 4.0.3
humanize-duration:
specifier: ^3.31.0
version: 3.31.0
lint-staged: lint-staged:
specifier: ^15.2.0 specifier: ^15.2.0
version: 15.2.0(supports-color@9.4.0) version: 15.2.0(supports-color@9.4.0)
@ -1160,10 +1154,6 @@ packages:
resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==} resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==}
dev: true dev: true
/@types/humanize-duration@3.27.3:
resolution: {integrity: sha512-wiiiFYjnrYDJE/ujU7wS/NShqp12IKrejozjDtcejP0zYi+cjyjVcfZHwcFUDKVJ7tHGsmgeW2ED92ABIIjfpg==}
dev: true
/@types/jquery@3.5.29: /@types/jquery@3.5.29:
resolution: {integrity: sha512-oXQQC9X9MOPRrMhPHHOsXqeQDnWeCDT3PelUIg/Oy8FAbzSZtFHRjc7IpbfFVmpLtJ+UOoywpRsuO5Jxjybyeg==} resolution: {integrity: sha512-oXQQC9X9MOPRrMhPHHOsXqeQDnWeCDT3PelUIg/Oy8FAbzSZtFHRjc7IpbfFVmpLtJ+UOoywpRsuO5Jxjybyeg==}
dependencies: dependencies:
@ -2803,10 +2793,6 @@ packages:
engines: {node: '>=16.17.0'} engines: {node: '>=16.17.0'}
dev: true dev: true
/humanize-duration@3.31.0:
resolution: {integrity: sha512-fRrehgBG26NNZysRlTq1S+HPtDpp3u+Jzdc/d5A4cEzOD86YLAkDaJyJg8krSdCi7CJ+s7ht3fwRj8Dl+Btd0w==}
dev: true
/iconv-lite@0.6.3: /iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}

@ -74,16 +74,16 @@ export async function build(
} }
try { try {
const { clientResult, serverResult, pageToHashMap } = await task( const { clientResult, serverResult, pageToHashMap } = await bundle(
'building client + server bundles', siteConfig,
() => bundle(siteConfig, buildOptions) buildOptions
) )
if (process.env.BUNDLE_ONLY) { if (process.env.BUNDLE_ONLY) {
return return
} }
await task('rendering pages', async (updateProgress) => { await task('rendering pages', async () => {
const renderEntry = const renderEntry =
pathToFileURL(path.join(siteConfig.tempDir, 'app.js')).toString() + pathToFileURL(path.join(siteConfig.tempDir, 'app.js')).toString() +
'?t=' + '?t=' +
@ -165,14 +165,9 @@ export async function build(
} }
const pages = ['404.md', ...siteConfig.pages] const pages = ['404.md', ...siteConfig.pages]
let count_done = 0 await pMap(pages, task, {
await pMap( concurrency: siteConfig.concurrency
pages, })
(page) => task(page).then(updateProgress(++count_done, pages.length)),
{
concurrency: siteConfig.concurrency
}
)
}) })
// emit page hash map for the case where a user session is open // emit page hash map for the case where a user session is open

@ -17,7 +17,6 @@ import {
type Awaitable type Awaitable
} from '../shared' } from '../shared'
import { processIncludes } from '../utils/processIncludes' import { processIncludes } from '../utils/processIncludes'
import { updateCurrentTask, clearLine } from '../utils/task'
import type { PageSplitSection } from '../../../types/local-search' import type { PageSplitSection } from '../../../types/local-search'
const debug = _debug('vitepress:local-search') const debug = _debug('vitepress:local-search')
@ -176,12 +175,10 @@ export async function localSearchPlugin(
} }
async function indexLocale(locale: string) { async function indexLocale(locale: string) {
let numIndexed = 0
const update = () =>
updateCurrentTask(++numIndexed, files.length, `🔍️ indexing ${locale}`)
const files = [...filesByLocale.get(locale)!] const files = [...filesByLocale.get(locale)!]
const task = (f: string) => indexFile(f, parallel).then(update) await pMap(files, (f) => indexFile(f, parallel), {
await pMap(files, task, { concurrency: siteConfig.concurrency }) concurrency: siteConfig.concurrency
})
} }
const parallel = shouldUseParallel(siteConfig, 'local-search') const parallel = shouldUseParallel(siteConfig, 'local-search')
@ -264,7 +261,7 @@ async function* splitPageIntoSections(
// Skip duplicate id, content will be treated as normal text // Skip duplicate id, content will be treated as normal text
if (existingIdSet.has(id)) { if (existingIdSet.has(id)) {
console.error( console.error(
`${clearLine}⚠️ Duplicate heading id "${id}" in ${pageName}` `\x1b[2K\r ⚠️ Duplicate heading id "${id}" in ${pageName}`
) )
continue continue
} }

@ -1,80 +1,18 @@
import ora from 'ora' import ora from 'ora'
import humanizeDuration from 'humanize-duration'
import c from 'picocolors'
import { workerMeta } from '../worker'
export const okMark = c.green('✓') export const okMark = '\x1b[32m✓\x1b[0m'
export const failMark = c.red('✖') export const failMark = '\x1b[31m✖\x1b[0m'
export const clearLine = '\x1b[2K\r'
export type UpdateHandle = (
done?: number,
total?: number,
subtask?: string
) => any
let updateHandle: UpdateHandle | null = null
export const updateCurrentTask: UpdateHandle = (...args) => {
if (workerMeta) workerMeta.updateCurrentTask(...args)
else if (updateHandle) updateHandle(...args)
else if (!process.stderr.isTTY) {
return
} else if (args.length === 0) {
process.stderr.write(clearLine)
} else {
const name = args[2] || 'unknown task'
process.stderr.write(
`${clearLine}${name} [${args.slice(0, 2).join(' / ')}]`
)
}
}
export async function task<T>(
taskName: string,
task: (update: UpdateHandle) => Promise<T>
): Promise<T> {
if (workerMeta) {
let retVal: T
await workerMeta.task(taskName, async (handle: UpdateHandle) => {
retVal = await task(handle)
})
return retVal!
}
export async function task(taskName: string, task: () => Promise<void>) {
const spinner = ora({ discardStdin: false }) const spinner = ora({ discardStdin: false })
spinner.start(taskName + '...') spinner.start(taskName + '...')
updateHandle = (done, total, subtask) => {
const taskFullName = subtask ? `${taskName} - ${subtask}` : taskName
if (done === undefined) {
spinner.text = taskFullName + '...'
} else if (total === undefined) {
spinner.text = `${taskFullName} [ ${done} ]`
} else {
// match length to display them in same width
const _total = `${total}`
const _done = `${done}`.padStart(_total.length, ' ')
spinner.text = `${taskFullName} [ ${_done} / ${_total} ]`
}
}
const timeStart = performance.now()
let success = true
try { try {
return await task(updateHandle) await task()
} catch (e) { } catch (e) {
success = false spinner.stopAndPersist({ symbol: failMark })
throw e throw e
} finally {
updateHandle = null
const timeEnd = performance.now()
const duration = humanizeDuration(timeEnd - timeStart, {
maxDecimalPoints: 2
})
const text = `${taskName} - ${duration}`
const symbol = success ? okMark : failMark
spinner.stopAndPersist({ symbol, text })
} }
spinner.stopAndPersist({ symbol: okMark })
} }

@ -3,7 +3,6 @@ import RPCContext, {
deferPromise, deferPromise,
type RPCContextOptions type RPCContextOptions
} from 'rpc-magic-proxy' } from 'rpc-magic-proxy'
import { task, updateCurrentTask } from './utils/task'
import c from 'picocolors' import c from 'picocolors'
import Queue from './utils/queue' import Queue from './utils/queue'
import _debug from 'debug' import _debug from 'debug'
@ -83,9 +82,7 @@ export async function launchWorkers(numWorkers: number, context: Object) {
workerId, workerId,
dispatchWork, dispatchWork,
// Save some RPC overhead when debugger is not active // Save some RPC overhead when debugger is not active
debug: debug.enabled ? debug : null, debug: debug.enabled ? debug : null
task,
updateCurrentTask
}, },
initWorkerHooks, initWorkerHooks,
getNextTask, getNextTask,
@ -137,8 +134,6 @@ export let workerMeta: {
workerId: string workerId: string
dispatchWork: typeof dispatchWork dispatchWork: typeof dispatchWork
debug: typeof debug debug: typeof debug
task: typeof task
updateCurrentTask: typeof updateCurrentTask
} | null = null } | null = null
const registry: Map<string, { main: Function; init?: Function }> = new Map() const registry: Map<string, { main: Function; init?: Function }> = new Map()

Loading…
Cancel
Save