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