Skip to content

Commit

Permalink
feat: export types also from @nuxtjs/storybook (#749)
Browse files Browse the repository at this point in the history
<!--
☝️ PR title should follow conventional commits
(https://conventionalcommits.org).
In particular, the title should start with one of the following types:

- docs: 📖 Documentation (updates to the documentation or readme)
- fix: 🐞 Bug fix (a non-breaking change that fixes an issue)
- feat: ✨ New feature/enhancement (a non-breaking change that adds
functionality or improves existing one)
- feat!/fix!: ⚠️ Breaking change (fix or feature that would cause
existing functionality to change)
- chore: 🧹 Chore (updates to the build process or auxiliary tools and
libraries)
-->

### 🔗 Linked issue

<!-- If it resolves an open issue, please link the issue here. For
example "Resolves #123" -->

### 📚 Description

Export types from `@storybook/vue3` also at `@nuxtjs/storybook`.

<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
  • Loading branch information
tobiasdiez authored Aug 13, 2024
1 parent e8837c4 commit a3fa103
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["composables", "dedupe", "nuxt", "ofetch", "Pinia"]
"cSpell.words": ["composables", "dedupe", "nuxt", "nuxtjs", "ofetch", "Pinia"]
}
46 changes: 46 additions & 0 deletions docs/content/1.getting-started/3.typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 'TypeScript'
description: 'Guide on how to use TypeScript with the Nuxt module'
---

To use the Nuxt module with TypeScript, ensure that imports typically from `@storybook/*` are now replaced by imports from `@nuxtjs/storybook` (or `@storybook-vue/nuxt` if the Nuxt module is not used). This is needed since the Storybook packages are dependencies of the Nuxt module, and are not directly installed in the project.

The following example demonstrates how to use types when configuring Storybook and for writing stories.

::code-group

```typescript [.storybook/main.ts]
import { StorybookConfig } from '@nuxtjs/storybook' // not from '@storybook/core-common'
export default {
stories: ['../components/**/*.stories.ts'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/vue3',
} as StorybookConfig
```

```typescript [components/Button.stories.ts]
import { Meta, Story } from '@nuxtjs/storybook' // not from '@storybook/vue'
import Button from './Button.vue'

export default {
title: 'Example/Button',
component: Button,
} as Meta

const Template: Story = (args) => ({
components: { Button },
setup() {
return { args }
},
template: '<Button v-bind="args" />',
})

export const Primary = Template.bind({})
Primary.args = {
primary: true,
label: 'Button',
}
```

::
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"example:showcase:build": "pnpm run --filter=./examples/showcase/** build",
"example:showcase:storybook:build": "pnpm run --filter=./examples/showcase/** build-storybook",
"example:showcase:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:showcase:storybook:build --project-token=chpt_a53adf402cb628c",
"build": "pnpm run --recursive --filter=./packages/* --parallel build",
"build": "pnpm run --recursive --filter=./packages/* build",
"package": "cd ./packages/storybook-addon && pnpm pack && cd ../nuxt-module && pnpm pack",
"lint": "pnpm lint:eslint && pnpm lint:prettier",
"lint:eslint": "eslint --max-warnings=0 --report-unused-disable-directives .",
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"type": "module",
"exports": {
".": {
"types": "./dist/types.d.ts",
"types": "./dist/module.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
Expand Down Expand Up @@ -57,7 +57,7 @@
"ufo": "^1.5.3"
},
"devDependencies": {
"@nuxt/module-builder": "0.8.1",
"@nuxt/module-builder": "0.8.3",
"vite": "5.4.0",
"unbuild": "2.0.0"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/nuxt-module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { logger } from './logger'

import { setupStorybook } from './storybook'

export type * from '@storybook-vue/nuxt'

export interface ModuleOptions {
/**
* The route where the Storybook application will be available in development mode.
Expand Down
29 changes: 0 additions & 29 deletions packages/storybook-addon/.storybook/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/storybook-addon/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Path: src/types.d.ts';
export * from '@storybook/vue3'
export * from './types.d'
10 changes: 0 additions & 10 deletions packages/storybook-addon/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types'
import type {
Preview,
StoryFn,
StoryObj,
VueRenderer,
Meta,
DecoratorFunction,
} from '@storybook/vue3'
import type { FrameworkOptions as FrameworkOptionsVue } from '@storybook/vue3-vite'
import type { StorybookConfigVite } from '@storybook/builder-vite'

Expand Down Expand Up @@ -40,5 +32,3 @@ export type StorybookConfig = Omit<
> &
StorybookConfigVite &
StorybookConfigFramework

export { Meta, StoryFn, StoryObj, Preview, VueRenderer, DecoratorFunction }
4 changes: 2 additions & 2 deletions packages/storybook-addon/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "./.storybook/tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"target": "ESNext",
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
"skipLibCheck": false,
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"paths": {
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3fa103

Please sign in to comment.