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