storybook 9.1.0-alpha.7 → 9.1.0-alpha.9
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 +69 -69
- package/dist/cli/bin/index.js +61 -61
- package/dist/common/index.cjs +43 -43
- package/dist/common/index.js +43 -43
- package/dist/components/index.cjs +4140 -3977
- package/dist/components/index.d.ts +8 -11
- package/dist/components/index.js +2741 -2574
- package/dist/core-server/index.cjs +4 -1
- package/dist/core-server/index.js +4 -1
- package/dist/core-server/presets/common-manager.js +307 -300
- package/dist/core-server/presets/common-preset.cjs +85031 -5227
- package/dist/core-server/presets/common-preset.js +85102 -5288
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.cjs +28727 -0
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +28728 -0
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.cjs +29339 -0
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +29340 -0
- package/dist/csf-tools/index.cjs +319 -321
- package/dist/csf-tools/index.js +239 -241
- package/dist/manager/globals-module-info.cjs +1 -1
- package/dist/manager/globals-module-info.js +1 -1
- package/dist/manager/globals-runtime.js +15073 -14903
- package/dist/manager/runtime.js +103 -103
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.d.ts +534 -8
- package/dist/manager-api/index.js +1 -1
- package/dist/preview/runtime.js +572 -568
- package/dist/telemetry/index.cjs +1733 -1642
- package/dist/telemetry/index.d.ts +2 -1
- package/dist/telemetry/index.js +1727 -1637
- package/dist/test/index.cjs +284 -280
- package/dist/test/index.d.ts +8 -1
- package/dist/test/index.js +5 -1
- package/package.json +14 -1
- package/templates/mocker-runtime.template.js +89 -0
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var Ge = Object.create;
|
|
3
|
-
var
|
|
3
|
+
var V = Object.defineProperty;
|
|
4
4
|
var ze = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var Xe = Object.getOwnPropertyNames;
|
|
6
6
|
var Ke = Object.getPrototypeOf, Je = Object.prototype.hasOwnProperty;
|
|
7
|
-
var f = (s, e) =>
|
|
7
|
+
var f = (s, e) => V(s, "name", { value: e, configurable: !0 });
|
|
8
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
|
+
V(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
13
|
for (let i of Xe(e))
|
|
14
|
-
!Je.call(s, i) && i !== r &&
|
|
14
|
+
!Je.call(s, i) && i !== r && V(s, i, { get: () => e[i], enumerable: !(t = ze(e, i)) || t.enumerable });
|
|
15
15
|
return s;
|
|
16
16
|
};
|
|
17
17
|
var z = (s, e, r) => (r = s != null ? Ge(Ke(s)) : {}, fe(
|
|
@@ -19,61 +19,61 @@ var z = (s, e, r) => (r = s != null ? Ge(Ke(s)) : {}, fe(
|
|
|
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
|
-
e || !s || !s.__esModule ?
|
|
22
|
+
e || !s || !s.__esModule ? V(r, "default", { value: s, enumerable: !0 }) : r,
|
|
23
23
|
s
|
|
24
|
-
)), Ye = (s) => fe(
|
|
24
|
+
)), Ye = (s) => fe(V({}, "__esModule", { value: !0 }), s);
|
|
25
25
|
|
|
26
26
|
// ../node_modules/ts-dedent/dist/index.js
|
|
27
|
-
var
|
|
27
|
+
var $ = Qe((A) => {
|
|
28
28
|
"use strict";
|
|
29
|
-
Object.defineProperty(
|
|
30
|
-
|
|
29
|
+
Object.defineProperty(A, "__esModule", { value: !0 });
|
|
30
|
+
A.dedent = void 0;
|
|
31
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);
|
|
35
35
|
t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
36
|
-
var i = t.reduce(function(
|
|
36
|
+
var i = t.reduce(function(c, p) {
|
|
37
37
|
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
38
|
-
return d ?
|
|
38
|
+
return d ? c.concat(d.map(function(g) {
|
|
39
39
|
var x, h;
|
|
40
40
|
return (h = (x = g.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && h !== void 0 ? h : 0;
|
|
41
|
-
})) :
|
|
41
|
+
})) : c;
|
|
42
42
|
}, []);
|
|
43
43
|
if (i.length) {
|
|
44
|
-
var
|
|
44
|
+
var a = new RegExp(`
|
|
45
45
|
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
46
|
-
t = t.map(function(
|
|
47
|
-
return
|
|
46
|
+
t = t.map(function(c) {
|
|
47
|
+
return c.replace(a, `
|
|
48
48
|
`);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
t[0] = t[0].replace(/^\r?\n/, "");
|
|
52
|
-
var
|
|
53
|
-
return e.forEach(function(
|
|
54
|
-
var d =
|
|
55
|
-
typeof
|
|
56
|
-
`) && (x = String(
|
|
52
|
+
var o = t[0];
|
|
53
|
+
return e.forEach(function(c, p) {
|
|
54
|
+
var d = o.match(/(?:^|\n)( *)$/), g = d ? d[1] : "", x = c;
|
|
55
|
+
typeof c == "string" && c.includes(`
|
|
56
|
+
`) && (x = String(c).split(`
|
|
57
57
|
`).map(function(h, b) {
|
|
58
58
|
return b === 0 ? h : "" + g + h;
|
|
59
59
|
}).join(`
|
|
60
|
-
`)),
|
|
61
|
-
}),
|
|
60
|
+
`)), o += x + t[p + 1];
|
|
61
|
+
}), o;
|
|
62
62
|
}
|
|
63
63
|
f(de, "dedent");
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
A.dedent = de;
|
|
65
|
+
A.default = de;
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// src/csf-tools/index.ts
|
|
69
69
|
var dt = {};
|
|
70
70
|
He(dt, {
|
|
71
|
-
BadMetaError: () =>
|
|
71
|
+
BadMetaError: () => M,
|
|
72
72
|
ConfigFile: () => ee,
|
|
73
73
|
CsfFile: () => K,
|
|
74
|
-
MixedFactoryError: () =>
|
|
74
|
+
MixedFactoryError: () => L,
|
|
75
75
|
MultipleMetaError: () => X,
|
|
76
|
-
NoMetaError: () =>
|
|
76
|
+
NoMetaError: () => R,
|
|
77
77
|
babelParse: () => $e.babelParse,
|
|
78
78
|
babelParseFile: () => be,
|
|
79
79
|
enrichCsf: () => pt,
|
|
@@ -100,39 +100,39 @@ He(dt, {
|
|
|
100
100
|
module.exports = Ye(dt);
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
|
-
var J = require("node:fs/promises"),
|
|
104
|
-
O = z(
|
|
103
|
+
var J = require("node:fs/promises"), l = require("storybook/internal/babel"), v = require("storybook/internal/csf"), re = require("storybook/internal/node-logger"),
|
|
104
|
+
O = z($(), 1);
|
|
105
105
|
|
|
106
106
|
// src/csf-tools/findVarInitialization.ts
|
|
107
|
-
var
|
|
107
|
+
var N = require("storybook/internal/babel");
|
|
108
108
|
var P = /* @__PURE__ */ f((s, e) => {
|
|
109
109
|
let r = null, t = null;
|
|
110
|
-
return e.body.find((i) => (
|
|
111
|
-
i.declaration) && (t = i.declaration.declarations), t && t.find((
|
|
112
|
-
id.name === s ? (r =
|
|
110
|
+
return e.body.find((i) => (N.types.isVariableDeclaration(i) ? t = i.declarations : N.types.isExportNamedDeclaration(i) && N.types.isVariableDeclaration(
|
|
111
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((a) => N.types.isVariableDeclarator(a) && N.types.isIdentifier(a.id) && a.
|
|
112
|
+
id.name === s ? (r = a.init, !0) : !1))), r;
|
|
113
113
|
}, "findVarInitialization");
|
|
114
114
|
|
|
115
115
|
// src/csf-tools/CsfFile.ts
|
|
116
116
|
var Ze = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, xe = /* @__PURE__ */ f((s) => Ze.test(s), "isValidPreviewPath");
|
|
117
117
|
function et(s) {
|
|
118
|
-
if (
|
|
118
|
+
if (l.types.isArrayExpression(s))
|
|
119
119
|
return s.elements.map((e) => {
|
|
120
|
-
if (
|
|
120
|
+
if (l.types.isStringLiteral(e))
|
|
121
121
|
return e.value;
|
|
122
122
|
throw new Error(`Expected string literal: ${e}`);
|
|
123
123
|
});
|
|
124
|
-
if (
|
|
124
|
+
if (l.types.isStringLiteral(s))
|
|
125
125
|
return new RegExp(s.value);
|
|
126
|
-
if (
|
|
126
|
+
if (l.types.isRegExpLiteral(s))
|
|
127
127
|
return new RegExp(s.pattern, s.flags);
|
|
128
128
|
throw new Error(`Unknown include/exclude: ${s}`);
|
|
129
129
|
}
|
|
130
130
|
f(et, "parseIncludeExclude");
|
|
131
131
|
function me(s) {
|
|
132
|
-
if (!
|
|
132
|
+
if (!l.types.isArrayExpression(s))
|
|
133
133
|
throw new Error("CSF: Expected tags array");
|
|
134
134
|
return s.elements.map((e) => {
|
|
135
|
-
if (
|
|
135
|
+
if (l.types.isStringLiteral(e))
|
|
136
136
|
return e.value;
|
|
137
137
|
throw new Error("CSF: Expected tag to be string literal");
|
|
138
138
|
});
|
|
@@ -147,19 +147,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
147
147
|
return `${e || ""} ${r}`.trim();
|
|
148
148
|
}, "formatLocation"), ye = /* @__PURE__ */ f((s) => it.test(s), "isModuleMock"), ue = /* @__PURE__ */ f((s, e, r) => {
|
|
149
149
|
let t = s;
|
|
150
|
-
if (
|
|
151
|
-
let { callee: i, arguments:
|
|
152
|
-
if (
|
|
153
|
-
name === "bind" && (
|
|
154
|
-
let
|
|
155
|
-
|
|
150
|
+
if (l.types.isCallExpression(s)) {
|
|
151
|
+
let { callee: i, arguments: a } = s;
|
|
152
|
+
if (l.types.isProgram(e) && l.types.isMemberExpression(i) && l.types.isIdentifier(i.object) && l.types.isIdentifier(i.property) && i.property.
|
|
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 = P(o, e);
|
|
155
|
+
c && (r._templates[o] = c, t = c);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
return
|
|
158
|
+
return l.types.isArrowFunctionExpression(t) || l.types.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
159
159
|
}, "isArgsStory"), tt = /* @__PURE__ */ f((s) => {
|
|
160
|
-
if (
|
|
160
|
+
if (l.types.isArrayExpression(s))
|
|
161
161
|
return s.elements.map((e) => {
|
|
162
|
-
if (
|
|
162
|
+
if (l.types.isStringLiteral(e))
|
|
163
163
|
return e.value;
|
|
164
164
|
throw new Error(`Expected string literal named export: ${e}`);
|
|
165
165
|
});
|
|
@@ -171,19 +171,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
171
171
|
},
|
|
172
172
|
{}
|
|
173
173
|
), "sortExports"), rt = /* @__PURE__ */ f((s) => {
|
|
174
|
-
if (
|
|
174
|
+
if (l.types.isArrowFunctionExpression(s) || l.types.isFunctionDeclaration(s)) {
|
|
175
175
|
let e = s.params;
|
|
176
176
|
if (e.length >= 1) {
|
|
177
177
|
let [r] = e;
|
|
178
|
-
if (
|
|
178
|
+
if (l.types.isObjectPattern(r))
|
|
179
179
|
return !!r.properties.find((t) => {
|
|
180
|
-
if (
|
|
180
|
+
if (l.types.isObjectProperty(t) && l.types.isIdentifier(t.key))
|
|
181
181
|
return t.key.name === "mount";
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
return !1;
|
|
186
|
-
}, "hasMount"), it = /^[.\/#].*\.mock($|\.[^.]*$)/i,
|
|
186
|
+
}, "hasMount"), it = /^[.\/#].*\.mock($|\.[^.]*$)/i, R = class extends Error {
|
|
187
187
|
static {
|
|
188
188
|
f(this, "NoMetaError");
|
|
189
189
|
}
|
|
@@ -207,7 +207,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
207
207
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
208
208
|
`), this.name = this.constructor.name;
|
|
209
209
|
}
|
|
210
|
-
},
|
|
210
|
+
}, L = class extends Error {
|
|
211
211
|
static {
|
|
212
212
|
f(this, "MixedFactoryError");
|
|
213
213
|
}
|
|
@@ -219,7 +219,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
219
219
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
220
220
|
`), this.name = this.constructor.name;
|
|
221
221
|
}
|
|
222
|
-
},
|
|
222
|
+
}, M = class extends Error {
|
|
223
223
|
static {
|
|
224
224
|
f(this, "BadMetaError");
|
|
225
225
|
}
|
|
@@ -246,10 +246,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
246
246
|
f(this, "CsfFile");
|
|
247
247
|
}
|
|
248
248
|
_parseTitle(e) {
|
|
249
|
-
let r =
|
|
250
|
-
if (
|
|
249
|
+
let r = l.types.isIdentifier(e) ? P(e.name, this._ast.program) : e;
|
|
250
|
+
if (l.types.isStringLiteral(r))
|
|
251
251
|
return r.value;
|
|
252
|
-
if (
|
|
252
|
+
if (l.types.isTSSatisfiesExpression(r) && l.types.isStringLiteral(r.expression))
|
|
253
253
|
return r.expression.value;
|
|
254
254
|
throw new Error(O.dedent`
|
|
255
255
|
CSF: unexpected dynamic title ${D(r, this._options.fileName)}
|
|
@@ -263,29 +263,29 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
263
263
|
this._metaNode = e;
|
|
264
264
|
let t = {};
|
|
265
265
|
e.properties.forEach((i) => {
|
|
266
|
-
if (
|
|
266
|
+
if (l.types.isIdentifier(i.key)) {
|
|
267
267
|
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
268
268
|
t.title = this._parseTitle(i.value);
|
|
269
269
|
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
270
270
|
t[i.key.name] = et(i.value);
|
|
271
271
|
else if (i.key.name === "component") {
|
|
272
|
-
let
|
|
273
|
-
if (
|
|
274
|
-
let
|
|
275
|
-
(d) =>
|
|
272
|
+
let a = i.value;
|
|
273
|
+
if (l.types.isIdentifier(a)) {
|
|
274
|
+
let c = a.name, p = r.body.find(
|
|
275
|
+
(d) => l.types.isImportDeclaration(d) && d.specifiers.find((g) => g.local.name === c)
|
|
276
276
|
);
|
|
277
277
|
if (p) {
|
|
278
278
|
let { source: d } = p;
|
|
279
|
-
|
|
279
|
+
l.types.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
let { code:
|
|
283
|
-
t.component =
|
|
282
|
+
let { code: o } = l.recast.print(i.value, {});
|
|
283
|
+
t.component = o;
|
|
284
284
|
} else if (i.key.name === "tags") {
|
|
285
|
-
let
|
|
286
|
-
|
|
285
|
+
let a = i.value;
|
|
286
|
+
l.types.isIdentifier(a) && (a = P(a.name, this._ast.program)), t.tags = me(a);
|
|
287
287
|
} else if (i.key.name === "id")
|
|
288
|
-
if (
|
|
288
|
+
if (l.types.isStringLiteral(i.value))
|
|
289
289
|
t.id = i.value.value;
|
|
290
290
|
else
|
|
291
291
|
throw new Error(`Unexpected component id: ${i.value}`);
|
|
@@ -294,49 +294,49 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
294
294
|
}
|
|
295
295
|
getStoryExport(e) {
|
|
296
296
|
let r = this._storyExports[e];
|
|
297
|
-
if (r =
|
|
297
|
+
if (r = l.types.isVariableDeclarator(r) ? r.init : r, l.types.isCallExpression(r)) {
|
|
298
298
|
let { callee: t, arguments: i } = r;
|
|
299
|
-
if (
|
|
300
|
-
(i.length === 0 || i.length === 1 &&
|
|
301
|
-
let { name:
|
|
302
|
-
r = this._templates[
|
|
299
|
+
if (l.types.isMemberExpression(t) && l.types.isIdentifier(t.object) && l.types.isIdentifier(t.property) && t.property.name === "bind" &&
|
|
300
|
+
(i.length === 0 || i.length === 1 && l.types.isObjectExpression(i[0]) && i[0].properties.length === 0)) {
|
|
301
|
+
let { name: a } = t.object;
|
|
302
|
+
r = this._templates[a];
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
return r;
|
|
306
306
|
}
|
|
307
307
|
parse() {
|
|
308
308
|
let e = this;
|
|
309
|
-
if ((0,
|
|
309
|
+
if ((0, l.traverse)(this._ast, {
|
|
310
310
|
ExportDefaultDeclaration: {
|
|
311
311
|
enter(t) {
|
|
312
|
-
let { node: i, parent:
|
|
313
|
-
if (e._options.transformInlineMeta && !
|
|
312
|
+
let { node: i, parent: a } = t, o = l.types.isIdentifier(i.declaration) && l.types.isProgram(a);
|
|
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
316
|
let g = [
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
l.types.variableDeclaration("const", [l.types.variableDeclarator(d, i.declaration)]),
|
|
318
|
+
l.types.exportDefaultDeclaration(d)
|
|
319
319
|
];
|
|
320
320
|
g.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(g);
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
|
-
let
|
|
324
|
-
if (
|
|
323
|
+
let c, p;
|
|
324
|
+
if (o) {
|
|
325
325
|
let d = i.declaration.name;
|
|
326
326
|
e._metaVariableName = d;
|
|
327
|
-
let g = /* @__PURE__ */ f((x) =>
|
|
327
|
+
let g = /* @__PURE__ */ f((x) => l.types.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
328
328
|
e._metaStatement = e._ast.program.body.find(
|
|
329
|
-
(x) =>
|
|
329
|
+
(x) => l.types.isVariableDeclaration(x) && x.declarations.find(g)
|
|
330
330
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
331
331
|
g
|
|
332
332
|
)?.init;
|
|
333
333
|
} else
|
|
334
334
|
e._metaStatement = i, p = i.declaration;
|
|
335
|
-
if (
|
|
335
|
+
if (l.types.isObjectExpression(p) ? c = p : (
|
|
336
336
|
// export default { ... } as Meta<...>
|
|
337
|
-
(
|
|
338
|
-
),
|
|
339
|
-
throw new
|
|
337
|
+
(l.types.isTSAsExpression(p) || l.types.isTSSatisfiesExpression(p)) && l.types.isObjectExpression(p.expression) && (c = p.expression)
|
|
338
|
+
), c && l.types.isProgram(a) && e._parseMeta(c, a), e._metaStatement && !e._metaNode)
|
|
339
|
+
throw new R(
|
|
340
340
|
"default export must be an object",
|
|
341
341
|
e._metaStatement,
|
|
342
342
|
e._options.fileName
|
|
@@ -346,64 +346,64 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
346
346
|
},
|
|
347
347
|
ExportNamedDeclaration: {
|
|
348
348
|
enter(t) {
|
|
349
|
-
let { node: i, parent:
|
|
350
|
-
|
|
351
|
-
isFunctionDeclaration(i.declaration) && (
|
|
352
|
-
if (
|
|
353
|
-
let p = !1, { name: d } =
|
|
354
|
-
if (d === "__namedExportsOrder" &&
|
|
355
|
-
e._namedExportsOrder = tt(
|
|
349
|
+
let { node: i, parent: a } = t, o;
|
|
350
|
+
l.types.isVariableDeclaration(i.declaration) ? o = i.declaration.declarations.filter((c) => l.types.isVariableDeclarator(c)) : l.types.
|
|
351
|
+
isFunctionDeclaration(i.declaration) && (o = [i.declaration]), o ? o.forEach((c) => {
|
|
352
|
+
if (l.types.isIdentifier(c.id)) {
|
|
353
|
+
let p = !1, { name: d } = c.id;
|
|
354
|
+
if (d === "__namedExportsOrder" && l.types.isVariableDeclarator(c)) {
|
|
355
|
+
e._namedExportsOrder = tt(c.init);
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
|
-
e._storyExports[d] =
|
|
358
|
+
e._storyExports[d] = c, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
359
359
|
let g = (0, v.storyNameFromExport)(d);
|
|
360
360
|
e._storyAnnotations[d] ? re.logger.warn(
|
|
361
361
|
`Unexpected annotations for "${d}" before story declaration`
|
|
362
362
|
) : e._storyAnnotations[d] = {};
|
|
363
363
|
let x;
|
|
364
|
-
if (
|
|
365
|
-
expression :
|
|
364
|
+
if (l.types.isVariableDeclarator(c) ? x = l.types.isTSAsExpression(c.init) || l.types.isTSSatisfiesExpression(c.init) ? c.init.
|
|
365
|
+
expression : c.init : x = c, l.types.isCallExpression(x) && l.types.isMemberExpression(x.callee) && l.types.isIdentifier(x.callee.
|
|
366
366
|
property) && (x.callee.property.name === "story" || x.callee.property.name === "extend") && (p = !0, x = x.arguments[0]), e._metaIsFactory &&
|
|
367
367
|
!p)
|
|
368
|
-
throw new
|
|
368
|
+
throw new L(
|
|
369
369
|
"expected factory story",
|
|
370
370
|
x,
|
|
371
371
|
e._options.fileName
|
|
372
372
|
);
|
|
373
373
|
if (!e._metaIsFactory && p)
|
|
374
|
-
throw e._metaNode ? new
|
|
374
|
+
throw e._metaNode ? new L(
|
|
375
375
|
"expected non-factory story",
|
|
376
376
|
x,
|
|
377
377
|
e._options.fileName
|
|
378
|
-
) : new
|
|
378
|
+
) : new M(
|
|
379
379
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
380
380
|
x,
|
|
381
381
|
e._options.fileName
|
|
382
382
|
);
|
|
383
383
|
let h = {};
|
|
384
|
-
|
|
385
|
-
if (
|
|
384
|
+
l.types.isObjectExpression(x) ? (h.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
385
|
+
if (l.types.isIdentifier(b.key)) {
|
|
386
386
|
if (b.key.name === "render")
|
|
387
387
|
h.__isArgsStory = ue(
|
|
388
388
|
b.value,
|
|
389
|
-
|
|
389
|
+
a,
|
|
390
390
|
e
|
|
391
391
|
);
|
|
392
|
-
else if (b.key.name === "name" &&
|
|
392
|
+
else if (b.key.name === "name" && l.types.isStringLiteral(b.value))
|
|
393
393
|
g = b.value.value;
|
|
394
|
-
else if (b.key.name === "storyName" &&
|
|
394
|
+
else if (b.key.name === "storyName" && l.types.isStringLiteral(b.value))
|
|
395
395
|
re.logger.warn(
|
|
396
396
|
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
397
397
|
);
|
|
398
|
-
else if (b.key.name === "parameters" &&
|
|
399
|
-
let
|
|
400
|
-
(
|
|
398
|
+
else if (b.key.name === "parameters" && l.types.isObjectExpression(b.value)) {
|
|
399
|
+
let _ = b.value.properties.find(
|
|
400
|
+
(W) => l.types.isObjectProperty(W) && l.types.isIdentifier(W.key) && W.key.name === "__id"
|
|
401
401
|
);
|
|
402
|
-
|
|
402
|
+
_ && (h.__id = _.value.value);
|
|
403
403
|
}
|
|
404
404
|
e._storyAnnotations[d][b.key.name] = b.value;
|
|
405
405
|
}
|
|
406
|
-
})) : h.__isArgsStory = ue(x,
|
|
406
|
+
})) : h.__isArgsStory = ue(x, a, e), e._stories[d] = {
|
|
407
407
|
id: "FIXME",
|
|
408
408
|
name: g,
|
|
409
409
|
parameters: h,
|
|
@@ -412,19 +412,19 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
414
|
}
|
|
415
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
416
|
-
if (
|
|
417
|
-
let { name: p } =
|
|
415
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((c) => {
|
|
416
|
+
if (l.types.isExportSpecifier(c) && l.types.isIdentifier(c.exported)) {
|
|
417
|
+
let { name: p } = c.exported, { name: d } = c.local, g = l.types.isProgram(a) ? P(d, a) : c.local;
|
|
418
418
|
if (p === "default") {
|
|
419
419
|
let x;
|
|
420
|
-
|
|
420
|
+
l.types.isObjectExpression(g) ? x = g : (
|
|
421
421
|
// export default { ... } as Meta<...>
|
|
422
|
-
|
|
423
|
-
), x &&
|
|
422
|
+
l.types.isTSAsExpression(g) && l.types.isObjectExpression(g.expression) && (x = g.expression)
|
|
423
|
+
), x && l.types.isProgram(a) && e._parseMeta(x, a);
|
|
424
424
|
} else {
|
|
425
425
|
let x = {}, h = g;
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
l.types.isObjectExpression(h) && h.properties.forEach((b) => {
|
|
427
|
+
l.types.isIdentifier(b.key) && (x[b.key.name] = b.value);
|
|
428
428
|
}), e._storyAnnotations[p] = x, e._storyStatements[p] = g, e._storyPaths[p] = t, e._stories[p] = {
|
|
429
429
|
id: "FIXME",
|
|
430
430
|
name: p,
|
|
@@ -439,14 +439,14 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
439
439
|
},
|
|
440
440
|
ExpressionStatement: {
|
|
441
441
|
enter({ node: t, parent: i }) {
|
|
442
|
-
let { expression:
|
|
443
|
-
if (
|
|
444
|
-
object) &&
|
|
445
|
-
let
|
|
446
|
-
if (e._storyAnnotations[
|
|
447
|
-
|
|
448
|
-
}) : e._storyAnnotations[
|
|
449
|
-
let d = p.value, g = e._stories[
|
|
442
|
+
let { expression: a } = t;
|
|
443
|
+
if (l.types.isProgram(i) && l.types.isAssignmentExpression(a) && l.types.isMemberExpression(a.left) && l.types.isIdentifier(a.left.
|
|
444
|
+
object) && l.types.isIdentifier(a.left.property)) {
|
|
445
|
+
let o = a.left.object.name, c = a.left.property.name, p = a.right;
|
|
446
|
+
if (e._storyAnnotations[o] && (c === "story" && l.types.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
447
|
+
l.types.isIdentifier(d.key) && (e._storyAnnotations[o][d.key.name] = d.value);
|
|
448
|
+
}) : e._storyAnnotations[o][c] = p), c === "storyName" && l.types.isStringLiteral(p)) {
|
|
449
|
+
let d = p.value, g = e._stories[o];
|
|
450
450
|
if (!g)
|
|
451
451
|
return;
|
|
452
452
|
g.name = d;
|
|
@@ -456,24 +456,24 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
456
456
|
},
|
|
457
457
|
CallExpression: {
|
|
458
458
|
enter(t) {
|
|
459
|
-
let { node: i } = t, { callee:
|
|
460
|
-
if (
|
|
459
|
+
let { node: i } = t, { callee: a } = i;
|
|
460
|
+
if (l.types.isIdentifier(a) && a.name === "storiesOf")
|
|
461
461
|
throw new Error(O.dedent`
|
|
462
462
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
463
463
|
|
|
464
464
|
SB8 does not support \`storiesOf\`.
|
|
465
465
|
`);
|
|
466
|
-
if (
|
|
466
|
+
if (l.types.isMemberExpression(a) && l.types.isIdentifier(a.property) && a.property.name === "meta" && l.types.isIdentifier(a.object) &&
|
|
467
467
|
i.arguments.length > 0) {
|
|
468
|
-
let
|
|
469
|
-
if (
|
|
470
|
-
if (xe(
|
|
468
|
+
let c = t.scope.getBinding(a.object.name)?.path?.parentPath?.node;
|
|
469
|
+
if (l.types.isImportDeclaration(c))
|
|
470
|
+
if (xe(c.source.value)) {
|
|
471
471
|
let p = i.arguments[0];
|
|
472
|
-
e._metaVariableName =
|
|
472
|
+
e._metaVariableName = a.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
473
473
|
} else
|
|
474
|
-
throw new
|
|
474
|
+
throw new M(
|
|
475
475
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
476
|
-
|
|
476
|
+
c,
|
|
477
477
|
e._options.fileName
|
|
478
478
|
);
|
|
479
479
|
}
|
|
@@ -482,36 +482,36 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
482
482
|
ImportDeclaration: {
|
|
483
483
|
enter({ node: t }) {
|
|
484
484
|
let { source: i } = t;
|
|
485
|
-
if (
|
|
485
|
+
if (l.types.isStringLiteral(i))
|
|
486
486
|
e.imports.push(i.value);
|
|
487
487
|
else
|
|
488
488
|
throw new Error("CSF: unexpected import source");
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
}), !e._meta)
|
|
492
|
-
throw new
|
|
492
|
+
throw new R("missing default export", e._ast, e._options.fileName);
|
|
493
493
|
let r = Object.entries(e._stories);
|
|
494
494
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
495
495
|
e._stories = r.reduce(
|
|
496
|
-
(t, [i,
|
|
496
|
+
(t, [i, a]) => {
|
|
497
497
|
if (!(0, v.isExportStory)(i, e._meta))
|
|
498
498
|
return t;
|
|
499
|
-
let
|
|
499
|
+
let o = a.parameters?.__id ?? (0, v.toId)(e._meta?.id || e._meta?.title, (0, v.storyNameFromExport)(i)), c = { ...a.parameters, __id: o },
|
|
500
500
|
{ includeStories: p } = e._meta || {};
|
|
501
|
-
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (
|
|
501
|
+
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (c.docsOnly = !0), t[i] = { ...a, id: o, parameters: c };
|
|
502
502
|
let d = e._storyAnnotations[i], { tags: g, play: x } = d;
|
|
503
503
|
if (g) {
|
|
504
|
-
let
|
|
505
|
-
t[i].tags = me(
|
|
504
|
+
let _ = l.types.isIdentifier(g) ? P(g.name, this._ast.program) : g;
|
|
505
|
+
t[i].tags = me(_);
|
|
506
506
|
}
|
|
507
507
|
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
508
508
|
let h = t[i].__stats;
|
|
509
|
-
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((
|
|
510
|
-
h[
|
|
509
|
+
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((_) => {
|
|
510
|
+
h[_] = !!d[_] || !!e._metaAnnotations[_];
|
|
511
511
|
});
|
|
512
512
|
let b = e.getStoryExport(i);
|
|
513
|
-
return h.storyFn = !!(
|
|
514
|
-
play), h.moduleMock = !!e.imports.find((
|
|
513
|
+
return h.storyFn = !!(l.types.isArrowFunctionExpression(b) || l.types.isFunctionDeclaration(b)), h.mount = rt(d.play ?? e._metaAnnotations.
|
|
514
|
+
play), h.moduleMock = !!e.imports.find((_) => ye(_)), t;
|
|
515
515
|
},
|
|
516
516
|
{}
|
|
517
517
|
), Object.keys(e._storyExports).forEach((t) => {
|
|
@@ -523,7 +523,7 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
523
523
|
if (t.length !== i.length)
|
|
524
524
|
throw new Error(
|
|
525
525
|
`Missing exports after sort: ${t.filter(
|
|
526
|
-
(
|
|
526
|
+
(a) => !i.includes(a)
|
|
527
527
|
)}`
|
|
528
528
|
);
|
|
529
529
|
}
|
|
@@ -562,13 +562,13 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
562
562
|
code: s,
|
|
563
563
|
filename: e = "",
|
|
564
564
|
ast: r
|
|
565
|
-
}) => new
|
|
566
|
-
let r = (0,
|
|
565
|
+
}) => new l.BabelFileClass({ filename: e }, { code: s, ast: r ?? (0, l.babelParse)(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
566
|
+
let r = (0, l.babelParse)(s), t = be({ code: s, filename: e.fileName, ast: r });
|
|
567
567
|
return new K(r, e, t);
|
|
568
568
|
}, "loadCsf"), ie = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
569
|
-
let t = (0,
|
|
569
|
+
let t = (0, l.generate)(s._ast, e, r);
|
|
570
570
|
return e.sourceMaps ? t : t.code;
|
|
571
|
-
}, "formatCsf"), he = /* @__PURE__ */ f((s, e = {}) =>
|
|
571
|
+
}, "formatCsf"), he = /* @__PURE__ */ f((s, e = {}) => l.recast.print(s._ast, e), "printCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
572
572
|
let r = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
573
573
|
return Q(r, { ...e, fileName: s });
|
|
574
574
|
}, "readCsf"), nt = /* @__PURE__ */ f(async (s, e) => {
|
|
@@ -578,20 +578,20 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
578
578
|
}, "writeCsf");
|
|
579
579
|
|
|
580
580
|
// src/csf-tools/ConfigFile.ts
|
|
581
|
-
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), Ee = z(
|
|
581
|
+
var te = require("node:fs/promises"), n = require("storybook/internal/babel"), H = require("storybook/internal/node-logger"), Ee = z($(), 1);
|
|
582
582
|
var se = /* @__PURE__ */ f(({
|
|
583
583
|
expectedType: s,
|
|
584
584
|
foundType: e,
|
|
585
585
|
node: r
|
|
586
586
|
}) => Ee.dedent`
|
|
587
587
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
588
|
-
`, "getCsfParsingErrorMessage"),
|
|
588
|
+
`, "getCsfParsingErrorMessage"), F = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
589
589
|
s.key.value : null, "propKey"), Y = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? Y(s.expression) :
|
|
590
590
|
s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
591
591
|
if (s.length === 0)
|
|
592
592
|
return e;
|
|
593
593
|
if (n.types.isObjectExpression(e)) {
|
|
594
|
-
let [r, ...t] = s, i = e.properties.find((
|
|
594
|
+
let [r, ...t] = s, i = e.properties.find((a) => F(a) === r);
|
|
595
595
|
if (i)
|
|
596
596
|
return _e(t, i.value);
|
|
597
597
|
}
|
|
@@ -602,26 +602,26 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
602
602
|
throw new Error("Expected object expression");
|
|
603
603
|
}
|
|
604
604
|
if (n.types.isObjectExpression(e)) {
|
|
605
|
-
let [r, ...t] = s, i = e.properties.find((
|
|
605
|
+
let [r, ...t] = s, i = e.properties.find((a) => F(a) === r);
|
|
606
606
|
if (i)
|
|
607
607
|
return t.length === 0 ? e.properties : je(t, i.value);
|
|
608
608
|
}
|
|
609
609
|
}, "_getPathProperties"), Z = /* @__PURE__ */ f((s, e) => {
|
|
610
610
|
let r = null, t = null;
|
|
611
611
|
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? t = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
612
|
-
i.declaration) && (t = i.declaration.declarations), t && t.find((
|
|
613
|
-
id.name === s ? (r =
|
|
614
|
-
}, "_findVarDeclarator"),
|
|
612
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((a) => n.types.isVariableDeclarator(a) && n.types.isIdentifier(a.id) && a.
|
|
613
|
+
id.name === s ? (r = a, !0) : !1))), r;
|
|
614
|
+
}, "_findVarDeclarator"), w = /* @__PURE__ */ f((s, e) => Z(s, e)?.init, "_findVarInitialization"), q = /* @__PURE__ */ f((s, e) => {
|
|
615
615
|
if (s.length === 0)
|
|
616
616
|
return e;
|
|
617
|
-
let [r, ...t] = s, i =
|
|
617
|
+
let [r, ...t] = s, i = q(t, e);
|
|
618
618
|
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(r), i)]);
|
|
619
|
-
}, "_makeObjectExpression"),
|
|
620
|
-
let [t, ...i] = s,
|
|
621
|
-
(
|
|
619
|
+
}, "_makeObjectExpression"), U = /* @__PURE__ */ f((s, e, r) => {
|
|
620
|
+
let [t, ...i] = s, a = r.properties.find(
|
|
621
|
+
(o) => F(o) === t
|
|
622
622
|
);
|
|
623
|
-
|
|
624
|
-
n.types.objectProperty(n.types.identifier(t),
|
|
623
|
+
a ? n.types.isObjectExpression(a.value) && i.length > 0 ? U(i, e, a.value) : a.value = q(i, e) : r.properties.push(
|
|
624
|
+
n.types.objectProperty(n.types.identifier(t), q(i, e))
|
|
625
625
|
);
|
|
626
626
|
}, "_updateExportNode"), ee = class {
|
|
627
627
|
constructor(e, r, t) {
|
|
@@ -638,10 +638,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
638
638
|
}
|
|
639
639
|
_parseExportsObject(e) {
|
|
640
640
|
this._exportsObject = e, e.properties.forEach((r) => {
|
|
641
|
-
let t =
|
|
641
|
+
let t = F(r);
|
|
642
642
|
if (t) {
|
|
643
643
|
let i = r.value;
|
|
644
|
-
n.types.isIdentifier(i) && (i =
|
|
644
|
+
n.types.isIdentifier(i) && (i = w(i.name, this._ast.program)), this._exports[t] = i;
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
647
|
}
|
|
@@ -651,7 +651,7 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
651
651
|
ExportDefaultDeclaration: {
|
|
652
652
|
enter({ node: r, parent: t }) {
|
|
653
653
|
e.hasDefaultExport = !0;
|
|
654
|
-
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ?
|
|
654
|
+
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ? w(r.declaration.name, t) : r.declaration;
|
|
655
655
|
i = Y(i), n.types.isCallExpression(i) && n.types.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.types.isObjectExpression(
|
|
656
656
|
i) ? e._parseExportsObject(i) : H.logger.warn(
|
|
657
657
|
se({
|
|
@@ -667,20 +667,20 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
667
667
|
if (n.types.isVariableDeclaration(r.declaration))
|
|
668
668
|
r.declaration.declarations.forEach((i) => {
|
|
669
669
|
if (n.types.isVariableDeclarator(i) && n.types.isIdentifier(i.id)) {
|
|
670
|
-
let { name:
|
|
671
|
-
n.types.isIdentifier(
|
|
670
|
+
let { name: a } = i.id, o = i.init;
|
|
671
|
+
n.types.isIdentifier(o) && (o = w(o.name, t)), e._exports[a] = o, e._exportDecls[a] = i;
|
|
672
672
|
}
|
|
673
673
|
});
|
|
674
674
|
else if (n.types.isFunctionDeclaration(r.declaration)) {
|
|
675
675
|
let i = r.declaration;
|
|
676
676
|
if (n.types.isIdentifier(i.id)) {
|
|
677
|
-
let { name:
|
|
678
|
-
e._exportDecls[
|
|
677
|
+
let { name: a } = i.id;
|
|
678
|
+
e._exportDecls[a] = i;
|
|
679
679
|
}
|
|
680
680
|
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
681
681
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
682
|
-
let { name:
|
|
683
|
-
|
|
682
|
+
let { name: a } = i.local, { name: o } = i.exported, c = Z(a, t);
|
|
683
|
+
c && (e._exports[o] = c.init, e._exportDecls[o] = c);
|
|
684
684
|
}
|
|
685
685
|
}) : H.logger.warn(
|
|
686
686
|
se({
|
|
@@ -694,16 +694,16 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
694
694
|
ExpressionStatement: {
|
|
695
695
|
enter({ node: r, parent: t }) {
|
|
696
696
|
if (n.types.isAssignmentExpression(r.expression) && r.expression.operator === "=") {
|
|
697
|
-
let { left: i, right:
|
|
697
|
+
let { left: i, right: a } = r.expression;
|
|
698
698
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
699
699
|
i.property.name === "exports") {
|
|
700
|
-
let
|
|
701
|
-
n.types.isIdentifier(
|
|
702
|
-
(
|
|
703
|
-
let p =
|
|
700
|
+
let o = a;
|
|
701
|
+
n.types.isIdentifier(a) && (o = w(a.name, t)), o = Y(o), n.types.isObjectExpression(o) ? (e._exportsObject = o, o.properties.forEach(
|
|
702
|
+
(c) => {
|
|
703
|
+
let p = F(c);
|
|
704
704
|
if (p) {
|
|
705
|
-
let d =
|
|
706
|
-
n.types.isIdentifier(d) && (d =
|
|
705
|
+
let d = c.value;
|
|
706
|
+
n.types.isIdentifier(d) && (d = w(
|
|
707
707
|
d.name,
|
|
708
708
|
t
|
|
709
709
|
)), e._exports[p] = d;
|
|
@@ -711,8 +711,8 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
711
711
|
})) : H.logger.warn(
|
|
712
712
|
se({
|
|
713
713
|
expectedType: "ObjectExpression",
|
|
714
|
-
foundType:
|
|
715
|
-
node:
|
|
714
|
+
foundType: o?.type,
|
|
715
|
+
node: o
|
|
716
716
|
})
|
|
717
717
|
);
|
|
718
718
|
}
|
|
@@ -751,31 +751,31 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
751
751
|
}
|
|
752
752
|
}
|
|
753
753
|
setFieldNode(e, r) {
|
|
754
|
-
let [t, ...i] = e,
|
|
754
|
+
let [t, ...i] = e, a = this._exports[t];
|
|
755
755
|
if (this._exportsObject) {
|
|
756
|
-
let p = this._exportsObject.properties.find((d) =>
|
|
756
|
+
let p = this._exportsObject.properties.find((d) => F(d) === t);
|
|
757
757
|
if (p && n.types.isIdentifier(p.value)) {
|
|
758
758
|
let d = Z(p.value.name, this._ast.program);
|
|
759
759
|
if (d && n.types.isObjectExpression(d.init)) {
|
|
760
|
-
|
|
760
|
+
U(i, r, d.init);
|
|
761
761
|
return;
|
|
762
762
|
}
|
|
763
763
|
}
|
|
764
|
-
|
|
764
|
+
U(e, r, this._exportsObject), this._exports[e[0]] = r;
|
|
765
765
|
return;
|
|
766
766
|
}
|
|
767
|
-
if (
|
|
768
|
-
|
|
767
|
+
if (a && n.types.isObjectExpression(a) && i.length > 0) {
|
|
768
|
+
U(i, r, a);
|
|
769
769
|
return;
|
|
770
770
|
}
|
|
771
|
-
let
|
|
772
|
-
if (
|
|
773
|
-
|
|
771
|
+
let o = Z(t, this._ast.program);
|
|
772
|
+
if (o && n.types.isObjectExpression(o.init)) {
|
|
773
|
+
U(i, r, o.init);
|
|
774
774
|
return;
|
|
775
775
|
}
|
|
776
|
-
if (
|
|
777
|
-
let
|
|
778
|
-
n.types.isVariableDeclarator(
|
|
776
|
+
if (a && i.length === 0 && this._exportDecls[e[0]]) {
|
|
777
|
+
let c = this._exportDecls[e[0]];
|
|
778
|
+
n.types.isVariableDeclarator(c) && (c.init = q([], r));
|
|
779
779
|
} else {
|
|
780
780
|
if (this.hasDefaultExport)
|
|
781
781
|
throw new Error(
|
|
@@ -784,10 +784,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
784
784
|
)}" field as the default export is not an object in this file.`
|
|
785
785
|
);
|
|
786
786
|
{
|
|
787
|
-
let
|
|
788
|
-
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(t),
|
|
787
|
+
let c = q(i, r), p = n.types.exportNamedDeclaration(
|
|
788
|
+
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(t), c)])
|
|
789
789
|
);
|
|
790
|
-
this._exports[t] =
|
|
790
|
+
this._exports[t] = c, this._ast.program.body.push(p);
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
}
|
|
@@ -855,31 +855,31 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
855
855
|
return t;
|
|
856
856
|
}
|
|
857
857
|
removeField(e) {
|
|
858
|
-
let r = /* @__PURE__ */ f((i,
|
|
859
|
-
let
|
|
860
|
-
(
|
|
858
|
+
let r = /* @__PURE__ */ f((i, a) => {
|
|
859
|
+
let o = i.findIndex(
|
|
860
|
+
(c) => n.types.isIdentifier(c.key) && c.key.name === a || n.types.isStringLiteral(c.key) && c.key.value === a
|
|
861
861
|
);
|
|
862
|
-
|
|
862
|
+
o >= 0 && i.splice(o, 1);
|
|
863
863
|
}, "removeProperty");
|
|
864
864
|
if (e.length === 1) {
|
|
865
865
|
let i = !1;
|
|
866
|
-
if (this._ast.program.body.forEach((
|
|
867
|
-
if (n.types.isExportNamedDeclaration(
|
|
868
|
-
let
|
|
869
|
-
n.types.isIdentifier(
|
|
866
|
+
if (this._ast.program.body.forEach((a) => {
|
|
867
|
+
if (n.types.isExportNamedDeclaration(a) && n.types.isVariableDeclaration(a.declaration)) {
|
|
868
|
+
let o = a.declaration.declarations[0];
|
|
869
|
+
n.types.isIdentifier(o.id) && o.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(a), 1), i = !0);
|
|
870
870
|
}
|
|
871
|
-
if (n.types.isExportDefaultDeclaration(
|
|
872
|
-
let
|
|
873
|
-
if (n.types.isIdentifier(
|
|
874
|
-
let
|
|
875
|
-
r(
|
|
871
|
+
if (n.types.isExportDefaultDeclaration(a)) {
|
|
872
|
+
let o = a.declaration;
|
|
873
|
+
if (n.types.isIdentifier(o) && (o = w(o.name, this._ast.program)), o = Y(o), n.types.isObjectExpression(o)) {
|
|
874
|
+
let c = o.properties;
|
|
875
|
+
r(c, e[0]), i = !0;
|
|
876
876
|
}
|
|
877
877
|
}
|
|
878
|
-
if (n.types.isExpressionStatement(
|
|
879
|
-
n.types.isIdentifier(
|
|
880
|
-
property) &&
|
|
881
|
-
let
|
|
882
|
-
r(
|
|
878
|
+
if (n.types.isExpressionStatement(a) && n.types.isAssignmentExpression(a.expression) && n.types.isMemberExpression(a.expression.left) &&
|
|
879
|
+
n.types.isIdentifier(a.expression.left.object) && a.expression.left.object.name === "module" && n.types.isIdentifier(a.expression.left.
|
|
880
|
+
property) && a.expression.left.property.name === "exports" && n.types.isObjectExpression(a.expression.right)) {
|
|
881
|
+
let o = a.expression.right.properties;
|
|
882
|
+
r(o, e[0]), i = !0;
|
|
883
883
|
}
|
|
884
884
|
}), i)
|
|
885
885
|
return;
|
|
@@ -911,8 +911,8 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
911
911
|
let t = this.getFieldNode(e);
|
|
912
912
|
if (t)
|
|
913
913
|
if (n.types.isArrayExpression(t)) {
|
|
914
|
-
let i = t.elements.findIndex((
|
|
915
|
-
|
|
914
|
+
let i = t.elements.findIndex((a) => n.types.isStringLiteral(a) ? a.value === r : n.types.isObjectExpression(a) ? this._getPresetValue(
|
|
915
|
+
a, "name") === r : this._getPnpWrappedValue(a) === r);
|
|
916
916
|
if (i >= 0)
|
|
917
917
|
t.elements.splice(i, 1);
|
|
918
918
|
else
|
|
@@ -933,12 +933,12 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
933
933
|
valueToNode(e) {
|
|
934
934
|
let r = this._inferQuotes(), t;
|
|
935
935
|
if (r === "single") {
|
|
936
|
-
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: r } }),
|
|
937
|
-
(0, n.traverse)(
|
|
936
|
+
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: r } }), a = (0, n.babelParse)(`const __x = ${i}`);
|
|
937
|
+
(0, n.traverse)(a, {
|
|
938
938
|
VariableDeclaration: {
|
|
939
|
-
enter({ node:
|
|
940
|
-
|
|
941
|
-
declarations[0].id.name === "__x" && (t =
|
|
939
|
+
enter({ node: o }) {
|
|
940
|
+
o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) && n.types.isIdentifier(o.declarations[0].id) && o.
|
|
941
|
+
declarations[0].id.name === "__x" && (t = o.declarations[0].init);
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
});
|
|
@@ -976,18 +976,18 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
976
976
|
* @param fromImport - The module to import from
|
|
977
977
|
*/
|
|
978
978
|
setRequireImport(e, r) {
|
|
979
|
-
let t = this._ast.program.body.find((
|
|
980
|
-
let
|
|
981
|
-
isCallExpression(
|
|
982
|
-
"require" && n.types.isStringLiteral(
|
|
979
|
+
let t = this._ast.program.body.find((o) => {
|
|
980
|
+
let c = n.types.isVariableDeclaration(o) && o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) && n.types.
|
|
981
|
+
isCallExpression(o.declarations[0].init) && n.types.isIdentifier(o.declarations[0].init.callee) && o.declarations[0].init.callee.name ===
|
|
982
|
+
"require" && n.types.isStringLiteral(o.declarations[0].init.arguments[0]) && (o.declarations[0].init.arguments[0].value === r || o.declarations[0].
|
|
983
983
|
init.arguments[0].value === r.split("node:")[1]);
|
|
984
|
-
return
|
|
985
|
-
}), i = /* @__PURE__ */ f((
|
|
986
|
-
(
|
|
987
|
-
), "hasRequireSpecifier"),
|
|
988
|
-
n.types.isIdentifier(
|
|
984
|
+
return c && (r = o.declarations[0].init.arguments[0].value), c;
|
|
985
|
+
}), i = /* @__PURE__ */ f((o) => n.types.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
|
|
986
|
+
(c) => n.types.isObjectProperty(c) && n.types.isIdentifier(c.key) && c.key.name === o
|
|
987
|
+
), "hasRequireSpecifier"), a = /* @__PURE__ */ f((o, c) => o.declarations.length === 1 && n.types.isVariableDeclarator(o.declarations[0]) &&
|
|
988
|
+
n.types.isIdentifier(o.declarations[0].id) && o.declarations[0].id.name === c, "hasDefaultRequireSpecifier");
|
|
989
989
|
if (typeof e == "string") {
|
|
990
|
-
let
|
|
990
|
+
let o = /* @__PURE__ */ f(() => {
|
|
991
991
|
this._ast.program.body.unshift(
|
|
992
992
|
n.types.variableDeclaration("const", [
|
|
993
993
|
n.types.variableDeclarator(
|
|
@@ -997,17 +997,17 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
997
997
|
])
|
|
998
998
|
);
|
|
999
999
|
}, "addDefaultRequireSpecifier");
|
|
1000
|
-
t &&
|
|
1001
|
-
} else t ? e.forEach((
|
|
1002
|
-
i(
|
|
1003
|
-
n.types.objectProperty(n.types.identifier(
|
|
1000
|
+
t && a(t, e) || o();
|
|
1001
|
+
} else t ? e.forEach((o) => {
|
|
1002
|
+
i(o) || t.declarations[0].id.properties.push(
|
|
1003
|
+
n.types.objectProperty(n.types.identifier(o), n.types.identifier(o), void 0, !0)
|
|
1004
1004
|
);
|
|
1005
1005
|
}) : this._ast.program.body.unshift(
|
|
1006
1006
|
n.types.variableDeclaration("const", [
|
|
1007
1007
|
n.types.variableDeclarator(
|
|
1008
1008
|
n.types.objectPattern(
|
|
1009
1009
|
e.map(
|
|
1010
|
-
(
|
|
1010
|
+
(o) => n.types.objectProperty(n.types.identifier(o), n.types.identifier(o), void 0, !0)
|
|
1011
1011
|
)
|
|
1012
1012
|
),
|
|
1013
1013
|
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(r)])
|
|
@@ -1044,10 +1044,10 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1044
1044
|
let t = this._ast.program.body.find((p) => {
|
|
1045
1045
|
let d = n.types.isImportDeclaration(p) && (p.source.value === r || p.source.value === r.split("node:")[1]);
|
|
1046
1046
|
return d && (r = p.source.value), d;
|
|
1047
|
-
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"),
|
|
1047
|
+
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"), a = /* @__PURE__ */ f(
|
|
1048
1048
|
(p, d) => p.specifiers.find(
|
|
1049
1049
|
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name === d
|
|
1050
|
-
), "hasImportSpecifier"),
|
|
1050
|
+
), "hasImportSpecifier"), o = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1051
1051
|
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1052
1052
|
), "hasNamespaceImportSpecifier");
|
|
1053
1053
|
e === null ? t || this._ast.program.body.unshift(n.types.importDeclaration([], n.types.stringLiteral(r))) : typeof e == "string" ? t ? (/* @__PURE__ */ f(
|
|
@@ -1061,13 +1061,13 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1061
1061
|
n.types.stringLiteral(r)
|
|
1062
1062
|
)
|
|
1063
1063
|
) : Array.isArray(e) ? t ? e.forEach((p) => {
|
|
1064
|
-
|
|
1064
|
+
a(t, p) || t.specifiers.push(i(p));
|
|
1065
1065
|
}) : this._ast.program.body.unshift(
|
|
1066
1066
|
n.types.importDeclaration(
|
|
1067
1067
|
e.map(i),
|
|
1068
1068
|
n.types.stringLiteral(r)
|
|
1069
1069
|
)
|
|
1070
|
-
) : e.namespace && (t ?
|
|
1070
|
+
) : e.namespace && (t ? o(t, e.namespace) || t.specifiers.push(
|
|
1071
1071
|
n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))
|
|
1072
1072
|
) : this._ast.program.body.unshift(
|
|
1073
1073
|
n.types.importDeclaration(
|
|
@@ -1093,14 +1093,14 @@ s, "unwrap"), _e = /* @__PURE__ */ f((s, e) => {
|
|
|
1093
1093
|
view")), "isCsfFactoryPreview");
|
|
1094
1094
|
|
|
1095
1095
|
// src/csf-tools/getStorySortParameter.ts
|
|
1096
|
-
var y = require("storybook/internal/babel"), De = require("storybook/internal/node-logger"), Ie = z(
|
|
1096
|
+
var y = require("storybook/internal/babel"), De = require("storybook/internal/node-logger"), Ie = z($(), 1);
|
|
1097
1097
|
var ne = /* @__PURE__ */ f((s, e) => {
|
|
1098
1098
|
let r;
|
|
1099
1099
|
return s.properties.forEach((t) => {
|
|
1100
1100
|
y.types.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1101
1101
|
}), r;
|
|
1102
1102
|
}, "getValue"), oe = /* @__PURE__ */ f((s) => {
|
|
1103
|
-
let e =
|
|
1103
|
+
let e = B(s);
|
|
1104
1104
|
if (y.types.isArrayExpression(e))
|
|
1105
1105
|
return e.elements.map((r) => oe(r));
|
|
1106
1106
|
if (y.types.isObjectExpression(e))
|
|
@@ -1108,9 +1108,9 @@ var ne = /* @__PURE__ */ f((s, e) => {
|
|
|
1108
1108
|
if (y.types.isLiteral(e))
|
|
1109
1109
|
return e.value;
|
|
1110
1110
|
if (y.types.isIdentifier(e))
|
|
1111
|
-
return
|
|
1111
|
+
return C(e.name, !0);
|
|
1112
1112
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1113
|
-
}, "parseValue"),
|
|
1113
|
+
}, "parseValue"), C = /* @__PURE__ */ f((s, e) => {
|
|
1114
1114
|
let r = Ie.dedent`
|
|
1115
1115
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1116
1116
|
|
|
@@ -1125,25 +1125,25 @@ var ne = /* @__PURE__ */ f((s, e) => {
|
|
|
1125
1125
|
if (e)
|
|
1126
1126
|
throw new Error(r);
|
|
1127
1127
|
De.logger.log(r);
|
|
1128
|
-
}, "unsupported"),
|
|
1128
|
+
}, "unsupported"), B = /* @__PURE__ */ f((s) => y.types.isTSAsExpression(s) || y.types.isTSSatisfiesExpression(s) ? s.expression : s, "strip\
|
|
1129
1129
|
TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
1130
|
-
let e =
|
|
1130
|
+
let e = B(s);
|
|
1131
1131
|
if (y.types.isObjectExpression(e)) {
|
|
1132
1132
|
let r = ne(e, "options");
|
|
1133
1133
|
if (r) {
|
|
1134
1134
|
if (y.types.isObjectExpression(r))
|
|
1135
1135
|
return ne(r, "storySort");
|
|
1136
|
-
|
|
1136
|
+
C("options", !0);
|
|
1137
1137
|
}
|
|
1138
1138
|
}
|
|
1139
1139
|
}, "parseParameters"), ve = /* @__PURE__ */ f((s, e) => {
|
|
1140
|
-
let r =
|
|
1140
|
+
let r = B(s);
|
|
1141
1141
|
if (y.types.isObjectExpression(r)) {
|
|
1142
1142
|
let t = ne(r, "parameters");
|
|
1143
1143
|
if (y.types.isIdentifier(t) && (t = P(t.name, e)), t)
|
|
1144
1144
|
return Ne(t);
|
|
1145
1145
|
} else
|
|
1146
|
-
|
|
1146
|
+
C("default", !0);
|
|
1147
1147
|
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
1148
1148
|
if (!s.includes("storySort"))
|
|
1149
1149
|
return;
|
|
@@ -1153,22 +1153,22 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1153
1153
|
enter({ node: t }) {
|
|
1154
1154
|
y.types.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((i) => {
|
|
1155
1155
|
if (y.types.isVariableDeclarator(i) && y.types.isIdentifier(i.id)) {
|
|
1156
|
-
let { name:
|
|
1157
|
-
if (
|
|
1158
|
-
let
|
|
1159
|
-
e = Ne(
|
|
1156
|
+
let { name: a } = i.id;
|
|
1157
|
+
if (a === "parameters" && i.init) {
|
|
1158
|
+
let o = B(i.init);
|
|
1159
|
+
e = Ne(o);
|
|
1160
1160
|
}
|
|
1161
1161
|
}
|
|
1162
1162
|
}) : t.specifiers.forEach((i) => {
|
|
1163
|
-
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" &&
|
|
1163
|
+
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" && C("parameters", !1);
|
|
1164
1164
|
});
|
|
1165
1165
|
}
|
|
1166
1166
|
},
|
|
1167
1167
|
ExportDefaultDeclaration: {
|
|
1168
1168
|
enter({ node: t }) {
|
|
1169
1169
|
let i = t.declaration;
|
|
1170
|
-
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i =
|
|
1171
|
-
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) :
|
|
1170
|
+
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i = B(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1171
|
+
e = ve(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = ve(i, r.program) : C("default", !1);
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
1174
|
}), !!e) {
|
|
@@ -1177,21 +1177,21 @@ TSModifiers"), Ne = /* @__PURE__ */ f((s) => {
|
|
|
1177
1177
|
return (0, eval)(t);
|
|
1178
1178
|
}
|
|
1179
1179
|
if (y.types.isFunctionExpression(e)) {
|
|
1180
|
-
let { code: t } = (0, y.generate)(e, {}), i = e.id?.name,
|
|
1180
|
+
let { code: t } = (0, y.generate)(e, {}), i = e.id?.name, a = `(a, b) => {
|
|
1181
1181
|
${t};
|
|
1182
1182
|
return ${i}(a, b)
|
|
1183
1183
|
}`;
|
|
1184
|
-
return (0, eval)(
|
|
1184
|
+
return (0, eval)(a);
|
|
1185
1185
|
}
|
|
1186
|
-
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? oe(e) :
|
|
1186
|
+
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? oe(e) : C("storySort", !0);
|
|
1187
1187
|
}
|
|
1188
1188
|
}, "getStorySortParameter");
|
|
1189
1189
|
|
|
1190
1190
|
// src/csf-tools/enrichCsf.ts
|
|
1191
1191
|
var u = require("storybook/internal/babel");
|
|
1192
1192
|
var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1193
|
-
let i = e.getStoryExport(r),
|
|
1194
|
-
i.callee.object.name === "meta",
|
|
1193
|
+
let i = e.getStoryExport(r), a = u.types.isCallExpression(i) && u.types.isMemberExpression(i.callee) && u.types.isIdentifier(i.callee.object) &&
|
|
1194
|
+
i.callee.object.name === "meta", o = !t?.disableSource && Te(i), c = !t?.disableDescription && ae(e._storyStatements[r]), p = [], d = a ? u.types.
|
|
1195
1195
|
memberExpression(u.types.identifier(r), u.types.identifier("input")) : u.types.identifier(r), g = u.types.memberExpression(d, u.types.identifier(
|
|
1196
1196
|
"parameters"));
|
|
1197
1197
|
p.push(u.types.spreadElement(g));
|
|
@@ -1201,7 +1201,7 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1201
1201
|
!1,
|
|
1202
1202
|
!0
|
|
1203
1203
|
), h = [];
|
|
1204
|
-
if (
|
|
1204
|
+
if (o) {
|
|
1205
1205
|
let b = u.types.optionalMemberExpression(
|
|
1206
1206
|
x,
|
|
1207
1207
|
u.types.identifier("source"),
|
|
@@ -1212,13 +1212,13 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1212
1212
|
u.types.objectProperty(
|
|
1213
1213
|
u.types.identifier("source"),
|
|
1214
1214
|
u.types.objectExpression([
|
|
1215
|
-
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(
|
|
1215
|
+
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(o)),
|
|
1216
1216
|
u.types.spreadElement(b)
|
|
1217
1217
|
])
|
|
1218
1218
|
)
|
|
1219
1219
|
);
|
|
1220
1220
|
}
|
|
1221
|
-
if (
|
|
1221
|
+
if (c) {
|
|
1222
1222
|
let b = u.types.optionalMemberExpression(
|
|
1223
1223
|
x,
|
|
1224
1224
|
u.types.identifier("description"),
|
|
@@ -1229,7 +1229,7 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1229
1229
|
u.types.objectProperty(
|
|
1230
1230
|
u.types.identifier("description"),
|
|
1231
1231
|
u.types.objectExpression([
|
|
1232
|
-
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(
|
|
1232
|
+
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(c)),
|
|
1233
1233
|
u.types.spreadElement(b)
|
|
1234
1234
|
])
|
|
1235
1235
|
)
|
|
@@ -1254,10 +1254,10 @@ var we = /* @__PURE__ */ f((s, e, r, t) => {
|
|
|
1254
1254
|
) || s.properties.unshift(r);
|
|
1255
1255
|
return;
|
|
1256
1256
|
}
|
|
1257
|
-
let [t, ...i] = e,
|
|
1258
|
-
(
|
|
1259
|
-
),
|
|
1260
|
-
|
|
1257
|
+
let [t, ...i] = e, a = s.properties.find(
|
|
1258
|
+
(c) => u.types.isObjectProperty(c) && u.types.isIdentifier(c.key) && c.key.name === t && u.types.isObjectExpression(c.value)
|
|
1259
|
+
), o;
|
|
1260
|
+
a ? o = a.value : (o = u.types.objectExpression([]), s.properties.push(u.types.objectProperty(u.types.identifier(t), o))), Fe(o, i, r);
|
|
1261
1261
|
}, "addComponentDescription"), Ce = /* @__PURE__ */ f((s, e, r) => {
|
|
1262
1262
|
let t = !r?.disableDescription && ae(e._metaStatement);
|
|
1263
1263
|
if (t) {
|
|
@@ -1286,7 +1286,7 @@ var $e = require("storybook/internal/babel");
|
|
|
1286
1286
|
|
|
1287
1287
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1288
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(
|
|
1289
|
+
ce = z($(), 1);
|
|
1290
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
1291
|
"isValidTest");
|
|
1292
1292
|
async function Ae({
|
|
@@ -1295,19 +1295,17 @@ async function Ae({
|
|
|
1295
1295
|
configDir: r,
|
|
1296
1296
|
stories: t,
|
|
1297
1297
|
tagsFilter: i,
|
|
1298
|
-
previewLevelTags:
|
|
1298
|
+
previewLevelTags: a = []
|
|
1299
1299
|
}) {
|
|
1300
|
-
|
|
1301
|
-
return s;
|
|
1302
|
-
let l = Q(s, {
|
|
1300
|
+
let o = Q(s, {
|
|
1303
1301
|
fileName: e,
|
|
1304
1302
|
transformInlineMeta: !0,
|
|
1305
|
-
makeTitle: /* @__PURE__ */ f((
|
|
1303
|
+
makeTitle: /* @__PURE__ */ f((E) => {
|
|
1306
1304
|
let S = (0, ke.getStoryTitle)({
|
|
1307
1305
|
storyFilePath: e,
|
|
1308
1306
|
configDir: r,
|
|
1309
1307
|
stories: t,
|
|
1310
|
-
userTitle:
|
|
1308
|
+
userTitle: E
|
|
1311
1309
|
}) || "unknown";
|
|
1312
1310
|
return S === "unknown" && le.logger.warn(
|
|
1313
1311
|
ce.dedent`
|
|
@@ -1316,10 +1314,10 @@ async function Ae({
|
|
|
1316
1314
|
`
|
|
1317
1315
|
), S;
|
|
1318
1316
|
}, "makeTitle")
|
|
1319
|
-
}).parse(),
|
|
1320
|
-
(
|
|
1321
|
-
),
|
|
1322
|
-
if (
|
|
1317
|
+
}).parse(), c = o._ast, p = o._metaVariableName, d = o._metaNode, g = d.properties.find(
|
|
1318
|
+
(E) => m.types.isObjectProperty(E) && m.types.isIdentifier(E.key) && E.key.name === "title"
|
|
1319
|
+
), x = m.types.stringLiteral(o._meta?.title || "unknown");
|
|
1320
|
+
if (g ? m.types.isObjectProperty(g) && (g.value = x) : d.properties.push(m.types.objectProperty(m.types.identifier("title"), x)), !d || !o.
|
|
1323
1321
|
_meta)
|
|
1324
1322
|
throw new Error(
|
|
1325
1323
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1327,49 +1325,49 @@ async function Ae({
|
|
|
1327
1325
|
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\
|
|
1328
1326
|
le an issue with details about your use case.`
|
|
1329
1327
|
);
|
|
1330
|
-
let
|
|
1331
|
-
Object.keys(
|
|
1328
|
+
let h = {};
|
|
1329
|
+
Object.keys(o._stories).map((E) => {
|
|
1332
1330
|
let S = (0, Ve.combineTags)(
|
|
1333
1331
|
"test",
|
|
1334
1332
|
"dev",
|
|
1335
|
-
...
|
|
1336
|
-
...
|
|
1337
|
-
...
|
|
1333
|
+
...a,
|
|
1334
|
+
...o.meta?.tags || [],
|
|
1335
|
+
...o._stories[E].tags || []
|
|
1338
1336
|
);
|
|
1339
|
-
ft(S, i) && (
|
|
1337
|
+
ft(S, i) && (h[E] = o._storyStatements[E]);
|
|
1340
1338
|
});
|
|
1341
|
-
let
|
|
1342
|
-
if (Object.keys(
|
|
1343
|
-
let
|
|
1344
|
-
m.types.callExpression(m.types.memberExpression(
|
|
1339
|
+
let b = o._file.path.scope.generateUidIdentifier("test"), _ = o._file.path.scope.generateUidIdentifier("describe");
|
|
1340
|
+
if (Object.keys(h).length === 0) {
|
|
1341
|
+
let E = m.types.expressionStatement(
|
|
1342
|
+
m.types.callExpression(m.types.memberExpression(_, m.types.identifier("skip")), [
|
|
1345
1343
|
m.types.stringLiteral("No valid tests found")
|
|
1346
1344
|
])
|
|
1347
1345
|
);
|
|
1348
|
-
|
|
1346
|
+
c.program.body.push(E);
|
|
1349
1347
|
let S = [
|
|
1350
1348
|
m.types.importDeclaration(
|
|
1351
1349
|
[
|
|
1352
|
-
m.types.importSpecifier(
|
|
1353
|
-
m.types.importSpecifier(
|
|
1350
|
+
m.types.importSpecifier(b, m.types.identifier("test")),
|
|
1351
|
+
m.types.importSpecifier(_, m.types.identifier("describe"))
|
|
1354
1352
|
],
|
|
1355
1353
|
m.types.stringLiteral("vitest")
|
|
1356
1354
|
)
|
|
1357
1355
|
];
|
|
1358
|
-
|
|
1356
|
+
c.program.body.unshift(...S);
|
|
1359
1357
|
} else {
|
|
1360
1358
|
let pe = function() {
|
|
1361
|
-
let j =
|
|
1362
|
-
m.types.callExpression(m.types.memberExpression(
|
|
1359
|
+
let j = o._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), I = m.types.memberExpression(
|
|
1360
|
+
m.types.callExpression(m.types.memberExpression(E, m.types.identifier("getState")), []),
|
|
1363
1361
|
m.types.identifier("testPath")
|
|
1364
|
-
),
|
|
1362
|
+
), T = m.types.memberExpression(
|
|
1365
1363
|
m.types.memberExpression(m.types.identifier("globalThis"), m.types.identifier("__vitest_worker__")),
|
|
1366
1364
|
m.types.identifier("filepath")
|
|
1367
|
-
),
|
|
1365
|
+
), k = m.types.logicalExpression(
|
|
1368
1366
|
"??",
|
|
1369
1367
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1370
1368
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1371
|
-
|
|
1372
|
-
|
|
1369
|
+
T,
|
|
1370
|
+
I
|
|
1373
1371
|
), G = m.types.callExpression(
|
|
1374
1372
|
m.types.memberExpression(
|
|
1375
1373
|
m.types.callExpression(m.types.identifier("convertToFilePath"), [
|
|
@@ -1380,37 +1378,37 @@ le an issue with details about your use case.`
|
|
|
1380
1378
|
]),
|
|
1381
1379
|
m.types.identifier("includes")
|
|
1382
1380
|
),
|
|
1383
|
-
[
|
|
1381
|
+
[k]
|
|
1384
1382
|
);
|
|
1385
1383
|
return { isRunningFromThisFileDeclaration: m.types.variableDeclaration("const", [
|
|
1386
1384
|
m.types.variableDeclarator(j, G)
|
|
1387
1385
|
]), isRunningFromThisFileId: j };
|
|
1388
1386
|
};
|
|
1389
|
-
var
|
|
1387
|
+
var W = pe;
|
|
1390
1388
|
f(pe, "getTestGuardDeclaration");
|
|
1391
|
-
let
|
|
1389
|
+
let E = o._file.path.scope.generateUidIdentifier("expect"), S = o._file.path.scope.generateUidIdentifier("testStory"), Re = m.types.identifier(
|
|
1392
1390
|
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Le, isRunningFromThisFileId: Me } = pe();
|
|
1393
|
-
|
|
1391
|
+
c.program.body.push(Le);
|
|
1394
1392
|
let Ue = /* @__PURE__ */ f(({
|
|
1395
1393
|
localName: j,
|
|
1396
|
-
exportName:
|
|
1397
|
-
testTitle:
|
|
1398
|
-
node:
|
|
1394
|
+
exportName: I,
|
|
1395
|
+
testTitle: T,
|
|
1396
|
+
node: k
|
|
1399
1397
|
}) => {
|
|
1400
1398
|
let G = m.types.expressionStatement(
|
|
1401
|
-
m.types.callExpression(
|
|
1402
|
-
m.types.stringLiteral(
|
|
1399
|
+
m.types.callExpression(b, [
|
|
1400
|
+
m.types.stringLiteral(T),
|
|
1403
1401
|
m.types.callExpression(S, [
|
|
1404
|
-
m.types.stringLiteral(
|
|
1402
|
+
m.types.stringLiteral(I),
|
|
1405
1403
|
m.types.identifier(j),
|
|
1406
|
-
m.types.identifier(
|
|
1404
|
+
m.types.identifier(p),
|
|
1407
1405
|
Re
|
|
1408
1406
|
])
|
|
1409
1407
|
])
|
|
1410
1408
|
);
|
|
1411
|
-
return G.loc =
|
|
1412
|
-
}, "getTestStatementForStory"), qe = Object.entries(
|
|
1413
|
-
if (
|
|
1409
|
+
return G.loc = k.loc, G;
|
|
1410
|
+
}, "getTestStatementForStory"), qe = Object.entries(h).map(([j, I]) => {
|
|
1411
|
+
if (I === null) {
|
|
1414
1412
|
le.logger.warn(
|
|
1415
1413
|
ce.dedent`
|
|
1416
1414
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
@@ -1419,15 +1417,15 @@ le an issue with details about your use case.`
|
|
|
1419
1417
|
);
|
|
1420
1418
|
return;
|
|
1421
1419
|
}
|
|
1422
|
-
let
|
|
1423
|
-
return Ue({ testTitle:
|
|
1420
|
+
let T = o._stories[j].localName ?? j, k = o._stories[j].name ?? j;
|
|
1421
|
+
return Ue({ testTitle: k, localName: T, exportName: j, node: I });
|
|
1424
1422
|
}).filter((j) => !!j), Be = m.types.ifStatement(Me, m.types.blockStatement(qe));
|
|
1425
|
-
|
|
1423
|
+
c.program.body.push(Be);
|
|
1426
1424
|
let We = [
|
|
1427
1425
|
m.types.importDeclaration(
|
|
1428
1426
|
[
|
|
1429
|
-
m.types.importSpecifier(
|
|
1430
|
-
m.types.importSpecifier(
|
|
1427
|
+
m.types.importSpecifier(b, m.types.identifier("test")),
|
|
1428
|
+
m.types.importSpecifier(E, m.types.identifier("expect"))
|
|
1431
1429
|
],
|
|
1432
1430
|
m.types.stringLiteral("vitest")
|
|
1433
1431
|
),
|
|
@@ -1439,8 +1437,8 @@ le an issue with details about your use case.`
|
|
|
1439
1437
|
m.types.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1440
1438
|
)
|
|
1441
1439
|
];
|
|
1442
|
-
|
|
1440
|
+
c.program.body.unshift(...We);
|
|
1443
1441
|
}
|
|
1444
|
-
return ie(
|
|
1442
|
+
return ie(o, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1445
1443
|
}
|
|
1446
1444
|
f(Ae, "vitestTransform");
|