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