-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20143 from storybookjs/tom/sb-982-add-using-chrom…
…atic-to-telemetry Telemetry: Add `chromatic` to addons list
- Loading branch information
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getChromaticVersionSpecifier } from './get-chromatic-version'; | ||
|
||
it('works for dependencies', () => { | ||
expect(getChromaticVersionSpecifier({ dependencies: { chromatic: '^6.11.4' } })).toBe('^6.11.4'); | ||
}); | ||
|
||
it('works for scripts', () => { | ||
expect(getChromaticVersionSpecifier({ scripts: { chromatic: 'npx chromatic -t abc123' } })).toBe( | ||
'latest' | ||
); | ||
}); | ||
|
||
it('fails otherwise', () => { | ||
expect(getChromaticVersionSpecifier({})).toBeUndefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { PackageJson } from '@storybook/types'; | ||
|
||
export function getChromaticVersionSpecifier(packageJson: PackageJson) { | ||
const dependency = | ||
packageJson.dependencies?.chromatic || | ||
packageJson.devDependencies?.chromatic || | ||
packageJson.peerDependencies?.chromatic; | ||
if (dependency) return dependency; | ||
|
||
// Chromatic isn't necessarily installed in dependencies, it can be run from npx | ||
return packageJson.scripts && | ||
Object.values(packageJson.scripts).find((s) => s?.match(/chromatic/)) | ||
? 'latest' | ||
: undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters