MCPcopy
hub / github.com/SBoudrias/Inquirer.js / runAsync

Method runAsync

packages/external-editor/src/index.ts:107–143  ·  view source on GitHub ↗
(callback?: StringCallback)

Source from the content-addressed store, hash-verified

105 }
106
107 public runAsync(callback?: StringCallback): Promise<string> {
108 this.createTempFile();
109 const promise = new Promise<void>((resolve, reject) => {
110 try {
111 const editorProcess = spawn(this.editor.bin, this.editorArgs(), {
112 shell: false,
113 stdio: 'inherit',
114 });
115 editorProcess.once('error', (launchError) => {
116 reject(new LaunchEditorError(launchError));
117 });
118 editorProcess.once('exit', (code: number | null) => {
119 this.lastExitStatus = code ?? 0;
120 resolve();
121 });
122 } catch (launchError) {
123 reject(new LaunchEditorError(launchError));
124 }
125 })
126 .then(() => {
127 this.readTemporaryFile();
128 return this.text;
129 })
130 .finally(() => {
131 this.cleanup();
132 });
133
134 if (callback) {
135 promise.then(
136 (text) => callback(undefined, text),
137 (err: unknown) =>
138 callback(err instanceof Error ? err : new Error(String(err)), undefined),
139 );
140 }
141
142 return promise;
143 }
144
145 private cleanup(): void {
146 if (!this.tempDir) return;

Callers 2

index.test.tsFile · 0.80
editAsyncFunction · 0.80

Calls 4

createTempFileMethod · 0.95
editorArgsMethod · 0.95
readTemporaryFileMethod · 0.95
cleanupMethod · 0.95

Tested by

no test coverage detected