schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
135 stars 20 forks source link

Broken file path on Windows in mapper file when the generated dir changed #173

Closed realth000 closed 2 months ago

realth000 commented 4 months ago

Description

I encountered this error when using v4.2.0 (latest version) on Windows with the following build config:

targets:
  $default:
    builders:
      dart_mappable_builder:
        options:
          build_extensions:
            'lib/{{}}.dart':
              - 'lib/generated/{{}}.mapper.dart'

The config above moved the generated mapper file from some/path/to/foo.mapper.dart to lib/generated/some/path/to/foo.mapper.dart and on Windows platform in the Generated code, the part of statement broke like this:

part of '..\main.dart';

which should be part of ..\\main.dart or part of ../main.dart.

Reproduce

Just use the repo here.

Or:

  1. Create a new flutter project and add dart_mappable (also the builder) as dependency.
  2. Add some code to use dart_mappable in main.dart:
    
    part '../generated/main.mapper.dart';

@MappableClass() class Foo with FooMappable {}

4. Save the following config in `build.yaml`:
```yaml
targets:
  $default:
    builders:
      dart_mappable_builder:
        options:
          build_extensions:
            'lib/{{}}.dart':
              - 'lib/generated/{{}}.mapper.dart'
  1. Run dart run build_runner build and in the generated file there is: part of '..\main.dart'; which is broken on Windows.

Info

realth000 commented 4 months ago

It seems replace the path separater \ with / can fix this like here.