storybook 9.0.0-rc.1 → 9.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/index.cjs +43 -43
- package/dist/bin/index.js +43 -43
- package/dist/builder-manager/index.cjs +28 -27
- package/dist/builder-manager/index.js +47 -46
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +1643 -1642
- package/dist/common/index.d.ts +2 -1
- package/dist/common/index.js +46 -45
- package/dist/core-server/presets/common-manager.js +1464 -1464
- package/dist/core-server/presets/common-preset.cjs +20 -17
- package/dist/core-server/presets/common-preset.js +19 -16
- package/dist/csf-tools/index.cjs +542 -535
- package/dist/csf-tools/index.js +531 -524
- package/dist/docs-tools/index.cjs +38 -40
- package/dist/docs-tools/index.d.ts +3 -5
- package/dist/docs-tools/index.js +94 -96
- package/dist/highlight/index.cjs +14 -14
- package/dist/highlight/index.d.ts +27 -14
- package/dist/highlight/index.js +3 -3
- package/dist/highlight/preview.cjs +309 -258
- package/dist/highlight/preview.js +335 -284
- package/dist/manager/globals-runtime.js +1 -1
- package/dist/manager/runtime.js +5 -4
- package/dist/manager-api/index.cjs +1 -1
- package/dist/manager-api/index.js +1 -1
- package/dist/preview/runtime.js +10530 -10468
- package/dist/test/preview.cjs +61 -49
- package/dist/test/preview.js +54 -42
- package/package.json +1 -1
package/dist/csf-tools/index.cjs
CHANGED
|
@@ -6,20 +6,20 @@ var ze = Object.getOwnPropertyNames;
|
|
|
6
6
|
var Xe = Object.getPrototypeOf, Ke = Object.prototype.hasOwnProperty;
|
|
7
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
|
-
for (var
|
|
10
|
-
A(s,
|
|
11
|
-
}, ce = (s, e,
|
|
9
|
+
for (var r in e)
|
|
10
|
+
A(s, r, { get: e[r], enumerable: !0 });
|
|
11
|
+
}, ce = (s, e, r, t) => {
|
|
12
12
|
if (e && typeof e == "object" || typeof e == "function")
|
|
13
13
|
for (let i of ze(e))
|
|
14
|
-
!Ke.call(s, i) && i !==
|
|
14
|
+
!Ke.call(s, i) && i !== r && A(s, i, { get: () => e[i], enumerable: !(t = Ge(e, i)) || t.enumerable });
|
|
15
15
|
return s;
|
|
16
16
|
};
|
|
17
|
-
var z = (s, e,
|
|
17
|
+
var z = (s, e, r) => (r = 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 ? A(
|
|
22
|
+
e || !s || !s.__esModule ? A(r, "default", { value: s, enumerable: !0 }) : r,
|
|
23
23
|
s
|
|
24
24
|
)), He = (s) => ce(A({}, "__esModule", { value: !0 }), s);
|
|
25
25
|
|
|
@@ -29,36 +29,36 @@ var R = Je(($) => {
|
|
|
29
29
|
Object.defineProperty($, "__esModule", { value: !0 });
|
|
30
30
|
$.dedent = void 0;
|
|
31
31
|
function pe(s) {
|
|
32
|
-
for (var e = [],
|
|
33
|
-
e[
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
var i =
|
|
37
|
-
var
|
|
38
|
-
return
|
|
39
|
-
var x,
|
|
40
|
-
return (
|
|
41
|
-
})) :
|
|
32
|
+
for (var e = [], r = 1; r < arguments.length; r++)
|
|
33
|
+
e[r - 1] = arguments[r];
|
|
34
|
+
var t = Array.from(typeof s == "string" ? [s] : s);
|
|
35
|
+
t[t.length - 1] = t[t.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
36
|
+
var i = t.reduce(function(l, p) {
|
|
37
|
+
var d = p.match(/\n([\t ]+|(?!\s).)/g);
|
|
38
|
+
return d ? l.concat(d.map(function(g) {
|
|
39
|
+
var x, h;
|
|
40
|
+
return (h = (x = g.match(/[\t ]/g)) === null || x === void 0 ? void 0 : x.length) !== null && h !== void 0 ? h : 0;
|
|
41
|
+
})) : l;
|
|
42
42
|
}, []);
|
|
43
43
|
if (i.length) {
|
|
44
44
|
var o = new RegExp(`
|
|
45
45
|
[ ]{` + Math.min.apply(Math, i) + "}", "g");
|
|
46
|
-
|
|
47
|
-
return
|
|
46
|
+
t = t.map(function(l) {
|
|
47
|
+
return l.replace(o, `
|
|
48
48
|
`);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
return e.forEach(function(
|
|
54
|
-
var
|
|
55
|
-
typeof
|
|
56
|
-
`) && (x = String(
|
|
57
|
-
`).map(function(
|
|
58
|
-
return b === 0 ?
|
|
51
|
+
t[0] = t[0].replace(/^\r?\n/, "");
|
|
52
|
+
var a = t[0];
|
|
53
|
+
return e.forEach(function(l, p) {
|
|
54
|
+
var d = a.match(/(?:^|\n)( *)$/), g = d ? d[1] : "", x = l;
|
|
55
|
+
typeof l == "string" && l.includes(`
|
|
56
|
+
`) && (x = String(l).split(`
|
|
57
|
+
`).map(function(h, b) {
|
|
58
|
+
return b === 0 ? h : "" + g + h;
|
|
59
59
|
}).join(`
|
|
60
|
-
`)),
|
|
61
|
-
}),
|
|
60
|
+
`)), a += x + t[p + 1];
|
|
61
|
+
}), a;
|
|
62
62
|
}
|
|
63
63
|
f(pe, "dedent");
|
|
64
64
|
$.dedent = pe;
|
|
@@ -78,7 +78,7 @@ Qe(dt, {
|
|
|
78
78
|
babelParseFile: () => ye,
|
|
79
79
|
enrichCsf: () => pt,
|
|
80
80
|
enrichCsfMeta: () => we,
|
|
81
|
-
enrichCsfStory: () =>
|
|
81
|
+
enrichCsfStory: () => Ie,
|
|
82
82
|
extractDescription: () => oe,
|
|
83
83
|
extractSource: () => Fe,
|
|
84
84
|
formatConfig: () => Se,
|
|
@@ -100,15 +100,15 @@ Qe(dt, {
|
|
|
100
100
|
module.exports = He(dt);
|
|
101
101
|
|
|
102
102
|
// src/csf-tools/CsfFile.ts
|
|
103
|
-
var J = require("node:fs/promises"), c = require("storybook/internal/babel"),
|
|
103
|
+
var J = require("node:fs/promises"), c = require("storybook/internal/babel"), v = require("storybook/internal/csf"), O = z(R(), 1);
|
|
104
104
|
|
|
105
105
|
// src/csf-tools/findVarInitialization.ts
|
|
106
106
|
var w = require("storybook/internal/babel");
|
|
107
107
|
var P = /* @__PURE__ */ f((s, e) => {
|
|
108
|
-
let
|
|
109
|
-
return e.body.find((i) => (w.types.isVariableDeclaration(i) ?
|
|
110
|
-
i.declaration) && (
|
|
111
|
-
id.name === s ? (
|
|
108
|
+
let r = null, t = null;
|
|
109
|
+
return e.body.find((i) => (w.types.isVariableDeclaration(i) ? t = i.declarations : w.types.isExportNamedDeclaration(i) && w.types.isVariableDeclaration(
|
|
110
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((o) => w.types.isVariableDeclarator(o) && w.types.isIdentifier(o.id) && o.
|
|
111
|
+
id.name === s ? (r = o.init, !0) : !1))), r;
|
|
112
112
|
}, "findVarInitialization");
|
|
113
113
|
|
|
114
114
|
// src/csf-tools/CsfFile.ts
|
|
@@ -138,23 +138,23 @@ function de(s) {
|
|
|
138
138
|
}
|
|
139
139
|
f(de, "parseTags");
|
|
140
140
|
var D = /* @__PURE__ */ f((s, e) => {
|
|
141
|
-
let
|
|
141
|
+
let r = "";
|
|
142
142
|
if (s.loc) {
|
|
143
|
-
let { line:
|
|
144
|
-
|
|
143
|
+
let { line: t, column: i } = s.loc?.start || {};
|
|
144
|
+
r = `(line ${t}, col ${i})`;
|
|
145
145
|
}
|
|
146
|
-
return `${e || ""} ${
|
|
147
|
-
}, "formatLocation"), xe = /* @__PURE__ */ f((s) => rt.test(s), "isModuleMock"),
|
|
148
|
-
let
|
|
146
|
+
return `${e || ""} ${r}`.trim();
|
|
147
|
+
}, "formatLocation"), xe = /* @__PURE__ */ f((s) => rt.test(s), "isModuleMock"), ue = /* @__PURE__ */ f((s, e, r) => {
|
|
148
|
+
let t = 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 a = i.object.name, l = P(a, e);
|
|
154
|
+
l && (r._templates[a] = l, t = l);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
return c.types.isArrowFunctionExpression(
|
|
157
|
+
return c.types.isArrowFunctionExpression(t) || c.types.isFunctionDeclaration(t) ? t.params.length > 0 : !1;
|
|
158
158
|
}, "isArgsStory"), et = /* @__PURE__ */ f((s) => {
|
|
159
159
|
if (c.types.isArrayExpression(s))
|
|
160
160
|
return s.elements.map((e) => {
|
|
@@ -163,21 +163,21 @@ var D = /* @__PURE__ */ f((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"),
|
|
167
|
-
(
|
|
168
|
-
let i = s[
|
|
169
|
-
return i && (t
|
|
166
|
+
}, "parseExportsOrder"), me = /* @__PURE__ */ f((s, e) => e.reduce(
|
|
167
|
+
(r, t) => {
|
|
168
|
+
let i = s[t];
|
|
169
|
+
return i && (r[t] = i), r;
|
|
170
170
|
},
|
|
171
171
|
{}
|
|
172
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) {
|
|
176
|
-
let [
|
|
177
|
-
if (c.types.isObjectPattern(
|
|
178
|
-
return !!
|
|
179
|
-
if (c.types.isObjectProperty(
|
|
180
|
-
return
|
|
176
|
+
let [r] = e;
|
|
177
|
+
if (c.types.isObjectPattern(r))
|
|
178
|
+
return !!r.properties.find((t) => {
|
|
179
|
+
if (c.types.isObjectProperty(t) && c.types.isIdentifier(t.key))
|
|
180
|
+
return t.key.name === "mount";
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -186,10 +186,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
186
186
|
static {
|
|
187
187
|
f(this, "NoMetaError");
|
|
188
188
|
}
|
|
189
|
-
constructor(e,
|
|
189
|
+
constructor(e, r, t) {
|
|
190
190
|
let i = "".trim();
|
|
191
191
|
super(O.dedent`
|
|
192
|
-
CSF: ${e} ${D(
|
|
192
|
+
CSF: ${e} ${D(r, t)}
|
|
193
193
|
|
|
194
194
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
195
195
|
`), this.name = this.constructor.name;
|
|
@@ -198,10 +198,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
198
198
|
static {
|
|
199
199
|
f(this, "MultipleMetaError");
|
|
200
200
|
}
|
|
201
|
-
constructor(e,
|
|
202
|
-
let i = `${e} ${D(
|
|
201
|
+
constructor(e, r, t) {
|
|
202
|
+
let i = `${e} ${D(r, t)}`.trim();
|
|
203
203
|
super(O.dedent`
|
|
204
|
-
CSF: ${e} ${D(
|
|
204
|
+
CSF: ${e} ${D(r, t)}
|
|
205
205
|
|
|
206
206
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
207
207
|
`), this.name = this.constructor.name;
|
|
@@ -210,10 +210,10 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
210
210
|
static {
|
|
211
211
|
f(this, "MixedFactoryError");
|
|
212
212
|
}
|
|
213
|
-
constructor(e,
|
|
214
|
-
let i = `${e} ${D(
|
|
213
|
+
constructor(e, r, t) {
|
|
214
|
+
let i = `${e} ${D(r, t)}`.trim();
|
|
215
215
|
super(O.dedent`
|
|
216
|
-
CSF: ${e} ${D(
|
|
216
|
+
CSF: ${e} ${D(r, t)}
|
|
217
217
|
|
|
218
218
|
More info: https://storybook.js.org/docs/writing-stories#default-export
|
|
219
219
|
`), this.name = this.constructor.name;
|
|
@@ -222,16 +222,16 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
222
222
|
static {
|
|
223
223
|
f(this, "BadMetaError");
|
|
224
224
|
}
|
|
225
|
-
constructor(e,
|
|
225
|
+
constructor(e, r, t) {
|
|
226
226
|
let i = "".trim();
|
|
227
227
|
super(O.dedent`
|
|
228
|
-
CSF: ${e} ${D(
|
|
228
|
+
CSF: ${e} ${D(r, t)}
|
|
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
|
-
constructor(e,
|
|
234
|
+
constructor(e, r, t) {
|
|
235
235
|
this._stories = {};
|
|
236
236
|
this._metaAnnotations = {};
|
|
237
237
|
this._storyExports = {};
|
|
@@ -239,91 +239,91 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
239
239
|
this._storyStatements = {};
|
|
240
240
|
this._storyAnnotations = {};
|
|
241
241
|
this._templates = {};
|
|
242
|
-
this._ast = e, this._file =
|
|
242
|
+
this._ast = e, this._file = t, this._options = r, this.imports = [];
|
|
243
243
|
}
|
|
244
244
|
static {
|
|
245
245
|
f(this, "CsfFile");
|
|
246
246
|
}
|
|
247
247
|
_parseTitle(e) {
|
|
248
|
-
let
|
|
249
|
-
if (c.types.isStringLiteral(
|
|
250
|
-
return
|
|
251
|
-
if (c.types.isTSSatisfiesExpression(
|
|
252
|
-
return
|
|
248
|
+
let r = c.types.isIdentifier(e) ? P(e.name, this._ast.program) : e;
|
|
249
|
+
if (c.types.isStringLiteral(r))
|
|
250
|
+
return r.value;
|
|
251
|
+
if (c.types.isTSSatisfiesExpression(r) && c.types.isStringLiteral(r.expression))
|
|
252
|
+
return r.expression.value;
|
|
253
253
|
throw new Error(O.dedent`
|
|
254
|
-
CSF: unexpected dynamic title ${D(
|
|
254
|
+
CSF: unexpected dynamic title ${D(r, this._options.fileName)}
|
|
255
255
|
|
|
256
256
|
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
257
257
|
`);
|
|
258
258
|
}
|
|
259
|
-
_parseMeta(e,
|
|
259
|
+
_parseMeta(e, r) {
|
|
260
260
|
if (this._metaNode)
|
|
261
261
|
throw new X("multiple meta objects", e, this._options.fileName);
|
|
262
262
|
this._metaNode = e;
|
|
263
|
-
let
|
|
263
|
+
let t = {};
|
|
264
264
|
e.properties.forEach((i) => {
|
|
265
265
|
if (c.types.isIdentifier(i.key)) {
|
|
266
266
|
if (this._metaAnnotations[i.key.name] = i.value, i.key.name === "title")
|
|
267
|
-
|
|
267
|
+
t.title = this._parseTitle(i.value);
|
|
268
268
|
else if (["includeStories", "excludeStories"].includes(i.key.name))
|
|
269
|
-
|
|
269
|
+
t[i.key.name] = Ze(i.value);
|
|
270
270
|
else if (i.key.name === "component") {
|
|
271
271
|
let o = i.value;
|
|
272
272
|
if (c.types.isIdentifier(o)) {
|
|
273
|
-
let
|
|
274
|
-
(
|
|
273
|
+
let l = o.name, p = r.body.find(
|
|
274
|
+
(d) => c.types.isImportDeclaration(d) && d.specifiers.find((g) => g.local.name === l)
|
|
275
275
|
);
|
|
276
276
|
if (p) {
|
|
277
|
-
let { source:
|
|
278
|
-
c.types.isStringLiteral(
|
|
277
|
+
let { source: d } = p;
|
|
278
|
+
c.types.isStringLiteral(d) && (this._rawComponentPath = d.value);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
let { code:
|
|
282
|
-
|
|
281
|
+
let { code: a } = c.recast.print(i.value, {});
|
|
282
|
+
t.component = a;
|
|
283
283
|
} else if (i.key.name === "tags") {
|
|
284
284
|
let o = i.value;
|
|
285
|
-
c.types.isIdentifier(o) && (o = P(o.name, this._ast.program)),
|
|
285
|
+
c.types.isIdentifier(o) && (o = P(o.name, this._ast.program)), t.tags = de(o);
|
|
286
286
|
} else if (i.key.name === "id")
|
|
287
287
|
if (c.types.isStringLiteral(i.value))
|
|
288
|
-
|
|
288
|
+
t.id = i.value.value;
|
|
289
289
|
else
|
|
290
290
|
throw new Error(`Unexpected component id: ${i.value}`);
|
|
291
291
|
}
|
|
292
|
-
}), this._meta =
|
|
292
|
+
}), this._meta = t;
|
|
293
293
|
}
|
|
294
294
|
getStoryExport(e) {
|
|
295
|
-
let
|
|
296
|
-
if (
|
|
297
|
-
let { callee:
|
|
298
|
-
if (c.types.isMemberExpression(
|
|
295
|
+
let r = this._storyExports[e];
|
|
296
|
+
if (r = c.types.isVariableDeclarator(r) ? r.init : r, c.types.isCallExpression(r)) {
|
|
297
|
+
let { callee: t, arguments: i } = r;
|
|
298
|
+
if (c.types.isMemberExpression(t) && c.types.isIdentifier(t.object) && c.types.isIdentifier(t.property) && t.property.name === "bind" &&
|
|
299
299
|
(i.length === 0 || i.length === 1 && c.types.isObjectExpression(i[0]) && i[0].properties.length === 0)) {
|
|
300
|
-
let { name: o } =
|
|
301
|
-
|
|
300
|
+
let { name: o } = t.object;
|
|
301
|
+
r = this._templates[o];
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
|
-
return
|
|
304
|
+
return r;
|
|
305
305
|
}
|
|
306
306
|
parse() {
|
|
307
307
|
let e = this;
|
|
308
308
|
if ((0, c.traverse)(this._ast, {
|
|
309
309
|
ExportDefaultDeclaration: {
|
|
310
|
-
enter(
|
|
311
|
-
let { node: i, parent: o } =
|
|
312
|
-
if (e._options.transformInlineMeta && !
|
|
313
|
-
let
|
|
314
|
-
e._metaVariableName =
|
|
310
|
+
enter(t) {
|
|
311
|
+
let { node: i, parent: o } = t, a = c.types.isIdentifier(i.declaration) && c.types.isProgram(o);
|
|
312
|
+
if (e._options.transformInlineMeta && !a && c.types.isExpression(i.declaration)) {
|
|
313
|
+
let d = t.scope.generateUidIdentifier("meta");
|
|
314
|
+
e._metaVariableName = d.name;
|
|
315
315
|
let g = [
|
|
316
|
-
c.types.variableDeclaration("const", [c.types.variableDeclarator(
|
|
317
|
-
c.types.exportDefaultDeclaration(
|
|
316
|
+
c.types.variableDeclaration("const", [c.types.variableDeclarator(d, i.declaration)]),
|
|
317
|
+
c.types.exportDefaultDeclaration(d)
|
|
318
318
|
];
|
|
319
|
-
g.forEach((x) => x.loc =
|
|
319
|
+
g.forEach((x) => x.loc = t.node.loc), t.replaceWithMultiple(g);
|
|
320
320
|
return;
|
|
321
321
|
}
|
|
322
|
-
let
|
|
323
|
-
if (
|
|
324
|
-
let
|
|
325
|
-
e._metaVariableName =
|
|
326
|
-
let g = /* @__PURE__ */ f((x) => c.types.isIdentifier(x.id) && x.id.name ===
|
|
322
|
+
let l, p;
|
|
323
|
+
if (a) {
|
|
324
|
+
let d = i.declaration.name;
|
|
325
|
+
e._metaVariableName = d;
|
|
326
|
+
let g = /* @__PURE__ */ f((x) => c.types.isIdentifier(x.id) && x.id.name === d, "isVariableDeclarator");
|
|
327
327
|
e._metaStatement = e._ast.program.body.find(
|
|
328
328
|
(x) => c.types.isVariableDeclaration(x) && x.declarations.find(g)
|
|
329
329
|
), p = (e?._metaStatement?.declarations || []).find(
|
|
@@ -331,37 +331,37 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
331
331
|
)?.init;
|
|
332
332
|
} else
|
|
333
333
|
e._metaStatement = i, p = i.declaration;
|
|
334
|
-
if (c.types.isObjectExpression(p) ?
|
|
334
|
+
if (c.types.isObjectExpression(p) ? l = p : (
|
|
335
335
|
// export default { ... } as Meta<...>
|
|
336
|
-
(c.types.isTSAsExpression(p) || c.types.isTSSatisfiesExpression(p)) && c.types.isObjectExpression(p.expression) && (
|
|
337
|
-
),
|
|
336
|
+
(c.types.isTSAsExpression(p) || c.types.isTSSatisfiesExpression(p)) && c.types.isObjectExpression(p.expression) && (l = p.expression)
|
|
337
|
+
), l && c.types.isProgram(o) && e._parseMeta(l, o), e._metaStatement && !e._metaNode)
|
|
338
338
|
throw new L(
|
|
339
339
|
"default export must be an object",
|
|
340
340
|
e._metaStatement,
|
|
341
341
|
e._options.fileName
|
|
342
342
|
);
|
|
343
|
-
e._metaPath =
|
|
343
|
+
e._metaPath = t;
|
|
344
344
|
}
|
|
345
345
|
},
|
|
346
346
|
ExportNamedDeclaration: {
|
|
347
|
-
enter(
|
|
348
|
-
let { node: i, parent: o } =
|
|
349
|
-
c.types.isVariableDeclaration(i.declaration) ?
|
|
350
|
-
isFunctionDeclaration(i.declaration) && (
|
|
351
|
-
if (c.types.isIdentifier(
|
|
352
|
-
let p = !1, { name:
|
|
353
|
-
if (
|
|
354
|
-
e._namedExportsOrder = et(
|
|
347
|
+
enter(t) {
|
|
348
|
+
let { node: i, parent: o } = t, a;
|
|
349
|
+
c.types.isVariableDeclaration(i.declaration) ? a = i.declaration.declarations.filter((l) => c.types.isVariableDeclarator(l)) : c.types.
|
|
350
|
+
isFunctionDeclaration(i.declaration) && (a = [i.declaration]), a ? a.forEach((l) => {
|
|
351
|
+
if (c.types.isIdentifier(l.id)) {
|
|
352
|
+
let p = !1, { name: d } = l.id;
|
|
353
|
+
if (d === "__namedExportsOrder" && c.types.isVariableDeclarator(l)) {
|
|
354
|
+
e._namedExportsOrder = et(l.init);
|
|
355
355
|
return;
|
|
356
356
|
}
|
|
357
|
-
e._storyExports[
|
|
358
|
-
let g = (0,
|
|
359
|
-
e._storyAnnotations[
|
|
360
|
-
`Unexpected annotations for "${
|
|
361
|
-
) : e._storyAnnotations[
|
|
357
|
+
e._storyExports[d] = l, e._storyPaths[d] = t, e._storyStatements[d] = i;
|
|
358
|
+
let g = (0, v.storyNameFromExport)(d);
|
|
359
|
+
e._storyAnnotations[d] ? fe.warn(
|
|
360
|
+
`Unexpected annotations for "${d}" before story declaration`
|
|
361
|
+
) : e._storyAnnotations[d] = {};
|
|
362
362
|
let x;
|
|
363
|
-
if (c.types.isVariableDeclarator(
|
|
364
|
-
expression :
|
|
363
|
+
if (c.types.isVariableDeclarator(l) ? x = c.types.isTSAsExpression(l.init) || c.types.isTSSatisfiesExpression(l.init) ? l.init.
|
|
364
|
+
expression : l.init : x = l, c.types.isCallExpression(x) && c.types.isMemberExpression(x.callee) && c.types.isIdentifier(x.callee.
|
|
365
365
|
property) && x.callee.property.name === "story" && (p = !0, x = x.arguments[0]), e._metaIsFactory && !p)
|
|
366
366
|
throw new M(
|
|
367
367
|
"expected factory story",
|
|
@@ -378,11 +378,11 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
378
378
|
x,
|
|
379
379
|
e._options.fileName
|
|
380
380
|
);
|
|
381
|
-
let
|
|
382
|
-
c.types.isObjectExpression(x) ? (
|
|
381
|
+
let h = {};
|
|
382
|
+
c.types.isObjectExpression(x) ? (h.__isArgsStory = !0, x.properties.forEach((b) => {
|
|
383
383
|
if (c.types.isIdentifier(b.key)) {
|
|
384
384
|
if (b.key.name === "render")
|
|
385
|
-
|
|
385
|
+
h.__isArgsStory = ue(
|
|
386
386
|
b.value,
|
|
387
387
|
o,
|
|
388
388
|
e
|
|
@@ -391,66 +391,70 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
391
391
|
g = b.value.value;
|
|
392
392
|
else if (b.key.name === "storyName" && c.types.isStringLiteral(b.value))
|
|
393
393
|
fe.warn(
|
|
394
|
-
`Unexpected usage of "storyName" in "${
|
|
394
|
+
`Unexpected usage of "storyName" in "${d}". Please use "name" instead.`
|
|
395
395
|
);
|
|
396
396
|
else if (b.key.name === "parameters" && c.types.isObjectExpression(b.value)) {
|
|
397
|
-
let
|
|
398
|
-
(
|
|
397
|
+
let E = b.value.properties.find(
|
|
398
|
+
(I) => c.types.isObjectProperty(I) && c.types.isIdentifier(I.key) && I.key.name === "__id"
|
|
399
399
|
);
|
|
400
|
-
|
|
400
|
+
E && (h.__id = E.value.value);
|
|
401
401
|
}
|
|
402
|
-
e._storyAnnotations[
|
|
402
|
+
e._storyAnnotations[d][b.key.name] = b.value;
|
|
403
403
|
}
|
|
404
|
-
})) :
|
|
404
|
+
})) : h.__isArgsStory = ue(x, o, e), e._stories[d] = {
|
|
405
405
|
id: "FIXME",
|
|
406
406
|
name: g,
|
|
407
|
-
parameters:
|
|
407
|
+
parameters: h,
|
|
408
408
|
__stats: {
|
|
409
409
|
factory: p
|
|
410
410
|
}
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
-
}) : i.specifiers.length > 0 && i.specifiers.forEach((
|
|
414
|
-
if (c.types.isExportSpecifier(
|
|
415
|
-
let { name: p } =
|
|
413
|
+
}) : i.specifiers.length > 0 && i.specifiers.forEach((l) => {
|
|
414
|
+
if (c.types.isExportSpecifier(l) && c.types.isIdentifier(l.exported)) {
|
|
415
|
+
let { name: p } = l.exported, { name: d } = l.local, g = c.types.isProgram(o) ? P(d, o) : l.local;
|
|
416
416
|
if (p === "default") {
|
|
417
417
|
let x;
|
|
418
418
|
c.types.isObjectExpression(g) ? x = g : (
|
|
419
419
|
// export default { ... } as Meta<...>
|
|
420
420
|
c.types.isTSAsExpression(g) && c.types.isObjectExpression(g.expression) && (x = g.expression)
|
|
421
421
|
), x && c.types.isProgram(o) && e._parseMeta(x, o);
|
|
422
|
-
} else
|
|
423
|
-
|
|
422
|
+
} else {
|
|
423
|
+
let x = {}, h = g;
|
|
424
|
+
c.types.isObjectExpression(h) && h.properties.forEach((b) => {
|
|
425
|
+
c.types.isIdentifier(b.key) && (x[b.key.name] = b.value);
|
|
426
|
+
}), e._storyAnnotations[p] = x, e._storyStatements[p] = g, e._storyPaths[p] = t, e._stories[p] = {
|
|
424
427
|
id: "FIXME",
|
|
425
428
|
name: p,
|
|
426
|
-
localName:
|
|
429
|
+
localName: d,
|
|
427
430
|
parameters: {},
|
|
428
431
|
__stats: {}
|
|
429
432
|
};
|
|
433
|
+
}
|
|
430
434
|
}
|
|
431
435
|
});
|
|
432
436
|
}
|
|
433
437
|
},
|
|
434
438
|
ExpressionStatement: {
|
|
435
|
-
enter({ node:
|
|
436
|
-
let { expression: o } =
|
|
439
|
+
enter({ node: t, parent: i }) {
|
|
440
|
+
let { expression: o } = t;
|
|
437
441
|
if (c.types.isProgram(i) && c.types.isAssignmentExpression(o) && c.types.isMemberExpression(o.left) && c.types.isIdentifier(o.left.
|
|
438
442
|
object) && c.types.isIdentifier(o.left.property)) {
|
|
439
|
-
let
|
|
440
|
-
if (e._storyAnnotations[
|
|
441
|
-
c.types.isIdentifier(
|
|
442
|
-
}) : e._storyAnnotations[
|
|
443
|
-
let
|
|
443
|
+
let a = o.left.object.name, l = o.left.property.name, p = o.right;
|
|
444
|
+
if (e._storyAnnotations[a] && (l === "story" && c.types.isObjectExpression(p) ? p.properties.forEach((d) => {
|
|
445
|
+
c.types.isIdentifier(d.key) && (e._storyAnnotations[a][d.key.name] = d.value);
|
|
446
|
+
}) : e._storyAnnotations[a][l] = p), l === "storyName" && c.types.isStringLiteral(p)) {
|
|
447
|
+
let d = p.value, g = e._stories[a];
|
|
444
448
|
if (!g)
|
|
445
449
|
return;
|
|
446
|
-
g.name =
|
|
450
|
+
g.name = d;
|
|
447
451
|
}
|
|
448
452
|
}
|
|
449
453
|
}
|
|
450
454
|
},
|
|
451
455
|
CallExpression: {
|
|
452
|
-
enter(
|
|
453
|
-
let { node: i } =
|
|
456
|
+
enter(t) {
|
|
457
|
+
let { node: i } = t, { callee: o } = i;
|
|
454
458
|
if (c.types.isIdentifier(o) && o.name === "storiesOf")
|
|
455
459
|
throw new Error(O.dedent`
|
|
456
460
|
Unexpected \`storiesOf\` usage: ${D(i, e._options.fileName)}.
|
|
@@ -459,23 +463,23 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
459
463
|
`);
|
|
460
464
|
if (c.types.isMemberExpression(o) && c.types.isIdentifier(o.property) && o.property.name === "meta" && c.types.isIdentifier(o.object) &&
|
|
461
465
|
i.arguments.length > 0) {
|
|
462
|
-
let
|
|
463
|
-
if (c.types.isImportDeclaration(
|
|
464
|
-
if (ge(
|
|
466
|
+
let l = t.scope.getBinding(o.object.name)?.path?.parentPath?.node;
|
|
467
|
+
if (c.types.isImportDeclaration(l))
|
|
468
|
+
if (ge(l.source.value)) {
|
|
465
469
|
let p = i.arguments[0];
|
|
466
470
|
e._metaVariableName = o.property.name, e._metaIsFactory = !0, e._parseMeta(p, e._ast.program);
|
|
467
471
|
} else
|
|
468
472
|
throw new U(
|
|
469
473
|
"meta() factory must be imported from .storybook/preview configuration",
|
|
470
|
-
|
|
474
|
+
l,
|
|
471
475
|
e._options.fileName
|
|
472
476
|
);
|
|
473
477
|
}
|
|
474
478
|
}
|
|
475
479
|
},
|
|
476
480
|
ImportDeclaration: {
|
|
477
|
-
enter({ node:
|
|
478
|
-
let { source: i } =
|
|
481
|
+
enter({ node: t }) {
|
|
482
|
+
let { source: i } = t;
|
|
479
483
|
if (c.types.isStringLiteral(i))
|
|
480
484
|
e.imports.push(i.value);
|
|
481
485
|
else
|
|
@@ -484,39 +488,39 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
484
488
|
}
|
|
485
489
|
}), !e._meta)
|
|
486
490
|
throw new L("missing default export", e._ast, e._options.fileName);
|
|
487
|
-
let
|
|
491
|
+
let r = Object.entries(e._stories);
|
|
488
492
|
if (e._meta.title = this._options.makeTitle(e._meta?.title), e._metaAnnotations.play && (e._meta.tags = [...e._meta.tags || [], "play-fn"]),
|
|
489
|
-
e._stories =
|
|
490
|
-
(
|
|
491
|
-
if (!(0,
|
|
492
|
-
return
|
|
493
|
-
let
|
|
493
|
+
e._stories = r.reduce(
|
|
494
|
+
(t, [i, o]) => {
|
|
495
|
+
if (!(0, v.isExportStory)(i, e._meta))
|
|
496
|
+
return t;
|
|
497
|
+
let a = o.parameters?.__id ?? (0, v.toId)(e._meta?.id || e._meta?.title, (0, v.storyNameFromExport)(i)), l = { ...o.parameters, __id: a },
|
|
494
498
|
{ includeStories: p } = e._meta || {};
|
|
495
|
-
i === "__page" && (
|
|
496
|
-
let
|
|
499
|
+
i === "__page" && (r.length === 1 || Array.isArray(p) && p.length === 1) && (l.docsOnly = !0), t[i] = { ...o, id: a, parameters: l };
|
|
500
|
+
let d = e._storyAnnotations[i], { tags: g, play: x } = d;
|
|
497
501
|
if (g) {
|
|
498
|
-
let
|
|
499
|
-
|
|
502
|
+
let E = c.types.isIdentifier(g) ? P(g.name, this._ast.program) : g;
|
|
503
|
+
t[i].tags = de(E);
|
|
500
504
|
}
|
|
501
|
-
x && (
|
|
502
|
-
let
|
|
503
|
-
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((
|
|
504
|
-
E
|
|
505
|
+
x && (t[i].tags = [...t[i].tags || [], "play-fn"]);
|
|
506
|
+
let h = t[i].__stats;
|
|
507
|
+
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((E) => {
|
|
508
|
+
h[E] = !!d[E] || !!e._metaAnnotations[E];
|
|
505
509
|
});
|
|
506
510
|
let b = e.getStoryExport(i);
|
|
507
|
-
return
|
|
508
|
-
play),
|
|
511
|
+
return h.storyFn = !!(c.types.isArrowFunctionExpression(b) || c.types.isFunctionDeclaration(b)), h.mount = tt(d.play ?? e._metaAnnotations.
|
|
512
|
+
play), h.moduleMock = !!e.imports.find((E) => xe(E)), t;
|
|
509
513
|
},
|
|
510
514
|
{}
|
|
511
|
-
), Object.keys(e._storyExports).forEach((
|
|
512
|
-
(0,
|
|
515
|
+
), Object.keys(e._storyExports).forEach((t) => {
|
|
516
|
+
(0, v.isExportStory)(t, e._meta) || (delete e._storyExports[t], delete e._storyAnnotations[t], delete e._storyStatements[t]);
|
|
513
517
|
}), e._namedExportsOrder) {
|
|
514
|
-
let
|
|
515
|
-
e._storyExports =
|
|
518
|
+
let t = Object.keys(e._storyExports);
|
|
519
|
+
e._storyExports = me(e._storyExports, e._namedExportsOrder), e._stories = me(e._stories, e._namedExportsOrder);
|
|
516
520
|
let i = Object.keys(e._storyExports);
|
|
517
|
-
if (
|
|
521
|
+
if (t.length !== i.length)
|
|
518
522
|
throw new Error(
|
|
519
|
-
`Missing exports after sort: ${
|
|
523
|
+
`Missing exports after sort: ${t.filter(
|
|
520
524
|
(o) => !i.includes(o)
|
|
521
525
|
)}`
|
|
522
526
|
);
|
|
@@ -536,35 +540,35 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
536
540
|
O.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
537
541
|
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
538
542
|
);
|
|
539
|
-
return Object.entries(this._stories).map(([
|
|
540
|
-
let i = [...this._meta?.tags ?? [], ...
|
|
543
|
+
return Object.entries(this._stories).map(([r, t]) => {
|
|
544
|
+
let i = [...this._meta?.tags ?? [], ...t.tags ?? []];
|
|
541
545
|
return {
|
|
542
546
|
type: "story",
|
|
543
547
|
importPath: e,
|
|
544
548
|
rawComponentPath: this._rawComponentPath,
|
|
545
|
-
exportName:
|
|
546
|
-
name:
|
|
549
|
+
exportName: r,
|
|
550
|
+
name: t.name,
|
|
547
551
|
title: this.meta?.title,
|
|
548
552
|
metaId: this.meta?.id,
|
|
549
553
|
tags: i,
|
|
550
|
-
__id:
|
|
551
|
-
__stats:
|
|
554
|
+
__id: t.id,
|
|
555
|
+
__stats: t.__stats
|
|
552
556
|
};
|
|
553
557
|
});
|
|
554
558
|
}
|
|
555
559
|
}, ye = /* @__PURE__ */ f(({
|
|
556
560
|
code: s,
|
|
557
561
|
filename: e = "",
|
|
558
|
-
ast:
|
|
559
|
-
}) => new c.BabelFileClass({ filename: e }, { code: s, ast:
|
|
560
|
-
let
|
|
561
|
-
return new K(
|
|
562
|
-
}, "loadCsf"), te = /* @__PURE__ */ f((s, e = { sourceMaps: !1 },
|
|
563
|
-
let
|
|
564
|
-
return e.sourceMaps ?
|
|
562
|
+
ast: r
|
|
563
|
+
}) => new c.BabelFileClass({ filename: e }, { code: s, ast: r ?? (0, c.babelParse)(s) }), "babelParseFile"), Q = /* @__PURE__ */ f((s, e) => {
|
|
564
|
+
let r = (0, c.babelParse)(s), t = ye({ code: s, filename: e.fileName, ast: r });
|
|
565
|
+
return new K(r, e, t);
|
|
566
|
+
}, "loadCsf"), te = /* @__PURE__ */ f((s, e = { sourceMaps: !1 }, r) => {
|
|
567
|
+
let t = (0, c.generate)(s._ast, e, r);
|
|
568
|
+
return e.sourceMaps ? t : t.code;
|
|
565
569
|
}, "formatCsf"), be = /* @__PURE__ */ f((s, e = {}) => c.recast.print(s._ast, e), "printCsf"), it = /* @__PURE__ */ f(async (s, e) => {
|
|
566
|
-
let
|
|
567
|
-
return Q(
|
|
570
|
+
let r = (await (0, J.readFile)(s, "utf-8")).toString();
|
|
571
|
+
return Q(r, { ...e, fileName: s });
|
|
568
572
|
}, "readCsf"), st = /* @__PURE__ */ f(async (s, e) => {
|
|
569
573
|
if (!(e || s._options.fileName))
|
|
570
574
|
throw new Error("Please specify a fileName for writeCsf");
|
|
@@ -572,22 +576,22 @@ var D = /* @__PURE__ */ f((s, e) => {
|
|
|
572
576
|
}, "writeCsf");
|
|
573
577
|
|
|
574
578
|
// src/csf-tools/ConfigFile.ts
|
|
575
|
-
var ee = require("node:fs/promises"), n = require("storybook/internal/babel"),
|
|
579
|
+
var ee = require("node:fs/promises"), n = require("storybook/internal/babel"), he = z(R(), 1);
|
|
576
580
|
var re = console, ie = /* @__PURE__ */ f(({
|
|
577
581
|
expectedType: s,
|
|
578
582
|
foundType: e,
|
|
579
|
-
node:
|
|
580
|
-
}) =>
|
|
581
|
-
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${
|
|
583
|
+
node: r
|
|
584
|
+
}) => he.dedent`
|
|
585
|
+
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${r?.type}'.
|
|
582
586
|
`, "getCsfParsingErrorMessage"), C = /* @__PURE__ */ f((s) => n.types.isIdentifier(s.key) ? s.key.name : n.types.isStringLiteral(s.key) ?
|
|
583
587
|
s.key.value : null, "propKey"), H = /* @__PURE__ */ f((s) => n.types.isTSAsExpression(s) || n.types.isTSSatisfiesExpression(s) ? H(s.expression) :
|
|
584
|
-
s, "unwrap"),
|
|
588
|
+
s, "unwrap"), Ee = /* @__PURE__ */ f((s, e) => {
|
|
585
589
|
if (s.length === 0)
|
|
586
590
|
return e;
|
|
587
591
|
if (n.types.isObjectExpression(e)) {
|
|
588
|
-
let [
|
|
592
|
+
let [r, ...t] = s, i = e.properties.find((o) => C(o) === r);
|
|
589
593
|
if (i)
|
|
590
|
-
return
|
|
594
|
+
return Ee(t, i.value);
|
|
591
595
|
}
|
|
592
596
|
}, "_getPath"), _e = /* @__PURE__ */ f((s, e) => {
|
|
593
597
|
if (s.length === 0) {
|
|
@@ -596,46 +600,46 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
596
600
|
throw new Error("Expected object expression");
|
|
597
601
|
}
|
|
598
602
|
if (n.types.isObjectExpression(e)) {
|
|
599
|
-
let [
|
|
603
|
+
let [r, ...t] = s, i = e.properties.find((o) => C(o) === r);
|
|
600
604
|
if (i)
|
|
601
|
-
return
|
|
605
|
+
return t.length === 0 ? e.properties : _e(t, i.value);
|
|
602
606
|
}
|
|
603
607
|
}, "_getPathProperties"), Y = /* @__PURE__ */ f((s, e) => {
|
|
604
|
-
let
|
|
605
|
-
return e.body.find((i) => (n.types.isVariableDeclaration(i) ?
|
|
606
|
-
i.declaration) && (
|
|
607
|
-
id.name === s ? (
|
|
608
|
+
let r = null, t = null;
|
|
609
|
+
return e.body.find((i) => (n.types.isVariableDeclaration(i) ? t = i.declarations : n.types.isExportNamedDeclaration(i) && n.types.isVariableDeclaration(
|
|
610
|
+
i.declaration) && (t = i.declaration.declarations), t && t.find((o) => n.types.isVariableDeclarator(o) && n.types.isIdentifier(o.id) && o.
|
|
611
|
+
id.name === s ? (r = o, !0) : !1))), r;
|
|
608
612
|
}, "_findVarDeclarator"), F = /* @__PURE__ */ f((s, e) => Y(s, e)?.init, "_findVarInitialization"), B = /* @__PURE__ */ f((s, e) => {
|
|
609
613
|
if (s.length === 0)
|
|
610
614
|
return e;
|
|
611
|
-
let [
|
|
612
|
-
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(
|
|
613
|
-
}, "_makeObjectExpression"), q = /* @__PURE__ */ f((s, e,
|
|
614
|
-
let [
|
|
615
|
-
(
|
|
615
|
+
let [r, ...t] = s, i = B(t, e);
|
|
616
|
+
return n.types.objectExpression([n.types.objectProperty(n.types.identifier(r), i)]);
|
|
617
|
+
}, "_makeObjectExpression"), q = /* @__PURE__ */ f((s, e, r) => {
|
|
618
|
+
let [t, ...i] = s, o = r.properties.find(
|
|
619
|
+
(a) => C(a) === t
|
|
616
620
|
);
|
|
617
|
-
o ? n.types.isObjectExpression(o.value) && i.length > 0 ? q(i, e, o.value) : o.value = B(i, e) :
|
|
618
|
-
n.types.objectProperty(n.types.identifier(
|
|
621
|
+
o ? n.types.isObjectExpression(o.value) && i.length > 0 ? q(i, e, o.value) : o.value = B(i, e) : r.properties.push(
|
|
622
|
+
n.types.objectProperty(n.types.identifier(t), B(i, e))
|
|
619
623
|
);
|
|
620
624
|
}, "_updateExportNode"), Z = class {
|
|
621
|
-
constructor(e,
|
|
625
|
+
constructor(e, r, t) {
|
|
622
626
|
this._exports = {};
|
|
623
627
|
// FIXME: this is a hack. this is only used in the case where the user is
|
|
624
628
|
// modifying a named export that's a scalar. The _exports map is not suitable
|
|
625
629
|
// for that. But rather than refactor the whole thing, we just use this as a stopgap.
|
|
626
630
|
this._exportDecls = {};
|
|
627
631
|
this.hasDefaultExport = !1;
|
|
628
|
-
this._ast = e, this._code =
|
|
632
|
+
this._ast = e, this._code = r, this.fileName = t;
|
|
629
633
|
}
|
|
630
634
|
static {
|
|
631
635
|
f(this, "ConfigFile");
|
|
632
636
|
}
|
|
633
637
|
_parseExportsObject(e) {
|
|
634
|
-
this._exportsObject = e, e.properties.forEach((
|
|
635
|
-
let
|
|
636
|
-
if (
|
|
637
|
-
let i =
|
|
638
|
-
n.types.isIdentifier(i) && (i = F(i.name, this._ast.program)), this._exports[
|
|
638
|
+
this._exportsObject = e, e.properties.forEach((r) => {
|
|
639
|
+
let t = C(r);
|
|
640
|
+
if (t) {
|
|
641
|
+
let i = r.value;
|
|
642
|
+
n.types.isIdentifier(i) && (i = F(i.name, this._ast.program)), this._exports[t] = i;
|
|
639
643
|
}
|
|
640
644
|
});
|
|
641
645
|
}
|
|
@@ -643,70 +647,70 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
643
647
|
let e = this;
|
|
644
648
|
return (0, n.traverse)(this._ast, {
|
|
645
649
|
ExportDefaultDeclaration: {
|
|
646
|
-
enter({ node:
|
|
650
|
+
enter({ node: r, parent: t }) {
|
|
647
651
|
e.hasDefaultExport = !0;
|
|
648
|
-
let i = n.types.isIdentifier(
|
|
652
|
+
let i = n.types.isIdentifier(r.declaration) && n.types.isProgram(t) ? F(r.declaration.name, t) : r.declaration;
|
|
649
653
|
i = H(i), n.types.isCallExpression(i) && n.types.isObjectExpression(i.arguments[0]) && (i = i.arguments[0]), n.types.isObjectExpression(
|
|
650
654
|
i) ? e._parseExportsObject(i) : re.warn(
|
|
651
655
|
ie({
|
|
652
656
|
expectedType: "ObjectExpression",
|
|
653
657
|
foundType: i?.type,
|
|
654
|
-
node: i ||
|
|
658
|
+
node: i || r.declaration
|
|
655
659
|
})
|
|
656
660
|
);
|
|
657
661
|
}
|
|
658
662
|
},
|
|
659
663
|
ExportNamedDeclaration: {
|
|
660
|
-
enter({ node:
|
|
661
|
-
if (n.types.isVariableDeclaration(
|
|
662
|
-
|
|
664
|
+
enter({ node: r, parent: t }) {
|
|
665
|
+
if (n.types.isVariableDeclaration(r.declaration))
|
|
666
|
+
r.declaration.declarations.forEach((i) => {
|
|
663
667
|
if (n.types.isVariableDeclarator(i) && n.types.isIdentifier(i.id)) {
|
|
664
|
-
let { name: o } = i.id,
|
|
665
|
-
n.types.isIdentifier(
|
|
668
|
+
let { name: o } = i.id, a = i.init;
|
|
669
|
+
n.types.isIdentifier(a) && (a = F(a.name, t)), e._exports[o] = a, e._exportDecls[o] = i;
|
|
666
670
|
}
|
|
667
671
|
});
|
|
668
|
-
else if (n.types.isFunctionDeclaration(
|
|
669
|
-
let i =
|
|
672
|
+
else if (n.types.isFunctionDeclaration(r.declaration)) {
|
|
673
|
+
let i = r.declaration;
|
|
670
674
|
if (n.types.isIdentifier(i.id)) {
|
|
671
675
|
let { name: o } = i.id;
|
|
672
676
|
e._exportDecls[o] = i;
|
|
673
677
|
}
|
|
674
|
-
} else
|
|
678
|
+
} else r.specifiers ? r.specifiers.forEach((i) => {
|
|
675
679
|
if (n.types.isExportSpecifier(i) && n.types.isIdentifier(i.local) && n.types.isIdentifier(i.exported)) {
|
|
676
|
-
let { name: o } = i.local, { name:
|
|
677
|
-
|
|
680
|
+
let { name: o } = i.local, { name: a } = i.exported, l = Y(o, t);
|
|
681
|
+
l && (e._exports[a] = l.init, e._exportDecls[a] = l);
|
|
678
682
|
}
|
|
679
683
|
}) : re.warn(
|
|
680
684
|
ie({
|
|
681
685
|
expectedType: "VariableDeclaration",
|
|
682
|
-
foundType:
|
|
683
|
-
node:
|
|
686
|
+
foundType: r.declaration?.type,
|
|
687
|
+
node: r.declaration
|
|
684
688
|
})
|
|
685
689
|
);
|
|
686
690
|
}
|
|
687
691
|
},
|
|
688
692
|
ExpressionStatement: {
|
|
689
|
-
enter({ node:
|
|
690
|
-
if (n.types.isAssignmentExpression(
|
|
691
|
-
let { left: i, right: o } =
|
|
693
|
+
enter({ node: r, parent: t }) {
|
|
694
|
+
if (n.types.isAssignmentExpression(r.expression) && r.expression.operator === "=") {
|
|
695
|
+
let { left: i, right: o } = r.expression;
|
|
692
696
|
if (n.types.isMemberExpression(i) && n.types.isIdentifier(i.object) && i.object.name === "module" && n.types.isIdentifier(i.property) &&
|
|
693
697
|
i.property.name === "exports") {
|
|
694
|
-
let
|
|
695
|
-
n.types.isIdentifier(o) && (
|
|
696
|
-
(
|
|
697
|
-
let p = C(
|
|
698
|
+
let a = o;
|
|
699
|
+
n.types.isIdentifier(o) && (a = F(o.name, t)), a = H(a), n.types.isObjectExpression(a) ? (e._exportsObject = a, a.properties.forEach(
|
|
700
|
+
(l) => {
|
|
701
|
+
let p = C(l);
|
|
698
702
|
if (p) {
|
|
699
|
-
let
|
|
700
|
-
n.types.isIdentifier(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
)), e._exports[p] =
|
|
703
|
+
let d = l.value;
|
|
704
|
+
n.types.isIdentifier(d) && (d = F(
|
|
705
|
+
d.name,
|
|
706
|
+
t
|
|
707
|
+
)), e._exports[p] = d;
|
|
704
708
|
}
|
|
705
709
|
})) : re.warn(
|
|
706
710
|
ie({
|
|
707
711
|
expectedType: "ObjectExpression",
|
|
708
|
-
foundType:
|
|
709
|
-
node:
|
|
712
|
+
foundType: a?.type,
|
|
713
|
+
node: a
|
|
710
714
|
})
|
|
711
715
|
);
|
|
712
716
|
}
|
|
@@ -714,28 +718,28 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
714
718
|
}
|
|
715
719
|
},
|
|
716
720
|
CallExpression: {
|
|
717
|
-
enter: /* @__PURE__ */ f(({ node:
|
|
718
|
-
n.types.isIdentifier(
|
|
719
|
-
e._parseExportsObject(
|
|
721
|
+
enter: /* @__PURE__ */ f(({ node: r }) => {
|
|
722
|
+
n.types.isIdentifier(r.callee) && r.callee.name === "definePreview" && r.arguments.length === 1 && n.types.isObjectExpression(r.arguments[0]) &&
|
|
723
|
+
e._parseExportsObject(r.arguments[0]);
|
|
720
724
|
}, "enter")
|
|
721
725
|
}
|
|
722
726
|
}), e;
|
|
723
727
|
}
|
|
724
728
|
getFieldNode(e) {
|
|
725
|
-
let [
|
|
729
|
+
let [r, ...t] = e, i = this._exports[r];
|
|
726
730
|
if (i)
|
|
727
|
-
return
|
|
731
|
+
return Ee(t, i);
|
|
728
732
|
}
|
|
729
733
|
getFieldProperties(e) {
|
|
730
|
-
let [
|
|
734
|
+
let [r, ...t] = e, i = this._exports[r];
|
|
731
735
|
if (i)
|
|
732
|
-
return _e(
|
|
736
|
+
return _e(t, i);
|
|
733
737
|
}
|
|
734
738
|
getFieldValue(e) {
|
|
735
|
-
let
|
|
736
|
-
if (
|
|
737
|
-
let { code:
|
|
738
|
-
return (0, eval)(`(() => (${
|
|
739
|
+
let r = this.getFieldNode(e);
|
|
740
|
+
if (r) {
|
|
741
|
+
let { code: t } = (0, n.generate)(r, {});
|
|
742
|
+
return (0, eval)(`(() => (${t}))()`);
|
|
739
743
|
}
|
|
740
744
|
}
|
|
741
745
|
getSafeFieldValue(e) {
|
|
@@ -744,32 +748,32 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
744
748
|
} catch {
|
|
745
749
|
}
|
|
746
750
|
}
|
|
747
|
-
setFieldNode(e,
|
|
748
|
-
let [
|
|
751
|
+
setFieldNode(e, r) {
|
|
752
|
+
let [t, ...i] = e, o = this._exports[t];
|
|
749
753
|
if (this._exportsObject) {
|
|
750
|
-
let p = this._exportsObject.properties.find((
|
|
754
|
+
let p = this._exportsObject.properties.find((d) => C(d) === t);
|
|
751
755
|
if (p && n.types.isIdentifier(p.value)) {
|
|
752
|
-
let
|
|
753
|
-
if (
|
|
754
|
-
q(i,
|
|
756
|
+
let d = Y(p.value.name, this._ast.program);
|
|
757
|
+
if (d && n.types.isObjectExpression(d.init)) {
|
|
758
|
+
q(i, r, d.init);
|
|
755
759
|
return;
|
|
756
760
|
}
|
|
757
761
|
}
|
|
758
|
-
q(e,
|
|
762
|
+
q(e, r, this._exportsObject), this._exports[e[0]] = r;
|
|
759
763
|
return;
|
|
760
764
|
}
|
|
761
765
|
if (o && n.types.isObjectExpression(o) && i.length > 0) {
|
|
762
|
-
q(i,
|
|
766
|
+
q(i, r, o);
|
|
763
767
|
return;
|
|
764
768
|
}
|
|
765
|
-
let
|
|
766
|
-
if (
|
|
767
|
-
q(i,
|
|
769
|
+
let a = Y(t, this._ast.program);
|
|
770
|
+
if (a && n.types.isObjectExpression(a.init)) {
|
|
771
|
+
q(i, r, a.init);
|
|
768
772
|
return;
|
|
769
773
|
}
|
|
770
774
|
if (o && i.length === 0 && this._exportDecls[e[0]]) {
|
|
771
|
-
let
|
|
772
|
-
n.types.isVariableDeclarator(
|
|
775
|
+
let l = this._exportDecls[e[0]];
|
|
776
|
+
n.types.isVariableDeclarator(l) && (l.init = B([], r));
|
|
773
777
|
} else {
|
|
774
778
|
if (this.hasDefaultExport)
|
|
775
779
|
throw new Error(
|
|
@@ -778,10 +782,10 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
778
782
|
)}" field as the default export is not an object in this file.`
|
|
779
783
|
);
|
|
780
784
|
{
|
|
781
|
-
let
|
|
782
|
-
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(
|
|
785
|
+
let l = B(i, r), p = n.types.exportNamedDeclaration(
|
|
786
|
+
n.types.variableDeclaration("const", [n.types.variableDeclarator(n.types.identifier(t), l)])
|
|
783
787
|
);
|
|
784
|
-
this._exports[
|
|
788
|
+
this._exports[t] = l, this._ast.program.body.push(p);
|
|
785
789
|
}
|
|
786
790
|
}
|
|
787
791
|
}
|
|
@@ -797,9 +801,9 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
797
801
|
* @returns The name of a node in a given path, supporting the following formats:
|
|
798
802
|
*/
|
|
799
803
|
getNameFromPath(e) {
|
|
800
|
-
let
|
|
801
|
-
if (
|
|
802
|
-
return this._getPresetValue(
|
|
804
|
+
let r = this.getFieldNode(e);
|
|
805
|
+
if (r)
|
|
806
|
+
return this._getPresetValue(r, "name");
|
|
803
807
|
}
|
|
804
808
|
/**
|
|
805
809
|
* Returns an array of names of a node in a given path, supporting the following formats:
|
|
@@ -815,19 +819,19 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
815
819
|
* ```
|
|
816
820
|
*/
|
|
817
821
|
getNamesFromPath(e) {
|
|
818
|
-
let
|
|
819
|
-
if (!
|
|
822
|
+
let r = this.getFieldNode(e);
|
|
823
|
+
if (!r)
|
|
820
824
|
return;
|
|
821
|
-
let
|
|
822
|
-
return n.types.isArrayExpression(
|
|
823
|
-
|
|
824
|
-
}),
|
|
825
|
+
let t = [];
|
|
826
|
+
return n.types.isArrayExpression(r) && r.elements.forEach((i) => {
|
|
827
|
+
t.push(this._getPresetValue(i, "name"));
|
|
828
|
+
}), t;
|
|
825
829
|
}
|
|
826
830
|
_getPnpWrappedValue(e) {
|
|
827
831
|
if (n.types.isCallExpression(e)) {
|
|
828
|
-
let
|
|
829
|
-
if (n.types.isStringLiteral(
|
|
830
|
-
return
|
|
832
|
+
let r = e.arguments[0];
|
|
833
|
+
if (n.types.isStringLiteral(r))
|
|
834
|
+
return r.value;
|
|
831
835
|
}
|
|
832
836
|
}
|
|
833
837
|
/**
|
|
@@ -836,88 +840,88 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
836
840
|
* 1. `{ node: 'value' }`
|
|
837
841
|
* 2. `{ node: { fallbackProperty: 'value' } }`
|
|
838
842
|
*/
|
|
839
|
-
_getPresetValue(e,
|
|
840
|
-
let
|
|
841
|
-
if (n.types.isStringLiteral(e) ?
|
|
842
|
-
n.types.isObjectProperty(i) && n.types.isIdentifier(i.key) && i.key.name ===
|
|
843
|
-
|
|
844
|
-
isStringLiteral(i.value) && (
|
|
845
|
-
}) : n.types.isCallExpression(e) && (
|
|
843
|
+
_getPresetValue(e, r) {
|
|
844
|
+
let t;
|
|
845
|
+
if (n.types.isStringLiteral(e) ? t = e.value : n.types.isObjectExpression(e) ? e.properties.forEach((i) => {
|
|
846
|
+
n.types.isObjectProperty(i) && n.types.isIdentifier(i.key) && i.key.name === r && (n.types.isStringLiteral(i.value) ? t = i.value.value :
|
|
847
|
+
t = this._getPnpWrappedValue(i.value)), n.types.isObjectProperty(i) && n.types.isStringLiteral(i.key) && i.key.value === "name" && n.types.
|
|
848
|
+
isStringLiteral(i.value) && (t = i.value.value);
|
|
849
|
+
}) : n.types.isCallExpression(e) && (t = this._getPnpWrappedValue(e)), !t)
|
|
846
850
|
throw new Error(
|
|
847
|
-
`The given node must be a string literal or an object expression with a "${
|
|
851
|
+
`The given node must be a string literal or an object expression with a "${r}" property that is a string literal.`
|
|
848
852
|
);
|
|
849
|
-
return
|
|
853
|
+
return t;
|
|
850
854
|
}
|
|
851
855
|
removeField(e) {
|
|
852
|
-
let
|
|
853
|
-
let
|
|
854
|
-
(
|
|
856
|
+
let r = /* @__PURE__ */ f((i, o) => {
|
|
857
|
+
let a = i.findIndex(
|
|
858
|
+
(l) => n.types.isIdentifier(l.key) && l.key.name === o || n.types.isStringLiteral(l.key) && l.key.value === o
|
|
855
859
|
);
|
|
856
|
-
|
|
860
|
+
a >= 0 && i.splice(a, 1);
|
|
857
861
|
}, "removeProperty");
|
|
858
862
|
if (e.length === 1) {
|
|
859
863
|
let i = !1;
|
|
860
864
|
if (this._ast.program.body.forEach((o) => {
|
|
861
865
|
if (n.types.isExportNamedDeclaration(o) && n.types.isVariableDeclaration(o.declaration)) {
|
|
862
|
-
let
|
|
863
|
-
n.types.isIdentifier(
|
|
866
|
+
let a = o.declaration.declarations[0];
|
|
867
|
+
n.types.isIdentifier(a.id) && a.id.name === e[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(o), 1), i = !0);
|
|
864
868
|
}
|
|
865
869
|
if (n.types.isExportDefaultDeclaration(o)) {
|
|
866
|
-
let
|
|
867
|
-
if (n.types.isIdentifier(
|
|
868
|
-
let
|
|
869
|
-
|
|
870
|
+
let a = o.declaration;
|
|
871
|
+
if (n.types.isIdentifier(a) && (a = F(a.name, this._ast.program)), a = H(a), n.types.isObjectExpression(a)) {
|
|
872
|
+
let l = a.properties;
|
|
873
|
+
r(l, e[0]), i = !0;
|
|
870
874
|
}
|
|
871
875
|
}
|
|
872
876
|
if (n.types.isExpressionStatement(o) && n.types.isAssignmentExpression(o.expression) && n.types.isMemberExpression(o.expression.left) &&
|
|
873
877
|
n.types.isIdentifier(o.expression.left.object) && o.expression.left.object.name === "module" && n.types.isIdentifier(o.expression.left.
|
|
874
878
|
property) && o.expression.left.property.name === "exports" && n.types.isObjectExpression(o.expression.right)) {
|
|
875
|
-
let
|
|
876
|
-
|
|
879
|
+
let a = o.expression.right.properties;
|
|
880
|
+
r(a, e[0]), i = !0;
|
|
877
881
|
}
|
|
878
882
|
}), i)
|
|
879
883
|
return;
|
|
880
884
|
}
|
|
881
|
-
let
|
|
882
|
-
if (
|
|
885
|
+
let t = this.getFieldProperties(e);
|
|
886
|
+
if (t) {
|
|
883
887
|
let i = e.at(-1);
|
|
884
|
-
t
|
|
888
|
+
r(t, i);
|
|
885
889
|
}
|
|
886
890
|
}
|
|
887
|
-
appendValueToArray(e,
|
|
888
|
-
let
|
|
889
|
-
|
|
891
|
+
appendValueToArray(e, r) {
|
|
892
|
+
let t = this.valueToNode(r);
|
|
893
|
+
t && this.appendNodeToArray(e, t);
|
|
890
894
|
}
|
|
891
|
-
appendNodeToArray(e,
|
|
892
|
-
let
|
|
893
|
-
if (!
|
|
894
|
-
this.setFieldNode(e, n.types.arrayExpression([
|
|
895
|
-
else if (n.types.isArrayExpression(
|
|
896
|
-
|
|
895
|
+
appendNodeToArray(e, r) {
|
|
896
|
+
let t = this.getFieldNode(e);
|
|
897
|
+
if (!t)
|
|
898
|
+
this.setFieldNode(e, n.types.arrayExpression([r]));
|
|
899
|
+
else if (n.types.isArrayExpression(t))
|
|
900
|
+
t.elements.push(r);
|
|
897
901
|
else
|
|
898
|
-
throw new Error(`Expected array at '${e.join(".")}', got '${
|
|
902
|
+
throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
|
|
899
903
|
}
|
|
900
904
|
/**
|
|
901
905
|
* Specialized helper to remove addons or other array entries that can either be strings or
|
|
902
906
|
* objects with a name property.
|
|
903
907
|
*/
|
|
904
|
-
removeEntryFromArray(e,
|
|
905
|
-
let
|
|
906
|
-
if (
|
|
907
|
-
if (n.types.isArrayExpression(
|
|
908
|
-
let i =
|
|
909
|
-
o, "name") ===
|
|
908
|
+
removeEntryFromArray(e, r) {
|
|
909
|
+
let t = this.getFieldNode(e);
|
|
910
|
+
if (t)
|
|
911
|
+
if (n.types.isArrayExpression(t)) {
|
|
912
|
+
let i = t.elements.findIndex((o) => n.types.isStringLiteral(o) ? o.value === r : n.types.isObjectExpression(o) ? this._getPresetValue(
|
|
913
|
+
o, "name") === r : this._getPnpWrappedValue(o) === r);
|
|
910
914
|
if (i >= 0)
|
|
911
|
-
|
|
915
|
+
t.elements.splice(i, 1);
|
|
912
916
|
else
|
|
913
|
-
throw new Error(`Could not find '${
|
|
917
|
+
throw new Error(`Could not find '${r}' in array at '${e.join(".")}'`);
|
|
914
918
|
} else
|
|
915
|
-
throw new Error(`Expected array at '${e.join(".")}', got '${
|
|
919
|
+
throw new Error(`Expected array at '${e.join(".")}', got '${t.type}'`);
|
|
916
920
|
}
|
|
917
921
|
_inferQuotes() {
|
|
918
922
|
if (!this._quotes) {
|
|
919
923
|
let e = (this._ast.tokens || []).slice(0, 500).reduce(
|
|
920
|
-
(
|
|
924
|
+
(r, t) => (t.type.label === "string" && (r[this._code[t.start]] += 1), r),
|
|
921
925
|
{ "'": 0, '"': 0 }
|
|
922
926
|
);
|
|
923
927
|
this._quotes = e["'"] > e['"'] ? "single" : "double";
|
|
@@ -925,26 +929,26 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
925
929
|
return this._quotes;
|
|
926
930
|
}
|
|
927
931
|
valueToNode(e) {
|
|
928
|
-
let
|
|
929
|
-
if (
|
|
930
|
-
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes:
|
|
932
|
+
let r = this._inferQuotes(), t;
|
|
933
|
+
if (r === "single") {
|
|
934
|
+
let { code: i } = (0, n.generate)(n.types.valueToNode(e), { jsescOption: { quotes: r } }), o = (0, n.babelParse)(`const __x = ${i}`);
|
|
931
935
|
(0, n.traverse)(o, {
|
|
932
936
|
VariableDeclaration: {
|
|
933
|
-
enter({ node:
|
|
934
|
-
|
|
935
|
-
declarations[0].id.name === "__x" && (
|
|
937
|
+
enter({ node: a }) {
|
|
938
|
+
a.declarations.length === 1 && n.types.isVariableDeclarator(a.declarations[0]) && n.types.isIdentifier(a.declarations[0].id) && a.
|
|
939
|
+
declarations[0].id.name === "__x" && (t = a.declarations[0].init);
|
|
936
940
|
}
|
|
937
941
|
}
|
|
938
942
|
});
|
|
939
943
|
} else
|
|
940
|
-
|
|
941
|
-
return
|
|
944
|
+
t = n.types.valueToNode(e);
|
|
945
|
+
return t;
|
|
942
946
|
}
|
|
943
|
-
setFieldValue(e,
|
|
944
|
-
let
|
|
945
|
-
if (!
|
|
946
|
-
throw new Error(`Unexpected value ${JSON.stringify(
|
|
947
|
-
this.setFieldNode(e,
|
|
947
|
+
setFieldValue(e, r) {
|
|
948
|
+
let t = this.valueToNode(r);
|
|
949
|
+
if (!t)
|
|
950
|
+
throw new Error(`Unexpected value ${JSON.stringify(r)}`);
|
|
951
|
+
this.setFieldNode(e, t);
|
|
948
952
|
}
|
|
949
953
|
getBodyDeclarations() {
|
|
950
954
|
return this._ast.program.body;
|
|
@@ -969,40 +973,42 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
969
973
|
* import will be set. Otherwise, an array of named imports will be set
|
|
970
974
|
* @param fromImport - The module to import from
|
|
971
975
|
*/
|
|
972
|
-
setRequireImport(e,
|
|
973
|
-
let
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
isStringLiteral(
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
),
|
|
980
|
-
|
|
976
|
+
setRequireImport(e, r) {
|
|
977
|
+
let t = this._ast.program.body.find((a) => {
|
|
978
|
+
let l = n.types.isVariableDeclaration(a) && a.declarations.length === 1 && n.types.isVariableDeclarator(a.declarations[0]) && n.types.
|
|
979
|
+
isCallExpression(a.declarations[0].init) && n.types.isIdentifier(a.declarations[0].init.callee) && a.declarations[0].init.callee.name ===
|
|
980
|
+
"require" && n.types.isStringLiteral(a.declarations[0].init.arguments[0]) && (a.declarations[0].init.arguments[0].value === r || a.declarations[0].
|
|
981
|
+
init.arguments[0].value === r.split("node:")[1]);
|
|
982
|
+
return l && (r = a.declarations[0].init.arguments[0].value), l;
|
|
983
|
+
}), i = /* @__PURE__ */ f((a) => n.types.isObjectPattern(t?.declarations[0].id) && t?.declarations[0].id.properties.find(
|
|
984
|
+
(l) => n.types.isObjectProperty(l) && n.types.isIdentifier(l.key) && l.key.name === a
|
|
985
|
+
), "hasRequireSpecifier"), o = /* @__PURE__ */ f((a, l) => a.declarations.length === 1 && n.types.isVariableDeclarator(a.declarations[0]) &&
|
|
986
|
+
n.types.isIdentifier(a.declarations[0].id) && a.declarations[0].id.name === l, "hasDefaultRequireSpecifier");
|
|
981
987
|
if (typeof e == "string") {
|
|
982
|
-
let
|
|
988
|
+
let a = /* @__PURE__ */ f(() => {
|
|
983
989
|
this._ast.program.body.unshift(
|
|
984
990
|
n.types.variableDeclaration("const", [
|
|
985
991
|
n.types.variableDeclarator(
|
|
986
992
|
n.types.identifier(e),
|
|
987
|
-
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(
|
|
993
|
+
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(r)])
|
|
988
994
|
)
|
|
989
995
|
])
|
|
990
996
|
);
|
|
991
997
|
}, "addDefaultRequireSpecifier");
|
|
992
|
-
|
|
993
|
-
} else
|
|
994
|
-
i(
|
|
995
|
-
n.types.objectProperty(n.types.identifier(
|
|
998
|
+
t && o(t, e) || a();
|
|
999
|
+
} else t ? e.forEach((a) => {
|
|
1000
|
+
i(a) || t.declarations[0].id.properties.push(
|
|
1001
|
+
n.types.objectProperty(n.types.identifier(a), n.types.identifier(a), void 0, !0)
|
|
996
1002
|
);
|
|
997
1003
|
}) : this._ast.program.body.unshift(
|
|
998
1004
|
n.types.variableDeclaration("const", [
|
|
999
1005
|
n.types.variableDeclarator(
|
|
1000
1006
|
n.types.objectPattern(
|
|
1001
1007
|
e.map(
|
|
1002
|
-
(
|
|
1008
|
+
(a) => n.types.objectProperty(n.types.identifier(a), n.types.identifier(a), void 0, !0)
|
|
1003
1009
|
)
|
|
1004
1010
|
),
|
|
1005
|
-
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(
|
|
1011
|
+
n.types.callExpression(n.types.identifier("require"), [n.types.stringLiteral(r)])
|
|
1006
1012
|
)
|
|
1007
1013
|
])
|
|
1008
1014
|
);
|
|
@@ -1032,77 +1038,78 @@ s, "unwrap"), he = /* @__PURE__ */ f((s, e) => {
|
|
|
1032
1038
|
* import will be set. Otherwise, an array of named imports will be set
|
|
1033
1039
|
* @param fromImport - The module to import from
|
|
1034
1040
|
*/
|
|
1035
|
-
setImport(e,
|
|
1036
|
-
let
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
),
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
)
|
|
1046
|
-
|
|
1047
|
-
|
|
1041
|
+
setImport(e, r) {
|
|
1042
|
+
let t = this._ast.program.body.find((p) => {
|
|
1043
|
+
let d = n.types.isImportDeclaration(p) && (p.source.value === r || p.source.value === r.split("node:")[1]);
|
|
1044
|
+
return d && (r = p.source.value), d;
|
|
1045
|
+
}), i = /* @__PURE__ */ f((p) => n.types.importSpecifier(n.types.identifier(p), n.types.identifier(p)), "getNewImportSpecifier"), o = /* @__PURE__ */ f(
|
|
1046
|
+
(p, d) => p.specifiers.find(
|
|
1047
|
+
(g) => n.types.isImportSpecifier(g) && n.types.isIdentifier(g.imported) && g.imported.name === d
|
|
1048
|
+
), "hasImportSpecifier"), a = /* @__PURE__ */ f((p, d) => p.specifiers.find(
|
|
1049
|
+
(g) => n.types.isImportNamespaceSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1050
|
+
), "hasNamespaceImportSpecifier");
|
|
1051
|
+
e === null ? t || this._ast.program.body.unshift(n.types.importDeclaration([], n.types.stringLiteral(r))) : typeof e == "string" ? t ? (/* @__PURE__ */ f(
|
|
1052
|
+
(p, d) => p.specifiers.find(
|
|
1053
|
+
(g) => n.types.isImportDefaultSpecifier(g) && n.types.isIdentifier(g.local) && g.local.name === d
|
|
1054
|
+
), "hasDefaultImportSpecifier"))(t, e) || t.specifiers.push(
|
|
1048
1055
|
n.types.importDefaultSpecifier(n.types.identifier(e))
|
|
1049
1056
|
) : this._ast.program.body.unshift(
|
|
1050
1057
|
n.types.importDeclaration(
|
|
1051
1058
|
[n.types.importDefaultSpecifier(n.types.identifier(e))],
|
|
1052
|
-
n.types.stringLiteral(
|
|
1059
|
+
n.types.stringLiteral(r)
|
|
1053
1060
|
)
|
|
1054
|
-
) : Array.isArray(e) ?
|
|
1055
|
-
|
|
1061
|
+
) : Array.isArray(e) ? t ? e.forEach((p) => {
|
|
1062
|
+
o(t, p) || t.specifiers.push(i(p));
|
|
1056
1063
|
}) : this._ast.program.body.unshift(
|
|
1057
1064
|
n.types.importDeclaration(
|
|
1058
|
-
e.map(
|
|
1059
|
-
n.types.stringLiteral(
|
|
1065
|
+
e.map(i),
|
|
1066
|
+
n.types.stringLiteral(r)
|
|
1060
1067
|
)
|
|
1061
|
-
) : e.namespace && (
|
|
1068
|
+
) : e.namespace && (t ? a(t, e.namespace) || t.specifiers.push(
|
|
1062
1069
|
n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))
|
|
1063
1070
|
) : this._ast.program.body.unshift(
|
|
1064
1071
|
n.types.importDeclaration(
|
|
1065
1072
|
[n.types.importNamespaceSpecifier(n.types.identifier(e.namespace))],
|
|
1066
|
-
n.types.stringLiteral(
|
|
1073
|
+
n.types.stringLiteral(r)
|
|
1067
1074
|
)
|
|
1068
1075
|
));
|
|
1069
1076
|
}
|
|
1070
1077
|
}, je = /* @__PURE__ */ f((s, e) => {
|
|
1071
|
-
let
|
|
1072
|
-
return new Z(
|
|
1078
|
+
let r = (0, n.babelParse)(s);
|
|
1079
|
+
return new Z(r, s, e);
|
|
1073
1080
|
}, "loadConfig"), Se = /* @__PURE__ */ f((s) => Pe(s).code, "formatConfig"), Pe = /* @__PURE__ */ f((s, e = {}) => n.recast.print(s._ast, e),
|
|
1074
1081
|
"printConfig"), nt = /* @__PURE__ */ f(async (s) => {
|
|
1075
1082
|
let e = (await (0, ee.readFile)(s, "utf-8")).toString();
|
|
1076
1083
|
return je(e, s).parse();
|
|
1077
1084
|
}, "readConfig"), ot = /* @__PURE__ */ f(async (s, e) => {
|
|
1078
|
-
let
|
|
1079
|
-
if (!
|
|
1085
|
+
let r = e || s.fileName;
|
|
1086
|
+
if (!r)
|
|
1080
1087
|
throw new Error("Please specify a fileName for writeConfig");
|
|
1081
|
-
await (0, ee.writeFile)(
|
|
1082
|
-
}, "writeConfig"), at = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((
|
|
1083
|
-
"@storybook") &&
|
|
1088
|
+
await (0, ee.writeFile)(r, Se(s));
|
|
1089
|
+
}, "writeConfig"), at = /* @__PURE__ */ f((s) => !!s._ast.program.body.find((r) => n.types.isImportDeclaration(r) && r.source.value.includes(
|
|
1090
|
+
"@storybook") && r.specifiers.some((t) => n.types.isImportSpecifier(t) && n.types.isIdentifier(t.imported) && t.imported.name === "definePre\
|
|
1084
1091
|
view")), "isCsfFactoryPreview");
|
|
1085
1092
|
|
|
1086
1093
|
// src/csf-tools/getStorySortParameter.ts
|
|
1087
|
-
var y = require("storybook/internal/babel"),
|
|
1094
|
+
var y = require("storybook/internal/babel"), ve = z(R(), 1);
|
|
1088
1095
|
var lt = console, se = /* @__PURE__ */ f((s, e) => {
|
|
1089
|
-
let
|
|
1090
|
-
return s.properties.forEach((
|
|
1091
|
-
y.types.isIdentifier(
|
|
1092
|
-
}),
|
|
1096
|
+
let r;
|
|
1097
|
+
return s.properties.forEach((t) => {
|
|
1098
|
+
y.types.isIdentifier(t.key) && t.key.name === e && (r = t.value);
|
|
1099
|
+
}), r;
|
|
1093
1100
|
}, "getValue"), ne = /* @__PURE__ */ f((s) => {
|
|
1094
1101
|
let e = W(s);
|
|
1095
1102
|
if (y.types.isArrayExpression(e))
|
|
1096
|
-
return e.elements.map((
|
|
1103
|
+
return e.elements.map((r) => ne(r));
|
|
1097
1104
|
if (y.types.isObjectExpression(e))
|
|
1098
|
-
return e.properties.reduce((
|
|
1105
|
+
return e.properties.reduce((r, t) => (y.types.isIdentifier(t.key) && (r[t.key.name] = ne(t.value)), r), {});
|
|
1099
1106
|
if (y.types.isLiteral(e))
|
|
1100
1107
|
return e.value;
|
|
1101
1108
|
if (y.types.isIdentifier(e))
|
|
1102
1109
|
return T(e.name, !0);
|
|
1103
1110
|
throw new Error(`Unknown node type ${e.type}`);
|
|
1104
1111
|
}, "parseValue"), T = /* @__PURE__ */ f((s, e) => {
|
|
1105
|
-
let
|
|
1112
|
+
let r = ve.dedent`
|
|
1106
1113
|
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1107
1114
|
|
|
1108
1115
|
export default {
|
|
@@ -1114,62 +1121,62 @@ var lt = console, se = /* @__PURE__ */ f((s, e) => {
|
|
|
1114
1121
|
};
|
|
1115
1122
|
`;
|
|
1116
1123
|
if (e)
|
|
1117
|
-
throw new Error(
|
|
1118
|
-
lt.info(
|
|
1124
|
+
throw new Error(r);
|
|
1125
|
+
lt.info(r);
|
|
1119
1126
|
}, "unsupported"), W = /* @__PURE__ */ f((s) => y.types.isTSAsExpression(s) || y.types.isTSSatisfiesExpression(s) ? s.expression : s, "strip\
|
|
1120
1127
|
TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
1121
1128
|
let e = W(s);
|
|
1122
1129
|
if (y.types.isObjectExpression(e)) {
|
|
1123
|
-
let
|
|
1124
|
-
if (
|
|
1125
|
-
if (y.types.isObjectExpression(
|
|
1126
|
-
return se(
|
|
1130
|
+
let r = se(e, "options");
|
|
1131
|
+
if (r) {
|
|
1132
|
+
if (y.types.isObjectExpression(r))
|
|
1133
|
+
return se(r, "storySort");
|
|
1127
1134
|
T("options", !0);
|
|
1128
1135
|
}
|
|
1129
1136
|
}
|
|
1130
1137
|
}, "parseParameters"), Oe = /* @__PURE__ */ f((s, e) => {
|
|
1131
|
-
let
|
|
1132
|
-
if (y.types.isObjectExpression(
|
|
1133
|
-
let
|
|
1134
|
-
if (y.types.isIdentifier(
|
|
1135
|
-
return De(
|
|
1138
|
+
let r = W(s);
|
|
1139
|
+
if (y.types.isObjectExpression(r)) {
|
|
1140
|
+
let t = se(r, "parameters");
|
|
1141
|
+
if (y.types.isIdentifier(t) && (t = P(t.name, e)), t)
|
|
1142
|
+
return De(t);
|
|
1136
1143
|
} else
|
|
1137
1144
|
T("default", !0);
|
|
1138
1145
|
}, "parseDefault"), ct = /* @__PURE__ */ f((s) => {
|
|
1139
1146
|
if (!s.includes("storySort"))
|
|
1140
1147
|
return;
|
|
1141
|
-
let e,
|
|
1142
|
-
if ((0, y.traverse)(
|
|
1148
|
+
let e, r = (0, y.babelParse)(s);
|
|
1149
|
+
if ((0, y.traverse)(r, {
|
|
1143
1150
|
ExportNamedDeclaration: {
|
|
1144
|
-
enter({ node:
|
|
1145
|
-
y.types.isVariableDeclaration(
|
|
1151
|
+
enter({ node: t }) {
|
|
1152
|
+
y.types.isVariableDeclaration(t.declaration) ? t.declaration.declarations.forEach((i) => {
|
|
1146
1153
|
if (y.types.isVariableDeclarator(i) && y.types.isIdentifier(i.id)) {
|
|
1147
1154
|
let { name: o } = i.id;
|
|
1148
1155
|
if (o === "parameters" && i.init) {
|
|
1149
|
-
let
|
|
1150
|
-
e = De(
|
|
1156
|
+
let a = W(i.init);
|
|
1157
|
+
e = De(a);
|
|
1151
1158
|
}
|
|
1152
1159
|
}
|
|
1153
|
-
}) :
|
|
1160
|
+
}) : t.specifiers.forEach((i) => {
|
|
1154
1161
|
y.types.isIdentifier(i.exported) && i.exported.name === "parameters" && T("parameters", !1);
|
|
1155
1162
|
});
|
|
1156
1163
|
}
|
|
1157
1164
|
},
|
|
1158
1165
|
ExportDefaultDeclaration: {
|
|
1159
|
-
enter({ node:
|
|
1160
|
-
let i =
|
|
1161
|
-
y.types.isIdentifier(i) && (i = P(i.name,
|
|
1162
|
-
e = Oe(i.arguments[0],
|
|
1166
|
+
enter({ node: t }) {
|
|
1167
|
+
let i = t.declaration;
|
|
1168
|
+
y.types.isIdentifier(i) && (i = P(i.name, r.program)), i = W(i), y.types.isCallExpression(i) && y.types.isObjectExpression(i.arguments?.[0]) ?
|
|
1169
|
+
e = Oe(i.arguments[0], r.program) : y.types.isObjectExpression(i) ? e = Oe(i, r.program) : T("default", !1);
|
|
1163
1170
|
}
|
|
1164
1171
|
}
|
|
1165
1172
|
}), !!e) {
|
|
1166
1173
|
if (y.types.isArrowFunctionExpression(e)) {
|
|
1167
|
-
let { code:
|
|
1168
|
-
return (0, eval)(
|
|
1174
|
+
let { code: t } = (0, y.generate)(e, {});
|
|
1175
|
+
return (0, eval)(t);
|
|
1169
1176
|
}
|
|
1170
1177
|
if (y.types.isFunctionExpression(e)) {
|
|
1171
|
-
let { code:
|
|
1172
|
-
${
|
|
1178
|
+
let { code: t } = (0, y.generate)(e, {}), i = e.id?.name, o = `(a, b) => {
|
|
1179
|
+
${t};
|
|
1173
1180
|
return ${i}(a, b)
|
|
1174
1181
|
}`;
|
|
1175
1182
|
return (0, eval)(o);
|
|
@@ -1179,96 +1186,96 @@ TSModifiers"), De = /* @__PURE__ */ f((s) => {
|
|
|
1179
1186
|
}, "getStorySortParameter");
|
|
1180
1187
|
|
|
1181
1188
|
// src/csf-tools/enrichCsf.ts
|
|
1182
|
-
var
|
|
1183
|
-
var
|
|
1184
|
-
let i = e.getStoryExport(
|
|
1185
|
-
i.callee.object.name === "meta",
|
|
1186
|
-
memberExpression(
|
|
1189
|
+
var m = require("storybook/internal/babel");
|
|
1190
|
+
var Ie = /* @__PURE__ */ f((s, e, r, t) => {
|
|
1191
|
+
let i = e.getStoryExport(r), o = m.types.isCallExpression(i) && m.types.isMemberExpression(i.callee) && m.types.isIdentifier(i.callee.object) &&
|
|
1192
|
+
i.callee.object.name === "meta", a = !t?.disableSource && Fe(i), l = !t?.disableDescription && oe(e._storyStatements[r]), p = [], d = o ? m.types.
|
|
1193
|
+
memberExpression(m.types.identifier(r), m.types.identifier("input")) : m.types.identifier(r), g = m.types.memberExpression(d, m.types.identifier(
|
|
1187
1194
|
"parameters"));
|
|
1188
|
-
p.push(
|
|
1189
|
-
let x =
|
|
1195
|
+
p.push(m.types.spreadElement(g));
|
|
1196
|
+
let x = m.types.optionalMemberExpression(
|
|
1190
1197
|
g,
|
|
1191
|
-
|
|
1198
|
+
m.types.identifier("docs"),
|
|
1192
1199
|
!1,
|
|
1193
1200
|
!0
|
|
1194
|
-
),
|
|
1195
|
-
if (
|
|
1196
|
-
let b =
|
|
1201
|
+
), h = [];
|
|
1202
|
+
if (a) {
|
|
1203
|
+
let b = m.types.optionalMemberExpression(
|
|
1197
1204
|
x,
|
|
1198
|
-
|
|
1205
|
+
m.types.identifier("source"),
|
|
1199
1206
|
!1,
|
|
1200
1207
|
!0
|
|
1201
1208
|
);
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1209
|
+
h.push(
|
|
1210
|
+
m.types.objectProperty(
|
|
1211
|
+
m.types.identifier("source"),
|
|
1212
|
+
m.types.objectExpression([
|
|
1213
|
+
m.types.objectProperty(m.types.identifier("originalSource"), m.types.stringLiteral(a)),
|
|
1214
|
+
m.types.spreadElement(b)
|
|
1208
1215
|
])
|
|
1209
1216
|
)
|
|
1210
1217
|
);
|
|
1211
1218
|
}
|
|
1212
|
-
if (
|
|
1213
|
-
let b =
|
|
1219
|
+
if (l) {
|
|
1220
|
+
let b = m.types.optionalMemberExpression(
|
|
1214
1221
|
x,
|
|
1215
|
-
|
|
1222
|
+
m.types.identifier("description"),
|
|
1216
1223
|
!1,
|
|
1217
1224
|
!0
|
|
1218
1225
|
);
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1226
|
+
h.push(
|
|
1227
|
+
m.types.objectProperty(
|
|
1228
|
+
m.types.identifier("description"),
|
|
1229
|
+
m.types.objectExpression([
|
|
1230
|
+
m.types.objectProperty(m.types.identifier("story"), m.types.stringLiteral(l)),
|
|
1231
|
+
m.types.spreadElement(b)
|
|
1225
1232
|
])
|
|
1226
1233
|
)
|
|
1227
1234
|
);
|
|
1228
1235
|
}
|
|
1229
|
-
if (
|
|
1236
|
+
if (h.length > 0) {
|
|
1230
1237
|
p.push(
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1238
|
+
m.types.objectProperty(
|
|
1239
|
+
m.types.identifier("docs"),
|
|
1240
|
+
m.types.objectExpression([m.types.spreadElement(x), ...h])
|
|
1234
1241
|
)
|
|
1235
1242
|
);
|
|
1236
|
-
let b =
|
|
1237
|
-
|
|
1243
|
+
let b = m.types.expressionStatement(
|
|
1244
|
+
m.types.assignmentExpression("=", g, m.types.objectExpression(p))
|
|
1238
1245
|
);
|
|
1239
1246
|
s._ast.program.body.push(b);
|
|
1240
1247
|
}
|
|
1241
|
-
}, "enrichCsfStory"), Ne = /* @__PURE__ */ f((s, e,
|
|
1248
|
+
}, "enrichCsfStory"), Ne = /* @__PURE__ */ f((s, e, r) => {
|
|
1242
1249
|
if (!e.length) {
|
|
1243
1250
|
s.properties.find(
|
|
1244
|
-
(p) =>
|
|
1245
|
-
) || s.properties.unshift(
|
|
1251
|
+
(p) => m.types.isObjectProperty(p) && m.types.isIdentifier(p.key) && p.key.name === "component"
|
|
1252
|
+
) || s.properties.unshift(r);
|
|
1246
1253
|
return;
|
|
1247
1254
|
}
|
|
1248
|
-
let [
|
|
1249
|
-
(
|
|
1250
|
-
),
|
|
1251
|
-
o ?
|
|
1252
|
-
}, "addComponentDescription"), we = /* @__PURE__ */ f((s, e,
|
|
1253
|
-
let
|
|
1254
|
-
if (
|
|
1255
|
+
let [t, ...i] = e, o = s.properties.find(
|
|
1256
|
+
(l) => m.types.isObjectProperty(l) && m.types.isIdentifier(l.key) && l.key.name === t && m.types.isObjectExpression(l.value)
|
|
1257
|
+
), a;
|
|
1258
|
+
o ? a = o.value : (a = m.types.objectExpression([]), s.properties.push(m.types.objectProperty(m.types.identifier(t), a))), Ne(a, i, r);
|
|
1259
|
+
}, "addComponentDescription"), we = /* @__PURE__ */ f((s, e, r) => {
|
|
1260
|
+
let t = !r?.disableDescription && oe(e._metaStatement);
|
|
1261
|
+
if (t) {
|
|
1255
1262
|
let i = s._metaNode;
|
|
1256
|
-
i &&
|
|
1263
|
+
i && m.types.isObjectExpression(i) && Ne(
|
|
1257
1264
|
i,
|
|
1258
1265
|
["parameters", "docs", "description"],
|
|
1259
|
-
|
|
1266
|
+
m.types.objectProperty(m.types.identifier("component"), m.types.stringLiteral(t))
|
|
1260
1267
|
);
|
|
1261
1268
|
}
|
|
1262
|
-
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e,
|
|
1263
|
-
we(s, e,
|
|
1264
|
-
|
|
1269
|
+
}, "enrichCsfMeta"), pt = /* @__PURE__ */ f((s, e, r) => {
|
|
1270
|
+
we(s, e, r), Object.keys(s._storyExports).forEach((t) => {
|
|
1271
|
+
Ie(s, e, t, r);
|
|
1265
1272
|
});
|
|
1266
1273
|
}, "enrichCsf"), Fe = /* @__PURE__ */ f((s) => {
|
|
1267
|
-
let e =
|
|
1268
|
-
return
|
|
1269
|
-
}, "extractSource"), oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((
|
|
1270
|
-
"*") ? null :
|
|
1271
|
-
`).map((
|
|
1274
|
+
let e = m.types.isVariableDeclarator(s) ? s.init : s, { code: r } = (0, m.generate)(e, {});
|
|
1275
|
+
return r;
|
|
1276
|
+
}, "extractSource"), oe = /* @__PURE__ */ f((s) => s?.leadingComments ? s.leadingComments.map((r) => r.type === "CommentLine" || !r.value.startsWith(
|
|
1277
|
+
"*") ? null : r.value.split(`
|
|
1278
|
+
`).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(`
|
|
1272
1279
|
`).trim()).filter(Boolean).join(`
|
|
1273
1280
|
`) : "", "extractDescription");
|
|
1274
1281
|
|
|
@@ -1276,40 +1283,40 @@ var ve = /* @__PURE__ */ f((s, e, t, r) => {
|
|
|
1276
1283
|
var Ae = require("storybook/internal/babel");
|
|
1277
1284
|
|
|
1278
1285
|
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1279
|
-
var
|
|
1280
|
-
var Ce = console, ft = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((
|
|
1281
|
-
includes(
|
|
1286
|
+
var u = require("storybook/internal/babel"), Te = require("storybook/internal/common"), ke = require("storybook/internal/csf"), ae = z(R(), 1);
|
|
1287
|
+
var Ce = console, ft = /* @__PURE__ */ f((s, e) => !(e.include.length && !e.include.some((r) => s?.includes(r)) || e.exclude.some((r) => s?.
|
|
1288
|
+
includes(r))), "isValidTest");
|
|
1282
1289
|
async function Ve({
|
|
1283
1290
|
code: s,
|
|
1284
1291
|
fileName: e,
|
|
1285
|
-
configDir:
|
|
1286
|
-
stories:
|
|
1292
|
+
configDir: r,
|
|
1293
|
+
stories: t,
|
|
1287
1294
|
tagsFilter: i,
|
|
1288
1295
|
previewLevelTags: o = []
|
|
1289
1296
|
}) {
|
|
1290
1297
|
if (!/\.stor(y|ies)\./.test(e))
|
|
1291
1298
|
return s;
|
|
1292
|
-
let
|
|
1299
|
+
let l = Q(s, {
|
|
1293
1300
|
fileName: e,
|
|
1294
1301
|
transformInlineMeta: !0,
|
|
1295
1302
|
makeTitle: /* @__PURE__ */ f((_) => {
|
|
1296
1303
|
let S = (0, Te.getStoryTitle)({
|
|
1297
1304
|
storyFilePath: e,
|
|
1298
|
-
configDir:
|
|
1299
|
-
stories:
|
|
1305
|
+
configDir: r,
|
|
1306
|
+
stories: t,
|
|
1300
1307
|
userTitle: _
|
|
1301
1308
|
}) || "unknown";
|
|
1302
1309
|
return S === "unknown" && Ce.warn(
|
|
1303
1310
|
ae.dedent`
|
|
1304
1311
|
[Storybook]: Could not calculate story title for "${e}".
|
|
1305
|
-
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${
|
|
1312
|
+
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${r}".
|
|
1306
1313
|
`
|
|
1307
1314
|
), S;
|
|
1308
1315
|
}, "makeTitle")
|
|
1309
|
-
}).parse(), p =
|
|
1310
|
-
(_) =>
|
|
1311
|
-
),
|
|
1312
|
-
if (x ?
|
|
1316
|
+
}).parse(), p = l._ast, d = l._metaVariableName, g = l._metaNode, x = g.properties.find(
|
|
1317
|
+
(_) => u.types.isObjectProperty(_) && u.types.isIdentifier(_.key) && _.key.name === "title"
|
|
1318
|
+
), h = u.types.stringLiteral(l._meta?.title || "unknown");
|
|
1319
|
+
if (x ? u.types.isObjectProperty(x) && (x.value = h) : g.properties.push(u.types.objectProperty(u.types.identifier("title"), h)), !g || !l.
|
|
1313
1320
|
_meta)
|
|
1314
1321
|
throw new Error(
|
|
1315
1322
|
`The Storybook vitest plugin could not detect the meta (default export) object in the story file.
|
|
@@ -1318,67 +1325,67 @@ Please make sure you have a default export with the meta object. If you are usin
|
|
|
1318
1325
|
le an issue with details about your use case.`
|
|
1319
1326
|
);
|
|
1320
1327
|
let b = {};
|
|
1321
|
-
Object.keys(
|
|
1328
|
+
Object.keys(l._stories).map((_) => {
|
|
1322
1329
|
let S = (0, ke.combineTags)(
|
|
1323
1330
|
"test",
|
|
1324
1331
|
"dev",
|
|
1325
1332
|
...o,
|
|
1326
|
-
...
|
|
1327
|
-
...
|
|
1333
|
+
...l.meta?.tags || [],
|
|
1334
|
+
...l._stories[_].tags || []
|
|
1328
1335
|
);
|
|
1329
|
-
ft(S, i) && (b[_] =
|
|
1336
|
+
ft(S, i) && (b[_] = l._storyStatements[_]);
|
|
1330
1337
|
});
|
|
1331
|
-
let
|
|
1338
|
+
let E = l._file.path.scope.generateUidIdentifier("test"), I = l._file.path.scope.generateUidIdentifier("describe");
|
|
1332
1339
|
if (Object.keys(b).length === 0) {
|
|
1333
|
-
let _ =
|
|
1334
|
-
|
|
1335
|
-
|
|
1340
|
+
let _ = u.types.expressionStatement(
|
|
1341
|
+
u.types.callExpression(u.types.memberExpression(I, u.types.identifier("skip")), [
|
|
1342
|
+
u.types.stringLiteral("No valid tests found")
|
|
1336
1343
|
])
|
|
1337
1344
|
);
|
|
1338
1345
|
p.program.body.push(_);
|
|
1339
1346
|
let S = [
|
|
1340
|
-
|
|
1347
|
+
u.types.importDeclaration(
|
|
1341
1348
|
[
|
|
1342
|
-
|
|
1343
|
-
|
|
1349
|
+
u.types.importSpecifier(E, u.types.identifier("test")),
|
|
1350
|
+
u.types.importSpecifier(I, u.types.identifier("describe"))
|
|
1344
1351
|
],
|
|
1345
|
-
|
|
1352
|
+
u.types.stringLiteral("vitest")
|
|
1346
1353
|
)
|
|
1347
1354
|
];
|
|
1348
1355
|
p.program.body.unshift(...S);
|
|
1349
1356
|
} else {
|
|
1350
1357
|
let le = function() {
|
|
1351
|
-
let j =
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
), k =
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
), V =
|
|
1358
|
+
let j = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), N = u.types.memberExpression(
|
|
1359
|
+
u.types.callExpression(u.types.memberExpression(_, u.types.identifier("getState")), []),
|
|
1360
|
+
u.types.identifier("testPath")
|
|
1361
|
+
), k = u.types.memberExpression(
|
|
1362
|
+
u.types.memberExpression(u.types.identifier("globalThis"), u.types.identifier("__vitest_worker__")),
|
|
1363
|
+
u.types.identifier("filepath")
|
|
1364
|
+
), V = u.types.logicalExpression(
|
|
1358
1365
|
"??",
|
|
1359
1366
|
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
1360
1367
|
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
1361
1368
|
k,
|
|
1362
1369
|
N
|
|
1363
|
-
), G =
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1370
|
+
), G = u.types.callExpression(
|
|
1371
|
+
u.types.memberExpression(
|
|
1372
|
+
u.types.callExpression(u.types.identifier("convertToFilePath"), [
|
|
1373
|
+
u.types.memberExpression(
|
|
1374
|
+
u.types.memberExpression(u.types.identifier("import"), u.types.identifier("meta")),
|
|
1375
|
+
u.types.identifier("url")
|
|
1369
1376
|
)
|
|
1370
1377
|
]),
|
|
1371
|
-
|
|
1378
|
+
u.types.identifier("includes")
|
|
1372
1379
|
),
|
|
1373
1380
|
[V]
|
|
1374
1381
|
);
|
|
1375
|
-
return { isRunningFromThisFileDeclaration:
|
|
1376
|
-
|
|
1382
|
+
return { isRunningFromThisFileDeclaration: u.types.variableDeclaration("const", [
|
|
1383
|
+
u.types.variableDeclarator(j, G)
|
|
1377
1384
|
]), isRunningFromThisFileId: j };
|
|
1378
1385
|
};
|
|
1379
|
-
var
|
|
1386
|
+
var ut = le;
|
|
1380
1387
|
f(le, "getTestGuardDeclaration");
|
|
1381
|
-
let _ =
|
|
1388
|
+
let _ = l._file.path.scope.generateUidIdentifier("expect"), S = l._file.path.scope.generateUidIdentifier("testStory"), $e = u.types.identifier(
|
|
1382
1389
|
JSON.stringify(i.skip)), { isRunningFromThisFileDeclaration: Re, isRunningFromThisFileId: Le } = le();
|
|
1383
1390
|
p.program.body.push(Re);
|
|
1384
1391
|
let Me = /* @__PURE__ */ f(({
|
|
@@ -1387,13 +1394,13 @@ le an issue with details about your use case.`
|
|
|
1387
1394
|
testTitle: k,
|
|
1388
1395
|
node: V
|
|
1389
1396
|
}) => {
|
|
1390
|
-
let G =
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
+
let G = u.types.expressionStatement(
|
|
1398
|
+
u.types.callExpression(E, [
|
|
1399
|
+
u.types.stringLiteral(k),
|
|
1400
|
+
u.types.callExpression(S, [
|
|
1401
|
+
u.types.stringLiteral(N),
|
|
1402
|
+
u.types.identifier(j),
|
|
1403
|
+
u.types.identifier(d),
|
|
1397
1404
|
$e
|
|
1398
1405
|
])
|
|
1399
1406
|
])
|
|
@@ -1409,28 +1416,28 @@ le an issue with details about your use case.`
|
|
|
1409
1416
|
);
|
|
1410
1417
|
return;
|
|
1411
1418
|
}
|
|
1412
|
-
let k =
|
|
1419
|
+
let k = l._stories[j].localName ?? j, V = l._stories[j].name ?? j;
|
|
1413
1420
|
return Me({ testTitle: V, localName: k, exportName: j, node: N });
|
|
1414
|
-
}).filter((j) => !!j), qe =
|
|
1421
|
+
}).filter((j) => !!j), qe = u.types.ifStatement(Le, u.types.blockStatement(Ue));
|
|
1415
1422
|
p.program.body.push(qe);
|
|
1416
1423
|
let Be = [
|
|
1417
|
-
|
|
1424
|
+
u.types.importDeclaration(
|
|
1418
1425
|
[
|
|
1419
|
-
|
|
1420
|
-
|
|
1426
|
+
u.types.importSpecifier(E, u.types.identifier("test")),
|
|
1427
|
+
u.types.importSpecifier(_, u.types.identifier("expect"))
|
|
1421
1428
|
],
|
|
1422
|
-
|
|
1429
|
+
u.types.stringLiteral("vitest")
|
|
1423
1430
|
),
|
|
1424
|
-
|
|
1431
|
+
u.types.importDeclaration(
|
|
1425
1432
|
[
|
|
1426
|
-
|
|
1427
|
-
|
|
1433
|
+
u.types.importSpecifier(S, u.types.identifier("testStory")),
|
|
1434
|
+
u.types.importSpecifier(u.types.identifier("convertToFilePath"), u.types.identifier("convertToFilePath"))
|
|
1428
1435
|
],
|
|
1429
|
-
|
|
1436
|
+
u.types.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
1430
1437
|
)
|
|
1431
1438
|
];
|
|
1432
1439
|
p.program.body.unshift(...Be);
|
|
1433
1440
|
}
|
|
1434
|
-
return te(
|
|
1441
|
+
return te(l, { sourceMaps: !0, sourceFileName: e }, s);
|
|
1435
1442
|
}
|
|
1436
1443
|
f(Ve, "vitestTransform");
|