feat(commands)!: defineCommand migration, lazy registration, in-process dispatch and command-owned key shortcuts - #6153
Draft
edusperoni wants to merge 19 commits into
Draft
edusperoni wants to merge 19 commits into
edusperoni wants to merge 19 commits into
Conversation
Options and arguments are declared on the definition and validated before run. Setup runs ahead of argument enforcement so a definition can derive its arguments; a redeclared CLI option keeps whatever it leaves unspecified; unknown options are tolerated instead of skipping validation; objectOption covers --env.* style values; a missing required argument keeps the command's preamble in the error.
Platform validation, dynamic delegation, native-add and widget, test, create/install/post-install-cli/help, enforced-parameter, device, self-contained, platform, plugin and hooks, open|*, and the rest. Class-based surfaces the migration left without callers are deprecated rather than removed, since extensions may import them.
… type registerCommand takes one shape and registers in one call, off the global binding and into the loading context's injector; built-in commands load on first use through a shared helper; getInjector becomes getRootInjector. Package-manager commands register from their real path, dev-post-install is reachable again, and a mistyped subcommand shows help in the terminal.
A command can run another in process without exiting on failure; a definition's setup state is scoped to one invocation; DeferredCommandResult is a discriminated union; the command-name types an extension needs are exported from the contracts. BREAKING CHANGE: ctx.arguments is now ctx.params on the command context.
ns start's key handling becomes a declarative table over a caller-supplied context, with state on the context and capabilities on the injector; the key-command surface leaves the injector facade. Failures from the spawned run children surface in the parent, and NS_NO_OPEN keeps the CLI from launching a browser where nobody is watching.
KeyShortcutRegistry is a contract with disposable registrations; the engine resolves help and dispatch through it, so an entry registered at runtime takes effect immediately. The shared entries become builders, a defineCommand may declare the keys it answers to, and ns run and ns debug get their own tables behind NS_COMMAND_SHORTCUTS (default off).
Stopping a bundler only sent SIGINT and returned, so a restart could spawn a replacement while the old watcher was still alive. The stale child's exit then evicted the replacement's map entry, and a compilation finishing on it still reached the prepare controller. Await the child's exit (escalating to SIGKILL), detach its output and IPC handlers, and key every eviction on process identity. The prepare controller now keeps its compilation handler per platform, so stopping one platform no longer leaves the other's listener attached.
r restarts the app of the running session without preparing, building or syncing; R prepares again first and rebuilds the native app only if needed; B always rebuilds it. The help hint is repeated once a burst of syncs settles, and a restart stays on the devices the session was given instead of every device attached to the platform.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks 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 |
A command's services type is now read off its setup function with ReturnType instead of being declared beside it and kept in sync by hand.
…oken The adapter now builds a child injector per invocation providing COMMAND_CONTEXT, and runs setup, canExecute, run, postRun and shortcuts under it. Handler signatures are unchanged; the token is the way a service or a field initializer reaches the context without threading it through. The provider reads the stage's own context, and nothing outside an invocation can resolve the token.
Command(meta) returns a base class whose static definition is a real defineCommand result: the handlers become methods, the instance is the setup result, and the adapter still only ever sees definitions. The definition is a static getter, so it resolves the subclass it is read through and caches on that constructor. Registration, the name-literal check and the extension manifest path take either form. COMMAND_CONTEXT is promoted to nativescript/contracts, which is what the base class reads in its field initializer.
platform|clean, update and device|*list are written as Command() classes, with their services as inject() fields and the constructor doing the initializeProjectData() work setup did. The per-platform device listings stay in the object form: they are generated from one function, which is what that form is for.
canExecute opens the invocation with the context it builds; execute and postCommandAction reuse it, so every stage, the class instance and COMMAND_CONTEXT hold the same object.
canExecuteCommand(name, args) resolves a registered command and primes its options exactly as runCommand does, then returns its own canExecute verdict. The child builds its setup from its own services, so a command can reuse another's precondition without importing its handlers.
The commands with real internal structure - state shared between canExecute and run, values derived once per invocation, several private steps - are classes now, with one inject() field per dependency and the handlers as methods. Long handlers are split into private methods along the seams that were already there. EmbedCommand asks prepare whether it could run instead of importing its canExecute, which is what canExecuteCommand exists for.
A simple command is now one defineCommand call with its handlers written inline, where ctx is typed by inference: the exported setupX/runX/canExecuteX functions and the IXServices and XCommandContext aliases nothing else read are gone. Handlers inject what they use at their own top, before the first await. No command hands another a bag of services any more. injectPlatformCommandServices and the setupX bundles are deleted; the shared platform checks take the context and resolve through ctx.injector. A setup that survives is side-effect only - the eager initializeProjectData that has to land ahead of the arguments policy.
Says that a handler resolves its own dependencies at its top, that services are never bundled or shared between commands, and that setup is optional sugar for one command. Documents canExecuteCommand as the way to reuse another command's precondition, and sharpens which authoring form fits which command.
CommandsService is the API a command or plugin runs or consults another command through: runCommand and canExecuteCommand take the registered name or the definition or class it was registered from. The free helpers stay as convenience over it; the *InProcess methods are deprecated.
A name is looked up in the registry; a definition or Command() class is built and run as the caller holds it, registered or not, its first name serving only hooks and reporting.
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
Modernizes how the CLI defines, registers and dispatches its own commands, and turns the
ns startkey handling into a shortcut system that any command can own.Commands
defineCommandfor the CLI's own commands. Every built-in command is now a declarative definition: options and arguments are declared on it and validated beforerun,setupruns ahead of argument enforcement, and unknown options are tolerated rather than skipping validation. Class-based surfaces the migration left without callers are deprecated, not removed, since extensions may import them.registerCommandhas one shape and registers in one call, off the global binding and into the loading context's injector. Built-in commands load on first use.getInjectorisgetRootInjector.DeferredCommandResultis a discriminated union, and the command-name types an extension needs are exported from the contracts.Key shortcuts
ns start's keys become a table over a caller-supplied context; the key-command surface leaves the injector facade.KeyShortcutRegistryis a contract with disposable registrations. Help and dispatch resolve through it, so an entry registered at runtime takes effect immediately. AdefineCommandmay declare the keys it answers to.rrestarts the app of the running session without preparing, building or syncing.Rprepares again first and rebuilds the native app only if the change scan says so.Balways rebuilds it.ns startforwards all three to its children.› press ? to list shortcutsline is repeated once a burst of syncs settles instead of scrolling away.Fixes found along the way
ns startsurfaces failures from its spawned run children.NS_NO_OPENkeeps the CLI from launching a browser where nobody is watching.Gating
Standalone-command shortcuts (
ns run,ns debug) are behindNS_COMMAND_SHORTCUTS=1and default off. With the flag unset,ns start, its children, and the standalone commands behave as before.Breaking change
ctx.argumentsis nowctx.paramson the command context (commitfeat(commands)!).Testing
npm test: 124 files, 2019 passed, 9 skipped.Not in this PR
ns startchildren instead of TTY sniffing; children advertising their shortcuts over IPC.