@@ -18,11 +18,14 @@ import requireFrom from 'import-from'
18
18
import requireFresh from 'import-fresh'
19
19
import objectHash from 'object-hash'
20
20
import * as svelte from 'prettier-plugin-svelte'
21
- import * as astro from 'prettier-plugin-astro'
22
21
import lineColumn from 'line-column'
23
22
import jsesc from 'jsesc'
24
23
import escalade from 'escalade/sync'
25
24
25
+ // We need to load this plugin dynamically because it's not available by default
26
+ // And we are not bundling it with the main Prettier plugin
27
+ let astro = loadIfExists ( 'prettier-plugin-astro' )
28
+
26
29
let contextMap = new Map ( )
27
30
28
31
function bigSign ( bigIntValue ) {
@@ -448,7 +451,7 @@ export const parsers = {
448
451
transformSvelte ( ast . html , { env, changes } )
449
452
ast . changes = changes
450
453
} ) ,
451
- astro : createParser ( astro . parsers . astro , transformAstro )
454
+ ... astro ? { astro : createParser ( astro . parsers . astro , transformAstro ) } : { } ,
452
455
}
453
456
454
457
function transformAstro ( ast , { env, changes } ) {
@@ -548,3 +551,14 @@ function visit(ast, callbackMap) {
548
551
}
549
552
_visit ( ast )
550
553
}
554
+
555
+ // For loading prettier plugins only if they exist
556
+ function loadIfExists ( name ) {
557
+ try {
558
+ if ( require . resolve ( name ) ) {
559
+ return require ( name )
560
+ }
561
+ } catch ( e ) {
562
+ return null
563
+ }
564
+ }
0 commit comments