@cappa/plugin-storybook 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -37,7 +37,6 @@ module.exports = __toCommonJS(index_cjs_exports);
37
37
 
38
38
  // src/cappa/plugin.ts
39
39
  var import_logger = require("@cappa/logger");
40
- var import_minimatch = require("minimatch");
41
40
 
42
41
  // src/cappa/storybook-url.ts
43
42
  function encodePairs(obj) {
@@ -177,23 +176,13 @@ async function waitForPlayFunctionCompletion(page, storyName) {
177
176
  });
178
177
  }
179
178
  }
180
- function matchesGlobPatterns(story, patterns) {
181
- return patterns.some((pattern) => {
182
- if ((0, import_minimatch.minimatch)(story.id, pattern)) {
183
- return true;
184
- }
185
- if ((0, import_minimatch.minimatch)(story.title, pattern)) {
186
- return true;
187
- }
188
- if ((0, import_minimatch.minimatch)(story.name, pattern)) {
189
- return true;
190
- }
191
- const fullPath = `${story.title}/${story.name}`;
192
- if ((0, import_minimatch.minimatch)(fullPath, pattern)) {
193
- return true;
194
- }
195
- return false;
196
- });
179
+ function toFilterContext(story) {
180
+ return {
181
+ id: story.id,
182
+ title: story.title,
183
+ name: story.name,
184
+ filePath: `${story.title}/${story.name}`
185
+ };
197
186
  }
198
187
  function createLatch() {
199
188
  let resolve;
@@ -216,8 +205,8 @@ var cappaPluginStorybook = (options) => {
216
205
  const logger = (0, import_logger.getLogger)();
217
206
  const {
218
207
  storybookUrl,
219
- includeStories = [],
220
- excludeStories = [],
208
+ includeStories,
209
+ excludeStories,
221
210
  storybook: defaultStorybookOptions
222
211
  } = options;
223
212
  const storiesUrl = `${storybookUrl}/index.json`;
@@ -231,14 +220,14 @@ var cappaPluginStorybook = (options) => {
231
220
  const data = await response.json();
232
221
  const stories = Object.values(data.entries);
233
222
  let filteredStories = stories;
234
- if (includeStories.length > 0) {
223
+ if (includeStories) {
235
224
  filteredStories = filteredStories.filter(
236
- (story) => matchesGlobPatterns(story, includeStories)
225
+ (story) => includeStories(toFilterContext(story))
237
226
  );
238
227
  }
239
- if (excludeStories.length > 0) {
228
+ if (excludeStories) {
240
229
  filteredStories = filteredStories.filter(
241
- (story) => !matchesGlobPatterns(story, excludeStories)
230
+ (story) => !excludeStories(toFilterContext(story))
242
231
  );
243
232
  }
244
233
  filteredStories = filteredStories.filter(
@@ -36,37 +36,31 @@ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook
36
36
  variants?: ScreenshotVariantOptionsStorybook[];
37
37
  }
38
38
 
39
+ /**
40
+ * Context passed to includeStories and excludeStories predicate functions.
41
+ * Use these fields to decide which stories to include or exclude.
42
+ */
43
+ interface StoryFilterContext {
44
+ id: string;
45
+ title: string;
46
+ name: string;
47
+ /** Full story path: `${title}/${name}` (e.g. "Button/Primary") */
48
+ filePath: string;
49
+ }
39
50
  interface StorybookPluginOptions {
40
51
  storybookUrl: string;
41
52
  /**
42
- * Array of glob patterns to include stories. Stories matching any of these patterns will be included.
43
- * Patterns can match against:
44
- * - Story ID (e.g., "button--primary")
45
- * - Story title (e.g., "Button")
46
- * - Story name (e.g., "Primary")
47
- * - Full story path (e.g., "Button/Primary")
48
- *
49
- * Examples:
50
- * - ["button--*"] - Include all button stories
51
- * - ["*--primary"] - Include all primary stories
52
- * - ["Button/*"] - Include all stories under Button title
53
- * - ["*--*"] - Include all stories
53
+ * Optional predicate to include stories. If provided, only stories for which
54
+ * it returns true are included. Example: (s) => s.id === 'button--primary'
55
+ * or (s) => s.title === 'Button'.
54
56
  */
55
- includeStories?: string[];
57
+ includeStories?: (story: StoryFilterContext) => boolean;
56
58
  /**
57
- * Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
58
- * Patterns can match against:
59
- * - Story ID (e.g., "button--primary")
60
- * - Story title (e.g., "Button")
61
- * - Story name (e.g., "Primary")
62
- * - Full story path (e.g., "Button/Primary")
63
- *
64
- * Examples:
65
- * - ["button--*"] - Exclude all button stories
66
- * - ["*--secondary"] - Exclude all secondary stories
67
- * - ["Input/*"] - Exclude all stories under Input title
59
+ * Optional predicate to exclude stories. If provided, stories for which it
60
+ * returns true are excluded (applied after includeStories). Example:
61
+ * (s) => s.title === 'Input'.
68
62
  */
69
- excludeStories?: string[];
63
+ excludeStories?: (story: StoryFilterContext) => boolean;
70
64
  defaultViewport?: {
71
65
  width: number;
72
66
  height: number;
@@ -78,10 +72,10 @@ interface StorybookPluginOptions {
78
72
  /**
79
73
  * Storybook Plugin for Cappa
80
74
  * Fetches stories from a running Storybook server and takes screenshots of each story.
81
- * Supports glob pattern matching for includeStories and excludeStories options.
75
+ * Supports includeStories and excludeStories predicate functions for filtering.
82
76
  */
83
77
  declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
84
78
 
85
79
  declare const previewAnnotations: string[];
86
80
 
87
- export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
81
+ export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StoryFilterContext, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
@@ -36,37 +36,31 @@ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook
36
36
  variants?: ScreenshotVariantOptionsStorybook[];
37
37
  }
38
38
 
39
+ /**
40
+ * Context passed to includeStories and excludeStories predicate functions.
41
+ * Use these fields to decide which stories to include or exclude.
42
+ */
43
+ interface StoryFilterContext {
44
+ id: string;
45
+ title: string;
46
+ name: string;
47
+ /** Full story path: `${title}/${name}` (e.g. "Button/Primary") */
48
+ filePath: string;
49
+ }
39
50
  interface StorybookPluginOptions {
40
51
  storybookUrl: string;
41
52
  /**
42
- * Array of glob patterns to include stories. Stories matching any of these patterns will be included.
43
- * Patterns can match against:
44
- * - Story ID (e.g., "button--primary")
45
- * - Story title (e.g., "Button")
46
- * - Story name (e.g., "Primary")
47
- * - Full story path (e.g., "Button/Primary")
48
- *
49
- * Examples:
50
- * - ["button--*"] - Include all button stories
51
- * - ["*--primary"] - Include all primary stories
52
- * - ["Button/*"] - Include all stories under Button title
53
- * - ["*--*"] - Include all stories
53
+ * Optional predicate to include stories. If provided, only stories for which
54
+ * it returns true are included. Example: (s) => s.id === 'button--primary'
55
+ * or (s) => s.title === 'Button'.
54
56
  */
55
- includeStories?: string[];
57
+ includeStories?: (story: StoryFilterContext) => boolean;
56
58
  /**
57
- * Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
58
- * Patterns can match against:
59
- * - Story ID (e.g., "button--primary")
60
- * - Story title (e.g., "Button")
61
- * - Story name (e.g., "Primary")
62
- * - Full story path (e.g., "Button/Primary")
63
- *
64
- * Examples:
65
- * - ["button--*"] - Exclude all button stories
66
- * - ["*--secondary"] - Exclude all secondary stories
67
- * - ["Input/*"] - Exclude all stories under Input title
59
+ * Optional predicate to exclude stories. If provided, stories for which it
60
+ * returns true are excluded (applied after includeStories). Example:
61
+ * (s) => s.title === 'Input'.
68
62
  */
69
- excludeStories?: string[];
63
+ excludeStories?: (story: StoryFilterContext) => boolean;
70
64
  defaultViewport?: {
71
65
  width: number;
72
66
  height: number;
@@ -78,10 +72,10 @@ interface StorybookPluginOptions {
78
72
  /**
79
73
  * Storybook Plugin for Cappa
80
74
  * Fetches stories from a running Storybook server and takes screenshots of each story.
81
- * Supports glob pattern matching for includeStories and excludeStories options.
75
+ * Supports includeStories and excludeStories predicate functions for filtering.
82
76
  */
83
77
  declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
84
78
 
85
79
  declare const previewAnnotations: string[];
86
80
 
87
- export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
81
+ export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StoryFilterContext, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@ import { fileURLToPath } from "url";
3
3
 
4
4
  // src/cappa/plugin.ts
5
5
  import { getLogger } from "@cappa/logger";
6
- import { minimatch } from "minimatch";
7
6
 
8
7
  // src/cappa/storybook-url.ts
9
8
  function encodePairs(obj) {
@@ -143,23 +142,13 @@ async function waitForPlayFunctionCompletion(page, storyName) {
143
142
  });
144
143
  }
145
144
  }
146
- function matchesGlobPatterns(story, patterns) {
147
- return patterns.some((pattern) => {
148
- if (minimatch(story.id, pattern)) {
149
- return true;
150
- }
151
- if (minimatch(story.title, pattern)) {
152
- return true;
153
- }
154
- if (minimatch(story.name, pattern)) {
155
- return true;
156
- }
157
- const fullPath = `${story.title}/${story.name}`;
158
- if (minimatch(fullPath, pattern)) {
159
- return true;
160
- }
161
- return false;
162
- });
145
+ function toFilterContext(story) {
146
+ return {
147
+ id: story.id,
148
+ title: story.title,
149
+ name: story.name,
150
+ filePath: `${story.title}/${story.name}`
151
+ };
163
152
  }
164
153
  function createLatch() {
165
154
  let resolve;
@@ -182,8 +171,8 @@ var cappaPluginStorybook = (options) => {
182
171
  const logger = getLogger();
183
172
  const {
184
173
  storybookUrl,
185
- includeStories = [],
186
- excludeStories = [],
174
+ includeStories,
175
+ excludeStories,
187
176
  storybook: defaultStorybookOptions
188
177
  } = options;
189
178
  const storiesUrl = `${storybookUrl}/index.json`;
@@ -197,14 +186,14 @@ var cappaPluginStorybook = (options) => {
197
186
  const data = await response.json();
198
187
  const stories = Object.values(data.entries);
199
188
  let filteredStories = stories;
200
- if (includeStories.length > 0) {
189
+ if (includeStories) {
201
190
  filteredStories = filteredStories.filter(
202
- (story) => matchesGlobPatterns(story, includeStories)
191
+ (story) => includeStories(toFilterContext(story))
203
192
  );
204
193
  }
205
- if (excludeStories.length > 0) {
194
+ if (excludeStories) {
206
195
  filteredStories = filteredStories.filter(
207
- (story) => !matchesGlobPatterns(story, excludeStories)
196
+ (story) => !excludeStories(toFilterContext(story))
208
197
  );
209
198
  }
210
199
  filteredStories = filteredStories.filter(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/plugin-storybook",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,11 +42,16 @@
42
42
  "./package.json": "./package.json"
43
43
  },
44
44
  "keywords": [
45
+ "storybook-addon",
45
46
  "screenshot",
46
47
  "plugin",
47
48
  "storybook",
48
49
  "visual-testing"
49
50
  ],
51
+ "storybook": {
52
+ "displayName": "Cappa",
53
+ "unsupportedFrameworks": []
54
+ },
50
55
  "peerDependencies": {
51
56
  "storybook": "^9 || ^10"
52
57
  },
@@ -58,7 +63,6 @@
58
63
  "dependencies": {
59
64
  "@swc/core": "^1.15.18",
60
65
  "chalk": "^5.6.2",
61
- "minimatch": "^10.2.4",
62
66
  "@cappa/core": "0.7.2",
63
67
  "@cappa/logger": "0.0.10"
64
68
  },