birdofpreyru / react-native-static-server

Embedded HTTP server for React Native
https://dr.pogodin.studio/docs/react-native-static-server
Other
135 stars 21 forks source link

extractBundledAssets() does not extract subfolders recursively #79

Closed the-unknown closed 10 months ago

the-unknown commented 10 months ago

Hey, I ran into strange behavior regarding asset-bundling. It seems that extractBundledAssets() will not extract sub-folders recursively.

This is my assets-folder structure: Screenshot of my assets-folder structure.

As you can see, there is a _next sub-folder inside of webroot, as I want to use a NextJS application. However, when I call await extractBundledAssets(fileDir, 'webroot'); it will not extract the _next sub-folder at all!

This is my code:

        if (extract) {
          await unlink(fileDir);
          console.log('Extracting web server assets...');
          await extractBundledAssets(fileDir, 'webroot');
        }

This is the content of build.gradle

    sourceSets {
        main {
            assets.srcDirs = [
                '../../assets',
            ]
        }
    }

This is the result.

emu64xa:/data/user/0/com.change.myexpoapp/files/webroot $ ls -al                                                                                                                                                                     
total 104
drwx------ 2 u0_a197 u0_a197  4096 2023-10-19 06:41 .
drwxrwx--x 3 u0_a197 u0_a197  4096 2023-10-19 06:50 ..
-rwx------ 1 u0_a197 u0_a197  7258 2023-10-19 06:41 404.html
-rwx------ 1 u0_a197 u0_a197 25931 2023-10-19 06:41 favicon.ico
-rwx------ 1 u0_a197 u0_a197  6327 2023-10-19 06:41 index.html
-rwx------ 1 u0_a197 u0_a197  3280 2023-10-19 06:41 index.txt
-rwx------ 1 u0_a197 u0_a197 11399 2023-10-19 06:41 mobile_logo.jpg
-rwx------ 1 u0_a197 u0_a197     5 2023-10-19 06:41 version
birdofpreyru commented 10 months ago

Not sure why... it works recursively in my own projects.

You know, the function is very simple, and implemented in TypeScript layer: https://github.com/birdofpreyru/react-native-static-server/blob/142ededf6429ff183ad603891069c6894064d5e6/src/index.tsx#L398-L412 why you just don't add some debug output directly into its source, within your node_modules, and figure out what is wrong there? Is there anything special about that folder, maybe asset.isDirectory() for some reason fails to classify it is as a directory?

the-unknown commented 10 months ago

ok, so I debugged this and it appears that a directory that starts with a "_" does not get recognized as directory and is just ignored. When I rename it from _next to next it works. This might be an issue with react-native-fs I guess.

birdofpreyru commented 10 months ago

Yeah, it looks so, I should look into it in my fork of RNFS. Thanks for noticing it :)