Skip to content

Commit

Permalink
Vite: Re-export essentials sub-addon preview annotations for pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Oct 31, 2022
1 parent 44abd49 commit f340e88
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 2 deletions.
38 changes: 37 additions & 1 deletion code/addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./preview/actions": {
"require": "./dist/preview/actions.js",
"import": "./dist/preview/actions.mjs",
"types": "./dist/actions.d.ts"
},
"./preview/backgrounds": {
"require": "./dist/preview/backgrounds.js",
"import": "./dist/preview/backgrounds.mjs",
"types": "./dist/backgrounds.d.ts"
},
"./preview/docs": {
"require": "./dist/preview/docs.js",
"import": "./dist/preview/docs.mjs",
"types": "./dist/docs.d.ts"
},
"./preview/highlight": {
"require": "./dist/preview/highlight.js",
"import": "./dist/preview/highlight.mjs",
"types": "./dist/highlight.d.ts"
},
"./preview/measure": {
"require": "./dist/preview/measure.js",
"import": "./dist/preview/measure.mjs",
"types": "./dist/measure.d.ts"
},
"./preview/outline": {
"require": "./dist/preview/outline.js",
"import": "./dist/preview/outline.mjs",
"types": "./dist/outline.d.ts"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -108,7 +138,13 @@
},
"bundler": {
"entries": [
"./src/index.ts"
"./src/index.ts",
"./src/preview/actions.ts",
"./src/preview/backgrounds.ts",
"./src/preview/docs.ts",
"./src/preview/highlight.ts",
"./src/preview/measure.ts",
"./src/preview/outline.ts"
],
"platform": "node"
},
Expand Down
4 changes: 4 additions & 0 deletions code/addons/essentials/src/preview/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-actions/preview';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/preview/backgrounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-backgrounds/preview';
3 changes: 3 additions & 0 deletions code/addons/essentials/src/preview/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-docs/preview';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/preview/highlight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-highlight/preview';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/preview/measure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-measure/preview';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/preview/outline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// This lint rule fails because it doesn't use export maps correctly

export * from '@storybook/addon-outline/preview';
14 changes: 13 additions & 1 deletion code/lib/builder-vite/src/codegen-modern-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ export async function generateModernIframeScriptCode(options: ExtendedOptions) {
);
const relativePreviewAnnotations = [...resolvedPreviewAnnotations, previewOrConfigFile]
.filter(Boolean)
.map((configEntry) => transformAbsPath(configEntry as string));
.map((configEntry) => {
// Convert absolute path into a "bare" import (See https://github.com/vitejs/vite/issues/5494)
const relative = transformAbsPath(configEntry as string);
// If this is a sub-addon of essentials, rewrite the import to point to essentials re-export
const match =
/@storybook\/addon-(actions|backgrounds|docs|highlight|measure|outline)\/preview/.exec(
relative
);
if (match) {
return `@storybook/addon-essentials/preview/${match[1]}`;
}
return relative;
});

// eslint-disable-next-line @typescript-eslint/no-shadow
const generateHMRHandler = (frameworkName: string): string => {
Expand Down

0 comments on commit f340e88

Please sign in to comment.