@@ -73,39 +73,60 @@ dock entries directly via the handle returned by
7373
7474A shorthand for call hook ` devtools:customTabs:refresh ` . It will refresh all custom tabs.
7575
76+ ### Spawning terminals
77+
78+ ** Use Vite DevTools' own terminals host** (` ctx.terminals ` ), reached through the
79+ connected context from [ ` onDevtoolsReady() ` ] ( #ondevtoolsready ) . It spawns and
80+ owns the process and surfaces it in the built-in ** Terminals** dock — no
81+ Nuxt-specific wrapper needed:
82+
83+ ``` ts
84+ import { onDevtoolsReady } from ' @nuxt/devtools-kit'
85+
86+ onDevtoolsReady ((ctx ) => {
87+ // Output-only child process
88+ ctx .terminals .startChildProcess (
89+ { command: ' npm' , args: [' run' , ' dev' ] },
90+ { id: ' my-module:dev' , title: ' Dev Server' , icon: ' logos-npm-icon' },
91+ )
92+
93+ // Fully interactive PTY (powered by `zigpty`, with a graceful pipe fallback)
94+ ctx .terminals .startPtySession (
95+ { command: ' bash' },
96+ { id: ' my-module:shell' , title: ' Shell' , interactive: true },
97+ )
98+ })
99+ ```
100+
101+ If your module needs to keep owning the process itself and merely stream output,
102+ register a read-only session with ` ctx.terminals.register({ id, title, status, stream }) ` .
103+ See the [ Vite DevTools Kit] ( https://github.com/vitejs/devtools ) docs for the full
104+ ` ctx.terminals ` API.
105+
76106### ` startSubprocess() `
77107
78108:: warning
79- ** Deprecated.** ` startSubprocess() ` is soft-deprecated (` NDT_DEP_0004 ` ) in favour
80- of the Vite DevTools terminals host
81- (` nuxt.devtools.terminals.startChildProcess(...) ` ). It still works as a shim. See
82- the [ migration guide] ( /module/migration-v4#ndt_dep_0004 ) .
109+ ** Deprecated — do not use in new code.** ` startSubprocess() ` is soft-deprecated
110+ (` NDT_DEP_0004 ` ) in favour of the Vite DevTools terminals host, used from the
111+ [ ` onDevtoolsReady ` ] ( #ondevtoolsready ) hook
112+ (` onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...)) ` — see
113+ [ Spawning terminals] ( #spawning-terminals ) above). It still works as a shim
114+ (bridged onto ` ctx.terminals ` ), so existing modules keep working, but it emits
115+ the ` NDT_DEP_0004 ` deprecation diagnostic and will be removed in a future major.
116+ See the [ migration guide] ( /module/migration-v4#ndt_dep_0004 ) .
83117::
84118
85- Start a sub process using ` tinyexec ` and create a terminal tab in DevTools.
119+ Legacy usage (module owns the process; output is surfaced as a read-only session
120+ in the built-in ** Terminals** dock):
86121
87122``` ts
88123import { startSubprocess } from ' @nuxt/devtools-kit'
89124
90125const subprocess = startSubprocess (
91- {
92- command: ' code-server' ,
93- args: [
94- ' serve-local' ,
95- ' --accept-server-license-terms' ,
96- ' --without-connection-token' ,
97- ` --port=${port } ` ,
98- ],
99- },
100- {
101- id: ' devtools:vscode' ,
102- name: ' VS Code Server' ,
103- icon: ' logos-visual-studio-code' ,
104- },
126+ { command: ' vite' , args: [' build' , ' --watch' ] },
127+ { id: ' my-module:build' , name: ' Build' , icon: ' ph:terminal-duotone' },
105128)
106- ```
107129
108- ``` ts
109130subprocess .restart ()
110131subprocess .terminate ()
111132```
0 commit comments