storybook 9.0.0-alpha.15 → 9.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/index.cjs +43 -43
- package/dist/bin/index.js +43 -43
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +43 -43
- package/dist/common/index.js +43 -43
- package/dist/core-server/presets/common-manager.js +276 -270
- package/dist/core-server/presets/common-preset.cjs +930 -913
- package/dist/core-server/presets/common-preset.js +1026 -1009
- package/dist/csf-tools/index.cjs +404 -387
- package/dist/csf-tools/index.js +404 -387
- package/dist/manager/globals-runtime.js +1 -1
- package/dist/manager/runtime.js +102 -100
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.js +1 -1
- package/package.json +1 -1
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var We = Object.create;
|
|
3
|
-
var
|
|
3
|
+
var A = Object.defineProperty;
|
|
4
4
|
var Ge = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var ze = Object.getOwnPropertyNames;
|
|
6
6
|
var Xe = Object.getPrototypeOf, Ke = Object.prototype.hasOwnProperty;
|
|
7
|
-
var
|
|
7
|
+
var f = (s, e) => A(s, "name", { value: e, configurable: !0 });
|
|
8
8
|
var Je = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports), Qe = (s, e) => {
|
|
9
9
|
for (var t in e)
|
|
10
|
-
|
|
11
|
-
},
|
|
10
|
+
A(s, t, { get: e[t], enumerable: !0 });
|
|
11
|
+
}, ce = (s, e, t, r) => {
|
|
12
12
|
if (e && typeof e == "object" || typeof e == "function")
|
|
13
13
|
for (let i of ze(e))
|
|
14
|
-
!Ke.call(s, i) && i !== t &&
|
|
14
|
+
!Ke.call(s, i) && i !== t && A(s, i, { get: () => e[i], enumerable: !(r = Ge(e, i)) || r.enumerable });
|
|
15
15
|
return s;
|
|
16
16
|
};
|
|
17
|
-
var
|
|
17
|
+
var z = (s, e, t) => (t = s != null ? We(Xe(s)) : {}, ce(
|
|
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
|
-
e || !s || !s.__esModule ?
|
|
22
|
+
e || !s || !s.__esModule ? A(t, "default", { value: s, enumerable: !0 }) : t,
|
|
23
23
|
s
|
|
24
|
-
)), He = (s) =>
|
|
24
|
+
)), He = (s) => ce(A({}, "__esModule", { value: !0 }), s);
|
|
25
25
|
|
|
26
26
|
// ../node_modules/ts-dedent/dist/index.js
|
|
27
|
-
var
|
|
27
|
+
var R = Je(($) => {
|
|
28
28
|
"use strict";
|
|
29
|
-
Object.defineProperty(
|
|
30
|
-
|
|
31
|
-
function
|
|
29
|
+
Object.defineProperty($, "__esModule", { value: !0 });
|
|
30
|
+
$.dedent = void 0;
|
|
31
|
+
function pe(s) {
|
|
32
32
|
for (var e = [], t = 1; t < arguments.length; t++)
|
|
33
33
|
e[t - 1] = arguments[t];
|
|
34
34
|
var r = Array.from(typeof s == "string" ? [s] : s);
|
|
35
35
|
r[r.length - 1] = r[r.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
36
|
-
var i = r.reduce(function(
|
|
37
|
-
var
|
|
38
|
-
return
|
|
36
|
+
var i = r.reduce(function(a, p) {
|
|
37
|
+
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
38
|
+
return d ? a.concat(d.map(function(g) {
|
|
39
39
|
var x, E;
|
|
40
40
|
return (E = (x = g.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && E !== void 0 ? E : 0;
|
|
41
|
-
})) :
|
|
41
|
+
})) : a;
|
|
42
42
|
}, []);
|
|
43
43
|
if (i.length) {
|
|
44
44
|
var o = new RegExp(`
|
|
45
45
|
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
46
|
-
r = r.map(function(
|
|
47
|
-
return
|
|
46
|
+
r = r.map(function(a) {
|
|
47
|
+
return a.replace(o, `
|
|
48
48
|
`);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
r[0] = r[0].replace(/^\r?\n/, "");
|
|
52
|
-
var
|
|
53
|
-
return e.forEach(function(
|
|
54
|
-
var
|
|
55
|
-
typeof
|
|
56
|
-
`) && (x = String(
|
|
52
|
+
var l = r[0];
|
|
53
|
+
return e.forEach(function(a, p) {
|
|
54
|
+
var d = l.match(/(?:^|\n)( *)$/), g = d ? d[1] : "", x = a;
|
|
55
|
+
typeof a == "string" && a.includes(`
|
|
56
|
+
`) && (x = String(a).split(`
|
|
57
57
|
`).map(function(E, b) {
|
|
58
58
|
return b === 0 ? E : "" + g + E;
|
|
59
59
|
}).join(`
|
|
60
|
-
`)),
|
|
61
|
-
}),
|
|
60
|
+
`)), l += x + r[p + 1];
|
|
61
|
+
}), l;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
f(pe, "dedent");
|
|
64
|
+
$.dedent = pe;
|
|
65
|
+
$.default = pe;
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// src/csf-tools/index.ts
|
|
69
69
|
var dt = {};
|
|
70
70
|
Qe(dt, {
|
|
71
|
-
BadMetaError: () =>
|
|
72
|
-
ConfigFile: () =>
|
|
73
|
-
CsfFile: () =>
|
|
74
|
-
MixedFactoryError: () =>
|
|
75
|
-
MultipleMetaError: () =>
|
|
76
|
-
NoMetaError: () =>
|
|
71
|
+
BadMetaError: () => U,
|
|
72
|
+
ConfigFile: () => Z,
|
|
73
|
+
CsfFile: () => K,
|
|
74
|
+
MixedFactoryError: () => M,
|
|
75
|
+
MultipleMetaError: () => X,
|
|
76
|
+
NoMetaError: () => L,
|
|
77
77
|
babelParse: () => Ae.babelParse,
|
|
78
|
-
babelParseFile: () =>
|
|
78
|
+
babelParseFile: () => ye,
|
|
79
79
|
enrichCsf: () => pt,
|
|
80
80
|
enrichCsfMeta: () => we,
|
|
81
81
|
enrichCsfStory: () => Ne,
|
|
82
|
-
extractDescription: () =>
|
|
82
|
+
extractDescription: () => oe,
|
|
83
83
|
extractSource: () => Fe,
|
|
84
84
|
formatConfig: () => Se,
|
|
85
|
-
formatCsf: () =>
|
|
85
|
+
formatCsf: () => te,
|
|
86
86
|
getStorySortParameter: () => ct,
|
|
87
87
|
isCsfFactoryPreview: () => at,
|
|
88
|
-
isModuleMock: () =>
|
|
89
|
-
isValidPreviewPath: () =>
|
|
88
|
+
isModuleMock: () => xe,
|
|
89
|
+
isValidPreviewPath: () => ge,
|
|
90
90
|
loadConfig: () => je,
|
|
91
|
-
loadCsf: () =>
|
|
92
|
-
printConfig: () =>
|
|
93
|
-
printCsf: () =>
|
|
91
|
+
loadCsf: () => Q,
|
|
92
|
+
printConfig: () => Oe,
|
|
93
|
+
printCsf: () => be,
|
|
94
94
|
readConfig: () => nt,
|
|
95
95
|
readCsf: () => it,
|
|
96
96
|
vitestTransform: () => Ve,
|
|
@@ -100,11 +100,11 @@ Qe(dt, {
|
|
|
100
100
|
module.exports = He(dt);
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
|
-
var
|
|
103
|
+
var J = require("node:fs/promises"), c = require("storybook/internal/babel"), I = require("storybook/internal/csf"), P = z(R(), 1);
|
|
104
104
|
|
|
105
105
|
// src/csf-tools/findVarInitialization.ts
|
|
106
106
|
var w = require("storybook/internal/babel");
|
|
107
|
-
var
|
|
107
|
+
var O = /* @__PURE__ */ f((s, e) => {
|
|
108
108
|
let t = null, r = null;
|
|
109
109
|
return e.body.find((i) => (w.types.isVariableDeclaration(i) ? r = i.declarations : w.types.isExportNamedDeclaration(i) && w.types.isVariableDeclaration(
|
|
110
110
|
i.declaration) && (r = i.declaration.declarations), r && r.find((o) => w.types.isVariableDeclarator(o) && w.types.isIdentifier(o.id) && o.
|
|
@@ -112,7 +112,7 @@ var P = /* @__PURE__ */ p((s, e) => {
|
|
|
112
112
|
}, "findVarInitialization");
|
|
113
113
|
|
|
114
114
|
// src/csf-tools/CsfFile.ts
|
|
115
|
-
var
|
|
115
|
+
var fe = console, Ye = /\/preview(.(js|jsx|mjs|ts|tsx))?$/, ge = /* @__PURE__ */ f((s) => Ye.test(s), "isValidPreviewPath");
|
|
116
116
|
function Ze(s) {
|
|
117
117
|
if (c.types.isArrayExpression(s))
|
|
118
118
|
return s.elements.map((e) => {
|
|
@@ -126,8 +126,8 @@ function Ze(s) {
|
|
|
126
126
|
return new RegExp(s.pattern, s.flags);
|
|
127
127
|
throw new Error(`Unknown include/exclude: ${s}`);
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
function
|
|
129
|
+
f(Ze, "parseIncludeExclude");
|
|
130
|
+
function de(s) {
|
|
131
131
|
if (!c.types.isArrayExpression(s))
|
|
132
132
|
throw new Error("CSF: Expected tags array");
|
|
133
133
|
return s.elements.map((e) => {
|
|
@@ -136,26 +136,26 @@ function fe(s) {
|
|
|
136
136
|
throw new Error("CSF: Expected tag to be string literal");
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
var D = /* @__PURE__ */
|
|
139
|
+
f(de, "parseTags");
|
|
140
|
+
var D = /* @__PURE__ */ f((s, e) => {
|
|
141
141
|
let t = "";
|
|
142
142
|
if (s.loc) {
|
|
143
143
|
let { line: r, column: i } = s.loc?.start || {};
|
|
144
144
|
t = `(line ${r}, col ${i})`;
|
|
145
145
|
}
|
|
146
146
|
return `${e || ""} ${t}`.trim();
|
|
147
|
-
}, "formatLocation"),
|
|
147
|
+
}, "formatLocation"), xe = /* @__PURE__ */ f((s) => rt.test(s), "isModuleMock"), me = /* @__PURE__ */ f((s, e, t) => {
|
|
148
148
|
let r = s;
|
|
149
149
|
if (c.types.isCallExpression(s)) {
|
|
150
150
|
let { callee: i, arguments: o } = s;
|
|
151
151
|
if (c.types.isProgram(e) && c.types.isMemberExpression(i) && c.types.isIdentifier(i.object) && c.types.isIdentifier(i.property) && i.property.
|
|
152
152
|
name === "bind" && (o.length === 0 || o.length === 1 && c.types.isObjectExpression(o[0]) && o[0].properties.length === 0)) {
|
|
153
|
-
let
|
|
154
|
-
|
|
153
|
+
let l = i.object.name, a = O(l, e);
|
|
154
|
+
a && (t._templates[l] = a, r = a);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
return c.types.isArrowFunctionExpression(r) || c.types.isFunctionDeclaration(r) ? r.params.length > 0 : !1;
|
|
158
|
-
}, "isArgsStory"), et = /* @__PURE__ */
|
|
158
|
+
}, "isArgsStory"), et = /* @__PURE__ */ f((s) => {
|
|
159
159
|
if (c.types.isArrayExpression(s))
|
|
160
160
|
return s.elements.map((e) => {
|
|
161
161
|
if (c.types.isStringLiteral(e))
|
|
@@ -163,13 +163,13 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
163
163
|
throw new Error(`Expected string literal named export: ${e}`);
|
|
164
164
|
});
|
|
165
165
|
throw new Error(`Expected array of string literals: ${s}`);
|
|
166
|
-
}, "parseExportsOrder"),
|
|
166
|
+
}, "parseExportsOrder"), ue = /* @__PURE__ */ f((s, e) => e.reduce(
|
|
167
167
|
(t, r) => {
|
|
168
168
|
let i = s[r];
|
|
169
169
|
return i && (t[r] = i), t;
|
|
170
170
|
},
|
|
171
171
|
{}
|
|
172
|
-
), "sortExports"), tt = /* @__PURE__ */
|
|
172
|
+
), "sortExports"), tt = /* @__PURE__ */ f((s) => {
|
|
173
173
|
if (c.types.isArrowFunctionExpression(s) || c.types.isFunctionDeclaration(s)) {
|
|
174
174
|
let e = s.params;
|
|
175
175
|
if (e.length >= 1) {
|
|
@@ -182,55 +182,55 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
return !1;
|
|
185
|
-
}, "hasMount"), rt = /^[.\/#].*\.mock($|\.[^.]*$)/i,
|
|
185
|
+
}, "hasMount"), rt = /^[.\/#].*\.mock($|\.[^.]*$)/i, L = class extends Error {
|
|
186
186
|
static {
|
|
187
|
-
|
|
187
|
+
f(this, "NoMetaError");
|
|
188
188
|
}
|
|
189
189
|
constructor(e, t, r) {
|
|
190
190
|
let i = "".trim();
|
|
191
|
-
super(
|
|
191
|
+
super(P.dedent`
|
|
192
192
|
CSF: ${e} ${D(t, r)}
|
|
193
193
|
|
|
194
194
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
195
195
|
`), this.name = this.constructor.name;
|
|
196
196
|
}
|
|
197
|
-
},
|
|
197
|
+
}, X = class extends Error {
|
|
198
198
|
static {
|
|
199
|
-
|
|
199
|
+
f(this, "MultipleMetaError");
|
|
200
200
|
}
|
|
201
201
|
constructor(e, t, r) {
|
|
202
202
|
let i = `${e} ${D(t, r)}`.trim();
|
|
203
|
-
super(
|
|
203
|
+
super(P.dedent`
|
|
204
204
|
CSF: ${e} ${D(t, r)}
|
|
205
205
|
|
|
206
206
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
207
207
|
`), this.name = this.constructor.name;
|
|
208
208
|
}
|
|
209
|
-
},
|
|
209
|
+
}, M = class extends Error {
|
|
210
210
|
static {
|
|
211
|
-
|
|
211
|
+
f(this, "MixedFactoryError");
|
|
212
212
|
}
|
|
213
213
|
constructor(e, t, r) {
|
|
214
214
|
let i = `${e} ${D(t, r)}`.trim();
|
|
215
|
-
super(
|
|
215
|
+
super(P.dedent`
|
|
216
216
|
CSF: ${e} ${D(t, r)}
|
|
217
217
|
|
|
218
218
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
219
219
|
`), this.name = this.constructor.name;
|
|
220
220
|
}
|
|
221
|
-
},
|
|
221
|
+
}, U = class extends Error {
|
|
222
222
|
static {
|
|
223
|
-
|
|
223
|
+
f(this, "BadMetaError");
|
|
224
224
|
}
|
|
225
225
|
constructor(e, t, r) {
|
|
226
226
|
let i = "".trim();
|
|
227
|
-
super(
|
|
227
|
+
super(P.dedent`
|
|
228
228
|
CSF: ${e} ${D(t, r)}
|
|
229
229
|
|
|
230
230
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
231
231
|
`), this.name = this.constructor.name;
|
|
232
232
|
}
|
|
233
|
-
},
|
|
233
|
+
}, K = class {
|
|
234
234
|
constructor(e, t, r) {
|
|
235
235
|
this._stories = {};
|
|
236
236
|
this._metaAnnotations = {};
|
|
@@ -242,15 +242,15 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
242
242
|
this._ast = e, this._file = r, this._options = t, this.imports = [];
|
|
243
243
|
}
|
|
244
244
|
static {
|
|
245
|
-
|
|
245
|
+
f(this, "CsfFile");
|
|
246
246
|
}
|
|
247
247
|
_parseTitle(e) {
|
|
248
|
-
let t = c.types.isIdentifier(e) ?
|
|
248
|
+
let t = c.types.isIdentifier(e) ? O(e.name, this._ast.program) : e;
|
|
249
249
|
if (c.types.isStringLiteral(t))
|
|
250
250
|
return t.value;
|
|
251
251
|
if (c.types.isTSSatisfiesExpression(t) && c.types.isStringLiteral(t.expression))
|
|
252
252
|
return t.expression.value;
|
|
253
|
-
throw new Error(
|
|
253
|
+
throw new Error(P.dedent`
|
|
254
254
|
CSF: unexpected dynamic title ${D(t, this._options.fileName)}
|
|
255
255
|
|
|
256
256
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
@@ -258,7 +258,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
258
258
|
}
|
|
259
259
|
_parseMeta(e, t) {
|
|
260
260
|
if (this._metaNode)
|
|
261
|
-
throw new
|
|
261
|
+
throw new X("multiple meta objects", e, this._options.fileName);
|
|
262
262
|
this._metaNode = e;
|
|
263
263
|
let r = {};
|
|
264
264
|
e.properties.forEach((i) => {
|
|
@@ -270,19 +270,19 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
270
270
|
else if (i.key.name === "component") {
|
|
271
271
|
let o = i.value;
|
|
272
272
|
if (c.types.isIdentifier(o)) {
|
|
273
|
-
let
|
|
274
|
-
(
|
|
273
|
+
let a = o.name, p = t.body.find(
|
|
274
|
+
(d) => c.types.isImportDeclaration(d) && d.specifiers.find((g) => g.local.name === a)
|
|
275
275
|
);
|
|
276
|
-
if (
|
|
277
|
-
let { source:
|
|
278
|
-
c.types.isStringLiteral(
|
|
276
|
+
if (p) {
|
|
277
|
+
let { source: d } = p;
|
|
278
|
+
c.types.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
let { code:
|
|
282
|
-
r.component =
|
|
281
|
+
let { code: l } = c.recast.print(i.value, {});
|
|
282
|
+
r.component = l;
|
|
283
283
|
} else if (i.key.name === "tags") {
|
|
284
284
|
let o = i.value;
|
|
285
|
-
c.types.isIdentifier(o) && (o =
|
|
285
|
+
c.types.isIdentifier(o) && (o = O(o.name, this._ast.program)), r.tags = de(o);
|
|
286
286
|
} else if (i.key.name === "id")
|
|
287
287
|
if (c.types.isStringLiteral(i.value))
|
|
288
288
|
r.id = i.value.value;
|
|
@@ -308,34 +308,34 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
308
308
|
if ((0, c.traverse)(this._ast, {
|
|
309
309
|
ExportDefaultDeclaration: {
|
|
310
310
|
enter(r) {
|
|
311
|
-
let { node: i, parent: o } = r,
|
|
312
|
-
if (e._options.transformInlineMeta && !
|
|
313
|
-
let
|
|
314
|
-
e._metaVariableName =
|
|
311
|
+
let { node: i, parent: o } = r, l = c.types.isIdentifier(i.declaration) && c.types.isProgram(o);
|
|
312
|
+
if (e._options.transformInlineMeta && !l && c.types.isExpression(i.declaration)) {
|
|
313
|
+
let d = r.scope.generateUidIdentifier("meta");
|
|
314
|
+
e._metaVariableName = d.name;
|
|
315
315
|
let g = [
|
|
316
|
-
c.types.variableDeclaration("const", [c.types.variableDeclarator(
|
|
317
|
-
c.types.exportDefaultDeclaration(
|
|
316
|
+
c.types.variableDeclaration("const", [c.types.variableDeclarator(d, i.declaration)]),
|
|
317
|
+
c.types.exportDefaultDeclaration(d)
|
|
318
318
|
];
|
|
319
319
|
g.forEach((x) => x.loc = r.node.loc), r.replaceWithMultiple(g);
|
|
320
320
|
return;
|
|
321
321
|
}
|
|
322
|
-
let
|
|
323
|
-
if (
|
|
324
|
-
let
|
|
325
|
-
e._metaVariableName =
|
|
326
|
-
let g = /* @__PURE__ */
|
|
322
|
+
let a, p;
|
|
323
|
+
if (l) {
|
|
324
|
+
let d = i.declaration.name;
|
|
325
|
+
e._metaVariableName = d;
|
|
326
|
+
let g = /* @__PURE__ */ f((x) => c.types.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
327
327
|
e._metaStatement = e._ast.program.body.find(
|
|
328
328
|
(x) => c.types.isVariableDeclaration(x) && x.declarations.find(g)
|
|
329
|
-
),
|
|
329
|
+
), p = (e?._metaStatement?.declarations || []).find(
|
|
330
330
|
g
|
|
331
331
|
)?.init;
|
|
332
332
|
} else
|
|
333
|
-
e._metaStatement = i,
|
|
334
|
-
if (c.types.isObjectExpression(
|
|
333
|
+
e._metaStatement = i, p = i.declaration;
|
|
334
|
+
if (c.types.isObjectExpression(p) ? a = p : (
|
|
335
335
|
// export default { ... } as Meta<...>
|
|
336
|
-
(c.types.isTSAsExpression(
|
|
337
|
-
),
|
|
338
|
-
throw new
|
|
336
|
+
(c.types.isTSAsExpression(p) || c.types.isTSSatisfiesExpression(p)) && c.types.isObjectExpression(p.expression) && (a = p.expression)
|
|
337
|
+
), a && c.types.isProgram(o) && e._parseMeta(a, o), e._metaStatement && !e._metaNode)
|
|
338
|
+
throw new L(
|
|
339
339
|
"default export must be an object",
|
|
340
340
|
e._metaStatement,
|
|
341
341
|
e._options.fileName
|
|
@@ -345,35 +345,35 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
345
345
|
},
|
|
346
346
|
ExportNamedDeclaration: {
|
|
347
347
|
enter(r) {
|
|
348
|
-
let { node: i, parent: o } = r,
|
|
349
|
-
c.types.isVariableDeclaration(i.declaration) ?
|
|
350
|
-
isFunctionDeclaration(i.declaration) && (
|
|
351
|
-
if (c.types.isIdentifier(
|
|
352
|
-
let
|
|
353
|
-
if (
|
|
354
|
-
e._namedExportsOrder = et(
|
|
348
|
+
let { node: i, parent: o } = r, l;
|
|
349
|
+
c.types.isVariableDeclaration(i.declaration) ? l = i.declaration.declarations.filter((a) => c.types.isVariableDeclarator(a)) : c.types.
|
|
350
|
+
isFunctionDeclaration(i.declaration) && (l = [i.declaration]), l ? l.forEach((a) => {
|
|
351
|
+
if (c.types.isIdentifier(a.id)) {
|
|
352
|
+
let p = !1, { name: d } = a.id;
|
|
353
|
+
if (d === "__namedExportsOrder" && c.types.isVariableDeclarator(a)) {
|
|
354
|
+
e._namedExportsOrder = et(a.init);
|
|
355
355
|
return;
|
|
356
356
|
}
|
|
357
|
-
e._storyExports[
|
|
358
|
-
let g = (0, I.storyNameFromExport)(
|
|
359
|
-
e._storyAnnotations[
|
|
360
|
-
`Unexpected annotations for "${
|
|
361
|
-
) : e._storyAnnotations[
|
|
357
|
+
e._storyExports[d] = a, e._storyPaths[d] = r, e._storyStatements[d] = i;
|
|
358
|
+
let g = (0, I.storyNameFromExport)(d);
|
|
359
|
+
e._storyAnnotations[d] ? fe.warn(
|
|
360
|
+
`Unexpected annotations for "${d}" before story declaration`
|
|
361
|
+
) : e._storyAnnotations[d] = {};
|
|
362
362
|
let x;
|
|
363
|
-
if (c.types.isVariableDeclarator(
|
|
364
|
-
expression :
|
|
365
|
-
property) && x.callee.property.name === "story" && (
|
|
366
|
-
throw new
|
|
363
|
+
if (c.types.isVariableDeclarator(a) ? x = c.types.isTSAsExpression(a.init) || c.types.isTSSatisfiesExpression(a.init) ? a.init.
|
|
364
|
+
expression : a.init : x = a, c.types.isCallExpression(x) && c.types.isMemberExpression(x.callee) && c.types.isIdentifier(x.callee.
|
|
365
|
+
property) && x.callee.property.name === "story" && (p = !0, x = x.arguments[0]), e._metaIsFactory && !p)
|
|
366
|
+
throw new M(
|
|
367
367
|
"expected factory story",
|
|
368
368
|
x,
|
|
369
369
|
e._options.fileName
|
|
370
370
|
);
|
|
371
|
-
if (!e._metaIsFactory &&
|
|
372
|
-
throw e._metaNode ? new
|
|
371
|
+
if (!e._metaIsFactory && p)
|
|
372
|
+
throw e._metaNode ? new M(
|
|
373
373
|
"expected non-factory story",
|
|
374
374
|
x,
|
|
375
375
|
e._options.fileName
|
|
376
|
-
) : new
|
|
376
|
+
) : new U(
|
|
377
377
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
378
378
|
x,
|
|
379
379
|
e._options.fileName
|
|
@@ -382,7 +382,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
382
382
|
c.types.isObjectExpression(x) ? (E.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
383
383
|
if (c.types.isIdentifier(b.key)) {
|
|
384
384
|
if (b.key.name === "render")
|
|
385
|
-
E.__isArgsStory =
|
|
385
|
+
E.__isArgsStory = me(
|
|
386
386
|
b.value,
|
|
387
387
|
o,
|
|
388
388
|
e
|
|
@@ -390,8 +390,8 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
390
390
|
else if (b.key.name === "name" && c.types.isStringLiteral(b.value))
|
|
391
391
|
g = b.value.value;
|
|
392
392
|
else if (b.key.name === "storyName" && c.types.isStringLiteral(b.value))
|
|
393
|
-
|
|
394
|
-
`Unexpected usage of "storyName" in "${
|
|
393
|
+
fe.warn(
|
|
394
|
+
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
395
395
|
);
|
|
396
396
|
else if (b.key.name === "parameters" && c.types.isObjectExpression(b.value)) {
|
|
397
397
|
let h = b.value.properties.find(
|
|
@@ -399,31 +399,31 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
399
399
|
);
|
|
400
400
|
h && (E.__id = h.value.value);
|
|
401
401
|
}
|
|
402
|
-
e._storyAnnotations[
|
|
402
|
+
e._storyAnnotations[d][b.key.name] = b.value;
|
|
403
403
|
}
|
|
404
|
-
})) : E.__isArgsStory =
|
|
404
|
+
})) : E.__isArgsStory = me(x, o, e), e._stories[d] = {
|
|
405
405
|
id: "FIXME",
|
|
406
406
|
name: g,
|
|
407
407
|
parameters: E,
|
|
408
408
|
__stats: {
|
|
409
|
-
factory:
|
|
409
|
+
factory: p
|
|
410
410
|
}
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
414
|
-
if (c.types.isExportSpecifier(
|
|
415
|
-
let { name:
|
|
416
|
-
if (
|
|
413
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((a) => {
|
|
414
|
+
if (c.types.isExportSpecifier(a) && c.types.isIdentifier(a.exported)) {
|
|
415
|
+
let { name: p } = a.exported, { name: d } = a.local, g = c.types.isProgram(o) ? O(a.local.name, o) : a.local;
|
|
416
|
+
if (p === "default") {
|
|
417
417
|
let x;
|
|
418
418
|
c.types.isObjectExpression(g) ? x = g : (
|
|
419
419
|
// export default { ... } as Meta<...>
|
|
420
420
|
c.types.isTSAsExpression(g) && c.types.isObjectExpression(g.expression) && (x = g.expression)
|
|
421
421
|
), x && c.types.isProgram(o) && e._parseMeta(x, o);
|
|
422
422
|
} else
|
|
423
|
-
e._storyAnnotations[
|
|
423
|
+
e._storyAnnotations[p] = {}, e._storyStatements[p] = g, e._storyPaths[p] = r, e._stories[p] = {
|
|
424
424
|
id: "FIXME",
|
|
425
|
-
name:
|
|
426
|
-
localName:
|
|
425
|
+
name: p,
|
|
426
|
+
localName: d,
|
|
427
427
|
parameters: {},
|
|
428
428
|
__stats: {}
|
|
429
429
|
};
|
|
@@ -436,14 +436,14 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
436
436
|
let { expression: o } = r;
|
|
437
437
|
if (c.types.isProgram(i) && c.types.isAssignmentExpression(o) && c.types.isMemberExpression(o.left) && c.types.isIdentifier(o.left.
|
|
438
438
|
object) && c.types.isIdentifier(o.left.property)) {
|
|
439
|
-
let
|
|
440
|
-
if (e._storyAnnotations[
|
|
441
|
-
c.types.isIdentifier(
|
|
442
|
-
}) : e._storyAnnotations[
|
|
443
|
-
let
|
|
439
|
+
let l = o.left.object.name, a = o.left.property.name, p = o.right;
|
|
440
|
+
if (e._storyAnnotations[l] && (a === "story" && c.types.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
441
|
+
c.types.isIdentifier(d.key) && (e._storyAnnotations[l][d.key.name] = d.value);
|
|
442
|
+
}) : e._storyAnnotations[l][a] = p), a === "storyName" && c.types.isStringLiteral(p)) {
|
|
443
|
+
let d = p.value, g = e._stories[l];
|
|
444
444
|
if (!g)
|
|
445
445
|
return;
|
|
446
|
-
g.name =
|
|
446
|
+
g.name = d;
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
}
|
|
@@ -452,22 +452,22 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
452
452
|
enter(r) {
|
|
453
453
|
let { node: i } = r, { callee: o } = i;
|
|
454
454
|
if (c.types.isIdentifier(o) && o.name === "storiesOf")
|
|
455
|
-
throw new Error(
|
|
455
|
+
throw new Error(P.dedent`
|
|
456
456
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
457
457
|
|
|
458
458
|
SB8 does not support \`storiesOf\`.
|
|
459
459
|
`);
|
|
460
460
|
if (c.types.isMemberExpression(o) && c.types.isIdentifier(o.property) && o.property.name === "meta" && c.types.isIdentifier(o.object) &&
|
|
461
461
|
i.arguments.length > 0) {
|
|
462
|
-
let
|
|
463
|
-
if (c.types.isImportDeclaration(
|
|
464
|
-
if (
|
|
465
|
-
let
|
|
466
|
-
e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(
|
|
462
|
+
let a = r.scope.getBinding(o.object.name)?.path?.parentPath?.node;
|
|
463
|
+
if (c.types.isImportDeclaration(a))
|
|
464
|
+
if (ge(a.source.value)) {
|
|
465
|
+
let p = i.arguments[0];
|
|
466
|
+
e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
467
467
|
} else
|
|
468
|
-
throw new
|
|
468
|
+
throw new U(
|
|
469
469
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
470
|
-
|
|
470
|
+
a,
|
|
471
471
|
e._options.fileName
|
|
472
472
|
);
|
|
473
473
|
}
|
|
@@ -483,36 +483,36 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
}), !e._meta)
|
|
486
|
-
throw new
|
|
486
|
+
throw new L("missing default export", e._ast, e._options.fileName);
|
|
487
487
|
let t = Object.entries(e._stories);
|
|
488
488
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
489
489
|
e._stories = t.reduce(
|
|
490
490
|
(r, [i, o]) => {
|
|
491
491
|
if (!(0, I.isExportStory)(i, e._meta))
|
|
492
492
|
return r;
|
|
493
|
-
let
|
|
494
|
-
{ includeStories:
|
|
495
|
-
i === "__page" && (t.length === 1 || Array.isArray(
|
|
496
|
-
let
|
|
493
|
+
let l = o.parameters?.__id ?? (0, I.toId)(e._meta?.id || e._meta?.title, (0, I.storyNameFromExport)(i)), a = { ...o.parameters, __id: l },
|
|
494
|
+
{ includeStories: p } = e._meta || {};
|
|
495
|
+
i === "__page" && (t.length === 1 || Array.isArray(p) && p.length === 1) && (a.docsOnly = !0), r[i] = { ...o, id: l, parameters: a };
|
|
496
|
+
let d = e._storyAnnotations[i], { tags: g, play: x } = d;
|
|
497
497
|
if (g) {
|
|
498
|
-
let h = c.types.isIdentifier(g) ?
|
|
499
|
-
r[i].tags =
|
|
498
|
+
let h = c.types.isIdentifier(g) ? O(g.name, this._ast.program) : g;
|
|
499
|
+
r[i].tags = de(h);
|
|
500
500
|
}
|
|
501
501
|
x && (r[i].tags = [...r[i].tags || [], "play-fn"]);
|
|
502
502
|
let E = r[i].__stats;
|
|
503
503
|
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((h) => {
|
|
504
|
-
E[h] = !!
|
|
504
|
+
E[h] = !!d[h] || !!e._metaAnnotations[h];
|
|
505
505
|
});
|
|
506
506
|
let b = e.getStoryExport(i);
|
|
507
|
-
return E.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), E.mount = tt(
|
|
508
|
-
play), E.moduleMock = !!e.imports.find((h) =>
|
|
507
|
+
return E.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), E.mount = tt(d.play ?? e._metaAnnotations.
|
|
508
|
+
play), E.moduleMock = !!e.imports.find((h) => xe(h)), r;
|
|
509
509
|
},
|
|
510
510
|
{}
|
|
511
511
|
), Object.keys(e._storyExports).forEach((r) => {
|
|
512
512
|
(0, I.isExportStory)(r, e._meta) || (delete e._storyExports[r], delete e._storyAnnotations[r], delete e._storyStatements[r]);
|
|
513
513
|
}), e._namedExportsOrder) {
|
|
514
514
|
let r = Object.keys(e._storyExports);
|
|
515
|
-
e._storyExports =
|
|
515
|
+
e._storyExports = ue(e._storyExports, e._namedExportsOrder), e._stories = ue(e._stories, e._namedExportsOrder);
|
|
516
516
|
let i = Object.keys(e._storyExports);
|
|
517
517
|
if (r.length !== i.length)
|
|
518
518
|
throw new Error(
|
|
@@ -533,7 +533,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
533
533
|
let { fileName: e } = this._options;
|
|
534
534
|
if (!e)
|
|
535
535
|
throw new Error(
|
|
536
|
-
|
|
536
|
+
P.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
537
537
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
538
538
|
);
|
|
539
539
|
return Object.entries(this._stories).map(([t, r]) => {
|
|
@@ -552,72 +552,72 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
552
552
|
};
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
|
-
},
|
|
555
|
+
}, ye = /* @__PURE__ */ f(({
|
|
556
556
|
code: s,
|
|
557
557
|
filename: e = "",
|
|
558
558
|
ast: t
|
|
559
|
-
}) => new c.BabelFileClass({ filename: e }, { code: s, ast: t ?? (0, c.babelParse)(s) }), "babelParseFile"),
|
|
560
|
-
let t = (0, c.babelParse)(s), r =
|
|
561
|
-
return new
|
|
562
|
-
}, "loadCsf"),
|
|
559
|
+
}) => new c.BabelFileClass({ filename: e }, { code: s, ast: t ?? (0, c.babelParse)(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
560
|
+
let t = (0, c.babelParse)(s), r = ye({ code: s, filename: e.fileName, ast: t });
|
|
561
|
+
return new K(t, e, r);
|
|
562
|
+
}, "loadCsf"), te = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, t) => {
|
|
563
563
|
let r = (0, c.generate)(s._ast, e, t);
|
|
564
564
|
return e.sourceMaps ? r : r.code;
|
|
565
|
-
}, "formatCsf"),
|
|
566
|
-
let t = (await (0,
|
|
567
|
-
return
|
|
568
|
-
}, "readCsf"), st = /* @__PURE__ */
|
|
565
|
+
}, "formatCsf"), be = /* @__PURE__ */ f((s, e = {}) => c.recast.print(s._ast, e), "printCsf"), it = /* @__PURE__ */ f(async (s, e) => {
|
|
566
|
+
let t = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
567
|
+
return Q(t, { ...e, fileName: s });
|
|
568
|
+
}, "readCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
569
569
|
if (!(e || s._options.fileName))
|
|
570
570
|
throw new Error("Please specify a fileName for writeCsf");
|
|
571
|
-
await (0,
|
|
571
|
+
await (0, J.writeFile)(e, be(s).code);
|
|
572
572
|
}, "writeCsf");
|
|
573
573
|
|
|
574
574
|
// src/csf-tools/ConfigFile.ts
|
|
575
|
-
var
|
|
576
|
-
var
|
|
575
|
+
var ee = require("node:fs/promises"), n = require("storybook/internal/babel"), Ee = z(R(), 1);
|
|
576
|
+
var re = console, ie = /* @__PURE__ */ f(({
|
|
577
577
|
expectedType: s,
|
|
578
578
|
foundType: e,
|
|
579
579
|
node: t
|
|
580
|
-
}) =>
|
|
580
|
+
}) => Ee.dedent`
|
|
581
581
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${t?.type}'.
|
|
582
|
-
`, "getCsfParsingErrorMessage"),
|
|
583
|
-
s.key.value : null, "propKey"),
|
|
584
|
-
s, "unwrap"),
|
|
582
|
+
`, "getCsfParsingErrorMessage"), C = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
583
|
+
s.key.value : null, "propKey"), H = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? H(s.expression) :
|
|
584
|
+
s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
585
585
|
if (s.length === 0)
|
|
586
586
|
return e;
|
|
587
587
|
if (n.types.isObjectExpression(e)) {
|
|
588
|
-
let [t, ...r] = s, i = e.properties.find((o) =>
|
|
588
|
+
let [t, ...r] = s, i = e.properties.find((o) => C(o) === t);
|
|
589
589
|
if (i)
|
|
590
|
-
return
|
|
590
|
+
return he(r, i.value);
|
|
591
591
|
}
|
|
592
|
-
}, "_getPath"),
|
|
592
|
+
}, "_getPath"), _e = /* @__PURE__ */ f((s, e) => {
|
|
593
593
|
if (s.length === 0) {
|
|
594
594
|
if (n.types.isObjectExpression(e))
|
|
595
595
|
return e.properties;
|
|
596
596
|
throw new Error("Expected object expression");
|
|
597
597
|
}
|
|
598
598
|
if (n.types.isObjectExpression(e)) {
|
|
599
|
-
let [t, ...r] = s, i = e.properties.find((o) =>
|
|
599
|
+
let [t, ...r] = s, i = e.properties.find((o) => C(o) === t);
|
|
600
600
|
if (i)
|
|
601
|
-
return r.length === 0 ? e.properties :
|
|
601
|
+
return r.length === 0 ? e.properties : _e(r, i.value);
|
|
602
602
|
}
|
|
603
|
-
}, "_getPathProperties"),
|
|
603
|
+
}, "_getPathProperties"), Y = /* @__PURE__ */ f((s, e) => {
|
|
604
604
|
let t = null, r = null;
|
|
605
605
|
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? r = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
606
606
|
i.declaration) && (r = i.declaration.declarations), r && r.find((o) => n.types.isVariableDeclarator(o) && n.types.isIdentifier(o.id) && o.
|
|
607
607
|
id.name === s ? (t = o, !0) : !1))), t;
|
|
608
|
-
}, "_findVarDeclarator"), F = /* @__PURE__ */
|
|
608
|
+
}, "_findVarDeclarator"), F = /* @__PURE__ */ f((s, e) => Y(s, e)?.init, "_findVarInitialization"), B = /* @__PURE__ */ f((s, e) => {
|
|
609
609
|
if (s.length === 0)
|
|
610
610
|
return e;
|
|
611
|
-
let [t, ...r] = s, i =
|
|
611
|
+
let [t, ...r] = s, i = B(r, e);
|
|
612
612
|
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(t), i)]);
|
|
613
|
-
}, "_makeObjectExpression"),
|
|
613
|
+
}, "_makeObjectExpression"), q = /* @__PURE__ */ f((s, e, t) => {
|
|
614
614
|
let [r, ...i] = s, o = t.properties.find(
|
|
615
|
-
(
|
|
615
|
+
(l) => C(l) === r
|
|
616
616
|
);
|
|
617
|
-
o ? n.types.isObjectExpression(o.value) && i.length > 0 ?
|
|
618
|
-
n.types.objectProperty(n.types.identifier(r),
|
|
617
|
+
o ? n.types.isObjectExpression(o.value) && i.length > 0 ? q(i, e, o.value) : o.value = B(i, e) : t.properties.push(
|
|
618
|
+
n.types.objectProperty(n.types.identifier(r), B(i, e))
|
|
619
619
|
);
|
|
620
|
-
}, "_updateExportNode"),
|
|
620
|
+
}, "_updateExportNode"), Z = class {
|
|
621
621
|
constructor(e, t, r) {
|
|
622
622
|
this._exports = {};
|
|
623
623
|
// FIXME: this is a hack. this is only used in the case where the user is
|
|
@@ -628,11 +628,11 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
628
628
|
this._ast = e, this._code = t, this.fileName = r;
|
|
629
629
|
}
|
|
630
630
|
static {
|
|
631
|
-
|
|
631
|
+
f(this, "ConfigFile");
|
|
632
632
|
}
|
|
633
633
|
_parseExportsObject(e) {
|
|
634
634
|
this._exportsObject = e, e.properties.forEach((t) => {
|
|
635
|
-
let r =
|
|
635
|
+
let r = C(t);
|
|
636
636
|
if (r) {
|
|
637
637
|
let i = t.value;
|
|
638
638
|
n.types.isIdentifier(i) && (i = F(i.name, this._ast.program)), this._exports[r] = i;
|
|
@@ -646,9 +646,9 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
646
646
|
enter({ node: t, parent: r }) {
|
|
647
647
|
e.hasDefaultExport = !0;
|
|
648
648
|
let i = n.types.isIdentifier(t.declaration) && n.types.isProgram(r) ? F(t.declaration.name, r) : t.declaration;
|
|
649
|
-
i =
|
|
650
|
-
i) ? e._parseExportsObject(i) :
|
|
651
|
-
|
|
649
|
+
i = H(i), n.types.isCallExpression(i) && n.types.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.types.isObjectExpression(
|
|
650
|
+
i) ? e._parseExportsObject(i) : re.warn(
|
|
651
|
+
ie({
|
|
652
652
|
expectedType: "ObjectExpression",
|
|
653
653
|
foundType: i?.type,
|
|
654
654
|
node: i || t.declaration
|
|
@@ -661,8 +661,8 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
661
661
|
if (n.types.isVariableDeclaration(t.declaration))
|
|
662
662
|
t.declaration.declarations.forEach((i) => {
|
|
663
663
|
if (n.types.isVariableDeclarator(i) && n.types.isIdentifier(i.id)) {
|
|
664
|
-
let { name: o } = i.id,
|
|
665
|
-
n.types.isIdentifier(
|
|
664
|
+
let { name: o } = i.id, l = i.init;
|
|
665
|
+
n.types.isIdentifier(l) && (l = F(l.name, r)), e._exports[o] = l, e._exportDecls[o] = i;
|
|
666
666
|
}
|
|
667
667
|
});
|
|
668
668
|
else if (n.types.isFunctionDeclaration(t.declaration)) {
|
|
@@ -673,11 +673,11 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
673
673
|
}
|
|
674
674
|
} else t.specifiers ? t.specifiers.forEach((i) => {
|
|
675
675
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
676
|
-
let { name: o } = i.local, { name:
|
|
677
|
-
|
|
676
|
+
let { name: o } = i.local, { name: l } = i.exported, a = Y(o, r);
|
|
677
|
+
a && (e._exports[l] = a.init, e._exportDecls[l] = a);
|
|
678
678
|
}
|
|
679
|
-
}) :
|
|
680
|
-
|
|
679
|
+
}) : re.warn(
|
|
680
|
+
ie({
|
|
681
681
|
expectedType: "VariableDeclaration",
|
|
682
682
|
foundType: t.declaration?.type,
|
|
683
683
|
node: t.declaration
|
|
@@ -691,22 +691,22 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
691
691
|
let { left: i, right: o } = t.expression;
|
|
692
692
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
693
693
|
i.property.name === "exports") {
|
|
694
|
-
let
|
|
695
|
-
n.types.isIdentifier(o) && (
|
|
696
|
-
(
|
|
697
|
-
let
|
|
698
|
-
if (
|
|
699
|
-
let
|
|
700
|
-
n.types.isIdentifier(
|
|
701
|
-
|
|
694
|
+
let l = o;
|
|
695
|
+
n.types.isIdentifier(o) && (l = F(o.name, r)), l = H(l), n.types.isObjectExpression(l) ? (e._exportsObject = l, l.properties.forEach(
|
|
696
|
+
(a) => {
|
|
697
|
+
let p = C(a);
|
|
698
|
+
if (p) {
|
|
699
|
+
let d = a.value;
|
|
700
|
+
n.types.isIdentifier(d) && (d = F(
|
|
701
|
+
d.name,
|
|
702
702
|
r
|
|
703
|
-
)), e._exports[
|
|
703
|
+
)), e._exports[p] = d;
|
|
704
704
|
}
|
|
705
|
-
})) :
|
|
706
|
-
|
|
705
|
+
})) : re.warn(
|
|
706
|
+
ie({
|
|
707
707
|
expectedType: "ObjectExpression",
|
|
708
|
-
foundType:
|
|
709
|
-
node:
|
|
708
|
+
foundType: l?.type,
|
|
709
|
+
node: l
|
|
710
710
|
})
|
|
711
711
|
);
|
|
712
712
|
}
|
|
@@ -714,7 +714,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
714
714
|
}
|
|
715
715
|
},
|
|
716
716
|
CallExpression: {
|
|
717
|
-
enter: /* @__PURE__ */
|
|
717
|
+
enter: /* @__PURE__ */ f(({ node: t }) => {
|
|
718
718
|
n.types.isIdentifier(t.callee) && t.callee.name === "definePreview" && t.arguments.length === 1 && n.types.isObjectExpression(t.arguments[0]) &&
|
|
719
719
|
e._parseExportsObject(t.arguments[0]);
|
|
720
720
|
}, "enter")
|
|
@@ -724,12 +724,12 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
724
724
|
getFieldNode(e) {
|
|
725
725
|
let [t, ...r] = e, i = this._exports[t];
|
|
726
726
|
if (i)
|
|
727
|
-
return
|
|
727
|
+
return he(r, i);
|
|
728
728
|
}
|
|
729
729
|
getFieldProperties(e) {
|
|
730
730
|
let [t, ...r] = e, i = this._exports[t];
|
|
731
731
|
if (i)
|
|
732
|
-
return
|
|
732
|
+
return _e(r, i);
|
|
733
733
|
}
|
|
734
734
|
getFieldValue(e) {
|
|
735
735
|
let t = this.getFieldNode(e);
|
|
@@ -746,13 +746,30 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
746
746
|
}
|
|
747
747
|
setFieldNode(e, t) {
|
|
748
748
|
let [r, ...i] = e, o = this._exports[r];
|
|
749
|
-
if (this._exportsObject)
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
749
|
+
if (this._exportsObject) {
|
|
750
|
+
let p = this._exportsObject.properties.find((d) => C(d) === r);
|
|
751
|
+
if (p && n.types.isIdentifier(p.value)) {
|
|
752
|
+
let d = Y(p.value.name, this._ast.program);
|
|
753
|
+
if (d && n.types.isObjectExpression(d.init)) {
|
|
754
|
+
q(i, t, d.init);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
q(e, t, this._exportsObject), this._exports[e[0]] = t;
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (o && n.types.isObjectExpression(o) && i.length > 0) {
|
|
762
|
+
q(i, t, o);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
let l = Y(r, this._ast.program);
|
|
766
|
+
if (l && n.types.isObjectExpression(l.init)) {
|
|
767
|
+
q(i, t, l.init);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (o && i.length === 0 && this._exportDecls[e[0]]) {
|
|
754
771
|
let a = this._exportDecls[e[0]];
|
|
755
|
-
n.types.isVariableDeclarator(a) && (a.init =
|
|
772
|
+
n.types.isVariableDeclarator(a) && (a.init = B([], t));
|
|
756
773
|
} else {
|
|
757
774
|
if (this.hasDefaultExport)
|
|
758
775
|
throw new Error(
|
|
@@ -761,10 +778,10 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
761
778
|
)}" field as the default export is not an object in this file.`
|
|
762
779
|
);
|
|
763
780
|
{
|
|
764
|
-
let a =
|
|
781
|
+
let a = B(i, t), p = n.types.exportNamedDeclaration(
|
|
765
782
|
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(r), a)])
|
|
766
783
|
);
|
|
767
|
-
this._exports[r] = a, this._ast.program.body.push(
|
|
784
|
+
this._exports[r] = a, this._ast.program.body.push(p);
|
|
768
785
|
}
|
|
769
786
|
}
|
|
770
787
|
}
|
|
@@ -832,31 +849,31 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
832
849
|
return r;
|
|
833
850
|
}
|
|
834
851
|
removeField(e) {
|
|
835
|
-
let t = /* @__PURE__ */
|
|
836
|
-
let
|
|
837
|
-
(
|
|
852
|
+
let t = /* @__PURE__ */ f((i, o) => {
|
|
853
|
+
let l = i.findIndex(
|
|
854
|
+
(a) => n.types.isIdentifier(a.key) && a.key.name === o || n.types.isStringLiteral(a.key) && a.key.value === o
|
|
838
855
|
);
|
|
839
|
-
|
|
856
|
+
l >= 0 && i.splice(l, 1);
|
|
840
857
|
}, "removeProperty");
|
|
841
858
|
if (e.length === 1) {
|
|
842
859
|
let i = !1;
|
|
843
860
|
if (this._ast.program.body.forEach((o) => {
|
|
844
861
|
if (n.types.isExportNamedDeclaration(o) && n.types.isVariableDeclaration(o.declaration)) {
|
|
845
|
-
let
|
|
846
|
-
n.types.isIdentifier(
|
|
862
|
+
let l = o.declaration.declarations[0];
|
|
863
|
+
n.types.isIdentifier(l.id) && l.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(o), 1), i = !0);
|
|
847
864
|
}
|
|
848
865
|
if (n.types.isExportDefaultDeclaration(o)) {
|
|
849
|
-
let
|
|
850
|
-
if (n.types.isIdentifier(
|
|
851
|
-
let
|
|
852
|
-
t(
|
|
866
|
+
let l = o.declaration;
|
|
867
|
+
if (n.types.isIdentifier(l) && (l = F(l.name, this._ast.program)), l = H(l), n.types.isObjectExpression(l)) {
|
|
868
|
+
let a = l.properties;
|
|
869
|
+
t(a, e[0]), i = !0;
|
|
853
870
|
}
|
|
854
871
|
}
|
|
855
872
|
if (n.types.isExpressionStatement(o) && n.types.isAssignmentExpression(o.expression) && n.types.isMemberExpression(o.expression.left) &&
|
|
856
873
|
n.types.isIdentifier(o.expression.left.object) && o.expression.left.object.name === "module" && n.types.isIdentifier(o.expression.left.
|
|
857
874
|
property) && o.expression.left.property.name === "exports" && n.types.isObjectExpression(o.expression.right)) {
|
|
858
|
-
let
|
|
859
|
-
t(
|
|
875
|
+
let l = o.expression.right.properties;
|
|
876
|
+
t(l, e[0]), i = !0;
|
|
860
877
|
}
|
|
861
878
|
}), i)
|
|
862
879
|
return;
|
|
@@ -913,9 +930,9 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
913
930
|
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: t } }), o = (0, n.babelParse)(`const __x = ${i}`);
|
|
914
931
|
(0, n.traverse)(o, {
|
|
915
932
|
VariableDeclaration: {
|
|
916
|
-
enter({ node:
|
|
917
|
-
|
|
918
|
-
declarations[0].id.name === "__x" && (r =
|
|
933
|
+
enter({ node: l }) {
|
|
934
|
+
l.declarations.length === 1 && n.types.isVariableDeclarator(l.declarations[0]) && n.types.isIdentifier(l.declarations[0].id) && l.
|
|
935
|
+
declarations[0].id.name === "__x" && (r = l.declarations[0].init);
|
|
919
936
|
}
|
|
920
937
|
}
|
|
921
938
|
});
|
|
@@ -954,15 +971,15 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
954
971
|
*/
|
|
955
972
|
setRequireImport(e, t) {
|
|
956
973
|
let r = this._ast.program.body.find(
|
|
957
|
-
(
|
|
958
|
-
|
|
959
|
-
isStringLiteral(
|
|
960
|
-
), i = /* @__PURE__ */
|
|
961
|
-
(
|
|
962
|
-
), "hasRequireSpecifier"), o = /* @__PURE__ */
|
|
963
|
-
n.types.isIdentifier(
|
|
974
|
+
(l) => n.types.isVariableDeclaration(l) && l.declarations.length === 1 && n.types.isVariableDeclarator(l.declarations[0]) && n.types.isCallExpression(
|
|
975
|
+
l.declarations[0].init) && n.types.isIdentifier(l.declarations[0].init.callee) && l.declarations[0].init.callee.name === "require" && n.types.
|
|
976
|
+
isStringLiteral(l.declarations[0].init.arguments[0]) && l.declarations[0].init.arguments[0].value === t
|
|
977
|
+
), i = /* @__PURE__ */ f((l) => n.types.isObjectPattern(r?.declarations[0].id) && r?.declarations[0].id.properties.find(
|
|
978
|
+
(a) => n.types.isObjectProperty(a) && n.types.isIdentifier(a.key) && a.key.name === l
|
|
979
|
+
), "hasRequireSpecifier"), o = /* @__PURE__ */ f((l, a) => l.declarations.length === 1 && n.types.isVariableDeclarator(l.declarations[0]) &&
|
|
980
|
+
n.types.isIdentifier(l.declarations[0].id) && l.declarations[0].id.name === a, "hasDefaultRequireSpecifier");
|
|
964
981
|
if (typeof e == "string") {
|
|
965
|
-
let
|
|
982
|
+
let l = /* @__PURE__ */ f(() => {
|
|
966
983
|
this._ast.program.body.unshift(
|
|
967
984
|
n.types.variableDeclaration("const", [
|
|
968
985
|
n.types.variableDeclarator(
|
|
@@ -972,17 +989,17 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
972
989
|
])
|
|
973
990
|
);
|
|
974
991
|
}, "addDefaultRequireSpecifier");
|
|
975
|
-
r && o(r, e) ||
|
|
976
|
-
} else r ? e.forEach((
|
|
977
|
-
i(
|
|
978
|
-
n.types.objectProperty(n.types.identifier(
|
|
992
|
+
r && o(r, e) || l();
|
|
993
|
+
} else r ? e.forEach((l) => {
|
|
994
|
+
i(l) || r.declarations[0].id.properties.push(
|
|
995
|
+
n.types.objectProperty(n.types.identifier(l), n.types.identifier(l), void 0, !0)
|
|
979
996
|
);
|
|
980
997
|
}) : this._ast.program.body.unshift(
|
|
981
998
|
n.types.variableDeclaration("const", [
|
|
982
999
|
n.types.variableDeclarator(
|
|
983
1000
|
n.types.objectPattern(
|
|
984
1001
|
e.map(
|
|
985
|
-
(
|
|
1002
|
+
(l) => n.types.objectProperty(n.types.identifier(l), n.types.identifier(l), void 0, !0)
|
|
986
1003
|
)
|
|
987
1004
|
),
|
|
988
1005
|
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(t)])
|
|
@@ -1016,32 +1033,32 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
1016
1033
|
* @param fromImport - The module to import from
|
|
1017
1034
|
*/
|
|
1018
1035
|
setImport(e, t) {
|
|
1019
|
-
let r = /* @__PURE__ */
|
|
1020
|
-
(
|
|
1021
|
-
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name ===
|
|
1022
|
-
), "hasImportSpecifier"), o = /* @__PURE__ */
|
|
1023
|
-
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name ===
|
|
1024
|
-
), "hasNamespaceImportSpecifier"),
|
|
1025
|
-
(g) => n.types.isImportDefaultSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name ===
|
|
1026
|
-
), "hasDefaultImportSpecifier"),
|
|
1027
|
-
(
|
|
1036
|
+
let r = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"), i = /* @__PURE__ */ f(
|
|
1037
|
+
(p, d) => p.specifiers.find(
|
|
1038
|
+
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name === d
|
|
1039
|
+
), "hasImportSpecifier"), o = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1040
|
+
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1041
|
+
), "hasNamespaceImportSpecifier"), l = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1042
|
+
(g) => n.types.isImportDefaultSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1043
|
+
), "hasDefaultImportSpecifier"), a = this._ast.program.body.find(
|
|
1044
|
+
(p) => n.types.isImportDeclaration(p) && p.source.value === t
|
|
1028
1045
|
);
|
|
1029
|
-
e === null ?
|
|
1030
|
-
|
|
1046
|
+
e === null ? a || this._ast.program.body.unshift(n.types.importDeclaration([], n.types.stringLiteral(t))) : typeof e == "string" ? a ? l(
|
|
1047
|
+
a, e) || a.specifiers.push(
|
|
1031
1048
|
n.types.importDefaultSpecifier(n.types.identifier(e))
|
|
1032
1049
|
) : this._ast.program.body.unshift(
|
|
1033
1050
|
n.types.importDeclaration(
|
|
1034
1051
|
[n.types.importDefaultSpecifier(n.types.identifier(e))],
|
|
1035
1052
|
n.types.stringLiteral(t)
|
|
1036
1053
|
)
|
|
1037
|
-
) : Array.isArray(e) ?
|
|
1038
|
-
i(
|
|
1054
|
+
) : Array.isArray(e) ? a ? e.forEach((p) => {
|
|
1055
|
+
i(a, p) || a.specifiers.push(r(p));
|
|
1039
1056
|
}) : this._ast.program.body.unshift(
|
|
1040
1057
|
n.types.importDeclaration(
|
|
1041
1058
|
e.map(r),
|
|
1042
1059
|
n.types.stringLiteral(t)
|
|
1043
1060
|
)
|
|
1044
|
-
) : e.namespace && (
|
|
1061
|
+
) : e.namespace && (a ? o(a, e.namespace) || a.specifiers.push(
|
|
1045
1062
|
n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))
|
|
1046
1063
|
) : this._ast.program.body.unshift(
|
|
1047
1064
|
n.types.importDeclaration(
|
|
@@ -1050,41 +1067,41 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
1050
1067
|
)
|
|
1051
1068
|
));
|
|
1052
1069
|
}
|
|
1053
|
-
}, je = /* @__PURE__ */
|
|
1070
|
+
}, je = /* @__PURE__ */ f((s, e) => {
|
|
1054
1071
|
let t = (0, n.babelParse)(s);
|
|
1055
|
-
return new
|
|
1056
|
-
}, "loadConfig"), Se = /* @__PURE__ */
|
|
1057
|
-
"printConfig"), nt = /* @__PURE__ */
|
|
1058
|
-
let e = (await (0,
|
|
1072
|
+
return new Z(t, s, e);
|
|
1073
|
+
}, "loadConfig"), Se = /* @__PURE__ */ f((s) => Oe(s).code, "formatConfig"), Oe = /* @__PURE__ */ f((s, e = {}) => n.recast.print(s._ast, e),
|
|
1074
|
+
"printConfig"), nt = /* @__PURE__ */ f(async (s) => {
|
|
1075
|
+
let e = (await (0, ee.readFile)(s, "utf-8")).toString();
|
|
1059
1076
|
return je(e, s).parse();
|
|
1060
|
-
}, "readConfig"), ot = /* @__PURE__ */
|
|
1077
|
+
}, "readConfig"), ot = /* @__PURE__ */ f(async (s, e) => {
|
|
1061
1078
|
let t = e || s.fileName;
|
|
1062
1079
|
if (!t)
|
|
1063
1080
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1064
|
-
await (0,
|
|
1065
|
-
}, "writeConfig"), at = /* @__PURE__ */
|
|
1081
|
+
await (0, ee.writeFile)(t, Se(s));
|
|
1082
|
+
}, "writeConfig"), at = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((t) => n.types.isImportDeclaration(t) && t.source.value.includes(
|
|
1066
1083
|
"@storybook") && t.specifiers.some((r) => n.types.isImportSpecifier(r) && n.types.isIdentifier(r.imported) && r.imported.name === "definePre\
|
|
1067
1084
|
view")), "isCsfFactoryPreview");
|
|
1068
1085
|
|
|
1069
1086
|
// src/csf-tools/getStorySortParameter.ts
|
|
1070
|
-
var y = require("storybook/internal/babel"), Ie =
|
|
1071
|
-
var lt = console,
|
|
1087
|
+
var y = require("storybook/internal/babel"), Ie = z(R(), 1);
|
|
1088
|
+
var lt = console, se = /* @__PURE__ */ f((s, e) => {
|
|
1072
1089
|
let t;
|
|
1073
1090
|
return s.properties.forEach((r) => {
|
|
1074
1091
|
y.types.isIdentifier(r.key) && r.key.name === e && (t = r.value);
|
|
1075
1092
|
}), t;
|
|
1076
|
-
}, "getValue"),
|
|
1077
|
-
let e =
|
|
1093
|
+
}, "getValue"), ne = /* @__PURE__ */ f((s) => {
|
|
1094
|
+
let e = W(s);
|
|
1078
1095
|
if (y.types.isArrayExpression(e))
|
|
1079
|
-
return e.elements.map((t) =>
|
|
1096
|
+
return e.elements.map((t) => ne(t));
|
|
1080
1097
|
if (y.types.isObjectExpression(e))
|
|
1081
|
-
return e.properties.reduce((t, r) => (y.types.isIdentifier(r.key) && (t[r.key.name] =
|
|
1098
|
+
return e.properties.reduce((t, r) => (y.types.isIdentifier(r.key) && (t[r.key.name] = ne(r.value)), t), {});
|
|
1082
1099
|
if (y.types.isLiteral(e))
|
|
1083
1100
|
return e.value;
|
|
1084
1101
|
if (y.types.isIdentifier(e))
|
|
1085
|
-
return
|
|
1102
|
+
return T(e.name, !0);
|
|
1086
1103
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1087
|
-
}, "parseValue"),
|
|
1104
|
+
}, "parseValue"), T = /* @__PURE__ */ f((s, e) => {
|
|
1088
1105
|
let t = Ie.dedent`
|
|
1089
1106
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1090
1107
|
|
|
@@ -1099,26 +1116,26 @@ var lt = console, ie = /* @__PURE__ */ p((s, e) => {
|
|
|
1099
1116
|
if (e)
|
|
1100
1117
|
throw new Error(t);
|
|
1101
1118
|
lt.info(t);
|
|
1102
|
-
}, "unsupported"),
|
|
1103
|
-
TSModifiers"), De = /* @__PURE__ */
|
|
1104
|
-
let e =
|
|
1119
|
+
}, "unsupported"), W = /* @__PURE__ */ f((s) => y.types.isTSAsExpression(s) || y.types.isTSSatisfiesExpression(s) ? s.expression : s, "strip\
|
|
1120
|
+
TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
1121
|
+
let e = W(s);
|
|
1105
1122
|
if (y.types.isObjectExpression(e)) {
|
|
1106
|
-
let t =
|
|
1123
|
+
let t = se(e, "options");
|
|
1107
1124
|
if (t) {
|
|
1108
1125
|
if (y.types.isObjectExpression(t))
|
|
1109
|
-
return
|
|
1110
|
-
|
|
1126
|
+
return se(t, "storySort");
|
|
1127
|
+
T("options", !0);
|
|
1111
1128
|
}
|
|
1112
1129
|
}
|
|
1113
|
-
}, "parseParameters"),
|
|
1114
|
-
let t =
|
|
1130
|
+
}, "parseParameters"), Pe = /* @__PURE__ */ f((s, e) => {
|
|
1131
|
+
let t = W(s);
|
|
1115
1132
|
if (y.types.isObjectExpression(t)) {
|
|
1116
|
-
let r =
|
|
1117
|
-
if (y.types.isIdentifier(r) && (r =
|
|
1133
|
+
let r = se(t, "parameters");
|
|
1134
|
+
if (y.types.isIdentifier(r) && (r = O(r.name, e)), r)
|
|
1118
1135
|
return De(r);
|
|
1119
1136
|
} else
|
|
1120
|
-
|
|
1121
|
-
}, "parseDefault"), ct = /* @__PURE__ */
|
|
1137
|
+
T("default", !0);
|
|
1138
|
+
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
1122
1139
|
if (!s.includes("storySort"))
|
|
1123
1140
|
return;
|
|
1124
1141
|
let e, t = (0, y.babelParse)(s);
|
|
@@ -1129,20 +1146,20 @@ TSModifiers"), De = /* @__PURE__ */ p((s) => {
|
|
|
1129
1146
|
if (y.types.isVariableDeclarator(i) && y.types.isIdentifier(i.id)) {
|
|
1130
1147
|
let { name: o } = i.id;
|
|
1131
1148
|
if (o === "parameters" && i.init) {
|
|
1132
|
-
let
|
|
1133
|
-
e = De(
|
|
1149
|
+
let l = W(i.init);
|
|
1150
|
+
e = De(l);
|
|
1134
1151
|
}
|
|
1135
1152
|
}
|
|
1136
1153
|
}) : r.specifiers.forEach((i) => {
|
|
1137
|
-
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" &&
|
|
1154
|
+
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" && T("parameters", !1);
|
|
1138
1155
|
});
|
|
1139
1156
|
}
|
|
1140
1157
|
},
|
|
1141
1158
|
ExportDefaultDeclaration: {
|
|
1142
1159
|
enter({ node: r }) {
|
|
1143
1160
|
let i = r.declaration;
|
|
1144
|
-
y.types.isIdentifier(i) && (i =
|
|
1145
|
-
e =
|
|
1161
|
+
y.types.isIdentifier(i) && (i = O(i.name, t.program)), i = W(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1162
|
+
e = Pe(i.arguments[0], t.program) : y.types.isObjectExpression(i) ? e = Pe(i, t.program) : T("default", !1);
|
|
1146
1163
|
}
|
|
1147
1164
|
}
|
|
1148
1165
|
}), !!e) {
|
|
@@ -1157,25 +1174,25 @@ TSModifiers"), De = /* @__PURE__ */ p((s) => {
|
|
|
1157
1174
|
}`;
|
|
1158
1175
|
return (0, eval)(o);
|
|
1159
1176
|
}
|
|
1160
|
-
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ?
|
|
1177
|
+
return y.types.isLiteral(e) || y.types.isArrayExpression(e) || y.types.isObjectExpression(e) ? ne(e) : T("storySort", !0);
|
|
1161
1178
|
}
|
|
1162
1179
|
}, "getStorySortParameter");
|
|
1163
1180
|
|
|
1164
1181
|
// src/csf-tools/enrichCsf.ts
|
|
1165
1182
|
var u = require("storybook/internal/babel");
|
|
1166
|
-
var Ne = /* @__PURE__ */
|
|
1183
|
+
var Ne = /* @__PURE__ */ f((s, e, t, r) => {
|
|
1167
1184
|
let i = e.getStoryExport(t), o = u.types.isCallExpression(i) && u.types.isMemberExpression(i.callee) && u.types.isIdentifier(i.callee.object) &&
|
|
1168
|
-
i.callee.object.name === "meta",
|
|
1169
|
-
memberExpression(u.types.identifier(t), u.types.identifier("input")) : u.types.identifier(t), g = u.types.memberExpression(
|
|
1185
|
+
i.callee.object.name === "meta", l = !r?.disableSource && Fe(i), a = !r?.disableDescription && oe(e._storyStatements[t]), p = [], d = o ? u.types.
|
|
1186
|
+
memberExpression(u.types.identifier(t), u.types.identifier("input")) : u.types.identifier(t), g = u.types.memberExpression(d, u.types.identifier(
|
|
1170
1187
|
"parameters"));
|
|
1171
|
-
|
|
1188
|
+
p.push(u.types.spreadElement(g));
|
|
1172
1189
|
let x = u.types.optionalMemberExpression(
|
|
1173
1190
|
g,
|
|
1174
1191
|
u.types.identifier("docs"),
|
|
1175
1192
|
!1,
|
|
1176
1193
|
!0
|
|
1177
1194
|
), E = [];
|
|
1178
|
-
if (
|
|
1195
|
+
if (l) {
|
|
1179
1196
|
let b = u.types.optionalMemberExpression(
|
|
1180
1197
|
x,
|
|
1181
1198
|
u.types.identifier("source"),
|
|
@@ -1186,13 +1203,13 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1186
1203
|
u.types.objectProperty(
|
|
1187
1204
|
u.types.identifier("source"),
|
|
1188
1205
|
u.types.objectExpression([
|
|
1189
|
-
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(
|
|
1206
|
+
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(l)),
|
|
1190
1207
|
u.types.spreadElement(b)
|
|
1191
1208
|
])
|
|
1192
1209
|
)
|
|
1193
1210
|
);
|
|
1194
1211
|
}
|
|
1195
|
-
if (
|
|
1212
|
+
if (a) {
|
|
1196
1213
|
let b = u.types.optionalMemberExpression(
|
|
1197
1214
|
x,
|
|
1198
1215
|
u.types.identifier("description"),
|
|
@@ -1203,37 +1220,37 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1203
1220
|
u.types.objectProperty(
|
|
1204
1221
|
u.types.identifier("description"),
|
|
1205
1222
|
u.types.objectExpression([
|
|
1206
|
-
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(
|
|
1223
|
+
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(a)),
|
|
1207
1224
|
u.types.spreadElement(b)
|
|
1208
1225
|
])
|
|
1209
1226
|
)
|
|
1210
1227
|
);
|
|
1211
1228
|
}
|
|
1212
1229
|
if (E.length > 0) {
|
|
1213
|
-
|
|
1230
|
+
p.push(
|
|
1214
1231
|
u.types.objectProperty(
|
|
1215
1232
|
u.types.identifier("docs"),
|
|
1216
1233
|
u.types.objectExpression([u.types.spreadElement(x), ...E])
|
|
1217
1234
|
)
|
|
1218
1235
|
);
|
|
1219
1236
|
let b = u.types.expressionStatement(
|
|
1220
|
-
u.types.assignmentExpression("=", g, u.types.objectExpression(
|
|
1237
|
+
u.types.assignmentExpression("=", g, u.types.objectExpression(p))
|
|
1221
1238
|
);
|
|
1222
1239
|
s._ast.program.body.push(b);
|
|
1223
1240
|
}
|
|
1224
|
-
}, "enrichCsfStory"), ve = /* @__PURE__ */
|
|
1241
|
+
}, "enrichCsfStory"), ve = /* @__PURE__ */ f((s, e, t) => {
|
|
1225
1242
|
if (!e.length) {
|
|
1226
1243
|
s.properties.find(
|
|
1227
|
-
(
|
|
1244
|
+
(p) => u.types.isObjectProperty(p) && u.types.isIdentifier(p.key) && p.key.name === "component"
|
|
1228
1245
|
) || s.properties.unshift(t);
|
|
1229
1246
|
return;
|
|
1230
1247
|
}
|
|
1231
1248
|
let [r, ...i] = e, o = s.properties.find(
|
|
1232
|
-
(
|
|
1233
|
-
),
|
|
1234
|
-
o ?
|
|
1235
|
-
}, "addComponentDescription"), we = /* @__PURE__ */
|
|
1236
|
-
let r = !t?.disableDescription &&
|
|
1249
|
+
(a) => u.types.isObjectProperty(a) && u.types.isIdentifier(a.key) && a.key.name === r && u.types.isObjectExpression(a.value)
|
|
1250
|
+
), l;
|
|
1251
|
+
o ? l = o.value : (l = u.types.objectExpression([]), s.properties.push(u.types.objectProperty(u.types.identifier(r), l))), ve(l, i, t);
|
|
1252
|
+
}, "addComponentDescription"), we = /* @__PURE__ */ f((s, e, t) => {
|
|
1253
|
+
let r = !t?.disableDescription && oe(e._metaStatement);
|
|
1237
1254
|
if (r) {
|
|
1238
1255
|
let i = s._metaNode;
|
|
1239
1256
|
i && u.types.isObjectExpression(i) && ve(
|
|
@@ -1242,14 +1259,14 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1242
1259
|
u.types.objectProperty(u.types.identifier("component"), u.types.stringLiteral(r))
|
|
1243
1260
|
);
|
|
1244
1261
|
}
|
|
1245
|
-
}, "enrichCsfMeta"), pt = /* @__PURE__ */
|
|
1262
|
+
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e, t) => {
|
|
1246
1263
|
we(s, e, t), Object.keys(s._storyExports).forEach((r) => {
|
|
1247
1264
|
Ne(s, e, r, t);
|
|
1248
1265
|
});
|
|
1249
|
-
}, "enrichCsf"), Fe = /* @__PURE__ */
|
|
1266
|
+
}, "enrichCsf"), Fe = /* @__PURE__ */ f((s) => {
|
|
1250
1267
|
let e = u.types.isVariableDeclarator(s) ? s.init : s, { code: t } = (0, u.generate)(e, {});
|
|
1251
1268
|
return t;
|
|
1252
|
-
}, "extractSource"),
|
|
1269
|
+
}, "extractSource"), oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((t) => t.type === "CommentLine" || !t.value.startsWith(
|
|
1253
1270
|
"*") ? null : t.value.split(`
|
|
1254
1271
|
`).map((r) => r.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1255
1272
|
`).trim()).filter(Boolean).join(`
|
|
@@ -1259,8 +1276,8 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1259
1276
|
var Ae = require("storybook/internal/babel");
|
|
1260
1277
|
|
|
1261
1278
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1262
|
-
var
|
|
1263
|
-
var Ce = console, ft = /* @__PURE__ */
|
|
1279
|
+
var m = require("storybook/internal/babel"), Te = require("storybook/internal/common"), ke = require("storybook/internal/csf"), ae = z(R(), 1);
|
|
1280
|
+
var Ce = console, ft = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((t) => s?.includes(t)) || e.exclude.some((t) => s?.
|
|
1264
1281
|
includes(t))), "isValidTest");
|
|
1265
1282
|
async function Ve({
|
|
1266
1283
|
code: s,
|
|
@@ -1272,10 +1289,10 @@ async function Ve({
|
|
|
1272
1289
|
}) {
|
|
1273
1290
|
if (!/\.stor(y|ies)\./.test(e))
|
|
1274
1291
|
return s;
|
|
1275
|
-
let
|
|
1292
|
+
let a = Q(s, {
|
|
1276
1293
|
fileName: e,
|
|
1277
1294
|
transformInlineMeta: !0,
|
|
1278
|
-
makeTitle: /* @__PURE__ */
|
|
1295
|
+
makeTitle: /* @__PURE__ */ f((_) => {
|
|
1279
1296
|
let S = (0, Te.getStoryTitle)({
|
|
1280
1297
|
storyFilePath: e,
|
|
1281
1298
|
configDir: t,
|
|
@@ -1283,16 +1300,16 @@ async function Ve({
|
|
|
1283
1300
|
userTitle: _
|
|
1284
1301
|
}) || "unknown";
|
|
1285
1302
|
return S === "unknown" && Ce.warn(
|
|
1286
|
-
|
|
1303
|
+
ae.dedent`
|
|
1287
1304
|
[Storybook]: Could not calculate story title for "${e}".
|
|
1288
1305
|
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${t}".
|
|
1289
1306
|
`
|
|
1290
1307
|
), S;
|
|
1291
1308
|
}, "makeTitle")
|
|
1292
|
-
}).parse(),
|
|
1293
|
-
(_) =>
|
|
1294
|
-
), E =
|
|
1295
|
-
if (x ?
|
|
1309
|
+
}).parse(), p = a._ast, d = a._metaVariableName, g = a._metaNode, x = g.properties.find(
|
|
1310
|
+
(_) => m.types.isObjectProperty(_) && m.types.isIdentifier(_.key) && _.key.name === "title"
|
|
1311
|
+
), E = m.types.stringLiteral(a._meta?.title || "unknown");
|
|
1312
|
+
if (x ? m.types.isObjectProperty(x) && (x.value = E) : g.properties.push(m.types.objectProperty(m.types.identifier("title"), E)), !g || !a.
|
|
1296
1313
|
_meta)
|
|
1297
1314
|
throw new Error(
|
|
1298
1315
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1301,114 +1318,114 @@ Please make sure you have a default export with the meta object. If you are usin
|
|
|
1301
1318
|
le an issue with details about your use case.`
|
|
1302
1319
|
);
|
|
1303
1320
|
let b = {};
|
|
1304
|
-
Object.keys(
|
|
1321
|
+
Object.keys(a._stories).map((_) => {
|
|
1305
1322
|
let S = (0, ke.combineTags)(
|
|
1306
1323
|
"test",
|
|
1307
1324
|
"dev",
|
|
1308
1325
|
...o,
|
|
1309
|
-
...
|
|
1310
|
-
...
|
|
1326
|
+
...a.meta?.tags || [],
|
|
1327
|
+
...a._stories[_].tags || []
|
|
1311
1328
|
);
|
|
1312
|
-
ft(S, i) && (b[_] =
|
|
1329
|
+
ft(S, i) && (b[_] = a._storyStatements[_]);
|
|
1313
1330
|
});
|
|
1314
|
-
let h =
|
|
1331
|
+
let h = a._file.path.scope.generateUidIdentifier("test"), N = a._file.path.scope.generateUidIdentifier("describe");
|
|
1315
1332
|
if (Object.keys(b).length === 0) {
|
|
1316
|
-
let _ =
|
|
1317
|
-
|
|
1318
|
-
|
|
1333
|
+
let _ = m.types.expressionStatement(
|
|
1334
|
+
m.types.callExpression(m.types.memberExpression(N, m.types.identifier("skip")), [
|
|
1335
|
+
m.types.stringLiteral("No valid tests found")
|
|
1319
1336
|
])
|
|
1320
1337
|
);
|
|
1321
|
-
|
|
1338
|
+
p.program.body.push(_);
|
|
1322
1339
|
let S = [
|
|
1323
|
-
|
|
1340
|
+
m.types.importDeclaration(
|
|
1324
1341
|
[
|
|
1325
|
-
|
|
1326
|
-
|
|
1342
|
+
m.types.importSpecifier(h, m.types.identifier("test")),
|
|
1343
|
+
m.types.importSpecifier(N, m.types.identifier("describe"))
|
|
1327
1344
|
],
|
|
1328
|
-
|
|
1345
|
+
m.types.stringLiteral("vitest")
|
|
1329
1346
|
)
|
|
1330
1347
|
];
|
|
1331
|
-
|
|
1348
|
+
p.program.body.unshift(...S);
|
|
1332
1349
|
} else {
|
|
1333
|
-
let
|
|
1334
|
-
let j =
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
),
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
),
|
|
1350
|
+
let le = function() {
|
|
1351
|
+
let j = a._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), v = m.types.memberExpression(
|
|
1352
|
+
m.types.callExpression(m.types.memberExpression(_, m.types.identifier("getState")), []),
|
|
1353
|
+
m.types.identifier("testPath")
|
|
1354
|
+
), k = m.types.memberExpression(
|
|
1355
|
+
m.types.memberExpression(m.types.identifier("globalThis"), m.types.identifier("__vitest_worker__")),
|
|
1356
|
+
m.types.identifier("filepath")
|
|
1357
|
+
), V = m.types.logicalExpression(
|
|
1341
1358
|
"??",
|
|
1342
1359
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1343
1360
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1344
|
-
|
|
1361
|
+
k,
|
|
1345
1362
|
v
|
|
1346
|
-
),
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1363
|
+
), G = m.types.callExpression(
|
|
1364
|
+
m.types.memberExpression(
|
|
1365
|
+
m.types.memberExpression(
|
|
1366
|
+
m.types.memberExpression(m.types.identifier("import"), m.types.identifier("meta")),
|
|
1367
|
+
m.types.identifier("url")
|
|
1351
1368
|
),
|
|
1352
|
-
|
|
1369
|
+
m.types.identifier("includes")
|
|
1353
1370
|
),
|
|
1354
|
-
[
|
|
1371
|
+
[V]
|
|
1355
1372
|
);
|
|
1356
|
-
return { isRunningFromThisFileDeclaration:
|
|
1357
|
-
|
|
1373
|
+
return { isRunningFromThisFileDeclaration: m.types.variableDeclaration("const", [
|
|
1374
|
+
m.types.variableDeclarator(j, G)
|
|
1358
1375
|
]), isRunningFromThisFileId: j };
|
|
1359
1376
|
};
|
|
1360
|
-
var mt =
|
|
1361
|
-
|
|
1362
|
-
let _ =
|
|
1363
|
-
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Re, isRunningFromThisFileId: Le } =
|
|
1364
|
-
|
|
1365
|
-
let Me = /* @__PURE__ */
|
|
1377
|
+
var mt = le;
|
|
1378
|
+
f(le, "getTestGuardDeclaration");
|
|
1379
|
+
let _ = a._file.path.scope.generateUidIdentifier("expect"), S = a._file.path.scope.generateUidIdentifier("testStory"), $e = m.types.identifier(
|
|
1380
|
+
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Re, isRunningFromThisFileId: Le } = le();
|
|
1381
|
+
p.program.body.push(Re);
|
|
1382
|
+
let Me = /* @__PURE__ */ f(({
|
|
1366
1383
|
localName: j,
|
|
1367
1384
|
exportName: v,
|
|
1368
|
-
testTitle:
|
|
1369
|
-
node:
|
|
1385
|
+
testTitle: k,
|
|
1386
|
+
node: V
|
|
1370
1387
|
}) => {
|
|
1371
|
-
let
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1388
|
+
let G = m.types.expressionStatement(
|
|
1389
|
+
m.types.callExpression(h, [
|
|
1390
|
+
m.types.stringLiteral(k),
|
|
1391
|
+
m.types.callExpression(S, [
|
|
1392
|
+
m.types.stringLiteral(v),
|
|
1393
|
+
m.types.identifier(j),
|
|
1394
|
+
m.types.identifier(d),
|
|
1378
1395
|
$e
|
|
1379
1396
|
])
|
|
1380
1397
|
])
|
|
1381
1398
|
);
|
|
1382
|
-
return
|
|
1399
|
+
return G.loc = V.loc, G;
|
|
1383
1400
|
}, "getTestStatementForStory"), Ue = Object.entries(b).map(([j, v]) => {
|
|
1384
1401
|
if (v === null) {
|
|
1385
1402
|
Ce.warn(
|
|
1386
|
-
|
|
1403
|
+
ae.dedent`
|
|
1387
1404
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
1388
1405
|
Please make sure to define stories in the same file and not re-export stories coming from other files".
|
|
1389
1406
|
`
|
|
1390
1407
|
);
|
|
1391
1408
|
return;
|
|
1392
1409
|
}
|
|
1393
|
-
let
|
|
1394
|
-
return Me({ testTitle:
|
|
1395
|
-
}).filter((j) => !!j), qe =
|
|
1396
|
-
|
|
1410
|
+
let k = a._stories[j].localName ?? j, V = a._stories[j].name ?? j;
|
|
1411
|
+
return Me({ testTitle: V, localName: k, exportName: j, node: v });
|
|
1412
|
+
}).filter((j) => !!j), qe = m.types.ifStatement(Le, m.types.blockStatement(Ue));
|
|
1413
|
+
p.program.body.push(qe);
|
|
1397
1414
|
let Be = [
|
|
1398
|
-
|
|
1415
|
+
m.types.importDeclaration(
|
|
1399
1416
|
[
|
|
1400
|
-
|
|
1401
|
-
|
|
1417
|
+
m.types.importSpecifier(h, m.types.identifier("test")),
|
|
1418
|
+
m.types.importSpecifier(_, m.types.identifier("expect"))
|
|
1402
1419
|
],
|
|
1403
|
-
|
|
1420
|
+
m.types.stringLiteral("vitest")
|
|
1404
1421
|
),
|
|
1405
|
-
|
|
1406
|
-
[
|
|
1407
|
-
|
|
1422
|
+
m.types.importDeclaration(
|
|
1423
|
+
[m.types.importSpecifier(S, m.types.identifier("testStory"))],
|
|
1424
|
+
m.types.stringLiteral("@storybook/addon-test/internal/test-utils")
|
|
1408
1425
|
)
|
|
1409
1426
|
];
|
|
1410
|
-
|
|
1427
|
+
p.program.body.unshift(...Be);
|
|
1411
1428
|
}
|
|
1412
|
-
return
|
|
1429
|
+
return te(a, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1413
1430
|
}
|
|
1414
|
-
|
|
1431
|
+
f(Ve, "vitestTransform");
|