@slidev/client 0.49.0-beta.3 → 0.49.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.ts +3 -0
- package/package.json +8 -8
- package/setup/code-runners.ts +14 -25
package/constants.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.49.0-beta.
|
|
4
|
+
"version": "0.49.0-beta.4",
|
|
5
5
|
"description": "Presentation slides for developers",
|
|
6
6
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@slidev/rough-notation": "^0.1.0",
|
|
38
38
|
"@typescript/ata": "^0.9.4",
|
|
39
39
|
"@unhead/vue": "^1.9.5",
|
|
40
|
-
"@unocss/reset": "^0.59.
|
|
40
|
+
"@unocss/reset": "^0.59.3",
|
|
41
41
|
"@vueuse/core": "^10.9.0",
|
|
42
42
|
"@vueuse/math": "^10.9.0",
|
|
43
43
|
"@vueuse/motion": "^2.1.0",
|
|
@@ -53,17 +53,17 @@
|
|
|
53
53
|
"prettier": "^3.2.5",
|
|
54
54
|
"recordrtc": "^5.6.2",
|
|
55
55
|
"shiki": "^1.3.0",
|
|
56
|
-
"shiki-magic-move": "^0.3.
|
|
56
|
+
"shiki-magic-move": "^0.3.6",
|
|
57
57
|
"typescript": "^5.4.5",
|
|
58
|
-
"unocss": "^0.59.
|
|
59
|
-
"vue": "^3.4.
|
|
58
|
+
"unocss": "^0.59.3",
|
|
59
|
+
"vue": "^3.4.22",
|
|
60
60
|
"vue-demi": "^0.14.7",
|
|
61
61
|
"vue-router": "^4.3.0",
|
|
62
62
|
"yaml": "^2.4.1",
|
|
63
|
-
"@slidev/parser": "0.49.0-beta.
|
|
64
|
-
"@slidev/types": "0.49.0-beta.
|
|
63
|
+
"@slidev/parser": "0.49.0-beta.4",
|
|
64
|
+
"@slidev/types": "0.49.0-beta.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"vite": "^5.2.
|
|
67
|
+
"vite": "^5.2.9"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/setup/code-runners.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createSingletonPromise
|
|
2
|
-
import type { CodeRunner,
|
|
1
|
+
import { createSingletonPromise } from '@antfu/utils'
|
|
2
|
+
import type { CodeRunner, CodeRunnerOutput, CodeRunnerOutputText, CodeRunnerOutputs } from '@slidev/types'
|
|
3
3
|
import type { CodeToHastOptions } from 'shiki'
|
|
4
4
|
import type ts from 'typescript'
|
|
5
5
|
import { isDark } from '../logic/dark'
|
|
6
|
+
import deps from '#slidev/monaco-run-deps'
|
|
6
7
|
import setups from '#slidev/setups/code-runners'
|
|
7
8
|
|
|
8
9
|
export default createSingletonPromise(async () => {
|
|
@@ -25,18 +26,6 @@ export default createSingletonPromise(async () => {
|
|
|
25
26
|
...options,
|
|
26
27
|
})
|
|
27
28
|
|
|
28
|
-
const resolveId = async (specifier: string) => {
|
|
29
|
-
if (!'./'.includes(specifier[0]) && !/^(@[^\/:]+?\/)?[^\/:]+$/.test(specifier))
|
|
30
|
-
return specifier // this might be a url or something else
|
|
31
|
-
const res = await fetch(`/@slidev/resolve-id?specifier=${specifier}`)
|
|
32
|
-
if (!res.ok)
|
|
33
|
-
return null
|
|
34
|
-
const id = await res.text()
|
|
35
|
-
if (!id)
|
|
36
|
-
return null
|
|
37
|
-
return `/@fs${ensurePrefix('/', slash(id))}`
|
|
38
|
-
}
|
|
39
|
-
|
|
40
29
|
const run = async (code: string, lang: string, options: Record<string, unknown>): Promise<CodeRunnerOutputs> => {
|
|
41
30
|
try {
|
|
42
31
|
const runner = runners[lang]
|
|
@@ -47,7 +36,6 @@ export default createSingletonPromise(async () => {
|
|
|
47
36
|
{
|
|
48
37
|
options,
|
|
49
38
|
highlight,
|
|
50
|
-
resolveId,
|
|
51
39
|
run: async (code, lang) => {
|
|
52
40
|
return await run(code, lang, options)
|
|
53
41
|
},
|
|
@@ -85,16 +73,20 @@ async function runJavaScript(code: string): Promise<CodeRunnerOutputs> {
|
|
|
85
73
|
replace.clear = () => allLogs.length = 0
|
|
86
74
|
const vmConsole = Object.assign({}, console, replace)
|
|
87
75
|
try {
|
|
88
|
-
const safeJS = `return async (console) => {
|
|
89
|
-
window.console = console
|
|
76
|
+
const safeJS = `return async (console, __slidev_import) => {
|
|
90
77
|
${sanitizeJS(code)}
|
|
91
78
|
}`
|
|
92
79
|
// eslint-disable-next-line no-new-func
|
|
93
|
-
await (new Function(safeJS)())(vmConsole)
|
|
80
|
+
await (new Function(safeJS)())(vmConsole, (specifier: string) => {
|
|
81
|
+
const mod = deps[specifier]
|
|
82
|
+
if (!mod)
|
|
83
|
+
throw new Error(`Module not found: ${specifier}.\nAvailable modules: ${Object.keys(deps).join(', ')}. Please refer to https://sli.dev/custom/config-code-runners#additional-runner-dependencies`)
|
|
84
|
+
return mod
|
|
85
|
+
})
|
|
94
86
|
}
|
|
95
87
|
catch (error) {
|
|
96
88
|
return {
|
|
97
|
-
error:
|
|
89
|
+
error: String(error),
|
|
98
90
|
}
|
|
99
91
|
}
|
|
100
92
|
|
|
@@ -175,7 +167,7 @@ async function runJavaScript(code: string): Promise<CodeRunnerOutputs> {
|
|
|
175
167
|
|
|
176
168
|
let tsModule: typeof import('typescript') | undefined
|
|
177
169
|
|
|
178
|
-
export async function runTypeScript(code: string
|
|
170
|
+
export async function runTypeScript(code: string) {
|
|
179
171
|
tsModule ??= await import('typescript')
|
|
180
172
|
|
|
181
173
|
code = tsModule.transpileModule(code, {
|
|
@@ -188,11 +180,8 @@ export async function runTypeScript(code: string, context: CodeRunnerContext) {
|
|
|
188
180
|
},
|
|
189
181
|
}).outputText
|
|
190
182
|
|
|
191
|
-
const importRegex = /import\s*\(
|
|
192
|
-
|
|
193
|
-
for (const [,,specifier] of code.matchAll(importRegex)!)
|
|
194
|
-
idMap[specifier] = await context.resolveId(specifier) ?? specifier
|
|
195
|
-
code = code.replace(importRegex, (_full, quote, specifier) => `import(${quote}${idMap[specifier] ?? specifier}${quote})`)
|
|
183
|
+
const importRegex = /import\s*\((.+)\)/g
|
|
184
|
+
code = code.replace(importRegex, (_full, specifier) => `__slidev_import(${specifier})`)
|
|
196
185
|
|
|
197
186
|
return await runJavaScript(code)
|
|
198
187
|
}
|