File tree Expand file tree Collapse file tree 1 file changed +23
-9
lines changed Expand file tree Collapse file tree 1 file changed +23
-9
lines changed Original file line number Diff line number Diff line change 1+ use std:: path:: { Component , Path } ;
2+
13use serde:: Deserialize ;
24use swc_core:: {
35 ecma:: { ast:: * , visit:: * } ,
@@ -41,15 +43,27 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
4143 let path = & raw_path. replace ( '\\' , "/" ) ;
4244
4345 if let Some ( relative_path) = path. strip_prefix ( cwd) {
44- let dir_type =
45- if relative_path. starts_with ( "/pages" ) || relative_path. starts_with ( "/src/pages" ) {
46- DirType :: Page
47- } else if relative_path. starts_with ( "/app" ) || relative_path. starts_with ( "/src/app" ) {
48- DirType :: App
49- } else {
50- // not page or app
51- return program;
52- } ;
46+ let mut is_page = false ;
47+
48+ for component in Path :: new ( relative_path) . components ( ) {
49+ match component {
50+ Component :: Normal ( str) => match str. to_str ( ) . unwrap_or_default ( ) {
51+ // skip non-source stuff
52+ "node_modules" | "dist" => {
53+ return program;
54+ }
55+ "pages" => {
56+ is_page = true ;
57+ break ;
58+ }
59+ _ => { }
60+ } ,
61+ _ => { }
62+ }
63+ }
64+
65+ // consider server components outside the app directory
66+ let dir_type = if is_page { DirType :: Page } else { DirType :: App } ;
5367
5468 let config = serde_json:: from_str :: < Config > (
5569 & _metadata
You can’t perform that action at this time.
0 commit comments