-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathindex.cjs
More file actions
68 lines (60 loc) · 1.71 KB
/
index.cjs
File metadata and controls
68 lines (60 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
/**
* @import {TsConfigSourceFile} from 'typescript'
* @import {Plugin} from 'unified'
*/
const {pathToFileURL} = require('node:url')
const {
createMdxLanguagePlugin,
resolveRemarkPlugins
} = require('@mdx-js/language-service')
const {
createAsyncLanguageServicePlugin
} = require('@volar/typescript/lib/quickstart/createAsyncLanguageServicePlugin.js')
const {loadPlugin} = require('load-plugin')
const {default: remarkFrontmatter} = require('remark-frontmatter')
const {default: remarkGfm} = require('remark-gfm')
const plugin = createAsyncLanguageServicePlugin(
['.mdx'],
2 /* JSX */,
async (ts, info) => {
if (info.project.projectKind !== ts.server.ProjectKind.Configured) {
return {
languagePlugins: [
createMdxLanguagePlugin([
[remarkFrontmatter, ['toml', 'yaml']],
remarkGfm
])
]
}
}
const cwd = info.project.getCurrentDirectory()
const configFile = /** @type {TsConfigSourceFile} */ (
info.project.getCompilerOptions().configFile
)
const commandLine = ts.parseJsonSourceFileConfigFileContent(
configFile,
ts.sys,
cwd,
undefined,
configFile.fileName
)
const plugins = await resolveRemarkPlugins(
commandLine.raw?.mdx,
(name) =>
/** @type {Promise<Plugin>} */ (
loadPlugin(name, {prefix: 'remark', from: pathToFileURL(cwd) + '/'})
)
)
return {
languagePlugins: [
createMdxLanguagePlugin(
plugins || [[remarkFrontmatter, ['toml', 'yaml']], remarkGfm],
Boolean(commandLine.raw?.mdx?.checkMdx),
commandLine.options.jsxImportSource
)
]
}
}
)
module.exports = plugin