storybook 9.0.0-alpha.2 → 9.0.0-alpha.21
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/README.md +1 -1
- package/assets/docs/addon-backgrounds.gif +0 -0
- package/assets/docs/addon-controls-args-annotated.png +0 -0
- package/assets/docs/addon-controls-args-background-color.png +0 -0
- package/assets/docs/addon-controls-args-background-string.png +0 -0
- package/assets/docs/addon-controls-args-docs.png +0 -0
- package/assets/docs/addon-controls-args-logging.png +0 -0
- package/assets/docs/addon-controls-args-no-annotation.png +0 -0
- package/assets/docs/addon-controls-args-reflow-slider.png +0 -0
- package/assets/docs/addon-controls-args-reflow.png +0 -0
- package/assets/docs/addon-controls-args-template.png +0 -0
- package/assets/docs/addon-controls-expanded.png +0 -0
- package/assets/docs/addon-controls-hero.gif +0 -0
- package/assets/docs/addon-controls-install.png +0 -0
- package/assets/docs/hero.gif +0 -0
- package/assets/docs/highlight.png +0 -0
- package/assets/docs/viewport.png +0 -0
- package/assets/server/base-preview-head.html +1 -3
- package/bin/index.cjs +2 -2
- package/dist/actions/decorator.d.ts +6 -0
- package/dist/actions/decorator.js +134 -0
- package/dist/actions/index.cjs +123 -0
- package/dist/actions/index.d.ts +102 -0
- package/dist/actions/index.js +108 -0
- package/dist/actions/preview.cjs +161 -0
- package/dist/actions/preview.d.ts +54 -0
- package/dist/actions/preview.js +152 -0
- package/dist/babel/index.cjs +822 -816
- package/dist/babel/index.js +822 -816
- package/dist/backgrounds/index.cjs +148 -0
- package/dist/backgrounds/index.d.ts +91 -0
- package/dist/backgrounds/index.js +130 -0
- package/dist/backgrounds/preview.cjs +143 -0
- package/dist/backgrounds/preview.d.ts +54 -0
- package/dist/backgrounds/preview.js +127 -0
- package/dist/bin/index.cjs +49 -70
- package/dist/bin/index.js +49 -70
- package/dist/builder-manager/index.cjs +319 -326
- package/dist/builder-manager/index.js +576 -583
- package/dist/channels/index.cjs +1026 -981
- package/dist/channels/index.js +1258 -1207
- package/dist/cli/bin/index.cjs +483 -483
- package/dist/cli/bin/index.js +495 -495
- package/dist/cli/index.cjs +61735 -7590
- package/dist/cli/index.d.ts +25 -21
- package/dist/cli/index.js +61776 -7631
- package/dist/client-logger/index.cjs +56 -88
- package/dist/client-logger/index.js +41 -47
- package/dist/common/index.cjs +16137 -9085
- package/dist/common/index.d.ts +35 -30
- package/dist/common/index.js +16230 -9172
- package/dist/component-testing/index.cjs +23 -0
- package/dist/component-testing/index.d.ts +3 -0
- package/dist/component-testing/index.js +5 -0
- package/dist/component-testing/preview.cjs +40 -0
- package/dist/component-testing/preview.d.ts +5 -0
- package/dist/component-testing/preview.js +25 -0
- package/dist/components/index.cjs +16268 -24926
- package/dist/components/index.d.ts +98 -347
- package/dist/components/index.js +5905 -19177
- package/dist/controls/decorator.d.ts +5 -0
- package/dist/controls/decorator.js +8 -0
- package/dist/controls/index.cjs +26 -0
- package/dist/controls/index.d.ts +39 -0
- package/dist/controls/index.js +6 -0
- package/dist/controls/preview.cjs +26 -0
- package/dist/controls/preview.d.ts +54 -0
- package/dist/controls/preview.js +9 -0
- package/dist/core-events/index.cjs +91 -106
- package/dist/core-events/index.d.ts +139 -104
- package/dist/core-events/index.js +79 -94
- package/dist/core-server/index.cjs +13898 -13409
- package/dist/core-server/index.d.ts +270 -3
- package/dist/core-server/index.js +13981 -13497
- package/dist/core-server/presets/common-manager.css +170 -0
- package/dist/core-server/presets/common-manager.js +12149 -17
- package/dist/core-server/presets/common-preset.cjs +3009 -3155
- package/dist/core-server/presets/common-preset.js +2862 -3009
- package/dist/csf/index.cjs +76 -120
- package/dist/csf/index.d.ts +2 -6
- package/dist/csf/index.js +69 -113
- package/dist/csf-tools/index.cjs +412 -403
- package/dist/csf-tools/index.d.ts +0 -4
- package/dist/csf-tools/index.js +410 -401
- package/dist/docs-tools/index.cjs +2569 -575
- package/dist/docs-tools/index.d.ts +2 -2
- package/dist/docs-tools/index.js +2565 -564
- package/dist/highlight/index.cjs +27 -0
- package/dist/highlight/index.d.ts +61 -0
- package/dist/highlight/index.js +7 -0
- package/dist/highlight/preview.cjs +535 -0
- package/dist/highlight/preview.d.ts +54 -0
- package/dist/highlight/preview.js +519 -0
- package/dist/instrumenter/index.cjs +2207 -2342
- package/dist/instrumenter/index.d.ts +8 -7
- package/dist/instrumenter/index.js +2430 -2603
- package/dist/manager/globals-module-info.cjs +291 -151
- package/dist/manager/globals-module-info.d.ts +1 -1
- package/dist/manager/globals-module-info.js +275 -135
- package/dist/manager/globals-runtime.js +60263 -28383
- package/dist/manager/globals.cjs +23 -19
- package/dist/manager/globals.d.ts +8 -5
- package/dist/manager/globals.js +10 -6
- package/dist/manager/runtime.js +4625 -3921
- package/dist/manager-api/index.cjs +4228 -3833
- package/dist/manager-api/index.d.ts +398 -102
- package/dist/manager-api/index.js +3500 -3084
- package/dist/manager-errors.d.ts +25 -1
- package/dist/manager-errors.js +50 -30
- package/dist/measure/index.cjs +476 -0
- package/dist/measure/index.d.ts +66 -0
- package/dist/measure/index.js +464 -0
- package/dist/measure/preview.cjs +466 -0
- package/dist/measure/preview.d.ts +59 -0
- package/dist/measure/preview.js +450 -0
- package/dist/outline/index.cjs +528 -0
- package/dist/outline/index.d.ts +66 -0
- package/dist/outline/index.js +500 -0
- package/dist/outline/preview.cjs +518 -0
- package/dist/outline/preview.d.ts +59 -0
- package/dist/outline/preview.js +486 -0
- package/dist/preview/globals.cjs +21 -17
- package/dist/preview/globals.d.ts +4 -1
- package/dist/preview/globals.js +6 -2
- package/dist/preview/runtime.js +46311 -6614
- package/dist/preview-api/index.cjs +1363 -1899
- package/dist/preview-api/index.d.ts +81 -395
- package/dist/preview-api/index.js +1711 -2169
- package/dist/preview-errors.cjs +119 -88
- package/dist/preview-errors.d.ts +30 -2
- package/dist/preview-errors.js +192 -142
- package/dist/router/index.cjs +847 -871
- package/dist/router/index.js +193 -199
- package/dist/server-errors.cjs +188 -124
- package/dist/server-errors.d.ts +36 -2
- package/dist/server-errors.js +188 -124
- package/dist/telemetry/index.cjs +1056 -1979
- package/dist/telemetry/index.d.ts +26 -5
- package/dist/telemetry/index.js +1091 -2010
- package/dist/test/index.cjs +35686 -0
- package/dist/test/index.d.ts +186 -0
- package/dist/test/index.js +33840 -0
- package/dist/test/preview.cjs +15870 -0
- package/dist/test/preview.d.ts +48 -0
- package/dist/test/preview.js +14501 -0
- package/dist/test/spy.cjs +258 -0
- package/dist/test/spy.d.ts +66 -0
- package/dist/test/spy.js +240 -0
- package/dist/theming/create.cjs +79 -2269
- package/dist/theming/create.js +67 -841
- package/dist/theming/index.cjs +1065 -3232
- package/dist/theming/index.js +951 -1719
- package/dist/types/index.cjs +11 -12
- package/dist/types/index.d.ts +684 -163
- package/dist/types/index.js +1 -2
- package/dist/viewport/index.cjs +310 -0
- package/dist/viewport/index.d.ts +320 -0
- package/dist/viewport/index.js +290 -0
- package/dist/viewport/preview.cjs +35 -0
- package/dist/viewport/preview.d.ts +68 -0
- package/dist/viewport/preview.js +19 -0
- package/package.json +359 -12
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
|
-
enrichCsfStory: () =>
|
|
82
|
-
extractDescription: () =>
|
|
81
|
+
enrichCsfStory: () => ve,
|
|
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,23 +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
|
-
|
|
246
|
-
}
|
|
247
|
-
/** @deprecated Use `_options.fileName` instead */
|
|
248
|
-
get _fileName() {
|
|
249
|
-
return this._options.fileName;
|
|
250
|
-
}
|
|
251
|
-
/** @deprecated Use `_options.makeTitle` instead */
|
|
252
|
-
get _makeTitle() {
|
|
253
|
-
return this._options.makeTitle;
|
|
245
|
+
f(this, "CsfFile");
|
|
254
246
|
}
|
|
255
247
|
_parseTitle(e) {
|
|
256
|
-
let t = c.types.isIdentifier(e) ?
|
|
248
|
+
let t = c.types.isIdentifier(e) ? O(e.name, this._ast.program) : e;
|
|
257
249
|
if (c.types.isStringLiteral(t))
|
|
258
250
|
return t.value;
|
|
259
251
|
if (c.types.isTSSatisfiesExpression(t) && c.types.isStringLiteral(t.expression))
|
|
260
252
|
return t.expression.value;
|
|
261
|
-
throw new Error(
|
|
253
|
+
throw new Error(P.dedent`
|
|
262
254
|
CSF: unexpected dynamic title ${D(t, this._options.fileName)}
|
|
263
255
|
|
|
264
256
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
@@ -266,7 +258,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
266
258
|
}
|
|
267
259
|
_parseMeta(e, t) {
|
|
268
260
|
if (this._metaNode)
|
|
269
|
-
throw new
|
|
261
|
+
throw new X("multiple meta objects", e, this._options.fileName);
|
|
270
262
|
this._metaNode = e;
|
|
271
263
|
let r = {};
|
|
272
264
|
e.properties.forEach((i) => {
|
|
@@ -278,19 +270,19 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
278
270
|
else if (i.key.name === "component") {
|
|
279
271
|
let o = i.value;
|
|
280
272
|
if (c.types.isIdentifier(o)) {
|
|
281
|
-
let
|
|
282
|
-
(
|
|
273
|
+
let a = o.name, p = t.body.find(
|
|
274
|
+
(d) => c.types.isImportDeclaration(d) && d.specifiers.find((g) => g.local.name === a)
|
|
283
275
|
);
|
|
284
|
-
if (
|
|
285
|
-
let { source:
|
|
286
|
-
c.types.isStringLiteral(
|
|
276
|
+
if (p) {
|
|
277
|
+
let { source: d } = p;
|
|
278
|
+
c.types.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
287
279
|
}
|
|
288
280
|
}
|
|
289
|
-
let { code:
|
|
290
|
-
r.component =
|
|
281
|
+
let { code: l } = c.recast.print(i.value, {});
|
|
282
|
+
r.component = l;
|
|
291
283
|
} else if (i.key.name === "tags") {
|
|
292
284
|
let o = i.value;
|
|
293
|
-
c.types.isIdentifier(o) && (o =
|
|
285
|
+
c.types.isIdentifier(o) && (o = O(o.name, this._ast.program)), r.tags = de(o);
|
|
294
286
|
} else if (i.key.name === "id")
|
|
295
287
|
if (c.types.isStringLiteral(i.value))
|
|
296
288
|
r.id = i.value.value;
|
|
@@ -316,34 +308,34 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
316
308
|
if ((0, c.traverse)(this._ast, {
|
|
317
309
|
ExportDefaultDeclaration: {
|
|
318
310
|
enter(r) {
|
|
319
|
-
let { node: i, parent: o } = r,
|
|
320
|
-
if (e._options.transformInlineMeta && !
|
|
321
|
-
let
|
|
322
|
-
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;
|
|
323
315
|
let g = [
|
|
324
|
-
c.types.variableDeclaration("const", [c.types.variableDeclarator(
|
|
325
|
-
c.types.exportDefaultDeclaration(
|
|
316
|
+
c.types.variableDeclaration("const", [c.types.variableDeclarator(d, i.declaration)]),
|
|
317
|
+
c.types.exportDefaultDeclaration(d)
|
|
326
318
|
];
|
|
327
319
|
g.forEach((x) => x.loc = r.node.loc), r.replaceWithMultiple(g);
|
|
328
320
|
return;
|
|
329
321
|
}
|
|
330
|
-
let
|
|
331
|
-
if (
|
|
332
|
-
let
|
|
333
|
-
e._metaVariableName =
|
|
334
|
-
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");
|
|
335
327
|
e._metaStatement = e._ast.program.body.find(
|
|
336
328
|
(x) => c.types.isVariableDeclaration(x) && x.declarations.find(g)
|
|
337
|
-
),
|
|
329
|
+
), p = (e?._metaStatement?.declarations || []).find(
|
|
338
330
|
g
|
|
339
331
|
)?.init;
|
|
340
332
|
} else
|
|
341
|
-
e._metaStatement = i,
|
|
342
|
-
if (c.types.isObjectExpression(
|
|
333
|
+
e._metaStatement = i, p = i.declaration;
|
|
334
|
+
if (c.types.isObjectExpression(p) ? a = p : (
|
|
343
335
|
// export default { ... } as Meta<...>
|
|
344
|
-
(c.types.isTSAsExpression(
|
|
345
|
-
),
|
|
346
|
-
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(
|
|
347
339
|
"default export must be an object",
|
|
348
340
|
e._metaStatement,
|
|
349
341
|
e._options.fileName
|
|
@@ -353,35 +345,35 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
353
345
|
},
|
|
354
346
|
ExportNamedDeclaration: {
|
|
355
347
|
enter(r) {
|
|
356
|
-
let { node: i, parent: o } = r,
|
|
357
|
-
c.types.isVariableDeclaration(i.declaration) ?
|
|
358
|
-
isFunctionDeclaration(i.declaration) && (
|
|
359
|
-
if (c.types.isIdentifier(
|
|
360
|
-
let
|
|
361
|
-
if (
|
|
362
|
-
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);
|
|
363
355
|
return;
|
|
364
356
|
}
|
|
365
|
-
e._storyExports[
|
|
366
|
-
let g = (0, I.storyNameFromExport)(
|
|
367
|
-
e._storyAnnotations[
|
|
368
|
-
`Unexpected annotations for "${
|
|
369
|
-
) : 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] = {};
|
|
370
362
|
let x;
|
|
371
|
-
if (c.types.isVariableDeclarator(
|
|
372
|
-
expression :
|
|
373
|
-
property) && x.callee.property.name === "story" && (
|
|
374
|
-
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(
|
|
375
367
|
"expected factory story",
|
|
376
368
|
x,
|
|
377
369
|
e._options.fileName
|
|
378
370
|
);
|
|
379
|
-
if (!e._metaIsFactory &&
|
|
380
|
-
throw e._metaNode ? new
|
|
371
|
+
if (!e._metaIsFactory && p)
|
|
372
|
+
throw e._metaNode ? new M(
|
|
381
373
|
"expected non-factory story",
|
|
382
374
|
x,
|
|
383
375
|
e._options.fileName
|
|
384
|
-
) : new
|
|
376
|
+
) : new U(
|
|
385
377
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
386
378
|
x,
|
|
387
379
|
e._options.fileName
|
|
@@ -390,7 +382,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
390
382
|
c.types.isObjectExpression(x) ? (E.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
391
383
|
if (c.types.isIdentifier(b.key)) {
|
|
392
384
|
if (b.key.name === "render")
|
|
393
|
-
E.__isArgsStory =
|
|
385
|
+
E.__isArgsStory = me(
|
|
394
386
|
b.value,
|
|
395
387
|
o,
|
|
396
388
|
e
|
|
@@ -398,40 +390,40 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
398
390
|
else if (b.key.name === "name" && c.types.isStringLiteral(b.value))
|
|
399
391
|
g = b.value.value;
|
|
400
392
|
else if (b.key.name === "storyName" && c.types.isStringLiteral(b.value))
|
|
401
|
-
|
|
402
|
-
`Unexpected usage of "storyName" in "${
|
|
393
|
+
fe.warn(
|
|
394
|
+
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
403
395
|
);
|
|
404
396
|
else if (b.key.name === "parameters" && c.types.isObjectExpression(b.value)) {
|
|
405
397
|
let h = b.value.properties.find(
|
|
406
|
-
(
|
|
398
|
+
(v) => c.types.isObjectProperty(v) && c.types.isIdentifier(v.key) && v.key.name === "__id"
|
|
407
399
|
);
|
|
408
400
|
h && (E.__id = h.value.value);
|
|
409
401
|
}
|
|
410
|
-
e._storyAnnotations[
|
|
402
|
+
e._storyAnnotations[d][b.key.name] = b.value;
|
|
411
403
|
}
|
|
412
|
-
})) : E.__isArgsStory =
|
|
404
|
+
})) : E.__isArgsStory = me(x, o, e), e._stories[d] = {
|
|
413
405
|
id: "FIXME",
|
|
414
406
|
name: g,
|
|
415
407
|
parameters: E,
|
|
416
408
|
__stats: {
|
|
417
|
-
factory:
|
|
409
|
+
factory: p
|
|
418
410
|
}
|
|
419
411
|
};
|
|
420
412
|
}
|
|
421
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
422
|
-
if (c.types.isExportSpecifier(
|
|
423
|
-
let { name:
|
|
424
|
-
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") {
|
|
425
417
|
let x;
|
|
426
418
|
c.types.isObjectExpression(g) ? x = g : (
|
|
427
419
|
// export default { ... } as Meta<...>
|
|
428
420
|
c.types.isTSAsExpression(g) && c.types.isObjectExpression(g.expression) && (x = g.expression)
|
|
429
421
|
), x && c.types.isProgram(o) && e._parseMeta(x, o);
|
|
430
422
|
} else
|
|
431
|
-
e._storyAnnotations[
|
|
423
|
+
e._storyAnnotations[p] = {}, e._storyStatements[p] = g, e._storyPaths[p] = r, e._stories[p] = {
|
|
432
424
|
id: "FIXME",
|
|
433
|
-
name:
|
|
434
|
-
localName:
|
|
425
|
+
name: p,
|
|
426
|
+
localName: d,
|
|
435
427
|
parameters: {},
|
|
436
428
|
__stats: {}
|
|
437
429
|
};
|
|
@@ -444,14 +436,14 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
444
436
|
let { expression: o } = r;
|
|
445
437
|
if (c.types.isProgram(i) && c.types.isAssignmentExpression(o) && c.types.isMemberExpression(o.left) && c.types.isIdentifier(o.left.
|
|
446
438
|
object) && c.types.isIdentifier(o.left.property)) {
|
|
447
|
-
let
|
|
448
|
-
if (e._storyAnnotations[
|
|
449
|
-
c.types.isIdentifier(
|
|
450
|
-
}) : e._storyAnnotations[
|
|
451
|
-
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];
|
|
452
444
|
if (!g)
|
|
453
445
|
return;
|
|
454
|
-
g.name =
|
|
446
|
+
g.name = d;
|
|
455
447
|
}
|
|
456
448
|
}
|
|
457
449
|
}
|
|
@@ -460,22 +452,22 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
460
452
|
enter(r) {
|
|
461
453
|
let { node: i } = r, { callee: o } = i;
|
|
462
454
|
if (c.types.isIdentifier(o) && o.name === "storiesOf")
|
|
463
|
-
throw new Error(
|
|
455
|
+
throw new Error(P.dedent`
|
|
464
456
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
465
457
|
|
|
466
458
|
SB8 does not support \`storiesOf\`.
|
|
467
459
|
`);
|
|
468
460
|
if (c.types.isMemberExpression(o) && c.types.isIdentifier(o.property) && o.property.name === "meta" && c.types.isIdentifier(o.object) &&
|
|
469
461
|
i.arguments.length > 0) {
|
|
470
|
-
let
|
|
471
|
-
if (c.types.isImportDeclaration(
|
|
472
|
-
if (
|
|
473
|
-
let
|
|
474
|
-
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);
|
|
475
467
|
} else
|
|
476
|
-
throw new
|
|
468
|
+
throw new U(
|
|
477
469
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
478
|
-
|
|
470
|
+
a,
|
|
479
471
|
e._options.fileName
|
|
480
472
|
);
|
|
481
473
|
}
|
|
@@ -491,36 +483,36 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
491
483
|
}
|
|
492
484
|
}
|
|
493
485
|
}), !e._meta)
|
|
494
|
-
throw new
|
|
486
|
+
throw new L("missing default export", e._ast, e._options.fileName);
|
|
495
487
|
let t = Object.entries(e._stories);
|
|
496
488
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
497
489
|
e._stories = t.reduce(
|
|
498
490
|
(r, [i, o]) => {
|
|
499
491
|
if (!(0, I.isExportStory)(i, e._meta))
|
|
500
492
|
return r;
|
|
501
|
-
let
|
|
502
|
-
{ includeStories:
|
|
503
|
-
i === "__page" && (t.length === 1 || Array.isArray(
|
|
504
|
-
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;
|
|
505
497
|
if (g) {
|
|
506
|
-
let h = c.types.isIdentifier(g) ?
|
|
507
|
-
r[i].tags =
|
|
498
|
+
let h = c.types.isIdentifier(g) ? O(g.name, this._ast.program) : g;
|
|
499
|
+
r[i].tags = de(h);
|
|
508
500
|
}
|
|
509
501
|
x && (r[i].tags = [...r[i].tags || [], "play-fn"]);
|
|
510
502
|
let E = r[i].__stats;
|
|
511
503
|
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((h) => {
|
|
512
|
-
E[h] = !!
|
|
504
|
+
E[h] = !!d[h] || !!e._metaAnnotations[h];
|
|
513
505
|
});
|
|
514
506
|
let b = e.getStoryExport(i);
|
|
515
|
-
return E.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), E.mount = tt(
|
|
516
|
-
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;
|
|
517
509
|
},
|
|
518
510
|
{}
|
|
519
511
|
), Object.keys(e._storyExports).forEach((r) => {
|
|
520
512
|
(0, I.isExportStory)(r, e._meta) || (delete e._storyExports[r], delete e._storyAnnotations[r], delete e._storyStatements[r]);
|
|
521
513
|
}), e._namedExportsOrder) {
|
|
522
514
|
let r = Object.keys(e._storyExports);
|
|
523
|
-
e._storyExports =
|
|
515
|
+
e._storyExports = ue(e._storyExports, e._namedExportsOrder), e._stories = ue(e._stories, e._namedExportsOrder);
|
|
524
516
|
let i = Object.keys(e._storyExports);
|
|
525
517
|
if (r.length !== i.length)
|
|
526
518
|
throw new Error(
|
|
@@ -541,7 +533,7 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
541
533
|
let { fileName: e } = this._options;
|
|
542
534
|
if (!e)
|
|
543
535
|
throw new Error(
|
|
544
|
-
|
|
536
|
+
P.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
545
537
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
546
538
|
);
|
|
547
539
|
return Object.entries(this._stories).map(([t, r]) => {
|
|
@@ -560,72 +552,72 @@ var D = /* @__PURE__ */ p((s, e) => {
|
|
|
560
552
|
};
|
|
561
553
|
});
|
|
562
554
|
}
|
|
563
|
-
},
|
|
555
|
+
}, ye = /* @__PURE__ */ f(({
|
|
564
556
|
code: s,
|
|
565
557
|
filename: e = "",
|
|
566
558
|
ast: t
|
|
567
|
-
}) => new c.BabelFileClass({ filename: e }, { code: s, ast: t ?? (0, c.babelParse)(s) }), "babelParseFile"),
|
|
568
|
-
let t = (0, c.babelParse)(s), r =
|
|
569
|
-
return new
|
|
570
|
-
}, "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) => {
|
|
571
563
|
let r = (0, c.generate)(s._ast, e, t);
|
|
572
564
|
return e.sourceMaps ? r : r.code;
|
|
573
|
-
}, "formatCsf"),
|
|
574
|
-
let t = (await (0,
|
|
575
|
-
return
|
|
576
|
-
}, "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) => {
|
|
577
569
|
if (!(e || s._options.fileName))
|
|
578
570
|
throw new Error("Please specify a fileName for writeCsf");
|
|
579
|
-
await (0,
|
|
571
|
+
await (0, J.writeFile)(e, be(s).code);
|
|
580
572
|
}, "writeCsf");
|
|
581
573
|
|
|
582
574
|
// src/csf-tools/ConfigFile.ts
|
|
583
|
-
var
|
|
584
|
-
var
|
|
575
|
+
var ee = require("node:fs/promises"), n = require("storybook/internal/babel"), Ee = z(R(), 1);
|
|
576
|
+
var re = console, ie = /* @__PURE__ */ f(({
|
|
585
577
|
expectedType: s,
|
|
586
578
|
foundType: e,
|
|
587
579
|
node: t
|
|
588
|
-
}) =>
|
|
580
|
+
}) => Ee.dedent`
|
|
589
581
|
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${t?.type}'.
|
|
590
|
-
`, "getCsfParsingErrorMessage"),
|
|
591
|
-
s.key.value : null, "propKey"),
|
|
592
|
-
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) => {
|
|
593
585
|
if (s.length === 0)
|
|
594
586
|
return e;
|
|
595
587
|
if (n.types.isObjectExpression(e)) {
|
|
596
|
-
let [t, ...r] = s, i = e.properties.find((o) =>
|
|
588
|
+
let [t, ...r] = s, i = e.properties.find((o) => C(o) === t);
|
|
597
589
|
if (i)
|
|
598
|
-
return
|
|
590
|
+
return he(r, i.value);
|
|
599
591
|
}
|
|
600
|
-
}, "_getPath"),
|
|
592
|
+
}, "_getPath"), _e = /* @__PURE__ */ f((s, e) => {
|
|
601
593
|
if (s.length === 0) {
|
|
602
594
|
if (n.types.isObjectExpression(e))
|
|
603
595
|
return e.properties;
|
|
604
596
|
throw new Error("Expected object expression");
|
|
605
597
|
}
|
|
606
598
|
if (n.types.isObjectExpression(e)) {
|
|
607
|
-
let [t, ...r] = s, i = e.properties.find((o) =>
|
|
599
|
+
let [t, ...r] = s, i = e.properties.find((o) => C(o) === t);
|
|
608
600
|
if (i)
|
|
609
|
-
return r.length === 0 ? e.properties :
|
|
601
|
+
return r.length === 0 ? e.properties : _e(r, i.value);
|
|
610
602
|
}
|
|
611
|
-
}, "_getPathProperties"),
|
|
603
|
+
}, "_getPathProperties"), Y = /* @__PURE__ */ f((s, e) => {
|
|
612
604
|
let t = null, r = null;
|
|
613
605
|
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? r = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
614
606
|
i.declaration) && (r = i.declaration.declarations), r && r.find((o) => n.types.isVariableDeclarator(o) && n.types.isIdentifier(o.id) && o.
|
|
615
607
|
id.name === s ? (t = o, !0) : !1))), t;
|
|
616
|
-
}, "_findVarDeclarator"), F = /* @__PURE__ */
|
|
608
|
+
}, "_findVarDeclarator"), F = /* @__PURE__ */ f((s, e) => Y(s, e)?.init, "_findVarInitialization"), B = /* @__PURE__ */ f((s, e) => {
|
|
617
609
|
if (s.length === 0)
|
|
618
610
|
return e;
|
|
619
|
-
let [t, ...r] = s, i =
|
|
611
|
+
let [t, ...r] = s, i = B(r, e);
|
|
620
612
|
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(t), i)]);
|
|
621
|
-
}, "_makeObjectExpression"),
|
|
613
|
+
}, "_makeObjectExpression"), q = /* @__PURE__ */ f((s, e, t) => {
|
|
622
614
|
let [r, ...i] = s, o = t.properties.find(
|
|
623
|
-
(
|
|
615
|
+
(l) => C(l) === r
|
|
624
616
|
);
|
|
625
|
-
o ? n.types.isObjectExpression(o.value) && i.length > 0 ?
|
|
626
|
-
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))
|
|
627
619
|
);
|
|
628
|
-
}, "_updateExportNode"),
|
|
620
|
+
}, "_updateExportNode"), Z = class {
|
|
629
621
|
constructor(e, t, r) {
|
|
630
622
|
this._exports = {};
|
|
631
623
|
// FIXME: this is a hack. this is only used in the case where the user is
|
|
@@ -636,11 +628,11 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
636
628
|
this._ast = e, this._code = t, this.fileName = r;
|
|
637
629
|
}
|
|
638
630
|
static {
|
|
639
|
-
|
|
631
|
+
f(this, "ConfigFile");
|
|
640
632
|
}
|
|
641
633
|
_parseExportsObject(e) {
|
|
642
634
|
this._exportsObject = e, e.properties.forEach((t) => {
|
|
643
|
-
let r =
|
|
635
|
+
let r = C(t);
|
|
644
636
|
if (r) {
|
|
645
637
|
let i = t.value;
|
|
646
638
|
n.types.isIdentifier(i) && (i = F(i.name, this._ast.program)), this._exports[r] = i;
|
|
@@ -654,9 +646,9 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
654
646
|
enter({ node: t, parent: r }) {
|
|
655
647
|
e.hasDefaultExport = !0;
|
|
656
648
|
let i = n.types.isIdentifier(t.declaration) && n.types.isProgram(r) ? F(t.declaration.name, r) : t.declaration;
|
|
657
|
-
i =
|
|
658
|
-
i) ? e._parseExportsObject(i) :
|
|
659
|
-
|
|
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({
|
|
660
652
|
expectedType: "ObjectExpression",
|
|
661
653
|
foundType: i?.type,
|
|
662
654
|
node: i || t.declaration
|
|
@@ -669,8 +661,8 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
669
661
|
if (n.types.isVariableDeclaration(t.declaration))
|
|
670
662
|
t.declaration.declarations.forEach((i) => {
|
|
671
663
|
if (n.types.isVariableDeclarator(i) && n.types.isIdentifier(i.id)) {
|
|
672
|
-
let { name: o } = i.id,
|
|
673
|
-
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;
|
|
674
666
|
}
|
|
675
667
|
});
|
|
676
668
|
else if (n.types.isFunctionDeclaration(t.declaration)) {
|
|
@@ -681,11 +673,11 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
681
673
|
}
|
|
682
674
|
} else t.specifiers ? t.specifiers.forEach((i) => {
|
|
683
675
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
684
|
-
let { name: o } = i.local, { name:
|
|
685
|
-
|
|
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);
|
|
686
678
|
}
|
|
687
|
-
}) :
|
|
688
|
-
|
|
679
|
+
}) : re.warn(
|
|
680
|
+
ie({
|
|
689
681
|
expectedType: "VariableDeclaration",
|
|
690
682
|
foundType: t.declaration?.type,
|
|
691
683
|
node: t.declaration
|
|
@@ -699,22 +691,22 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
699
691
|
let { left: i, right: o } = t.expression;
|
|
700
692
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
701
693
|
i.property.name === "exports") {
|
|
702
|
-
let
|
|
703
|
-
n.types.isIdentifier(o) && (
|
|
704
|
-
(
|
|
705
|
-
let
|
|
706
|
-
if (
|
|
707
|
-
let
|
|
708
|
-
n.types.isIdentifier(
|
|
709
|
-
|
|
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,
|
|
710
702
|
r
|
|
711
|
-
)), e._exports[
|
|
703
|
+
)), e._exports[p] = d;
|
|
712
704
|
}
|
|
713
|
-
})) :
|
|
714
|
-
|
|
705
|
+
})) : re.warn(
|
|
706
|
+
ie({
|
|
715
707
|
expectedType: "ObjectExpression",
|
|
716
|
-
foundType:
|
|
717
|
-
node:
|
|
708
|
+
foundType: l?.type,
|
|
709
|
+
node: l
|
|
718
710
|
})
|
|
719
711
|
);
|
|
720
712
|
}
|
|
@@ -722,7 +714,7 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
722
714
|
}
|
|
723
715
|
},
|
|
724
716
|
CallExpression: {
|
|
725
|
-
enter: /* @__PURE__ */
|
|
717
|
+
enter: /* @__PURE__ */ f(({ node: t }) => {
|
|
726
718
|
n.types.isIdentifier(t.callee) && t.callee.name === "definePreview" && t.arguments.length === 1 && n.types.isObjectExpression(t.arguments[0]) &&
|
|
727
719
|
e._parseExportsObject(t.arguments[0]);
|
|
728
720
|
}, "enter")
|
|
@@ -732,12 +724,12 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
732
724
|
getFieldNode(e) {
|
|
733
725
|
let [t, ...r] = e, i = this._exports[t];
|
|
734
726
|
if (i)
|
|
735
|
-
return
|
|
727
|
+
return he(r, i);
|
|
736
728
|
}
|
|
737
729
|
getFieldProperties(e) {
|
|
738
730
|
let [t, ...r] = e, i = this._exports[t];
|
|
739
731
|
if (i)
|
|
740
|
-
return
|
|
732
|
+
return _e(r, i);
|
|
741
733
|
}
|
|
742
734
|
getFieldValue(e) {
|
|
743
735
|
let t = this.getFieldNode(e);
|
|
@@ -754,13 +746,30 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
754
746
|
}
|
|
755
747
|
setFieldNode(e, t) {
|
|
756
748
|
let [r, ...i] = e, o = this._exports[r];
|
|
757
|
-
if (this._exportsObject)
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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]]) {
|
|
762
771
|
let a = this._exportDecls[e[0]];
|
|
763
|
-
n.types.isVariableDeclarator(a) && (a.init =
|
|
772
|
+
n.types.isVariableDeclarator(a) && (a.init = B([], t));
|
|
764
773
|
} else {
|
|
765
774
|
if (this.hasDefaultExport)
|
|
766
775
|
throw new Error(
|
|
@@ -769,10 +778,10 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
769
778
|
)}" field as the default export is not an object in this file.`
|
|
770
779
|
);
|
|
771
780
|
{
|
|
772
|
-
let a =
|
|
781
|
+
let a = B(i, t), p = n.types.exportNamedDeclaration(
|
|
773
782
|
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(r), a)])
|
|
774
783
|
);
|
|
775
|
-
this._exports[r] = a, this._ast.program.body.push(
|
|
784
|
+
this._exports[r] = a, this._ast.program.body.push(p);
|
|
776
785
|
}
|
|
777
786
|
}
|
|
778
787
|
}
|
|
@@ -840,31 +849,31 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
840
849
|
return r;
|
|
841
850
|
}
|
|
842
851
|
removeField(e) {
|
|
843
|
-
let t = /* @__PURE__ */
|
|
844
|
-
let
|
|
845
|
-
(
|
|
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
|
|
846
855
|
);
|
|
847
|
-
|
|
856
|
+
l >= 0 && i.splice(l, 1);
|
|
848
857
|
}, "removeProperty");
|
|
849
858
|
if (e.length === 1) {
|
|
850
859
|
let i = !1;
|
|
851
860
|
if (this._ast.program.body.forEach((o) => {
|
|
852
861
|
if (n.types.isExportNamedDeclaration(o) && n.types.isVariableDeclaration(o.declaration)) {
|
|
853
|
-
let
|
|
854
|
-
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);
|
|
855
864
|
}
|
|
856
865
|
if (n.types.isExportDefaultDeclaration(o)) {
|
|
857
|
-
let
|
|
858
|
-
if (n.types.isIdentifier(
|
|
859
|
-
let
|
|
860
|
-
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;
|
|
861
870
|
}
|
|
862
871
|
}
|
|
863
872
|
if (n.types.isExpressionStatement(o) && n.types.isAssignmentExpression(o.expression) && n.types.isMemberExpression(o.expression.left) &&
|
|
864
873
|
n.types.isIdentifier(o.expression.left.object) && o.expression.left.object.name === "module" && n.types.isIdentifier(o.expression.left.
|
|
865
874
|
property) && o.expression.left.property.name === "exports" && n.types.isObjectExpression(o.expression.right)) {
|
|
866
|
-
let
|
|
867
|
-
t(
|
|
875
|
+
let l = o.expression.right.properties;
|
|
876
|
+
t(l, e[0]), i = !0;
|
|
868
877
|
}
|
|
869
878
|
}), i)
|
|
870
879
|
return;
|
|
@@ -921,9 +930,9 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
921
930
|
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: t } }), o = (0, n.babelParse)(`const __x = ${i}`);
|
|
922
931
|
(0, n.traverse)(o, {
|
|
923
932
|
VariableDeclaration: {
|
|
924
|
-
enter({ node:
|
|
925
|
-
|
|
926
|
-
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);
|
|
927
936
|
}
|
|
928
937
|
}
|
|
929
938
|
});
|
|
@@ -962,15 +971,15 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
962
971
|
*/
|
|
963
972
|
setRequireImport(e, t) {
|
|
964
973
|
let r = this._ast.program.body.find(
|
|
965
|
-
(
|
|
966
|
-
|
|
967
|
-
isStringLiteral(
|
|
968
|
-
), i = /* @__PURE__ */
|
|
969
|
-
(
|
|
970
|
-
), "hasRequireSpecifier"), o = /* @__PURE__ */
|
|
971
|
-
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");
|
|
972
981
|
if (typeof e == "string") {
|
|
973
|
-
let
|
|
982
|
+
let l = /* @__PURE__ */ f(() => {
|
|
974
983
|
this._ast.program.body.unshift(
|
|
975
984
|
n.types.variableDeclaration("const", [
|
|
976
985
|
n.types.variableDeclarator(
|
|
@@ -980,17 +989,17 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
980
989
|
])
|
|
981
990
|
);
|
|
982
991
|
}, "addDefaultRequireSpecifier");
|
|
983
|
-
r && o(r, e) ||
|
|
984
|
-
} else r ? e.forEach((
|
|
985
|
-
i(
|
|
986
|
-
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)
|
|
987
996
|
);
|
|
988
997
|
}) : this._ast.program.body.unshift(
|
|
989
998
|
n.types.variableDeclaration("const", [
|
|
990
999
|
n.types.variableDeclarator(
|
|
991
1000
|
n.types.objectPattern(
|
|
992
1001
|
e.map(
|
|
993
|
-
(
|
|
1002
|
+
(l) => n.types.objectProperty(n.types.identifier(l), n.types.identifier(l), void 0, !0)
|
|
994
1003
|
)
|
|
995
1004
|
),
|
|
996
1005
|
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(t)])
|
|
@@ -1024,32 +1033,32 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
1024
1033
|
* @param fromImport - The module to import from
|
|
1025
1034
|
*/
|
|
1026
1035
|
setImport(e, t) {
|
|
1027
|
-
let r = /* @__PURE__ */
|
|
1028
|
-
(
|
|
1029
|
-
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name ===
|
|
1030
|
-
), "hasImportSpecifier"), o = /* @__PURE__ */
|
|
1031
|
-
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name ===
|
|
1032
|
-
), "hasNamespaceImportSpecifier"),
|
|
1033
|
-
(g) => n.types.isImportDefaultSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name ===
|
|
1034
|
-
), "hasDefaultImportSpecifier"),
|
|
1035
|
-
(
|
|
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
|
|
1036
1045
|
);
|
|
1037
|
-
e === null ?
|
|
1038
|
-
|
|
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(
|
|
1039
1048
|
n.types.importDefaultSpecifier(n.types.identifier(e))
|
|
1040
1049
|
) : this._ast.program.body.unshift(
|
|
1041
1050
|
n.types.importDeclaration(
|
|
1042
1051
|
[n.types.importDefaultSpecifier(n.types.identifier(e))],
|
|
1043
1052
|
n.types.stringLiteral(t)
|
|
1044
1053
|
)
|
|
1045
|
-
) : Array.isArray(e) ?
|
|
1046
|
-
i(
|
|
1054
|
+
) : Array.isArray(e) ? a ? e.forEach((p) => {
|
|
1055
|
+
i(a, p) || a.specifiers.push(r(p));
|
|
1047
1056
|
}) : this._ast.program.body.unshift(
|
|
1048
1057
|
n.types.importDeclaration(
|
|
1049
1058
|
e.map(r),
|
|
1050
1059
|
n.types.stringLiteral(t)
|
|
1051
1060
|
)
|
|
1052
|
-
) : e.namespace && (
|
|
1061
|
+
) : e.namespace && (a ? o(a, e.namespace) || a.specifiers.push(
|
|
1053
1062
|
n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))
|
|
1054
1063
|
) : this._ast.program.body.unshift(
|
|
1055
1064
|
n.types.importDeclaration(
|
|
@@ -1058,41 +1067,41 @@ s, "unwrap"), Ee = /* @__PURE__ */ p((s, e) => {
|
|
|
1058
1067
|
)
|
|
1059
1068
|
));
|
|
1060
1069
|
}
|
|
1061
|
-
}, je = /* @__PURE__ */
|
|
1070
|
+
}, je = /* @__PURE__ */ f((s, e) => {
|
|
1062
1071
|
let t = (0, n.babelParse)(s);
|
|
1063
|
-
return new
|
|
1064
|
-
}, "loadConfig"), Se = /* @__PURE__ */
|
|
1065
|
-
"printConfig"), nt = /* @__PURE__ */
|
|
1066
|
-
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();
|
|
1067
1076
|
return je(e, s).parse();
|
|
1068
|
-
}, "readConfig"), ot = /* @__PURE__ */
|
|
1077
|
+
}, "readConfig"), ot = /* @__PURE__ */ f(async (s, e) => {
|
|
1069
1078
|
let t = e || s.fileName;
|
|
1070
1079
|
if (!t)
|
|
1071
1080
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1072
|
-
await (0,
|
|
1073
|
-
}, "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(
|
|
1074
1083
|
"@storybook") && t.specifiers.some((r) => n.types.isImportSpecifier(r) && n.types.isIdentifier(r.imported) && r.imported.name === "definePre\
|
|
1075
1084
|
view")), "isCsfFactoryPreview");
|
|
1076
1085
|
|
|
1077
1086
|
// src/csf-tools/getStorySortParameter.ts
|
|
1078
|
-
var y = require("storybook/internal/babel"), Ie =
|
|
1079
|
-
var lt = console,
|
|
1087
|
+
var y = require("storybook/internal/babel"), Ie = z(R(), 1);
|
|
1088
|
+
var lt = console, se = /* @__PURE__ */ f((s, e) => {
|
|
1080
1089
|
let t;
|
|
1081
1090
|
return s.properties.forEach((r) => {
|
|
1082
1091
|
y.types.isIdentifier(r.key) && r.key.name === e && (t = r.value);
|
|
1083
1092
|
}), t;
|
|
1084
|
-
}, "getValue"),
|
|
1085
|
-
let e =
|
|
1093
|
+
}, "getValue"), ne = /* @__PURE__ */ f((s) => {
|
|
1094
|
+
let e = W(s);
|
|
1086
1095
|
if (y.types.isArrayExpression(e))
|
|
1087
|
-
return e.elements.map((t) =>
|
|
1096
|
+
return e.elements.map((t) => ne(t));
|
|
1088
1097
|
if (y.types.isObjectExpression(e))
|
|
1089
|
-
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), {});
|
|
1090
1099
|
if (y.types.isLiteral(e))
|
|
1091
1100
|
return e.value;
|
|
1092
1101
|
if (y.types.isIdentifier(e))
|
|
1093
|
-
return
|
|
1102
|
+
return T(e.name, !0);
|
|
1094
1103
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1095
|
-
}, "parseValue"),
|
|
1104
|
+
}, "parseValue"), T = /* @__PURE__ */ f((s, e) => {
|
|
1096
1105
|
let t = Ie.dedent`
|
|
1097
1106
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1098
1107
|
|
|
@@ -1107,26 +1116,26 @@ var lt = console, ie = /* @__PURE__ */ p((s, e) => {
|
|
|
1107
1116
|
if (e)
|
|
1108
1117
|
throw new Error(t);
|
|
1109
1118
|
lt.info(t);
|
|
1110
|
-
}, "unsupported"),
|
|
1111
|
-
TSModifiers"), De = /* @__PURE__ */
|
|
1112
|
-
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);
|
|
1113
1122
|
if (y.types.isObjectExpression(e)) {
|
|
1114
|
-
let t =
|
|
1123
|
+
let t = se(e, "options");
|
|
1115
1124
|
if (t) {
|
|
1116
1125
|
if (y.types.isObjectExpression(t))
|
|
1117
|
-
return
|
|
1118
|
-
|
|
1126
|
+
return se(t, "storySort");
|
|
1127
|
+
T("options", !0);
|
|
1119
1128
|
}
|
|
1120
1129
|
}
|
|
1121
|
-
}, "parseParameters"),
|
|
1122
|
-
let t =
|
|
1130
|
+
}, "parseParameters"), Pe = /* @__PURE__ */ f((s, e) => {
|
|
1131
|
+
let t = W(s);
|
|
1123
1132
|
if (y.types.isObjectExpression(t)) {
|
|
1124
|
-
let r =
|
|
1125
|
-
if (y.types.isIdentifier(r) && (r =
|
|
1133
|
+
let r = se(t, "parameters");
|
|
1134
|
+
if (y.types.isIdentifier(r) && (r = O(r.name, e)), r)
|
|
1126
1135
|
return De(r);
|
|
1127
1136
|
} else
|
|
1128
|
-
|
|
1129
|
-
}, "parseDefault"), ct = /* @__PURE__ */
|
|
1137
|
+
T("default", !0);
|
|
1138
|
+
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
1130
1139
|
if (!s.includes("storySort"))
|
|
1131
1140
|
return;
|
|
1132
1141
|
let e, t = (0, y.babelParse)(s);
|
|
@@ -1137,20 +1146,20 @@ TSModifiers"), De = /* @__PURE__ */ p((s) => {
|
|
|
1137
1146
|
if (y.types.isVariableDeclarator(i) && y.types.isIdentifier(i.id)) {
|
|
1138
1147
|
let { name: o } = i.id;
|
|
1139
1148
|
if (o === "parameters" && i.init) {
|
|
1140
|
-
let
|
|
1141
|
-
e = De(
|
|
1149
|
+
let l = W(i.init);
|
|
1150
|
+
e = De(l);
|
|
1142
1151
|
}
|
|
1143
1152
|
}
|
|
1144
1153
|
}) : r.specifiers.forEach((i) => {
|
|
1145
|
-
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" &&
|
|
1154
|
+
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" && T("parameters", !1);
|
|
1146
1155
|
});
|
|
1147
1156
|
}
|
|
1148
1157
|
},
|
|
1149
1158
|
ExportDefaultDeclaration: {
|
|
1150
1159
|
enter({ node: r }) {
|
|
1151
1160
|
let i = r.declaration;
|
|
1152
|
-
y.types.isIdentifier(i) && (i =
|
|
1153
|
-
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);
|
|
1154
1163
|
}
|
|
1155
1164
|
}
|
|
1156
1165
|
}), !!e) {
|
|
@@ -1165,25 +1174,25 @@ TSModifiers"), De = /* @__PURE__ */ p((s) => {
|
|
|
1165
1174
|
}`;
|
|
1166
1175
|
return (0, eval)(o);
|
|
1167
1176
|
}
|
|
1168
|
-
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);
|
|
1169
1178
|
}
|
|
1170
1179
|
}, "getStorySortParameter");
|
|
1171
1180
|
|
|
1172
1181
|
// src/csf-tools/enrichCsf.ts
|
|
1173
1182
|
var u = require("storybook/internal/babel");
|
|
1174
|
-
var
|
|
1183
|
+
var ve = /* @__PURE__ */ f((s, e, t, r) => {
|
|
1175
1184
|
let i = e.getStoryExport(t), o = u.types.isCallExpression(i) && u.types.isMemberExpression(i.callee) && u.types.isIdentifier(i.callee.object) &&
|
|
1176
|
-
i.callee.object.name === "meta",
|
|
1177
|
-
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(
|
|
1178
1187
|
"parameters"));
|
|
1179
|
-
|
|
1188
|
+
p.push(u.types.spreadElement(g));
|
|
1180
1189
|
let x = u.types.optionalMemberExpression(
|
|
1181
1190
|
g,
|
|
1182
1191
|
u.types.identifier("docs"),
|
|
1183
1192
|
!1,
|
|
1184
1193
|
!0
|
|
1185
1194
|
), E = [];
|
|
1186
|
-
if (
|
|
1195
|
+
if (l) {
|
|
1187
1196
|
let b = u.types.optionalMemberExpression(
|
|
1188
1197
|
x,
|
|
1189
1198
|
u.types.identifier("source"),
|
|
@@ -1194,13 +1203,13 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1194
1203
|
u.types.objectProperty(
|
|
1195
1204
|
u.types.identifier("source"),
|
|
1196
1205
|
u.types.objectExpression([
|
|
1197
|
-
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(
|
|
1206
|
+
u.types.objectProperty(u.types.identifier("originalSource"), u.types.stringLiteral(l)),
|
|
1198
1207
|
u.types.spreadElement(b)
|
|
1199
1208
|
])
|
|
1200
1209
|
)
|
|
1201
1210
|
);
|
|
1202
1211
|
}
|
|
1203
|
-
if (
|
|
1212
|
+
if (a) {
|
|
1204
1213
|
let b = u.types.optionalMemberExpression(
|
|
1205
1214
|
x,
|
|
1206
1215
|
u.types.identifier("description"),
|
|
@@ -1211,53 +1220,53 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1211
1220
|
u.types.objectProperty(
|
|
1212
1221
|
u.types.identifier("description"),
|
|
1213
1222
|
u.types.objectExpression([
|
|
1214
|
-
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(
|
|
1223
|
+
u.types.objectProperty(u.types.identifier("story"), u.types.stringLiteral(a)),
|
|
1215
1224
|
u.types.spreadElement(b)
|
|
1216
1225
|
])
|
|
1217
1226
|
)
|
|
1218
1227
|
);
|
|
1219
1228
|
}
|
|
1220
1229
|
if (E.length > 0) {
|
|
1221
|
-
|
|
1230
|
+
p.push(
|
|
1222
1231
|
u.types.objectProperty(
|
|
1223
1232
|
u.types.identifier("docs"),
|
|
1224
1233
|
u.types.objectExpression([u.types.spreadElement(x), ...E])
|
|
1225
1234
|
)
|
|
1226
1235
|
);
|
|
1227
1236
|
let b = u.types.expressionStatement(
|
|
1228
|
-
u.types.assignmentExpression("=", g, u.types.objectExpression(
|
|
1237
|
+
u.types.assignmentExpression("=", g, u.types.objectExpression(p))
|
|
1229
1238
|
);
|
|
1230
1239
|
s._ast.program.body.push(b);
|
|
1231
1240
|
}
|
|
1232
|
-
}, "enrichCsfStory"),
|
|
1241
|
+
}, "enrichCsfStory"), Ne = /* @__PURE__ */ f((s, e, t) => {
|
|
1233
1242
|
if (!e.length) {
|
|
1234
1243
|
s.properties.find(
|
|
1235
|
-
(
|
|
1244
|
+
(p) => u.types.isObjectProperty(p) && u.types.isIdentifier(p.key) && p.key.name === "component"
|
|
1236
1245
|
) || s.properties.unshift(t);
|
|
1237
1246
|
return;
|
|
1238
1247
|
}
|
|
1239
1248
|
let [r, ...i] = e, o = s.properties.find(
|
|
1240
|
-
(
|
|
1241
|
-
),
|
|
1242
|
-
o ?
|
|
1243
|
-
}, "addComponentDescription"), we = /* @__PURE__ */
|
|
1244
|
-
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))), Ne(l, i, t);
|
|
1252
|
+
}, "addComponentDescription"), we = /* @__PURE__ */ f((s, e, t) => {
|
|
1253
|
+
let r = !t?.disableDescription && oe(e._metaStatement);
|
|
1245
1254
|
if (r) {
|
|
1246
1255
|
let i = s._metaNode;
|
|
1247
|
-
i && u.types.isObjectExpression(i) &&
|
|
1256
|
+
i && u.types.isObjectExpression(i) && Ne(
|
|
1248
1257
|
i,
|
|
1249
1258
|
["parameters", "docs", "description"],
|
|
1250
1259
|
u.types.objectProperty(u.types.identifier("component"), u.types.stringLiteral(r))
|
|
1251
1260
|
);
|
|
1252
1261
|
}
|
|
1253
|
-
}, "enrichCsfMeta"), pt = /* @__PURE__ */
|
|
1262
|
+
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e, t) => {
|
|
1254
1263
|
we(s, e, t), Object.keys(s._storyExports).forEach((r) => {
|
|
1255
|
-
|
|
1264
|
+
ve(s, e, r, t);
|
|
1256
1265
|
});
|
|
1257
|
-
}, "enrichCsf"), Fe = /* @__PURE__ */
|
|
1266
|
+
}, "enrichCsf"), Fe = /* @__PURE__ */ f((s) => {
|
|
1258
1267
|
let e = u.types.isVariableDeclarator(s) ? s.init : s, { code: t } = (0, u.generate)(e, {});
|
|
1259
1268
|
return t;
|
|
1260
|
-
}, "extractSource"),
|
|
1269
|
+
}, "extractSource"), oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((t) => t.type === "CommentLine" || !t.value.startsWith(
|
|
1261
1270
|
"*") ? null : t.value.split(`
|
|
1262
1271
|
`).map((r) => r.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1263
1272
|
`).trim()).filter(Boolean).join(`
|
|
@@ -1267,8 +1276,8 @@ var Ne = /* @__PURE__ */ p((s, e, t, r) => {
|
|
|
1267
1276
|
var Ae = require("storybook/internal/babel");
|
|
1268
1277
|
|
|
1269
1278
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1270
|
-
var
|
|
1271
|
-
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?.
|
|
1272
1281
|
includes(t))), "isValidTest");
|
|
1273
1282
|
async function Ve({
|
|
1274
1283
|
code: s,
|
|
@@ -1280,10 +1289,10 @@ async function Ve({
|
|
|
1280
1289
|
}) {
|
|
1281
1290
|
if (!/\.stor(y|ies)\./.test(e))
|
|
1282
1291
|
return s;
|
|
1283
|
-
let
|
|
1292
|
+
let a = Q(s, {
|
|
1284
1293
|
fileName: e,
|
|
1285
1294
|
transformInlineMeta: !0,
|
|
1286
|
-
makeTitle: /* @__PURE__ */
|
|
1295
|
+
makeTitle: /* @__PURE__ */ f((_) => {
|
|
1287
1296
|
let S = (0, Te.getStoryTitle)({
|
|
1288
1297
|
storyFilePath: e,
|
|
1289
1298
|
configDir: t,
|
|
@@ -1291,16 +1300,16 @@ async function Ve({
|
|
|
1291
1300
|
userTitle: _
|
|
1292
1301
|
}) || "unknown";
|
|
1293
1302
|
return S === "unknown" && Ce.warn(
|
|
1294
|
-
|
|
1303
|
+
ae.dedent`
|
|
1295
1304
|
[Storybook]: Could not calculate story title for "${e}".
|
|
1296
1305
|
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${t}".
|
|
1297
1306
|
`
|
|
1298
1307
|
), S;
|
|
1299
1308
|
}, "makeTitle")
|
|
1300
|
-
}).parse(),
|
|
1301
|
-
(_) =>
|
|
1302
|
-
), E =
|
|
1303
|
-
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.
|
|
1304
1313
|
_meta)
|
|
1305
1314
|
throw new Error(
|
|
1306
1315
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1309,114 +1318,114 @@ Please make sure you have a default export with the meta object. If you are usin
|
|
|
1309
1318
|
le an issue with details about your use case.`
|
|
1310
1319
|
);
|
|
1311
1320
|
let b = {};
|
|
1312
|
-
Object.keys(
|
|
1321
|
+
Object.keys(a._stories).map((_) => {
|
|
1313
1322
|
let S = (0, ke.combineTags)(
|
|
1314
1323
|
"test",
|
|
1315
1324
|
"dev",
|
|
1316
1325
|
...o,
|
|
1317
|
-
...
|
|
1318
|
-
...
|
|
1326
|
+
...a.meta?.tags || [],
|
|
1327
|
+
...a._stories[_].tags || []
|
|
1319
1328
|
);
|
|
1320
|
-
ft(S, i) && (b[_] =
|
|
1329
|
+
ft(S, i) && (b[_] = a._storyStatements[_]);
|
|
1321
1330
|
});
|
|
1322
|
-
let h =
|
|
1331
|
+
let h = a._file.path.scope.generateUidIdentifier("test"), v = a._file.path.scope.generateUidIdentifier("describe");
|
|
1323
1332
|
if (Object.keys(b).length === 0) {
|
|
1324
|
-
let _ =
|
|
1325
|
-
|
|
1326
|
-
|
|
1333
|
+
let _ = m.types.expressionStatement(
|
|
1334
|
+
m.types.callExpression(m.types.memberExpression(v, m.types.identifier("skip")), [
|
|
1335
|
+
m.types.stringLiteral("No valid tests found")
|
|
1327
1336
|
])
|
|
1328
1337
|
);
|
|
1329
|
-
|
|
1338
|
+
p.program.body.push(_);
|
|
1330
1339
|
let S = [
|
|
1331
|
-
|
|
1340
|
+
m.types.importDeclaration(
|
|
1332
1341
|
[
|
|
1333
|
-
|
|
1334
|
-
|
|
1342
|
+
m.types.importSpecifier(h, m.types.identifier("test")),
|
|
1343
|
+
m.types.importSpecifier(v, m.types.identifier("describe"))
|
|
1335
1344
|
],
|
|
1336
|
-
|
|
1345
|
+
m.types.stringLiteral("vitest")
|
|
1337
1346
|
)
|
|
1338
1347
|
];
|
|
1339
|
-
|
|
1348
|
+
p.program.body.unshift(...S);
|
|
1340
1349
|
} else {
|
|
1341
|
-
let
|
|
1342
|
-
let j =
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
),
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
),
|
|
1350
|
+
let le = function() {
|
|
1351
|
+
let j = a._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), N = 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(
|
|
1349
1358
|
"??",
|
|
1350
1359
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1351
1360
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
),
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1361
|
+
k,
|
|
1362
|
+
N
|
|
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")
|
|
1359
1368
|
),
|
|
1360
|
-
|
|
1369
|
+
m.types.identifier("includes")
|
|
1361
1370
|
),
|
|
1362
|
-
[
|
|
1371
|
+
[V]
|
|
1363
1372
|
);
|
|
1364
|
-
return { isRunningFromThisFileDeclaration:
|
|
1365
|
-
|
|
1373
|
+
return { isRunningFromThisFileDeclaration: m.types.variableDeclaration("const", [
|
|
1374
|
+
m.types.variableDeclarator(j, G)
|
|
1366
1375
|
]), isRunningFromThisFileId: j };
|
|
1367
1376
|
};
|
|
1368
|
-
var mt =
|
|
1369
|
-
|
|
1370
|
-
let _ =
|
|
1371
|
-
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Re, isRunningFromThisFileId: Le } =
|
|
1372
|
-
|
|
1373
|
-
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(({
|
|
1374
1383
|
localName: j,
|
|
1375
|
-
exportName:
|
|
1376
|
-
testTitle:
|
|
1377
|
-
node:
|
|
1384
|
+
exportName: N,
|
|
1385
|
+
testTitle: k,
|
|
1386
|
+
node: V
|
|
1378
1387
|
}) => {
|
|
1379
|
-
let
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
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(N),
|
|
1393
|
+
m.types.identifier(j),
|
|
1394
|
+
m.types.identifier(d),
|
|
1386
1395
|
$e
|
|
1387
1396
|
])
|
|
1388
1397
|
])
|
|
1389
1398
|
);
|
|
1390
|
-
return
|
|
1391
|
-
}, "getTestStatementForStory"), Ue = Object.entries(b).map(([j,
|
|
1392
|
-
if (
|
|
1399
|
+
return G.loc = V.loc, G;
|
|
1400
|
+
}, "getTestStatementForStory"), Ue = Object.entries(b).map(([j, N]) => {
|
|
1401
|
+
if (N === null) {
|
|
1393
1402
|
Ce.warn(
|
|
1394
|
-
|
|
1403
|
+
ae.dedent`
|
|
1395
1404
|
[Storybook]: Could not transform "${j}" story into test at "${e}".
|
|
1396
1405
|
Please make sure to define stories in the same file and not re-export stories coming from other files".
|
|
1397
1406
|
`
|
|
1398
1407
|
);
|
|
1399
1408
|
return;
|
|
1400
1409
|
}
|
|
1401
|
-
let
|
|
1402
|
-
return Me({ testTitle:
|
|
1403
|
-
}).filter((j) => !!j), qe =
|
|
1404
|
-
|
|
1410
|
+
let k = a._stories[j].localName ?? j, V = a._stories[j].name ?? j;
|
|
1411
|
+
return Me({ testTitle: V, localName: k, exportName: j, node: N });
|
|
1412
|
+
}).filter((j) => !!j), qe = m.types.ifStatement(Le, m.types.blockStatement(Ue));
|
|
1413
|
+
p.program.body.push(qe);
|
|
1405
1414
|
let Be = [
|
|
1406
|
-
|
|
1415
|
+
m.types.importDeclaration(
|
|
1407
1416
|
[
|
|
1408
|
-
|
|
1409
|
-
|
|
1417
|
+
m.types.importSpecifier(h, m.types.identifier("test")),
|
|
1418
|
+
m.types.importSpecifier(_, m.types.identifier("expect"))
|
|
1410
1419
|
],
|
|
1411
|
-
|
|
1420
|
+
m.types.stringLiteral("vitest")
|
|
1412
1421
|
),
|
|
1413
|
-
|
|
1414
|
-
[
|
|
1415
|
-
|
|
1422
|
+
m.types.importDeclaration(
|
|
1423
|
+
[m.types.importSpecifier(S, m.types.identifier("testStory"))],
|
|
1424
|
+
m.types.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1416
1425
|
)
|
|
1417
1426
|
];
|
|
1418
|
-
|
|
1427
|
+
p.program.body.unshift(...Be);
|
|
1419
1428
|
}
|
|
1420
|
-
return
|
|
1429
|
+
return te(a, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1421
1430
|
}
|
|
1422
|
-
|
|
1431
|
+
f(Ve, "vitestTransform");
|