@@ -61,12 +61,8 @@ const autoJSCodePlugin: Plugin<[], md.Root> = () => async (tree, file) => {
61
61
// Remove our flag from the meta so other plugins don't trip up
62
62
const newMeta = node . meta . replace ( META_FLAG_REGEX , '' )
63
63
64
- const jsCodeBlock = await makeJsCodeBlock ( newMeta , node , {
65
- location : file . path ,
66
- } )
67
- const tsCodeBlock = await makeTsCodeBlock ( newMeta , node , {
68
- location : file . path ,
69
- } )
64
+ const jsCodeBlock = await makeJsCodeBlock ( newMeta , node )
65
+ const tsCodeBlock = await makeTsCodeBlock ( newMeta , node )
70
66
71
67
// The specific structure of the new node was retrieved by copy-pasting
72
68
// an example into the MDX playground and inspecting the AST.
@@ -115,8 +111,7 @@ const CODE_BLOCK_TITLE_REGEX = /title=(?<quote>["'])(?<title>.*?)\1/
115
111
116
112
async function makeJsCodeBlock (
117
113
metaString : string ,
118
- node : md . Code ,
119
- { location } : { location : string }
114
+ node : md . Code
120
115
) : Promise < md . Code > {
121
116
// Find the `title=` meta param and change the extension
122
117
const meta = metaString . replace (
@@ -130,7 +125,6 @@ async function makeJsCodeBlock(
130
125
const isJsx = node . lang . endsWith ( 'x' )
131
126
const code = await format ( convertToJs ( node . value , { isJsx } ) , {
132
127
parser : 'babel' ,
133
- location,
134
128
} )
135
129
136
130
return {
@@ -143,11 +137,10 @@ async function makeJsCodeBlock(
143
137
144
138
async function makeTsCodeBlock (
145
139
metaString : string ,
146
- node : md . Code ,
147
- { location } : { location : string }
140
+ node : md . Code
148
141
) : Promise < md . Code > {
149
142
const lang = node . lang
150
- const code = await format ( node . value , { parser : 'babel-ts' , location } )
143
+ const code = await format ( node . value , { parser : 'babel-ts' } )
151
144
152
145
return {
153
146
type : 'code' ,
@@ -173,16 +166,17 @@ function convertToJs(code: string, { isJsx }: { isJsx: boolean }) {
173
166
return blankSourceFile ( sourceFile )
174
167
}
175
168
169
+ let prettierConfig : prettier . Options | undefined
170
+
176
171
async function format (
177
172
code : string ,
178
- { parser, location } : { parser : prettier . Options [ 'parser' ] ; location : string }
173
+ { parser } : { parser : prettier . Options [ 'parser' ] }
179
174
) {
180
- const config = await prettier . resolveConfig ( location , {
175
+ prettierConfig ?? = await prettier . resolveConfig ( __dirname , {
181
176
useCache : true ,
182
177
editorconfig : true ,
183
178
} )
184
-
185
- return prettier . format ( code , { ...config , parser } )
179
+ return prettier . format ( code , { ...prettierConfig , parser } )
186
180
}
187
181
188
182
function transformExt ( inPath : string , fn : ( ext : string ) => string ) {
0 commit comments