From ea7c2429103c901fcce012285c87a2476576d0fd Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 20:43:32 +0100 Subject: [PATCH] split the web-components renderer preview entrypoint into docs & non-docs parts --- code/renderers/web-components/package.json | 12 +++++----- code/renderers/web-components/preset.js | 1 + code/renderers/web-components/preview.js | 1 - code/renderers/web-components/src/config.ts | 5 ---- code/renderers/web-components/src/preset.ts | 23 +++++++++++++++++++ .../web-components/src/preview-docs.ts | 2 ++ code/renderers/web-components/src/preview.ts | 2 ++ 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 code/renderers/web-components/preset.js delete mode 100644 code/renderers/web-components/preview.js delete mode 100644 code/renderers/web-components/src/config.ts create mode 100644 code/renderers/web-components/src/preset.ts create mode 100644 code/renderers/web-components/src/preview-docs.ts create mode 100644 code/renderers/web-components/src/preview.ts diff --git a/code/renderers/web-components/package.json b/code/renderers/web-components/package.json index 43a43b404127..018d8c0a78a3 100644 --- a/code/renderers/web-components/package.json +++ b/code/renderers/web-components/package.json @@ -29,11 +29,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,7 +80,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/web-components/preset.js b/code/renderers/web-components/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/web-components/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/web-components/preview.js b/code/renderers/web-components/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/web-components/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/web-components/src/config.ts b/code/renderers/web-components/src/config.ts deleted file mode 100644 index abf93dbc12f2..000000000000 --- a/code/renderers/web-components/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'web-components' as const, ...docsParams }; -export { decorators, argTypesEnhancers } from './docs/config'; -export { render, renderToCanvas } from './render'; diff --git a/code/renderers/web-components/src/preset.ts b/code/renderers/web-components/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/web-components/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/web-components/src/preview-docs.ts b/code/renderers/web-components/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/web-components/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/web-components/src/preview.ts b/code/renderers/web-components/src/preview.ts new file mode 100644 index 000000000000..c0a759dcab8a --- /dev/null +++ b/code/renderers/web-components/src/preview.ts @@ -0,0 +1,2 @@ +export const parameters: {} = { renderer: 'web-components' }; +export { render, renderToCanvas } from './render';