File tree Expand file tree Collapse file tree 3 files changed +54
-4
lines changed
Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Original file line number Diff line number Diff line change 4040 "validate" : " kcd-scripts validate"
4141 },
4242 "dependencies" : {
43- "@babel/runtime" : " ^7.13.17 " ,
43+ "@babel/runtime" : " ^7.14.0 " ,
4444 "@esbuild-plugins/node-resolve" : " ^0.1.4" ,
4545 "@fal-works/esbuild-plugin-global-externals" : " ^2.1.1" ,
4646 "esbuild" : " ^0.11.16" ,
4949 "remark-frontmatter" : " ^3.0.0" ,
5050 "remark-mdx-frontmatter" : " ^1.0.1" ,
5151 "uvu" : " ^0.5.1" ,
52- "xdm" : " ^1.8 .0"
52+ "xdm" : " ^1.9 .0"
5353 },
5454 "devDependencies" : {
5555 "@testing-library/react" : " ^11.2.6" ,
Original file line number Diff line number Diff line change 11import './setup-tests.js'
2+ import path from 'path'
23import { test } from 'uvu'
34import * as assert from 'uvu/assert'
45import React from 'react'
56import rtl from '@testing-library/react'
67import leftPad from 'left-pad'
78import { remarkMdxImages } from 'remark-mdx-images'
8- import path from 'path'
99import { bundleMDX } from '../index.js'
1010import { getMDXComponent } from '../client.js'
1111
@@ -252,6 +252,44 @@ import LeftPad from 'left-pad-js'
252252 assert . match ( container . innerHTML , 'this is left pad' )
253253} )
254254
255+ test ( 'should respect the configured loader for files' , async ( ) => {
256+ const mdxSource = `
257+ # Title
258+
259+ import {Demo} from './demo'
260+
261+ <Demo />
262+ ` . trim ( )
263+
264+ const files = {
265+ './demo.ts' : `
266+ import React from 'react'
267+
268+ export const Demo: React.FC = () => {
269+ return <p>Sample</p>
270+ }
271+ ` . trim ( ) ,
272+ }
273+
274+ const { code} = await bundleMDX ( mdxSource , {
275+ files,
276+ esbuildOptions : options => {
277+ options . loader = {
278+ ...options . loader ,
279+ '.ts' : 'tsx' ,
280+ }
281+
282+ return options
283+ } ,
284+ } )
285+
286+ const Component = getMDXComponent ( code )
287+
288+ const { container} = render ( React . createElement ( Component ) )
289+
290+ assert . match ( container . innerHTML , 'Sample' )
291+ } )
292+
255293test ( 'require from current directory' , async ( ) => {
256294 const mdxSource = `
257295# Title
Original file line number Diff line number Diff line change @@ -104,9 +104,21 @@ async function bundleMDX(
104104 return { contents : vfile . toString ( ) , loader : 'jsx' }
105105 }
106106 default : {
107+ /** @type import('esbuild').Loader */
108+ let loader
109+
110+ if (
111+ build . initialOptions . loader &&
112+ build . initialOptions . loader [ `.${ fileType } ` ]
113+ ) {
114+ loader = build . initialOptions . loader [ `.${ fileType } ` ]
115+ } else {
116+ loader = /** @type import('esbuild').Loader */ ( fileType )
117+ }
118+
107119 return {
108120 contents,
109- loader : /** @type import('esbuild').Loader */ ( fileType ) ,
121+ loader,
110122 }
111123 }
112124 }
You can’t perform that action at this time.
0 commit comments