Skip to content

Commit

Permalink
Merge pull request #19790 from storybookjs/build/ts-up-addon-docs
Browse files Browse the repository at this point in the history
Build: convert addon-docs to use ts-up
  • Loading branch information
ndelangen authored Nov 11, 2022
2 parents 02e4a69 + 40f48eb commit 3826bd3
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 140 deletions.
58 changes: 46 additions & 12 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,44 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./preview": {
"require": "./dist/preview.js",
"import": "./dist/preview.mjs",
"types": "./dist/preview.d.ts"
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./dist/preview": {
"require": "./dist/preview.js",
"import": "./dist/preview.mjs",
"types": "./dist/preview.d.ts"
},
"./dist/preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./svelte/HOC.svelte": "./svelte/HOC.svelte",
"./ember": "./ember/index.js",
"./ember/index.js": "./ember/index.js",
"./angular": "./angular/index.js",
"./angular/index.js": "./angular/index.js",
"./web-components/index.js": "./web-components/index.js",
"./jest-transform-mdx.js": "./jest-transform-mdx.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"angular/**/*",
Expand All @@ -46,29 +81,21 @@
],
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.12.12",
"@jest/transform": "^26.6.2",
"@mdx-js/react": "^2.1.5",
"@storybook/addons": "7.0.0-alpha.48",
"@storybook/api": "7.0.0-alpha.48",
"@storybook/blocks": "7.0.0-alpha.48",
"@storybook/components": "7.0.0-alpha.48",
"@storybook/core-common": "7.0.0-alpha.48",
"@storybook/core-events": "7.0.0-alpha.48",
"@storybook/csf-plugin": "7.0.0-alpha.48",
"@storybook/csf-tools": "7.0.0-alpha.48",
"@storybook/docs-tools": "7.0.0-alpha.48",
"@storybook/mdx2-csf": "next",
"@storybook/node-logger": "7.0.0-alpha.48",
"@storybook/postinstall": "7.0.0-alpha.48",
"@storybook/preview-web": "7.0.0-alpha.48",
"@storybook/store": "7.0.0-alpha.48",
"@storybook/theming": "7.0.0-alpha.48",
"@storybook/types": "7.0.0-alpha.48",
"dequal": "^2.0.2",
"fs-extra": "^9.0.1",
"global": "^4.4.0",
"remark-external-links": "^8.0.0",
Expand All @@ -94,6 +121,13 @@
"publishConfig": {
"access": "public"
},
"bundler": {
"entries": [
"./src/index.ts",
"./src/preset.ts",
"./src/preview.ts"
]
},
"gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd",
"storybook": {
"displayName": "Docs",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/docs/preset.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/cjs/preset');
module.exports = require('./dist/preset');
2 changes: 1 addition & 1 deletion code/addons/docs/preview.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/esm/preview';
export * from './dist/preview';
1 change: 1 addition & 0 deletions code/addons/docs/src/DocsRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class DocsRenderer<TFramework extends Framework> {
...defaultComponents,
...docsParameter?.components,
};

ReactDOM.render(
<MDXProvider components={components}>
<Docs key={Math.random()} context={context} docsParameter={docsParameter} />
Expand Down
1 change: 0 additions & 1 deletion code/addons/docs/src/blocks.ts

This file was deleted.

2 changes: 1 addition & 1 deletion code/addons/docs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './blocks';
export * from '@storybook/blocks';
export { DocsRenderer } from './DocsRenderer';
16 changes: 13 additions & 3 deletions code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: Bab
};
}

export async function webpack(
async function webpack(
webpackConfig: any = {},
options: Options &
BabelParams & {
Expand Down Expand Up @@ -160,7 +160,7 @@ export async function webpack(
return result;
}

export const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => {
const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => {
const mdxIndexer = async (fileName: string, opts: CoreCommon_IndexerOptions) => {
let code = (await fs.readFile(fileName, 'utf-8')).toString();
const { compile } = await import('@storybook/mdx2-csf');
Expand All @@ -176,11 +176,21 @@ export const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => {
];
};

export const docs = (docsOptions: DocsOptions) => {
const docs = (docsOptions: DocsOptions) => {
return {
...docsOptions,
enabled: true,
defaultName: 'Docs',
docsPage: true,
};
};

/*
* This is a workaround for https://github.com/Swatinem/rollup-plugin-dts/issues/162
* something down the dependency chain is using typescript namespaces, which are not supported by rollup-plugin-dts
*/
const webpackX = webpack as any;
const storyIndexersX = storyIndexers as any;
const docsX = docs as any;

export { webpackX as webpack, storyIndexersX as storyIndexers, docsX as docs };
28 changes: 0 additions & 28 deletions code/addons/docs/src/shared.ts

This file was deleted.

38 changes: 0 additions & 38 deletions code/addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,44 +135,6 @@
"peerDependencies": {
"@babel/core": "^7.9.6"
},
"peerDependenciesMeta": {
"@storybook/angular": {
"optional": true
},
"@storybook/html": {
"optional": true
},
"@storybook/vue": {
"optional": true
},
"@storybook/vue3": {
"optional": true
},
"@storybook/web-components": {
"optional": true
},
"lit": {
"optional": true
},
"lit-html": {
"optional": true
},
"react": {
"optional": true
},
"react-dom": {
"optional": true
},
"svelte": {
"optional": true
},
"sveltedoc-parser": {
"optional": true
},
"vue": {
"optional": true
}
},
"publishConfig": {
"access": "public"
},
Expand Down
3 changes: 2 additions & 1 deletion code/addons/essentials/src/docs/preset.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from '@storybook/addon-docs/preset';
/* eslint-disable import/export */
export * from '@storybook/addon-docs/dist/preset';
2 changes: 1 addition & 1 deletion code/addons/essentials/src/docs/preview.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '@storybook/addon-docs/preview';
export * from '@storybook/addon-docs/dist/preview';
4 changes: 0 additions & 4 deletions code/addons/essentials/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
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';
4 changes: 3 additions & 1 deletion code/ui/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"*.d.ts"
],
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
Expand Down Expand Up @@ -70,7 +71,8 @@
"@types/color-convert": "^2.0.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 2 additions & 3 deletions code/ui/blocks/src/blocks/enhanceSource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Parameters } from '@storybook/types';
import type { Story } from '@storybook/store';
import type { Parameters, Store_Story } from '@storybook/types';
import { combineParameters } from '@storybook/store';

// ============================================================
Expand Down Expand Up @@ -77,7 +76,7 @@ const extract = (targetId: string, { source, locationsMap }: StorySource) => {
return extractSource(location, lines);
};

export const enhanceSource = (story: Story<any>): Parameters => {
export const enhanceSource = (story: Store_Story<any>): Parameters => {
const { id, parameters } = story;
const { storySource, docs = {} } = parameters;
const { transformSource } = docs;
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/src/blocks/external/ExternalPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ExternalPreview<TFramework extends Framework = Framework> extends P

private moduleExportsByImportPath: Record<Path, Store_ModuleExports> = {};

constructor(public projectAnnotations: ProjectAnnotations) {
constructor(public projectAnnotations: ProjectAnnotations<TFramework>) {
super(new Channel());

this.initialize({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ export class JsonObject extends Component<JsonObjectProps, JsonObjectState> {
onChildUpdate(childKey: string, childData: any) {
const { data, keyPath } = this.state;
// Update data
// @ts-expect-error (Converted from ts-ignore)
data[childKey] = childData;
// Put new data
this.setState({
Expand Down Expand Up @@ -1117,7 +1116,6 @@ export class JsonObject extends Component<JsonObjectProps, JsonObjectState> {
beforeAddAction(key, keyPath, deep, newValue)
.then(() => {
// Update data
// @ts-expect-error (Converted from ts-ignore)
data[key] = newValue;
this.setState({
data,
Expand All @@ -1143,7 +1141,6 @@ export class JsonObject extends Component<JsonObjectProps, JsonObjectState> {
return () => {
const { beforeRemoveAction, logger } = this.props;
const { data, keyPath, nextDeep: deep } = this.state;
// @ts-expect-error (Converted from ts-ignore)
const oldValue = data[key];
// Before Remove Action
beforeRemoveAction(key, keyPath, deep, oldValue)
Expand All @@ -1156,7 +1153,6 @@ export class JsonObject extends Component<JsonObjectProps, JsonObjectState> {
type: deltaTypes.REMOVE_DELTA_TYPE,
};

// @ts-expect-error (Converted from ts-ignore)
delete data[key];
this.setState({ data });

Expand All @@ -1182,14 +1178,12 @@ export class JsonObject extends Component<JsonObjectProps, JsonObjectState> {
const { data, keyPath, nextDeep: deep } = this.state;

// Old value
// @ts-expect-error (Converted from ts-ignore)
const oldValue = data[key];

// Before update action
beforeUpdateAction(key, keyPath, deep, oldValue, value)
.then(() => {
// Update value
// @ts-expect-error (Converted from ts-ignore)
data[key] = value;
// Set state
this.setState({
Expand Down
34 changes: 1 addition & 33 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5501,23 +5501,15 @@ __metadata:
"@babel/plugin-transform-react-jsx": ^7.12.12
"@jest/transform": ^26.6.2
"@mdx-js/react": ^2.1.5
"@storybook/addons": 7.0.0-alpha.48
"@storybook/api": 7.0.0-alpha.48
"@storybook/blocks": 7.0.0-alpha.48
"@storybook/components": 7.0.0-alpha.48
"@storybook/core-common": 7.0.0-alpha.48
"@storybook/core-events": 7.0.0-alpha.48
"@storybook/csf-plugin": 7.0.0-alpha.48
"@storybook/csf-tools": 7.0.0-alpha.48
"@storybook/docs-tools": 7.0.0-alpha.48
"@storybook/mdx2-csf": next
"@storybook/node-logger": 7.0.0-alpha.48
"@storybook/postinstall": 7.0.0-alpha.48
"@storybook/preview-web": 7.0.0-alpha.48
"@storybook/store": 7.0.0-alpha.48
"@storybook/theming": 7.0.0-alpha.48
"@storybook/types": 7.0.0-alpha.48
dequal: ^2.0.2
fs-extra: ^9.0.1
global: ^4.4.0
remark-external-links: ^8.0.0
Expand Down Expand Up @@ -5559,31 +5551,6 @@ __metadata:
typescript: ~4.6.3
peerDependencies:
"@babel/core": ^7.9.6
peerDependenciesMeta:
"@storybook/angular":
optional: true
"@storybook/html":
optional: true
"@storybook/vue":
optional: true
"@storybook/vue3":
optional: true
"@storybook/web-components":
optional: true
lit:
optional: true
lit-html:
optional: true
react:
optional: true
react-dom:
optional: true
svelte:
optional: true
sveltedoc-parser:
optional: true
vue:
optional: true
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -6150,6 +6117,7 @@ __metadata:
util-deprecate: ^1.0.2
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
languageName: unknown
linkType: soft

Expand Down
Loading

0 comments on commit 3826bd3

Please sign in to comment.