Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local Dart libs paths are not properly relativized #275

Open
cgrand opened this issue Oct 3, 2023 · 1 comment
Open

local Dart libs paths are not properly relativized #275

cgrand opened this issue Oct 3, 2023 · 1 comment

Comments

@cgrand
Copy link
Contributor

cgrand commented Oct 3, 2023

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 for dump-ns )
@cgrand
Copy link
Contributor Author

cgrand commented Oct 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant