Resolve injected client using package_config in AOT mode#2801
Resolve injected client using package_config in AOT mode#2801jyameo wants to merge 4 commits intodart-lang:mainfrom
Conversation
| // snapshot. | ||
| try { | ||
| if (Platform.script.scheme == 'file') { | ||
| final packageConfig = await findPackageConfig( |
There was a problem hiding this comment.
What packageConfig does this actually find here? I'm confused about how there could be one when this is running in AOT mode so it makes me suspect this is just finding some random packageConfig on your local machine that happens to some entry in it that works.
That could explain why this doesn't work on CI when the test runs since it is starting from a clean state.
There was a problem hiding this comment.
Nick's right. This method checks for .dart_tool/package_config.json in the CWD, and if it can't find it, it checks for .dart_tool/package_config.json in the parent directory. If it still can't find it, it repeats the process until we hit the root directory.
We somehow need to be able to determine the package:dwds version being used, find the PUB_CACHE, and search for the directory for the correct version of DWDS. That's unfortunately going to be brittle since an installed, precompiled webdev instance doesn't require its dependencies to still be present in the PUB_CACHE.
@dcharkes, this seems like something that should be solved by packaging client.js with webdev as part of dart install. Can you provide any guidance here? 😄
There was a problem hiding this comment.
I don't have enough context here. DWDS is called from webdev directly?
Why are you finding the package config here? For what purpose?
I believe webdev was partially fixed to be able to work via dart install:
DevToolsServer.serveDevTools()throws while spawning DTD when run in AOT mode #2759- Webdev + dart install + Flutter + Windows #2758
With dart install you cannot rely on:
- Having access to your own source code.
- Having access to a Dart SDK. (You can
dart installsomething and then remove the Dart or Flutter SDK and the installed apps should keep working.)
Can you explain in more detail what dwds is trying to do here?
@dcharkes, this seems like something that should be solved by packaging
client.jswithwebdevas part ofdart install. Can you provide any guidance here? 😄
I have no idea what this means.
There was a problem hiding this comment.
You are absolutely right guys! My apologies. I had mistakenly assumed that globally activated packages would preserve their .dart_tool/package_config.json layout relative to the generated snapshot inside ~/.pub-cache/. I'll continue to investigate this
There was a problem hiding this comment.
Dart data assets are not here yet:
As discussed offline with @bkonyi, until data assets are in Dart standalone, the best way to bundle a file is to just have it as a string or base64 encoded byte array.
There was a problem hiding this comment.
Thanks for the feedback guys! I will use the embedded string approach moving forward.
|
Closing this PR. Will send out another PR using the approach discussed above. |
Description
Fixes a
StateError: Cannot resolve "package:dwds/src/injected/client.js"that occurs when usingwebdev servein an AOT-compiled environment (e.g.dart pub global activate webdev).Because Dart strips the default package configuration mapping inside AOT snapshots,
Isolate.resolvePackageUri()evaluates tonull. This PR introduces a graceful natively-supported fallback viapackage_configthat reads the active snapshot's URI viaPlatform.scriptto accurately locate the host's.dart_tool/package_config.json. This successfully resolves the injected debugging client out of.pub-cache.Changes
dwds/lib/src/handlers/injector.dart: Implemented afindPackageConfigfallback block for whenIsolate.resolvePackageUrinatively fails.Testing
dart testexecutes test isolates from temporary OS cache directories that physically lack a.dart_tool/package_config.jsonfolder hierarchy, which inherently breaks thePlatform.scriptupwards traversal).Related to #2761