Description
After upgrading to dprint 0.53.1, WASM plugins hosted on GitHub Releases fail to resolve. The same configuration works on 0.53.0.
Reproduction
dprint.json:
{
"plugins": [
"https://github.com/azais-corentin/cmakefmt/releases/download/v0.2.0/cmakefmt-dprint.wasm"
]
}
Without checksum:
$ dprint check
Error resolving plugin https://github.com/.../cmakefmt-dprint.wasm:
The plugin must have a checksum specified for security reasons since it is not a Wasm plugin.
With checksum:
$ dprint check # (using the suggested @<hash> suffix)
Error resolving plugin https://github.com/.../cmakefmt-dprint.wasm:
Could not resolve plugin type from url or file path: https://release-assets.githubusercontent.com/github-production-release-asset/...
Local file works fine:
$ dprint check --plugins /path/to/cmakefmt-dprint.wasm
# works correctly
Environment
- dprint 0.53.1 (regression)
- dprint 0.53.0 (works)
- Linux x86_64
Analysis
PR #1114 changed crates/dprint/src/plugins/cache.rs to call plugin_kind() on the resolved_source (the post-redirect URL) instead of the original source_reference:
- } else if source_reference.plugin_kind() != Some(PluginKind::Wasm) {
+ } else if resolved_source.plugin_kind() != Some(PluginKind::Wasm) {
plugin_kind() in path_source.rs determines the plugin type by checking if the URL ends with .wasm or .json. GitHub Releases redirect to a CDN URL like:
https://release-assets.githubusercontent.com/github-production-release-asset/<uuid>?sp=r&sv=...
This URL does not end in .wasm, so plugin_kind() returns None, and the plugin is rejected as non-WASM.
The fix in #1114 was correct for process plugins (relative URLs in process plugin configs need to resolve against the redirected URL), but the plugin type detection should still use the original URL since that's what carries the file extension.
Suggested Fix
Use source_reference.plugin_kind() (original URL) for plugin type detection, while keeping resolved_source for everything else (relative URL resolution, caching, etc.):
// plugin type comes from the original URL (which has the .wasm extension)
} else if source_reference.plugin_kind() != Some(PluginKind::Wasm) {
Alternatively, plugin_kind() could also inspect the WASM magic bytes (\0asm) of the downloaded content as a fallback when the URL extension is ambiguous.
Description
After upgrading to dprint 0.53.1, WASM plugins hosted on GitHub Releases fail to resolve. The same configuration works on 0.53.0.
Reproduction
dprint.json:
{ "plugins": [ "https://github.com/azais-corentin/cmakefmt/releases/download/v0.2.0/cmakefmt-dprint.wasm" ] }Without checksum:
With checksum:
Local file works fine:
Environment
Analysis
PR #1114 changed
crates/dprint/src/plugins/cache.rsto callplugin_kind()on theresolved_source(the post-redirect URL) instead of the originalsource_reference:plugin_kind()inpath_source.rsdetermines the plugin type by checking if the URL ends with.wasmor.json. GitHub Releases redirect to a CDN URL like:This URL does not end in
.wasm, soplugin_kind()returnsNone, and the plugin is rejected as non-WASM.The fix in #1114 was correct for process plugins (relative URLs in process plugin configs need to resolve against the redirected URL), but the plugin type detection should still use the original URL since that's what carries the file extension.
Suggested Fix
Use
source_reference.plugin_kind()(original URL) for plugin type detection, while keepingresolved_sourcefor everything else (relative URL resolution, caching, etc.):Alternatively,
plugin_kind()could also inspect the WASM magic bytes (\0asm) of the downloaded content as a fallback when the URL extension is ambiguous.