bower-away icon indicating copy to clipboard operation
bower-away copied to clipboard

Serving static content from sys link directory is not working

Open amrelhagary opened this issue 8 years ago • 9 comments

I followed the instruction and I get a sys link folder bower_components linked to @bower_components in npm and when I refresh the index page it gives me 404.

amrelhagary avatar Nov 24 '17 17:11 amrelhagary

what do you mean by sys link? are you on windows? can you browse this folder using file explorer?

sheerun avatar Nov 25 '17 16:11 sheerun

I am on Mac and I can browse the files, I am not sure what is the problem if I replaced the sys linked folder with actual bower_components it works. I am using docker on mac os.

amrelhagary avatar Nov 25 '17 18:11 amrelhagary

Do you mean symlinked? Could you prepare github repository to reproduce this issue?

sheerun avatar Nov 25 '17 19:11 sheerun

I think the problem with docker.

amrelhagary avatar Nov 25 '17 22:11 amrelhagary

I just encountered the same issue. The root cause appears to be that yarn install creates absolute symlink, and this causes issues if the file system (or directory) is cloned via some form of sandboxing (openshift or docker?).

I fixed this by changing the postinstall hook to generate relative links.

node -e \"try { require('fs').symlinkSync('../node_modules/@bower_components', 'public/libs', 'junction') } catch (e) { }\"

This is a bit of a corner case though, but it might be sensible by default to generate relative symlinks?

hsalokor avatar Nov 29 '17 11:11 hsalokor

interesting

@hsalokor @GabLeRoux @samypr100 do relative symlinks work with windows junctions?

sheerun avatar Nov 29 '17 14:11 sheerun

I have no access right now to a Windows machine in order to test, but Node.js fs-module documentation seems to suggest that the above code would work, but would create absolute junction.

Note that Windows junction points require the destination path to be absolute. When using 'junction', the target argument will automatically be normalized to absolute path.

It probably needs some testing in real Windows environment - I think it would be acceptable to create relative links on OS X and Linux, and fall back to absolute paths on Windows.

hsalokor avatar Nov 29 '17 14:11 hsalokor

I've created this repository to give this issue a try: https://github.com/GabLeRoux/bower-away-test.git

In an administrator shell on Windows 10, I did this:

PS C:\Users\IEUser\Desktop> git clone https://github.com/GabLeRoux/bower-away-test.git
Cloning into 'bower-away-test'...
remote: Counting objects: 17, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 17 (delta 5), reused 17 (delta 5), pack-reused 0
Unpacking objects: 100% (17/17), done.
PS C:\Users\IEUser\Desktop> cd .\bower-away-test\
PS C:\Users\IEUser\Desktop\bower-away-test> dir


    Directory: C:\Users\IEUser\Desktop\bower-away-test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       11/29/2017   7:53 AM                public
-a----       11/29/2017   7:53 AM             38 .bowerrc
-a----       11/29/2017   7:53 AM             27 .gitignore
-a----       11/29/2017   7:53 AM            380 bower.json
-a----       11/29/2017   7:53 AM            537 package.json
-a----       11/29/2017   7:53 AM            291 yarn.lock


PS C:\Users\IEUser\Desktop\bower-away-test> yarn install
yarn install v1.3.2
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
$ node -e "try { require('fs').symlinkSync(require('path').resolve('node_modules/@bower_components'), 'public/libs', 'junction') } catch (e) { }"
Done in 5.26s.
PS C:\Users\IEUser\Desktop\bower-away-test> dir


    Directory: C:\Users\IEUser\Desktop\bower-away-test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       11/29/2017   7:53 AM                node_modules
d-----       11/29/2017   7:53 AM                public
-a----       11/29/2017   7:53 AM             38 .bowerrc
-a----       11/29/2017   7:53 AM             27 .gitignore
-a----       11/29/2017   7:53 AM            380 bower.json
-a----       11/29/2017   7:53 AM            537 package.json
-a----       11/29/2017   7:53 AM            291 yarn.lock


PS C:\Users\IEUser\Desktop\bower-away-test> dir .\public\libs\


    Directory: C:\Users\IEUser\Desktop\bower-away-test\public\libs


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       11/29/2017   7:53 AM                font-awesome

It worked well as expected, I used

bower-away --version
1.1.2

I will try with this when I get some more time.

-"postinstall": "node -e \"try { require('fs').symlinkSync(require('path').resolve('node_modules/@bower_components'), 'public/libs', 'junction') } catch (e) { }\""
+"postinstall": "node -e \"try { require('fs').symlinkSync('../node_modules/@bower_components', 'public/libs', 'junction') } catch (e) { }\""

GabLeRoux avatar Nov 29 '17 15:11 GabLeRoux

Hint: I'm using a windows vm from Microsoft modern.ie's vms. This way, everybody can test on windows, but it takes a few minutes to setup. 👍

GabLeRoux avatar Nov 29 '17 16:11 GabLeRoux