Home / File/ shell.ts — astro Source File

shell.ts — astro Source File

Architecture documentation for shell.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  10115483_0549_8783_e6e6_0b4589ba34bd["shell.ts"]
  dc804f3e_b1ea_df4a_3cc9_40b536be6a5d["node:child_process"]
  10115483_0549_8783_e6e6_0b4589ba34bd --> dc804f3e_b1ea_df4a_3cc9_40b536be6a5d
  8f34f3e8_2f0f_1f0d_91dc_c25ece8c8169["node:stream"]
  10115483_0549_8783_e6e6_0b4589ba34bd --> 8f34f3e8_2f0f_1f0d_91dc_c25ece8c8169
  e4593735_c42a_3714_337e_772395e10c40["consumers"]
  10115483_0549_8783_e6e6_0b4589ba34bd --> e4593735_c42a_3714_337e_772395e10c40
  style 10115483_0549_8783_e6e6_0b4589ba34bd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// This is an extremely simplified version of [`execa`](https://github.com/sindresorhus/execa)
// intended to keep our dependency size down
import type { ChildProcess, StdioOptions } from 'node:child_process';
import { spawn } from 'node:child_process';
import type { Readable } from 'node:stream';
import { text as textFromStream } from 'node:stream/consumers';

interface ExecaOptions {
	cwd?: string | URL;
	stdio?: StdioOptions;
	timeout?: number;
}
interface Output {
	stdout: string;
	stderr: string;
	exitCode: number;
}
const text = (stream: NodeJS.ReadableStream | Readable | null) =>
	stream ? textFromStream(stream).then((t) => t.trimEnd()) : '';

let signal: AbortSignal;
export async function shell(
	command: string,
	flags: string[],
	opts: ExecaOptions = {},
): Promise<Output> {
	let child: ChildProcess;
	let stdout = '';
	let stderr = '';
	if (!signal) {
		const controller = new AbortController();
		// Ensure spawned process is cancelled on exit
		process.once('beforeexit', () => controller.abort());
		process.once('exit', () => controller.abort());
		signal = controller.signal;
	}
	try {
		child = spawn(`${command} ${flags.join(' ')}`, {
			cwd: opts.cwd,
			shell: true,
			stdio: opts.stdio,
			timeout: opts.timeout,
			signal,
		});
		const done = new Promise((resolve) => child.on('close', resolve));
		[stdout, stderr] = await Promise.all([text(child.stdout), text(child.stderr)]);
		await done;
	} catch {
		throw { stdout, stderr, exitCode: 1 };
	}
	const { exitCode } = child;
	if (exitCode === null) {
		throw new Error('Timeout');
	}
	if (exitCode !== 0) {
		throw new Error(stderr);
	}
	return { stdout, stderr, exitCode };
}

Domain

Subdomains

Functions

Dependencies

  • consumers
  • node:child_process
  • node:stream

Frequently Asked Questions

What does shell.ts do?
shell.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in shell.ts?
shell.ts defines 2 function(s): shell, text.
What does shell.ts depend on?
shell.ts imports 3 module(s): consumers, node:child_process, node:stream.
Where is shell.ts in the architecture?
shell.ts is located at packages/upgrade/src/shell.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/upgrade/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free