diff options
-rw-r--r-- | .changeset/hot-teachers-wave.md | 5 | ||||
-rw-r--r-- | packages/astro/src/cli/info/index.ts | 18 |
2 files changed, 17 insertions, 6 deletions
diff --git a/.changeset/hot-teachers-wave.md b/.changeset/hot-teachers-wave.md new file mode 100644 index 000000000..f13ca5bd6 --- /dev/null +++ b/.changeset/hot-teachers-wave.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Safely bail when the `xclip` command does not exist on Linux when trying to copy to clipboard with `astro info` diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index cfa9aca8f..591d1226b 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -49,13 +49,19 @@ async function copyToClipboard(text: string) { } else if (system === 'win32') { command = 'clip'; } else { - // Unix: check if `xclip` is installed - const output = execSync('which xclip', { encoding: 'utf8' }); - if (output[0] !== '/') { - // Did not find a path for xclip, bail out! - return; + try { + // Unix: check if `xclip` is installed + const output = execSync('which xclip', { encoding: 'utf8' }); + if (output[0] !== '/') { + // Did not find a path for xclip, bail out! + return; + } + command = 'xclip -sel clipboard -l 1'; + } + catch (e) { + // Did not find xclip, bail out! + return } - command = 'xclip -sel clipboard -l 1'; } console.log(); |