storybook 9.1.4 → 9.1.5
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/bin/index.cjs +43 -43
- package/dist/bin/index.js +43 -43
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +43 -43
- package/dist/common/index.js +43 -43
- package/dist/core-server/index.cjs +1 -1
- package/dist/core-server/index.js +1 -1
- package/dist/csf-tools/index.cjs +133 -128
- package/dist/csf-tools/index.js +225 -220
- package/dist/manager/globals-runtime.js +1 -1
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.d.ts +8 -534
- package/dist/manager-api/index.js +1 -1
- package/dist/telemetry/index.cjs +1 -1
- package/dist/telemetry/index.js +1 -1
- package/package.json +1 -1
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -35,9 +35,9 @@ var $ = Qe((A) => {
|
|
|
35
35
|
t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
36
36
|
var i = t.reduce(function(c, p) {
|
|
37
37
|
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
38
|
-
return d ? c.concat(d.map(function(
|
|
39
|
-
var x,
|
|
40
|
-
return (
|
|
38
|
+
return d ? c.concat(d.map(function(u) {
|
|
39
|
+
var x, E;
|
|
40
|
+
return (E = (x = u.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && E !== void 0 ? E : 0;
|
|
41
41
|
})) : c;
|
|
42
42
|
}, []);
|
|
43
43
|
if (i.length) {
|
|
@@ -51,11 +51,11 @@ var $ = Qe((A) => {
|
|
|
51
51
|
t[0] = t[0].replace(/^\r?\n/, "");
|
|
52
52
|
var o = t[0];
|
|
53
53
|
return e.forEach(function(c, p) {
|
|
54
|
-
var d = o.match(/(?:^|\n)( *)$/),
|
|
54
|
+
var d = o.match(/(?:^|\n)( *)$/), u = d ? d[1] : "", x = c;
|
|
55
55
|
typeof c == "string" && c.includes(`
|
|
56
56
|
`) && (x = String(c).split(`
|
|
57
|
-
`).map(function(
|
|
58
|
-
return b === 0 ?
|
|
57
|
+
`).map(function(E, b) {
|
|
58
|
+
return b === 0 ? E : "" + u + E;
|
|
59
59
|
}).join(`
|
|
60
60
|
`)), o += x + t[p + 1];
|
|
61
61
|
}), o;
|
|
@@ -81,7 +81,7 @@ He(dt, {
|
|
|
81
81
|
enrichCsfStory: () => we,
|
|
82
82
|
extractDescription: () => ae,
|
|
83
83
|
extractSource: () => Te,
|
|
84
|
-
formatConfig: () =>
|
|
84
|
+
formatConfig: () => Oe,
|
|
85
85
|
formatCsf: () => ie,
|
|
86
86
|
getStorySortParameter: () => ct,
|
|
87
87
|
isCsfFactoryPreview: () => lt,
|
|
@@ -89,8 +89,8 @@ He(dt, {
|
|
|
89
89
|
isValidPreviewPath: () => xe,
|
|
90
90
|
loadConfig: () => Se,
|
|
91
91
|
loadCsf: () => Q,
|
|
92
|
-
printConfig: () =>
|
|
93
|
-
printCsf: () =>
|
|
92
|
+
printConfig: () => Pe,
|
|
93
|
+
printCsf: () => Ee,
|
|
94
94
|
readConfig: () => ot,
|
|
95
95
|
readCsf: () => st,
|
|
96
96
|
vitestTransform: () => Ae,
|
|
@@ -101,11 +101,11 @@ module.exports = Ye(dt);
|
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
103
|
var J = require("node:fs/promises"), l = require("storybook/internal/babel"), v = require("storybook/internal/csf"), re = require("storybook/internal/node-logger"),
|
|
104
|
-
|
|
104
|
+
P = z($(), 1);
|
|
105
105
|
|
|
106
106
|
// src/csf-tools/findVarInitialization.ts
|
|
107
107
|
var N = require("storybook/internal/babel");
|
|
108
|
-
var
|
|
108
|
+
var O = /* @__PURE__ */ f((s, e) => {
|
|
109
109
|
let r = null, t = null;
|
|
110
110
|
return e.body.find((i) => (N.types.isVariableDeclaration(i) ? t = i.declarations : N.types.isExportNamedDeclaration(i) && N.types.isVariableDeclaration(
|
|
111
111
|
i.declaration) && (t = i.declaration.declarations), t && t.find((a) => N.types.isVariableDeclarator(a) && N.types.isIdentifier(a.id) && a.
|
|
@@ -151,7 +151,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
151
151
|
let { callee: i, arguments: a } = s;
|
|
152
152
|
if (l.types.isProgram(e) && l.types.isMemberExpression(i) && l.types.isIdentifier(i.object) && l.types.isIdentifier(i.property) && i.property.
|
|
153
153
|
name === "bind" && (a.length === 0 || a.length === 1 && l.types.isObjectExpression(a[0]) && a[0].properties.length === 0)) {
|
|
154
|
-
let o = i.object.name, c =
|
|
154
|
+
let o = i.object.name, c = O(o, e);
|
|
155
155
|
c && (r._templates[o] = c, t = c);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -189,10 +189,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
189
189
|
}
|
|
190
190
|
constructor(e, r, t) {
|
|
191
191
|
let i = e.trim();
|
|
192
|
-
super(
|
|
192
|
+
super(P.dedent`
|
|
193
193
|
CSF: ${i} ${D(r, t)}
|
|
194
194
|
|
|
195
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
195
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
196
196
|
`), this.name = this.constructor.name;
|
|
197
197
|
}
|
|
198
198
|
}, X = class extends Error {
|
|
@@ -201,10 +201,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
201
201
|
}
|
|
202
202
|
constructor(e, r, t) {
|
|
203
203
|
let i = `${e} ${D(r, t)}`.trim();
|
|
204
|
-
super(
|
|
204
|
+
super(P.dedent`
|
|
205
205
|
CSF: ${e} ${D(r, t)}
|
|
206
206
|
|
|
207
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
207
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
208
208
|
`), this.name = this.constructor.name;
|
|
209
209
|
}
|
|
210
210
|
}, L = class extends Error {
|
|
@@ -213,10 +213,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
213
213
|
}
|
|
214
214
|
constructor(e, r, t) {
|
|
215
215
|
let i = `${e} ${D(r, t)}`.trim();
|
|
216
|
-
super(
|
|
216
|
+
super(P.dedent`
|
|
217
217
|
CSF: ${e} ${D(r, t)}
|
|
218
218
|
|
|
219
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
219
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
220
220
|
`), this.name = this.constructor.name;
|
|
221
221
|
}
|
|
222
222
|
}, M = class extends Error {
|
|
@@ -225,10 +225,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
225
225
|
}
|
|
226
226
|
constructor(e, r, t) {
|
|
227
227
|
let i = "".trim();
|
|
228
|
-
super(
|
|
228
|
+
super(P.dedent`
|
|
229
229
|
CSF: ${e} ${D(r, t)}
|
|
230
230
|
|
|
231
|
-
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
231
|
+
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
232
232
|
`), this.name = this.constructor.name;
|
|
233
233
|
}
|
|
234
234
|
}, K = class {
|
|
@@ -246,12 +246,12 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
246
246
|
f(this, "CsfFile");
|
|
247
247
|
}
|
|
248
248
|
_parseTitle(e) {
|
|
249
|
-
let r = l.types.isIdentifier(e) ?
|
|
249
|
+
let r = l.types.isIdentifier(e) ? O(e.name, this._ast.program) : e;
|
|
250
250
|
if (l.types.isStringLiteral(r))
|
|
251
251
|
return r.value;
|
|
252
252
|
if (l.types.isTSSatisfiesExpression(r) && l.types.isStringLiteral(r.expression))
|
|
253
253
|
return r.expression.value;
|
|
254
|
-
throw new Error(
|
|
254
|
+
throw new Error(P.dedent`
|
|
255
255
|
CSF: unexpected dynamic title ${D(r, this._options.fileName)}
|
|
256
256
|
|
|
257
257
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
@@ -272,7 +272,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
272
272
|
let a = i.value;
|
|
273
273
|
if (l.types.isIdentifier(a)) {
|
|
274
274
|
let c = a.name, p = r.body.find(
|
|
275
|
-
(d) => l.types.isImportDeclaration(d) && d.specifiers.find((
|
|
275
|
+
(d) => l.types.isImportDeclaration(d) && d.specifiers.find((u) => u.local.name === c)
|
|
276
276
|
);
|
|
277
277
|
if (p) {
|
|
278
278
|
let { source: d } = p;
|
|
@@ -283,7 +283,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
283
283
|
t.component = o;
|
|
284
284
|
} else if (i.key.name === "tags") {
|
|
285
285
|
let a = i.value;
|
|
286
|
-
l.types.isIdentifier(a) && (a =
|
|
286
|
+
l.types.isIdentifier(a) && (a = O(a.name, this._ast.program)), t.tags = me(a);
|
|
287
287
|
} else if (i.key.name === "id")
|
|
288
288
|
if (l.types.isStringLiteral(i.value))
|
|
289
289
|
t.id = i.value.value;
|
|
@@ -313,28 +313,30 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
313
313
|
if (e._options.transformInlineMeta && !o && l.types.isExpression(i.declaration)) {
|
|
314
314
|
let d = t.scope.generateUidIdentifier("meta");
|
|
315
315
|
e._metaVariableName = d.name;
|
|
316
|
-
let
|
|
316
|
+
let u = [
|
|
317
317
|
l.types.variableDeclaration("const", [l.types.variableDeclarator(d, i.declaration)]),
|
|
318
318
|
l.types.exportDefaultDeclaration(d)
|
|
319
319
|
];
|
|
320
|
-
|
|
320
|
+
u.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(u);
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
323
|
let c, p;
|
|
324
324
|
if (o) {
|
|
325
325
|
let d = i.declaration.name;
|
|
326
326
|
e._metaVariableName = d;
|
|
327
|
-
let
|
|
327
|
+
let u = /* @__PURE__ */ f((x) => l.types.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
328
328
|
e._metaStatement = e._ast.program.body.find(
|
|
329
|
-
(x) => l.types.isVariableDeclaration(x) && x.declarations.find(
|
|
329
|
+
(x) => l.types.isVariableDeclaration(x) && x.declarations.find(u)
|
|
330
330
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
331
|
-
|
|
331
|
+
u
|
|
332
332
|
)?.init;
|
|
333
333
|
} else
|
|
334
334
|
e._metaStatement = i, p = i.declaration;
|
|
335
|
-
if (l.types.isObjectExpression(p) ? c = p : (
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
if (l.types.isObjectExpression(p) ? c = p : /* export default { ... } as Meta<...> */ /* export default { ... } satisfies Meta<...> */ (l.types.
|
|
336
|
+
isTSAsExpression(p) || l.types.isTSSatisfiesExpression(p)) && l.types.isObjectExpression(p.expression) ? c = p.expression : (
|
|
337
|
+
// export default { ... } satisfies Meta as Meta<...>
|
|
338
|
+
l.types.isTSAsExpression(p) && l.types.isTSSatisfiesExpression(p.expression) && l.types.isObjectExpression(p.expression.expression) &&
|
|
339
|
+
(c = p.expression.expression)
|
|
338
340
|
), c && l.types.isProgram(a) && e._parseMeta(c, a), e._metaStatement && !e._metaNode)
|
|
339
341
|
throw new R(
|
|
340
342
|
"default export must be an object",
|
|
@@ -356,14 +358,15 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
356
358
|
return;
|
|
357
359
|
}
|
|
358
360
|
e._storyExports[d] = c, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
359
|
-
let
|
|
361
|
+
let u = (0, v.storyNameFromExport)(d);
|
|
360
362
|
e._storyAnnotations[d] ? re.logger.warn(
|
|
361
363
|
`Unexpected annotations for "${d}" before story declaration`
|
|
362
364
|
) : e._storyAnnotations[d] = {};
|
|
363
365
|
let x;
|
|
364
|
-
if (l.types.isVariableDeclarator(c) ?
|
|
365
|
-
|
|
366
|
-
|
|
366
|
+
if (l.types.isVariableDeclarator(c) ? l.types.isTSAsExpression(c.init) && l.types.isTSSatisfiesExpression(c.init.expression) ?
|
|
367
|
+
x = c.init.expression.expression : l.types.isTSAsExpression(c.init) || l.types.isTSSatisfiesExpression(c.init) ? x = c.init.expression :
|
|
368
|
+
x = c.init : x = c, l.types.isCallExpression(x) && l.types.isMemberExpression(x.callee) && l.types.isIdentifier(x.callee.property) &&
|
|
369
|
+
(x.callee.property.name === "story" || x.callee.property.name === "extend") && (p = !0, x = x.arguments[0]), e._metaIsFactory &&
|
|
367
370
|
!p)
|
|
368
371
|
throw new L(
|
|
369
372
|
"expected factory story",
|
|
@@ -380,17 +383,17 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
380
383
|
x,
|
|
381
384
|
e._options.fileName
|
|
382
385
|
);
|
|
383
|
-
let
|
|
384
|
-
l.types.isObjectExpression(x) ? (
|
|
386
|
+
let E = {};
|
|
387
|
+
l.types.isObjectExpression(x) ? (E.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
385
388
|
if (l.types.isIdentifier(b.key)) {
|
|
386
389
|
if (b.key.name === "render")
|
|
387
|
-
|
|
390
|
+
E.__isArgsStory = ue(
|
|
388
391
|
b.value,
|
|
389
392
|
a,
|
|
390
393
|
e
|
|
391
394
|
);
|
|
392
395
|
else if (b.key.name === "name" && l.types.isStringLiteral(b.value))
|
|
393
|
-
|
|
396
|
+
u = b.value.value;
|
|
394
397
|
else if (b.key.name === "storyName" && l.types.isStringLiteral(b.value))
|
|
395
398
|
re.logger.warn(
|
|
396
399
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
@@ -399,14 +402,14 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
399
402
|
let _ = b.value.properties.find(
|
|
400
403
|
(W) => l.types.isObjectProperty(W) && l.types.isIdentifier(W.key) && W.key.name === "__id"
|
|
401
404
|
);
|
|
402
|
-
_ && (
|
|
405
|
+
_ && (E.__id = _.value.value);
|
|
403
406
|
}
|
|
404
407
|
e._storyAnnotations[d][b.key.name] = b.value;
|
|
405
408
|
}
|
|
406
|
-
})) :
|
|
409
|
+
})) : E.__isArgsStory = ue(x, a, e), e._stories[d] = {
|
|
407
410
|
id: "FIXME",
|
|
408
|
-
name:
|
|
409
|
-
parameters:
|
|
411
|
+
name: u,
|
|
412
|
+
parameters: E,
|
|
410
413
|
__stats: {
|
|
411
414
|
factory: p
|
|
412
415
|
}
|
|
@@ -414,18 +417,20 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
414
417
|
}
|
|
415
418
|
}) : i.specifiers.length > 0 && i.specifiers.forEach((c) => {
|
|
416
419
|
if (l.types.isExportSpecifier(c) && l.types.isIdentifier(c.exported)) {
|
|
417
|
-
let { name: p } = c.exported, { name: d } = c.local,
|
|
420
|
+
let { name: p } = c.exported, { name: d } = c.local, u = l.types.isProgram(a) ? O(d, a) : c.local;
|
|
418
421
|
if (p === "default") {
|
|
419
422
|
let x;
|
|
420
|
-
l.types.isObjectExpression(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
+
l.types.isObjectExpression(u) ? x = u : /* export default { ... } as Meta<...> */ /* export default { ... } satisfies Meta<...> */ (l.types.
|
|
424
|
+
isTSAsExpression(u) || l.types.isTSSatisfiesExpression(u)) && l.types.isObjectExpression(u.expression) ? x = u.expression : (
|
|
425
|
+
// export default { ... } satisfies Meta as Meta<...>
|
|
426
|
+
l.types.isTSAsExpression(u) && l.types.isTSSatisfiesExpression(u.expression) && l.types.isObjectExpression(u.expression.expression) &&
|
|
427
|
+
(x = u.expression.expression)
|
|
423
428
|
), x && l.types.isProgram(a) && e._parseMeta(x, a);
|
|
424
429
|
} else {
|
|
425
|
-
let x = {},
|
|
426
|
-
l.types.isObjectExpression(
|
|
430
|
+
let x = {}, E = u;
|
|
431
|
+
l.types.isObjectExpression(E) && E.properties.forEach((b) => {
|
|
427
432
|
l.types.isIdentifier(b.key) && (x[b.key.name] = b.value);
|
|
428
|
-
}), e._storyAnnotations[p] = x, e._storyStatements[p] =
|
|
433
|
+
}), e._storyAnnotations[p] = x, e._storyStatements[p] = u, e._storyPaths[p] = t, e._stories[p] = {
|
|
429
434
|
id: "FIXME",
|
|
430
435
|
name: p,
|
|
431
436
|
localName: d,
|
|
@@ -446,10 +451,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
446
451
|
if (e._storyAnnotations[o] && (c === "story" && l.types.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
447
452
|
l.types.isIdentifier(d.key) && (e._storyAnnotations[o][d.key.name] = d.value);
|
|
448
453
|
}) : e._storyAnnotations[o][c] = p), c === "storyName" && l.types.isStringLiteral(p)) {
|
|
449
|
-
let d = p.value,
|
|
450
|
-
if (!
|
|
454
|
+
let d = p.value, u = e._stories[o];
|
|
455
|
+
if (!u)
|
|
451
456
|
return;
|
|
452
|
-
|
|
457
|
+
u.name = d;
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
460
|
}
|
|
@@ -458,10 +463,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
458
463
|
enter(t) {
|
|
459
464
|
let { node: i } = t, { callee: a } = i;
|
|
460
465
|
if (l.types.isIdentifier(a) && a.name === "storiesOf")
|
|
461
|
-
throw new Error(
|
|
466
|
+
throw new Error(P.dedent`
|
|
462
467
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
463
468
|
|
|
464
|
-
SB8 does not support \`storiesOf\`.
|
|
469
|
+
SB8 does not support \`storiesOf\`.
|
|
465
470
|
`);
|
|
466
471
|
if (l.types.isMemberExpression(a) && l.types.isIdentifier(a.property) && a.property.name === "meta" && l.types.isIdentifier(a.object) &&
|
|
467
472
|
i.arguments.length > 0) {
|
|
@@ -499,19 +504,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
499
504
|
let o = a.parameters?.__id ?? (0, v.toId)(e._meta?.id || e._meta?.title, (0, v.storyNameFromExport)(i)), c = { ...a.parameters, __id: o },
|
|
500
505
|
{ includeStories: p } = e._meta || {};
|
|
501
506
|
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (c.docsOnly = !0), t[i] = { ...a, id: o, parameters: c };
|
|
502
|
-
let d = e._storyAnnotations[i], { tags:
|
|
503
|
-
if (
|
|
504
|
-
let _ = l.types.isIdentifier(
|
|
507
|
+
let d = e._storyAnnotations[i], { tags: u, play: x } = d;
|
|
508
|
+
if (u) {
|
|
509
|
+
let _ = l.types.isIdentifier(u) ? O(u.name, this._ast.program) : u;
|
|
505
510
|
t[i].tags = me(_);
|
|
506
511
|
}
|
|
507
512
|
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
508
|
-
let
|
|
513
|
+
let E = t[i].__stats;
|
|
509
514
|
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((_) => {
|
|
510
|
-
|
|
515
|
+
E[_] = !!d[_] || !!e._metaAnnotations[_];
|
|
511
516
|
});
|
|
512
517
|
let b = e.getStoryExport(i);
|
|
513
|
-
return
|
|
514
|
-
play),
|
|
518
|
+
return E.storyFn = !!(l.types.isArrowFunctionExpression(b) || l.types.isFunctionDeclaration(b)), E.mount = rt(d.play ?? e._metaAnnotations.
|
|
519
|
+
play), E.moduleMock = !!e.imports.find((_) => ye(_)), t;
|
|
515
520
|
},
|
|
516
521
|
{}
|
|
517
522
|
), Object.keys(e._storyExports).forEach((t) => {
|
|
@@ -539,7 +544,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
539
544
|
let { fileName: e } = this._options;
|
|
540
545
|
if (!e)
|
|
541
546
|
throw new Error(
|
|
542
|
-
|
|
547
|
+
P.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
543
548
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
544
549
|
);
|
|
545
550
|
return Object.entries(this._stories).map(([r, t]) => {
|
|
@@ -568,22 +573,22 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
568
573
|
}, "loadCsf"), ie = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
569
574
|
let t = (0, l.generate)(s._ast, e, r);
|
|
570
575
|
return e.sourceMaps ? t : t.code;
|
|
571
|
-
}, "formatCsf"),
|
|
576
|
+
}, "formatCsf"), Ee = /* @__PURE__ */ f((s, e = {}) => l.recast.print(s._ast, e), "printCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
572
577
|
let r = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
573
578
|
return Q(r, { ...e, fileName: s });
|
|
574
579
|
}, "readCsf"), nt = /* @__PURE__ */ f(async (s, e) => {
|
|
575
580
|
if (!(e || s._options.fileName))
|
|
576
581
|
throw new Error("Please specify a fileName for writeCsf");
|
|
577
|
-
await (0, J.writeFile)(e,
|
|
582
|
+
await (0, J.writeFile)(e, Ee(s).code);
|
|
578
583
|
}, "writeCsf");
|
|
579
584
|
|
|
580
585
|
// src/csf-tools/ConfigFile.ts
|
|
581
|
-
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"),
|
|
586
|
+
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), he = z($(), 1);
|
|
582
587
|
var se = /* @__PURE__ */ f(({
|
|
583
588
|
expectedType: s,
|
|
584
589
|
foundType: e,
|
|
585
590
|
node: r
|
|
586
|
-
}) =>
|
|
591
|
+
}) => he.dedent`
|
|
587
592
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
588
593
|
`, "getCsfParsingErrorMessage"), F = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
589
594
|
s.key.value : null, "propKey"), Y = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? Y(s.expression) :
|
|
@@ -1046,13 +1051,13 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1046
1051
|
return d && (r = p.source.value), d;
|
|
1047
1052
|
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"), a = /* @__PURE__ */ f(
|
|
1048
1053
|
(p, d) => p.specifiers.find(
|
|
1049
|
-
(
|
|
1054
|
+
(u) => n.types.isImportSpecifier(u) && n.types.isIdentifier(u.imported) && u.imported.name === d
|
|
1050
1055
|
), "hasImportSpecifier"), o = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1051
|
-
(
|
|
1056
|
+
(u) => n.types.isImportNamespaceSpecifier(u) && n.types.isIdentifier(u.local) && u.local.name === d
|
|
1052
1057
|
), "hasNamespaceImportSpecifier");
|
|
1053
1058
|
e === null ? t || this._ast.program.body.unshift(n.types.importDeclaration([], n.types.stringLiteral(r))) : typeof e == "string" ? t ? (/* @__PURE__ */ f(
|
|
1054
1059
|
(p, d) => p.specifiers.find(
|
|
1055
|
-
(
|
|
1060
|
+
(u) => n.types.isImportDefaultSpecifier(u) && n.types.isIdentifier(u.local) && u.local.name === d
|
|
1056
1061
|
), "hasDefaultImportSpecifier"))(t, e) || t.specifiers.push(
|
|
1057
1062
|
n.types.importDefaultSpecifier(n.types.identifier(e))
|
|
1058
1063
|
) : this._ast.program.body.unshift(
|
|
@@ -1079,7 +1084,7 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1079
1084
|
}, Se = /* @__PURE__ */ f((s, e) => {
|
|
1080
1085
|
let r = (0, n.babelParse)(s);
|
|
1081
1086
|
return new ee(r, s, e);
|
|
1082
|
-
}, "loadConfig"),
|
|
1087
|
+
}, "loadConfig"), Oe = /* @__PURE__ */ f((s) => Pe(s).code, "formatConfig"), Pe = /* @__PURE__ */ f((s, e = {}) => n.recast.print(s._ast, e),
|
|
1083
1088
|
"printConfig"), ot = /* @__PURE__ */ f(async (s) => {
|
|
1084
1089
|
let e = (await (0, te.readFile)(s, "utf-8")).toString();
|
|
1085
1090
|
return Se(e, s).parse();
|
|
@@ -1087,7 +1092,7 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1087
1092
|
let r = e || s.fileName;
|
|
1088
1093
|
if (!r)
|
|
1089
1094
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1090
|
-
await (0, te.writeFile)(r,
|
|
1095
|
+
await (0, te.writeFile)(r, Oe(s));
|
|
1091
1096
|
}, "writeConfig"), lt = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((r) => n.types.isImportDeclaration(r) && r.source.value.includes(
|
|
1092
1097
|
"@storybook") && r.specifiers.some((t) => n.types.isImportSpecifier(t) && n.types.isIdentifier(t.imported) && t.imported.name === "definePre\
|
|
1093
1098
|
view")), "isCsfFactoryPreview");
|
|
@@ -1140,7 +1145,7 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1140
1145
|
let r = B(s);
|
|
1141
1146
|
if (y.types.isObjectExpression(r)) {
|
|
1142
1147
|
let t = ne(r, "parameters");
|
|
1143
|
-
if (y.types.isIdentifier(t) && (t =
|
|
1148
|
+
if (y.types.isIdentifier(t) && (t = O(t.name, e)), t)
|
|
1144
1149
|
return Ne(t);
|
|
1145
1150
|
} else
|
|
1146
1151
|
C("default", !0);
|
|
@@ -1167,7 +1172,7 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1167
1172
|
ExportDefaultDeclaration: {
|
|
1168
1173
|
enter({ node: t }) {
|
|
1169
1174
|
let i = t.declaration;
|
|
1170
|
-
y.types.isIdentifier(i) && (i =
|
|
1175
|
+
y.types.isIdentifier(i) && (i = O(i.name, r.program)), i = B(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1171
1176
|
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) : C("default", !1);
|
|
1172
1177
|
}
|
|
1173
1178
|
}
|
|
@@ -1188,84 +1193,84 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1188
1193
|
}, "getStorySortParameter");
|
|
1189
1194
|
|
|
1190
1195
|
// src/csf-tools/enrichCsf.ts
|
|
1191
|
-
var
|
|
1196
|
+
var g = require("storybook/internal/babel");
|
|
1192
1197
|
var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1193
|
-
let i = e.getStoryExport(r), a =
|
|
1194
|
-
i.callee.object.name === "meta", o = !t?.disableSource && Te(i), c = !t?.disableDescription && ae(e._storyStatements[r]), p = [], d = a ?
|
|
1195
|
-
memberExpression(
|
|
1198
|
+
let i = e.getStoryExport(r), a = g.types.isCallExpression(i) && g.types.isMemberExpression(i.callee) && g.types.isIdentifier(i.callee.object) &&
|
|
1199
|
+
i.callee.object.name === "meta", o = !t?.disableSource && Te(i), c = !t?.disableDescription && ae(e._storyStatements[r]), p = [], d = a ? g.types.
|
|
1200
|
+
memberExpression(g.types.identifier(r), g.types.identifier("input")) : g.types.identifier(r), u = g.types.memberExpression(d, g.types.identifier(
|
|
1196
1201
|
"parameters"));
|
|
1197
|
-
p.push(
|
|
1198
|
-
let x =
|
|
1199
|
-
|
|
1200
|
-
|
|
1202
|
+
p.push(g.types.spreadElement(u));
|
|
1203
|
+
let x = g.types.optionalMemberExpression(
|
|
1204
|
+
u,
|
|
1205
|
+
g.types.identifier("docs"),
|
|
1201
1206
|
!1,
|
|
1202
1207
|
!0
|
|
1203
|
-
),
|
|
1208
|
+
), E = [];
|
|
1204
1209
|
if (o) {
|
|
1205
|
-
let b =
|
|
1210
|
+
let b = g.types.optionalMemberExpression(
|
|
1206
1211
|
x,
|
|
1207
|
-
|
|
1212
|
+
g.types.identifier("source"),
|
|
1208
1213
|
!1,
|
|
1209
1214
|
!0
|
|
1210
1215
|
);
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1216
|
+
E.push(
|
|
1217
|
+
g.types.objectProperty(
|
|
1218
|
+
g.types.identifier("source"),
|
|
1219
|
+
g.types.objectExpression([
|
|
1220
|
+
g.types.objectProperty(g.types.identifier("originalSource"), g.types.stringLiteral(o)),
|
|
1221
|
+
g.types.spreadElement(b)
|
|
1217
1222
|
])
|
|
1218
1223
|
)
|
|
1219
1224
|
);
|
|
1220
1225
|
}
|
|
1221
1226
|
if (c) {
|
|
1222
|
-
let b =
|
|
1227
|
+
let b = g.types.optionalMemberExpression(
|
|
1223
1228
|
x,
|
|
1224
|
-
|
|
1229
|
+
g.types.identifier("description"),
|
|
1225
1230
|
!1,
|
|
1226
1231
|
!0
|
|
1227
1232
|
);
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1233
|
+
E.push(
|
|
1234
|
+
g.types.objectProperty(
|
|
1235
|
+
g.types.identifier("description"),
|
|
1236
|
+
g.types.objectExpression([
|
|
1237
|
+
g.types.objectProperty(g.types.identifier("story"), g.types.stringLiteral(c)),
|
|
1238
|
+
g.types.spreadElement(b)
|
|
1234
1239
|
])
|
|
1235
1240
|
)
|
|
1236
1241
|
);
|
|
1237
1242
|
}
|
|
1238
|
-
if (
|
|
1243
|
+
if (E.length > 0) {
|
|
1239
1244
|
p.push(
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1245
|
+
g.types.objectProperty(
|
|
1246
|
+
g.types.identifier("docs"),
|
|
1247
|
+
g.types.objectExpression([g.types.spreadElement(x), ...E])
|
|
1243
1248
|
)
|
|
1244
1249
|
);
|
|
1245
|
-
let b =
|
|
1246
|
-
|
|
1250
|
+
let b = g.types.expressionStatement(
|
|
1251
|
+
g.types.assignmentExpression("=", u, g.types.objectExpression(p))
|
|
1247
1252
|
);
|
|
1248
1253
|
s._ast.program.body.push(b);
|
|
1249
1254
|
}
|
|
1250
1255
|
}, "enrichCsfStory"), Fe = /* @__PURE__ */ f((s, e, r) => {
|
|
1251
1256
|
if (!e.length) {
|
|
1252
1257
|
s.properties.find(
|
|
1253
|
-
(p) =>
|
|
1258
|
+
(p) => g.types.isObjectProperty(p) && g.types.isIdentifier(p.key) && p.key.name === "component"
|
|
1254
1259
|
) || s.properties.unshift(r);
|
|
1255
1260
|
return;
|
|
1256
1261
|
}
|
|
1257
1262
|
let [t, ...i] = e, a = s.properties.find(
|
|
1258
|
-
(c) =>
|
|
1263
|
+
(c) => g.types.isObjectProperty(c) && g.types.isIdentifier(c.key) && c.key.name === t && g.types.isObjectExpression(c.value)
|
|
1259
1264
|
), o;
|
|
1260
|
-
a ? o = a.value : (o =
|
|
1265
|
+
a ? o = a.value : (o = g.types.objectExpression([]), s.properties.push(g.types.objectProperty(g.types.identifier(t), o))), Fe(o, i, r);
|
|
1261
1266
|
}, "addComponentDescription"), Ce = /* @__PURE__ */ f((s, e, r) => {
|
|
1262
1267
|
let t = !r?.disableDescription && ae(e._metaStatement);
|
|
1263
1268
|
if (t) {
|
|
1264
1269
|
let i = s._metaNode;
|
|
1265
|
-
i &&
|
|
1270
|
+
i && g.types.isObjectExpression(i) && Fe(
|
|
1266
1271
|
i,
|
|
1267
1272
|
["parameters", "docs", "description"],
|
|
1268
|
-
|
|
1273
|
+
g.types.objectProperty(g.types.identifier("component"), g.types.stringLiteral(t))
|
|
1269
1274
|
);
|
|
1270
1275
|
}
|
|
1271
1276
|
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e, r) => {
|
|
@@ -1273,7 +1278,7 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1273
1278
|
we(s, e, t, r);
|
|
1274
1279
|
});
|
|
1275
1280
|
}, "enrichCsf"), Te = /* @__PURE__ */ f((s) => {
|
|
1276
|
-
let e =
|
|
1281
|
+
let e = g.types.isVariableDeclarator(s) ? s.init : s, { code: r } = (0, g.generate)(e, {});
|
|
1277
1282
|
return r;
|
|
1278
1283
|
}, "extractSource"), ae = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((r) => r.type === "CommentLine" || !r.value.startsWith(
|
|
1279
1284
|
"*") ? null : r.value.split(`
|
|
@@ -1300,12 +1305,12 @@ async function Ae({
|
|
|
1300
1305
|
let o = Q(s, {
|
|
1301
1306
|
fileName: e,
|
|
1302
1307
|
transformInlineMeta: !0,
|
|
1303
|
-
makeTitle: /* @__PURE__ */ f((
|
|
1308
|
+
makeTitle: /* @__PURE__ */ f((h) => {
|
|
1304
1309
|
let S = (0, ke.getStoryTitle)({
|
|
1305
1310
|
storyFilePath: e,
|
|
1306
1311
|
configDir: r,
|
|
1307
1312
|
stories: t,
|
|
1308
|
-
userTitle:
|
|
1313
|
+
userTitle: h
|
|
1309
1314
|
}) || "unknown";
|
|
1310
1315
|
return S === "unknown" && le.logger.warn(
|
|
1311
1316
|
ce.dedent`
|
|
@@ -1314,10 +1319,10 @@ async function Ae({
|
|
|
1314
1319
|
`
|
|
1315
1320
|
), S;
|
|
1316
1321
|
}, "makeTitle")
|
|
1317
|
-
}).parse(), c = o._ast, p = o._metaVariableName, d = o._metaNode,
|
|
1318
|
-
(
|
|
1322
|
+
}).parse(), c = o._ast, p = o._metaVariableName, d = o._metaNode, u = d.properties.find(
|
|
1323
|
+
(h) => m.types.isObjectProperty(h) && m.types.isIdentifier(h.key) && h.key.name === "title"
|
|
1319
1324
|
), x = m.types.stringLiteral(o._meta?.title || "unknown");
|
|
1320
|
-
if (
|
|
1325
|
+
if (u ? m.types.isObjectProperty(u) && (u.value = x) : d.properties.push(m.types.objectProperty(m.types.identifier("title"), x)), !d || !o.
|
|
1321
1326
|
_meta)
|
|
1322
1327
|
throw new Error(
|
|
1323
1328
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1325,25 +1330,25 @@ async function Ae({
|
|
|
1325
1330
|
Please make sure you have a default export with the meta object. If you are using a different export format that is not supported, please fi\
|
|
1326
1331
|
le an issue with details about your use case.`
|
|
1327
1332
|
);
|
|
1328
|
-
let
|
|
1329
|
-
Object.keys(o._stories).map((
|
|
1333
|
+
let E = {};
|
|
1334
|
+
Object.keys(o._stories).map((h) => {
|
|
1330
1335
|
let S = (0, Ve.combineTags)(
|
|
1331
1336
|
"test",
|
|
1332
1337
|
"dev",
|
|
1333
1338
|
...a,
|
|
1334
1339
|
...o.meta?.tags || [],
|
|
1335
|
-
...o._stories[
|
|
1340
|
+
...o._stories[h].tags || []
|
|
1336
1341
|
);
|
|
1337
|
-
ft(S, i) && (h
|
|
1342
|
+
ft(S, i) && (E[h] = o._storyStatements[h]);
|
|
1338
1343
|
});
|
|
1339
1344
|
let b = o._file.path.scope.generateUidIdentifier("test"), _ = o._file.path.scope.generateUidIdentifier("describe");
|
|
1340
|
-
if (Object.keys(
|
|
1341
|
-
let
|
|
1345
|
+
if (Object.keys(E).length === 0) {
|
|
1346
|
+
let h = m.types.expressionStatement(
|
|
1342
1347
|
m.types.callExpression(m.types.memberExpression(_, m.types.identifier("skip")), [
|
|
1343
1348
|
m.types.stringLiteral("No valid tests found")
|
|
1344
1349
|
])
|
|
1345
1350
|
);
|
|
1346
|
-
c.program.body.push(
|
|
1351
|
+
c.program.body.push(h);
|
|
1347
1352
|
let S = [
|
|
1348
1353
|
m.types.importDeclaration(
|
|
1349
1354
|
[
|
|
@@ -1357,7 +1362,7 @@ le an issue with details about your use case.`
|
|
|
1357
1362
|
} else {
|
|
1358
1363
|
let pe = function() {
|
|
1359
1364
|
let j = o._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), I = m.types.memberExpression(
|
|
1360
|
-
m.types.callExpression(m.types.memberExpression(
|
|
1365
|
+
m.types.callExpression(m.types.memberExpression(h, m.types.identifier("getState")), []),
|
|
1361
1366
|
m.types.identifier("testPath")
|
|
1362
1367
|
), T = m.types.memberExpression(
|
|
1363
1368
|
m.types.memberExpression(m.types.identifier("globalThis"), m.types.identifier("__vitest_worker__")),
|
|
@@ -1386,7 +1391,7 @@ le an issue with details about your use case.`
|
|
|
1386
1391
|
};
|
|
1387
1392
|
var W = pe;
|
|
1388
1393
|
f(pe, "getTestGuardDeclaration");
|
|
1389
|
-
let
|
|
1394
|
+
let h = o._file.path.scope.generateUidIdentifier("expect"), S = o._file.path.scope.generateUidIdentifier("testStory"), Re = m.types.identifier(
|
|
1390
1395
|
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Le, isRunningFromThisFileId: Me } = pe();
|
|
1391
1396
|
c.program.body.push(Le);
|
|
1392
1397
|
let Ue = /* @__PURE__ */ f(({
|
|
@@ -1407,7 +1412,7 @@ le an issue with details about your use case.`
|
|
|
1407
1412
|
])
|
|
1408
1413
|
);
|
|
1409
1414
|
return G.loc = k.loc, G;
|
|
1410
|
-
}, "getTestStatementForStory"), qe = Object.entries(
|
|
1415
|
+
}, "getTestStatementForStory"), qe = Object.entries(E).map(([j, I]) => {
|
|
1411
1416
|
if (I === null) {
|
|
1412
1417
|
le.logger.warn(
|
|
1413
1418
|
ce.dedent`
|
|
@@ -1425,7 +1430,7 @@ le an issue with details about your use case.`
|
|
|
1425
1430
|
m.types.importDeclaration(
|
|
1426
1431
|
[
|
|
1427
1432
|
m.types.importSpecifier(b, m.types.identifier("test")),
|
|
1428
|
-
m.types.importSpecifier(
|
|
1433
|
+
m.types.importSpecifier(h, m.types.identifier("expect"))
|
|
1429
1434
|
],
|
|
1430
1435
|
m.types.stringLiteral("vitest")
|
|
1431
1436
|
),
|