From 3b603c47326691a272d10aa7b4516c605ecaab79 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 1 Jun 2023 10:06:37 -0700 Subject: [PATCH] fix: ignore directories.bin if bin is present --- lib/normalize.js | 2 +- test/prepare.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/normalize.js b/lib/normalize.js index bc101cd..b51680f 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -158,7 +158,7 @@ const normalize = async (pkg, { strict, steps }) => { } // expand "directories.bin" - if (steps.includes('binDir') && data.directories?.bin) { + if (steps.includes('binDir') && data.directories?.bin && !data.bin) { const binsDir = path.resolve(pkg.path, path.join('.', path.join('/', data.directories.bin))) const bins = await glob('**', { cwd: binsDir }) data.bin = bins.reduce((acc, binFile) => { diff --git a/test/prepare.js b/test/prepare.js index c73db79..d68488e 100644 --- a/test/prepare.js +++ b/test/prepare.js @@ -95,6 +95,25 @@ t.test('bin', t => { t.strictSame(content.bin, { echo: 'bin/echo' }) }) + t.test('directories.bin with bin', async t => { + const { content } = await pkg.prepare(t.testdir({ + 'package.json': JSON.stringify({ + name: 'bin-test', + directories: { + bin: './bin', + }, + bin: { + echo: './bin/echo', + }, + }), + bin: { + echo: '#!/bin/sh\n\necho "hello world"', + echo2: '#!/bin/sh\n\necho "hello world2"', + }, + })) + t.strictSame(content.bin, { echo: 'bin/echo' }) + }) + t.end() })