Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
fix(keywords): stopped modifying existing list when no new tags are p…
Browse files Browse the repository at this point in the history
…rovided
  • Loading branch information
travi committed Jun 23, 2021
1 parent 4fa7958 commit 3c0bdc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/package-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/package.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 3c0bdc2

Please sign in to comment.