Stop one dart:io type from hiding the package from web - #248
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #248 +/- ##
=======================================
Coverage 77.84% 77.84%
=======================================
Files 81 82 +1
Lines 6395 6395
=======================================
Hits 4978 4978
Misses 1417 1417
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
pub.dev listed android, ios, windows, linux and macos and not web. That also keeps the package out of any search narrowed to web, so it costs discoverability rather than a badge. The cause was one type. `SftpFile.downloadToRandomAccess` takes a `dart:io` `RandomAccessFile`, and naming it from the SFTP library made pana classify the whole package as unavailable there, even though everything else compiled and ran and 4.0.0 had already made the ciphers and SFTP work under dart2js. The method moves to an `SftpFileDownload` extension in its own library, exported conditionally the way `SSHSocket` and dynamic forwarding already are. Nothing changes for a caller on the VM: same import from `package:dartssh2/dartssh2.dart`, same call. On the web the extension is absent, along with the `RandomAccessFile` it would need. The extension reaches back through `isClosed`, already public, and `readChunk`, which was `_readChunk` and is now `@internal`. That one method is the entire seam. `_ReadCompletion` was used by nothing else so it moved too, and the two size constants are redeclared rather than widening the surface further. Saying `platform:web` on pub.dev is a stronger claim than a paragraph in the README, so CI now checks it. Everything that ran under `-p chrome` until now proved the pieces compile and behave, and none of it put a packet on a wire, which is the gap that let every AEAD cipher and the whole of SFTP sit broken on the web until 4.0.0 with a green suite the whole time. So the browser now runs against the same sshd container the VM interop tests use, through `tool/ws_bridge.dart`, because a browser has no TCP socket of its own. Four tests: a handshake, a command, a session pinned to aes256-gcm because its nonce counter is the code that threw under dart2js, and an SFTP round trip because every size and offset on the wire is a 64-bit field. The socket they connect through is the WebSocket one the README tells web users to write, so it doubles as a worked example. They skip when the bridge is not there, the way the VM interop tests skip without the server, decided by probing the bridge rather than by a compile-time define: `dart test` has neither `--define` nor `--dart2js-args`, and a browser has no `Platform.environment`. Verified: pana reports `platform:web` on this branch and not on main, and the four browser tests pass in CI against the real server. Project coverage is unchanged at 4978/6395, the lines codecov reports as new being the same error paths that were already uncovered before the move.
vicajilau
force-pushed
the
feat/web-platform
branch
from
September 4, 2026 06:33
e897277 to
bdcece8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pub.dev lists dartssh2 for android, ios, windows, linux and macos, and not web. That is not just a badge: pub.dev's platform filter means the package does not appear at all in a search narrowed to web.
The cause is a single type.
SftpFile.downloadToRandomAccesstakes adart:ioRandomAccessFile, and naming it from the SFTP library was enough for pana to classify the whole package as unavailable there, even though everything else compiled and ran and 4.0.0 had already fixed the ciphers and SFTP under dart2js.What changed
The method moves to an
SftpFileDownloadextension inlib/src/sftp/sftp_file_io.dart, exported conditionally the waySSHSocketand dynamic forwarding already are.Non-breaking on the VM. Same
package:dartssh2/dartssh2.dartimport, samefile.downloadToRandomAccess(raf)call. On the web the extension is absent, along with theRandomAccessFileit would have needed.The extension reaches back into
SftpFilethroughisClosed, which was already public, andreadChunk, which was_readChunkand is now@internal. That one method is the entire seam._ReadCompletionwas used by nothing else so it moved with the method, and the two size constants are redeclared in the new library rather than widening the internal surface further.Verified with pana rather than argued
Same tool pub.dev scores with:
dart formatanddart analyze --fatal-infosclean, 703 tests passing.Note
I tried the cheaper version first, a conditional
import 'dart:io' if ...with a stubRandomAccessFile, and it does not work. That trick is for types the package hands back, not types a caller passes in: the stub class and the real one are unrelated, so every existing call site stops compiling. This route avoids that entirely.README gains a line saying
downloadToRandomAccessis the one thing not available on the web, alongside the existing ChaCha20-Poly1305 caveat.