Skip to content

Commit c3a24c0

Browse files
committed
feat!: migrate cli to full ESM
1 parent 7d69362 commit c3a24c0

File tree

14 files changed

+39
-32
lines changed

14 files changed

+39
-32
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// Auto fix
1818
"editor.codeActionsOnSave": {
19-
"source.fixAll.eslint": true,
19+
"source.fixAll.eslint": "explicit",
2020
"source.organizeImports": false
2121
},
2222

packages/client/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"url": "https://github.com/slidevjs/slidev"
1212
},
1313
"bugs": "https://github.com/slidevjs/slidev/issues",
14+
"exports": {
15+
"./package.json": "./package.json",
16+
"./*": "./*"
17+
},
1418
"engines": {
1519
"node": ">=18.0.0"
1620
},

packages/slidev/bin/slidev.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/slidev/bin/slidev.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
import ('../dist/cli.mjs')

packages/slidev/node/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ injectPreparserExtensionLoader(async (headmatter?: Record<string, unknown>, file
4646
return await loadSetups(roots, 'preparser.ts', { filepath, headmatter }, [], mergeArrays)
4747
})
4848

49-
const cli = yargs
49+
const cli = yargs(process.argv.slice(2))
5050
.scriptName('slidev')
5151
.usage('$0 [args]')
5252
.version(version)

packages/slidev/node/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { dirname, join, resolve } from 'node:path'
22
import process from 'node:process'
3+
import { fileURLToPath } from 'node:url'
34
import type Vue from '@vitejs/plugin-vue'
45
import type VueJsx from '@vitejs/plugin-vue-jsx'
56
import type Icons from 'unplugin-icons/vite'
@@ -19,6 +20,7 @@ import { getThemeMeta, promptForThemeInstallation, resolveThemeName } from './th
1920
import { getAddons } from './addons'
2021

2122
const debug = _debug('slidev:options')
23+
const __dirname = dirname(fileURLToPath(import.meta.url))
2224

2325
export interface SlidevEntryOptions {
2426
/**

packages/slidev/node/plugins/loaders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'node:process'
33
import type { Connect, ModuleNode, Plugin, Update, ViteDevServer } from 'vite'
44
import { isString, notNullish, objectMap, range, slash, uniq } from '@antfu/utils'
55
import fg from 'fast-glob'
6-
import fs, { existsSync } from 'fs-extra'
6+
import fs from 'fs-extra'
77
import Markdown from 'markdown-it'
88
import { bold, gray, red, yellow } from 'kolorist'
99

@@ -552,7 +552,7 @@ defineProps<{ no: number | string }>()`)
552552
]
553553

554554
for (const style of styles) {
555-
if (existsSync(style)) {
555+
if (fs.existsSync(style)) {
556556
imports.push(`import "${toAtFS(style)}"`)
557557
continue
558558
}

packages/slidev/node/plugins/markdown-it-prism.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// forked from https://github.com/jGleitz/markdown-it-prism
22
// it's modified to output line wrapper `<div class="line" />` for each line
33

4+
import { createRequire } from 'node:module'
45
import type { Grammar } from 'prismjs'
56
import Prism from 'prismjs'
6-
import loadLanguages from 'prismjs/components/'
7+
import loadLanguages from 'prismjs/components/index.js'
78
import type MarkdownIt from 'markdown-it'
89
import * as htmlparser2 from 'htmlparser2'
910
import { escapeVueInCode } from './markdown'
1011

12+
const require = createRequire(import.meta.url)
13+
1114
interface Options {
1215
plugins: string[]
1316
/**
@@ -90,7 +93,6 @@ function loadPrismLang(lang: string): Grammar | undefined {
9093
*/
9194
function loadPrismPlugin(name: string): void {
9295
try {
93-
// eslint-disable-next-line ts/no-require-imports
9496
require(`prismjs/plugins/${name}/prism-${name}`)
9597
}
9698
catch (e) {

packages/slidev/node/plugins/setupNode.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolve } from 'node:path'
2-
import { pathExists } from 'fs-extra'
2+
import { fileURLToPath } from 'node:url'
3+
import fs from 'fs-extra'
34
import { isObject } from '@antfu/utils'
45
import jiti from 'jiti'
56

@@ -26,8 +27,8 @@ export async function loadSetups<T, R extends object>(
2627
let returns = initial
2728
for (const root of roots) {
2829
const path = resolve(root, 'setup', name)
29-
if (await pathExists(path)) {
30-
const { default: setup } = jiti(__filename)(path)
30+
if (await fs.pathExists(path)) {
31+
const { default: setup } = jiti(fileURLToPath(import.meta.url))(path)
3132
const result = await setup(arg)
3233
if (result !== null) {
3334
returns = typeof merge === 'function'

packages/slidev/node/plugins/unocss.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolve } from 'node:path'
22
import { existsSync } from 'node:fs'
3+
import { fileURLToPath } from 'node:url'
34
import { uniq } from '@antfu/utils'
45
import type { Theme } from '@unocss/preset-uno'
56
import type { UserConfig } from '@unocss/core'
@@ -26,7 +27,7 @@ export async function createUnocssPlugin(
2627

2728
const configs = configFiles
2829
.map((i) => {
29-
const loaded = jiti(__filename)(i)
30+
const loaded = jiti(fileURLToPath(import.meta.url))(i)
3031
const config = 'default' in loaded ? loaded.default : loaded
3132
return config
3233
})

0 commit comments

Comments
 (0)