File tree Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " astro-vtbot " : minor
3
+ ---
4
+
5
+ Enables installation as an Astro integration with ` npx astro add astro-vtbot ` . This automatically adds the ` <Linter> ` component to all your ` <ViewTransition> ` pages!
6
+
Original file line number Diff line number Diff line change
1
+ /// <reference types="astro/client" />
2
+ /// <reference path="../.astro/types.d.ts" />
Original file line number Diff line number Diff line change
1
+
2
+ import type { AstroConfig , AstroIntegration } from "astro" ;
3
+ import vitePluginVtbotExtend from "./vite-plugin-extend" ;
4
+
5
+ type VtBotOptions = {
6
+ autoLint : boolean ;
7
+ } ;
8
+
9
+ export default function createIntegration ( options ?: VtBotOptions ) : AstroIntegration {
10
+ let config : AstroConfig ;
11
+ return {
12
+ name : 'astro-vtbot' ,
13
+ hooks : {
14
+ 'astro:config:setup' : ( { updateConfig } ) => {
15
+ ( options ?. autoLint ?? true ) && updateConfig ( {
16
+ vite : {
17
+ plugins : [ vitePluginVtbotExtend ( ) ] ,
18
+ } ,
19
+ } ) ;
20
+ } ,
21
+
22
+ 'astro:config:done' : async ( { config : cfg } ) => {
23
+ config = cfg ;
24
+ } ,
25
+ } ,
26
+ } ;
27
+ }
Original file line number Diff line number Diff line change
1
+ import VTPL from './vtpl.astro' ;
2
+ export * from 'astro:transitions' ;
3
+ export { VTPL as ViewTransitions } ;
Original file line number Diff line number Diff line change
1
+ import { parse } from "acorn" ;
2
+ import { walk , type Node } from 'estree-walker' ;
3
+ import type { Plugin } from "vite" ;
4
+
5
+ export default function vitePluginVtbotExtend ( ) : Plugin {
6
+ return {
7
+ name : "vtbot:linter" ,
8
+ enforce : "pre" ,
9
+ transform ( code : string , id : string ) {
10
+ if ( ! import . meta. env . DEV || id . endsWith ( "vtpl.astro" ) || ! id . endsWith ( ".astro" ) ) return ;
11
+
12
+ const match = code . match ( / f r o m \s * [ ' " ] a s t r o : t r a n s i t i o n s [ " ' ] / ms) ;
13
+ if ( match ) {
14
+ console . log ( 'id :>> ' , id ) ;
15
+ const ast = parse ( code , {
16
+ ecmaVersion : 'latest' ,
17
+ sourceType : 'module' ,
18
+ } ) as Node ;
19
+
20
+ walk ( ast , {
21
+ enter ( node : any ) {
22
+ if ( node . type === 'ImportDeclaration' && node . source . value === 'astro:transitions' ) {
23
+ code = code . substring ( 0 , node . source . start ) + '"astro-vtbot/vtext"' + code . substring ( node . source . end ) ;
24
+ }
25
+ }
26
+ } ) ;
27
+ } ;
28
+ return code ;
29
+ }
30
+ } ;
31
+ } ;
32
+
Original file line number Diff line number Diff line change
1
+ ---
2
+ import { ViewTransitions } from ' astro:transitions' ;
3
+ import Linter from ' ../components/Linter.astro' ;
4
+ ---
5
+
6
+ <ViewTransitions />
7
+ <Linter />
You can’t perform that action at this time.
0 commit comments