-
-
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.
Use an object instead of tuple for previewAnnotations
- Loading branch information
Showing
6 changed files
with
54 additions
and
32 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
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
30 changes: 21 additions & 9 deletions
30
code/lib/builder-vite/src/utils/process-preview-annotation.ts
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 |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import type { PreviewAnnotation } from '@storybook/types'; | ||
import { resolve } from 'path'; | ||
|
||
/** | ||
* Preview annotations can take several forms, and vite needs them to be a bit more restrained. | ||
* For node_modules, we want bare imports (so vite can process them), and for files in the user's source, | ||
* Preview annotations can take several forms, and vite needs them to be | ||
* a bit more restrained. | ||
* | ||
* For node_modules, we want bare imports (so vite can process them), | ||
* and for files in the user's source, | ||
* we want absolute paths. | ||
*/ | ||
export function processPreviewAnnotation(path: string | string[] | undefined) { | ||
// If entry is a tuple, take the first, which is the non-absolute path. | ||
// This is so that webpack can use an absolute path (the second item in the tuple), and | ||
// continue supporting super-addons in pnp/pnpm without requiring them to re-export their | ||
// sub-addons as we do in addon-essentials. | ||
if (Array.isArray(path)) { | ||
return path[0]; | ||
export function processPreviewAnnotation(path: PreviewAnnotation | undefined) { | ||
// If entry is an object, take the first, which is the | ||
// bare (non-absolute) specifier. | ||
// This is so that webpack can use an absolute path, and | ||
// continue supporting super-addons in pnp/pnpm without | ||
// requiring them to re-export their sub-addons as we do | ||
// in addon-essentials. | ||
if (typeof path === 'object') { | ||
return path.bare; | ||
} | ||
// resolve relative paths into absolute paths, but don't resolve "bare" imports | ||
if (path?.startsWith('./') || path?.startsWith('../')) { | ||
return resolve(path); | ||
} | ||
// This should not occur, since we use `.filter(Boolean)` prior to | ||
// calling this function, but this makes typescript happy | ||
if (!path) { | ||
throw new Error('Could not determine path for previewAnnotation'); | ||
} | ||
|
||
return path; | ||
} |
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
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