fable-compiler / repl

Fable online REPL
http://fable.io/repl
MIT License
64 stars 37 forks source link

Strange include path for .js file #141

Closed davedawkins closed 2 years ago

davedawkins commented 2 years ago

This is how Sutil/WebComponents.fs imports webcomponent.js

[<Import("makeWebComponent", "./webcomponent.js")>]

However it produces a runtime error in the REPL with a strange import path, which I'm able to fix with a symbolic link. I'm wondering if the include path needs to be more REPL-friendly in some say?

The requested path is effectively "/src/Fable.Repl.Lib/Sutil/webcomponent.js"

For reference this is the patch to my deployment script (from Sutil's point of view which is hosting the repl at https://sutil.dev/repl"

mkdir ${TARGETDIR}/src
ln -s ${TARGETDIR}/../repl/js/repl/fable-repl-lib ${TARGETDIR}/src/Fable.Repl.Lib
alfonsogarciacaro commented 2 years ago

Sorry for the late reply. Github is being quite hot recently and totally missed this notification 😅

Yes, I had the same issue when including Sutil. This is because in Fable CLI the F# sources and potential JS files are kept in the same directory for packages, but the REPL Lib is precompiled so we have to tell Fable to keep the import relative and not to use the original source. So two steps:

  1. Add ${outPath} in front of the import path to tell Fable to keep the import relative
  2. Move the .js files to the output dir after Fable compilation

Example: https://github.com/fable-compiler/repl/blob/38e90b12be124be5db9cb4e897804e0ca066b71a/src/Fable.Repl.Lib/Sutil/Interop.fs#L40-L46

davedawkins commented 2 years ago

Great, thank you!