Skip to content

fix(npm): vendor the current Dart sources instead of a v0.9.1 snapshot - #61

Merged
charliewwdev merged 2 commits into
mainfrom
fix/npm-vendored-dart-stale
Sep 1, 2026
Merged

fix(npm): vendor the current Dart sources instead of a v0.9.1 snapshot#61
charliewwdev merged 2 commits into
mainfrom
fix/npm-vendored-dart-stale

Conversation

@charliewwdev

Copy link
Copy Markdown
Member

Fixes problem 1 of #52. Also unblocks the Dart fallback that #45, #49 and #50 depend on.

Summary

The npm wrapper runs the server from vendored Dart source whenever a native binary is missing or fails to launch. That vendored tree was frozen at v0.9.1 while lib/ grew to 100 files, so npm users have been running a server ~40 releases old.

That is the exact symptom reported in #52: the published server rejects tap by ref and by coordinates with

-32603 Internal error: Invalid argument(s): Must provide key or text for tap

and that string exists nowhere in v0.9.36 source — only in packaging/npm/dart/lib/src/flutter_skill_client.dart, the stale copy. Current source says "Must provide key, text, or ref for tap".

Why it drifted — three compounding bugs

  1. build.js computed rootDir as path.join(__dirname, '..', '..'), which lands on packaging/, not the repo root. Every source path missed, so the script only ever printed Warning: ... not found and copied nothing.
  2. Even with the path fixed, it copied a hardcoded list of nine files. Everything added since — drivers/, discovery/, bridge/, engine/, protocol/, diagnostics/, cli/tool_handlers/ — was silently skipped.
  3. Nothing ran it during a release. publish-npm checks out the repo and calls npm publish directly, so whatever was committed got shipped.

Changes

  • Mirror whole directories (lib/) instead of an enumerated list, so newly added files can never be missed again.
  • Fix the repo-root path.
  • Fail loudly: a missing expected source file exits non-zero, which aborts npm publish rather than shipping a broken fallback.
  • Verify the generated pubspec.yaml name matches the package: import in bin/server.dart — a rename upstream would otherwise leave the fallback uncompilable (the stale tree had diverged to flutter_skill_npm).
  • Strip dev_dependencies from the vendored pubspec so the pub get the wrapper runs on first launch stays light.
  • Add prepack so npm regenerates the tree before every npm pack / npm publish. The tree stays committed as a safety net, and is regenerated here.

Test plan

  • node scripts/build.jsCopied lib/ (100 files), 102 files vendored for flutter_skill 0.9.36 (was: 7 Dart files at v0.9.1)
  • Vendored copy compiles and serves: flutter pub get && dart run bin/server.dart serverinitialize returns "version":"0.9.36"
  • The reported failure is gone. tools/call tap {x:10,y:20} against the vendored copy now fails with Not connected to Flutter app — i.e. the argument is accepted — instead of Must provide key or text for tap
  • npm pack --dry-run → prepack fires, tarball contains 100 dart/lib files including dart/lib/src/cli/tool_handlers/bf_interaction.dart, dart/lib/src/drivers/flutter_driver.dart, dart/lib/src/discovery/unified_discovery.dart
  • Failure guard: temporarily removed lib/flutter_skill.dart → build exits 1 with required source file is missing, publishing would abort
  • Generated pubspec is name: flutter_skill / version: 0.9.36 / publish_to: 'none', matching package:flutter_skill/... in the entrypoint

Note

Problem 2 of #52 (topmost-route matching) was fixed by #53 and is merged but unreleased. Problem 3 (Semantics-based targeting) is tracked separately.

🤖 Generated with Claude Code

The npm wrapper falls back to running the server from vendored Dart
source whenever a native binary is unavailable, but that tree had been
frozen at v0.9.1 while lib/ grew to 100 files. Users on npm were running
a server nearly forty releases old, which is why tap by `ref` and by
coordinates were rejected with an error string that no longer exists in
the source (issue #52, problem 1).

Two reasons it drifted:

- `build.js` resolved the repository root one directory too high, so
  every source path missed and it only ever printed warnings.
- Even when run, it copied a hardcoded list of nine files. Everything
  added since — drivers/, discovery/, bridge/, engine/, protocol/,
  diagnostics/, cli/tool_handlers/ — was silently skipped.
- Nothing invoked it during a release; `npm publish` shipped whatever
  happened to be committed.

Mirror whole directories rather than an enumerated list, fix the root
path, and abort with a non-zero exit when an expected source file is
missing so a broken tree cannot be published quietly. The generated
pubspec drops dev dependencies and is checked against the entrypoint's
`package:` import, since a rename there would leave the fallback unable
to compile. Wiring the script to `prepack` means npm regenerates the
tree before every `npm pack` and `npm publish`.
`dart analyze` treats warnings as fatal (exit 2), and this unreferenced
declaration was one of the issues keeping it red. Regenerating the
vendored tree in this branch would otherwise have duplicated the warning
into packaging/npm/dart/, so it is removed here rather than separately.

dart analyze now reports no issues at all.
@charliewwdev

Copy link
Copy Markdown
Member Author

Follow-up: dart analyze is now completely clean on this branch (exit 0, No issues found!).

Regenerating the vendored tree removes the two errors it was causing:

error - packaging/npm/dart/bin/server.dart:1:8 - Target of URI doesn't exist: 'package:flutter_skill_npm/src/cli/server.dart'
error - packaging/npm/dart/bin/server.dart:3:33 - The function 'runServer' isn't defined

I also removed the unreferenced _checkForExistingChrome in lib/src/cli/serve.dart in this branch rather than separately — dart analyze treats warnings as fatal, and regenerating the vendored tree would otherwise have duplicated that warning into packaging/npm/dart/.

The dart check here will still show red, for a reason unrelated to this PR: ci.yml pins FLUTTER_VERSION: 3.24.0, but lib/flutter_skill.dart:4552 uses Color.withValues, which needs Flutter 3.27. That needs a workflow edit I could not push (token lacks the workflow scope). Details in #62.

@charliewwdev
charliewwdev merged commit 94c8730 into main Sep 1, 2026
4 of 5 checks passed
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