Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Install latest version of non-core addon #23956

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions code/lib/cli/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useNpmWarning,
type PackageManagerName,
} from './js-package-manager';
import { getStorybookVersion } from './utils';
import { getStorybookVersion, isCorePackage } from './utils';

const logger = console;

Expand Down Expand Up @@ -76,8 +76,9 @@ export async function add(

// add to package.json
const isStorybookAddon = addonName.startsWith('@storybook/');
const isAddonFromCore = isCorePackage(addonName);
const storybookVersion = await getStorybookVersion(packageManager);
const version = versionSpecifier || (isStorybookAddon ? storybookVersion : latestVersion);
const version = versionSpecifier || (isAddonFromCore ? storybookVersion : latestVersion);
const addonWithVersion = SemVer.valid(version)
? `${addonName}@^${version}`
: `${addonName}@${version}`;
Expand Down
25 changes: 1 addition & 24 deletions code/lib/cli/src/upgrade.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
addExtraFlags,
addNxPackagesToReject,
getStorybookVersion,
isCorePackage,
} from './upgrade';
import { addExtraFlags, addNxPackagesToReject, getStorybookVersion } from './upgrade';

describe.each([
['│ │ │ ├── @babel/code-frame@7.10.3 deduped', null],
Expand All @@ -26,24 +21,6 @@ describe.each([
});
});

describe.each([
['@storybook/react', true],
['@storybook/node-logger', true],
['@storybook/addon-info', true],
['@storybook/something-random', true],
['@storybook/preset-create-react-app', false],
['@storybook/linter-config', false],
['@storybook/design-system', false],
['@storybook/addon-styling', false],
['@storybook/addon-styling-webpack', false],
['@nx/storybook', false],
['@nrwl/storybook', false],
])('isCorePackage', (input, output) => {
it(`${input}`, () => {
expect(isCorePackage(input)).toEqual(output);
});
});

describe('extra flags', () => {
const extraFlags = {
'react-scripts@<5': ['--foo'],
Expand Down
32 changes: 1 addition & 31 deletions code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { PackageJsonWithMaybeDeps, PackageManagerName } from './js-package-
import { getPackageDetails, JsPackageManagerFactory, useNpmWarning } from './js-package-manager';
import { commandLog } from './helpers';
import { automigrate } from './automigrate';
import { isCorePackage } from './utils';

type Package = {
package: string;
Expand All @@ -25,37 +26,6 @@ export const getStorybookVersion = (line: string) => {
};
};

const excludeList = [
'@storybook/addon-bench',
'@storybook/addon-console',
'@storybook/addon-postcss',
'@storybook/addon-styling',
'@storybook/addon-styling-webpack',
'@storybook/babel-plugin-require-context-hook',
'@storybook/bench',
'@storybook/builder-vite',
'@storybook/csf',
'@storybook/design-system',
'@storybook/ember-cli-storybook',
'@storybook/eslint-config-storybook',
'@storybook/expect',
'@storybook/jest',
'@storybook/linter-config',
'@storybook/mdx1-csf',
'@storybook/mdx2-csf',
'@storybook/react-docgen-typescript-plugin',
'@storybook/storybook-deployer',
'@storybook/test-runner',
'@storybook/testing-library',
'@storybook/testing-react',
'@nrwl/storybook',
'@nx/storybook',
];
export const isCorePackage = (pkg: string) =>
pkg.startsWith('@storybook/') &&
!pkg.startsWith('@storybook/preset-') &&
!excludeList.includes(pkg);

const deprecatedPackages = [
{
minVersion: '6.0.0-alpha.0',
Expand Down
21 changes: 21 additions & 0 deletions code/lib/cli/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { isCorePackage } from './utils';

describe('UTILS', () => {
describe.each([
['@storybook/react', true],
['@storybook/node-logger', true],
['@storybook/addon-info', true],
['@storybook/something-random', true],
['@storybook/preset-create-react-app', false],
['@storybook/linter-config', false],
['@storybook/design-system', false],
['@storybook/addon-styling', false],
['@storybook/addon-styling-webpack', false],
['@nx/storybook', false],
['@nrwl/storybook', false],
])('isCorePackage', (input, output) => {
it(`It should return "${output}" when given "${input}"`, () => {
expect(isCorePackage(input)).toEqual(output);
});
});
});
31 changes: 31 additions & 0 deletions code/lib/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,34 @@ export const createLogStream = async (
logStream.once('error', reject);
});
};

const PACKAGES_EXCLUDED_FROM_CORE = [
'@storybook/addon-bench',
'@storybook/addon-console',
'@storybook/addon-postcss',
'@storybook/addon-styling',
'@storybook/addon-styling-webpack',
'@storybook/babel-plugin-require-context-hook',
'@storybook/bench',
'@storybook/builder-vite',
'@storybook/csf',
'@storybook/design-system',
'@storybook/ember-cli-storybook',
'@storybook/eslint-config-storybook',
'@storybook/expect',
'@storybook/jest',
'@storybook/linter-config',
'@storybook/mdx1-csf',
'@storybook/mdx2-csf',
'@storybook/react-docgen-typescript-plugin',
'@storybook/storybook-deployer',
'@storybook/test-runner',
'@storybook/testing-library',
'@storybook/testing-react',
'@nrwl/storybook',
'@nx/storybook',
];
export const isCorePackage = (pkg: string) =>
pkg.startsWith('@storybook/') &&
!pkg.startsWith('@storybook/preset-') &&
!PACKAGES_EXCLUDED_FROM_CORE.includes(pkg);