Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
if: startsWith(matrix.os, 'ubuntu')
run: melos test:dart --no-select

- name: Test flutter_gen_core against both xml majors (6.x and 7.x)
if: startsWith(matrix.os, 'ubuntu')
run: melos test:xml-matrix

- name: Run tests for Flutter packages
if: startsWith(matrix.os, 'ubuntu')
run: melos test:flutter --no-select
Expand Down
4 changes: 4 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ scripts:
bash ./scripts/coverage.sh packages/core
description: bash ./scripts/coverage.sh packages/core

test:xml-matrix:
run: dart scripts/test_xml_versions.dart
description: Run flutter_gen_core tests against both supported xml majors (6.x and 7.x)

publish:force:
run: dart pub publish -f
exec:
Expand Down
3 changes: 1 addition & 2 deletions packages/core/lib/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class _Color {
_Color.fromXmlElement(XmlElement element)
: this(
element.getAttribute('name')!,
// ignore: deprecated_member_use
element.text,
element.innerText,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new API introduced in v7? If yes then it's not compatible with v6 then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it appeared earlier. I'll find a proof

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-06-06 at 22 37 25 it was introduced in 4.2.0 and deprecated in 6.3.0

element.getAttribute('type')?.split(' ') ?? List.empty(),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
path: ^1.8.0
yaml: ^3.0.0
mime: '>=1.0.0 <3.0.0'
xml: ^6.0.0
xml: '>=6.0.0 <8.0.0'
dartx: ^1.0.0
color: ^3.0.0
collection: ^1.15.0
Expand Down
134 changes: 134 additions & 0 deletions scripts/test_xml_versions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Verify flutter_gen_core works against every supported major `xml` version.
//
// The package declares `xml: '>=6.0.0 <8.0.0'`, but a normal `dart pub get`
// only ever resolves one major: `image` (a transitive dependency) pins `xml`,
// so its newest releases force `xml` 7.x. As a result the normal `melos test`
// never exercises the 6.x line.
//
// This script pins each major in turn via a temporary `pubspec_overrides.yaml`
// (gitignored) and runs the core test suite against it, so a regression on
// either xml 6.x or 7.x is caught.
//
// The 6.x pass also pins `image` below 4.9.0: `image` 4.9.0+ requires `xml`
// ^7.0.1, so a downstream package constrained to `xml` 6.x resolves `image`
// to its last 6.x-compatible release (4.8.0). Pinning only `xml` would instead
// leave the newest `image` overridden onto an incompatible `xml` and fail to
// compile, which is not a real resolution any consumer could hit.
//
// It is pure Dart (only `dart:io`) so it runs identically on Linux, macOS and
// Windows. The xml 7.x pass requires Dart >= 3.11; on older toolchains it is
// skipped with a warning instead of failing.
//
// Run via `melos test:xml-matrix` or `dart scripts/test_xml_versions.dart`.

import 'dart:io';

Future<void> main() async {
final coreDir = Directory('${_repoRoot().path}/packages/core');
final override = File('${coreDir.path}/pubspec_overrides.yaml');

// Always remove the temporary override and re-resolve so the working tree
// and lockfile are left in their default state, even if a pass fails.
void cleanup() {
if (override.existsSync()) override.deleteSync();
Process.runSync(
Platform.resolvedExecutable,
['pub', 'get'],
workingDirectory: coreDir.path,
);
}

try {
// image 4.9.0+ requires xml ^7.0.1, so the xml 6.x pass must also pin
// image to its last 6.x-compatible release. This mirrors what pub resolves
// for a downstream package constrained to xml 6.x.
await _runPass(
'^6.0.0',
coreDir,
override,
extraOverrides: {'image': "'>=4.5.4 <4.9.0'"},
);

final dart = _dartVersion();
if (dart.major > 3 || (dart.major == 3 && dart.minor >= 11)) {
await _runPass('^7.0.0', coreDir, override);
} else {
stdout.writeln('\n⚠️ Skipping xml 7.x pass: requires Dart >= 3.11 '
'(found ${dart.major}.${dart.minor}).');
}
} catch (error) {
cleanup();
stderr.writeln('\n❌ $error');
exit(1);
}

cleanup();
stdout
.writeln('\n✅ flutter_gen_core passed against all checked xml versions.');
}

Future<void> _runPass(
String constraint,
Directory coreDir,
File override, {
Map<String, String> extraOverrides = const {},
}) async {
stdout.writeln('\n========================================================');
stdout.writeln(' flutter_gen_core test pass — pinning xml: $constraint');
stdout.writeln('========================================================');
final overrides = StringBuffer('dependency_overrides:\n xml: $constraint\n');
extraOverrides.forEach((name, c) => overrides.writeln(' $name: $c'));
override.writeAsStringSync(overrides.toString());
await _dart(['pub', 'get'], coreDir);
stdout.writeln('-> resolved xml ${_resolvedXmlVersion(coreDir)}');
await _dart(['test'], coreDir);
}

/// Runs `dart <args>` in [cwd], streaming output, and throws on failure.
Future<void> _dart(List<String> args, Directory cwd) async {
final process = await Process.start(
Platform.resolvedExecutable,
args,
workingDirectory: cwd.path,
mode: ProcessStartMode.inheritStdio,
);
final code = await process.exitCode;
if (code != 0) {
throw 'dart ${args.join(' ')} failed (exit $code) in ${cwd.path}';
}
}

/// Parses the running Dart SDK version, e.g. "3.11.3 (stable) (...)".
({int major, int minor}) _dartVersion() {
final parts = Platform.version.split(' ').first.split('.');
return (major: int.parse(parts[0]), minor: int.parse(parts[1]));
}

/// Reads the resolved `xml` version out of `packages/core/pubspec.lock`.
String _resolvedXmlVersion(Directory coreDir) {
final lock = File('${coreDir.path}/pubspec.lock');
if (!lock.existsSync()) return 'unknown';
final lines = lock.readAsLinesSync();
for (var i = 0; i < lines.length; i++) {
if (lines[i].trimRight() == ' xml:') {
for (var j = i + 1;
j < lines.length && lines[j].startsWith(' ');
j++) {
final match = RegExp(r'version:\s*"?([^"\s]+)"?').firstMatch(lines[j]);
if (match != null) return match.group(1)!;
}
}
}
return 'unknown';
}

/// Locates the melos workspace root by walking up from this script's location,
/// falling back to the current directory (melos runs scripts from the root).
Directory _repoRoot() {
var dir = File.fromUri(Platform.script).parent;
while (dir.path != dir.parent.path) {
if (File('${dir.path}/melos.yaml').existsSync()) return dir;
dir = dir.parent;
}
return Directory.current;
}
Loading