Skip to content

Commit

Permalink
Merge pull request #19689 from storybookjs/nested-addons
Browse files Browse the repository at this point in the history
Vite: Re-export essentials sub-addon preview annotations for pnpm
  • Loading branch information
shilman authored Nov 10, 2022
2 parents 97eefcc + 9d9a92d commit 02e4a69
Show file tree
Hide file tree
Showing 48 changed files with 427 additions and 128 deletions.
13 changes: 13 additions & 0 deletions code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"manager": [
"dist/manager.d.ts"
],
"preview": [
"dist/preview.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand Down
13 changes: 13 additions & 0 deletions code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"manager": [
"dist/manager.d.ts"
],
"preview": [
"dist/preview.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand Down
10 changes: 10 additions & 0 deletions code/addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"manager": [
"dist/manager.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand Down
86 changes: 85 additions & 1 deletion code/addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,76 @@
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./actions/preview": {
"require": "./dist/actions/preview.js",
"import": "./dist/actions/preview.mjs",
"types": "./dist/actions/preview.d.ts"
},
"./actions/manager": {
"require": "./dist/actions/manager.js",
"import": "./dist/actions/manager.mjs",
"types": "./dist/actions/manager.d.ts"
},
"./backgrounds/preview": {
"require": "./dist/backgrounds/preview.js",
"import": "./dist/backgrounds/preview.mjs",
"types": "./dist/backgrounds/preview.d.ts"
},
"./backgrounds/manager": {
"require": "./dist/backgrounds/manager.js",
"import": "./dist/backgrounds/manager.mjs",
"types": "./dist/backgrounds/manager.d.ts"
},
"./controls/manager": {
"require": "./dist/controls/manager.js",
"import": "./dist/controls/manager.mjs",
"types": "./dist/controls/manager.d.ts"
},
"./docs/preview": {
"require": "./dist/docs/preview.js",
"import": "./dist/docs/preview.mjs",
"types": "./dist/docs/preview.d.ts"
},
"./docs/preset": {
"require": "./dist/docs/preset.js",
"import": "./dist/docs/preset.mjs",
"types": "./dist/docs/preset.d.ts"
},
"./highlight/preview": {
"require": "./dist/highlight/preview.js",
"import": "./dist/highlight/preview.mjs",
"types": "./dist/highlight/preview.d.ts"
},
"./measure/preview": {
"require": "./dist/measure/preview.js",
"import": "./dist/measure/preview.mjs",
"types": "./dist/measure/preview.d.ts"
},
"./measure/manager": {
"require": "./dist/measure/manager.js",
"import": "./dist/measure/manager.mjs",
"types": "./dist/measure/manager.d.ts"
},
"./outline/preview": {
"require": "./dist/outline/preview.js",
"import": "./dist/outline/preview.mjs",
"types": "./dist/outline/preview.d.ts"
},
"./outline/manager": {
"require": "./dist/outline/manager.js",
"import": "./dist/outline/manager.mjs",
"types": "./dist/outline/manager.d.ts"
},
"./toolbars/manager": {
"require": "./dist/toolbars/manager.js",
"import": "./dist/toolbars/manager.mjs",
"types": "./dist/toolbars/manager.d.ts"
},
"./viewport/manager": {
"require": "./dist/viewport/manager.js",
"import": "./dist/viewport/manager.mjs",
"types": "./dist/viewport/manager.d.ts"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -108,7 +178,21 @@
},
"bundler": {
"entries": [
"./src/index.ts"
"./src/index.ts",
"./src/actions/preview.ts",
"./src/actions/manager.ts",
"./src/backgrounds/preview.ts",
"./src/backgrounds/manager.ts",
"./src/controls/manager.ts",
"./src/docs/preview.ts",
"./src/docs/preset.ts",
"./src/highlight/preview.ts",
"./src/measure/preview.ts",
"./src/measure/manager.ts",
"./src/outline/preview.ts",
"./src/outline/manager.ts",
"./src/toolbars/manager.ts",
"./src/viewport/manager.ts"
],
"platform": "node"
},
Expand Down
2 changes: 2 additions & 0 deletions code/addons/essentials/src/actions/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-actions/manager';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/actions/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered

export * from '@storybook/addon-actions/preview';
2 changes: 2 additions & 0 deletions code/addons/essentials/src/backgrounds/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-backgrounds/manager';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/backgrounds/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered

export * from '@storybook/addon-backgrounds/preview';
2 changes: 2 additions & 0 deletions code/addons/essentials/src/controls/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-controls/manager';
1 change: 1 addition & 0 deletions code/addons/essentials/src/docs/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@storybook/addon-docs/preset';
1 change: 1 addition & 0 deletions code/addons/essentials/src/docs/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@storybook/addon-docs/preview';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/highlight/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered

export * from '@storybook/addon-highlight/preview';
53 changes: 20 additions & 33 deletions code/addons/essentials/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path, { dirname, join } from 'path';
import path from 'path';
import { logger } from '@storybook/node-logger';
import { serverRequire } from '@storybook/core-common';

Expand All @@ -24,7 +24,8 @@ const requireMain = (configDir: string) => {
};

export function addons(options: PresetOptions) {
const checkInstalled = (addon: string, main: any) => {
const checkInstalled = (addonName: string, main: any) => {
const addon = `@storybook/addon-${addonName}`;
const existingAddon = main.addons?.find((entry: string | { name: string }) => {
const name = typeof entry === 'string' ? entry : entry.name;
return name?.startsWith(addon);
Expand All @@ -36,35 +37,21 @@ export function addons(options: PresetOptions) {
};

const main = requireMain(options.configDir);
return (
[
'docs',
'controls',
'actions',
'backgrounds',
'viewport',
'toolbars',
'measure',
'outline',
'highlight',
]
.filter((key) => (options as any)[key] !== false)
.map((key) => `@storybook/addon-${key}`)
.filter((addon) => !checkInstalled(addon, main))
// Use `require.resolve` to ensure Yarn PnP compatibility
// Files of various addons should be resolved in the context of `addon-essentials` as they are listed as deps here
// and not in `@storybook/core` nor in SB user projects. If `@storybook/core` make the require itself Yarn 2 will
// throw an error saying that the package to require must be added as a dependency. Doing `require.resolve` will
// allow `@storybook/core` to work with absolute path directly, no more require of dep no more issue.
// File to load can be `preset.js`, `register.js`, or the package entry point, so we need to check all these cases
// as it's done in `lib/core/src/server/presets.js`.
.map((addon) => {
try {
return dirname(require.resolve(join(addon, 'package.json')));
// eslint-disable-next-line no-empty
} catch (err) {}

return require.resolve(addon);
})
);
return [
'docs',
'controls',
'actions',
'backgrounds',
'viewport',
'toolbars',
'measure',
'outline',
'highlight',
]
.filter((key) => (options as any)[key] !== false)
.filter((addon) => !checkInstalled(addon, main))
.map((addon) => {
// We point to the re-export from addon-essentials to support yarn pnp and pnpm.
return `@storybook/addon-essentials/${addon}`;
});
}
2 changes: 2 additions & 0 deletions code/addons/essentials/src/measure/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-measure/manager';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/measure/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered

export * from '@storybook/addon-measure/preview';
2 changes: 2 additions & 0 deletions code/addons/essentials/src/outline/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-outline/manager';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/outline/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/export */
// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered

export * from '@storybook/addon-outline/preview';
2 changes: 2 additions & 0 deletions code/addons/essentials/src/toolbars/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-toolbars/manager';
4 changes: 4 additions & 0 deletions code/addons/essentials/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
declare module 'fs';

// TODO: Remove this once addon-docs is generated with tsup
declare module '@storybook/addon-docs/preview';
declare module '@storybook/addon-docs/preset';
2 changes: 2 additions & 0 deletions code/addons/essentials/src/viewport/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762
export * from '@storybook/addon-viewport/manager';
18 changes: 14 additions & 4 deletions code/addons/highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@
"types": "./dist/index.d.ts"
},
"./preview": {
"require": "./dist/highlight.js",
"import": "./dist/highlight.mjs",
"types": "./dist/highlight.d.ts"
"require": "./dist/preview.js",
"import": "./dist/preview.mjs",
"types": "./dist/preview.d.ts"
},
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"preview": [
"dist/preview.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand All @@ -64,7 +74,7 @@
"bundler": {
"entries": [
"./src/index.ts",
"./src/highlight.ts"
"./src/preview.ts"
]
},
"gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/highlight/preview.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/highlight';
export * from './dist/preview';
File renamed without changes.
21 changes: 17 additions & 4 deletions code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"types": "./dist/manager.d.ts"
},
"./preview": {
"require": "./dist/preset/preview.js",
"import": "./dist/preset/preview.mjs",
"types": "./dist/preset/preview.d.ts"
"require": "./dist/preview.js",
"import": "./dist/preview.mjs",
"types": "./dist/preview.d.ts"
},
"./register.js": {
"require": "./dist/manager.js",
Expand All @@ -47,6 +47,19 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"manager": [
"dist/manager.d.ts"
],
"preview": [
"dist/preview.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand Down Expand Up @@ -99,7 +112,7 @@
"entries": [
"./src/index.ts",
"./src/manager.tsx",
"./src/preset/preview.ts",
"./src/preview.ts",
"./src/preset/checkActionsLoaded.ts"
],
"platform": "node"
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/preview.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/preset/preview';
export * from './dist/preview';
File renamed without changes.
10 changes: 10 additions & 0 deletions code/addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"manager": [
"dist/manager.d.ts"
]
}
},
"files": [
"dist/**/*",
"README.md",
Expand Down
Loading

0 comments on commit 02e4a69

Please sign in to comment.