Skip to content

Tags: Add project tags, negation, dev/autodocs/test system tags #26634

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

Merged
merged 34 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
32e854a
Add metaTags, tag removal
shilman Mar 24, 2024
ab64211
Switch tag removal prefix from `-` to `!`
shilman Mar 26, 2024
b5b17f5
Add project-level tags
shilman Mar 29, 2024
c52d943
Deprecate main.js docs.autodocs in favor of tags
shilman Mar 29, 2024
ebce080
Add autodocs tag in preview if docs.autodics is true
shilman Mar 29, 2024
f54b030
Always apply dev/docs/test tags
shilman Apr 4, 2024
fea9c2e
Fix tag precedence in CSF combineTags util
shilman Apr 5, 2024
bcd3da8
Remove metaTags concept
shilman Apr 5, 2024
e55bee6
Merge branch 'next' into shilman/add-tag-exclusion
shilman May 4, 2024
f677115
Add preview.js watcher for project tags
shilman May 4, 2024
5dfa56b
Restore dev/docs/test default tags
shilman May 4, 2024
3160354
Preserver negated tags for index
shilman May 5, 2024
a9c0730
Remove auto-generated story tag, update tests
shilman May 5, 2024
ca88bca
Add dev/docs tag behaviors
shilman May 5, 2024
d89ff2e
Deprecate main.js `docs.autodocs` and remove from CLI template
shilman May 5, 2024
149dd06
Replace `docs` tag by `autodocs`
shilman May 6, 2024
5fc32ee
Fix MDX detection now that MDX can inherit autodocs tags
shilman May 6, 2024
8f7d569
Update snapshots
shilman May 6, 2024
d4ac168
Merge branch 'next' into shilman/add-tag-exclusion
shilman May 6, 2024
5b46717
Fix portable stories tests
shilman May 6, 2024
f5447a3
Fix tags inheritance story
shilman May 6, 2024
01923cd
Remove bogus console.log
shilman May 6, 2024
dc28521
Try clearing the webpack mock
shilman May 6, 2024
d810f8e
Try to fix CI
shilman May 6, 2024
bdbd332
Fix bad merge
shilman May 6, 2024
b751b83
Merge branch 'next' into shilman/add-tag-exclusion
shilman May 6, 2024
31ae4d6
Fix yarn.lock
shilman May 7, 2024
1a4bd14
Update csf-tools babel deps
shilman May 7, 2024
8b35e06
Another attempt to fix yarn.lock
shilman May 7, 2024
15d7ef9
Continue to show autodocs even when primary story is !dev
shilman May 7, 2024
83639e0
Add e2e tests for new tags behavior
shilman May 7, 2024
aad8a11
Fix CI?
shilman May 7, 2024
14f86ec
Fix tags stories
shilman May 7, 2024
2dee030
Merge branch 'next' into shilman/add-tag-exclusion
shilman May 7, 2024
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
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts"
},
"dependencies": {
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/global": "^5.0.0",
"ts-dedent": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/types": "^7.23.0",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/csf-tools": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@storybook/channels": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/csf-tools": "workspace:*",
"@storybook/docs-mdx": "3.0.0",
"@storybook/global": "^5.0.0",
Expand Down
23 changes: 18 additions & 5 deletions code/lib/core-server/src/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { userOrAutoTitleFromSpecifier, sortStoriesV7 } from '@storybook/preview-
import { commonGlobOptions, normalizeStoryPath } from '@storybook/core-common';
import { logger, once } from '@storybook/node-logger';
import { getStorySortParameter } from '@storybook/csf-tools';
import { storyNameFromExport, toId } from '@storybook/csf';
import { storyNameFromExport, toId, combineTags } from '@storybook/csf';
import { analyze } from '@storybook/docs-mdx';
import dedent from 'ts-dedent';
import { autoName } from './autoName';
Expand Down Expand Up @@ -55,6 +55,7 @@ export type StoryIndexGeneratorOptions = {
};

export const AUTODOCS_TAG = 'autodocs';
export const NO_AUTODOCS_TAG = `-${AUTODOCS_TAG}`;
export const STORIES_MDX_TAG = 'stories-mdx';
export const PLAY_FN_TAG = 'play-fn';

Expand Down Expand Up @@ -291,7 +292,7 @@ export class StoryIndexGenerator {
const title = input.title ?? defaultMakeTitle();
// eslint-disable-next-line no-underscore-dangle
const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName));
const tags = (input.tags || []).concat('story');
const tags = combineTags(...(input.tags ?? []), ...(input.metaTags ?? []), 'story');

return {
type: 'story',
Expand All @@ -300,6 +301,7 @@ export class StoryIndexGenerator {
name,
title,
importPath,
metaTags: input.metaTags ?? [],
tags,
};
});
Expand All @@ -312,7 +314,9 @@ export class StoryIndexGenerator {
const hasAutodocsTag = entries.some((entry) => entry.tags.includes(AUTODOCS_TAG));
const isStoriesMdx = entries.some((entry) => entry.tags.includes(STORIES_MDX_TAG));
const createDocEntry =
autodocs === true || (autodocs === 'tag' && hasAutodocsTag) || isStoriesMdx;
(autodocs === true && !entries.some((entry) => entry.tags.includes(NO_AUTODOCS_TAG))) ||
(autodocs === 'tag' && hasAutodocsTag) ||
isStoriesMdx;

if (createDocEntry && this.options.build?.test?.disableAutoDocs !== true) {
const name = this.options.docs.defaultName ?? 'Docs';
Expand All @@ -326,7 +330,12 @@ export class StoryIndexGenerator {
name,
importPath,
type: 'docs',
tags: [...metaTags, 'docs', ...(!hasAutodocsTag && !isStoriesMdx ? [AUTODOCS_TAG] : [])],
metaTags,
tags: combineTags(
...metaTags,
'docs',
...(!hasAutodocsTag && !isStoriesMdx ? [AUTODOCS_TAG] : [])
),
storiesImports: [],
});
}
Expand Down Expand Up @@ -433,7 +442,11 @@ export class StoryIndexGenerator {
storiesImports: sortedDependencies.map((dep) => dep.entries[0].importPath),
type: 'docs',
// FIXME: update this to use the index entry's metaTags once we update this to run on `IndexInputs`
tags: [...(result.tags || []), csfEntry ? 'attached-mdx' : 'unattached-mdx', 'docs'],
tags: combineTags(
...(result.tags || []),
csfEntry ? 'attached-mdx' : 'unattached-mdx',
'docs'
),
};
return docsEntry;
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@babel/parser": "^7.23.0",
"@babel/traverse": "^7.23.2",
"@babel/types": "^7.23.0",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/types": "workspace:*",
"fs-extra": "^11.1.0",
"recast": "^0.23.5",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/manager-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@storybook/channels": "workspace:*",
"@storybook/client-logger": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.5",
"@storybook/router": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@storybook/channels": "workspace:*",
"@storybook/client-logger": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/global": "^5.0.0",
"@storybook/types": "workspace:*",
"@types/qs": "^6.9.5",
Expand Down
8 changes: 6 additions & 2 deletions code/lib/preview-api/src/modules/store/csf/prepareStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
StoryContextForLoaders,
StrictArgTypes,
} from '@storybook/types';
import { includeConditionalArg } from '@storybook/csf';
import { includeConditionalArg, combineTags } from '@storybook/csf';

import { applyHooks } from '../../addons';
import { combineParameters } from '../parameters';
Expand Down Expand Up @@ -140,7 +140,11 @@ function preparePartialAnnotations<TRenderer extends Renderer>(
// anything at render time. The assumption is that as we don't load all the stories at once, this
// will have a limited cost. If this proves misguided, we can refactor it.

const tags = [...(storyAnnotations?.tags || componentAnnotations.tags || []), 'story'];
const tags = combineTags(
...(storyAnnotations?.tags ?? []),
...(componentAnnotations.tags ?? []),
'story'
);

const parameters: Parameters = combineParameters(
projectAnnotations.parameters,
Expand Down
4 changes: 4 additions & 0 deletions code/lib/preview-api/template/stories/tags.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ export const TestOnly = {
export const DevOnly = {
tags: ['dev-only'],
};

export const TagRemoval = {
tags: ['-component-two'],
};
2 changes: 1 addition & 1 deletion code/lib/source-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/types": "workspace:*",
"estraverse": "^5.2.0",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"file-system-cache": "2.3.0"
},
"devDependencies": {
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.0.0",
"typescript": "^5.3.2"
Expand Down
1 change: 1 addition & 0 deletions code/lib/types/src/modules/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface BaseIndexEntry {
id: StoryId;
name: StoryName;
title: ComponentTitle;
metaTags?: Tag[];
tags?: Tag[];
importPath: Path;
}
Expand Down
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@storybook/core-events": "workspace:*",
"@storybook/core-server": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/csf-plugin": "workspace:*",
"@storybook/csf-tools": "workspace:*",
"@storybook/docs-tools": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/csf-tools": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/preview-api": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/docs-tools": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.5",
Expand Down
2 changes: 1 addition & 1 deletion code/ui/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@radix-ui/react-slot": "^1.0.2",
"@storybook/client-logger": "workspace:*",
"@storybook/csf": "^0.1.2",
"@storybook/csf": "0.1.4--canary.80.632d12b.0",
"@storybook/global": "^5.0.0",
"@storybook/icons": "^1.2.5",
"@storybook/theming": "workspace:*",
Expand Down
42 changes: 21 additions & 21 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5256,7 +5256,7 @@ __metadata:
dependencies:
"@storybook/client-logger": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/global": "npm:^5.0.0"
"@storybook/manager-api": "workspace:*"
"@storybook/preview-api": "workspace:*"
Expand Down Expand Up @@ -5524,7 +5524,7 @@ __metadata:
"@storybook/client-logger": "workspace:*"
"@storybook/components": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/docs-tools": "workspace:*"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
Expand Down Expand Up @@ -5755,7 +5755,7 @@ __metadata:
"@babel/core": "npm:^7.23.2"
"@babel/preset-env": "npm:^7.23.2"
"@babel/types": "npm:^7.23.0"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/csf-tools": "workspace:*"
"@storybook/node-logger": "workspace:*"
"@storybook/types": "workspace:*"
Expand Down Expand Up @@ -5791,7 +5791,7 @@ __metadata:
"@radix-ui/react-scroll-area": "npm:^1.0.5"
"@radix-ui/react-slot": "npm:^1.0.2"
"@storybook/client-logger": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
"@storybook/test": "workspace:*"
Expand Down Expand Up @@ -5884,7 +5884,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/csf-tools": "workspace:*"
"@storybook/docs-mdx": "npm:3.0.0"
"@storybook/global": "npm:^5.0.0"
Expand Down Expand Up @@ -5964,7 +5964,7 @@ __metadata:
"@babel/parser": "npm:^7.23.0"
"@babel/traverse": "npm:^7.23.2"
"@babel/types": "npm:^7.23.0"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/types": "workspace:*"
"@types/fs-extra": "npm:^11.0.1"
"@types/js-yaml": "npm:^4.0.5"
Expand All @@ -5976,6 +5976,15 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/csf@npm:0.1.4--canary.80.632d12b.0":
version: 0.1.4--canary.80.632d12b.0
resolution: "@storybook/csf@npm:0.1.4--canary.80.632d12b.0"
dependencies:
type-fest: "npm:^2.19.0"
checksum: 10c0/8e2c9562d874ea78ad578eac3132bcc0dc4116e52a0cea7921888796ffa4225f106d4286bce92655584ae1ad1cf5150fd891af6cec5eb261a2e5ba5ecc4fa879
languageName: node
linkType: hard

"@storybook/csf@npm:^0.0.1":
version: 0.0.1
resolution: "@storybook/csf@npm:0.0.1"
Expand All @@ -5985,15 +5994,6 @@ __metadata:
languageName: node
linkType: hard

"@storybook/csf@npm:^0.1.2":
version: 0.1.2
resolution: "@storybook/csf@npm:0.1.2"
dependencies:
type-fest: "npm:^2.19.0"
checksum: 10c0/b51a55292e5d2af8b1d135a28ecaa94f8860ddfedcb393adfa2cca1ee23853156066f737d8be1cb5412f572781aa525dc0b2f6e4a6f6ce805489f0149efe837c
languageName: node
linkType: hard

"@storybook/docs-mdx@npm:3.0.0":
version: 3.0.0
resolution: "@storybook/docs-mdx@npm:3.0.0"
Expand Down Expand Up @@ -6161,7 +6161,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/global": "npm:^5.0.0"
"@storybook/icons": "npm:^1.2.5"
"@storybook/router": "workspace:*"
Expand Down Expand Up @@ -6493,7 +6493,7 @@ __metadata:
"@storybook/client-logger": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/global": "npm:^5.0.0"
"@storybook/types": "workspace:*"
"@types/qs": "npm:^6.9.5"
Expand Down Expand Up @@ -6678,7 +6678,7 @@ __metadata:
"@storybook/core-events": "workspace:*"
"@storybook/core-server": "workspace:*"
"@storybook/core-webpack": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/csf-plugin": "workspace:*"
"@storybook/csf-tools": "workspace:*"
"@storybook/docs-tools": "workspace:*"
Expand Down Expand Up @@ -6833,7 +6833,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/server@workspace:renderers/server"
dependencies:
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/csf-tools": "workspace:*"
"@storybook/global": "npm:^5.0.0"
"@storybook/preview-api": "workspace:*"
Expand All @@ -6850,7 +6850,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/source-loader@workspace:lib/source-loader"
dependencies:
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@storybook/types": "workspace:*"
estraverse: "npm:^5.2.0"
lodash: "npm:^4.17.21"
Expand Down Expand Up @@ -7028,7 +7028,7 @@ __metadata:
resolution: "@storybook/types@workspace:lib/types"
dependencies:
"@storybook/channels": "workspace:*"
"@storybook/csf": "npm:^0.1.2"
"@storybook/csf": "npm:0.1.4--canary.80.632d12b.0"
"@types/express": "npm:^4.7.0"
"@types/fs-extra": "npm:^11.0.1"
"@types/node": "npm:^18.0.0"
Expand Down
Loading