diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 5f36d477cd..348d2fae3b 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -119,36 +119,36 @@ export function readFromClipboard() { let args: Array = []; if (system === 'darwin') { - command = 'pbpaste'; + command = 'pbpaste'; } else if (system === 'win32') { - command = 'powershell'; - args = ['-command', 'Get-Clipboard']; + command = 'powershell'; + args = ['-command', 'Get-Clipboard']; } else { - const unixCommands: Array<[string, Array]> = [ - ['xclip', ['-sel', 'clipboard', '-o']], - ['wl-paste', []], - ]; - for (const [unixCommand, unixArgs] of unixCommands) { - try { - const output = spawnSync('which', [unixCommand], { encoding: 'utf8' }); - if (output.stdout.trim()) { - command = unixCommand; - args = unixArgs; - break; - } - } catch { - continue; - } + const unixCommands: Array<[string, Array]> = [ + ['xclip', ['-sel', 'clipboard', '-o']], + ['wl-paste', []], + ]; + for (const [unixCommand, unixArgs] of unixCommands) { + try { + const output = spawnSync('which', [unixCommand], { encoding: 'utf8' }); + if (output.stdout.trim()) { + command = unixCommand; + args = unixArgs; + break; + } + } catch { + continue; } + } } if (!command) { - throw new Error('Clipboard read command not found!'); + throw new Error('Clipboard read command not found!'); } const result = spawnSync(command, args, { encoding: 'utf8' }); if (result.error) { - throw result.error; + throw result.error; } return result.stdout.trim(); } diff --git a/packages/astro/test/cli.test.js b/packages/astro/test/cli.test.js index 4bacc3ec22..ce30b12bbd 100644 --- a/packages/astro/test/cli.test.js +++ b/packages/astro/test/cli.test.js @@ -2,13 +2,13 @@ import assert from 'node:assert/strict'; import { promises as fs, readFileSync } from 'node:fs'; import { isIPv4 } from 'node:net'; import { join } from 'node:path'; +import { platform } from 'node:process'; import { Writable } from 'node:stream'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { stripVTControlCharacters } from 'node:util'; -import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js'; import { readFromClipboard } from '../dist/cli/info/index.js'; -import { platform } from 'node:process'; +import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js'; describe('astro cli', () => { const cliServerLogSetupWithFixture = (flags, cmd) => { @@ -88,14 +88,16 @@ describe('astro cli', () => { assert.equal(proc.exitCode, 0); // On Linux we only check if we have Wayland or x11. In Codespaces it falsely reports that it does have x11 - if(platform === 'linux' && ((!process.env.WAYLAND_DISPLAY && !process.env.DISPLAY) || process.env.CODESPACES)) { + if ( + platform === 'linux' && + ((!process.env.WAYLAND_DISPLAY && !process.env.DISPLAY) || process.env.CODESPACES) + ) { assert.ok(proc.stdout.includes('Please manually copy the text above')); } else { assert.ok(proc.stdout.includes('Copied to clipboard!')); const clipboardContent = await readFromClipboard(); assert.ok(clipboardContent.includes(`v${pkgVersion}`)); } - }); it(