File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 1- use std:: ops:: IndexMut ;
1+ use std:: {
2+ ops:: IndexMut ,
3+ path:: { Component , Path } ,
4+ } ;
25
36use serde:: Deserialize ;
47use swc_plugin:: {
58 ast:: * ,
6- metadata:: TransformPluginProgramMetadata ,
9+ metadata:: { TransformPluginMetadataContextKind , TransformPluginProgramMetadata } ,
710 plugin_transform,
811 syntax_pos:: DUMMY_SP ,
912 utils:: { prepend_stmt, take:: Take , ExprFactory } ,
@@ -962,5 +965,19 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
962965 let config = serde_json:: from_str :: < Config > ( & _metadata. get_transform_plugin_config ( ) . unwrap ( ) )
963966 . expect ( "Failed to parse plugin config" ) ;
964967
965- program. fold_with ( & mut plugin ( config) )
968+ match _metadata. get_context ( & TransformPluginMetadataContextKind :: Filename ) {
969+ Some ( s) => {
970+ // check file is under 'pages' directory
971+ let is_page = Path :: new ( & s. replace ( '\\' , "/" ) ) . components ( ) . any ( |cmp| match cmp {
972+ Component :: Normal ( str) => str. to_str ( ) . unwrap_or_default ( ) == "pages" ,
973+ _ => false ,
974+ } ) ;
975+
976+ if is_page {
977+ return program. fold_with ( & mut plugin ( config) ) ;
978+ }
979+ program
980+ }
981+ None => program,
982+ }
966983}
You can’t perform that action at this time.
0 commit comments