storybook 10.1.0-alpha.1 → 10.1.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/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
- package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
- package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
- package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
- package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
- package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
- package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
- package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
- package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-74YHFU5B.js} +44 -109
- package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
- package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
- package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
- package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
- package/dist/_browser-chunks/chunk-BE2DAXKJ.js +2966 -0
- package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
- package/dist/_browser-chunks/chunk-EBHB6RPS.js +61 -0
- package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
- package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
- package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
- package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
- package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
- package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
- package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
- package/dist/_browser-chunks/chunk-L4RMQ7D7.js +223 -0
- package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
- package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
- package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
- package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
- package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
- package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
- package/dist/_browser-chunks/chunk-WXP2XJ3O.js +950 -0
- package/dist/_browser-chunks/chunk-X3DUQ5RA.js +47 -0
- package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
- package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
- package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
- package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
- package/dist/_browser-chunks/{syntaxhighlighter-DK2ODWXH.js → syntaxhighlighter-WKBQ5RC7.js} +707 -1851
- package/dist/_node-chunks/{builder-manager-6UBDPV7P.js → builder-manager-PMPHOSM2.js} +495 -1013
- package/dist/_node-chunks/camelcase-K3IOOFQW.js +18 -0
- package/dist/_node-chunks/{chunk-QNUGJO6L.js → chunk-32NE3UE3.js} +15 -24
- package/dist/_node-chunks/chunk-4GZCFQFG.js +58 -0
- package/dist/_node-chunks/chunk-5QK5MSOI.js +943 -0
- package/dist/_node-chunks/{chunk-3FPF5Y2F.js → chunk-6ZOLETQK.js} +8 -10
- package/dist/_node-chunks/chunk-7I22Y76Z.js +1047 -0
- package/dist/_node-chunks/chunk-AKTRSR3O.js +72 -0
- package/dist/_node-chunks/chunk-BBOP3XCK.js +119 -0
- package/dist/_node-chunks/chunk-C2GQVDWI.js +34 -0
- package/dist/_node-chunks/{chunk-SCTKVDWR.js → chunk-GG2WQZSG.js} +4619 -7350
- package/dist/_node-chunks/chunk-GQJOWVVR.js +3214 -0
- package/dist/_node-chunks/chunk-JCRM2YVK.js +3009 -0
- package/dist/_node-chunks/chunk-KK4AT5F3.js +1029 -0
- package/dist/_node-chunks/chunk-L7MYXJUM.js +1114 -0
- package/dist/_node-chunks/{chunk-LAU7VVPC.js → chunk-LCZO45L7.js} +469 -983
- package/dist/_node-chunks/chunk-LR3QITDI.js +209 -0
- package/dist/_node-chunks/chunk-LXG4DK35.js +3171 -0
- package/dist/_node-chunks/chunk-MJ3WOS6F.js +37 -0
- package/dist/_node-chunks/chunk-PHOZWZZO.js +61 -0
- package/dist/_node-chunks/chunk-QECOQWRJ.js +936 -0
- package/dist/_node-chunks/chunk-QH4V5YDB.js +20 -0
- package/dist/_node-chunks/chunk-R6HWGZWD.js +26 -0
- package/dist/_node-chunks/chunk-SPQXMU2Q.js +759 -0
- package/dist/_node-chunks/chunk-TXZY6V6O.js +1564 -0
- package/dist/_node-chunks/chunk-UGDPX5LE.js +756 -0
- package/dist/_node-chunks/chunk-UY26MQLT.js +603 -0
- package/dist/_node-chunks/chunk-WK3EMYK6.js +61 -0
- package/dist/_node-chunks/{chunk-CJHAP7SE.js → chunk-WLHMN7AP.js} +292 -688
- package/dist/_node-chunks/chunk-XGVLB4UJ.js +54 -0
- package/dist/_node-chunks/{chunk-J7N7PD5Q.js → chunk-YHRFI6BE.js} +87 -227
- package/dist/_node-chunks/chunk-YK4KVMFW.js +18 -0
- package/dist/_node-chunks/chunk-ZZALGOA6.js +4523 -0
- package/dist/_node-chunks/chunk-ZZPBSYA5.js +301 -0
- package/dist/_node-chunks/chunk-ZZSRFAC6.js +45571 -0
- package/dist/_node-chunks/dist-4DWOCZUD.js +121 -0
- package/dist/_node-chunks/globby-AAARUKEU.js +3452 -0
- package/dist/_node-chunks/lib-HEUKGL62.js +366 -0
- package/dist/_node-chunks/mdx-N42X6CFJ-DCVRPS6N.js +14329 -0
- package/dist/_node-chunks/p-limit-F5ZKJ6WZ.js +116 -0
- package/dist/_node-chunks/plugin-7YY7JXCH.js +123 -0
- package/dist/_node-chunks/{plugin-HJLCLGNT.js → plugin-SZP3CW6W.js} +36 -56
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-TGKNDPO6.js +46623 -0
- package/dist/_node-chunks/webpack-mock-plugin-LNTZZFBE.js +92 -0
- package/dist/actions/decorator.js +21 -42
- package/dist/actions/index.js +3 -3
- package/dist/babel/index.d.ts +671 -335
- package/dist/babel/index.js +11 -11
- package/dist/bin/core.js +592 -1546
- package/dist/bin/dispatcher.js +26 -37
- package/dist/bin/loader.js +23 -34
- package/dist/channels/index.js +98 -234
- package/dist/cli/index.js +1966 -5347
- package/dist/client-logger/index.js +31 -61
- package/dist/common/index.d.ts +210 -3
- package/dist/common/index.js +28 -20
- package/dist/components/index.d.ts +472 -280
- package/dist/components/index.js +15992 -75
- package/dist/core-events/index.js +2 -66
- package/dist/core-server/index.js +3837 -7191
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +2511 -5219
- package/dist/core-server/presets/common-override-preset.js +31 -60
- package/dist/core-server/presets/common-preset.js +434 -924
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +15 -19
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +12 -17
- package/dist/csf/index.js +534 -1172
- package/dist/csf-tools/index.d.ts +15 -4
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +6 -6
- package/dist/highlight/index.js +2 -2
- package/dist/instrumenter/index.js +199 -415
- package/dist/manager/globals-runtime.js +47968 -56484
- package/dist/manager/globals.js +2 -3
- package/dist/manager/runtime.js +4901 -10318
- package/dist/manager-api/index.d.ts +11 -3
- package/dist/manager-api/index.js +1250 -2397
- package/dist/manager-errors.d.ts +3 -0
- package/dist/manager-errors.js +3 -3
- package/dist/node-logger/index.d.ts +1 -1
- package/dist/node-logger/index.js +1270 -2593
- package/dist/preview/globals.js +2 -3
- package/dist/preview/runtime.js +10767 -22386
- package/dist/preview-api/index.d.ts +67 -68
- package/dist/preview-api/index.js +15 -15
- package/dist/preview-errors.d.ts +3 -0
- package/dist/preview-errors.js +4 -4
- package/dist/router/index.js +347 -899
- package/dist/server-errors.d.ts +3 -0
- package/dist/server-errors.js +10 -10
- package/dist/telemetry/index.js +24 -24
- package/dist/test/index.js +6129 -11914
- package/dist/theming/create.d.ts +4 -2
- package/dist/theming/create.js +4 -4
- package/dist/theming/index.d.ts +3397 -2628
- package/dist/theming/index.js +502 -1091
- package/dist/types/index.d.ts +50 -5
- package/dist/types/index.js +2 -11
- package/dist/viewport/index.js +3 -3
- package/package.json +17 -9
- package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
- package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
- package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
- package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
- package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
- package/dist/_browser-chunks/chunk-C4XOKMDU.js +0 -270
- package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
- package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
- package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
- package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
- package/dist/_browser-chunks/chunk-I74EUU5O.js +0 -5809
- package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
- package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
- package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
- package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
- package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
- package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
- package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
- package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
- package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
- package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
- package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
- package/dist/_browser-chunks/chunk-W4QKLQSC.js +0 -4182
- package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
- package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
- package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
- package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
- package/dist/_node-chunks/camelcase-WKJOVNPM.js +0 -18
- package/dist/_node-chunks/chunk-2RIKHYCS.js +0 -304
- package/dist/_node-chunks/chunk-3JCSHYSU.js +0 -1657
- package/dist/_node-chunks/chunk-4GE6Q4MX.js +0 -1531
- package/dist/_node-chunks/chunk-5SEHHENC.js +0 -64656
- package/dist/_node-chunks/chunk-6GD23U64.js +0 -420
- package/dist/_node-chunks/chunk-6OAXYS5T.js +0 -1544
- package/dist/_node-chunks/chunk-7TNUMFKR.js +0 -4741
- package/dist/_node-chunks/chunk-BCDHUXAJ.js +0 -4272
- package/dist/_node-chunks/chunk-BYVQZ2HU.js +0 -220
- package/dist/_node-chunks/chunk-DAMVKHAC.js +0 -101
- package/dist/_node-chunks/chunk-FEOC7OX2.js +0 -1586
- package/dist/_node-chunks/chunk-FY7XZPLY.js +0 -2248
- package/dist/_node-chunks/chunk-GD2FXWDF.js +0 -697
- package/dist/_node-chunks/chunk-HM6B7FE5.js +0 -18
- package/dist/_node-chunks/chunk-HORWITP7.js +0 -90
- package/dist/_node-chunks/chunk-II4AFH3V.js +0 -28
- package/dist/_node-chunks/chunk-MF2PUEWG.js +0 -5029
- package/dist/_node-chunks/chunk-RVE4UTVQ.js +0 -1518
- package/dist/_node-chunks/chunk-TUFWZUTO.js +0 -69
- package/dist/_node-chunks/chunk-TXHNWNH4.js +0 -79
- package/dist/_node-chunks/chunk-ULWNTI6M.js +0 -1198
- package/dist/_node-chunks/chunk-VYRFXLRO.js +0 -6712
- package/dist/_node-chunks/chunk-WNOSTIYP.js +0 -34
- package/dist/_node-chunks/chunk-X67VGZN4.js +0 -1250
- package/dist/_node-chunks/chunk-XCEBYOA4.js +0 -61
- package/dist/_node-chunks/chunk-XW7YMR7I.js +0 -111
- package/dist/_node-chunks/chunk-ZRFYQ46H.js +0 -61
- package/dist/_node-chunks/dist-APCKHSY3.js +0 -175
- package/dist/_node-chunks/globby-TSGXGDA2.js +0 -5222
- package/dist/_node-chunks/lib-DZ5TVIU5.js +0 -518
- package/dist/_node-chunks/mdx-N42X6CFJ-Z6BYQCPN.js +0 -22017
- package/dist/_node-chunks/p-limit-MLJNGG2K.js +0 -168
- package/dist/_node-chunks/plugin-J3JI3ZKJ.js +0 -159
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-3QHNTM5B.js +0 -69102
- package/dist/_node-chunks/webpack-mock-plugin-4Y3MWPJ6.js +0 -124
|
@@ -1,2248 +0,0 @@
|
|
|
1
|
-
import CJS_COMPAT_NODE_URL_in4hyfgp7kn from 'node:url';
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_in4hyfgp7kn from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_in4hyfgp7kn from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_in4hyfgp7kn.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_in4hyfgp7kn.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_in4hyfgp7kn.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
import {
|
|
13
|
-
require_dist
|
|
14
|
-
} from "./chunk-TUFWZUTO.js";
|
|
15
|
-
import {
|
|
16
|
-
__name,
|
|
17
|
-
__toESM
|
|
18
|
-
} from "./chunk-XCEBYOA4.js";
|
|
19
|
-
|
|
20
|
-
// src/csf-tools/CsfFile.ts
|
|
21
|
-
var import_ts_dedent = __toESM(require_dist(), 1);
|
|
22
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
23
|
-
import {
|
|
24
|
-
BabelFileClass,
|
|
25
|
-
babelParse,
|
|
26
|
-
generate,
|
|
27
|
-
recast,
|
|
28
|
-
types as t2,
|
|
29
|
-
traverse
|
|
30
|
-
} from "storybook/internal/babel";
|
|
31
|
-
import { isExportStory, storyNameFromExport, toId, toTestId } from "storybook/internal/csf";
|
|
32
|
-
import { logger } from "storybook/internal/node-logger";
|
|
33
|
-
|
|
34
|
-
// src/csf-tools/findVarInitialization.ts
|
|
35
|
-
import { types as t } from "storybook/internal/babel";
|
|
36
|
-
var findVarInitialization = /* @__PURE__ */ __name((identifier, program) => {
|
|
37
|
-
let init = null;
|
|
38
|
-
let declarations = null;
|
|
39
|
-
program.body.find((node) => {
|
|
40
|
-
if (t.isVariableDeclaration(node)) {
|
|
41
|
-
declarations = node.declarations;
|
|
42
|
-
} else if (t.isExportNamedDeclaration(node) && t.isVariableDeclaration(node.declaration)) {
|
|
43
|
-
declarations = node.declaration.declarations;
|
|
44
|
-
}
|
|
45
|
-
return declarations && declarations.find((decl) => {
|
|
46
|
-
if (t.isVariableDeclarator(decl) && t.isIdentifier(decl.id) && decl.id.name === identifier) {
|
|
47
|
-
init = decl.init;
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
return init;
|
|
54
|
-
}, "findVarInitialization");
|
|
55
|
-
|
|
56
|
-
// src/csf-tools/CsfFile.ts
|
|
57
|
-
var PREVIEW_FILE_REGEX = /\/preview(.(js|jsx|mjs|ts|tsx))?$/;
|
|
58
|
-
var isValidPreviewPath = /* @__PURE__ */ __name((filepath) => PREVIEW_FILE_REGEX.test(filepath), "isValidPreviewPath");
|
|
59
|
-
function parseIncludeExclude(prop) {
|
|
60
|
-
if (t2.isArrayExpression(prop)) {
|
|
61
|
-
return prop.elements.map((e) => {
|
|
62
|
-
if (t2.isStringLiteral(e)) {
|
|
63
|
-
return e.value;
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Expected string literal: ${e}`);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (t2.isStringLiteral(prop)) {
|
|
69
|
-
return new RegExp(prop.value);
|
|
70
|
-
}
|
|
71
|
-
if (t2.isRegExpLiteral(prop)) {
|
|
72
|
-
return new RegExp(prop.pattern, prop.flags);
|
|
73
|
-
}
|
|
74
|
-
throw new Error(`Unknown include/exclude: ${prop}`);
|
|
75
|
-
}
|
|
76
|
-
__name(parseIncludeExclude, "parseIncludeExclude");
|
|
77
|
-
function parseTags(prop) {
|
|
78
|
-
if (!t2.isArrayExpression(prop)) {
|
|
79
|
-
throw new Error("CSF: Expected tags array");
|
|
80
|
-
}
|
|
81
|
-
return prop.elements.map((e) => {
|
|
82
|
-
if (t2.isStringLiteral(e)) {
|
|
83
|
-
return e.value;
|
|
84
|
-
}
|
|
85
|
-
throw new Error(`CSF: Expected tag to be string literal`);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
__name(parseTags, "parseTags");
|
|
89
|
-
function parseTestTags(optionsNode, program) {
|
|
90
|
-
if (!optionsNode) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
let node = optionsNode;
|
|
94
|
-
if (t2.isIdentifier(node)) {
|
|
95
|
-
node = findVarInitialization(node.name, program);
|
|
96
|
-
}
|
|
97
|
-
if (t2.isObjectExpression(node)) {
|
|
98
|
-
const tagsProp = node.properties.find(
|
|
99
|
-
(property) => t2.isObjectProperty(property) && t2.isIdentifier(property.key) && property.key.name === "tags"
|
|
100
|
-
);
|
|
101
|
-
if (tagsProp) {
|
|
102
|
-
let tagsNode = tagsProp.value;
|
|
103
|
-
if (t2.isIdentifier(tagsNode)) {
|
|
104
|
-
tagsNode = findVarInitialization(tagsNode.name, program);
|
|
105
|
-
}
|
|
106
|
-
return parseTags(tagsNode);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
__name(parseTestTags, "parseTestTags");
|
|
112
|
-
var formatLocation = /* @__PURE__ */ __name((node, fileName) => {
|
|
113
|
-
let loc = "";
|
|
114
|
-
if (node.loc) {
|
|
115
|
-
const { line, column } = node.loc?.start || {};
|
|
116
|
-
loc = `(line ${line}, col ${column})`;
|
|
117
|
-
}
|
|
118
|
-
return `${fileName || ""} ${loc}`.trim();
|
|
119
|
-
}, "formatLocation");
|
|
120
|
-
var isModuleMock = /* @__PURE__ */ __name((importPath) => MODULE_MOCK_REGEX.test(importPath), "isModuleMock");
|
|
121
|
-
var isArgsStory = /* @__PURE__ */ __name((init, parent, csf) => {
|
|
122
|
-
let storyFn = init;
|
|
123
|
-
if (t2.isCallExpression(init)) {
|
|
124
|
-
const { callee, arguments: bindArguments } = init;
|
|
125
|
-
if (t2.isProgram(parent) && t2.isMemberExpression(callee) && t2.isIdentifier(callee.object) && t2.isIdentifier(callee.property) && callee.property.name === "bind" && (bindArguments.length === 0 || bindArguments.length === 1 && t2.isObjectExpression(bindArguments[0]) && bindArguments[0].properties.length === 0)) {
|
|
126
|
-
const boundIdentifier = callee.object.name;
|
|
127
|
-
const template = findVarInitialization(boundIdentifier, parent);
|
|
128
|
-
if (template) {
|
|
129
|
-
csf._templates[boundIdentifier] = template;
|
|
130
|
-
storyFn = template;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (t2.isArrowFunctionExpression(storyFn)) {
|
|
135
|
-
return storyFn.params.length > 0;
|
|
136
|
-
}
|
|
137
|
-
if (t2.isFunctionDeclaration(storyFn)) {
|
|
138
|
-
return storyFn.params.length > 0;
|
|
139
|
-
}
|
|
140
|
-
return false;
|
|
141
|
-
}, "isArgsStory");
|
|
142
|
-
var parseExportsOrder = /* @__PURE__ */ __name((init) => {
|
|
143
|
-
if (t2.isArrayExpression(init)) {
|
|
144
|
-
return init.elements.map((item) => {
|
|
145
|
-
if (t2.isStringLiteral(item)) {
|
|
146
|
-
return item.value;
|
|
147
|
-
}
|
|
148
|
-
throw new Error(`Expected string literal named export: ${item}`);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
throw new Error(`Expected array of string literals: ${init}`);
|
|
152
|
-
}, "parseExportsOrder");
|
|
153
|
-
var sortExports = /* @__PURE__ */ __name((exportByName, order) => {
|
|
154
|
-
return order.reduce(
|
|
155
|
-
(acc, name) => {
|
|
156
|
-
const namedExport = exportByName[name];
|
|
157
|
-
if (namedExport) {
|
|
158
|
-
acc[name] = namedExport;
|
|
159
|
-
}
|
|
160
|
-
return acc;
|
|
161
|
-
},
|
|
162
|
-
{}
|
|
163
|
-
);
|
|
164
|
-
}, "sortExports");
|
|
165
|
-
var hasMount = /* @__PURE__ */ __name((play) => {
|
|
166
|
-
if (t2.isArrowFunctionExpression(play) || t2.isFunctionDeclaration(play) || t2.isObjectMethod(play)) {
|
|
167
|
-
const params = play.params;
|
|
168
|
-
if (params.length >= 1) {
|
|
169
|
-
const [arg] = params;
|
|
170
|
-
if (t2.isObjectPattern(arg)) {
|
|
171
|
-
return !!arg.properties.find((prop) => {
|
|
172
|
-
if (t2.isObjectProperty(prop) && t2.isIdentifier(prop.key)) {
|
|
173
|
-
return prop.key.name === "mount";
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
}, "hasMount");
|
|
181
|
-
var MODULE_MOCK_REGEX = /^[.\/#].*\.mock($|\.[^.]*$)/i;
|
|
182
|
-
var NoMetaError = class extends Error {
|
|
183
|
-
static {
|
|
184
|
-
__name(this, "NoMetaError");
|
|
185
|
-
}
|
|
186
|
-
constructor(message, ast, fileName) {
|
|
187
|
-
const msg = message.trim();
|
|
188
|
-
super(import_ts_dedent.dedent`
|
|
189
|
-
CSF: ${msg} ${formatLocation(ast, fileName)}
|
|
190
|
-
|
|
191
|
-
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
192
|
-
`);
|
|
193
|
-
this.name = this.constructor.name;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
var MultipleMetaError = class extends Error {
|
|
197
|
-
static {
|
|
198
|
-
__name(this, "MultipleMetaError");
|
|
199
|
-
}
|
|
200
|
-
constructor(message, ast, fileName) {
|
|
201
|
-
const msg = `${message} ${formatLocation(ast, fileName)}`.trim();
|
|
202
|
-
super(import_ts_dedent.dedent`
|
|
203
|
-
CSF: ${message} ${formatLocation(ast, fileName)}
|
|
204
|
-
|
|
205
|
-
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
206
|
-
`);
|
|
207
|
-
this.name = this.constructor.name;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
var MixedFactoryError = class extends Error {
|
|
211
|
-
static {
|
|
212
|
-
__name(this, "MixedFactoryError");
|
|
213
|
-
}
|
|
214
|
-
constructor(message, ast, fileName) {
|
|
215
|
-
const msg = `${message} ${formatLocation(ast, fileName)}`.trim();
|
|
216
|
-
super(import_ts_dedent.dedent`
|
|
217
|
-
CSF: ${message} ${formatLocation(ast, fileName)}
|
|
218
|
-
|
|
219
|
-
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
220
|
-
`);
|
|
221
|
-
this.name = this.constructor.name;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
var BadMetaError = class extends Error {
|
|
225
|
-
static {
|
|
226
|
-
__name(this, "BadMetaError");
|
|
227
|
-
}
|
|
228
|
-
constructor(message, ast, fileName) {
|
|
229
|
-
const msg = ``.trim();
|
|
230
|
-
super(import_ts_dedent.dedent`
|
|
231
|
-
CSF: ${message} ${formatLocation(ast, fileName)}
|
|
232
|
-
|
|
233
|
-
More info: https://storybook.js.org/docs/writing-stories?ref=error#default-export
|
|
234
|
-
`);
|
|
235
|
-
this.name = this.constructor.name;
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
var CsfFile = class {
|
|
239
|
-
constructor(ast, options, file) {
|
|
240
|
-
this._stories = {};
|
|
241
|
-
this._metaAnnotations = {};
|
|
242
|
-
this._storyExports = {};
|
|
243
|
-
this._storyPaths = {};
|
|
244
|
-
this._storyStatements = {};
|
|
245
|
-
this._storyAnnotations = {};
|
|
246
|
-
this._templates = {};
|
|
247
|
-
this._tests = [];
|
|
248
|
-
this._ast = ast;
|
|
249
|
-
this._file = file;
|
|
250
|
-
this._options = options;
|
|
251
|
-
this.imports = [];
|
|
252
|
-
}
|
|
253
|
-
static {
|
|
254
|
-
__name(this, "CsfFile");
|
|
255
|
-
}
|
|
256
|
-
_parseTitle(value) {
|
|
257
|
-
const node = t2.isIdentifier(value) ? findVarInitialization(value.name, this._ast.program) : value;
|
|
258
|
-
if (t2.isStringLiteral(node)) {
|
|
259
|
-
return node.value;
|
|
260
|
-
}
|
|
261
|
-
if (t2.isTSSatisfiesExpression(node) && t2.isStringLiteral(node.expression)) {
|
|
262
|
-
return node.expression.value;
|
|
263
|
-
}
|
|
264
|
-
throw new Error(import_ts_dedent.dedent`
|
|
265
|
-
CSF: unexpected dynamic title ${formatLocation(node, this._options.fileName)}
|
|
266
|
-
|
|
267
|
-
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
|
|
268
|
-
`);
|
|
269
|
-
}
|
|
270
|
-
_parseMeta(declaration, program) {
|
|
271
|
-
if (this._metaNode) {
|
|
272
|
-
throw new MultipleMetaError("multiple meta objects", declaration, this._options.fileName);
|
|
273
|
-
}
|
|
274
|
-
this._metaNode = declaration;
|
|
275
|
-
const meta = {};
|
|
276
|
-
declaration.properties.forEach((p) => {
|
|
277
|
-
if (t2.isIdentifier(p.key)) {
|
|
278
|
-
const value = t2.isObjectMethod(p) ? p : p.value;
|
|
279
|
-
this._metaAnnotations[p.key.name] = value;
|
|
280
|
-
if (p.key.name === "title") {
|
|
281
|
-
meta.title = this._parseTitle(p.value);
|
|
282
|
-
} else if (["includeStories", "excludeStories"].includes(p.key.name)) {
|
|
283
|
-
meta[p.key.name] = parseIncludeExclude(p.value);
|
|
284
|
-
} else if (p.key.name === "component") {
|
|
285
|
-
const n = p.value;
|
|
286
|
-
if (t2.isIdentifier(n)) {
|
|
287
|
-
const id = n.name;
|
|
288
|
-
const importStmt = program.body.find(
|
|
289
|
-
(stmt) => t2.isImportDeclaration(stmt) && stmt.specifiers.find((spec) => spec.local.name === id)
|
|
290
|
-
);
|
|
291
|
-
if (importStmt) {
|
|
292
|
-
const { source } = importStmt;
|
|
293
|
-
if (t2.isStringLiteral(source)) {
|
|
294
|
-
this._rawComponentPath = source.value;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const { code } = recast.print(p.value, {});
|
|
299
|
-
meta.component = code;
|
|
300
|
-
} else if (p.key.name === "tags") {
|
|
301
|
-
let node = p.value;
|
|
302
|
-
if (t2.isIdentifier(node)) {
|
|
303
|
-
node = findVarInitialization(node.name, this._ast.program);
|
|
304
|
-
}
|
|
305
|
-
meta.tags = parseTags(node);
|
|
306
|
-
} else if (p.key.name === "id") {
|
|
307
|
-
if (t2.isStringLiteral(p.value)) {
|
|
308
|
-
meta.id = p.value.value;
|
|
309
|
-
} else {
|
|
310
|
-
throw new Error(`Unexpected component id: ${p.value}`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
this._meta = meta;
|
|
316
|
-
}
|
|
317
|
-
getStoryExport(key) {
|
|
318
|
-
let node = this._storyExports[key];
|
|
319
|
-
node = t2.isVariableDeclarator(node) ? node.init : node;
|
|
320
|
-
if (t2.isCallExpression(node)) {
|
|
321
|
-
const { callee, arguments: bindArguments } = node;
|
|
322
|
-
if (t2.isMemberExpression(callee) && t2.isIdentifier(callee.object) && t2.isIdentifier(callee.property) && callee.property.name === "bind" && (bindArguments.length === 0 || bindArguments.length === 1 && t2.isObjectExpression(bindArguments[0]) && bindArguments[0].properties.length === 0)) {
|
|
323
|
-
const { name } = callee.object;
|
|
324
|
-
node = this._templates[name];
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return node;
|
|
328
|
-
}
|
|
329
|
-
parse() {
|
|
330
|
-
const self = this;
|
|
331
|
-
traverse(this._ast, {
|
|
332
|
-
ExportDefaultDeclaration: {
|
|
333
|
-
enter(path) {
|
|
334
|
-
const { node, parent } = path;
|
|
335
|
-
const isVariableReference = t2.isIdentifier(node.declaration) && t2.isProgram(parent);
|
|
336
|
-
if (self._options.transformInlineMeta && !isVariableReference && t2.isExpression(node.declaration)) {
|
|
337
|
-
const metaId = path.scope.generateUidIdentifier("meta");
|
|
338
|
-
self._metaVariableName = metaId.name;
|
|
339
|
-
const nodes = [
|
|
340
|
-
t2.variableDeclaration("const", [t2.variableDeclarator(metaId, node.declaration)]),
|
|
341
|
-
t2.exportDefaultDeclaration(metaId)
|
|
342
|
-
];
|
|
343
|
-
nodes.forEach((_node) => _node.loc = path.node.loc);
|
|
344
|
-
path.replaceWithMultiple(nodes);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
let metaNode;
|
|
348
|
-
let decl;
|
|
349
|
-
if (isVariableReference) {
|
|
350
|
-
const variableName = node.declaration.name;
|
|
351
|
-
self._metaVariableName = variableName;
|
|
352
|
-
const isVariableDeclarator = /* @__PURE__ */ __name((declaration) => t2.isIdentifier(declaration.id) && declaration.id.name === variableName, "isVariableDeclarator");
|
|
353
|
-
self._metaStatement = self._ast.program.body.find(
|
|
354
|
-
(topLevelNode) => t2.isVariableDeclaration(topLevelNode) && topLevelNode.declarations.find(isVariableDeclarator)
|
|
355
|
-
);
|
|
356
|
-
decl = (self?._metaStatement?.declarations || []).find(
|
|
357
|
-
isVariableDeclarator
|
|
358
|
-
)?.init;
|
|
359
|
-
} else {
|
|
360
|
-
self._metaStatement = node;
|
|
361
|
-
decl = node.declaration;
|
|
362
|
-
}
|
|
363
|
-
if (t2.isObjectExpression(decl)) {
|
|
364
|
-
metaNode = decl;
|
|
365
|
-
} else if (
|
|
366
|
-
// export default { ... } as Meta<...>
|
|
367
|
-
// export default { ... } satisfies Meta<...>
|
|
368
|
-
(t2.isTSAsExpression(decl) || t2.isTSSatisfiesExpression(decl)) && t2.isObjectExpression(decl.expression)
|
|
369
|
-
) {
|
|
370
|
-
metaNode = decl.expression;
|
|
371
|
-
} else if (
|
|
372
|
-
// export default { ... } satisfies Meta as Meta<...>
|
|
373
|
-
t2.isTSAsExpression(decl) && t2.isTSSatisfiesExpression(decl.expression) && t2.isObjectExpression(decl.expression.expression)
|
|
374
|
-
) {
|
|
375
|
-
metaNode = decl.expression.expression;
|
|
376
|
-
}
|
|
377
|
-
if (metaNode && t2.isProgram(parent)) {
|
|
378
|
-
self._parseMeta(metaNode, parent);
|
|
379
|
-
}
|
|
380
|
-
if (self._metaStatement && !self._metaNode) {
|
|
381
|
-
throw new NoMetaError(
|
|
382
|
-
"default export must be an object",
|
|
383
|
-
self._metaStatement,
|
|
384
|
-
self._options.fileName
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
self._metaPath = path;
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
ExportNamedDeclaration: {
|
|
391
|
-
enter(path) {
|
|
392
|
-
const { node, parent } = path;
|
|
393
|
-
let declarations;
|
|
394
|
-
if (t2.isVariableDeclaration(node.declaration)) {
|
|
395
|
-
declarations = node.declaration.declarations.filter((d) => t2.isVariableDeclarator(d));
|
|
396
|
-
} else if (t2.isFunctionDeclaration(node.declaration)) {
|
|
397
|
-
declarations = [node.declaration];
|
|
398
|
-
}
|
|
399
|
-
if (declarations) {
|
|
400
|
-
declarations.forEach((decl) => {
|
|
401
|
-
if (t2.isIdentifier(decl.id)) {
|
|
402
|
-
let storyIsFactory = false;
|
|
403
|
-
const { name: exportName } = decl.id;
|
|
404
|
-
if (exportName === "__namedExportsOrder" && t2.isVariableDeclarator(decl)) {
|
|
405
|
-
self._namedExportsOrder = parseExportsOrder(decl.init);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
self._storyExports[exportName] = decl;
|
|
409
|
-
self._storyPaths[exportName] = path;
|
|
410
|
-
self._storyStatements[exportName] = node;
|
|
411
|
-
let name = storyNameFromExport(exportName);
|
|
412
|
-
if (self._storyAnnotations[exportName]) {
|
|
413
|
-
logger.warn(
|
|
414
|
-
`Unexpected annotations for "${exportName}" before story declaration`
|
|
415
|
-
);
|
|
416
|
-
} else {
|
|
417
|
-
self._storyAnnotations[exportName] = {};
|
|
418
|
-
}
|
|
419
|
-
let storyNode;
|
|
420
|
-
if (t2.isVariableDeclarator(decl)) {
|
|
421
|
-
if (t2.isTSAsExpression(decl.init) && t2.isTSSatisfiesExpression(decl.init.expression)) {
|
|
422
|
-
storyNode = decl.init.expression.expression;
|
|
423
|
-
} else if (t2.isTSAsExpression(decl.init) || t2.isTSSatisfiesExpression(decl.init)) {
|
|
424
|
-
storyNode = decl.init.expression;
|
|
425
|
-
} else {
|
|
426
|
-
storyNode = decl.init;
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
storyNode = decl;
|
|
430
|
-
}
|
|
431
|
-
if (t2.isCallExpression(storyNode) && t2.isMemberExpression(storyNode.callee) && t2.isIdentifier(storyNode.callee.property) && (storyNode.callee.property.name === "story" || storyNode.callee.property.name === "extend")) {
|
|
432
|
-
storyIsFactory = true;
|
|
433
|
-
storyNode = storyNode.arguments[0];
|
|
434
|
-
}
|
|
435
|
-
if (self._metaIsFactory && !storyIsFactory) {
|
|
436
|
-
throw new MixedFactoryError(
|
|
437
|
-
"expected factory story",
|
|
438
|
-
storyNode,
|
|
439
|
-
self._options.fileName
|
|
440
|
-
);
|
|
441
|
-
} else if (!self._metaIsFactory && storyIsFactory) {
|
|
442
|
-
if (self._metaNode) {
|
|
443
|
-
throw new MixedFactoryError(
|
|
444
|
-
"expected non-factory story",
|
|
445
|
-
storyNode,
|
|
446
|
-
self._options.fileName
|
|
447
|
-
);
|
|
448
|
-
} else {
|
|
449
|
-
throw new BadMetaError(
|
|
450
|
-
"meta() factory must be imported from .storybook/preview configuration",
|
|
451
|
-
storyNode,
|
|
452
|
-
self._options.fileName
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
const parameters = {};
|
|
457
|
-
if (t2.isObjectExpression(storyNode)) {
|
|
458
|
-
parameters.__isArgsStory = true;
|
|
459
|
-
storyNode.properties.forEach((p) => {
|
|
460
|
-
if (t2.isIdentifier(p.key)) {
|
|
461
|
-
const key = p.key.name;
|
|
462
|
-
if (t2.isObjectMethod(p)) {
|
|
463
|
-
self._storyAnnotations[exportName][key] = p;
|
|
464
|
-
} else {
|
|
465
|
-
if (p.key.name === "render") {
|
|
466
|
-
parameters.__isArgsStory = isArgsStory(
|
|
467
|
-
p.value,
|
|
468
|
-
parent,
|
|
469
|
-
self
|
|
470
|
-
);
|
|
471
|
-
} else if (p.key.name === "name" && t2.isStringLiteral(p.value)) {
|
|
472
|
-
name = p.value.value;
|
|
473
|
-
} else if (p.key.name === "storyName" && t2.isStringLiteral(p.value)) {
|
|
474
|
-
logger.warn(
|
|
475
|
-
`Unexpected usage of "storyName" in "${exportName}". Please use "name" instead.`
|
|
476
|
-
);
|
|
477
|
-
} else if (p.key.name === "parameters" && t2.isObjectExpression(p.value)) {
|
|
478
|
-
const idProperty = p.value.properties.find(
|
|
479
|
-
(property) => t2.isObjectProperty(property) && t2.isIdentifier(property.key) && property.key.name === "__id"
|
|
480
|
-
);
|
|
481
|
-
if (idProperty) {
|
|
482
|
-
parameters.__id = idProperty.value.value;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
self._storyAnnotations[exportName][p.key.name] = p.value;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
} else {
|
|
490
|
-
parameters.__isArgsStory = isArgsStory(storyNode, parent, self);
|
|
491
|
-
}
|
|
492
|
-
self._stories[exportName] = {
|
|
493
|
-
id: "FIXME",
|
|
494
|
-
name,
|
|
495
|
-
parameters,
|
|
496
|
-
__stats: {
|
|
497
|
-
factory: storyIsFactory
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
} else if (node.specifiers.length > 0) {
|
|
503
|
-
node.specifiers.forEach((specifier) => {
|
|
504
|
-
if (t2.isExportSpecifier(specifier) && t2.isIdentifier(specifier.exported)) {
|
|
505
|
-
const { name: exportName } = specifier.exported;
|
|
506
|
-
const { name: localName } = specifier.local;
|
|
507
|
-
const decl = t2.isProgram(parent) ? findVarInitialization(localName, parent) : specifier.local;
|
|
508
|
-
if (exportName === "default") {
|
|
509
|
-
let metaNode;
|
|
510
|
-
if (t2.isObjectExpression(decl)) {
|
|
511
|
-
metaNode = decl;
|
|
512
|
-
} else if (
|
|
513
|
-
// export default { ... } as Meta<...>
|
|
514
|
-
// export default { ... } satisfies Meta<...>
|
|
515
|
-
(t2.isTSAsExpression(decl) || t2.isTSSatisfiesExpression(decl)) && t2.isObjectExpression(decl.expression)
|
|
516
|
-
) {
|
|
517
|
-
metaNode = decl.expression;
|
|
518
|
-
} else if (
|
|
519
|
-
// export default { ... } satisfies Meta as Meta<...>
|
|
520
|
-
t2.isTSAsExpression(decl) && t2.isTSSatisfiesExpression(decl.expression) && t2.isObjectExpression(decl.expression.expression)
|
|
521
|
-
) {
|
|
522
|
-
metaNode = decl.expression.expression;
|
|
523
|
-
}
|
|
524
|
-
if (metaNode && t2.isProgram(parent)) {
|
|
525
|
-
self._parseMeta(metaNode, parent);
|
|
526
|
-
}
|
|
527
|
-
} else {
|
|
528
|
-
const annotations = {};
|
|
529
|
-
const storyNode = decl;
|
|
530
|
-
if (t2.isObjectExpression(storyNode)) {
|
|
531
|
-
storyNode.properties.forEach((p) => {
|
|
532
|
-
if (t2.isIdentifier(p.key)) {
|
|
533
|
-
annotations[p.key.name] = p.value;
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
self._storyAnnotations[exportName] = annotations;
|
|
538
|
-
self._storyStatements[exportName] = decl;
|
|
539
|
-
self._storyPaths[exportName] = path;
|
|
540
|
-
self._stories[exportName] = {
|
|
541
|
-
id: "FIXME",
|
|
542
|
-
name: exportName,
|
|
543
|
-
localName,
|
|
544
|
-
parameters: {},
|
|
545
|
-
__stats: {}
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
},
|
|
553
|
-
ExpressionStatement: {
|
|
554
|
-
enter({ node, parent }) {
|
|
555
|
-
const { expression } = node;
|
|
556
|
-
if (t2.isProgram(parent) && t2.isAssignmentExpression(expression) && t2.isMemberExpression(expression.left) && t2.isIdentifier(expression.left.object) && t2.isIdentifier(expression.left.property)) {
|
|
557
|
-
const exportName = expression.left.object.name;
|
|
558
|
-
const annotationKey = expression.left.property.name;
|
|
559
|
-
const annotationValue = expression.right;
|
|
560
|
-
if (self._storyAnnotations[exportName]) {
|
|
561
|
-
if (annotationKey === "story" && t2.isObjectExpression(annotationValue)) {
|
|
562
|
-
annotationValue.properties.forEach((prop) => {
|
|
563
|
-
if (t2.isIdentifier(prop.key)) {
|
|
564
|
-
self._storyAnnotations[exportName][prop.key.name] = prop.value;
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
} else {
|
|
568
|
-
self._storyAnnotations[exportName][annotationKey] = annotationValue;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
if (annotationKey === "storyName" && t2.isStringLiteral(annotationValue)) {
|
|
572
|
-
const storyName = annotationValue.value;
|
|
573
|
-
const story = self._stories[exportName];
|
|
574
|
-
if (!story) {
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
story.name = storyName;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
if (t2.isCallExpression(expression) && t2.isMemberExpression(expression.callee) && t2.isIdentifier(expression.callee.object) && t2.isIdentifier(expression.callee.property) && expression.callee.property.name === "test" && expression.arguments.length >= 2 && t2.isStringLiteral(expression.arguments[0])) {
|
|
581
|
-
const exportName = expression.callee.object.name;
|
|
582
|
-
const testName = expression.arguments[0].value;
|
|
583
|
-
const testFunction = expression.arguments.length === 2 ? expression.arguments[1] : expression.arguments[2];
|
|
584
|
-
const testArguments = expression.arguments.length === 2 ? null : expression.arguments[1];
|
|
585
|
-
const tags = parseTestTags(testArguments, self._ast.program);
|
|
586
|
-
self._tests.push({
|
|
587
|
-
function: testFunction,
|
|
588
|
-
name: testName,
|
|
589
|
-
node: expression,
|
|
590
|
-
// can't set id because meta title isn't available yet
|
|
591
|
-
// so it's set later on
|
|
592
|
-
id: "FIXME",
|
|
593
|
-
tags,
|
|
594
|
-
parent: { node: self._storyStatements[exportName] }
|
|
595
|
-
});
|
|
596
|
-
self._stories[exportName].__stats.tests = true;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
},
|
|
600
|
-
CallExpression: {
|
|
601
|
-
enter(path) {
|
|
602
|
-
const { node } = path;
|
|
603
|
-
const { callee } = node;
|
|
604
|
-
if (t2.isIdentifier(callee) && callee.name === "storiesOf") {
|
|
605
|
-
throw new Error(import_ts_dedent.dedent`
|
|
606
|
-
Unexpected \`storiesOf\` usage: ${formatLocation(node, self._options.fileName)}.
|
|
607
|
-
|
|
608
|
-
SB8 does not support \`storiesOf\`.
|
|
609
|
-
`);
|
|
610
|
-
}
|
|
611
|
-
if (t2.isMemberExpression(callee) && t2.isIdentifier(callee.property) && callee.property.name === "meta" && t2.isIdentifier(callee.object) && node.arguments.length > 0) {
|
|
612
|
-
const configCandidate = path.scope.getBinding(callee.object.name);
|
|
613
|
-
const configParent = configCandidate?.path?.parentPath?.node;
|
|
614
|
-
if (t2.isImportDeclaration(configParent)) {
|
|
615
|
-
if (isValidPreviewPath(configParent.source.value)) {
|
|
616
|
-
self._metaIsFactory = true;
|
|
617
|
-
const metaDeclarator = path.findParent(
|
|
618
|
-
(p) => p.isVariableDeclarator()
|
|
619
|
-
);
|
|
620
|
-
self._metaVariableName = t2.isIdentifier(metaDeclarator.node.id) ? metaDeclarator.node.id.name : callee.property.name;
|
|
621
|
-
const metaNode = node.arguments[0];
|
|
622
|
-
self._parseMeta(metaNode, self._ast.program);
|
|
623
|
-
} else {
|
|
624
|
-
throw new BadMetaError(
|
|
625
|
-
"meta() factory must be imported from .storybook/preview configuration",
|
|
626
|
-
configParent,
|
|
627
|
-
self._options.fileName
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
},
|
|
634
|
-
ImportDeclaration: {
|
|
635
|
-
enter({ node }) {
|
|
636
|
-
const { source } = node;
|
|
637
|
-
if (t2.isStringLiteral(source)) {
|
|
638
|
-
self.imports.push(source.value);
|
|
639
|
-
} else {
|
|
640
|
-
throw new Error("CSF: unexpected import source");
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
if (!self._meta) {
|
|
646
|
-
throw new NoMetaError("missing default export", self._ast, self._options.fileName);
|
|
647
|
-
}
|
|
648
|
-
const entries = Object.entries(self._stories);
|
|
649
|
-
self._meta.title = this._options.makeTitle(self._meta?.title);
|
|
650
|
-
if (self._metaAnnotations.play) {
|
|
651
|
-
self._meta.tags = [...self._meta.tags || [], "play-fn"];
|
|
652
|
-
}
|
|
653
|
-
self._stories = entries.reduce(
|
|
654
|
-
(acc, [key, story]) => {
|
|
655
|
-
if (!isExportStory(key, self._meta)) {
|
|
656
|
-
return acc;
|
|
657
|
-
}
|
|
658
|
-
const id = story.parameters?.__id ?? toId(self._meta?.id || self._meta?.title, storyNameFromExport(key));
|
|
659
|
-
const parameters = { ...story.parameters, __id: id };
|
|
660
|
-
const { includeStories } = self._meta || {};
|
|
661
|
-
if (key === "__page" && (entries.length === 1 || Array.isArray(includeStories) && includeStories.length === 1)) {
|
|
662
|
-
parameters.docsOnly = true;
|
|
663
|
-
}
|
|
664
|
-
acc[key] = { ...story, id, parameters };
|
|
665
|
-
const storyAnnotations = self._storyAnnotations[key];
|
|
666
|
-
const { tags, play } = storyAnnotations;
|
|
667
|
-
if (tags) {
|
|
668
|
-
const node = t2.isIdentifier(tags) ? findVarInitialization(tags.name, this._ast.program) : tags;
|
|
669
|
-
acc[key].tags = parseTags(node);
|
|
670
|
-
}
|
|
671
|
-
if (play) {
|
|
672
|
-
acc[key].tags = [...acc[key].tags || [], "play-fn"];
|
|
673
|
-
}
|
|
674
|
-
const stats = acc[key].__stats;
|
|
675
|
-
["play", "render", "loaders", "beforeEach", "globals", "tags"].forEach((annotation) => {
|
|
676
|
-
stats[annotation] = !!storyAnnotations[annotation] || !!self._metaAnnotations[annotation];
|
|
677
|
-
});
|
|
678
|
-
const storyExport = self.getStoryExport(key);
|
|
679
|
-
stats.storyFn = !!(t2.isArrowFunctionExpression(storyExport) || t2.isFunctionDeclaration(storyExport));
|
|
680
|
-
stats.mount = hasMount(storyAnnotations.play ?? self._metaAnnotations.play);
|
|
681
|
-
stats.moduleMock = !!self.imports.find((fname) => isModuleMock(fname));
|
|
682
|
-
const storyNode = self._storyStatements[key];
|
|
683
|
-
const storyTests = self._tests.filter((t7) => t7.parent.node === storyNode);
|
|
684
|
-
if (storyTests.length > 0) {
|
|
685
|
-
stats.tests = true;
|
|
686
|
-
storyTests.forEach((test) => {
|
|
687
|
-
test.id = toTestId(id, test.name);
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
return acc;
|
|
691
|
-
},
|
|
692
|
-
{}
|
|
693
|
-
);
|
|
694
|
-
Object.keys(self._storyExports).forEach((key) => {
|
|
695
|
-
if (!isExportStory(key, self._meta)) {
|
|
696
|
-
delete self._storyExports[key];
|
|
697
|
-
delete self._storyAnnotations[key];
|
|
698
|
-
delete self._storyStatements[key];
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
if (self._namedExportsOrder) {
|
|
702
|
-
const unsortedExports = Object.keys(self._storyExports);
|
|
703
|
-
self._storyExports = sortExports(self._storyExports, self._namedExportsOrder);
|
|
704
|
-
self._stories = sortExports(self._stories, self._namedExportsOrder);
|
|
705
|
-
const sortedExports = Object.keys(self._storyExports);
|
|
706
|
-
if (unsortedExports.length !== sortedExports.length) {
|
|
707
|
-
throw new Error(
|
|
708
|
-
`Missing exports after sort: ${unsortedExports.filter(
|
|
709
|
-
(key) => !sortedExports.includes(key)
|
|
710
|
-
)}`
|
|
711
|
-
);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
return self;
|
|
715
|
-
}
|
|
716
|
-
get meta() {
|
|
717
|
-
return this._meta;
|
|
718
|
-
}
|
|
719
|
-
get stories() {
|
|
720
|
-
return Object.values(this._stories);
|
|
721
|
-
}
|
|
722
|
-
getStoryTests(story) {
|
|
723
|
-
const storyNode = typeof story === "string" ? this._storyStatements[story] : story;
|
|
724
|
-
if (!storyNode) {
|
|
725
|
-
return [];
|
|
726
|
-
}
|
|
727
|
-
return this._tests.filter((t7) => t7.parent.node === storyNode);
|
|
728
|
-
}
|
|
729
|
-
get indexInputs() {
|
|
730
|
-
const { fileName } = this._options;
|
|
731
|
-
if (!fileName) {
|
|
732
|
-
throw new Error(
|
|
733
|
-
import_ts_dedent.dedent`Cannot automatically create index inputs with CsfFile.indexInputs because the CsfFile instance was created without a the fileName option.
|
|
734
|
-
Either add the fileName option when creating the CsfFile instance, or create the index inputs manually.`
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
const index = [];
|
|
738
|
-
Object.entries(this._stories).map(([exportName, story]) => {
|
|
739
|
-
const tags = [...this._meta?.tags ?? [], ...story.tags ?? []];
|
|
740
|
-
const storyInput = {
|
|
741
|
-
importPath: fileName,
|
|
742
|
-
rawComponentPath: this._rawComponentPath,
|
|
743
|
-
exportName,
|
|
744
|
-
title: this.meta?.title,
|
|
745
|
-
metaId: this.meta?.id,
|
|
746
|
-
tags,
|
|
747
|
-
__id: story.id,
|
|
748
|
-
__stats: story.__stats
|
|
749
|
-
};
|
|
750
|
-
const tests = this.getStoryTests(exportName);
|
|
751
|
-
const hasTests = tests.length > 0;
|
|
752
|
-
index.push({
|
|
753
|
-
...storyInput,
|
|
754
|
-
type: "story",
|
|
755
|
-
subtype: "story",
|
|
756
|
-
name: story.name
|
|
757
|
-
});
|
|
758
|
-
if (hasTests) {
|
|
759
|
-
tests.forEach((test) => {
|
|
760
|
-
index.push({
|
|
761
|
-
...storyInput,
|
|
762
|
-
// TODO implementent proper title => path behavior in `transformStoryIndexToStoriesHash`
|
|
763
|
-
// title: `${storyInput.title}/${story.name}`,
|
|
764
|
-
type: "story",
|
|
765
|
-
subtype: "test",
|
|
766
|
-
name: test.name,
|
|
767
|
-
parent: story.id,
|
|
768
|
-
parentName: story.name,
|
|
769
|
-
tags: [
|
|
770
|
-
...storyInput.tags,
|
|
771
|
-
// this tag comes before test tags so users can invert if they like
|
|
772
|
-
"!autodocs",
|
|
773
|
-
...test.tags,
|
|
774
|
-
// this tag comes after test tags so users can't change it
|
|
775
|
-
"test-fn"
|
|
776
|
-
],
|
|
777
|
-
__id: test.id
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
return index;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
var babelParseFile = /* @__PURE__ */ __name(({
|
|
786
|
-
code,
|
|
787
|
-
filename = "",
|
|
788
|
-
ast
|
|
789
|
-
}) => {
|
|
790
|
-
return new BabelFileClass({ filename }, { code, ast: ast ?? babelParse(code) });
|
|
791
|
-
}, "babelParseFile");
|
|
792
|
-
var loadCsf = /* @__PURE__ */ __name((code, options) => {
|
|
793
|
-
const ast = babelParse(code);
|
|
794
|
-
const file = babelParseFile({ code, filename: options.fileName, ast });
|
|
795
|
-
return new CsfFile(ast, options, file);
|
|
796
|
-
}, "loadCsf");
|
|
797
|
-
var formatCsf = /* @__PURE__ */ __name((csf, options = { sourceMaps: false }, code) => {
|
|
798
|
-
const result = generate(csf._ast, options, code);
|
|
799
|
-
if (options.sourceMaps) {
|
|
800
|
-
return result;
|
|
801
|
-
}
|
|
802
|
-
return result.code;
|
|
803
|
-
}, "formatCsf");
|
|
804
|
-
var printCsf = /* @__PURE__ */ __name((csf, options = {}) => {
|
|
805
|
-
return recast.print(csf._ast, options);
|
|
806
|
-
}, "printCsf");
|
|
807
|
-
var readCsf = /* @__PURE__ */ __name(async (fileName, options) => {
|
|
808
|
-
const code = (await readFile(fileName, "utf-8")).toString();
|
|
809
|
-
return loadCsf(code, { ...options, fileName });
|
|
810
|
-
}, "readCsf");
|
|
811
|
-
var writeCsf = /* @__PURE__ */ __name(async (csf, fileName) => {
|
|
812
|
-
const fname = fileName || csf._options.fileName;
|
|
813
|
-
if (!fname) {
|
|
814
|
-
throw new Error("Please specify a fileName for writeCsf");
|
|
815
|
-
}
|
|
816
|
-
await writeFile(fileName, printCsf(csf).code);
|
|
817
|
-
}, "writeCsf");
|
|
818
|
-
|
|
819
|
-
// src/csf-tools/ConfigFile.ts
|
|
820
|
-
var import_ts_dedent2 = __toESM(require_dist(), 1);
|
|
821
|
-
import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
822
|
-
import {
|
|
823
|
-
babelParse as babelParse2,
|
|
824
|
-
generate as generate2,
|
|
825
|
-
recast as recast2,
|
|
826
|
-
types as t3,
|
|
827
|
-
traverse as traverse2
|
|
828
|
-
} from "storybook/internal/babel";
|
|
829
|
-
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
830
|
-
var getCsfParsingErrorMessage = /* @__PURE__ */ __name(({
|
|
831
|
-
expectedType,
|
|
832
|
-
foundType,
|
|
833
|
-
node
|
|
834
|
-
}) => {
|
|
835
|
-
return import_ts_dedent2.dedent`
|
|
836
|
-
CSF Parsing error: Expected '${expectedType}' but found '${foundType}' instead in '${node?.type}'.
|
|
837
|
-
`;
|
|
838
|
-
}, "getCsfParsingErrorMessage");
|
|
839
|
-
var propKey = /* @__PURE__ */ __name((p) => {
|
|
840
|
-
if (t3.isIdentifier(p.key)) {
|
|
841
|
-
return p.key.name;
|
|
842
|
-
}
|
|
843
|
-
if (t3.isStringLiteral(p.key)) {
|
|
844
|
-
return p.key.value;
|
|
845
|
-
}
|
|
846
|
-
return null;
|
|
847
|
-
}, "propKey");
|
|
848
|
-
var unwrap = /* @__PURE__ */ __name((node) => {
|
|
849
|
-
if (t3.isTSAsExpression(node) || t3.isTSSatisfiesExpression(node)) {
|
|
850
|
-
return unwrap(node.expression);
|
|
851
|
-
}
|
|
852
|
-
return node;
|
|
853
|
-
}, "unwrap");
|
|
854
|
-
var _getPath = /* @__PURE__ */ __name((path, node) => {
|
|
855
|
-
if (path.length === 0) {
|
|
856
|
-
return node;
|
|
857
|
-
}
|
|
858
|
-
if (t3.isObjectExpression(node)) {
|
|
859
|
-
const [first, ...rest] = path;
|
|
860
|
-
const field = node.properties.find((p) => propKey(p) === first);
|
|
861
|
-
if (field) {
|
|
862
|
-
return _getPath(rest, field.value);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
return void 0;
|
|
866
|
-
}, "_getPath");
|
|
867
|
-
var _getPathProperties = /* @__PURE__ */ __name((path, node) => {
|
|
868
|
-
if (path.length === 0) {
|
|
869
|
-
if (t3.isObjectExpression(node)) {
|
|
870
|
-
return node.properties;
|
|
871
|
-
}
|
|
872
|
-
throw new Error("Expected object expression");
|
|
873
|
-
}
|
|
874
|
-
if (t3.isObjectExpression(node)) {
|
|
875
|
-
const [first, ...rest] = path;
|
|
876
|
-
const field = node.properties.find((p) => propKey(p) === first);
|
|
877
|
-
if (field) {
|
|
878
|
-
if (rest.length === 0) {
|
|
879
|
-
return node.properties;
|
|
880
|
-
}
|
|
881
|
-
return _getPathProperties(rest, field.value);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
return void 0;
|
|
885
|
-
}, "_getPathProperties");
|
|
886
|
-
var _findVarDeclarator = /* @__PURE__ */ __name((identifier, program) => {
|
|
887
|
-
let declarator = null;
|
|
888
|
-
let declarations = null;
|
|
889
|
-
program.body.find((node) => {
|
|
890
|
-
if (t3.isVariableDeclaration(node)) {
|
|
891
|
-
declarations = node.declarations;
|
|
892
|
-
} else if (t3.isExportNamedDeclaration(node) && t3.isVariableDeclaration(node.declaration)) {
|
|
893
|
-
declarations = node.declaration.declarations;
|
|
894
|
-
}
|
|
895
|
-
return declarations && declarations.find((decl) => {
|
|
896
|
-
if (t3.isVariableDeclarator(decl) && t3.isIdentifier(decl.id) && decl.id.name === identifier) {
|
|
897
|
-
declarator = decl;
|
|
898
|
-
return true;
|
|
899
|
-
}
|
|
900
|
-
return false;
|
|
901
|
-
});
|
|
902
|
-
});
|
|
903
|
-
return declarator;
|
|
904
|
-
}, "_findVarDeclarator");
|
|
905
|
-
var _findVarInitialization = /* @__PURE__ */ __name((identifier, program) => {
|
|
906
|
-
const declarator = _findVarDeclarator(identifier, program);
|
|
907
|
-
return declarator?.init;
|
|
908
|
-
}, "_findVarInitialization");
|
|
909
|
-
var _makeObjectExpression = /* @__PURE__ */ __name((path, value) => {
|
|
910
|
-
if (path.length === 0) {
|
|
911
|
-
return value;
|
|
912
|
-
}
|
|
913
|
-
const [first, ...rest] = path;
|
|
914
|
-
const innerExpression = _makeObjectExpression(rest, value);
|
|
915
|
-
return t3.objectExpression([t3.objectProperty(t3.identifier(first), innerExpression)]);
|
|
916
|
-
}, "_makeObjectExpression");
|
|
917
|
-
var _updateExportNode = /* @__PURE__ */ __name((path, expr, existing) => {
|
|
918
|
-
const [first, ...rest] = path;
|
|
919
|
-
const existingField = existing.properties.find(
|
|
920
|
-
(p) => propKey(p) === first
|
|
921
|
-
);
|
|
922
|
-
if (!existingField) {
|
|
923
|
-
existing.properties.push(
|
|
924
|
-
t3.objectProperty(t3.identifier(first), _makeObjectExpression(rest, expr))
|
|
925
|
-
);
|
|
926
|
-
} else if (t3.isObjectExpression(existingField.value) && rest.length > 0) {
|
|
927
|
-
_updateExportNode(rest, expr, existingField.value);
|
|
928
|
-
} else {
|
|
929
|
-
existingField.value = _makeObjectExpression(rest, expr);
|
|
930
|
-
}
|
|
931
|
-
}, "_updateExportNode");
|
|
932
|
-
var ConfigFile = class {
|
|
933
|
-
constructor(ast, code, fileName) {
|
|
934
|
-
this._exports = {};
|
|
935
|
-
// FIXME: this is a hack. this is only used in the case where the user is
|
|
936
|
-
// modifying a named export that's a scalar. The _exports map is not suitable
|
|
937
|
-
// for that. But rather than refactor the whole thing, we just use this as a stopgap.
|
|
938
|
-
this._exportDecls = {};
|
|
939
|
-
this.hasDefaultExport = false;
|
|
940
|
-
this._ast = ast;
|
|
941
|
-
this._code = code;
|
|
942
|
-
this.fileName = fileName;
|
|
943
|
-
}
|
|
944
|
-
static {
|
|
945
|
-
__name(this, "ConfigFile");
|
|
946
|
-
}
|
|
947
|
-
_parseExportsObject(exportsObject) {
|
|
948
|
-
this._exportsObject = exportsObject;
|
|
949
|
-
exportsObject.properties.forEach((p) => {
|
|
950
|
-
const exportName = propKey(p);
|
|
951
|
-
if (exportName) {
|
|
952
|
-
let exportVal = p.value;
|
|
953
|
-
if (t3.isIdentifier(exportVal)) {
|
|
954
|
-
exportVal = _findVarInitialization(exportVal.name, this._ast.program);
|
|
955
|
-
}
|
|
956
|
-
this._exports[exportName] = exportVal;
|
|
957
|
-
}
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
parse() {
|
|
961
|
-
const self = this;
|
|
962
|
-
traverse2(this._ast, {
|
|
963
|
-
ExportDefaultDeclaration: {
|
|
964
|
-
enter({ node, parent }) {
|
|
965
|
-
self.hasDefaultExport = true;
|
|
966
|
-
let decl = t3.isIdentifier(node.declaration) && t3.isProgram(parent) ? _findVarInitialization(node.declaration.name, parent) : node.declaration;
|
|
967
|
-
decl = unwrap(decl);
|
|
968
|
-
if (t3.isCallExpression(decl) && t3.isObjectExpression(decl.arguments[0])) {
|
|
969
|
-
decl = decl.arguments[0];
|
|
970
|
-
}
|
|
971
|
-
if (t3.isObjectExpression(decl)) {
|
|
972
|
-
self._parseExportsObject(decl);
|
|
973
|
-
} else {
|
|
974
|
-
logger2.warn(
|
|
975
|
-
getCsfParsingErrorMessage({
|
|
976
|
-
expectedType: "ObjectExpression",
|
|
977
|
-
foundType: decl?.type,
|
|
978
|
-
node: decl || node.declaration
|
|
979
|
-
})
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
},
|
|
984
|
-
ExportNamedDeclaration: {
|
|
985
|
-
enter({ node, parent }) {
|
|
986
|
-
if (t3.isVariableDeclaration(node.declaration)) {
|
|
987
|
-
node.declaration.declarations.forEach((decl) => {
|
|
988
|
-
if (t3.isVariableDeclarator(decl) && t3.isIdentifier(decl.id)) {
|
|
989
|
-
const { name: exportName } = decl.id;
|
|
990
|
-
let exportVal = decl.init;
|
|
991
|
-
if (t3.isIdentifier(exportVal)) {
|
|
992
|
-
exportVal = _findVarInitialization(exportVal.name, parent);
|
|
993
|
-
}
|
|
994
|
-
self._exports[exportName] = exportVal;
|
|
995
|
-
self._exportDecls[exportName] = decl;
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
} else if (t3.isFunctionDeclaration(node.declaration)) {
|
|
999
|
-
const decl = node.declaration;
|
|
1000
|
-
if (t3.isIdentifier(decl.id)) {
|
|
1001
|
-
const { name: exportName } = decl.id;
|
|
1002
|
-
self._exportDecls[exportName] = decl;
|
|
1003
|
-
}
|
|
1004
|
-
} else if (node.specifiers) {
|
|
1005
|
-
node.specifiers.forEach((spec) => {
|
|
1006
|
-
if (t3.isExportSpecifier(spec) && t3.isIdentifier(spec.local) && t3.isIdentifier(spec.exported)) {
|
|
1007
|
-
const { name: localName } = spec.local;
|
|
1008
|
-
const { name: exportName } = spec.exported;
|
|
1009
|
-
const decl = _findVarDeclarator(localName, parent);
|
|
1010
|
-
if (decl) {
|
|
1011
|
-
self._exports[exportName] = decl.init;
|
|
1012
|
-
self._exportDecls[exportName] = decl;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
});
|
|
1016
|
-
} else {
|
|
1017
|
-
logger2.warn(
|
|
1018
|
-
getCsfParsingErrorMessage({
|
|
1019
|
-
expectedType: "VariableDeclaration",
|
|
1020
|
-
foundType: node.declaration?.type,
|
|
1021
|
-
node: node.declaration
|
|
1022
|
-
})
|
|
1023
|
-
);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
},
|
|
1027
|
-
ExpressionStatement: {
|
|
1028
|
-
enter({ node, parent }) {
|
|
1029
|
-
if (t3.isAssignmentExpression(node.expression) && node.expression.operator === "=") {
|
|
1030
|
-
const { left, right } = node.expression;
|
|
1031
|
-
if (t3.isMemberExpression(left) && t3.isIdentifier(left.object) && left.object.name === "module" && t3.isIdentifier(left.property) && left.property.name === "exports") {
|
|
1032
|
-
let exportObject = right;
|
|
1033
|
-
if (t3.isIdentifier(right)) {
|
|
1034
|
-
exportObject = _findVarInitialization(right.name, parent);
|
|
1035
|
-
}
|
|
1036
|
-
exportObject = unwrap(exportObject);
|
|
1037
|
-
if (t3.isObjectExpression(exportObject)) {
|
|
1038
|
-
self._exportsObject = exportObject;
|
|
1039
|
-
exportObject.properties.forEach((p) => {
|
|
1040
|
-
const exportName = propKey(p);
|
|
1041
|
-
if (exportName) {
|
|
1042
|
-
let exportVal = p.value;
|
|
1043
|
-
if (t3.isIdentifier(exportVal)) {
|
|
1044
|
-
exportVal = _findVarInitialization(
|
|
1045
|
-
exportVal.name,
|
|
1046
|
-
parent
|
|
1047
|
-
);
|
|
1048
|
-
}
|
|
1049
|
-
self._exports[exportName] = exportVal;
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
|
-
} else {
|
|
1053
|
-
logger2.warn(
|
|
1054
|
-
getCsfParsingErrorMessage({
|
|
1055
|
-
expectedType: "ObjectExpression",
|
|
1056
|
-
foundType: exportObject?.type,
|
|
1057
|
-
node: exportObject
|
|
1058
|
-
})
|
|
1059
|
-
);
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
},
|
|
1065
|
-
CallExpression: {
|
|
1066
|
-
enter: /* @__PURE__ */ __name(({ node }) => {
|
|
1067
|
-
if (t3.isIdentifier(node.callee) && node.callee.name === "definePreview" && node.arguments.length === 1 && t3.isObjectExpression(node.arguments[0])) {
|
|
1068
|
-
self._parseExportsObject(node.arguments[0]);
|
|
1069
|
-
}
|
|
1070
|
-
}, "enter")
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
return self;
|
|
1074
|
-
}
|
|
1075
|
-
getFieldNode(path) {
|
|
1076
|
-
const [root, ...rest] = path;
|
|
1077
|
-
const exported = this._exports[root];
|
|
1078
|
-
if (!exported) {
|
|
1079
|
-
return void 0;
|
|
1080
|
-
}
|
|
1081
|
-
return _getPath(rest, exported);
|
|
1082
|
-
}
|
|
1083
|
-
getFieldProperties(path) {
|
|
1084
|
-
const [root, ...rest] = path;
|
|
1085
|
-
const exported = this._exports[root];
|
|
1086
|
-
if (!exported) {
|
|
1087
|
-
return void 0;
|
|
1088
|
-
}
|
|
1089
|
-
return _getPathProperties(rest, exported);
|
|
1090
|
-
}
|
|
1091
|
-
getFieldValue(path) {
|
|
1092
|
-
const node = this.getFieldNode(path);
|
|
1093
|
-
if (node) {
|
|
1094
|
-
const { code } = generate2(node, {});
|
|
1095
|
-
const value = (0, eval)(`(() => (${code}))()`);
|
|
1096
|
-
return value;
|
|
1097
|
-
}
|
|
1098
|
-
return void 0;
|
|
1099
|
-
}
|
|
1100
|
-
getSafeFieldValue(path) {
|
|
1101
|
-
try {
|
|
1102
|
-
return this.getFieldValue(path);
|
|
1103
|
-
} catch (e) {
|
|
1104
|
-
}
|
|
1105
|
-
return void 0;
|
|
1106
|
-
}
|
|
1107
|
-
setFieldNode(path, expr) {
|
|
1108
|
-
const [first, ...rest] = path;
|
|
1109
|
-
const exportNode = this._exports[first];
|
|
1110
|
-
if (this._exportsObject) {
|
|
1111
|
-
const properties = this._exportsObject.properties;
|
|
1112
|
-
const existingProp = properties.find((p) => propKey(p) === first);
|
|
1113
|
-
if (existingProp && t3.isIdentifier(existingProp.value)) {
|
|
1114
|
-
const varDecl2 = _findVarDeclarator(existingProp.value.name, this._ast.program);
|
|
1115
|
-
if (varDecl2 && t3.isObjectExpression(varDecl2.init)) {
|
|
1116
|
-
_updateExportNode(rest, expr, varDecl2.init);
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
_updateExportNode(path, expr, this._exportsObject);
|
|
1121
|
-
this._exports[path[0]] = expr;
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
if (exportNode && t3.isObjectExpression(exportNode) && rest.length > 0) {
|
|
1125
|
-
_updateExportNode(rest, expr, exportNode);
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
const varDecl = _findVarDeclarator(first, this._ast.program);
|
|
1129
|
-
if (varDecl && t3.isObjectExpression(varDecl.init)) {
|
|
1130
|
-
_updateExportNode(rest, expr, varDecl.init);
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
if (exportNode && rest.length === 0 && this._exportDecls[path[0]]) {
|
|
1134
|
-
const decl = this._exportDecls[path[0]];
|
|
1135
|
-
if (t3.isVariableDeclarator(decl)) {
|
|
1136
|
-
decl.init = _makeObjectExpression([], expr);
|
|
1137
|
-
}
|
|
1138
|
-
} else if (this.hasDefaultExport) {
|
|
1139
|
-
throw new Error(
|
|
1140
|
-
`Could not set the "${path.join(
|
|
1141
|
-
"."
|
|
1142
|
-
)}" field as the default export is not an object in this file.`
|
|
1143
|
-
);
|
|
1144
|
-
} else {
|
|
1145
|
-
const exportObj = _makeObjectExpression(rest, expr);
|
|
1146
|
-
const newExport = t3.exportNamedDeclaration(
|
|
1147
|
-
t3.variableDeclaration("const", [t3.variableDeclarator(t3.identifier(first), exportObj)])
|
|
1148
|
-
);
|
|
1149
|
-
this._exports[first] = exportObj;
|
|
1150
|
-
this._ast.program.body.push(newExport);
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
/**
|
|
1154
|
-
* @example
|
|
1155
|
-
*
|
|
1156
|
-
* ```ts
|
|
1157
|
-
* // 1. { framework: 'framework-name' }
|
|
1158
|
-
* // 2. { framework: { name: 'framework-name', options: {} }
|
|
1159
|
-
* getNameFromPath(['framework']); // => 'framework-name'
|
|
1160
|
-
* ```
|
|
1161
|
-
*
|
|
1162
|
-
* @returns The name of a node in a given path, supporting the following formats:
|
|
1163
|
-
*/
|
|
1164
|
-
getNameFromPath(path) {
|
|
1165
|
-
const node = this.getFieldNode(path);
|
|
1166
|
-
if (!node) {
|
|
1167
|
-
return void 0;
|
|
1168
|
-
}
|
|
1169
|
-
return this._getPresetValue(node, "name");
|
|
1170
|
-
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Returns an array of names of a node in a given path, supporting the following formats:
|
|
1173
|
-
*
|
|
1174
|
-
* @example
|
|
1175
|
-
*
|
|
1176
|
-
* ```ts
|
|
1177
|
-
* const config = {
|
|
1178
|
-
* addons: ['first-addon', { name: 'second-addon', options: {} }],
|
|
1179
|
-
* };
|
|
1180
|
-
* // => ['first-addon', 'second-addon']
|
|
1181
|
-
* getNamesFromPath(['addons']);
|
|
1182
|
-
* ```
|
|
1183
|
-
*/
|
|
1184
|
-
getNamesFromPath(path) {
|
|
1185
|
-
const node = this.getFieldNode(path);
|
|
1186
|
-
if (!node) {
|
|
1187
|
-
return void 0;
|
|
1188
|
-
}
|
|
1189
|
-
const pathNames = [];
|
|
1190
|
-
if (t3.isArrayExpression(node)) {
|
|
1191
|
-
node.elements.forEach((element) => {
|
|
1192
|
-
pathNames.push(this._getPresetValue(element, "name"));
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
return pathNames;
|
|
1196
|
-
}
|
|
1197
|
-
_getPnpWrappedValue(node) {
|
|
1198
|
-
if (t3.isCallExpression(node)) {
|
|
1199
|
-
const arg = node.arguments[0];
|
|
1200
|
-
if (t3.isStringLiteral(arg)) {
|
|
1201
|
-
return arg.value;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return void 0;
|
|
1205
|
-
}
|
|
1206
|
-
/**
|
|
1207
|
-
* Given a node and a fallback property, returns a **non-evaluated** string value of the node.
|
|
1208
|
-
*
|
|
1209
|
-
* 1. `{ node: 'value' }`
|
|
1210
|
-
* 2. `{ node: { fallbackProperty: 'value' } }`
|
|
1211
|
-
*/
|
|
1212
|
-
_getPresetValue(node, fallbackProperty) {
|
|
1213
|
-
let value;
|
|
1214
|
-
if (t3.isStringLiteral(node)) {
|
|
1215
|
-
value = node.value;
|
|
1216
|
-
} else if (t3.isObjectExpression(node)) {
|
|
1217
|
-
node.properties.forEach((prop) => {
|
|
1218
|
-
if (t3.isObjectProperty(prop) && t3.isIdentifier(prop.key) && prop.key.name === fallbackProperty) {
|
|
1219
|
-
if (t3.isStringLiteral(prop.value)) {
|
|
1220
|
-
value = prop.value.value;
|
|
1221
|
-
} else {
|
|
1222
|
-
value = this._getPnpWrappedValue(prop.value);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
if (t3.isObjectProperty(prop) && t3.isStringLiteral(prop.key) && prop.key.value === "name" && t3.isStringLiteral(prop.value)) {
|
|
1226
|
-
value = prop.value.value;
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
} else if (t3.isCallExpression(node)) {
|
|
1230
|
-
value = this._getPnpWrappedValue(node);
|
|
1231
|
-
}
|
|
1232
|
-
if (!value) {
|
|
1233
|
-
throw new Error(
|
|
1234
|
-
`The given node must be a string literal or an object expression with a "${fallbackProperty}" property that is a string literal.`
|
|
1235
|
-
);
|
|
1236
|
-
}
|
|
1237
|
-
return value;
|
|
1238
|
-
}
|
|
1239
|
-
removeField(path) {
|
|
1240
|
-
const removeProperty = /* @__PURE__ */ __name((properties2, prop) => {
|
|
1241
|
-
const index = properties2.findIndex(
|
|
1242
|
-
(p) => t3.isIdentifier(p.key) && p.key.name === prop || t3.isStringLiteral(p.key) && p.key.value === prop
|
|
1243
|
-
);
|
|
1244
|
-
if (index >= 0) {
|
|
1245
|
-
properties2.splice(index, 1);
|
|
1246
|
-
}
|
|
1247
|
-
}, "removeProperty");
|
|
1248
|
-
if (path.length === 1) {
|
|
1249
|
-
let removedRootProperty = false;
|
|
1250
|
-
this._ast.program.body.forEach((node) => {
|
|
1251
|
-
if (t3.isExportNamedDeclaration(node) && t3.isVariableDeclaration(node.declaration)) {
|
|
1252
|
-
const decl = node.declaration.declarations[0];
|
|
1253
|
-
if (t3.isIdentifier(decl.id) && decl.id.name === path[0]) {
|
|
1254
|
-
this._ast.program.body.splice(this._ast.program.body.indexOf(node), 1);
|
|
1255
|
-
removedRootProperty = true;
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
if (t3.isExportDefaultDeclaration(node)) {
|
|
1259
|
-
let decl = node.declaration;
|
|
1260
|
-
if (t3.isIdentifier(decl)) {
|
|
1261
|
-
decl = _findVarInitialization(decl.name, this._ast.program);
|
|
1262
|
-
}
|
|
1263
|
-
decl = unwrap(decl);
|
|
1264
|
-
if (t3.isObjectExpression(decl)) {
|
|
1265
|
-
const properties2 = decl.properties;
|
|
1266
|
-
removeProperty(properties2, path[0]);
|
|
1267
|
-
removedRootProperty = true;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
if (t3.isExpressionStatement(node) && t3.isAssignmentExpression(node.expression) && t3.isMemberExpression(node.expression.left) && t3.isIdentifier(node.expression.left.object) && node.expression.left.object.name === "module" && t3.isIdentifier(node.expression.left.property) && node.expression.left.property.name === "exports" && t3.isObjectExpression(node.expression.right)) {
|
|
1271
|
-
const properties2 = node.expression.right.properties;
|
|
1272
|
-
removeProperty(properties2, path[0]);
|
|
1273
|
-
removedRootProperty = true;
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
if (removedRootProperty) {
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
const properties = this.getFieldProperties(path);
|
|
1281
|
-
if (properties) {
|
|
1282
|
-
const lastPath = path.at(-1);
|
|
1283
|
-
removeProperty(properties, lastPath);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
appendValueToArray(path, value) {
|
|
1287
|
-
const node = this.valueToNode(value);
|
|
1288
|
-
if (node) {
|
|
1289
|
-
this.appendNodeToArray(path, node);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
appendNodeToArray(path, node) {
|
|
1293
|
-
const current = this.getFieldNode(path);
|
|
1294
|
-
if (!current) {
|
|
1295
|
-
this.setFieldNode(path, t3.arrayExpression([node]));
|
|
1296
|
-
} else if (t3.isArrayExpression(current)) {
|
|
1297
|
-
current.elements.push(node);
|
|
1298
|
-
} else {
|
|
1299
|
-
throw new Error(`Expected array at '${path.join(".")}', got '${current.type}'`);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Specialized helper to remove addons or other array entries that can either be strings or
|
|
1304
|
-
* objects with a name property.
|
|
1305
|
-
*/
|
|
1306
|
-
removeEntryFromArray(path, value) {
|
|
1307
|
-
const current = this.getFieldNode(path);
|
|
1308
|
-
if (!current) {
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
if (t3.isArrayExpression(current)) {
|
|
1312
|
-
const index = current.elements.findIndex((element) => {
|
|
1313
|
-
if (t3.isStringLiteral(element)) {
|
|
1314
|
-
return element.value === value;
|
|
1315
|
-
}
|
|
1316
|
-
if (t3.isObjectExpression(element)) {
|
|
1317
|
-
const name = this._getPresetValue(element, "name");
|
|
1318
|
-
return name === value;
|
|
1319
|
-
}
|
|
1320
|
-
return this._getPnpWrappedValue(element) === value;
|
|
1321
|
-
});
|
|
1322
|
-
if (index >= 0) {
|
|
1323
|
-
current.elements.splice(index, 1);
|
|
1324
|
-
} else {
|
|
1325
|
-
throw new Error(`Could not find '${value}' in array at '${path.join(".")}'`);
|
|
1326
|
-
}
|
|
1327
|
-
} else {
|
|
1328
|
-
throw new Error(`Expected array at '${path.join(".")}', got '${current.type}'`);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
_inferQuotes() {
|
|
1332
|
-
if (!this._quotes) {
|
|
1333
|
-
const occurrences = (this._ast.tokens || []).slice(0, 500).reduce(
|
|
1334
|
-
(acc, token) => {
|
|
1335
|
-
if (token.type.label === "string") {
|
|
1336
|
-
acc[this._code[token.start]] += 1;
|
|
1337
|
-
}
|
|
1338
|
-
return acc;
|
|
1339
|
-
},
|
|
1340
|
-
{ "'": 0, '"': 0 }
|
|
1341
|
-
);
|
|
1342
|
-
this._quotes = occurrences["'"] > occurrences['"'] ? "single" : "double";
|
|
1343
|
-
}
|
|
1344
|
-
return this._quotes;
|
|
1345
|
-
}
|
|
1346
|
-
valueToNode(value) {
|
|
1347
|
-
const quotes = this._inferQuotes();
|
|
1348
|
-
let valueNode;
|
|
1349
|
-
if (quotes === "single") {
|
|
1350
|
-
const { code } = generate2(t3.valueToNode(value), { jsescOption: { quotes } });
|
|
1351
|
-
const program = babelParse2(`const __x = ${code}`);
|
|
1352
|
-
traverse2(program, {
|
|
1353
|
-
VariableDeclaration: {
|
|
1354
|
-
enter({ node }) {
|
|
1355
|
-
if (node.declarations.length === 1 && t3.isVariableDeclarator(node.declarations[0]) && t3.isIdentifier(node.declarations[0].id) && node.declarations[0].id.name === "__x") {
|
|
1356
|
-
valueNode = node.declarations[0].init;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
});
|
|
1361
|
-
} else {
|
|
1362
|
-
valueNode = t3.valueToNode(value);
|
|
1363
|
-
}
|
|
1364
|
-
return valueNode;
|
|
1365
|
-
}
|
|
1366
|
-
setFieldValue(path, value) {
|
|
1367
|
-
const valueNode = this.valueToNode(value);
|
|
1368
|
-
if (!valueNode) {
|
|
1369
|
-
throw new Error(`Unexpected value ${JSON.stringify(value)}`);
|
|
1370
|
-
}
|
|
1371
|
-
this.setFieldNode(path, valueNode);
|
|
1372
|
-
}
|
|
1373
|
-
getBodyDeclarations() {
|
|
1374
|
-
return this._ast.program.body;
|
|
1375
|
-
}
|
|
1376
|
-
setBodyDeclaration(declaration) {
|
|
1377
|
-
this._ast.program.body.push(declaration);
|
|
1378
|
-
}
|
|
1379
|
-
/**
|
|
1380
|
-
* Import specifiers for a specific require import
|
|
1381
|
-
*
|
|
1382
|
-
* @example
|
|
1383
|
-
*
|
|
1384
|
-
* ```ts
|
|
1385
|
-
* // const { foo } = require('bar');
|
|
1386
|
-
* setRequireImport(['foo'], 'bar');
|
|
1387
|
-
*
|
|
1388
|
-
* // const foo = require('bar');
|
|
1389
|
-
* setRequireImport('foo', 'bar');
|
|
1390
|
-
* ```
|
|
1391
|
-
*
|
|
1392
|
-
* @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
|
|
1393
|
-
* import will be set. Otherwise, an array of named imports will be set
|
|
1394
|
-
* @param fromImport - The module to import from
|
|
1395
|
-
*/
|
|
1396
|
-
setRequireImport(importSpecifier, fromImport) {
|
|
1397
|
-
const requireDeclaration = this._ast.program.body.find((node) => {
|
|
1398
|
-
const hasDeclaration = t3.isVariableDeclaration(node) && node.declarations.length === 1 && t3.isVariableDeclarator(node.declarations[0]) && t3.isCallExpression(node.declarations[0].init) && t3.isIdentifier(node.declarations[0].init.callee) && node.declarations[0].init.callee.name === "require" && t3.isStringLiteral(node.declarations[0].init.arguments[0]) && (node.declarations[0].init.arguments[0].value === fromImport || node.declarations[0].init.arguments[0].value === fromImport.split("node:")[1]);
|
|
1399
|
-
if (hasDeclaration) {
|
|
1400
|
-
fromImport = node.declarations[0].init.arguments[0].value;
|
|
1401
|
-
}
|
|
1402
|
-
return hasDeclaration;
|
|
1403
|
-
});
|
|
1404
|
-
const hasRequireSpecifier = /* @__PURE__ */ __name((name) => t3.isObjectPattern(requireDeclaration?.declarations[0].id) && requireDeclaration?.declarations[0].id.properties.find(
|
|
1405
|
-
(specifier) => t3.isObjectProperty(specifier) && t3.isIdentifier(specifier.key) && specifier.key.name === name
|
|
1406
|
-
), "hasRequireSpecifier");
|
|
1407
|
-
const hasDefaultRequireSpecifier = /* @__PURE__ */ __name((declaration, name) => declaration.declarations.length === 1 && t3.isVariableDeclarator(declaration.declarations[0]) && t3.isIdentifier(declaration.declarations[0].id) && declaration.declarations[0].id.name === name, "hasDefaultRequireSpecifier");
|
|
1408
|
-
if (typeof importSpecifier === "string") {
|
|
1409
|
-
const addDefaultRequireSpecifier = /* @__PURE__ */ __name(() => {
|
|
1410
|
-
this._ast.program.body.unshift(
|
|
1411
|
-
t3.variableDeclaration("const", [
|
|
1412
|
-
t3.variableDeclarator(
|
|
1413
|
-
t3.identifier(importSpecifier),
|
|
1414
|
-
t3.callExpression(t3.identifier("require"), [t3.stringLiteral(fromImport)])
|
|
1415
|
-
)
|
|
1416
|
-
])
|
|
1417
|
-
);
|
|
1418
|
-
}, "addDefaultRequireSpecifier");
|
|
1419
|
-
if (requireDeclaration) {
|
|
1420
|
-
if (!hasDefaultRequireSpecifier(requireDeclaration, importSpecifier)) {
|
|
1421
|
-
addDefaultRequireSpecifier();
|
|
1422
|
-
}
|
|
1423
|
-
} else {
|
|
1424
|
-
addDefaultRequireSpecifier();
|
|
1425
|
-
}
|
|
1426
|
-
} else if (requireDeclaration) {
|
|
1427
|
-
importSpecifier.forEach((specifier) => {
|
|
1428
|
-
if (!hasRequireSpecifier(specifier)) {
|
|
1429
|
-
requireDeclaration.declarations[0].id.properties.push(
|
|
1430
|
-
t3.objectProperty(t3.identifier(specifier), t3.identifier(specifier), void 0, true)
|
|
1431
|
-
);
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
} else {
|
|
1435
|
-
this._ast.program.body.unshift(
|
|
1436
|
-
t3.variableDeclaration("const", [
|
|
1437
|
-
t3.variableDeclarator(
|
|
1438
|
-
t3.objectPattern(
|
|
1439
|
-
importSpecifier.map(
|
|
1440
|
-
(specifier) => t3.objectProperty(t3.identifier(specifier), t3.identifier(specifier), void 0, true)
|
|
1441
|
-
)
|
|
1442
|
-
),
|
|
1443
|
-
t3.callExpression(t3.identifier("require"), [t3.stringLiteral(fromImport)])
|
|
1444
|
-
)
|
|
1445
|
-
])
|
|
1446
|
-
);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* Set import specifiers for a given import statement.
|
|
1451
|
-
*
|
|
1452
|
-
* Does not support setting type imports (yet)
|
|
1453
|
-
*
|
|
1454
|
-
* @example
|
|
1455
|
-
*
|
|
1456
|
-
* ```ts
|
|
1457
|
-
* // import { foo } from 'bar';
|
|
1458
|
-
* setImport(['foo'], 'bar');
|
|
1459
|
-
*
|
|
1460
|
-
* // import foo from 'bar';
|
|
1461
|
-
* setImport('foo', 'bar');
|
|
1462
|
-
*
|
|
1463
|
-
* // import * as foo from 'bar';
|
|
1464
|
-
* setImport({ namespace: 'foo' }, 'bar');
|
|
1465
|
-
*
|
|
1466
|
-
* // import 'bar';
|
|
1467
|
-
* setImport(null, 'bar');
|
|
1468
|
-
* ```
|
|
1469
|
-
*
|
|
1470
|
-
* @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
|
|
1471
|
-
* import will be set. Otherwise, an array of named imports will be set
|
|
1472
|
-
* @param fromImport - The module to import from
|
|
1473
|
-
*/
|
|
1474
|
-
setImport(importSpecifier, fromImport) {
|
|
1475
|
-
const importDeclaration = this._ast.program.body.find((node) => {
|
|
1476
|
-
const hasDeclaration = t3.isImportDeclaration(node) && (node.source.value === fromImport || node.source.value === fromImport.split("node:")[1]);
|
|
1477
|
-
if (hasDeclaration) {
|
|
1478
|
-
fromImport = node.source.value;
|
|
1479
|
-
}
|
|
1480
|
-
return hasDeclaration;
|
|
1481
|
-
});
|
|
1482
|
-
const getNewImportSpecifier = /* @__PURE__ */ __name((specifier) => t3.importSpecifier(t3.identifier(specifier), t3.identifier(specifier)), "getNewImportSpecifier");
|
|
1483
|
-
const hasImportSpecifier = /* @__PURE__ */ __name((declaration, name) => declaration.specifiers.find(
|
|
1484
|
-
(specifier) => t3.isImportSpecifier(specifier) && t3.isIdentifier(specifier.imported) && specifier.imported.name === name
|
|
1485
|
-
), "hasImportSpecifier");
|
|
1486
|
-
const hasNamespaceImportSpecifier = /* @__PURE__ */ __name((declaration, name) => declaration.specifiers.find(
|
|
1487
|
-
(specifier) => t3.isImportNamespaceSpecifier(specifier) && t3.isIdentifier(specifier.local) && specifier.local.name === name
|
|
1488
|
-
), "hasNamespaceImportSpecifier");
|
|
1489
|
-
const hasDefaultImportSpecifier = /* @__PURE__ */ __name((declaration, name) => declaration.specifiers.find(
|
|
1490
|
-
(specifier) => t3.isImportDefaultSpecifier(specifier) && t3.isIdentifier(specifier.local) && specifier.local.name === name
|
|
1491
|
-
), "hasDefaultImportSpecifier");
|
|
1492
|
-
if (importSpecifier === null) {
|
|
1493
|
-
if (!importDeclaration) {
|
|
1494
|
-
this._ast.program.body.unshift(t3.importDeclaration([], t3.stringLiteral(fromImport)));
|
|
1495
|
-
}
|
|
1496
|
-
} else if (typeof importSpecifier === "string") {
|
|
1497
|
-
if (importDeclaration) {
|
|
1498
|
-
if (!hasDefaultImportSpecifier(importDeclaration, importSpecifier)) {
|
|
1499
|
-
importDeclaration.specifiers.push(
|
|
1500
|
-
t3.importDefaultSpecifier(t3.identifier(importSpecifier))
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
} else {
|
|
1504
|
-
this._ast.program.body.unshift(
|
|
1505
|
-
t3.importDeclaration(
|
|
1506
|
-
[t3.importDefaultSpecifier(t3.identifier(importSpecifier))],
|
|
1507
|
-
t3.stringLiteral(fromImport)
|
|
1508
|
-
)
|
|
1509
|
-
);
|
|
1510
|
-
}
|
|
1511
|
-
} else if (Array.isArray(importSpecifier)) {
|
|
1512
|
-
if (importDeclaration) {
|
|
1513
|
-
importSpecifier.forEach((specifier) => {
|
|
1514
|
-
if (!hasImportSpecifier(importDeclaration, specifier)) {
|
|
1515
|
-
importDeclaration.specifiers.push(getNewImportSpecifier(specifier));
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
} else {
|
|
1519
|
-
this._ast.program.body.unshift(
|
|
1520
|
-
t3.importDeclaration(
|
|
1521
|
-
importSpecifier.map(getNewImportSpecifier),
|
|
1522
|
-
t3.stringLiteral(fromImport)
|
|
1523
|
-
)
|
|
1524
|
-
);
|
|
1525
|
-
}
|
|
1526
|
-
} else if (importSpecifier.namespace) {
|
|
1527
|
-
if (importDeclaration) {
|
|
1528
|
-
if (!hasNamespaceImportSpecifier(importDeclaration, importSpecifier.namespace)) {
|
|
1529
|
-
importDeclaration.specifiers.push(
|
|
1530
|
-
t3.importNamespaceSpecifier(t3.identifier(importSpecifier.namespace))
|
|
1531
|
-
);
|
|
1532
|
-
}
|
|
1533
|
-
} else {
|
|
1534
|
-
this._ast.program.body.unshift(
|
|
1535
|
-
t3.importDeclaration(
|
|
1536
|
-
[t3.importNamespaceSpecifier(t3.identifier(importSpecifier.namespace))],
|
|
1537
|
-
t3.stringLiteral(fromImport)
|
|
1538
|
-
)
|
|
1539
|
-
);
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
_removeRequireImport(importSpecifier, fromImport) {
|
|
1544
|
-
const requireDeclarationIndex = this._ast.program.body.findIndex((node) => {
|
|
1545
|
-
const hasDeclaration = t3.isVariableDeclaration(node) && node.declarations.length === 1 && t3.isVariableDeclarator(node.declarations[0]) && t3.isCallExpression(node.declarations[0].init) && t3.isIdentifier(node.declarations[0].init.callee) && node.declarations[0].init.callee.name === "require" && t3.isStringLiteral(node.declarations[0].init.arguments[0]) && (node.declarations[0].init.arguments[0].value === fromImport || node.declarations[0].init.arguments[0].value === fromImport.split("node:")[1]);
|
|
1546
|
-
return hasDeclaration;
|
|
1547
|
-
});
|
|
1548
|
-
if (requireDeclarationIndex === -1) {
|
|
1549
|
-
return;
|
|
1550
|
-
}
|
|
1551
|
-
const requireDeclaration = this._ast.program.body[requireDeclarationIndex];
|
|
1552
|
-
const declarator = requireDeclaration.declarations[0];
|
|
1553
|
-
if (importSpecifier === null) {
|
|
1554
|
-
return;
|
|
1555
|
-
}
|
|
1556
|
-
if (typeof importSpecifier === "string") {
|
|
1557
|
-
if (t3.isIdentifier(declarator.id) && declarator.id.name === importSpecifier) {
|
|
1558
|
-
this._ast.program.body.splice(requireDeclarationIndex, 1);
|
|
1559
|
-
}
|
|
1560
|
-
return;
|
|
1561
|
-
}
|
|
1562
|
-
if (typeof importSpecifier === "object" && "namespace" in importSpecifier) {
|
|
1563
|
-
return;
|
|
1564
|
-
}
|
|
1565
|
-
if (Array.isArray(importSpecifier) && t3.isObjectPattern(declarator.id)) {
|
|
1566
|
-
const objectPattern = declarator.id;
|
|
1567
|
-
importSpecifier.forEach((specifier) => {
|
|
1568
|
-
const index = objectPattern.properties.findIndex(
|
|
1569
|
-
(prop) => t3.isObjectProperty(prop) && t3.isIdentifier(prop.key) && prop.key.name === specifier
|
|
1570
|
-
);
|
|
1571
|
-
if (index !== -1) {
|
|
1572
|
-
objectPattern.properties.splice(index, 1);
|
|
1573
|
-
}
|
|
1574
|
-
});
|
|
1575
|
-
if (objectPattern.properties.length === 0) {
|
|
1576
|
-
this._ast.program.body.splice(requireDeclarationIndex, 1);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
_removeImport(importSpecifier, fromImport) {
|
|
1581
|
-
const importDeclarationIndex = this._ast.program.body.findIndex(
|
|
1582
|
-
(node) => t3.isImportDeclaration(node) && (node.source.value === fromImport || node.source.value === fromImport.split("node:")[1])
|
|
1583
|
-
);
|
|
1584
|
-
if (importDeclarationIndex === -1) {
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1587
|
-
const importDeclaration = this._ast.program.body[importDeclarationIndex];
|
|
1588
|
-
if (importSpecifier === null) {
|
|
1589
|
-
if (importDeclaration.specifiers.length === 0) {
|
|
1590
|
-
this._ast.program.body.splice(importDeclarationIndex, 1);
|
|
1591
|
-
}
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
if (typeof importSpecifier === "object" && "namespace" in importSpecifier) {
|
|
1595
|
-
const index = importDeclaration.specifiers.findIndex(
|
|
1596
|
-
(specifier) => t3.isImportNamespaceSpecifier(specifier) && t3.isIdentifier(specifier.local) && specifier.local.name === importSpecifier.namespace
|
|
1597
|
-
);
|
|
1598
|
-
if (index !== -1) {
|
|
1599
|
-
importDeclaration.specifiers.splice(index, 1);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
if (typeof importSpecifier === "string") {
|
|
1603
|
-
const index = importDeclaration.specifiers.findIndex(
|
|
1604
|
-
(specifier) => t3.isImportDefaultSpecifier(specifier) && t3.isIdentifier(specifier.local) && specifier.local.name === importSpecifier
|
|
1605
|
-
);
|
|
1606
|
-
if (index !== -1) {
|
|
1607
|
-
importDeclaration.specifiers.splice(index, 1);
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
if (Array.isArray(importSpecifier)) {
|
|
1611
|
-
importSpecifier.forEach((specifier) => {
|
|
1612
|
-
const index = importDeclaration.specifiers.findIndex(
|
|
1613
|
-
(current) => t3.isImportSpecifier(current) && t3.isIdentifier(current.imported) && current.imported.name === specifier
|
|
1614
|
-
);
|
|
1615
|
-
if (index !== -1) {
|
|
1616
|
-
importDeclaration.specifiers.splice(index, 1);
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
if (importDeclaration.specifiers.length === 0) {
|
|
1621
|
-
this._ast.program.body.splice(importDeclarationIndex, 1);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Remove import specifiers for a given import statement.
|
|
1626
|
-
*
|
|
1627
|
-
* Does not support removing type imports (yet)
|
|
1628
|
-
*
|
|
1629
|
-
* @example
|
|
1630
|
-
*
|
|
1631
|
-
* ```ts
|
|
1632
|
-
* // import { foo } from 'bar';
|
|
1633
|
-
* setImport(['foo'], 'bar');
|
|
1634
|
-
*
|
|
1635
|
-
* // import foo from 'bar';
|
|
1636
|
-
* setImport('foo', 'bar');
|
|
1637
|
-
*
|
|
1638
|
-
* // import * as foo from 'bar';
|
|
1639
|
-
* setImport({ namespace: 'foo' }, 'bar');
|
|
1640
|
-
*
|
|
1641
|
-
* // import 'bar';
|
|
1642
|
-
* setImport(null, 'bar');
|
|
1643
|
-
* ```
|
|
1644
|
-
*
|
|
1645
|
-
* @param importSpecifiers - The import specifiers to remove. If a string is passed in, will only
|
|
1646
|
-
* remove the default import. Otherwise, named imports matching the array will be removed.
|
|
1647
|
-
* @param fromImport - The module to import from
|
|
1648
|
-
*/
|
|
1649
|
-
removeImport(importSpecifier, fromImport) {
|
|
1650
|
-
this._removeRequireImport(importSpecifier, fromImport);
|
|
1651
|
-
this._removeImport(importSpecifier, fromImport);
|
|
1652
|
-
}
|
|
1653
|
-
};
|
|
1654
|
-
var loadConfig = /* @__PURE__ */ __name((code, fileName) => {
|
|
1655
|
-
const ast = babelParse2(code);
|
|
1656
|
-
return new ConfigFile(ast, code, fileName);
|
|
1657
|
-
}, "loadConfig");
|
|
1658
|
-
var formatConfig = /* @__PURE__ */ __name((config) => {
|
|
1659
|
-
return printConfig(config).code;
|
|
1660
|
-
}, "formatConfig");
|
|
1661
|
-
var printConfig = /* @__PURE__ */ __name((config, options = {}) => {
|
|
1662
|
-
return recast2.print(config._ast, options);
|
|
1663
|
-
}, "printConfig");
|
|
1664
|
-
var readConfig = /* @__PURE__ */ __name(async (fileName) => {
|
|
1665
|
-
const code = (await readFile2(fileName, "utf-8")).toString();
|
|
1666
|
-
return loadConfig(code, fileName).parse();
|
|
1667
|
-
}, "readConfig");
|
|
1668
|
-
var writeConfig = /* @__PURE__ */ __name(async (config, fileName) => {
|
|
1669
|
-
const fname = fileName || config.fileName;
|
|
1670
|
-
if (!fname) {
|
|
1671
|
-
throw new Error("Please specify a fileName for writeConfig");
|
|
1672
|
-
}
|
|
1673
|
-
await writeFile2(fname, formatConfig(config));
|
|
1674
|
-
}, "writeConfig");
|
|
1675
|
-
var isCsfFactoryPreview = /* @__PURE__ */ __name((previewConfig) => {
|
|
1676
|
-
const program = previewConfig._ast.program;
|
|
1677
|
-
return !!program.body.find((node) => {
|
|
1678
|
-
return t3.isImportDeclaration(node) && node.source.value.includes("@storybook") && node.specifiers.some((specifier) => {
|
|
1679
|
-
return t3.isImportSpecifier(specifier) && t3.isIdentifier(specifier.imported) && specifier.imported.name === "definePreview";
|
|
1680
|
-
});
|
|
1681
|
-
});
|
|
1682
|
-
}, "isCsfFactoryPreview");
|
|
1683
|
-
|
|
1684
|
-
// src/csf-tools/getStorySortParameter.ts
|
|
1685
|
-
var import_ts_dedent3 = __toESM(require_dist(), 1);
|
|
1686
|
-
import { babelParse as babelParse3, generate as generate3, types as t4, traverse as traverse3 } from "storybook/internal/babel";
|
|
1687
|
-
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
1688
|
-
var getValue = /* @__PURE__ */ __name((obj, key) => {
|
|
1689
|
-
let value;
|
|
1690
|
-
obj.properties.forEach((p) => {
|
|
1691
|
-
if (t4.isIdentifier(p.key) && p.key.name === key) {
|
|
1692
|
-
value = p.value;
|
|
1693
|
-
}
|
|
1694
|
-
});
|
|
1695
|
-
return value;
|
|
1696
|
-
}, "getValue");
|
|
1697
|
-
var parseValue = /* @__PURE__ */ __name((value) => {
|
|
1698
|
-
const expr = stripTSModifiers(value);
|
|
1699
|
-
if (t4.isArrayExpression(expr)) {
|
|
1700
|
-
return expr.elements.map((o) => {
|
|
1701
|
-
return parseValue(o);
|
|
1702
|
-
});
|
|
1703
|
-
}
|
|
1704
|
-
if (t4.isObjectExpression(expr)) {
|
|
1705
|
-
return expr.properties.reduce((acc, p) => {
|
|
1706
|
-
if (t4.isIdentifier(p.key)) {
|
|
1707
|
-
acc[p.key.name] = parseValue(p.value);
|
|
1708
|
-
}
|
|
1709
|
-
return acc;
|
|
1710
|
-
}, {});
|
|
1711
|
-
}
|
|
1712
|
-
if (t4.isLiteral(expr)) {
|
|
1713
|
-
return expr.value;
|
|
1714
|
-
}
|
|
1715
|
-
if (t4.isIdentifier(expr)) {
|
|
1716
|
-
return unsupported(expr.name, true);
|
|
1717
|
-
}
|
|
1718
|
-
throw new Error(`Unknown node type ${expr.type}`);
|
|
1719
|
-
}, "parseValue");
|
|
1720
|
-
var unsupported = /* @__PURE__ */ __name((unexpectedVar, isError) => {
|
|
1721
|
-
const message = import_ts_dedent3.dedent`
|
|
1722
|
-
Unexpected '${unexpectedVar}'. Parameter 'options.storySort' should be defined inline e.g.:
|
|
1723
|
-
|
|
1724
|
-
export default {
|
|
1725
|
-
parameters: {
|
|
1726
|
-
options: {
|
|
1727
|
-
storySort: <array | object | function>
|
|
1728
|
-
},
|
|
1729
|
-
},
|
|
1730
|
-
};
|
|
1731
|
-
`;
|
|
1732
|
-
if (isError) {
|
|
1733
|
-
throw new Error(message);
|
|
1734
|
-
} else {
|
|
1735
|
-
logger3.log(message);
|
|
1736
|
-
}
|
|
1737
|
-
}, "unsupported");
|
|
1738
|
-
var stripTSModifiers = /* @__PURE__ */ __name((expr) => t4.isTSAsExpression(expr) || t4.isTSSatisfiesExpression(expr) ? expr.expression : expr, "stripTSModifiers");
|
|
1739
|
-
var parseParameters = /* @__PURE__ */ __name((params) => {
|
|
1740
|
-
const paramsObject = stripTSModifiers(params);
|
|
1741
|
-
if (t4.isObjectExpression(paramsObject)) {
|
|
1742
|
-
const options = getValue(paramsObject, "options");
|
|
1743
|
-
if (options) {
|
|
1744
|
-
if (t4.isObjectExpression(options)) {
|
|
1745
|
-
return getValue(options, "storySort");
|
|
1746
|
-
}
|
|
1747
|
-
unsupported("options", true);
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
return void 0;
|
|
1751
|
-
}, "parseParameters");
|
|
1752
|
-
var parseDefault = /* @__PURE__ */ __name((defaultExpr, program) => {
|
|
1753
|
-
const defaultObj = stripTSModifiers(defaultExpr);
|
|
1754
|
-
if (t4.isObjectExpression(defaultObj)) {
|
|
1755
|
-
let params = getValue(defaultObj, "parameters");
|
|
1756
|
-
if (t4.isIdentifier(params)) {
|
|
1757
|
-
params = findVarInitialization(params.name, program);
|
|
1758
|
-
}
|
|
1759
|
-
if (params) {
|
|
1760
|
-
return parseParameters(params);
|
|
1761
|
-
}
|
|
1762
|
-
} else {
|
|
1763
|
-
unsupported("default", true);
|
|
1764
|
-
}
|
|
1765
|
-
return void 0;
|
|
1766
|
-
}, "parseDefault");
|
|
1767
|
-
var getStorySortParameter = /* @__PURE__ */ __name((previewCode) => {
|
|
1768
|
-
if (!previewCode.includes("storySort")) {
|
|
1769
|
-
return void 0;
|
|
1770
|
-
}
|
|
1771
|
-
let storySort;
|
|
1772
|
-
const ast = babelParse3(previewCode);
|
|
1773
|
-
traverse3(ast, {
|
|
1774
|
-
ExportNamedDeclaration: {
|
|
1775
|
-
enter({ node }) {
|
|
1776
|
-
if (t4.isVariableDeclaration(node.declaration)) {
|
|
1777
|
-
node.declaration.declarations.forEach((decl) => {
|
|
1778
|
-
if (t4.isVariableDeclarator(decl) && t4.isIdentifier(decl.id)) {
|
|
1779
|
-
const { name: exportName } = decl.id;
|
|
1780
|
-
if (exportName === "parameters" && decl.init) {
|
|
1781
|
-
const paramsObject = stripTSModifiers(decl.init);
|
|
1782
|
-
storySort = parseParameters(paramsObject);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
});
|
|
1786
|
-
} else {
|
|
1787
|
-
node.specifiers.forEach((spec) => {
|
|
1788
|
-
if (t4.isIdentifier(spec.exported) && spec.exported.name === "parameters") {
|
|
1789
|
-
unsupported("parameters", false);
|
|
1790
|
-
}
|
|
1791
|
-
});
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
},
|
|
1795
|
-
ExportDefaultDeclaration: {
|
|
1796
|
-
enter({ node }) {
|
|
1797
|
-
let defaultObj = node.declaration;
|
|
1798
|
-
if (t4.isIdentifier(defaultObj)) {
|
|
1799
|
-
defaultObj = findVarInitialization(defaultObj.name, ast.program);
|
|
1800
|
-
}
|
|
1801
|
-
defaultObj = stripTSModifiers(defaultObj);
|
|
1802
|
-
if (t4.isCallExpression(defaultObj) && t4.isObjectExpression(defaultObj.arguments?.[0])) {
|
|
1803
|
-
storySort = parseDefault(defaultObj.arguments[0], ast.program);
|
|
1804
|
-
} else if (t4.isObjectExpression(defaultObj)) {
|
|
1805
|
-
storySort = parseDefault(defaultObj, ast.program);
|
|
1806
|
-
} else {
|
|
1807
|
-
unsupported("default", false);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
});
|
|
1812
|
-
if (!storySort) {
|
|
1813
|
-
return void 0;
|
|
1814
|
-
}
|
|
1815
|
-
if (t4.isArrowFunctionExpression(storySort)) {
|
|
1816
|
-
const { code: sortCode } = generate3(storySort, {});
|
|
1817
|
-
return (0, eval)(sortCode);
|
|
1818
|
-
}
|
|
1819
|
-
if (t4.isFunctionExpression(storySort)) {
|
|
1820
|
-
const { code: sortCode } = generate3(storySort, {});
|
|
1821
|
-
const functionName = storySort.id?.name;
|
|
1822
|
-
const wrapper = `(a, b) => {
|
|
1823
|
-
${sortCode};
|
|
1824
|
-
return ${functionName}(a, b)
|
|
1825
|
-
}`;
|
|
1826
|
-
return (0, eval)(wrapper);
|
|
1827
|
-
}
|
|
1828
|
-
if (t4.isLiteral(storySort) || t4.isArrayExpression(storySort) || t4.isObjectExpression(storySort)) {
|
|
1829
|
-
return parseValue(storySort);
|
|
1830
|
-
}
|
|
1831
|
-
return unsupported("storySort", true);
|
|
1832
|
-
}, "getStorySortParameter");
|
|
1833
|
-
|
|
1834
|
-
// src/csf-tools/enrichCsf.ts
|
|
1835
|
-
import { generate as generate4, types as t5 } from "storybook/internal/babel";
|
|
1836
|
-
var enrichCsfStory = /* @__PURE__ */ __name((csf, csfSource, key, options) => {
|
|
1837
|
-
const storyExport = csfSource.getStoryExport(key);
|
|
1838
|
-
const isCsfFactory = t5.isCallExpression(storyExport) && t5.isMemberExpression(storyExport.callee) && t5.isIdentifier(storyExport.callee.object) && storyExport.callee.object.name === "meta";
|
|
1839
|
-
const source = !options?.disableSource && extractSource(storyExport);
|
|
1840
|
-
const description = !options?.disableDescription && extractDescription(csfSource._storyStatements[key]);
|
|
1841
|
-
const parameters = [];
|
|
1842
|
-
const baseStoryObject = isCsfFactory ? t5.memberExpression(t5.identifier(key), t5.identifier("input")) : t5.identifier(key);
|
|
1843
|
-
const originalParameters = t5.memberExpression(baseStoryObject, t5.identifier("parameters"));
|
|
1844
|
-
parameters.push(t5.spreadElement(originalParameters));
|
|
1845
|
-
const optionalDocs = t5.optionalMemberExpression(
|
|
1846
|
-
originalParameters,
|
|
1847
|
-
t5.identifier("docs"),
|
|
1848
|
-
false,
|
|
1849
|
-
true
|
|
1850
|
-
);
|
|
1851
|
-
const extraDocsParameters = [];
|
|
1852
|
-
if (source) {
|
|
1853
|
-
const optionalSource = t5.optionalMemberExpression(
|
|
1854
|
-
optionalDocs,
|
|
1855
|
-
t5.identifier("source"),
|
|
1856
|
-
false,
|
|
1857
|
-
true
|
|
1858
|
-
);
|
|
1859
|
-
extraDocsParameters.push(
|
|
1860
|
-
t5.objectProperty(
|
|
1861
|
-
t5.identifier("source"),
|
|
1862
|
-
t5.objectExpression([
|
|
1863
|
-
t5.objectProperty(t5.identifier("originalSource"), t5.stringLiteral(source)),
|
|
1864
|
-
t5.spreadElement(optionalSource)
|
|
1865
|
-
])
|
|
1866
|
-
)
|
|
1867
|
-
);
|
|
1868
|
-
}
|
|
1869
|
-
if (description) {
|
|
1870
|
-
const optionalDescription = t5.optionalMemberExpression(
|
|
1871
|
-
optionalDocs,
|
|
1872
|
-
t5.identifier("description"),
|
|
1873
|
-
false,
|
|
1874
|
-
true
|
|
1875
|
-
);
|
|
1876
|
-
extraDocsParameters.push(
|
|
1877
|
-
t5.objectProperty(
|
|
1878
|
-
t5.identifier("description"),
|
|
1879
|
-
t5.objectExpression([
|
|
1880
|
-
t5.objectProperty(t5.identifier("story"), t5.stringLiteral(description)),
|
|
1881
|
-
t5.spreadElement(optionalDescription)
|
|
1882
|
-
])
|
|
1883
|
-
)
|
|
1884
|
-
);
|
|
1885
|
-
}
|
|
1886
|
-
if (extraDocsParameters.length > 0) {
|
|
1887
|
-
parameters.push(
|
|
1888
|
-
t5.objectProperty(
|
|
1889
|
-
t5.identifier("docs"),
|
|
1890
|
-
t5.objectExpression([t5.spreadElement(optionalDocs), ...extraDocsParameters])
|
|
1891
|
-
)
|
|
1892
|
-
);
|
|
1893
|
-
const addParameter = t5.expressionStatement(
|
|
1894
|
-
t5.assignmentExpression("=", originalParameters, t5.objectExpression(parameters))
|
|
1895
|
-
);
|
|
1896
|
-
csf._ast.program.body.push(addParameter);
|
|
1897
|
-
}
|
|
1898
|
-
}, "enrichCsfStory");
|
|
1899
|
-
var addComponentDescription = /* @__PURE__ */ __name((node, path, value) => {
|
|
1900
|
-
if (!path.length) {
|
|
1901
|
-
const hasExistingComponent = node.properties.find(
|
|
1902
|
-
(p) => t5.isObjectProperty(p) && t5.isIdentifier(p.key) && p.key.name === "component"
|
|
1903
|
-
);
|
|
1904
|
-
if (!hasExistingComponent) {
|
|
1905
|
-
node.properties.unshift(value);
|
|
1906
|
-
}
|
|
1907
|
-
return;
|
|
1908
|
-
}
|
|
1909
|
-
const [first, ...rest] = path;
|
|
1910
|
-
const existing = node.properties.find(
|
|
1911
|
-
(p) => t5.isObjectProperty(p) && t5.isIdentifier(p.key) && p.key.name === first && t5.isObjectExpression(p.value)
|
|
1912
|
-
);
|
|
1913
|
-
let subNode;
|
|
1914
|
-
if (existing) {
|
|
1915
|
-
subNode = existing.value;
|
|
1916
|
-
} else {
|
|
1917
|
-
subNode = t5.objectExpression([]);
|
|
1918
|
-
node.properties.push(t5.objectProperty(t5.identifier(first), subNode));
|
|
1919
|
-
}
|
|
1920
|
-
addComponentDescription(subNode, rest, value);
|
|
1921
|
-
}, "addComponentDescription");
|
|
1922
|
-
var enrichCsfMeta = /* @__PURE__ */ __name((csf, csfSource, options) => {
|
|
1923
|
-
const description = !options?.disableDescription && extractDescription(csfSource._metaStatement);
|
|
1924
|
-
if (description) {
|
|
1925
|
-
const metaNode = csf._metaNode;
|
|
1926
|
-
if (metaNode && t5.isObjectExpression(metaNode)) {
|
|
1927
|
-
addComponentDescription(
|
|
1928
|
-
metaNode,
|
|
1929
|
-
["parameters", "docs", "description"],
|
|
1930
|
-
t5.objectProperty(t5.identifier("component"), t5.stringLiteral(description))
|
|
1931
|
-
);
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
}, "enrichCsfMeta");
|
|
1935
|
-
var enrichCsf = /* @__PURE__ */ __name((csf, csfSource, options) => {
|
|
1936
|
-
enrichCsfMeta(csf, csfSource, options);
|
|
1937
|
-
Object.keys(csf._storyExports).forEach((key) => {
|
|
1938
|
-
enrichCsfStory(csf, csfSource, key, options);
|
|
1939
|
-
});
|
|
1940
|
-
}, "enrichCsf");
|
|
1941
|
-
var extractSource = /* @__PURE__ */ __name((node) => {
|
|
1942
|
-
const src = t5.isVariableDeclarator(node) ? node.init : node;
|
|
1943
|
-
const { code } = generate4(src, {});
|
|
1944
|
-
return code;
|
|
1945
|
-
}, "extractSource");
|
|
1946
|
-
var extractDescription = /* @__PURE__ */ __name((node) => {
|
|
1947
|
-
if (!node?.leadingComments) {
|
|
1948
|
-
return "";
|
|
1949
|
-
}
|
|
1950
|
-
const comments = node.leadingComments.map((comment) => {
|
|
1951
|
-
if (comment.type === "CommentLine" || !comment.value.startsWith("*")) {
|
|
1952
|
-
return null;
|
|
1953
|
-
}
|
|
1954
|
-
return comment.value.split("\n").map((line) => line.replace(/^(\s+)?(\*+)?(\s)?/, "")).join("\n").trim();
|
|
1955
|
-
}).filter(Boolean);
|
|
1956
|
-
return comments.join("\n");
|
|
1957
|
-
}, "extractDescription");
|
|
1958
|
-
|
|
1959
|
-
// src/csf-tools/index.ts
|
|
1960
|
-
import { babelParse as babelParse4 } from "storybook/internal/babel";
|
|
1961
|
-
|
|
1962
|
-
// src/csf-tools/vitest-plugin/transformer.ts
|
|
1963
|
-
var import_ts_dedent4 = __toESM(require_dist(), 1);
|
|
1964
|
-
import { types as t6 } from "storybook/internal/babel";
|
|
1965
|
-
import { getStoryTitle } from "storybook/internal/common";
|
|
1966
|
-
import { combineTags } from "storybook/internal/csf";
|
|
1967
|
-
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
1968
|
-
var isValidTest = /* @__PURE__ */ __name((storyTags, tagsFilter) => {
|
|
1969
|
-
if (tagsFilter.include.length && !tagsFilter.include.some((tag) => storyTags?.includes(tag))) {
|
|
1970
|
-
return false;
|
|
1971
|
-
}
|
|
1972
|
-
if (tagsFilter.exclude.some((tag) => storyTags?.includes(tag))) {
|
|
1973
|
-
return false;
|
|
1974
|
-
}
|
|
1975
|
-
return true;
|
|
1976
|
-
}, "isValidTest");
|
|
1977
|
-
var DOUBLE_SPACES = " ";
|
|
1978
|
-
var getLiteralWithZeroWidthSpace = /* @__PURE__ */ __name((testTitle) => t6.stringLiteral(`${testTitle}${DOUBLE_SPACES}`), "getLiteralWithZeroWidthSpace");
|
|
1979
|
-
async function vitestTransform({
|
|
1980
|
-
code,
|
|
1981
|
-
fileName,
|
|
1982
|
-
configDir,
|
|
1983
|
-
stories,
|
|
1984
|
-
tagsFilter,
|
|
1985
|
-
previewLevelTags = []
|
|
1986
|
-
}) {
|
|
1987
|
-
const parsed = loadCsf(code, {
|
|
1988
|
-
fileName,
|
|
1989
|
-
transformInlineMeta: true,
|
|
1990
|
-
makeTitle: /* @__PURE__ */ __name((title) => {
|
|
1991
|
-
const result = getStoryTitle({
|
|
1992
|
-
storyFilePath: fileName,
|
|
1993
|
-
configDir,
|
|
1994
|
-
stories,
|
|
1995
|
-
userTitle: title
|
|
1996
|
-
}) || "unknown";
|
|
1997
|
-
if (result === "unknown") {
|
|
1998
|
-
logger4.warn(
|
|
1999
|
-
import_ts_dedent4.dedent`
|
|
2000
|
-
[Storybook]: Could not calculate story title for "${fileName}".
|
|
2001
|
-
Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${configDir}".
|
|
2002
|
-
`
|
|
2003
|
-
);
|
|
2004
|
-
}
|
|
2005
|
-
return result;
|
|
2006
|
-
}, "makeTitle")
|
|
2007
|
-
}).parse();
|
|
2008
|
-
const ast = parsed._ast;
|
|
2009
|
-
const metaExportName = parsed._metaVariableName;
|
|
2010
|
-
const metaNode = parsed._metaNode;
|
|
2011
|
-
const metaTitleProperty = metaNode.properties.find(
|
|
2012
|
-
(prop) => t6.isObjectProperty(prop) && t6.isIdentifier(prop.key) && prop.key.name === "title"
|
|
2013
|
-
);
|
|
2014
|
-
const metaTitle = t6.stringLiteral(parsed._meta?.title || "unknown");
|
|
2015
|
-
if (!metaTitleProperty) {
|
|
2016
|
-
metaNode.properties.push(t6.objectProperty(t6.identifier("title"), metaTitle));
|
|
2017
|
-
} else if (t6.isObjectProperty(metaTitleProperty)) {
|
|
2018
|
-
metaTitleProperty.value = metaTitle;
|
|
2019
|
-
}
|
|
2020
|
-
if (!metaNode || !parsed._meta) {
|
|
2021
|
-
throw new Error(
|
|
2022
|
-
"The Storybook vitest plugin could not detect the meta (default export) object in the story file. \n\nPlease make sure you have a default export with the meta object. If you are using a different export format that is not supported, please file an issue with details about your use case."
|
|
2023
|
-
);
|
|
2024
|
-
}
|
|
2025
|
-
const validStories = {};
|
|
2026
|
-
Object.keys(parsed._stories).forEach((key) => {
|
|
2027
|
-
const finalTags = combineTags(
|
|
2028
|
-
"test",
|
|
2029
|
-
"dev",
|
|
2030
|
-
...previewLevelTags,
|
|
2031
|
-
...parsed.meta?.tags || [],
|
|
2032
|
-
...parsed._stories[key].tags || []
|
|
2033
|
-
);
|
|
2034
|
-
if (isValidTest(finalTags, tagsFilter)) {
|
|
2035
|
-
validStories[key] = parsed._storyStatements[key];
|
|
2036
|
-
}
|
|
2037
|
-
});
|
|
2038
|
-
const vitestTestId = parsed._file.path.scope.generateUidIdentifier("test");
|
|
2039
|
-
const vitestDescribeId = parsed._file.path.scope.generateUidIdentifier("describe");
|
|
2040
|
-
if (Object.keys(validStories).length === 0) {
|
|
2041
|
-
const describeSkipBlock = t6.expressionStatement(
|
|
2042
|
-
t6.callExpression(t6.memberExpression(vitestDescribeId, t6.identifier("skip")), [
|
|
2043
|
-
t6.stringLiteral("No valid tests found")
|
|
2044
|
-
])
|
|
2045
|
-
);
|
|
2046
|
-
ast.program.body.push(describeSkipBlock);
|
|
2047
|
-
const imports2 = [
|
|
2048
|
-
t6.importDeclaration(
|
|
2049
|
-
[
|
|
2050
|
-
t6.importSpecifier(vitestTestId, t6.identifier("test")),
|
|
2051
|
-
t6.importSpecifier(vitestDescribeId, t6.identifier("describe"))
|
|
2052
|
-
],
|
|
2053
|
-
t6.stringLiteral("vitest")
|
|
2054
|
-
)
|
|
2055
|
-
];
|
|
2056
|
-
ast.program.body.unshift(...imports2);
|
|
2057
|
-
return formatCsf(parsed, { sourceMaps: true, sourceFileName: fileName }, code);
|
|
2058
|
-
}
|
|
2059
|
-
const vitestExpectId = parsed._file.path.scope.generateUidIdentifier("expect");
|
|
2060
|
-
const testStoryId = parsed._file.path.scope.generateUidIdentifier("testStory");
|
|
2061
|
-
const skipTagsId = t6.identifier(JSON.stringify(tagsFilter.skip));
|
|
2062
|
-
function getTestGuardDeclaration() {
|
|
2063
|
-
const isRunningFromThisFileId2 = parsed._file.path.scope.generateUidIdentifier("isRunningFromThisFile");
|
|
2064
|
-
const testPathProperty = t6.memberExpression(
|
|
2065
|
-
t6.callExpression(t6.memberExpression(vitestExpectId, t6.identifier("getState")), []),
|
|
2066
|
-
t6.identifier("testPath")
|
|
2067
|
-
);
|
|
2068
|
-
const filePathProperty = t6.memberExpression(
|
|
2069
|
-
t6.memberExpression(t6.identifier("globalThis"), t6.identifier("__vitest_worker__")),
|
|
2070
|
-
t6.identifier("filepath")
|
|
2071
|
-
);
|
|
2072
|
-
const nullishCoalescingExpression = t6.logicalExpression(
|
|
2073
|
-
"??",
|
|
2074
|
-
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
|
|
2075
|
-
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
|
|
2076
|
-
filePathProperty,
|
|
2077
|
-
testPathProperty
|
|
2078
|
-
);
|
|
2079
|
-
const includesCall = t6.callExpression(
|
|
2080
|
-
t6.memberExpression(
|
|
2081
|
-
t6.callExpression(t6.identifier("convertToFilePath"), [
|
|
2082
|
-
t6.memberExpression(
|
|
2083
|
-
t6.memberExpression(t6.identifier("import"), t6.identifier("meta")),
|
|
2084
|
-
t6.identifier("url")
|
|
2085
|
-
)
|
|
2086
|
-
]),
|
|
2087
|
-
t6.identifier("includes")
|
|
2088
|
-
),
|
|
2089
|
-
[nullishCoalescingExpression]
|
|
2090
|
-
);
|
|
2091
|
-
const isRunningFromThisFileDeclaration2 = t6.variableDeclaration("const", [
|
|
2092
|
-
t6.variableDeclarator(isRunningFromThisFileId2, includesCall)
|
|
2093
|
-
]);
|
|
2094
|
-
return { isRunningFromThisFileDeclaration: isRunningFromThisFileDeclaration2, isRunningFromThisFileId: isRunningFromThisFileId2 };
|
|
2095
|
-
}
|
|
2096
|
-
__name(getTestGuardDeclaration, "getTestGuardDeclaration");
|
|
2097
|
-
const { isRunningFromThisFileDeclaration, isRunningFromThisFileId } = getTestGuardDeclaration();
|
|
2098
|
-
ast.program.body.push(isRunningFromThisFileDeclaration);
|
|
2099
|
-
const getTestStatementForStory = /* @__PURE__ */ __name(({
|
|
2100
|
-
localName,
|
|
2101
|
-
exportName,
|
|
2102
|
-
testTitle,
|
|
2103
|
-
node,
|
|
2104
|
-
overrideSourcemap = true,
|
|
2105
|
-
storyId
|
|
2106
|
-
}) => {
|
|
2107
|
-
const testStoryCall = t6.expressionStatement(
|
|
2108
|
-
t6.callExpression(vitestTestId, [
|
|
2109
|
-
t6.stringLiteral(testTitle),
|
|
2110
|
-
t6.callExpression(testStoryId, [
|
|
2111
|
-
t6.stringLiteral(exportName),
|
|
2112
|
-
t6.identifier(localName),
|
|
2113
|
-
t6.identifier(metaExportName),
|
|
2114
|
-
skipTagsId,
|
|
2115
|
-
t6.stringLiteral(storyId)
|
|
2116
|
-
])
|
|
2117
|
-
])
|
|
2118
|
-
);
|
|
2119
|
-
if (overrideSourcemap) {
|
|
2120
|
-
testStoryCall.loc = node.loc;
|
|
2121
|
-
}
|
|
2122
|
-
return testStoryCall;
|
|
2123
|
-
}, "getTestStatementForStory");
|
|
2124
|
-
const getDescribeStatementForStory = /* @__PURE__ */ __name((options) => {
|
|
2125
|
-
const { localName, describeTitle, exportName, tests, node, parentStoryId } = options;
|
|
2126
|
-
const describeBlock = t6.callExpression(vitestDescribeId, [
|
|
2127
|
-
getLiteralWithZeroWidthSpace(describeTitle),
|
|
2128
|
-
t6.arrowFunctionExpression(
|
|
2129
|
-
[],
|
|
2130
|
-
t6.blockStatement([
|
|
2131
|
-
getTestStatementForStory({
|
|
2132
|
-
...options,
|
|
2133
|
-
testTitle: "base story",
|
|
2134
|
-
overrideSourcemap: false,
|
|
2135
|
-
storyId: parentStoryId
|
|
2136
|
-
}),
|
|
2137
|
-
...tests.map(({ name: testName, node: testNode, id: storyId }) => {
|
|
2138
|
-
const testStatement = t6.expressionStatement(
|
|
2139
|
-
t6.callExpression(vitestTestId, [
|
|
2140
|
-
t6.stringLiteral(testName),
|
|
2141
|
-
t6.callExpression(testStoryId, [
|
|
2142
|
-
t6.stringLiteral(exportName),
|
|
2143
|
-
t6.identifier(localName),
|
|
2144
|
-
t6.identifier(metaExportName),
|
|
2145
|
-
t6.arrayExpression([]),
|
|
2146
|
-
t6.stringLiteral(storyId),
|
|
2147
|
-
t6.stringLiteral(testName)
|
|
2148
|
-
])
|
|
2149
|
-
])
|
|
2150
|
-
);
|
|
2151
|
-
testStatement.loc = testNode.loc;
|
|
2152
|
-
return testStatement;
|
|
2153
|
-
})
|
|
2154
|
-
])
|
|
2155
|
-
)
|
|
2156
|
-
]);
|
|
2157
|
-
describeBlock.loc = node.loc;
|
|
2158
|
-
return t6.expressionStatement(describeBlock);
|
|
2159
|
-
}, "getDescribeStatementForStory");
|
|
2160
|
-
const storyTestStatements = Object.entries(validStories).map(([exportName, node]) => {
|
|
2161
|
-
if (node === null) {
|
|
2162
|
-
logger4.warn(
|
|
2163
|
-
import_ts_dedent4.dedent`
|
|
2164
|
-
[Storybook]: Could not transform "${exportName}" story into test at "${fileName}".
|
|
2165
|
-
Please make sure to define stories in the same file and not re-export stories coming from other files".
|
|
2166
|
-
`
|
|
2167
|
-
);
|
|
2168
|
-
return;
|
|
2169
|
-
}
|
|
2170
|
-
const localName = parsed._stories[exportName].localName ?? exportName;
|
|
2171
|
-
const testTitle = parsed._stories[exportName].name ?? exportName;
|
|
2172
|
-
const storyId = parsed._stories[exportName].id;
|
|
2173
|
-
const tests = parsed.getStoryTests(exportName);
|
|
2174
|
-
if (tests?.length > 0) {
|
|
2175
|
-
return getDescribeStatementForStory({
|
|
2176
|
-
localName,
|
|
2177
|
-
describeTitle: testTitle,
|
|
2178
|
-
exportName,
|
|
2179
|
-
tests,
|
|
2180
|
-
node,
|
|
2181
|
-
parentStoryId: storyId
|
|
2182
|
-
});
|
|
2183
|
-
}
|
|
2184
|
-
return getTestStatementForStory({
|
|
2185
|
-
testTitle,
|
|
2186
|
-
localName,
|
|
2187
|
-
exportName,
|
|
2188
|
-
node,
|
|
2189
|
-
storyId
|
|
2190
|
-
});
|
|
2191
|
-
}).filter((st) => !!st);
|
|
2192
|
-
const testBlock = t6.ifStatement(isRunningFromThisFileId, t6.blockStatement(storyTestStatements));
|
|
2193
|
-
ast.program.body.push(testBlock);
|
|
2194
|
-
const hasTests = Object.keys(validStories).some(
|
|
2195
|
-
(exportName) => parsed.getStoryTests(exportName).length > 0
|
|
2196
|
-
);
|
|
2197
|
-
const imports = [
|
|
2198
|
-
t6.importDeclaration(
|
|
2199
|
-
[
|
|
2200
|
-
t6.importSpecifier(vitestTestId, t6.identifier("test")),
|
|
2201
|
-
t6.importSpecifier(vitestExpectId, t6.identifier("expect")),
|
|
2202
|
-
...hasTests ? [t6.importSpecifier(vitestDescribeId, t6.identifier("describe"))] : []
|
|
2203
|
-
],
|
|
2204
|
-
t6.stringLiteral("vitest")
|
|
2205
|
-
),
|
|
2206
|
-
t6.importDeclaration(
|
|
2207
|
-
[
|
|
2208
|
-
t6.importSpecifier(testStoryId, t6.identifier("testStory")),
|
|
2209
|
-
t6.importSpecifier(t6.identifier("convertToFilePath"), t6.identifier("convertToFilePath"))
|
|
2210
|
-
],
|
|
2211
|
-
t6.stringLiteral("@storybook/addon-vitest/internal/test-utils")
|
|
2212
|
-
)
|
|
2213
|
-
];
|
|
2214
|
-
ast.program.body.unshift(...imports);
|
|
2215
|
-
return formatCsf(parsed, { sourceMaps: true, sourceFileName: fileName }, code);
|
|
2216
|
-
}
|
|
2217
|
-
__name(vitestTransform, "vitestTransform");
|
|
2218
|
-
|
|
2219
|
-
export {
|
|
2220
|
-
isValidPreviewPath,
|
|
2221
|
-
isModuleMock,
|
|
2222
|
-
NoMetaError,
|
|
2223
|
-
MultipleMetaError,
|
|
2224
|
-
MixedFactoryError,
|
|
2225
|
-
BadMetaError,
|
|
2226
|
-
CsfFile,
|
|
2227
|
-
babelParseFile,
|
|
2228
|
-
loadCsf,
|
|
2229
|
-
formatCsf,
|
|
2230
|
-
printCsf,
|
|
2231
|
-
readCsf,
|
|
2232
|
-
writeCsf,
|
|
2233
|
-
ConfigFile,
|
|
2234
|
-
loadConfig,
|
|
2235
|
-
formatConfig,
|
|
2236
|
-
printConfig,
|
|
2237
|
-
readConfig,
|
|
2238
|
-
writeConfig,
|
|
2239
|
-
isCsfFactoryPreview,
|
|
2240
|
-
getStorySortParameter,
|
|
2241
|
-
enrichCsfStory,
|
|
2242
|
-
enrichCsfMeta,
|
|
2243
|
-
enrichCsf,
|
|
2244
|
-
extractSource,
|
|
2245
|
-
extractDescription,
|
|
2246
|
-
vitestTransform,
|
|
2247
|
-
babelParse4 as babelParse
|
|
2248
|
-
};
|