@@ -14,21 +14,21 @@ import {test} from 'uvu'
14
14
import * as assert from 'uvu/assert'
15
15
import esbuild from 'esbuild'
16
16
import React from 'react'
17
- import { renderToStaticMarkup } from 'react-dom/server.js '
17
+ import { renderToStaticMarkup } from 'react-dom/server'
18
18
import esbuildMdx from '../index.js'
19
19
20
20
test ( '@mdx-js/esbuild' , async ( ) => {
21
21
// MDX.
22
22
await fs . writeFile (
23
- new URL ( './ esbuild.mdx' , import . meta. url ) ,
23
+ new URL ( 'esbuild.mdx' , import . meta. url ) ,
24
24
'export const Message = () => <>World!</>\n\n# Hello, <Message />'
25
25
)
26
26
27
27
await esbuild . build ( {
28
28
bundle : true ,
29
29
define : { 'process.env.NODE_ENV' : '"development"' } ,
30
- entryPoints : [ fileURLToPath ( new URL ( './ esbuild.mdx' , import . meta. url ) ) ] ,
31
- outfile : fileURLToPath ( new URL ( './ esbuild.js' , import . meta. url ) ) ,
30
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.mdx' , import . meta. url ) ) ] ,
31
+ outfile : fileURLToPath ( new URL ( 'esbuild.js' , import . meta. url ) ) ,
32
32
format : 'esm' ,
33
33
plugins : [ esbuildMdx ( ) ]
34
34
} )
@@ -44,30 +44,30 @@ test('@mdx-js/esbuild', async () => {
44
44
'should compile'
45
45
)
46
46
47
- await fs . unlink ( new URL ( './ esbuild.mdx' , import . meta. url ) )
48
- await fs . unlink ( new URL ( './ esbuild.js' , import . meta. url ) )
47
+ await fs . unlink ( new URL ( 'esbuild.mdx' , import . meta. url ) )
48
+ await fs . unlink ( new URL ( 'esbuild.js' , import . meta. url ) )
49
49
50
50
// Resolve directory.
51
51
await fs . writeFile (
52
- new URL ( './ esbuild-resolve.mdx' , import . meta. url ) ,
52
+ new URL ( 'esbuild-resolve.mdx' , import . meta. url ) ,
53
53
'import Content from "./folder/file.mdx"\n\n<Content/>'
54
54
)
55
- await fs . mkdir ( new URL ( './ folder' , import . meta. url ) )
55
+ await fs . mkdir ( new URL ( 'folder' , import . meta. url ) )
56
56
await fs . writeFile (
57
- new URL ( './ folder/file.mdx' , import . meta. url ) ,
57
+ new URL ( 'folder/file.mdx' , import . meta. url ) ,
58
58
'import {data} from "./file.js"\n\n{data}'
59
59
)
60
60
await fs . writeFile (
61
- new URL ( './ folder/file.js' , import . meta. url ) ,
61
+ new URL ( 'folder/file.js' , import . meta. url ) ,
62
62
'export const data = 0.1'
63
63
)
64
64
await esbuild . build ( {
65
65
bundle : true ,
66
66
define : { 'process.env.NODE_ENV' : '"development"' } ,
67
67
entryPoints : [
68
- fileURLToPath ( new URL ( './ esbuild-resolve.mdx' , import . meta. url ) )
68
+ fileURLToPath ( new URL ( 'esbuild-resolve.mdx' , import . meta. url ) )
69
69
] ,
70
- outfile : fileURLToPath ( new URL ( './ esbuild-resolve.js' , import . meta. url ) ) ,
70
+ outfile : fileURLToPath ( new URL ( 'esbuild-resolve.js' , import . meta. url ) ) ,
71
71
format : 'esm' ,
72
72
plugins : [ esbuildMdx ( ) ]
73
73
} )
@@ -82,18 +82,18 @@ test('@mdx-js/esbuild', async () => {
82
82
'should compile'
83
83
)
84
84
85
- await fs . unlink ( new URL ( './ esbuild-resolve.mdx' , import . meta. url ) )
86
- await fs . unlink ( new URL ( './ esbuild-resolve.js' , import . meta. url ) )
87
- await fs . rmdir ( new URL ( './ folder/' , import . meta. url ) , { recursive : true } )
85
+ await fs . unlink ( new URL ( 'esbuild-resolve.mdx' , import . meta. url ) )
86
+ await fs . unlink ( new URL ( 'esbuild-resolve.js' , import . meta. url ) )
87
+ await fs . rmdir ( new URL ( 'folder/' , import . meta. url ) , { recursive : true } )
88
88
89
89
// Markdown.
90
- await fs . writeFile ( new URL ( './ esbuild.md' , import . meta. url ) , '\ta' )
90
+ await fs . writeFile ( new URL ( 'esbuild.md' , import . meta. url ) , '\ta' )
91
91
92
92
await esbuild . build ( {
93
93
bundle : true ,
94
94
define : { 'process.env.NODE_ENV' : '"development"' } ,
95
- entryPoints : [ fileURLToPath ( new URL ( './ esbuild.md' , import . meta. url ) ) ] ,
96
- outfile : fileURLToPath ( new URL ( './ esbuild-md.js' , import . meta. url ) ) ,
95
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.md' , import . meta. url ) ) ] ,
96
+ outfile : fileURLToPath ( new URL ( 'esbuild-md.js' , import . meta. url ) ) ,
97
97
format : 'esm' ,
98
98
plugins : [ esbuildMdx ( ) ]
99
99
} )
@@ -108,17 +108,17 @@ test('@mdx-js/esbuild', async () => {
108
108
'should compile `.md`'
109
109
)
110
110
111
- await fs . unlink ( new URL ( './ esbuild.md' , import . meta. url ) )
112
- await fs . unlink ( new URL ( './ esbuild-md.js' , import . meta. url ) )
111
+ await fs . unlink ( new URL ( 'esbuild.md' , import . meta. url ) )
112
+ await fs . unlink ( new URL ( 'esbuild-md.js' , import . meta. url ) )
113
113
114
114
// `.md` as MDX extension.
115
- await fs . writeFile ( new URL ( './ esbuild.md' , import . meta. url ) , '\ta' )
115
+ await fs . writeFile ( new URL ( 'esbuild.md' , import . meta. url ) , '\ta' )
116
116
117
117
await esbuild . build ( {
118
118
bundle : true ,
119
119
define : { 'process.env.NODE_ENV' : '"development"' } ,
120
- entryPoints : [ fileURLToPath ( new URL ( './ esbuild.md' , import . meta. url ) ) ] ,
121
- outfile : fileURLToPath ( new URL ( './ esbuild-md-as-mdx.js' , import . meta. url ) ) ,
120
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.md' , import . meta. url ) ) ] ,
121
+ outfile : fileURLToPath ( new URL ( 'esbuild-md-as-mdx.js' , import . meta. url ) ) ,
122
122
format : 'esm' ,
123
123
plugins : [ esbuildMdx ( { mdExtensions : [ ] , mdxExtensions : [ '.md' ] } ) ]
124
124
} )
@@ -133,20 +133,18 @@ test('@mdx-js/esbuild', async () => {
133
133
'should compile `.md` as MDX w/ configuration'
134
134
)
135
135
136
- await fs . unlink ( new URL ( './ esbuild.md' , import . meta. url ) )
137
- await fs . unlink ( new URL ( './ esbuild-md-as-mdx.js' , import . meta. url ) )
136
+ await fs . unlink ( new URL ( 'esbuild.md' , import . meta. url ) )
137
+ await fs . unlink ( new URL ( 'esbuild-md-as-mdx.js' , import . meta. url ) )
138
138
139
139
// File not in `extnames`:
140
- await fs . writeFile ( new URL ( './ esbuild.md' , import . meta. url ) , 'a' )
141
- await fs . writeFile ( new URL ( './ esbuild.mdx' , import . meta. url ) , 'a' )
140
+ await fs . writeFile ( new URL ( 'esbuild.md' , import . meta. url ) , 'a' )
141
+ await fs . writeFile ( new URL ( 'esbuild.mdx' , import . meta. url ) , 'a' )
142
142
143
143
console . log ( '\nnote: the following error is expected!\n' )
144
144
try {
145
145
await esbuild . build ( {
146
- entryPoints : [ fileURLToPath ( new URL ( './esbuild.md' , import . meta. url ) ) ] ,
147
- outfile : fileURLToPath (
148
- new URL ( './esbuild-md-as-mdx.js' , import . meta. url )
149
- ) ,
146
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.md' , import . meta. url ) ) ] ,
147
+ outfile : fileURLToPath ( new URL ( 'esbuild-md-as-mdx.js' , import . meta. url ) ) ,
150
148
plugins : [ esbuildMdx ( { format : 'mdx' } ) ]
151
149
} )
152
150
assert . unreachable ( )
@@ -161,10 +159,8 @@ test('@mdx-js/esbuild', async () => {
161
159
console . log ( '\nnote: the following error is expected!\n' )
162
160
try {
163
161
await esbuild . build ( {
164
- entryPoints : [ fileURLToPath ( new URL ( './esbuild.mdx' , import . meta. url ) ) ] ,
165
- outfile : fileURLToPath (
166
- new URL ( './esbuild-md-as-mdx.js' , import . meta. url )
167
- ) ,
162
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.mdx' , import . meta. url ) ) ] ,
163
+ outfile : fileURLToPath ( new URL ( 'esbuild-md-as-mdx.js' , import . meta. url ) ) ,
168
164
plugins : [ esbuildMdx ( { format : 'md' } ) ]
169
165
} )
170
166
assert . unreachable ( )
@@ -176,22 +172,22 @@ test('@mdx-js/esbuild', async () => {
176
172
)
177
173
}
178
174
179
- await fs . unlink ( new URL ( './ esbuild.md' , import . meta. url ) )
180
- await fs . unlink ( new URL ( './ esbuild.mdx' , import . meta. url ) )
175
+ await fs . unlink ( new URL ( 'esbuild.md' , import . meta. url ) )
176
+ await fs . unlink ( new URL ( 'esbuild.mdx' , import . meta. url ) )
181
177
182
178
console . log ( '\nnote: the following errors and warnings are expected!\n' )
183
179
184
180
await fs . writeFile (
185
- new URL ( './ esbuild-broken.mdx' , import . meta. url ) ,
181
+ new URL ( 'esbuild-broken.mdx' , import . meta. url ) ,
186
182
'asd <https://example.com>?'
187
183
)
188
184
189
185
try {
190
186
await esbuild . build ( {
191
187
entryPoints : [
192
- fileURLToPath ( new URL ( './ esbuild-broken.mdx' , import . meta. url ) )
188
+ fileURLToPath ( new URL ( 'esbuild-broken.mdx' , import . meta. url ) )
193
189
] ,
194
- outfile : fileURLToPath ( new URL ( './ esbuild.js' , import . meta. url ) ) ,
190
+ outfile : fileURLToPath ( new URL ( 'esbuild.js' , import . meta. url ) ) ,
195
191
plugins : [ esbuildMdx ( ) ]
196
192
} )
197
193
assert . unreachable ( 'esbuild should throw' )
@@ -219,19 +215,19 @@ test('@mdx-js/esbuild', async () => {
219
215
)
220
216
}
221
217
222
- await fs . unlink ( new URL ( './ esbuild-broken.mdx' , import . meta. url ) )
218
+ await fs . unlink ( new URL ( 'esbuild-broken.mdx' , import . meta. url ) )
223
219
224
220
await fs . writeFile (
225
- new URL ( './ esbuild-warnings.mdx' , import . meta. url ) ,
221
+ new URL ( 'esbuild-warnings.mdx' , import . meta. url ) ,
226
222
'export const Message = () => <>World!</>\n\n# Hello, <Message />'
227
223
)
228
224
229
225
try {
230
226
await esbuild . build ( {
231
227
entryPoints : [
232
- fileURLToPath ( new URL ( './ esbuild-warnings.mdx' , import . meta. url ) )
228
+ fileURLToPath ( new URL ( 'esbuild-warnings.mdx' , import . meta. url ) )
233
229
] ,
234
- outfile : fileURLToPath ( new URL ( './ esbuild-warnings.js' , import . meta. url ) ) ,
230
+ outfile : fileURLToPath ( new URL ( 'esbuild-warnings.js' , import . meta. url ) ) ,
235
231
format : 'esm' ,
236
232
plugins : [
237
233
esbuildMdx ( {
@@ -386,20 +382,20 @@ test('@mdx-js/esbuild', async () => {
386
382
)
387
383
}
388
384
389
- await fs . unlink ( new URL ( './ esbuild-warnings.mdx' , import . meta. url ) )
385
+ await fs . unlink ( new URL ( 'esbuild-warnings.mdx' , import . meta. url ) )
390
386
391
387
await fs . writeFile (
392
- new URL ( './ esbuild-plugin-crash.mdx' , import . meta. url ) ,
388
+ new URL ( 'esbuild-plugin-crash.mdx' , import . meta. url ) ,
393
389
'# hi'
394
390
)
395
391
396
392
try {
397
393
await esbuild . build ( {
398
394
entryPoints : [
399
- fileURLToPath ( new URL ( './ esbuild-plugin-crash.mdx' , import . meta. url ) )
395
+ fileURLToPath ( new URL ( 'esbuild-plugin-crash.mdx' , import . meta. url ) )
400
396
] ,
401
397
outfile : fileURLToPath (
402
- new URL ( './ esbuild-plugin-crash.js' , import . meta. url )
398
+ new URL ( 'esbuild-plugin-crash.js' , import . meta. url )
403
399
) ,
404
400
format : 'esm' ,
405
401
plugins : [
@@ -449,25 +445,25 @@ test('@mdx-js/esbuild', async () => {
449
445
)
450
446
}
451
447
452
- await fs . unlink ( new URL ( './ esbuild-plugin-crash.mdx' , import . meta. url ) )
448
+ await fs . unlink ( new URL ( 'esbuild-plugin-crash.mdx' , import . meta. url ) )
453
449
454
450
console . log ( '\nnote: the preceding errors and warnings are expected!\n' )
455
451
456
452
/** @type {(contents: string) => import('esbuild').Plugin } */
457
453
const inlinePlugin = ( contents ) => ( {
458
454
name : 'inline plugin' ,
459
- setup : ( build ) => {
455
+ setup ( build ) {
460
456
build . onResolve ( { filter : / e s b u i l d \. m d x / } , ( ) => ( {
461
- path : fileURLToPath ( new URL ( './ esbuild.mdx' , import . meta. url ) ) ,
457
+ path : fileURLToPath ( new URL ( 'esbuild.mdx' , import . meta. url ) ) ,
462
458
pluginData : { contents}
463
459
} ) )
464
460
}
465
461
} )
466
462
467
463
await esbuild . build ( {
468
- entryPoints : [ fileURLToPath ( new URL ( './ esbuild.mdx' , import . meta. url ) ) ] ,
464
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.mdx' , import . meta. url ) ) ] ,
469
465
outfile : fileURLToPath (
470
- new URL ( './ esbuild-compile-from-memory.js' , import . meta. url )
466
+ new URL ( 'esbuild-compile-from-memory.js' , import . meta. url )
471
467
) ,
472
468
plugins : [ inlinePlugin ( `# Test` ) , esbuildMdx ( ) ] ,
473
469
define : { 'process.env.NODE_ENV' : '"development"' } ,
@@ -485,12 +481,12 @@ test('@mdx-js/esbuild', async () => {
485
481
'should compile from `pluginData.content`'
486
482
)
487
483
488
- await fs . unlink ( new URL ( './ esbuild-compile-from-memory.js' , import . meta. url ) )
484
+ await fs . unlink ( new URL ( 'esbuild-compile-from-memory.js' , import . meta. url ) )
489
485
490
486
await esbuild . build ( {
491
- entryPoints : [ fileURLToPath ( new URL ( './ esbuild.mdx' , import . meta. url ) ) ] ,
487
+ entryPoints : [ fileURLToPath ( new URL ( 'esbuild.mdx' , import . meta. url ) ) ] ,
492
488
outfile : fileURLToPath (
493
- new URL ( './ esbuild-compile-from-memory-empty.js' , import . meta. url )
489
+ new URL ( 'esbuild-compile-from-memory-empty.js' , import . meta. url )
494
490
) ,
495
491
plugins : [ inlinePlugin ( `` ) , esbuildMdx ( ) ] ,
496
492
define : { 'process.env.NODE_ENV' : '"development"' } ,
@@ -509,21 +505,21 @@ test('@mdx-js/esbuild', async () => {
509
505
)
510
506
511
507
await fs . unlink (
512
- new URL ( './ esbuild-compile-from-memory-empty.js' , import . meta. url )
508
+ new URL ( 'esbuild-compile-from-memory-empty.js' , import . meta. url )
513
509
)
514
510
515
511
// Remote markdown.
516
512
await fs . writeFile (
517
- new URL ( './ esbuild-with-remote-md.mdx' , import . meta. url ) ,
513
+ new URL ( 'esbuild-with-remote-md.mdx' , import . meta. url ) ,
518
514
'import Content from "https://raw.githubusercontent.com/mdx-js/mdx/main/packages/esbuild/test/files/md-file.md"\n\n<Content />'
519
515
)
520
516
521
517
await esbuild . build ( {
522
518
entryPoints : [
523
- fileURLToPath ( new URL ( './ esbuild-with-remote-md.mdx' , import . meta. url ) )
519
+ fileURLToPath ( new URL ( 'esbuild-with-remote-md.mdx' , import . meta. url ) )
524
520
] ,
525
521
outfile : fileURLToPath (
526
- new URL ( './ esbuild-with-remote-md.js' , import . meta. url )
522
+ new URL ( 'esbuild-with-remote-md.js' , import . meta. url )
527
523
) ,
528
524
bundle : true ,
529
525
define : { 'process.env.NODE_ENV' : '"development"' } ,
@@ -541,21 +537,21 @@ test('@mdx-js/esbuild', async () => {
541
537
'should compile remote markdown files w/ `allowDangerousRemoteMdx`'
542
538
)
543
539
544
- await fs . unlink ( new URL ( './ esbuild-with-remote-md.mdx' , import . meta. url ) )
545
- await fs . unlink ( new URL ( './ esbuild-with-remote-md.js' , import . meta. url ) )
540
+ await fs . unlink ( new URL ( 'esbuild-with-remote-md.mdx' , import . meta. url ) )
541
+ await fs . unlink ( new URL ( 'esbuild-with-remote-md.js' , import . meta. url ) )
546
542
547
543
// Remote MDX importing more markdown.
548
544
await fs . writeFile (
549
- new URL ( './ esbuild-with-remote-mdx.mdx' , import . meta. url ) ,
545
+ new URL ( 'esbuild-with-remote-mdx.mdx' , import . meta. url ) ,
550
546
'import Content from "https://raw.githubusercontent.com/mdx-js/mdx/main/packages/esbuild/test/files/mdx-file-importing-markdown.mdx"\n\n<Content />'
551
547
)
552
548
553
549
await esbuild . build ( {
554
550
entryPoints : [
555
- fileURLToPath ( new URL ( './ esbuild-with-remote-mdx.mdx' , import . meta. url ) )
551
+ fileURLToPath ( new URL ( 'esbuild-with-remote-mdx.mdx' , import . meta. url ) )
556
552
] ,
557
553
outfile : fileURLToPath (
558
- new URL ( './ esbuild-with-remote-mdx.js' , import . meta. url )
554
+ new URL ( 'esbuild-with-remote-mdx.js' , import . meta. url )
559
555
) ,
560
556
bundle : true ,
561
557
define : { 'process.env.NODE_ENV' : '"development"' } ,
@@ -573,8 +569,8 @@ test('@mdx-js/esbuild', async () => {
573
569
'should compile remote MD, MDX, and JS files w/ `allowDangerousRemoteMdx`'
574
570
)
575
571
576
- await fs . unlink ( new URL ( './ esbuild-with-remote-mdx.mdx' , import . meta. url ) )
577
- await fs . unlink ( new URL ( './ esbuild-with-remote-mdx.js' , import . meta. url ) )
572
+ await fs . unlink ( new URL ( 'esbuild-with-remote-mdx.mdx' , import . meta. url ) )
573
+ await fs . unlink ( new URL ( 'esbuild-with-remote-mdx.js' , import . meta. url ) )
578
574
} )
579
575
580
576
test . run ( )
0 commit comments