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

Core: Fix addon/preset detection for local addons #9485

Merged
merged 2 commits into from
Jan 16, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/core/src/server/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const isObject = val => val != null && typeof val === 'object' && Array.isArray(
const isFunction = val => typeof val === 'function';

// Copied out of parse-package-name
// '@storybook/addon-actions/register' => ( name: '@storybook/addon-actions', path: '/register', version: '' )
const RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
const RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
function parsePackageName(input) {
Expand Down Expand Up @@ -38,6 +39,8 @@ const resolvePresetFunction = (input, presetOptions, storybookOptions) => {
return [];
};

const isLocalFileImport = packageName => /^[./]/.test(packageName);

/**
* Parse an addon into either a managerEntry or a preset. Throw on invalid input.
*
Expand All @@ -55,7 +58,12 @@ const resolvePresetFunction = (input, presetOptions, storybookOptions) => {
* => { type: 'presets', item: { name: '@storybook/addon-docs/preset', options } }
*/
export const resolveAddonName = name => {
const { path } = parsePackageName(name);
let path;
if (isLocalFileImport(name)) {
path = name;
} else {
({ path } = parsePackageName(name));
}

// when user provides full path, we don't need to do anything
if (path) {
Expand Down
4 changes: 4 additions & 0 deletions lib/core/src/server/presets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ describe('splitAddons', () => {
'@storybook/addon-actions/register',
'storybook-addon-readme/register',
'addon-foo/register.js',
'./local-addon-relative/register',
'/local-addon-absolute/register',
];
expect(splitAddons(addons)).toEqual({
managerEntries: addons,
Expand All @@ -401,6 +403,8 @@ describe('splitAddons', () => {
'@storybook/addon-essentials',
'@storybook/addon-docs/presets',
'addon-bar/presets.js',
'./local-addon-relative/presets',
'/local-addon-absolute/presets',
];
expect(splitAddons(addons)).toEqual({
managerEntries: [],
Expand Down