From 3c0bdc25364bf4c88e40879532ad518348114a70 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Wed, 23 Jun 2021 14:07:39 -0500 Subject: [PATCH] fix(keywords): stopped modifying existing list when no new tags are provided --- src/package-test.js | 15 +++++++++++++++ src/package.js | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/package-test.js b/src/package-test.js index 0fcc260..e64d26e 100644 --- a/src/package-test.js +++ b/src/package-test.js @@ -70,6 +70,21 @@ suite('package.json lifter', () => { JSON.stringify({...packageJsonContents, scripts: {}, keywords: [...existingKeywords, ...tags]}, null, 2) ); }); + + test('that keywords are not modified when some keywords already exist but none are provided', async () => { + const existingKeywords = any.listOf(any.word); + fs.readFile + .withArgs(pathToPackageJson, 'utf8') + .resolves(JSON.stringify({...packageJsonContents, scripts: {}, keywords: existingKeywords})); + + await liftPackage({projectRoot, scripts: {}}); + + assert.calledWith( + fs.writeFile, + pathToPackageJson, + JSON.stringify({...packageJsonContents, scripts: {}, keywords: existingKeywords}, null, 2) + ); + }); }); suite('dependencies', () => { diff --git a/src/package.js b/src/package.js index ccae904..11efa14 100644 --- a/src/package.js +++ b/src/package.js @@ -1,6 +1,6 @@ import {promises as fs} from 'fs'; import {info} from '@travi/cli-messages'; -import {installDependencies, PROD_DEPENDENCY_TYPE, DEV_DEPENDENCY_TYPE} from '@form8ion/javascript-core'; +import {DEV_DEPENDENCY_TYPE, installDependencies, PROD_DEPENDENCY_TYPE} from '@form8ion/javascript-core'; export default async function ({ projectRoot, @@ -24,7 +24,9 @@ export default async function ({ { ...existingPackageJsonContents, scripts: {...existingPackageJsonContents.scripts, ...scripts}, - keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags + ...tags && { + keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags + } }, null, 2