storybook 9.1.0-alpha.5 → 9.1.0-alpha.7
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/assets/browser/favicon-wrapper.svg +46 -0
- package/assets/browser/favicon.svg +1 -1
- package/dist/bin/index.cjs +62 -69
- package/dist/bin/index.js +43 -50
- package/dist/cli/bin/index.cjs +932 -932
- package/dist/cli/bin/index.js +635 -634
- package/dist/cli/index.cjs +14965 -14973
- package/dist/cli/index.d.ts +713 -15
- package/dist/cli/index.js +13488 -13495
- package/dist/common/index.cjs +13169 -13067
- package/dist/common/index.d.ts +348 -73
- package/dist/common/index.js +24024 -23919
- package/dist/components/index.cjs +1462 -1448
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.js +412 -397
- package/dist/core-server/index.cjs +6649 -6588
- package/dist/core-server/index.d.ts +14 -2
- package/dist/core-server/index.js +6053 -5993
- package/dist/core-server/presets/common-manager.js +3438 -3353
- package/dist/core-server/presets/common-preset.cjs +2370 -2374
- package/dist/core-server/presets/common-preset.js +1881 -1881
- package/dist/csf/index.cjs +2536 -736
- package/dist/csf/index.d.ts +251 -9
- package/dist/csf/index.js +2558 -749
- package/dist/csf-tools/index.cjs +226 -224
- package/dist/csf-tools/index.js +116 -112
- package/dist/instrumenter/index.cjs +1150 -1099
- package/dist/instrumenter/index.d.ts +1 -0
- package/dist/instrumenter/index.js +1261 -1214
- package/dist/manager/globals-runtime.js +21317 -23959
- package/dist/manager/runtime.js +3713 -3534
- package/dist/manager-api/index.cjs +74 -74
- package/dist/manager-api/index.d.ts +8 -531
- package/dist/manager-api/index.js +142 -142
- package/dist/node-logger/index.cjs +8520 -994
- package/dist/node-logger/index.d.ts +395 -2
- package/dist/node-logger/index.js +8535 -995
- package/dist/preview/runtime.js +13337 -16032
- package/dist/preview-api/index.cjs +273 -271
- package/dist/preview-api/index.d.ts +4 -1
- package/dist/preview-api/index.js +14 -12
- package/dist/server-errors.cjs +201 -242
- package/dist/server-errors.d.ts +1 -12
- package/dist/server-errors.js +182 -223
- package/dist/telemetry/index.cjs +1314 -1313
- package/dist/telemetry/index.d.ts +3 -2
- package/dist/telemetry/index.js +1195 -1192
- package/dist/test/index.cjs +9136 -9815
- package/dist/test/index.js +8339 -9025
- package/dist/types/index.d.ts +15 -15
- package/package.json +6 -188
- package/dist/actions/preview.cjs +0 -159
- package/dist/actions/preview.d.ts +0 -45
- package/dist/actions/preview.js +0 -149
- package/dist/backgrounds/index.cjs +0 -16
- package/dist/backgrounds/index.d.ts +0 -2
- package/dist/backgrounds/index.js +0 -0
- package/dist/backgrounds/preview.cjs +0 -143
- package/dist/backgrounds/preview.d.ts +0 -53
- package/dist/backgrounds/preview.js +0 -127
- package/dist/component-testing/index.cjs +0 -23
- package/dist/component-testing/index.d.ts +0 -3
- package/dist/component-testing/index.js +0 -5
- package/dist/component-testing/preview.cjs +0 -40
- package/dist/component-testing/preview.d.ts +0 -5
- package/dist/component-testing/preview.js +0 -25
- package/dist/controls/preview.cjs +0 -26
- package/dist/controls/preview.d.ts +0 -43
- package/dist/controls/preview.js +0 -9
- package/dist/highlight/preview.cjs +0 -590
- package/dist/highlight/preview.d.ts +0 -20
- package/dist/highlight/preview.js +0 -575
- package/dist/measure/index.cjs +0 -16
- package/dist/measure/index.d.ts +0 -2
- package/dist/measure/index.js +0 -0
- package/dist/measure/preview.cjs +0 -466
- package/dist/measure/preview.d.ts +0 -25
- package/dist/measure/preview.js +0 -450
- package/dist/outline/index.cjs +0 -16
- package/dist/outline/index.d.ts +0 -2
- package/dist/outline/index.js +0 -0
- package/dist/outline/preview.cjs +0 -518
- package/dist/outline/preview.d.ts +0 -25
- package/dist/outline/preview.js +0 -486
- package/dist/test/preview.cjs +0 -73
- package/dist/test/preview.d.ts +0 -17
- package/dist/test/preview.js +0 -66
- package/dist/viewport/preview.cjs +0 -35
- package/dist/viewport/preview.d.ts +0 -62
- package/dist/viewport/preview.js +0 -19
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var Ge = Object.create;
|
|
3
3
|
var A = Object.defineProperty;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
4
|
+
var ze = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var Xe = Object.getOwnPropertyNames;
|
|
6
|
+
var Ke = Object.getPrototypeOf, Je = Object.prototype.hasOwnProperty;
|
|
7
7
|
var f = (s, e) => A(s, "name", { value: e, configurable: !0 });
|
|
8
|
-
var
|
|
8
|
+
var Qe = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports), He = (s, e) => {
|
|
9
9
|
for (var r in e)
|
|
10
10
|
A(s, r, { get: e[r], enumerable: !0 });
|
|
11
|
-
},
|
|
11
|
+
}, fe = (s, e, r, t) => {
|
|
12
12
|
if (e && typeof e == "object" || typeof e == "function")
|
|
13
|
-
for (let i of
|
|
14
|
-
!
|
|
13
|
+
for (let i of Xe(e))
|
|
14
|
+
!Je.call(s, i) && i !== r && A(s, i, { get: () => e[i], enumerable: !(t = ze(e, i)) || t.enumerable });
|
|
15
15
|
return s;
|
|
16
16
|
};
|
|
17
|
-
var z = (s, e, r) => (r = s != null ?
|
|
17
|
+
var z = (s, e, r) => (r = s != null ? Ge(Ke(s)) : {}, fe(
|
|
18
18
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
19
|
// file that has been converted to a CommonJS file using a Babel-
|
|
20
20
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
21
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
22
|
e || !s || !s.__esModule ? A(r, "default", { value: s, enumerable: !0 }) : r,
|
|
23
23
|
s
|
|
24
|
-
)),
|
|
24
|
+
)), Ye = (s) => fe(A({}, "__esModule", { value: !0 }), s);
|
|
25
25
|
|
|
26
26
|
// ../node_modules/ts-dedent/dist/index.js
|
|
27
|
-
var R =
|
|
27
|
+
var R = Qe(($) => {
|
|
28
28
|
"use strict";
|
|
29
29
|
Object.defineProperty($, "__esModule", { value: !0 });
|
|
30
30
|
$.dedent = void 0;
|
|
31
|
-
function
|
|
31
|
+
function de(s) {
|
|
32
32
|
for (var e = [], r = 1; r < arguments.length; r++)
|
|
33
33
|
e[r - 1] = arguments[r];
|
|
34
34
|
var t = Array.from(typeof s == "string" ? [s] : s);
|
|
@@ -60,47 +60,48 @@ var R = Je(($) => {
|
|
|
60
60
|
`)), a += x + t[p + 1];
|
|
61
61
|
}), a;
|
|
62
62
|
}
|
|
63
|
-
f(
|
|
64
|
-
$.dedent =
|
|
65
|
-
$.default =
|
|
63
|
+
f(de, "dedent");
|
|
64
|
+
$.dedent = de;
|
|
65
|
+
$.default = de;
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// src/csf-tools/index.ts
|
|
69
69
|
var dt = {};
|
|
70
|
-
|
|
70
|
+
He(dt, {
|
|
71
71
|
BadMetaError: () => U,
|
|
72
|
-
ConfigFile: () =>
|
|
72
|
+
ConfigFile: () => ee,
|
|
73
73
|
CsfFile: () => K,
|
|
74
74
|
MixedFactoryError: () => M,
|
|
75
75
|
MultipleMetaError: () => X,
|
|
76
76
|
NoMetaError: () => L,
|
|
77
|
-
babelParse: () =>
|
|
78
|
-
babelParseFile: () =>
|
|
77
|
+
babelParse: () => $e.babelParse,
|
|
78
|
+
babelParseFile: () => be,
|
|
79
79
|
enrichCsf: () => pt,
|
|
80
|
-
enrichCsfMeta: () =>
|
|
81
|
-
enrichCsfStory: () =>
|
|
82
|
-
extractDescription: () =>
|
|
83
|
-
extractSource: () =>
|
|
84
|
-
formatConfig: () =>
|
|
85
|
-
formatCsf: () =>
|
|
80
|
+
enrichCsfMeta: () => Ce,
|
|
81
|
+
enrichCsfStory: () => we,
|
|
82
|
+
extractDescription: () => ae,
|
|
83
|
+
extractSource: () => Te,
|
|
84
|
+
formatConfig: () => Pe,
|
|
85
|
+
formatCsf: () => ie,
|
|
86
86
|
getStorySortParameter: () => ct,
|
|
87
|
-
isCsfFactoryPreview: () =>
|
|
88
|
-
isModuleMock: () =>
|
|
89
|
-
isValidPreviewPath: () =>
|
|
90
|
-
loadConfig: () =>
|
|
87
|
+
isCsfFactoryPreview: () => lt,
|
|
88
|
+
isModuleMock: () => ye,
|
|
89
|
+
isValidPreviewPath: () => xe,
|
|
90
|
+
loadConfig: () => Se,
|
|
91
91
|
loadCsf: () => Q,
|
|
92
|
-
printConfig: () =>
|
|
93
|
-
printCsf: () =>
|
|
94
|
-
readConfig: () =>
|
|
95
|
-
readCsf: () =>
|
|
96
|
-
vitestTransform: () =>
|
|
97
|
-
writeConfig: () =>
|
|
98
|
-
writeCsf: () =>
|
|
92
|
+
printConfig: () => Oe,
|
|
93
|
+
printCsf: () => he,
|
|
94
|
+
readConfig: () => ot,
|
|
95
|
+
readCsf: () => st,
|
|
96
|
+
vitestTransform: () => Ae,
|
|
97
|
+
writeConfig: () => at,
|
|
98
|
+
writeCsf: () => nt
|
|
99
99
|
});
|
|
100
|
-
module.exports =
|
|
100
|
+
module.exports = Ye(dt);
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
|
-
var J = require("node:fs/promises"), c = require("storybook/internal/babel"), v = require("storybook/internal/csf"),
|
|
103
|
+
var J = require("node:fs/promises"), c = require("storybook/internal/babel"), v = require("storybook/internal/csf"), re = require("storybook/internal/node-logger"),
|
|
104
|
+
O = z(R(), 1);
|
|
104
105
|
|
|
105
106
|
// src/csf-tools/findVarInitialization.ts
|
|
106
107
|
var w = require("storybook/internal/babel");
|
|
@@ -112,8 +113,8 @@ var P = /* @__PURE__ */ f((s, e) => {
|
|
|
112
113
|
}, "findVarInitialization");
|
|
113
114
|
|
|
114
115
|
// src/csf-tools/CsfFile.ts
|
|
115
|
-
var
|
|
116
|
-
function
|
|
116
|
+
var Ze = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, xe = /* @__PURE__ */ f((s) => Ze.test(s), "isValidPreviewPath");
|
|
117
|
+
function et(s) {
|
|
117
118
|
if (c.types.isArrayExpression(s))
|
|
118
119
|
return s.elements.map((e) => {
|
|
119
120
|
if (c.types.isStringLiteral(e))
|
|
@@ -126,8 +127,8 @@ function Ze(s) {
|
|
|
126
127
|
return new RegExp(s.pattern, s.flags);
|
|
127
128
|
throw new Error(`Unknown include/exclude: ${s}`);
|
|
128
129
|
}
|
|
129
|
-
f(
|
|
130
|
-
function
|
|
130
|
+
f(et, "parseIncludeExclude");
|
|
131
|
+
function me(s) {
|
|
131
132
|
if (!c.types.isArrayExpression(s))
|
|
132
133
|
throw new Error("CSF: Expected tags array");
|
|
133
134
|
return s.elements.map((e) => {
|
|
@@ -136,7 +137,7 @@ function de(s) {
|
|
|
136
137
|
throw new Error("CSF: Expected tag to be string literal");
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
|
-
f(
|
|
140
|
+
f(me, "parseTags");
|
|
140
141
|
var D = /* @__PURE__ */ f((s, e) => {
|
|
141
142
|
let r = "";
|
|
142
143
|
if (s.loc) {
|
|
@@ -144,7 +145,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
144
145
|
r = `(line ${t}, col ${i})`;
|
|
145
146
|
}
|
|
146
147
|
return `${e || ""} ${r}`.trim();
|
|
147
|
-
}, "formatLocation"),
|
|
148
|
+
}, "formatLocation"), ye = /* @__PURE__ */ f((s) => it.test(s), "isModuleMock"), ue = /* @__PURE__ */ f((s, e, r) => {
|
|
148
149
|
let t = s;
|
|
149
150
|
if (c.types.isCallExpression(s)) {
|
|
150
151
|
let { callee: i, arguments: o } = s;
|
|
@@ -155,7 +156,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
return c.types.isArrowFunctionExpression(t) || c.types.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
158
|
-
}, "isArgsStory"),
|
|
159
|
+
}, "isArgsStory"), tt = /* @__PURE__ */ f((s) => {
|
|
159
160
|
if (c.types.isArrayExpression(s))
|
|
160
161
|
return s.elements.map((e) => {
|
|
161
162
|
if (c.types.isStringLiteral(e))
|
|
@@ -163,13 +164,13 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
163
164
|
throw new Error(`Expected string literal named export: ${e}`);
|
|
164
165
|
});
|
|
165
166
|
throw new Error(`Expected array of string literals: ${s}`);
|
|
166
|
-
}, "parseExportsOrder"),
|
|
167
|
+
}, "parseExportsOrder"), ge = /* @__PURE__ */ f((s, e) => e.reduce(
|
|
167
168
|
(r, t) => {
|
|
168
169
|
let i = s[t];
|
|
169
170
|
return i && (r[t] = i), r;
|
|
170
171
|
},
|
|
171
172
|
{}
|
|
172
|
-
), "sortExports"),
|
|
173
|
+
), "sortExports"), rt = /* @__PURE__ */ f((s) => {
|
|
173
174
|
if (c.types.isArrowFunctionExpression(s) || c.types.isFunctionDeclaration(s)) {
|
|
174
175
|
let e = s.params;
|
|
175
176
|
if (e.length >= 1) {
|
|
@@ -182,14 +183,14 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
return !1;
|
|
185
|
-
}, "hasMount"),
|
|
186
|
+
}, "hasMount"), it = /^[.\/#].*\.mock($|\.[^.]*$)/i, L = class extends Error {
|
|
186
187
|
static {
|
|
187
188
|
f(this, "NoMetaError");
|
|
188
189
|
}
|
|
189
190
|
constructor(e, r, t) {
|
|
190
|
-
let i =
|
|
191
|
+
let i = e.trim();
|
|
191
192
|
super(O.dedent`
|
|
192
|
-
CSF: ${
|
|
193
|
+
CSF: ${i} ${D(r, t)}
|
|
193
194
|
|
|
194
195
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
195
196
|
`), this.name = this.constructor.name;
|
|
@@ -266,7 +267,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
266
267
|
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
267
268
|
t.title = this._parseTitle(i.value);
|
|
268
269
|
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
269
|
-
t[i.key.name] =
|
|
270
|
+
t[i.key.name] = et(i.value);
|
|
270
271
|
else if (i.key.name === "component") {
|
|
271
272
|
let o = i.value;
|
|
272
273
|
if (c.types.isIdentifier(o)) {
|
|
@@ -282,7 +283,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
282
283
|
t.component = a;
|
|
283
284
|
} else if (i.key.name === "tags") {
|
|
284
285
|
let o = i.value;
|
|
285
|
-
c.types.isIdentifier(o) && (o = P(o.name, this._ast.program)), t.tags =
|
|
286
|
+
c.types.isIdentifier(o) && (o = P(o.name, this._ast.program)), t.tags = me(o);
|
|
286
287
|
} else if (i.key.name === "id")
|
|
287
288
|
if (c.types.isStringLiteral(i.value))
|
|
288
289
|
t.id = i.value.value;
|
|
@@ -351,12 +352,12 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
351
352
|
if (c.types.isIdentifier(l.id)) {
|
|
352
353
|
let p = !1, { name: d } = l.id;
|
|
353
354
|
if (d === "__namedExportsOrder" && c.types.isVariableDeclarator(l)) {
|
|
354
|
-
e._namedExportsOrder =
|
|
355
|
+
e._namedExportsOrder = tt(l.init);
|
|
355
356
|
return;
|
|
356
357
|
}
|
|
357
358
|
e._storyExports[d] = l, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
358
359
|
let g = (0, v.storyNameFromExport)(d);
|
|
359
|
-
e._storyAnnotations[d] ?
|
|
360
|
+
e._storyAnnotations[d] ? re.logger.warn(
|
|
360
361
|
`Unexpected annotations for "${d}" before story declaration`
|
|
361
362
|
) : e._storyAnnotations[d] = {};
|
|
362
363
|
let x;
|
|
@@ -391,7 +392,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
391
392
|
else if (b.key.name === "name" && c.types.isStringLiteral(b.value))
|
|
392
393
|
g = b.value.value;
|
|
393
394
|
else if (b.key.name === "storyName" && c.types.isStringLiteral(b.value))
|
|
394
|
-
|
|
395
|
+
re.logger.warn(
|
|
395
396
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
396
397
|
);
|
|
397
398
|
else if (b.key.name === "parameters" && c.types.isObjectExpression(b.value)) {
|
|
@@ -466,7 +467,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
466
467
|
i.arguments.length > 0) {
|
|
467
468
|
let l = t.scope.getBinding(o.object.name)?.path?.parentPath?.node;
|
|
468
469
|
if (c.types.isImportDeclaration(l))
|
|
469
|
-
if (
|
|
470
|
+
if (xe(l.source.value)) {
|
|
470
471
|
let p = i.arguments[0];
|
|
471
472
|
e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
472
473
|
} else
|
|
@@ -501,7 +502,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
501
502
|
let d = e._storyAnnotations[i], { tags: g, play: x } = d;
|
|
502
503
|
if (g) {
|
|
503
504
|
let E = c.types.isIdentifier(g) ? P(g.name, this._ast.program) : g;
|
|
504
|
-
t[i].tags =
|
|
505
|
+
t[i].tags = me(E);
|
|
505
506
|
}
|
|
506
507
|
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
507
508
|
let h = t[i].__stats;
|
|
@@ -509,15 +510,15 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
509
510
|
h[E] = !!d[E] || !!e._metaAnnotations[E];
|
|
510
511
|
});
|
|
511
512
|
let b = e.getStoryExport(i);
|
|
512
|
-
return h.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), h.mount =
|
|
513
|
-
play), h.moduleMock = !!e.imports.find((E) =>
|
|
513
|
+
return h.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), h.mount = rt(d.play ?? e._metaAnnotations.
|
|
514
|
+
play), h.moduleMock = !!e.imports.find((E) => ye(E)), t;
|
|
514
515
|
},
|
|
515
516
|
{}
|
|
516
517
|
), Object.keys(e._storyExports).forEach((t) => {
|
|
517
518
|
(0, v.isExportStory)(t, e._meta) || (delete e._storyExports[t], delete e._storyAnnotations[t], delete e._storyStatements[t]);
|
|
518
519
|
}), e._namedExportsOrder) {
|
|
519
520
|
let t = Object.keys(e._storyExports);
|
|
520
|
-
e._storyExports =
|
|
521
|
+
e._storyExports = ge(e._storyExports, e._namedExportsOrder), e._stories = ge(e._stories, e._namedExportsOrder);
|
|
521
522
|
let i = Object.keys(e._storyExports);
|
|
522
523
|
if (t.length !== i.length)
|
|
523
524
|
throw new Error(
|
|
@@ -557,44 +558,44 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
557
558
|
};
|
|
558
559
|
});
|
|
559
560
|
}
|
|
560
|
-
},
|
|
561
|
+
}, be = /* @__PURE__ */ f(({
|
|
561
562
|
code: s,
|
|
562
563
|
filename: e = "",
|
|
563
564
|
ast: r
|
|
564
565
|
}) => new c.BabelFileClass({ filename: e }, { code: s, ast: r ?? (0, c.babelParse)(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
565
|
-
let r = (0, c.babelParse)(s), t =
|
|
566
|
+
let r = (0, c.babelParse)(s), t = be({ code: s, filename: e.fileName, ast: r });
|
|
566
567
|
return new K(r, e, t);
|
|
567
|
-
}, "loadCsf"),
|
|
568
|
+
}, "loadCsf"), ie = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
568
569
|
let t = (0, c.generate)(s._ast, e, r);
|
|
569
570
|
return e.sourceMaps ? t : t.code;
|
|
570
|
-
}, "formatCsf"),
|
|
571
|
+
}, "formatCsf"), he = /* @__PURE__ */ f((s, e = {}) => c.recast.print(s._ast, e), "printCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
571
572
|
let r = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
572
573
|
return Q(r, { ...e, fileName: s });
|
|
573
|
-
}, "readCsf"),
|
|
574
|
+
}, "readCsf"), nt = /* @__PURE__ */ f(async (s, e) => {
|
|
574
575
|
if (!(e || s._options.fileName))
|
|
575
576
|
throw new Error("Please specify a fileName for writeCsf");
|
|
576
|
-
await (0, J.writeFile)(e,
|
|
577
|
+
await (0, J.writeFile)(e, he(s).code);
|
|
577
578
|
}, "writeCsf");
|
|
578
579
|
|
|
579
580
|
// src/csf-tools/ConfigFile.ts
|
|
580
|
-
var
|
|
581
|
-
var
|
|
581
|
+
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), Ee = z(R(), 1);
|
|
582
|
+
var se = /* @__PURE__ */ f(({
|
|
582
583
|
expectedType: s,
|
|
583
584
|
foundType: e,
|
|
584
585
|
node: r
|
|
585
|
-
}) =>
|
|
586
|
+
}) => Ee.dedent`
|
|
586
587
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
587
588
|
`, "getCsfParsingErrorMessage"), C = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
588
|
-
s.key.value : null, "propKey"),
|
|
589
|
-
s, "unwrap"),
|
|
589
|
+
s.key.value : null, "propKey"), Y = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? Y(s.expression) :
|
|
590
|
+
s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
590
591
|
if (s.length === 0)
|
|
591
592
|
return e;
|
|
592
593
|
if (n.types.isObjectExpression(e)) {
|
|
593
594
|
let [r, ...t] = s, i = e.properties.find((o) => C(o) === r);
|
|
594
595
|
if (i)
|
|
595
|
-
return
|
|
596
|
+
return _e(t, i.value);
|
|
596
597
|
}
|
|
597
|
-
}, "_getPath"),
|
|
598
|
+
}, "_getPath"), je = /* @__PURE__ */ f((s, e) => {
|
|
598
599
|
if (s.length === 0) {
|
|
599
600
|
if (n.types.isObjectExpression(e))
|
|
600
601
|
return e.properties;
|
|
@@ -603,14 +604,14 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
603
604
|
if (n.types.isObjectExpression(e)) {
|
|
604
605
|
let [r, ...t] = s, i = e.properties.find((o) => C(o) === r);
|
|
605
606
|
if (i)
|
|
606
|
-
return t.length === 0 ? e.properties :
|
|
607
|
+
return t.length === 0 ? e.properties : je(t, i.value);
|
|
607
608
|
}
|
|
608
|
-
}, "_getPathProperties"),
|
|
609
|
+
}, "_getPathProperties"), Z = /* @__PURE__ */ f((s, e) => {
|
|
609
610
|
let r = null, t = null;
|
|
610
611
|
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? t = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
611
612
|
i.declaration) && (t = i.declaration.declarations), t && t.find((o) => n.types.isVariableDeclarator(o) && n.types.isIdentifier(o.id) && o.
|
|
612
613
|
id.name === s ? (r = o, !0) : !1))), r;
|
|
613
|
-
}, "_findVarDeclarator"), F = /* @__PURE__ */ f((s, e) =>
|
|
614
|
+
}, "_findVarDeclarator"), F = /* @__PURE__ */ f((s, e) => Z(s, e)?.init, "_findVarInitialization"), B = /* @__PURE__ */ f((s, e) => {
|
|
614
615
|
if (s.length === 0)
|
|
615
616
|
return e;
|
|
616
617
|
let [r, ...t] = s, i = B(t, e);
|
|
@@ -622,7 +623,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
622
623
|
o ? n.types.isObjectExpression(o.value) && i.length > 0 ? q(i, e, o.value) : o.value = B(i, e) : r.properties.push(
|
|
623
624
|
n.types.objectProperty(n.types.identifier(t), B(i, e))
|
|
624
625
|
);
|
|
625
|
-
}, "_updateExportNode"),
|
|
626
|
+
}, "_updateExportNode"), ee = class {
|
|
626
627
|
constructor(e, r, t) {
|
|
627
628
|
this._exports = {};
|
|
628
629
|
// FIXME: this is a hack. this is only used in the case where the user is
|
|
@@ -651,9 +652,9 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
651
652
|
enter({ node: r, parent: t }) {
|
|
652
653
|
e.hasDefaultExport = !0;
|
|
653
654
|
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ? F(r.declaration.name, t) : r.declaration;
|
|
654
|
-
i =
|
|
655
|
-
i) ? e._parseExportsObject(i) :
|
|
656
|
-
|
|
655
|
+
i = Y(i), n.types.isCallExpression(i) && n.types.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.types.isObjectExpression(
|
|
656
|
+
i) ? e._parseExportsObject(i) : H.logger.warn(
|
|
657
|
+
se({
|
|
657
658
|
expectedType: "ObjectExpression",
|
|
658
659
|
foundType: i?.type,
|
|
659
660
|
node: i || r.declaration
|
|
@@ -678,11 +679,11 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
678
679
|
}
|
|
679
680
|
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
680
681
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
681
|
-
let { name: o } = i.local, { name: a } = i.exported, l =
|
|
682
|
+
let { name: o } = i.local, { name: a } = i.exported, l = Z(o, t);
|
|
682
683
|
l && (e._exports[a] = l.init, e._exportDecls[a] = l);
|
|
683
684
|
}
|
|
684
|
-
}) :
|
|
685
|
-
|
|
685
|
+
}) : H.logger.warn(
|
|
686
|
+
se({
|
|
686
687
|
expectedType: "VariableDeclaration",
|
|
687
688
|
foundType: r.declaration?.type,
|
|
688
689
|
node: r.declaration
|
|
@@ -697,7 +698,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
697
698
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
698
699
|
i.property.name === "exports") {
|
|
699
700
|
let a = o;
|
|
700
|
-
n.types.isIdentifier(o) && (a = F(o.name, t)), a =
|
|
701
|
+
n.types.isIdentifier(o) && (a = F(o.name, t)), a = Y(a), n.types.isObjectExpression(a) ? (e._exportsObject = a, a.properties.forEach(
|
|
701
702
|
(l) => {
|
|
702
703
|
let p = C(l);
|
|
703
704
|
if (p) {
|
|
@@ -707,8 +708,8 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
707
708
|
t
|
|
708
709
|
)), e._exports[p] = d;
|
|
709
710
|
}
|
|
710
|
-
})) :
|
|
711
|
-
|
|
711
|
+
})) : H.logger.warn(
|
|
712
|
+
se({
|
|
712
713
|
expectedType: "ObjectExpression",
|
|
713
714
|
foundType: a?.type,
|
|
714
715
|
node: a
|
|
@@ -729,12 +730,12 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
729
730
|
getFieldNode(e) {
|
|
730
731
|
let [r, ...t] = e, i = this._exports[r];
|
|
731
732
|
if (i)
|
|
732
|
-
return
|
|
733
|
+
return _e(t, i);
|
|
733
734
|
}
|
|
734
735
|
getFieldProperties(e) {
|
|
735
736
|
let [r, ...t] = e, i = this._exports[r];
|
|
736
737
|
if (i)
|
|
737
|
-
return
|
|
738
|
+
return je(t, i);
|
|
738
739
|
}
|
|
739
740
|
getFieldValue(e) {
|
|
740
741
|
let r = this.getFieldNode(e);
|
|
@@ -754,7 +755,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
754
755
|
if (this._exportsObject) {
|
|
755
756
|
let p = this._exportsObject.properties.find((d) => C(d) === t);
|
|
756
757
|
if (p && n.types.isIdentifier(p.value)) {
|
|
757
|
-
let d =
|
|
758
|
+
let d = Z(p.value.name, this._ast.program);
|
|
758
759
|
if (d && n.types.isObjectExpression(d.init)) {
|
|
759
760
|
q(i, r, d.init);
|
|
760
761
|
return;
|
|
@@ -767,7 +768,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
767
768
|
q(i, r, o);
|
|
768
769
|
return;
|
|
769
770
|
}
|
|
770
|
-
let a =
|
|
771
|
+
let a = Z(t, this._ast.program);
|
|
771
772
|
if (a && n.types.isObjectExpression(a.init)) {
|
|
772
773
|
q(i, r, a.init);
|
|
773
774
|
return;
|
|
@@ -869,7 +870,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
869
870
|
}
|
|
870
871
|
if (n.types.isExportDefaultDeclaration(o)) {
|
|
871
872
|
let a = o.declaration;
|
|
872
|
-
if (n.types.isIdentifier(a) && (a = F(a.name, this._ast.program)), a =
|
|
873
|
+
if (n.types.isIdentifier(a) && (a = F(a.name, this._ast.program)), a = Y(a), n.types.isObjectExpression(a)) {
|
|
873
874
|
let l = a.properties;
|
|
874
875
|
r(l, e[0]), i = !0;
|
|
875
876
|
}
|
|
@@ -1075,42 +1076,42 @@ s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
|
1075
1076
|
)
|
|
1076
1077
|
));
|
|
1077
1078
|
}
|
|
1078
|
-
},
|
|
1079
|
+
}, Se = /* @__PURE__ */ f((s, e) => {
|
|
1079
1080
|
let r = (0, n.babelParse)(s);
|
|
1080
|
-
return new
|
|
1081
|
-
}, "loadConfig"),
|
|
1082
|
-
"printConfig"),
|
|
1083
|
-
let e = (await (0,
|
|
1084
|
-
return
|
|
1085
|
-
}, "readConfig"),
|
|
1081
|
+
return new ee(r, s, e);
|
|
1082
|
+
}, "loadConfig"), Pe = /* @__PURE__ */ f((s) => Oe(s).code, "formatConfig"), Oe = /* @__PURE__ */ f((s, e = {}) => n.recast.print(s._ast, e),
|
|
1083
|
+
"printConfig"), ot = /* @__PURE__ */ f(async (s) => {
|
|
1084
|
+
let e = (await (0, te.readFile)(s, "utf-8")).toString();
|
|
1085
|
+
return Se(e, s).parse();
|
|
1086
|
+
}, "readConfig"), at = /* @__PURE__ */ f(async (s, e) => {
|
|
1086
1087
|
let r = e || s.fileName;
|
|
1087
1088
|
if (!r)
|
|
1088
1089
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1089
|
-
await (0,
|
|
1090
|
-
}, "writeConfig"),
|
|
1090
|
+
await (0, te.writeFile)(r, Pe(s));
|
|
1091
|
+
}, "writeConfig"), lt = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((r) => n.types.isImportDeclaration(r) && r.source.value.includes(
|
|
1091
1092
|
"@storybook") && r.specifiers.some((t) => n.types.isImportSpecifier(t) && n.types.isIdentifier(t.imported) && t.imported.name === "definePre\
|
|
1092
1093
|
view")), "isCsfFactoryPreview");
|
|
1093
1094
|
|
|
1094
1095
|
// src/csf-tools/getStorySortParameter.ts
|
|
1095
|
-
var y = require("storybook/internal/babel"),
|
|
1096
|
-
var
|
|
1096
|
+
var y = require("storybook/internal/babel"), De = require("storybook/internal/node-logger"), Ie = z(R(), 1);
|
|
1097
|
+
var ne = /* @__PURE__ */ f((s, e) => {
|
|
1097
1098
|
let r;
|
|
1098
1099
|
return s.properties.forEach((t) => {
|
|
1099
1100
|
y.types.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1100
1101
|
}), r;
|
|
1101
|
-
}, "getValue"),
|
|
1102
|
+
}, "getValue"), oe = /* @__PURE__ */ f((s) => {
|
|
1102
1103
|
let e = W(s);
|
|
1103
1104
|
if (y.types.isArrayExpression(e))
|
|
1104
|
-
return e.elements.map((r) =>
|
|
1105
|
+
return e.elements.map((r) => oe(r));
|
|
1105
1106
|
if (y.types.isObjectExpression(e))
|
|
1106
|
-
return e.properties.reduce((r, t) => (y.types.isIdentifier(t.key) && (r[t.key.name] =
|
|
1107
|
+
return e.properties.reduce((r, t) => (y.types.isIdentifier(t.key) && (r[t.key.name] = oe(t.value)), r), {});
|
|
1107
1108
|
if (y.types.isLiteral(e))
|
|
1108
1109
|
return e.value;
|
|
1109
1110
|
if (y.types.isIdentifier(e))
|
|
1110
1111
|
return T(e.name, !0);
|
|
1111
1112
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1112
1113
|
}, "parseValue"), T = /* @__PURE__ */ f((s, e) => {
|
|
1113
|
-
let r =
|
|
1114
|
+
let r = Ie.dedent`
|
|
1114
1115
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1115
1116
|
|
|
1116
1117
|
export default {
|
|
@@ -1123,24 +1124,24 @@ var lt = console, se = /* @__PURE__ */ f((s, e) => {
|
|
|
1123
1124
|
`;
|
|
1124
1125
|
if (e)
|
|
1125
1126
|
throw new Error(r);
|
|
1126
|
-
|
|
1127
|
+
De.logger.log(r);
|
|
1127
1128
|
}, "unsupported"), W = /* @__PURE__ */ f((s) => y.types.isTSAsExpression(s) || y.types.isTSSatisfiesExpression(s) ? s.expression : s, "strip\
|
|
1128
|
-
TSModifiers"),
|
|
1129
|
+
TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
1129
1130
|
let e = W(s);
|
|
1130
1131
|
if (y.types.isObjectExpression(e)) {
|
|
1131
|
-
let r =
|
|
1132
|
+
let r = ne(e, "options");
|
|
1132
1133
|
if (r) {
|
|
1133
1134
|
if (y.types.isObjectExpression(r))
|
|
1134
|
-
return
|
|
1135
|
+
return ne(r, "storySort");
|
|
1135
1136
|
T("options", !0);
|
|
1136
1137
|
}
|
|
1137
1138
|
}
|
|
1138
|
-
}, "parseParameters"),
|
|
1139
|
+
}, "parseParameters"), ve = /* @__PURE__ */ f((s, e) => {
|
|
1139
1140
|
let r = W(s);
|
|
1140
1141
|
if (y.types.isObjectExpression(r)) {
|
|
1141
|
-
let t =
|
|
1142
|
+
let t = ne(r, "parameters");
|
|
1142
1143
|
if (y.types.isIdentifier(t) && (t = P(t.name, e)), t)
|
|
1143
|
-
return
|
|
1144
|
+
return Ne(t);
|
|
1144
1145
|
} else
|
|
1145
1146
|
T("default", !0);
|
|
1146
1147
|
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
@@ -1155,7 +1156,7 @@ TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
|
1155
1156
|
let { name: o } = i.id;
|
|
1156
1157
|
if (o === "parameters" && i.init) {
|
|
1157
1158
|
let a = W(i.init);
|
|
1158
|
-
e =
|
|
1159
|
+
e = Ne(a);
|
|
1159
1160
|
}
|
|
1160
1161
|
}
|
|
1161
1162
|
}) : t.specifiers.forEach((i) => {
|
|
@@ -1167,7 +1168,7 @@ TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
|
1167
1168
|
enter({ node: t }) {
|
|
1168
1169
|
let i = t.declaration;
|
|
1169
1170
|
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i = W(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1170
|
-
e =
|
|
1171
|
+
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) : T("default", !1);
|
|
1171
1172
|
}
|
|
1172
1173
|
}
|
|
1173
1174
|
}), !!e) {
|
|
@@ -1182,112 +1183,113 @@ TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
|
1182
1183
|
}`;
|
|
1183
1184
|
return (0, eval)(o);
|
|
1184
1185
|
}
|
|
1185
|
-
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ?
|
|
1186
|
+
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? oe(e) : T("storySort", !0);
|
|
1186
1187
|
}
|
|
1187
1188
|
}, "getStorySortParameter");
|
|
1188
1189
|
|
|
1189
1190
|
// src/csf-tools/enrichCsf.ts
|
|
1190
|
-
var
|
|
1191
|
-
var
|
|
1192
|
-
let i = e.getStoryExport(r), o =
|
|
1193
|
-
i.callee.object.name === "meta", a = !t?.disableSource &&
|
|
1194
|
-
memberExpression(
|
|
1191
|
+
var u = require("storybook/internal/babel");
|
|
1192
|
+
var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1193
|
+
let i = e.getStoryExport(r), o = u.types.isCallExpression(i) && u.types.isMemberExpression(i.callee) && u.types.isIdentifier(i.callee.object) &&
|
|
1194
|
+
i.callee.object.name === "meta", a = !t?.disableSource && Te(i), l = !t?.disableDescription && ae(e._storyStatements[r]), p = [], d = o ? u.types.
|
|
1195
|
+
memberExpression(u.types.identifier(r), u.types.identifier("input")) : u.types.identifier(r), g = u.types.memberExpression(d, u.types.identifier(
|
|
1195
1196
|
"parameters"));
|
|
1196
|
-
p.push(
|
|
1197
|
-
let x =
|
|
1197
|
+
p.push(u.types.spreadElement(g));
|
|
1198
|
+
let x = u.types.optionalMemberExpression(
|
|
1198
1199
|
g,
|
|
1199
|
-
|
|
1200
|
+
u.types.identifier("docs"),
|
|
1200
1201
|
!1,
|
|
1201
1202
|
!0
|
|
1202
1203
|
), h = [];
|
|
1203
1204
|
if (a) {
|
|
1204
|
-
let b =
|
|
1205
|
+
let b = u.types.optionalMemberExpression(
|
|
1205
1206
|
x,
|
|
1206
|
-
|
|
1207
|
+
u.types.identifier("source"),
|
|
1207
1208
|
!1,
|
|
1208
1209
|
!0
|
|
1209
1210
|
);
|
|
1210
1211
|
h.push(
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1212
|
+
u.types.objectProperty(
|
|
1213
|
+
u.types.identifier("source"),
|
|
1214
|
+
u.types.objectExpression([
|
|
1215
|
+
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(a)),
|
|
1216
|
+
u.types.spreadElement(b)
|
|
1216
1217
|
])
|
|
1217
1218
|
)
|
|
1218
1219
|
);
|
|
1219
1220
|
}
|
|
1220
1221
|
if (l) {
|
|
1221
|
-
let b =
|
|
1222
|
+
let b = u.types.optionalMemberExpression(
|
|
1222
1223
|
x,
|
|
1223
|
-
|
|
1224
|
+
u.types.identifier("description"),
|
|
1224
1225
|
!1,
|
|
1225
1226
|
!0
|
|
1226
1227
|
);
|
|
1227
1228
|
h.push(
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1229
|
+
u.types.objectProperty(
|
|
1230
|
+
u.types.identifier("description"),
|
|
1231
|
+
u.types.objectExpression([
|
|
1232
|
+
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(l)),
|
|
1233
|
+
u.types.spreadElement(b)
|
|
1233
1234
|
])
|
|
1234
1235
|
)
|
|
1235
1236
|
);
|
|
1236
1237
|
}
|
|
1237
1238
|
if (h.length > 0) {
|
|
1238
1239
|
p.push(
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1240
|
+
u.types.objectProperty(
|
|
1241
|
+
u.types.identifier("docs"),
|
|
1242
|
+
u.types.objectExpression([u.types.spreadElement(x), ...h])
|
|
1242
1243
|
)
|
|
1243
1244
|
);
|
|
1244
|
-
let b =
|
|
1245
|
-
|
|
1245
|
+
let b = u.types.expressionStatement(
|
|
1246
|
+
u.types.assignmentExpression("=", g, u.types.objectExpression(p))
|
|
1246
1247
|
);
|
|
1247
1248
|
s._ast.program.body.push(b);
|
|
1248
1249
|
}
|
|
1249
|
-
}, "enrichCsfStory"),
|
|
1250
|
+
}, "enrichCsfStory"), Fe = /* @__PURE__ */ f((s, e, r) => {
|
|
1250
1251
|
if (!e.length) {
|
|
1251
1252
|
s.properties.find(
|
|
1252
|
-
(p) =>
|
|
1253
|
+
(p) => u.types.isObjectProperty(p) && u.types.isIdentifier(p.key) && p.key.name === "component"
|
|
1253
1254
|
) || s.properties.unshift(r);
|
|
1254
1255
|
return;
|
|
1255
1256
|
}
|
|
1256
1257
|
let [t, ...i] = e, o = s.properties.find(
|
|
1257
|
-
(l) =>
|
|
1258
|
+
(l) => u.types.isObjectProperty(l) && u.types.isIdentifier(l.key) && l.key.name === t && u.types.isObjectExpression(l.value)
|
|
1258
1259
|
), a;
|
|
1259
|
-
o ? a = o.value : (a =
|
|
1260
|
-
}, "addComponentDescription"),
|
|
1261
|
-
let t = !r?.disableDescription &&
|
|
1260
|
+
o ? a = o.value : (a = u.types.objectExpression([]), s.properties.push(u.types.objectProperty(u.types.identifier(t), a))), Fe(a, i, r);
|
|
1261
|
+
}, "addComponentDescription"), Ce = /* @__PURE__ */ f((s, e, r) => {
|
|
1262
|
+
let t = !r?.disableDescription && ae(e._metaStatement);
|
|
1262
1263
|
if (t) {
|
|
1263
1264
|
let i = s._metaNode;
|
|
1264
|
-
i &&
|
|
1265
|
+
i && u.types.isObjectExpression(i) && Fe(
|
|
1265
1266
|
i,
|
|
1266
1267
|
["parameters", "docs", "description"],
|
|
1267
|
-
|
|
1268
|
+
u.types.objectProperty(u.types.identifier("component"), u.types.stringLiteral(t))
|
|
1268
1269
|
);
|
|
1269
1270
|
}
|
|
1270
1271
|
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e, r) => {
|
|
1271
|
-
|
|
1272
|
-
|
|
1272
|
+
Ce(s, e, r), Object.keys(s._storyExports).forEach((t) => {
|
|
1273
|
+
we(s, e, t, r);
|
|
1273
1274
|
});
|
|
1274
|
-
}, "enrichCsf"),
|
|
1275
|
-
let e =
|
|
1275
|
+
}, "enrichCsf"), Te = /* @__PURE__ */ f((s) => {
|
|
1276
|
+
let e = u.types.isVariableDeclarator(s) ? s.init : s, { code: r } = (0, u.generate)(e, {});
|
|
1276
1277
|
return r;
|
|
1277
|
-
}, "extractSource"),
|
|
1278
|
+
}, "extractSource"), ae = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((r) => r.type === "CommentLine" || !r.value.startsWith(
|
|
1278
1279
|
"*") ? null : r.value.split(`
|
|
1279
1280
|
`).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1280
1281
|
`).trim()).filter(Boolean).join(`
|
|
1281
1282
|
`) : "", "extractDescription");
|
|
1282
1283
|
|
|
1283
1284
|
// src/csf-tools/index.ts
|
|
1284
|
-
var
|
|
1285
|
+
var $e = require("storybook/internal/babel");
|
|
1285
1286
|
|
|
1286
1287
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1287
|
-
var
|
|
1288
|
-
|
|
1289
|
-
includes(r)))
|
|
1290
|
-
|
|
1288
|
+
var m = require("storybook/internal/babel"), ke = require("storybook/internal/common"), Ve = require("storybook/internal/csf"), le = require("storybook/internal/node-logger"),
|
|
1289
|
+
ce = z(R(), 1);
|
|
1290
|
+
var ft = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((r) => s?.includes(r)) || e.exclude.some((r) => s?.includes(r))),
|
|
1291
|
+
"isValidTest");
|
|
1292
|
+
async function Ae({
|
|
1291
1293
|
code: s,
|
|
1292
1294
|
fileName: e,
|
|
1293
1295
|
configDir: r,
|
|
@@ -1301,23 +1303,23 @@ async function Ve({
|
|
|
1301
1303
|
fileName: e,
|
|
1302
1304
|
transformInlineMeta: !0,
|
|
1303
1305
|
makeTitle: /* @__PURE__ */ f((_) => {
|
|
1304
|
-
let S = (0,
|
|
1306
|
+
let S = (0, ke.getStoryTitle)({
|
|
1305
1307
|
storyFilePath: e,
|
|
1306
1308
|
configDir: r,
|
|
1307
1309
|
stories: t,
|
|
1308
1310
|
userTitle: _
|
|
1309
1311
|
}) || "unknown";
|
|
1310
|
-
return S === "unknown" &&
|
|
1311
|
-
|
|
1312
|
+
return S === "unknown" && le.logger.warn(
|
|
1313
|
+
ce.dedent`
|
|
1312
1314
|
[Storybook]: Could not calculate story title for "${e}".
|
|
1313
1315
|
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${r}".
|
|
1314
1316
|
`
|
|
1315
1317
|
), S;
|
|
1316
1318
|
}, "makeTitle")
|
|
1317
1319
|
}).parse(), p = l._ast, d = l._metaVariableName, g = l._metaNode, x = g.properties.find(
|
|
1318
|
-
(_) =>
|
|
1319
|
-
), h =
|
|
1320
|
-
if (x ?
|
|
1320
|
+
(_) => m.types.isObjectProperty(_) && m.types.isIdentifier(_.key) && _.key.name === "title"
|
|
1321
|
+
), h = m.types.stringLiteral(l._meta?.title || "unknown");
|
|
1322
|
+
if (x ? m.types.isObjectProperty(x) && (x.value = h) : g.properties.push(m.types.objectProperty(m.types.identifier("title"), h)), !g || !l.
|
|
1321
1323
|
_meta)
|
|
1322
1324
|
throw new Error(
|
|
1323
1325
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1327,7 +1329,7 @@ le an issue with details about your use case.`
|
|
|
1327
1329
|
);
|
|
1328
1330
|
let b = {};
|
|
1329
1331
|
Object.keys(l._stories).map((_) => {
|
|
1330
|
-
let S = (0,
|
|
1332
|
+
let S = (0, Ve.combineTags)(
|
|
1331
1333
|
"test",
|
|
1332
1334
|
"dev",
|
|
1333
1335
|
...o,
|
|
@@ -1338,79 +1340,79 @@ le an issue with details about your use case.`
|
|
|
1338
1340
|
});
|
|
1339
1341
|
let E = l._file.path.scope.generateUidIdentifier("test"), I = l._file.path.scope.generateUidIdentifier("describe");
|
|
1340
1342
|
if (Object.keys(b).length === 0) {
|
|
1341
|
-
let _ =
|
|
1342
|
-
|
|
1343
|
-
|
|
1343
|
+
let _ = m.types.expressionStatement(
|
|
1344
|
+
m.types.callExpression(m.types.memberExpression(I, m.types.identifier("skip")), [
|
|
1345
|
+
m.types.stringLiteral("No valid tests found")
|
|
1344
1346
|
])
|
|
1345
1347
|
);
|
|
1346
1348
|
p.program.body.push(_);
|
|
1347
1349
|
let S = [
|
|
1348
|
-
|
|
1350
|
+
m.types.importDeclaration(
|
|
1349
1351
|
[
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
+
m.types.importSpecifier(E, m.types.identifier("test")),
|
|
1353
|
+
m.types.importSpecifier(I, m.types.identifier("describe"))
|
|
1352
1354
|
],
|
|
1353
|
-
|
|
1355
|
+
m.types.stringLiteral("vitest")
|
|
1354
1356
|
)
|
|
1355
1357
|
];
|
|
1356
1358
|
p.program.body.unshift(...S);
|
|
1357
1359
|
} else {
|
|
1358
|
-
let
|
|
1359
|
-
let j = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), N =
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
), k =
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
), V =
|
|
1360
|
+
let pe = function() {
|
|
1361
|
+
let j = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), N = m.types.memberExpression(
|
|
1362
|
+
m.types.callExpression(m.types.memberExpression(_, m.types.identifier("getState")), []),
|
|
1363
|
+
m.types.identifier("testPath")
|
|
1364
|
+
), k = m.types.memberExpression(
|
|
1365
|
+
m.types.memberExpression(m.types.identifier("globalThis"), m.types.identifier("__vitest_worker__")),
|
|
1366
|
+
m.types.identifier("filepath")
|
|
1367
|
+
), V = m.types.logicalExpression(
|
|
1366
1368
|
"??",
|
|
1367
1369
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1368
1370
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1369
1371
|
k,
|
|
1370
1372
|
N
|
|
1371
|
-
), G =
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1373
|
+
), G = m.types.callExpression(
|
|
1374
|
+
m.types.memberExpression(
|
|
1375
|
+
m.types.callExpression(m.types.identifier("convertToFilePath"), [
|
|
1376
|
+
m.types.memberExpression(
|
|
1377
|
+
m.types.memberExpression(m.types.identifier("import"), m.types.identifier("meta")),
|
|
1378
|
+
m.types.identifier("url")
|
|
1377
1379
|
)
|
|
1378
1380
|
]),
|
|
1379
|
-
|
|
1381
|
+
m.types.identifier("includes")
|
|
1380
1382
|
),
|
|
1381
1383
|
[V]
|
|
1382
1384
|
);
|
|
1383
|
-
return { isRunningFromThisFileDeclaration:
|
|
1384
|
-
|
|
1385
|
+
return { isRunningFromThisFileDeclaration: m.types.variableDeclaration("const", [
|
|
1386
|
+
m.types.variableDeclarator(j, G)
|
|
1385
1387
|
]), isRunningFromThisFileId: j };
|
|
1386
1388
|
};
|
|
1387
|
-
var
|
|
1388
|
-
f(
|
|
1389
|
-
let _ = l._file.path.scope.generateUidIdentifier("expect"), S = l._file.path.scope.generateUidIdentifier("testStory"),
|
|
1390
|
-
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration:
|
|
1391
|
-
p.program.body.push(
|
|
1392
|
-
let
|
|
1389
|
+
var mt = pe;
|
|
1390
|
+
f(pe, "getTestGuardDeclaration");
|
|
1391
|
+
let _ = l._file.path.scope.generateUidIdentifier("expect"), S = l._file.path.scope.generateUidIdentifier("testStory"), Re = m.types.identifier(
|
|
1392
|
+
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Le, isRunningFromThisFileId: Me } = pe();
|
|
1393
|
+
p.program.body.push(Le);
|
|
1394
|
+
let Ue = /* @__PURE__ */ f(({
|
|
1393
1395
|
localName: j,
|
|
1394
1396
|
exportName: N,
|
|
1395
1397
|
testTitle: k,
|
|
1396
1398
|
node: V
|
|
1397
1399
|
}) => {
|
|
1398
|
-
let G =
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1400
|
+
let G = m.types.expressionStatement(
|
|
1401
|
+
m.types.callExpression(E, [
|
|
1402
|
+
m.types.stringLiteral(k),
|
|
1403
|
+
m.types.callExpression(S, [
|
|
1404
|
+
m.types.stringLiteral(N),
|
|
1405
|
+
m.types.identifier(j),
|
|
1406
|
+
m.types.identifier(d),
|
|
1407
|
+
Re
|
|
1406
1408
|
])
|
|
1407
1409
|
])
|
|
1408
1410
|
);
|
|
1409
1411
|
return G.loc = V.loc, G;
|
|
1410
|
-
}, "getTestStatementForStory"),
|
|
1412
|
+
}, "getTestStatementForStory"), qe = Object.entries(b).map(([j, N]) => {
|
|
1411
1413
|
if (N === null) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
+
le.logger.warn(
|
|
1415
|
+
ce.dedent`
|
|
1414
1416
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
1415
1417
|
Please make sure to define stories in the same file and not re-export stories coming from other files".
|
|
1416
1418
|
`
|
|
@@ -1418,27 +1420,27 @@ le an issue with details about your use case.`
|
|
|
1418
1420
|
return;
|
|
1419
1421
|
}
|
|
1420
1422
|
let k = l._stories[j].localName ?? j, V = l._stories[j].name ?? j;
|
|
1421
|
-
return
|
|
1422
|
-
}).filter((j) => !!j),
|
|
1423
|
-
p.program.body.push(
|
|
1424
|
-
let
|
|
1425
|
-
|
|
1423
|
+
return Ue({ testTitle: V, localName: k, exportName: j, node: N });
|
|
1424
|
+
}).filter((j) => !!j), Be = m.types.ifStatement(Me, m.types.blockStatement(qe));
|
|
1425
|
+
p.program.body.push(Be);
|
|
1426
|
+
let We = [
|
|
1427
|
+
m.types.importDeclaration(
|
|
1426
1428
|
[
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
+
m.types.importSpecifier(E, m.types.identifier("test")),
|
|
1430
|
+
m.types.importSpecifier(_, m.types.identifier("expect"))
|
|
1429
1431
|
],
|
|
1430
|
-
|
|
1432
|
+
m.types.stringLiteral("vitest")
|
|
1431
1433
|
),
|
|
1432
|
-
|
|
1434
|
+
m.types.importDeclaration(
|
|
1433
1435
|
[
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
+
m.types.importSpecifier(S, m.types.identifier("testStory")),
|
|
1437
|
+
m.types.importSpecifier(m.types.identifier("convertToFilePath"), m.types.identifier("convertToFilePath"))
|
|
1436
1438
|
],
|
|
1437
|
-
|
|
1439
|
+
m.types.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1438
1440
|
)
|
|
1439
1441
|
];
|
|
1440
|
-
p.program.body.unshift(...
|
|
1442
|
+
p.program.body.unshift(...We);
|
|
1441
1443
|
}
|
|
1442
|
-
return
|
|
1444
|
+
return ie(l, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1443
1445
|
}
|
|
1444
|
-
f(
|
|
1446
|
+
f(Ae, "vitestTransform");
|