Skip to content

Register extension packages inside the extensions list, not the import block - #91

Draft
AdamMusa wants to merge 2 commits into
mainfrom
fix/extension-registration-in-list
Draft

AdamMusa wants to merge 2 commits into
mainfrom
fix/extension-registration-in-list

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Summary

When a Ruflet app lists its own extension package in ruflet.yaml:

extensions:
  - ext_pkg:
      path: /abs/path/to/ext_pkg

ruflet build writes ext_pkg.Extension(), into the import block of build/client/lib/main.server.dart and main.self.dart, not into final extensions = <RufletExtension>[ ... ];. The entrypoint stops parsing:

line 5, column 5 of lib/main.server.dart: Functions must have an explicit list of parameters.

so a real flutter build fails. This happens with published gems 0.0.21, 0.0.22 and 0.0.23, and with main. It was found while reviewing AdamMusa/ruflet-template#2, and template main e32c873 shows the same thing.

Cause

insert_missing_extension (now in packages/ruflet/lib/ruflet/cli/build/contributors/extensions.rb, after #75 split build_command.rb) puts the registration before the first // --FAT_CLIENT_START-- anywhere in the file. The template's main.server.dart and main.self.dart also wrap some imports at the top of the file in FAT_CLIENT markers, so the first match is in the import block.

Fix

  1. fix: register extension packages inside the extensions list: look for the marker only between the final extensions = <RufletExtension>[ line and its closing ];. If the list has no marker of its own (or has no closing ];), insert the registration right after the list opening.
  2. fix: leave an entrypoint without an extensions list unchanged: the template's lib/main.dart only calls main.self.dart and has no extensions list. The old fallback appended the registration at the end of that file, so it failed to parse with the same error. flutter build targets main.self.dart/main.server.dart, so builds still passed, but dart format/flutter analyze of lib/ failed, and so would anything that compiles lib/main.dart. A file without the list is now left alone: no registration and no import. This commit stands on its own and can be dropped if you'd rather keep the old fallback.

Both callers use the shared helper: sync_external_extension_registrations (git/path packages) and sync_client_main_extensions (re-adding a bundled extension the template lists).

The template's entrypoints are not changed. Published gems rely on the import-block markers.

Released gems

0.0.21, 0.0.22 and 0.0.23 can't be fixed. Any app that lists its own extension package keeps failing to build on those versions, and only a new gem release fixes it. An existing build/client left broken by those gems needs no cleanup: the template_refresh contributor copies lib/main.dart, main.self.dart and main.server.dart fresh from the template at the start of every build, so the first build with the fixed gem writes them correctly.

Behavior changes (compat goldens)

Only services_app changes. It is the one fixture with extension packages (compat_git_ext from git, compat_local_ext from a path). Its 25 build goldens that pin those registrations were regenerated. All 234 goldens were checked, and no other golden changed.

  • lib/main.self.dart, lib/main.server.dart: compat_git_ext.Extension(), and compat_local_ext.Extension(), move from the import block into the extensions list, before its // --FAT_CLIENT_START--. File sizes are unchanged.
  • lib/main.dart: no longer edited. It is now identical to the template, so the "files identical" count goes from 188 to 189.

Testing

  • New packages/ruflet/test/build_extension_registration_test.rb. Its entrypoint has the template's shape: FAT_CLIENT blocks in the imports and in the list. It also covers a list with no marker of its own, an unclosed list, a rebuild (no duplicates) and the main.dart wrapper. Three of its tests fail on main, and the main.dart test also fails on the first commit alone.
  • Every packages/ruflet/test/*_test.rb passes, including compat_goldens_test.rb (242 runs).
  • ruby packages/ruflet/test/compat/compat.rb: before the golden regeneration it reported exactly the 25 services_app goldens and nothing else; afterwards, 234 checked, 0 failing.
  • Real build: an app from ruflet new with a path ext_pkg, template e32c873, Flutter 3.41.2. ruflet build web built build/web, and dart format --output=none parses lib/main.dart, lib/main.self.dart and lib/main.server.dart.

insert_missing_extension put a registration before the first
`// --FAT_CLIENT_START--` in the file. The template's main.self.dart and
main.server.dart also bracket imports at the top with those markers, so an
extension package listed in ruflet.yaml (git or path) was registered in the
import block and the entrypoint no longer parsed:

    line 5, column 5 of lib/main.server.dart: Functions must have an
    explicit list of parameters.

Search for the marker only between `final extensions = <RufletExtension>[`
and its closing `];`, and register first in the list when it has no marker
there. The template's markers are unchanged: published gems rely on them.

The services_app goldens, the only fixture with extension packages, change
accordingly: compat_git_ext and compat_local_ext move from the import block
into the list in main.self.dart and main.server.dart. No other golden changes.
The template's lib/main.dart only calls main.self.dart and has no
`final extensions = <RufletExtension>[` list. insert_missing_extension
appended the registration at the end of such a file, so with an extension
package listed in ruflet.yaml lib/main.dart ended in

    Future<void> main() => self_app.main();
        compat_git_ext.Extension(),

and failed to parse with the same "Functions must have an explicit list of
parameters" error. `flutter build` targets main.self.dart or
main.server.dart, so builds passed, but `dart format`/`flutter analyze` of
lib/ and anything that compiles lib/main.dart failed.

Without the list there is nowhere to register: insert_missing_extension now
returns the file as is, and sync_external_extension_registrations skips the
file, import included.

The services_app goldens change only in lib/main.dart, which is now
identical to the template.
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

Successfully merging this pull request may close these issues.

1 participant