Skip to content

Commit 4a6578d

Browse files
committedSep 27, 2024··
feat: update deps, use jiti v2
1 parent 3a3cf6a commit 4a6578d

File tree

9 files changed

+429
-864
lines changed

9 files changed

+429
-864
lines changed
 

Diff for: ‎packages/client/setup/context-menu.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { ContextMenuItem } from '@slidev/types'
21
/// <reference types="unplugin-icons/types/vue3" />
2+
3+
import type { ContextMenuItem } from '@slidev/types'
34
import type { ComputedRef } from 'vue'
45
import setups from '#slidev/setups/context-menu'
56
import IconApps from '~icons/carbon/apps'
67
import IconArrowDown from '~icons/carbon/arrow-down'
78
import IconArrowLeft from '~icons/carbon/arrow-left'
89
import IconArrowRight from '~icons/carbon/arrow-right'
9-
1010
import IconArrowUp from '~icons/carbon/arrow-up'
1111
import IconMaximize from '~icons/carbon/maximize'
1212
import IconMinimize from '~icons/carbon/minimize'

Diff for: ‎packages/client/setup/monaco.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const setup = createSingletonPromise(async () => {
9292
monaco.languages.register({ id: 'typescript' })
9393
monaco.languages.register({ id: 'javascript' })
9494

95-
const { shiki, langs, themes, shikiToMonaco } = await import('#slidev/shiki')
95+
const { shiki, languages, themes, shikiToMonaco } = await import('#slidev/shiki')
9696
const highlighter = await shiki
9797

9898
const editorOptions: MonacoSetupReturn['editorOptions'] & object = {}
@@ -114,7 +114,7 @@ const setup = createSingletonPromise(async () => {
114114
})
115115
}
116116
// Register all languages, otherwise Monaco will not highlight them
117-
for (const lang of langs) {
117+
for (const lang of languages) {
118118
monaco.languages.register({ id: lang })
119119
}
120120

Diff for: ‎packages/slidev/node/cli.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const CONFIG_RESTART_FIELDS: (keyof SlidevConfig)[] = [
3535
/**
3636
* Files that triggers a restart when added or removed
3737
*/
38-
const FILES_CREATE_RESTART_GLOBS = [
38+
const FILES_CREATE_RESTART = [
3939
'global-bottom.vue',
4040
'global-top.vue',
4141
'uno.config.js',
@@ -44,7 +44,7 @@ const FILES_CREATE_RESTART_GLOBS = [
4444
'unocss.config.ts',
4545
]
4646

47-
const FILES_CHANGE_RESTART_GLOBS = [
47+
const FILES_CHANGE_RESTART = [
4848
'setup/shiki.ts',
4949
'setup/katex.ts',
5050
'setup/preparser.ts',
@@ -298,8 +298,8 @@ cli.command(
298298
// Start watcher to restart server on file changes
299299
const { watch } = await import('chokidar')
300300
const watcher = watch([
301-
...FILES_CREATE_RESTART_GLOBS,
302-
...FILES_CHANGE_RESTART_GLOBS,
301+
...FILES_CREATE_RESTART,
302+
...FILES_CHANGE_RESTART,
303303
], {
304304
ignored: ['node_modules', '.git'],
305305
ignoreInitial: true,
@@ -313,7 +313,7 @@ cli.command(
313313
restartServer()
314314
})
315315
watcher.on('change', (file) => {
316-
if (FILES_CREATE_RESTART_GLOBS.includes(file))
316+
if (FILES_CREATE_RESTART.includes(file))
317317
return
318318
console.log(yellow(`\n file ${file} changed, restarting...\n`))
319319
restartServer()

Diff for: ‎packages/slidev/node/setups/load.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Awaitable } from '@antfu/utils'
12
import { resolve } from 'node:path'
23
import { deepMergeWithArray } from '@antfu/utils'
34
import fs from 'fs-extra'
@@ -7,19 +8,19 @@ export async function loadSetups<F extends (...args: any) => any>(
78
roots: string[],
89
filename: string,
910
args: Parameters<F>,
10-
extraLoader?: (root: string) => Awaited<ReturnType<F>>[],
11+
extraLoader?: (root: string) => Awaitable<Awaited<ReturnType<F>>[]>,
1112
) {
1213
const returns: Awaited<ReturnType<F>>[] = []
1314
for (const root of roots) {
1415
const path = resolve(root, 'setup', filename)
1516
if (fs.existsSync(path)) {
16-
const { default: setup } = loadModule(path)
17+
const { default: setup } = await loadModule(path) as { default: F }
1718
const ret = await setup(...args)
1819
if (ret)
1920
returns.push(ret)
2021
}
2122
if (extraLoader)
22-
returns.push(...extraLoader(root))
23+
returns.push(...await extraLoader(root))
2324
}
2425
return returns
2526
}

Diff for: ‎packages/slidev/node/setups/unocss.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ import { loadModule } from '../utils'
1010
export default async function setupUnocss(
1111
{ clientRoot, roots, data, utils }: ResolvedSlidevOptions,
1212
) {
13-
function loadFileConfigs(root: string): UserConfig<Theme>[] {
14-
return [
15-
resolve(root, 'uno.config.ts'),
16-
resolve(root, 'unocss.config.ts'),
17-
].map((i) => {
18-
if (!existsSync(i))
19-
return undefined
20-
const loaded = loadModule(i)
21-
return 'default' in loaded ? loaded.default : loaded
22-
})
13+
async function loadFileConfigs(root: string): Promise<UserConfig<Theme>[]> {
14+
return (await Promise
15+
.all([
16+
resolve(root, 'uno.config.ts'),
17+
resolve(root, 'unocss.config.ts'),
18+
]
19+
.map(async (i) => {
20+
if (!existsSync(i))
21+
return undefined
22+
const loaded = await loadModule(i) as UserConfig<Theme> | { default: UserConfig<Theme> }
23+
return 'default' in loaded ? loaded.default : loaded
24+
})))
25+
.filter(x => !!x)
2326
}
2427

2528
const configs = [
@@ -35,7 +38,7 @@ export default async function setupUnocss(
3538
}),
3639
],
3740
},
38-
...loadFileConfigs(clientRoot),
41+
...await loadFileConfigs(clientRoot),
3942
...await loadSetups<UnoSetup>(roots, 'unocss.ts', [], loadFileConfigs),
4043
].filter(Boolean) as UserConfig<Theme>[]
4144

Diff for: ‎packages/slidev/node/utils.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { ResolvedFontOptions, SlideInfo } from '@slidev/types'
2-
import type { JITI } from 'jiti'
32
import type { Token } from 'markdown-it'
43
import type { Connect } from 'vite'
54
import { fileURLToPath } from 'node:url'
6-
import createJiti from 'jiti'
5+
import { createJiti } from 'jiti'
76
import YAML from 'yaml'
87

9-
let jiti: JITI | undefined
10-
export function loadModule(absolutePath: string) {
8+
type Jiti = ReturnType<typeof createJiti>
9+
let jiti: Jiti | undefined
10+
export function loadModule<T = unknown>(absolutePath: string): Promise<T> {
1111
jiti ??= createJiti(fileURLToPath(import.meta.url))
12-
return jiti(absolutePath)
12+
return jiti.import(absolutePath) as Promise<T>
1313
}
1414

1515
export function stringifyMarkdownTokens(tokens: Token[]) {

Diff for: ‎packages/types/client.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ declare module '#slidev/shiki' {
4646

4747
export { shikiToMonaco } from '@shikijs/monaco'
4848

49-
export const langs: BundledLanguage[]
49+
export const languages: BundledLanguage[]
5050
export const themes: BundledTheme | Record<string, BundledTheme>
5151
export const shiki: Promise<ShikiHighlighterCore>
5252
export function getHighlighter(): Promise<(code: string, lang: string, options?: Partial<CodeToHastOptions>) => string>

0 commit comments

Comments
 (0)
Please sign in to comment.