diff --git a/.changeset/five-badgers-repeat.md b/.changeset/five-badgers-repeat.md new file mode 100644 index 0000000000..7ce1e8f9d7 --- /dev/null +++ b/.changeset/five-badgers-repeat.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-setup": patch +--- + +A summary should be printed. diff --git a/packages/plugin-commands-setup/src/setup.ts b/packages/plugin-commands-setup/src/setup.ts index d07434f007..26f71d89b0 100644 --- a/packages/plugin-commands-setup/src/setup.ts +++ b/packages/plugin-commands-setup/src/setup.ts @@ -47,22 +47,26 @@ export async function handler ( async function setupShell (configFile: string, pnpmHomeDir: string) { if (!fs.existsSync(configFile)) return `Could not setup pnpm. No ${configFile} found` const configContent = await fs.promises.readFile(configFile, 'utf8') - if (configContent.includes('PNPM_HOME')) return '' + if (configContent.includes('PNPM_HOME')) { + return `PNPM_HOME is already in ${configFile}` + } await fs.promises.writeFile(configFile, `${configContent} export PNPM_HOME="${pnpmHomeDir}" export PATH="$PNPM_HOME:$PATH" `, 'utf8') - return '' + return `Updated ${configFile}` } async function setupFishShell (pnpmHomeDir: string) { const configFile = path.join(os.homedir(), '.config/fish/config.fish') if (!fs.existsSync(configFile)) return `Could not setup pnpm. No ${configFile} found` const configContent = await fs.promises.readFile(configFile, 'utf8') - if (configContent.includes('PNPM_HOME')) return '' + if (configContent.includes('PNPM_HOME')) { + return `PNPM_HOME is already in ${configFile}` + } await fs.promises.writeFile(configFile, `${configContent} set -gx PNPM_HOME "${pnpmHomeDir}" set -gx PATH "$PNPM_HOME" $PATH `, 'utf8') - return '' + return `Updated ${configFile}` } diff --git a/packages/plugin-commands-setup/test/setup.test.ts b/packages/plugin-commands-setup/test/setup.test.ts index bb2724c9bc..ee87fe3dc3 100644 --- a/packages/plugin-commands-setup/test/setup.test.ts +++ b/packages/plugin-commands-setup/test/setup.test.ts @@ -17,9 +17,10 @@ test('PNPM_HOME is added to ~/.bashrc', async () => { tempDir() fs.writeFileSync('.bashrc', '', 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^Updated /) const bashRCContent = fs.readFileSync('.bashrc', 'utf8') expect(bashRCContent).toEqual(` export PNPM_HOME="${__dirname}" @@ -35,9 +36,10 @@ export PNPM_HOME="pnpm_home" export PATH="$PNPM_HOME:$PATH" `, 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^PNPM_HOME is already in /) const bashRCContent = fs.readFileSync('.bashrc', 'utf8') expect(bashRCContent).toEqual(` export PNPM_HOME="pnpm_home" @@ -50,9 +52,10 @@ test('PNPM_HOME is added to ~/.zshrc', async () => { tempDir() fs.writeFileSync('.zshrc', '', 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^Updated /) const bashRCContent = fs.readFileSync('.zshrc', 'utf8') expect(bashRCContent).toEqual(` export PNPM_HOME="${__dirname}" @@ -68,9 +71,10 @@ export PNPM_HOME="pnpm_home" export PATH="$PNPM_HOME:$PATH" `, 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^PNPM_HOME is already in /) const bashRCContent = fs.readFileSync('.zshrc', 'utf8') expect(bashRCContent).toEqual(` export PNPM_HOME="pnpm_home" @@ -84,9 +88,10 @@ test('PNPM_HOME is added to ~/.config/fish/config.fish', async () => { fs.mkdirSync('.config/fish', { recursive: true }) fs.writeFileSync('.config/fish/config.fish', '', 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^Updated /) const bashRCContent = fs.readFileSync('.config/fish/config.fish', 'utf8') expect(bashRCContent).toEqual(` set -gx PNPM_HOME "${__dirname}" @@ -103,9 +108,10 @@ set -gx PNPM_HOME "pnpm_home" set -gx PATH "$PNPM_HOME" $PATH `, 'utf8') homedir['mockReturnValue'](process.cwd()) - await setup.handler({ + const output = await setup.handler({ pnpmHomeDir: __dirname, }) + expect(output).toMatch(/^PNPM_HOME is already in /) const bashRCContent = fs.readFileSync('.config/fish/config.fish', 'utf8') expect(bashRCContent).toEqual(` set -gx PNPM_HOME "pnpm_home"