diff options
author | 2023-11-10 18:58:47 +0530 | |
---|---|---|
committer | 2023-11-10 08:28:47 -0500 | |
commit | 7dedd17fc4c48aba31d9d39a10a94cd271b19746 (patch) | |
tree | b1d72a8720cb0ca176ee383f4a5b54652d65396b | |
parent | 49b82edb2c0d5058ec1adaed33d8b027220091c1 (diff) | |
download | astro-7dedd17fc4c48aba31d9d39a10a94cd271b19746.tar.gz astro-7dedd17fc4c48aba31d9d39a10a94cd271b19746.tar.zst astro-7dedd17fc4c48aba31d9d39a10a94cd271b19746.zip |
fix: Astro info throws when xclip is not available (#9042)
* Update index.ts
* Create hot-teachers-wave.md
* Update .changeset/hot-teachers-wave.md
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
---------
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
-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(); |