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

Vite: Re-export essentials sub-addon preview annotations for pnpm #19689

Merged
merged 40 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
87582dc
Vite: Re-export essentials sub-addon preview annotations for pnpm
IanVS Oct 31, 2022
cec6654
Standardize addon preview location / export
IanVS Nov 2, 2022
a61403a
Use /dist/preview in addons
IanVS Nov 2, 2022
ede9562
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 2, 2022
9fe7fdc
Upgrade to TS 4.8
IanVS Nov 2, 2022
d41699a
Use Node16 moduleResolution
IanVS Nov 2, 2022
9264795
Add typescript eslint resolver
IanVS Nov 2, 2022
edb90d6
Remove /dist from exports & imports
IanVS Nov 2, 2022
8c62083
Update typescript in /scripts too
IanVS Nov 2, 2022
4560a33
Limit Node16 to only where it's needed, for now
IanVS Nov 3, 2022
0add1a9
Fix TS 4.8 errors
IanVS Nov 3, 2022
3d8d1a1
Restore moduleResolution in scripts
IanVS Nov 3, 2022
00bb65c
downgrade eslint-import-resolver-typescript
IanVS Nov 3, 2022
1f6b189
Remove typescript import resolver for now
IanVS Nov 3, 2022
39055be
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 3, 2022
af941fd
Add typesVersions to addons
IanVS Nov 3, 2022
aaa4a21
Re-export all addons from addon-essentials
IanVS Nov 3, 2022
756ea18
Keep addons relative, but use addon-essentials re-exports
IanVS Nov 3, 2022
0e8b0ba
Remove node16 moduleResolution
IanVS Nov 3, 2022
afaf141
Adjust builder-vite ssv6
IanVS Nov 3, 2022
2db1bc7
Remove unused imports
IanVS Nov 3, 2022
e7dc1c3
Remove unused eslint disable directives
IanVS Nov 3, 2022
f640293
Revert "Upgrade to TS 4.8"
IanVS Nov 4, 2022
8dda382
Revert "Fix TS 4.8 errors"
IanVS Nov 4, 2022
744051b
Revert "Update typescript in /scripts too"
IanVS Nov 4, 2022
e9d30c8
Update hasDocsOrControls to account for new path
IanVS Nov 4, 2022
2327569
Fix builder-webpack5 exports paths
IanVS Nov 4, 2022
a291e26
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 4, 2022
4af0653
Remove unrelated change
IanVS Nov 4, 2022
50826f2
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 8, 2022
b793868
Maintain WP back-compat by using tuple of [bare, absolute]
IanVS Nov 8, 2022
5bcd1e3
Add warning for super-addons not re-exporting their sub-addons
IanVS Nov 8, 2022
4931ec8
Fix deepscan
IanVS Nov 8, 2022
deb3b35
Remove warning
IanVS Nov 8, 2022
e23737e
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 8, 2022
4e15f69
Fix addon handling in SSv6
IanVS Nov 8, 2022
0813b24
Fix pnpm storybook module imports for SSv6
IanVS Nov 8, 2022
0428198
Remove errant console.log
IanVS Nov 8, 2022
18a6ba9
Merge remote-tracking branch 'origin/next' into nested-addons
IanVS Nov 8, 2022
9d9a92d
Use an object instead of tuple for previewAnnotations
IanVS Nov 9, 2022
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
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change wasn't entirely necessary here, but seemed like a good idea to keep the addons consistent with each other.

"./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';
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also have remained as before, but it was inconsistent with the rest of the addons, and it's nice for them all to follow the same pattern. I did the same for addon-outline as well.

"./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';
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