schultek/dart_mappable

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

Closed this issue · 1 comments

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 {}
  1. Save the following config in build.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

  • dart_mappable version: v4.2.0
  • dart_mappable_builder version: v4.2.0
  • flutter version: 3.19.1
  • OS: Windows 10

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