From a790975f9e3bb36daa4d849d3e37bdb620574bee Mon Sep 17 00:00:00 2001 From: Simon Taggart Date: Tue, 28 Feb 2023 17:37:55 -0800 Subject: [PATCH] fix: dangerJS check now correctly detects missing design token changes (#3057) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../missing-changesets-check.spec.ts | 19 ++++++++-- .danger/__tests__/utils.spec.ts | 35 +++++++++++++++++++ .danger/utils.ts | 9 ++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/.danger/__tests__/missing-changesets-check.spec.ts b/.danger/__tests__/missing-changesets-check.spec.ts index 1a99195cd5..b03c97bd7f 100644 --- a/.danger/__tests__/missing-changesets-check.spec.ts +++ b/.danger/__tests__/missing-changesets-check.spec.ts @@ -29,6 +29,12 @@ const mockPackList = [ private: true, location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-core/primitives/box', }, + { + name: '@twilio-paste/design-tokens', + version: '0.0.0', + private: false, + location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-design-tokens', + }, ]; describe('getMissingPackagesFromChangesets()', () => { @@ -54,9 +60,15 @@ describe('getMissingPackagesFromChangesets()', () => { './.danger/__fixtures__/changeset/popular-cheetahs-punch.md', './.danger/__fixtures__/changeset/pretty-cameras-burn.md', ], - ['@twilio-paste/avatar', '@twilio-paste/box', '@twilio-paste/icons', '@twilio-paste/core'] + [ + '@twilio-paste/avatar', + '@twilio-paste/box', + '@twilio-paste/icons', + '@twilio-paste/core', + '@twilio-paste/design-tokens', + ] ) - ).toEqual(['@twilio-paste/core']); + ).toEqual(['@twilio-paste/core', '@twilio-paste/design-tokens']); expect( getMissingPackagesFromChangesets( @@ -92,6 +104,7 @@ describe('missingChangesetCheck()', () => { 'packages/paste-icons/src/index.tsx', 'packages/paste-core/components/avatar/src/index.tsx', 'packages/paste-core/primitives/box/src/index.tsx', + 'packages/paste-design-tokens/tokens/themes/evergreen/global/background-color.yml', 'yarn.lock', './.danger/__fixtures__/changeset/pretty-cameras-burn.md', ], @@ -99,7 +112,7 @@ describe('missingChangesetCheck()', () => { }, }; missingChangesetCheck(mockPackList); - expect(global.fail).toHaveBeenCalledTimes(1); + expect(global.fail).toHaveBeenCalledTimes(2); }); it('should fail twice for two packages that are not in a changeset', () => { diff --git a/.danger/__tests__/utils.spec.ts b/.danger/__tests__/utils.spec.ts index a5ddc49f23..e95347c5d6 100644 --- a/.danger/__tests__/utils.spec.ts +++ b/.danger/__tests__/utils.spec.ts @@ -232,6 +232,41 @@ describe('danger utils', () => { ) ).toEqual(['@twilio-paste/style-props', '@twilio-paste/alert-dialog']); }); + + it('should return the design-tokens package with even though no src files are updated', () => { + expect( + getUnpublishedPackageNames( + [ + 'package.json', + 'packages/paste-style-props/src/index.ts', + 'packages/paste-core/components/alert-dialog/stories/index.stories.tsx', + 'packages/paste-design-tokens/tokens/themes/evergreen/global/background-color.yml', + 'yarn.lock', + '.changeset/pretty-cameras-burn.md', + ], + [ + { + name: '@twilio-paste/alert-dialog', + version: '3.1.0', + private: false, + location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-core/components/alert-dialog', + }, + { + name: '@twilio-paste/style-props', + version: '3.1.0', + private: false, + location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-style-props', + }, + { + name: '@twilio-paste/design-tokens', + version: '3.1.0', + private: false, + location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-design-tokens', + }, + ] + ) + ).toEqual(['@twilio-paste/style-props', '@twilio-paste/design-tokens']); + }); }); describe('getChangesetsFromFiles', () => { diff --git a/.danger/utils.ts b/.danger/utils.ts index c5d8400089..681de298f9 100644 --- a/.danger/utils.ts +++ b/.danger/utils.ts @@ -68,7 +68,14 @@ export const getUnpublishedPackageNames = (touchedFiles: string[], publicPackage touchedFiles.forEach((filePath) => { const packageName = getPackageNameFromPath(filePath, publicPackages); - if (filePath.includes('/src/')) { + // all packages are uniform, except for design tokens. Source files are in the src directory. + // any changes to tokens, formatters or types in design tokens also need to be released + if ( + filePath.includes('/src/') || + filePath.includes('/paste-design-tokens/tokens/') || + filePath.includes('/paste-design-tokens/formatters/') || + filePath.includes('/paste-design-tokens/types/') + ) { uniquePackages.add(packageName); } });