GetDutchie / brick

An intuitive way to work with persistent data in Dart

Home Page:https://getdutchie.github.io/brick/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relative imports in models are not correctly transferred to brick.g.dart

devj3ns opened this issue · comments

When a model has a relative import, for example to a request transformer file, the import is copied without fixing the path to the brick.g.dart file. This leads to the project running into a build error because of the wrong import(s) in brick.g.dart.

In the docs, it says:

Every import in a model definition file will be copied to brick.g.dart

Changing the imports to absolute imports fixes the bug as written in #347 (comment)

Now my question is if brick could fix these relative imports in the future. Otherwise, I would like to add a hint to the documentation.

@devj3ns Thanks for opening this, but I'm sorry to tell you that Brick will not support relative imports. You should still be able to use part within your model files. Decoding the original source path relative to where brick.g.dart lives goes beyond the responsibilities of Brick; it's also something of a security concern. Relative paths make determining unique imports required to brick.g.dart tricky. And lastly it requires too much state - the generator has to be aware of a model's position in a folder structure so that it's aware of where the relative paths exist.

Full transparency, it's not impossible to implement. But I've had this debate for a few years and settled on only absolute imports.

Please feel free to add a note to the documentation. You're right that nothing on this currently exists in the docs.

@tshedor thanks for the explanation, I understand that.

Then I will open a PR for adding this to the docs today :)