feat(v3): wails3 migrate - automated v2 to v3 project migration#5758
Draft
taliesin-ai wants to merge 4 commits into
Draft
feat(v3): wails3 migrate - automated v2 to v3 project migration#5758taliesin-ai wants to merge 4 commits into
wails3 migrate - automated v2 to v3 project migration#5758taliesin-ai wants to merge 4 commits into
Conversation
… migration wails3 migrate -d ./myv2project -o ./myv3project converts a Wails v2 project into a v3 project: - Parses wails.json and the declarative options.App literal passed to wails.Run (syntax-only, no module downloads needed) and generates an equivalent programmatic main.go via application.New() + app.Window.NewWithOptions(), preserving user code and comments through textual surgery on just the wails.Run statement and imports. - Maps v2 options to v3 (window geometry, start state, background colour, platform-specific options, single instance, asset server), converts Bind entries into v3 services and bridges the OnStartup/OnDomReady/OnShutdown/OnBeforeClose lifecycle callbacks. - Adds pkg/v2compat/runtime: the v2 runtime API (context-first functions) implemented on the v3 application API, so migrated code only needs its import path rewritten. Covers events, window control, dialogs, clipboard, browser, screens, logging and app control; every function documents its v3 replacement for incremental migration. - Migrates the frontend: regenerates wailsjs/ as a compatibility layer over @wailsio/runtime (runtime shim + Call.ByName binding shims from the parsed bound-struct methods) and adds the npm dependency. - Scaffolds the v3 build system via the init machinery: Taskfile, build/ assets and build/config.yml populated from the v2 metadata (product info, file associations, protocols, bundle id kept as com.wails.<name> so the app keeps its identity). - Transforms go.mod (wails/v2 -> wails/v3, go directive raised), preserving all other requires. - Writes MIGRATION.md documenting every mapped option and any manual steps (menus, custom loggers, EnumBind, ...). Docs: the v2-to-v3 migration guide now leads with the automated path.
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The migrate command now announces its experimental status in the CLI output, the generated MIGRATION.md and the migration guide, with a pointer to the issue tracker for reports and contributions.
The bridge is no longer a public package in the v3 module: its source lives at internal/migrate/v2compat/runtime (compiled, vetted and tested in-repo but not importable) and wails3 migrate copies it into the output project as <module>/v2compat/runtime with a generated-code header explaining it is temporary. This means only migrated projects carry the v2-style API - nobody can adopt it for new code - and there is no sunset obligation on the v3 module: each project deletes its own bridge functions as call sites are ported to the v3 API, and removes the package when nothing imports it. Import rewriting now targets the project-local path, and the bridge is only emitted when the project actually needs it (v2 runtime imports or lifecycle hooks).
…at layers Half-migrated code helps nobody, and compatibility shims invite new code onto the old API. The migrate command now draws a hard line: Migrated fully (deterministic): - project scaffold, Taskfile, build assets, config.yml from wails.json - main.go rewritten around application.New()/NewWithOptions with the options mapped; lifecycle hooks wired natively (ApplicationStarted event, WindowRuntimeReady event, Options.OnShutdown, ShouldQuit) - go.mod v2 -> v3; frontend copied with @wailsio/runtime added Documented instead of migrated: - every call into the v2 runtime package, listed in MIGRATION.md by file:line with its concrete v3 replacement; the sources are copied untouched, so the compiler points at exactly the listed locations until they are ported - every frontend wailsjs import, with the @wailsio/runtime equivalent and the generate-bindings workflow; the generated wailsjs directory is not carried over (it is v2 build output and cannot work with v3) Removed: the v2compat runtime bridge and the generated wailsjs shims. go mod tidy is skipped (with a warning) while v2 call sites remain, since tidying would re-add the v2 dependency and let old calls compile only to fail at runtime; MIGRATION.md spells this out.
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.
Summary
Warning
This command is experimental. It handles the common v2 project shapes well, but your mileage may vary: generated projects should be reviewed and tested thoroughly. Please report anything it gets wrong via the issue tracker; PRs improving the tool are very welcome. The CLI, the generated MIGRATION.md and the docs all carry this notice.
wails3 migrate -d ./myv2project -o ./myv3projecthelps convert a Wails v2 project into a Wails v3 project.The design principle: migrate what maps deterministically, document the rest, and never leave code half-rewritten. The tool does not modify application logic and does not generate compatibility layers - code that still uses the v2 API is copied untouched, every such location is enumerated in a generated
MIGRATION.mdwith its concrete v3 replacement, and the compiler points at exactly those locations until they are ported.What it migrates
Parse (syntax-only
go/parser, works without the v2 module in the module cache):wails.json(with v2's defaulting rules),go.mod, theoptions.Appliteral insidewails.Run(...), theBindentries, lifecycle callbacks and embed directives.Generate:
main.gorewritten aroundapplication.New()+app.Window.NewWithOptions()via textual surgery: only thewails.Runstatement and the import block are replaced, all other user code and comments are preserved byte-for-byte, then gofmt'd. The error-handling shape is preserved.mac.TitleBarHiddenInset()->application.MacTitleBarHiddenInset).Titlemaps to bothOptions.Nameand the window title.Bind->Services. Lifecycle hooks are wired natively in the generated main file:OnStartup->events.Common.ApplicationStarted,OnDomReady->events.Common.WindowRuntimeReady,OnShutdown->Options.OnShutdown,OnBeforeClose-> aShouldQuitwrapper. Public v3 API only, no shims.frontend:install),build/assets andbuild/config.ymlpopulated from the v2 metadata. File associations and protocols move fromwails.jsonintoconfig.yml(with anUpdateBuildAssetspass so plists/manifests pick them up). The bundle id keeps v2'scom.wails.<name>convention so migrated apps keep their identity. The v2build/appicon.pngis preserved.go.mod:wails/v2->wails/v3(atversion.LatestStable()), go directive raised to 1.24, all other requires kept.@wailsio/runtimeadded topackage.json. The generatedwailsjs/directory is not carried over - it is v2 build output that cannot work against a v3 backend.What it documents instead of migrating
MIGRATION.mdcontains a Port these to the v3 API table:runtimepackage, byfile:line, with the concrete v3 replacement (e.g.runtime.EventsEmit->app.Event.Emit(name, data...);runtime.WindowSetTitle->window.SetTitle(title)viaapp.Window.Current(); dialogs -> the v3 builder API;MessageDialog-> button callbacks). ~60 v2 functions are mapped.wailsjs/runtimeorwailsjs/go/..., with the@wailsio/runtimeequivalent and thewails3 generate bindingsworkflow.EnumBind, custom Windows themes, ...) and notes on everything else the tool did.Deliberate consequences:
go mod tidyis skipped (with a warning) while v2 call sites remain: tidying would re-add the v2 dependency and let the old calls compile, only to fail at runtime inside a v3 application. MIGRATION.md spells this out; after porting, the user runs tidy +wails3 generate bindings.Verified
internal/migrate), plus end-to-end command tests (internal/commands) covering the full run, the MIGRATION.md checklist contents, untouched-source guarantees, output-safety guards and non-v2 rejection.OnStartup(ApplicationStarted event) fired, confirmed via a marker file.@wailsio/runtime@3.0.0-alpha.95.gofmt/go vetclean; fullinternal/commandsandinternal/migratesuites pass.Docs
The Migrating from v2 to v3 guide now leads with the automated path, describing exactly what is migrated and what is documented, under an Experimental caution.
Notes for review
pkg/v2compat, then generated into the project) and generatedwailsjsJS shims. Both were removed by design decision: compatibility layers invite code to stay on (or newly adopt) the v2 API, and half-automatic rewriting risks silently changing behaviour. The advise-first model keeps the tool honest. The history is in the branch commits if we ever want to revisit.templates.InstallmutatesProjectDir, chdirs and prints via barefmt.Print; the migrate command works around all three (restores cwd, silences stdout for the scratch scaffold). Happy to refactor Install instead if preferred.go.modusesversion.LatestStable()(version.txt) rather thanv3.0.0-dev, so the require always resolves.