ClojureDart
ClojureDart copied to clipboard
local Dart libs paths are not properly relativized
This only affects dart projects; flutter projects seem to cope with the issue.
To reproduce, create a dart file in lib and require it from a clojure ns. Then in the the compiled dart for the ns, the path to the local dart file will have an extra ../
. (Flutter seems ok with that but not Dart.)
This comes from an imbalance where libs from compiled nses are stored by the compiler with the "lib" prefix (to be able to relativize properly when test
and other directories are involved.
Current workaround is to require the file as "package:projectname-as-set-in-pubspec-yaml/myfile.dart"
.
(This https://stackoverflow.com/a/61604885 points to the fact that relative paths is just a meter of style.)
Possible solutions:
- to automatically generate
package:projectname-as-set-in-pubspec-yaml/
we need to parse the YAML. (In this case could we go as far as remove all relativization logic -- I'm still concerned about what happens when multiple source directories are in use) - we get the analyzer to give us the canonical lib
- we ask the user to prefix with
lib
and fix the existence check and deal with relative/absolute libs path depending on where in the compiler we are (I believe the relative path matters only fordump-ns
)
https://dart.dev/effective-dart/usage#dont-allow-an-import-path-to-reach-into-or-out-of-lib
tests shouldn't use relative paths
import 'package:my_package/api.dart'; import '../lib/api.dart'; Dart thinks those are imports of two completely unrelated libraries. To avoid confusing Dart and yourself, follow these two rules: Don’t use /lib/ in import paths. Don’t use ../ to escape the lib directory.