create-storybook 10.2.4 → 10.2.6
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/_node-chunks/{chunk-6IPEYKLS.js → chunk-5BPXECTR.js} +646 -99
- package/dist/_node-chunks/{chunk-SELEDHTP.js → chunk-6GIN6MWS.js} +7 -7
- package/dist/_node-chunks/chunk-OQWKAX3X.js +92 -0
- package/dist/_node-chunks/{chunk-FRKTKJP6.js → chunk-THR72EAG.js} +6 -6
- package/dist/_node-chunks/{postinstallAddon-YDLXBU2S.js → postinstallAddon-SN6SHJQO.js} +11 -10
- package/dist/_node-chunks/{run-QKY6KKQJ.js → run-IIT4V4GL.js} +11 -10
- package/dist/_node-chunks/vitest.config-7QH3VAVK.js +53 -0
- package/dist/_node-chunks/vitest.config.3.2-HJ3TVZJ4.js +53 -0
- package/dist/_node-chunks/vitest.config.4-IRNJJKM3.js +55 -0
- package/dist/_node-chunks/vitest.workspace-YTF65SM6.js +50 -0
- package/dist/bin/index.js +9 -9
- package/dist/index.js +10 -9
- package/package.json +2 -2
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_n3uavwb99b from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_n3uavwb99b from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_n3uavwb99b from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_n3uavwb99b.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_n3uavwb99b.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_n3uavwb99b.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
require_dist
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6GIN6MWS.js";
|
|
15
|
+
import {
|
|
16
|
+
dirname,
|
|
17
|
+
normalize,
|
|
18
|
+
relative,
|
|
19
|
+
resolve
|
|
20
|
+
} from "./chunk-OQWKAX3X.js";
|
|
15
21
|
import {
|
|
16
22
|
__commonJS,
|
|
17
23
|
__toESM
|
|
18
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-THR72EAG.js";
|
|
19
25
|
|
|
20
26
|
// ../../../node_modules/picocolors/picocolors.js
|
|
21
27
|
var require_picocolors = __commonJS({
|
|
@@ -563,7 +569,7 @@ import { logger as logger4, prompt as prompt2 } from "storybook/internal/node-lo
|
|
|
563
569
|
|
|
564
570
|
// src/services/ProjectTypeService.ts
|
|
565
571
|
import { existsSync as existsSync2 } from "node:fs";
|
|
566
|
-
import { resolve as
|
|
572
|
+
import { resolve as resolve3 } from "node:path";
|
|
567
573
|
import { ProjectType as ProjectType2 } from "storybook/internal/cli";
|
|
568
574
|
import { HandledError, getProjectRoot } from "storybook/internal/common";
|
|
569
575
|
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
@@ -575,18 +581,18 @@ import { join as join2 } from "node:path";
|
|
|
575
581
|
import { existsSync, statSync } from "node:fs";
|
|
576
582
|
|
|
577
583
|
// ../../../node_modules/empathic/walk.mjs
|
|
578
|
-
import { dirname } from "node:path";
|
|
584
|
+
import { dirname as dirname2 } from "node:path";
|
|
579
585
|
|
|
580
586
|
// ../../../node_modules/empathic/resolve.mjs
|
|
581
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
587
|
+
import { isAbsolute, join, resolve as resolve2 } from "node:path";
|
|
582
588
|
function absolute(input, root) {
|
|
583
|
-
return isAbsolute(input) ? input :
|
|
589
|
+
return isAbsolute(input) ? input : resolve2(root || ".", input);
|
|
584
590
|
}
|
|
585
591
|
|
|
586
592
|
// ../../../node_modules/empathic/walk.mjs
|
|
587
593
|
function up(base, options) {
|
|
588
594
|
let { last, cwd } = options || {}, tmp = absolute(base, cwd), root = absolute(last || "/", cwd), prev, arr = [];
|
|
589
|
-
for (; prev !== root && (arr.push(tmp), tmp =
|
|
595
|
+
for (; prev !== root && (arr.push(tmp), tmp = dirname2(prev = tmp), tmp !== prev); )
|
|
590
596
|
;
|
|
591
597
|
return arr;
|
|
592
598
|
}
|
|
@@ -695,7 +701,7 @@ var ProjectTypeService = class {
|
|
|
695
701
|
}
|
|
696
702
|
];
|
|
697
703
|
}
|
|
698
|
-
isStorybookInstantiated(configDir =
|
|
704
|
+
isStorybookInstantiated(configDir = resolve3(process.cwd(), ".storybook")) {
|
|
699
705
|
return existsSync2(configDir);
|
|
700
706
|
}
|
|
701
707
|
async validateProvidedType(projectTypeProvided) {
|
|
@@ -743,8 +749,8 @@ var ProjectTypeService = class {
|
|
|
743
749
|
getModulePackageJSONVersion("@babel/plugin-transform-typescript"),
|
|
744
750
|
getModulePackageJSONVersion("@typescript-eslint/parser"),
|
|
745
751
|
getModulePackageJSONVersion("eslint-plugin-storybook")
|
|
746
|
-
]),
|
|
747
|
-
return isTypescriptDirectDependency && typescriptVersion ?
|
|
752
|
+
]), satisfies2 = (version, range) => version ? semver.satisfies(version, range, { includePrerelease: !0 }) : !1;
|
|
753
|
+
return isTypescriptDirectDependency && typescriptVersion ? satisfies2(typescriptVersion, ">=4.9.0") && (!prettierVersion || semver.gte(prettierVersion, "2.8.0")) && (!babelPluginTransformTypescriptVersion || satisfies2(babelPluginTransformTypescriptVersion, ">=7.20.0")) && (!typescriptEslintParserVersion || satisfies2(typescriptEslintParserVersion, ">=5.44.0")) && (!eslintPluginStorybookVersion || satisfies2(eslintPluginStorybookVersion, ">=0.6.8")) ? language = SupportedLanguage.TYPESCRIPT : logger3.warn(
|
|
748
754
|
"Detected TypeScript < 4.9 or incompatible tooling, populating with JavaScript examples"
|
|
749
755
|
) : existsSync2("tsconfig.json") && (language = SupportedLanguage.TYPESCRIPT), language;
|
|
750
756
|
}
|
|
@@ -1029,7 +1035,7 @@ var UserPreferencesCommand = class {
|
|
|
1029
1035
|
|
|
1030
1036
|
// src/generators/baseGenerator.ts
|
|
1031
1037
|
import { mkdir } from "node:fs/promises";
|
|
1032
|
-
import { dirname as
|
|
1038
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
1033
1039
|
import { fileURLToPath } from "node:url";
|
|
1034
1040
|
import {
|
|
1035
1041
|
configureEslintPlugin,
|
|
@@ -1062,7 +1068,7 @@ var import_ts_dedent7 = __toESM(require_dist(), 1);
|
|
|
1062
1068
|
// src/generators/configure.ts
|
|
1063
1069
|
var import_ts_dedent6 = __toESM(require_dist(), 1);
|
|
1064
1070
|
import { stat, writeFile } from "node:fs/promises";
|
|
1065
|
-
import { resolve as
|
|
1071
|
+
import { resolve as resolve4 } from "node:path";
|
|
1066
1072
|
import { logger as logger8 } from "storybook/internal/node-logger";
|
|
1067
1073
|
import { Feature as Feature4, SupportedLanguage as SupportedLanguage2 } from "storybook/internal/types";
|
|
1068
1074
|
var pathExists = async (path) => stat(path).then(() => !0).catch(() => !1);
|
|
@@ -1076,7 +1082,7 @@ async function configureMain({
|
|
|
1076
1082
|
features,
|
|
1077
1083
|
...custom
|
|
1078
1084
|
}) {
|
|
1079
|
-
let srcPath =
|
|
1085
|
+
let srcPath = resolve4(storybookConfigFolder, "../src"), prefix2 = await pathExists(srcPath) ? "../src" : "../stories", stories = features.has(Feature4.DOCS) ? [`${prefix2}/**/*.mdx`] : [];
|
|
1080
1086
|
stories.push(`${prefix2}/**/*.stories.@(${extensions.join("|")})`);
|
|
1081
1087
|
let config = {
|
|
1082
1088
|
stories,
|
|
@@ -1284,7 +1290,7 @@ async function baseGenerator(packageManager, npmOptions, { language, builder, fr
|
|
|
1284
1290
|
language,
|
|
1285
1291
|
destination: componentsDestinationPath,
|
|
1286
1292
|
commonAssetsDir: join3(
|
|
1287
|
-
|
|
1293
|
+
dirname3(fileURLToPath(import.meta.resolve("create-storybook/package.json"))),
|
|
1288
1294
|
"rendererAssets",
|
|
1289
1295
|
"common"
|
|
1290
1296
|
),
|
|
@@ -1388,14 +1394,554 @@ var GeneratorExecutionCommand = class {
|
|
|
1388
1394
|
}) => new GeneratorExecutionCommand(dependencyCollector, packageManager).execute(options);
|
|
1389
1395
|
|
|
1390
1396
|
// src/commands/AddonConfigurationCommand.ts
|
|
1391
|
-
var
|
|
1392
|
-
import { AddonVitestService as
|
|
1393
|
-
import { CLI_COLORS as
|
|
1397
|
+
var import_ts_dedent9 = __toESM(require_dist(), 1);
|
|
1398
|
+
import { AddonVitestService as AddonVitestService3 } from "storybook/internal/cli";
|
|
1399
|
+
import { CLI_COLORS as CLI_COLORS3, logger as logger9, prompt as prompt6 } from "storybook/internal/node-logger";
|
|
1394
1400
|
import { ErrorCollector } from "storybook/internal/telemetry";
|
|
1401
|
+
|
|
1402
|
+
// ../../addons/a11y/src/postinstall.ts
|
|
1403
|
+
import { JsPackageManagerFactory as JsPackageManagerFactory2, versions as versions2 } from "storybook/internal/common";
|
|
1404
|
+
async function postinstall(options) {
|
|
1405
|
+
let args = [
|
|
1406
|
+
options.skipInstall ? `storybook@${versions2.storybook}` : "storybook",
|
|
1407
|
+
"automigrate",
|
|
1408
|
+
"addon-a11y-addon-test"
|
|
1409
|
+
];
|
|
1410
|
+
args.push("--loglevel", "silent"), args.push("--skip-doctor"), options.yes && args.push("--yes"), options.packageManager && args.push("--package-manager", options.packageManager), options.configDir && args.push("--config-dir", options.configDir), await JsPackageManagerFactory2.getPackageManager({
|
|
1411
|
+
force: options.packageManager,
|
|
1412
|
+
configDir: options.configDir
|
|
1413
|
+
}).runPackageCommand({ args, useRemotePkg: !!options.skipInstall });
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// ../../addons/vitest/src/postinstall.ts
|
|
1417
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
1418
|
+
import * as fs from "node:fs/promises";
|
|
1419
|
+
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
1420
|
+
import { babelParse, generate, traverse } from "storybook/internal/babel";
|
|
1421
|
+
import { AddonVitestService as AddonVitestService2 } from "storybook/internal/cli";
|
|
1422
|
+
import {
|
|
1423
|
+
JsPackageManagerFactory as JsPackageManagerFactory3,
|
|
1424
|
+
formatFileContent,
|
|
1425
|
+
getProjectRoot as getProjectRoot3,
|
|
1426
|
+
getStorybookInfo,
|
|
1427
|
+
versions as versions3
|
|
1428
|
+
} from "storybook/internal/common";
|
|
1429
|
+
import { CLI_COLORS as CLI_COLORS2 } from "storybook/internal/node-logger";
|
|
1430
|
+
import {
|
|
1431
|
+
AddonVitestPostinstallConfigUpdateError,
|
|
1432
|
+
AddonVitestPostinstallError,
|
|
1433
|
+
AddonVitestPostinstallFailedAddonA11yError,
|
|
1434
|
+
AddonVitestPostinstallPrerequisiteCheckError,
|
|
1435
|
+
AddonVitestPostinstallWorkspaceUpdateError
|
|
1436
|
+
} from "storybook/internal/server-errors";
|
|
1437
|
+
import { SupportedFramework as SupportedFramework3 } from "storybook/internal/types";
|
|
1438
|
+
var import_ts_dedent8 = __toESM(require_dist(), 1);
|
|
1439
|
+
import { coerce, satisfies } from "semver";
|
|
1440
|
+
|
|
1441
|
+
// ../../core/src/component-testing/constants.ts
|
|
1442
|
+
var ADDON_ID = "storybook/interactions", PANEL_ID = `${ADDON_ID}/panel`;
|
|
1443
|
+
var DOCUMENTATION_LINK = "writing-tests/integrations/vitest-addon", DOCUMENTATION_DISCREPANCY_LINK = `${DOCUMENTATION_LINK}#what-happens-when-there-are-different-test-results-in-multiple-environments`;
|
|
1444
|
+
|
|
1445
|
+
// ../../addons/a11y/src/constants.ts
|
|
1446
|
+
var ADDON_ID2 = "storybook/a11y", PANEL_ID2 = `${ADDON_ID2}/panel`;
|
|
1447
|
+
var UI_STATE_ID = `${ADDON_ID2}/ui`, RESULT = `${ADDON_ID2}/result`, REQUEST = `${ADDON_ID2}/request`, RUNNING = `${ADDON_ID2}/running`, ERROR = `${ADDON_ID2}/error`, MANUAL = `${ADDON_ID2}/manual`, SELECT = `${ADDON_ID2}/select`, DOCUMENTATION_LINK2 = "writing-tests/accessibility-testing", DOCUMENTATION_DISCREPANCY_LINK2 = `${DOCUMENTATION_LINK2}#why-are-my-tests-failing-in-different-environments`;
|
|
1448
|
+
|
|
1449
|
+
// ../../addons/vitest/src/constants.ts
|
|
1450
|
+
var ADDON_ID3 = "storybook/test", TEST_PROVIDER_ID = `${ADDON_ID3}/test-provider`, STORYBOOK_ADDON_TEST_CHANNEL = `${ADDON_ID3}/channel`;
|
|
1451
|
+
var DOCUMENTATION_LINK3 = "writing-tests/integrations/vitest-addon", DOCUMENTATION_FATAL_ERROR_LINK = `${DOCUMENTATION_LINK3}#what-happens-if-vitest-itself-has-an-error`;
|
|
1452
|
+
var storeOptions = {
|
|
1453
|
+
id: ADDON_ID3,
|
|
1454
|
+
initialState: {
|
|
1455
|
+
config: {
|
|
1456
|
+
coverage: !1,
|
|
1457
|
+
a11y: !1
|
|
1458
|
+
},
|
|
1459
|
+
watching: !1,
|
|
1460
|
+
cancelling: !1,
|
|
1461
|
+
fatalError: void 0,
|
|
1462
|
+
indexUrl: void 0,
|
|
1463
|
+
previewAnnotations: [],
|
|
1464
|
+
currentRun: {
|
|
1465
|
+
triggeredBy: void 0,
|
|
1466
|
+
config: {
|
|
1467
|
+
coverage: !1,
|
|
1468
|
+
a11y: !1
|
|
1469
|
+
},
|
|
1470
|
+
componentTestCount: {
|
|
1471
|
+
success: 0,
|
|
1472
|
+
error: 0
|
|
1473
|
+
},
|
|
1474
|
+
a11yCount: {
|
|
1475
|
+
success: 0,
|
|
1476
|
+
warning: 0,
|
|
1477
|
+
error: 0
|
|
1478
|
+
},
|
|
1479
|
+
storyIds: void 0,
|
|
1480
|
+
totalTestCount: void 0,
|
|
1481
|
+
startedAt: void 0,
|
|
1482
|
+
finishedAt: void 0,
|
|
1483
|
+
unhandledErrors: [],
|
|
1484
|
+
coverageSummary: void 0
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
var STORE_CHANNEL_EVENT_NAME = `UNIVERSAL_STORE:${storeOptions.id}`;
|
|
1489
|
+
|
|
1490
|
+
// ../../addons/vitest/src/updateVitestFile.ts
|
|
1491
|
+
async function getTemplatePath(name) {
|
|
1492
|
+
switch (name) {
|
|
1493
|
+
case "vitest.config.template":
|
|
1494
|
+
return import("./vitest.config-7QH3VAVK.js");
|
|
1495
|
+
case "vitest.config.4.template":
|
|
1496
|
+
return import("./vitest.config.4-IRNJJKM3.js");
|
|
1497
|
+
case "vitest.config.3.2.template":
|
|
1498
|
+
return import("./vitest.config.3.2-HJ3TVZJ4.js");
|
|
1499
|
+
case "vitest.workspace.template":
|
|
1500
|
+
return import("./vitest.workspace-YTF65SM6.js");
|
|
1501
|
+
default:
|
|
1502
|
+
throw new Error(`Unknown template: ${name}`);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
var loadTemplate = async (name, replacements) => {
|
|
1506
|
+
let template = (await getTemplatePath(name)).default;
|
|
1507
|
+
return Object.entries(replacements).forEach(
|
|
1508
|
+
([key, value]) => template = template.replace(key, normalize(value))
|
|
1509
|
+
), template;
|
|
1510
|
+
}, mergeProperties = (source, target) => {
|
|
1511
|
+
for (let sourceProp of source)
|
|
1512
|
+
if (sourceProp.type === "ObjectProperty") {
|
|
1513
|
+
let targetProp = target.find(
|
|
1514
|
+
(p) => sourceProp.key.type === "Identifier" && p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === sourceProp.key.name
|
|
1515
|
+
);
|
|
1516
|
+
targetProp && targetProp.type === "ObjectProperty" ? sourceProp.value.type === "ObjectExpression" && targetProp.value.type === "ObjectExpression" ? mergeProperties(sourceProp.value.properties, targetProp.value.properties) : sourceProp.value.type === "ArrayExpression" && targetProp.value.type === "ArrayExpression" ? targetProp.value.elements.push(...sourceProp.value.elements) : targetProp.value = sourceProp.value : target.push(sourceProp);
|
|
1517
|
+
}
|
|
1518
|
+
}, getTargetConfigObject = (target, exportDefault) => {
|
|
1519
|
+
let decl = exportDefault.declaration;
|
|
1520
|
+
if (decl.type === "ObjectExpression")
|
|
1521
|
+
return decl;
|
|
1522
|
+
if (decl.type === "CallExpression" && decl.callee.type === "Identifier" && decl.callee.name === "defineConfig" && decl.arguments[0]?.type === "ObjectExpression")
|
|
1523
|
+
return decl.arguments[0];
|
|
1524
|
+
if (decl.type === "Identifier") {
|
|
1525
|
+
let varName = decl.name, varDecl = target.program.body.find(
|
|
1526
|
+
(n) => n.type === "VariableDeclaration" && n.declarations.some((d) => d.id.type === "Identifier" && d.id.name === varName)
|
|
1527
|
+
);
|
|
1528
|
+
if (!varDecl)
|
|
1529
|
+
return null;
|
|
1530
|
+
let declarator = varDecl.declarations.find(
|
|
1531
|
+
(d) => d.id.type === "Identifier" && d.id.name === varName
|
|
1532
|
+
);
|
|
1533
|
+
if (!declarator?.init)
|
|
1534
|
+
return null;
|
|
1535
|
+
let init = declarator.init;
|
|
1536
|
+
return init.type === "CallExpression" && init.callee.type === "Identifier" && init.callee.name === "defineConfig" && init.arguments[0]?.type === "ObjectExpression" ? init.arguments[0] : init.type === "ObjectExpression" ? init : null;
|
|
1537
|
+
}
|
|
1538
|
+
return null;
|
|
1539
|
+
}, updateConfigFile = (source, target) => {
|
|
1540
|
+
let updated = !1, sourceExportDefault = source.program.body.find(
|
|
1541
|
+
(n) => n.type === "ExportDefaultDeclaration"
|
|
1542
|
+
);
|
|
1543
|
+
if (!sourceExportDefault || sourceExportDefault.declaration.type !== "CallExpression")
|
|
1544
|
+
return !1;
|
|
1545
|
+
let targetExportDefault = target.program.body.find(
|
|
1546
|
+
(n) => n.type === "ExportDefaultDeclaration"
|
|
1547
|
+
);
|
|
1548
|
+
if (!targetExportDefault)
|
|
1549
|
+
return !1;
|
|
1550
|
+
let rejectFunctionNotation = (decl) => decl.type === "CallExpression" && decl.callee.type === "Identifier" && decl.callee.name === "defineConfig" && decl.arguments.length > 0 && decl.arguments[0].type === "ArrowFunctionExpression";
|
|
1551
|
+
if (targetExportDefault.declaration.type === "CallExpression" && rejectFunctionNotation(targetExportDefault.declaration))
|
|
1552
|
+
return !1;
|
|
1553
|
+
if (targetExportDefault.declaration.type === "Identifier") {
|
|
1554
|
+
let varName = targetExportDefault.declaration.name, declarator = target.program.body.find(
|
|
1555
|
+
(n) => n.type === "VariableDeclaration" && n.declarations.some((d) => d.id.type === "Identifier" && d.id.name === varName)
|
|
1556
|
+
)?.declarations.find(
|
|
1557
|
+
(d) => d.id.type === "Identifier" && d.id.name === varName
|
|
1558
|
+
);
|
|
1559
|
+
if (declarator?.init?.type === "CallExpression" && rejectFunctionNotation(declarator.init))
|
|
1560
|
+
return !1;
|
|
1561
|
+
}
|
|
1562
|
+
let canHandleConfig = !1;
|
|
1563
|
+
if ((getTargetConfigObject(target, targetExportDefault) !== null || targetExportDefault.declaration.type === "CallExpression" && targetExportDefault.declaration.callee.type === "Identifier" && targetExportDefault.declaration.callee.name === "mergeConfig" && targetExportDefault.declaration.arguments.length >= 2) && (canHandleConfig = !0), !canHandleConfig)
|
|
1564
|
+
return !1;
|
|
1565
|
+
for (let sourceNode of source.program.body)
|
|
1566
|
+
if (sourceNode.type === "ImportDeclaration") {
|
|
1567
|
+
if (!target.program.body.some(
|
|
1568
|
+
(targetNode) => targetNode.type === sourceNode.type && targetNode.specifiers.some((s) => s.local.name === sourceNode.specifiers[0].local.name)
|
|
1569
|
+
)) {
|
|
1570
|
+
let lastImport = target.program.body.findLastIndex((n) => n.type === "ImportDeclaration");
|
|
1571
|
+
target.program.body.splice(lastImport + 1, 0, sourceNode);
|
|
1572
|
+
}
|
|
1573
|
+
} else if (sourceNode.type === "VariableDeclaration") {
|
|
1574
|
+
if (!target.program.body.some(
|
|
1575
|
+
(targetNode) => targetNode.type === sourceNode.type && targetNode.declarations.some(
|
|
1576
|
+
(d) => "name" in d.id && "name" in sourceNode.declarations[0].id && d.id.name === sourceNode.declarations[0].id.name
|
|
1577
|
+
)
|
|
1578
|
+
)) {
|
|
1579
|
+
let lastImport = target.program.body.findLastIndex((n) => n.type === "ImportDeclaration");
|
|
1580
|
+
target.program.body.splice(lastImport + 1, 0, sourceNode);
|
|
1581
|
+
}
|
|
1582
|
+
} else if (sourceNode.type === "ExportDefaultDeclaration") {
|
|
1583
|
+
let exportDefault = target.program.body.find((n) => n.type === "ExportDefaultDeclaration");
|
|
1584
|
+
if (exportDefault && sourceNode.declaration.type === "CallExpression" && sourceNode.declaration.arguments.length > 0 && sourceNode.declaration.arguments[0].type === "ObjectExpression") {
|
|
1585
|
+
let { properties } = sourceNode.declaration.arguments[0], targetConfigObject = getTargetConfigObject(target, exportDefault);
|
|
1586
|
+
if (targetConfigObject !== null)
|
|
1587
|
+
mergeProperties(properties, targetConfigObject.properties), updated = !0;
|
|
1588
|
+
else if (exportDefault.declaration.type === "CallExpression" && exportDefault.declaration.callee.type === "Identifier" && exportDefault.declaration.callee.name === "mergeConfig" && exportDefault.declaration.arguments.length >= 2) {
|
|
1589
|
+
let configObjectNodes = [];
|
|
1590
|
+
for (let arg of exportDefault.declaration.arguments)
|
|
1591
|
+
arg?.type === "CallExpression" && arg.callee.type === "Identifier" && arg.callee.name === "defineConfig" && arg.arguments[0]?.type === "ObjectExpression" ? configObjectNodes.push(arg.arguments[0]) : arg?.type === "ObjectExpression" && configObjectNodes.push(arg);
|
|
1592
|
+
let targetConfigObject2 = configObjectNodes.find(
|
|
1593
|
+
(obj) => obj.properties.some(
|
|
1594
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "test"
|
|
1595
|
+
)
|
|
1596
|
+
) || configObjectNodes[0];
|
|
1597
|
+
if (!targetConfigObject2)
|
|
1598
|
+
return !1;
|
|
1599
|
+
let existingTestProp = targetConfigObject2.properties.find(
|
|
1600
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "test"
|
|
1601
|
+
);
|
|
1602
|
+
if (existingTestProp && existingTestProp.value.type === "ObjectExpression") {
|
|
1603
|
+
let templateTestProp = properties.find(
|
|
1604
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "test"
|
|
1605
|
+
), hasProjectsProp = (p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "projects" && p.value.type === "ArrayExpression", existingProjectsProp = existingTestProp.value.properties.find(hasProjectsProp);
|
|
1606
|
+
if (existingProjectsProp) {
|
|
1607
|
+
if (templateTestProp && templateTestProp.value.type === "ObjectExpression") {
|
|
1608
|
+
let templateProjectsProp = templateTestProp.value.properties.find(hasProjectsProp);
|
|
1609
|
+
if (templateProjectsProp && templateProjectsProp.value.type === "ArrayExpression") {
|
|
1610
|
+
let templateElements = templateProjectsProp.value.elements;
|
|
1611
|
+
existingProjectsProp.value.elements.push(
|
|
1612
|
+
...templateElements
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
for (let templateProp of templateTestProp.value.properties)
|
|
1616
|
+
templateProp.type === "ObjectProperty" && templateProp.key.type === "Identifier" && templateProp.key.name !== "projects" && !existingTestProp.value.properties.find(
|
|
1617
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === templateProp.key.name
|
|
1618
|
+
) && templateProp.type === "ObjectProperty" && existingTestProp.value.properties.push(templateProp);
|
|
1619
|
+
}
|
|
1620
|
+
let otherTemplateProps = properties.filter(
|
|
1621
|
+
(p) => !(p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "test")
|
|
1622
|
+
);
|
|
1623
|
+
otherTemplateProps.length > 0 && mergeProperties(otherTemplateProps, targetConfigObject2.properties);
|
|
1624
|
+
} else if (templateTestProp && templateTestProp.value.type === "ObjectExpression") {
|
|
1625
|
+
let workspaceOrProjectsProp = templateTestProp.value.properties.find(
|
|
1626
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && (p.key.name === "workspace" || p.key.name === "projects")
|
|
1627
|
+
);
|
|
1628
|
+
if (workspaceOrProjectsProp && workspaceOrProjectsProp.value.type === "ArrayExpression") {
|
|
1629
|
+
let coverageProp = existingTestProp.value.properties.find(
|
|
1630
|
+
(p) => p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "coverage"
|
|
1631
|
+
), testConfigForProject = {
|
|
1632
|
+
type: "ObjectExpression",
|
|
1633
|
+
properties: existingTestProp.value.properties.filter(
|
|
1634
|
+
(p) => p !== coverageProp
|
|
1635
|
+
)
|
|
1636
|
+
}, existingTestProject = {
|
|
1637
|
+
type: "ObjectExpression",
|
|
1638
|
+
properties: [
|
|
1639
|
+
{
|
|
1640
|
+
type: "ObjectProperty",
|
|
1641
|
+
key: { type: "Identifier", name: "extends" },
|
|
1642
|
+
value: { type: "BooleanLiteral", value: !0 },
|
|
1643
|
+
computed: !1,
|
|
1644
|
+
shorthand: !1
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
type: "ObjectProperty",
|
|
1648
|
+
key: { type: "Identifier", name: "test" },
|
|
1649
|
+
value: testConfigForProject,
|
|
1650
|
+
computed: !1,
|
|
1651
|
+
shorthand: !1
|
|
1652
|
+
}
|
|
1653
|
+
]
|
|
1654
|
+
};
|
|
1655
|
+
workspaceOrProjectsProp.value.elements.unshift(existingTestProject), targetConfigObject2.properties = targetConfigObject2.properties.filter(
|
|
1656
|
+
(p) => p !== existingTestProp
|
|
1657
|
+
), coverageProp && templateTestProp.value.type === "ObjectExpression" && templateTestProp.value.properties.unshift(coverageProp), mergeProperties(properties, targetConfigObject2.properties);
|
|
1658
|
+
} else
|
|
1659
|
+
mergeProperties(properties, targetConfigObject2.properties);
|
|
1660
|
+
} else
|
|
1661
|
+
mergeProperties(properties, targetConfigObject2.properties);
|
|
1662
|
+
} else
|
|
1663
|
+
mergeProperties(properties, targetConfigObject2.properties);
|
|
1664
|
+
updated = !0;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
return updated;
|
|
1669
|
+
}, updateWorkspaceFile = (source, target) => {
|
|
1670
|
+
let updated = !1;
|
|
1671
|
+
for (let sourceNode of source.program.body)
|
|
1672
|
+
if (sourceNode.type === "ImportDeclaration") {
|
|
1673
|
+
if (!target.program.body.some(
|
|
1674
|
+
(targetNode) => targetNode.type === sourceNode.type && targetNode.source.value === sourceNode.source.value && targetNode.specifiers.some((s) => s.local.name === sourceNode.specifiers[0].local.name)
|
|
1675
|
+
)) {
|
|
1676
|
+
let lastImport = target.program.body.findLastIndex((n) => n.type === "ImportDeclaration");
|
|
1677
|
+
target.program.body.splice(lastImport + 1, 0, sourceNode);
|
|
1678
|
+
}
|
|
1679
|
+
} else if (sourceNode.type === "VariableDeclaration") {
|
|
1680
|
+
if (!target.program.body.some(
|
|
1681
|
+
(targetNode) => targetNode.type === sourceNode.type && targetNode.declarations.some(
|
|
1682
|
+
(d) => "name" in d.id && "name" in sourceNode.declarations[0].id && d.id.name === sourceNode.declarations[0].id.name
|
|
1683
|
+
)
|
|
1684
|
+
)) {
|
|
1685
|
+
let lastImport = target.program.body.findLastIndex((n) => n.type === "ImportDeclaration");
|
|
1686
|
+
target.program.body.splice(lastImport + 1, 0, sourceNode);
|
|
1687
|
+
}
|
|
1688
|
+
} else if (sourceNode.type === "ExportDefaultDeclaration") {
|
|
1689
|
+
let exportDefault = target.program.body.find((n) => n.type === "ExportDefaultDeclaration");
|
|
1690
|
+
if (exportDefault && sourceNode.declaration.type === "CallExpression" && sourceNode.declaration.arguments.length > 0 && sourceNode.declaration.arguments[0].type === "ArrayExpression" && sourceNode.declaration.arguments[0].elements.length > 0) {
|
|
1691
|
+
let { elements } = sourceNode.declaration.arguments[0];
|
|
1692
|
+
exportDefault.declaration.type === "ArrayExpression" ? (exportDefault.declaration.elements.push(...elements), updated = !0) : exportDefault.declaration.type === "CallExpression" && exportDefault.declaration.callee.type === "Identifier" && exportDefault.declaration.callee.name === "defineWorkspace" && exportDefault.declaration.arguments[0]?.type === "ArrayExpression" && (exportDefault.declaration.arguments[0].elements.push(...elements), updated = !0);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
return updated;
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
// ../../addons/vitest/src/postinstall.ts
|
|
1699
|
+
var ADDON_NAME = "@storybook/addon-vitest", EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cts", ".mts", ".cjs", ".mjs"], STORYBOOK_TEST_PLUGIN_SOURCE = `${ADDON_NAME}/vitest-plugin`, addonA11yName = "@storybook/addon-a11y";
|
|
1700
|
+
async function postInstall(options) {
|
|
1701
|
+
let errors = [], { logger: logger17, prompt: prompt10 } = options, packageManager = JsPackageManagerFactory3.getPackageManager({
|
|
1702
|
+
force: options.packageManager
|
|
1703
|
+
}), findFile = (basename, extensions = EXTENSIONS) => any(
|
|
1704
|
+
extensions.map((ext) => basename + ext),
|
|
1705
|
+
{ last: getProjectRoot3(), cwd: options.configDir }
|
|
1706
|
+
), allDeps = packageManager.getAllDependencies(), vitestVersionSpecifier = await packageManager.getInstalledVersion("vitest");
|
|
1707
|
+
!vitestVersionSpecifier && allDeps.vitest && (vitestVersionSpecifier = allDeps.vitest), vitestVersionSpecifier = coerce(vitestVersionSpecifier)?.version ?? null, logger17.debug(`Vitest version specifier: ${vitestVersionSpecifier}`);
|
|
1708
|
+
let isVitest3_2To4 = vitestVersionSpecifier ? satisfies(vitestVersionSpecifier, ">=3.2.0 <4.0.0") : !1, isVitest4OrNewer = vitestVersionSpecifier ? satisfies(vitestVersionSpecifier, ">=4.0.0") : !0, info = await getStorybookInfo(options.configDir), addonVitestService = new AddonVitestService2(packageManager), compatibilityResult = await addonVitestService.validateCompatibility({
|
|
1709
|
+
framework: info.framework,
|
|
1710
|
+
builder: info.builder
|
|
1711
|
+
}), result = null;
|
|
1712
|
+
if (!compatibilityResult.compatible && compatibilityResult.reasons) {
|
|
1713
|
+
let reasons = compatibilityResult.reasons.map((r) => `\u2022 ${CLI_COLORS2.error(r)}`);
|
|
1714
|
+
reasons.unshift(import_ts_dedent8.dedent`
|
|
1715
|
+
Automated setup failed
|
|
1716
|
+
The following packages have incompatibilities that prevent automated setup:
|
|
1717
|
+
`), reasons.push(
|
|
1718
|
+
import_ts_dedent8.dedent`
|
|
1719
|
+
You can fix these issues and rerun the command to reinstall. If you wish to roll back the installation, remove ${ADDON_NAME} from the "addons" array
|
|
1720
|
+
in your main Storybook config file and remove the dependency from your package.json file.
|
|
1721
|
+
|
|
1722
|
+
Please check the documentation for more information about its requirements and installation:
|
|
1723
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK3}
|
|
1724
|
+
`
|
|
1725
|
+
), result = reasons.map((r) => r.trim()).join(`
|
|
1726
|
+
|
|
1727
|
+
`);
|
|
1728
|
+
}
|
|
1729
|
+
if (result)
|
|
1730
|
+
throw logger17.error(result), new AddonVitestPostinstallPrerequisiteCheckError({
|
|
1731
|
+
reasons: compatibilityResult.reasons
|
|
1732
|
+
});
|
|
1733
|
+
if (!options.skipDependencyManagement) {
|
|
1734
|
+
let versionedDependencies = await addonVitestService.collectDependencies();
|
|
1735
|
+
info.framework === SupportedFramework3.NEXTJS && packageManager.getAllDependencies()["@storybook/nextjs-vite"];
|
|
1736
|
+
let v8Version = await packageManager.getInstalledVersion("@vitest/coverage-v8"), istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1737
|
+
!v8Version && !istanbulVersion && logger17.step(
|
|
1738
|
+
import_ts_dedent8.dedent`
|
|
1739
|
+
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1740
|
+
|
|
1741
|
+
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1742
|
+
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1743
|
+
`
|
|
1744
|
+
), versionedDependencies.length > 0 && (logger17.step("Adding dependencies to your package.json"), logger17.log(" " + versionedDependencies.join(", ")), await packageManager.addDependencies(
|
|
1745
|
+
{ type: "devDependencies", skipInstall: !0 },
|
|
1746
|
+
versionedDependencies
|
|
1747
|
+
)), options.skipInstall || await packageManager.installDependencies();
|
|
1748
|
+
}
|
|
1749
|
+
options.skipDependencyManagement || (options.skipInstall ? logger17.warn(import_ts_dedent8.dedent`
|
|
1750
|
+
Playwright browser binaries installation skipped. Please run the following command manually later:
|
|
1751
|
+
${CLI_COLORS2.cta("npx playwright install chromium --with-deps")}
|
|
1752
|
+
`) : await addonVitestService.installPlaywright({
|
|
1753
|
+
yes: options.yes,
|
|
1754
|
+
useRemotePkg: !!options.skipInstall
|
|
1755
|
+
}));
|
|
1756
|
+
let fileExtension = allDeps.typescript || findFile("tsconfig", [...EXTENSIONS, ".json"]) ? "ts" : "js", vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`), existingSetupFile = EXTENSIONS.map((ext) => resolve(options.configDir, `vitest.setup${ext}`)).find(existsSync3) || null;
|
|
1757
|
+
if (existingSetupFile)
|
|
1758
|
+
logger17.step("Found existing Vitest setup file, reusing:"), logger17.log(`${existingSetupFile}
|
|
1759
|
+
`);
|
|
1760
|
+
else {
|
|
1761
|
+
logger17.step("Creating a Vitest setup file for Storybook:"), logger17.log(`${vitestSetupFile}
|
|
1762
|
+
`);
|
|
1763
|
+
let previewExists = EXTENSIONS.map((ext) => resolve(options.configDir, `preview${ext}`)).some(
|
|
1764
|
+
existsSync3
|
|
1765
|
+
), imports = [`import { setProjectAnnotations } from '${info.frameworkPackage}';`], projectAnnotations = [];
|
|
1766
|
+
previewExists && (imports.push("import * as projectAnnotations from './preview';"), projectAnnotations.push("projectAnnotations")), await writeFile2(
|
|
1767
|
+
vitestSetupFile,
|
|
1768
|
+
import_ts_dedent8.dedent`
|
|
1769
|
+
${imports.join(`
|
|
1770
|
+
`)}
|
|
1771
|
+
|
|
1772
|
+
// This is an important step to apply the right configuration when testing your stories.
|
|
1773
|
+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
|
|
1774
|
+
setProjectAnnotations([${projectAnnotations.join(", ")}]);
|
|
1775
|
+
`
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
let vitestWorkspaceFile = findFile("vitest.workspace", [".ts", ".js", ".json"]), viteConfigFile = findFile("vite.config"), vitestConfigFile = findFile("vitest.config"), vitestShimFile = findFile("vitest.shims.d"), rootConfig = vitestConfigFile || viteConfigFile;
|
|
1779
|
+
fileExtension === "ts" && !vitestShimFile && await writeFile2(
|
|
1780
|
+
"vitest.shims.d.ts",
|
|
1781
|
+
isVitest4OrNewer ? '/// <reference types="@vitest/browser-playwright" />' : '/// <reference types="@vitest/browser/providers/playwright" />'
|
|
1782
|
+
);
|
|
1783
|
+
let getTemplateName = () => isVitest4OrNewer ? "vitest.config.4.template" : isVitest3_2To4 ? "vitest.config.3.2.template" : "vitest.config.template";
|
|
1784
|
+
if (vitestWorkspaceFile) {
|
|
1785
|
+
let workspaceFileContent = await fs.readFile(vitestWorkspaceFile, "utf8");
|
|
1786
|
+
if (isConfigAlreadySetup(vitestWorkspaceFile, workspaceFileContent)) {
|
|
1787
|
+
logger17.step(
|
|
1788
|
+
CLI_COLORS2.success("Vitest for Storybook is already properly configured. Skipping setup.")
|
|
1789
|
+
);
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
let workspaceTemplate = await loadTemplate("vitest.workspace.template", {
|
|
1793
|
+
EXTENDS_WORKSPACE: viteConfigFile ? relative(dirname(vitestWorkspaceFile), viteConfigFile) : "",
|
|
1794
|
+
CONFIG_DIR: options.configDir,
|
|
1795
|
+
SETUP_FILE: relative(dirname(vitestWorkspaceFile), existingSetupFile ?? vitestSetupFile)
|
|
1796
|
+
}).then((t) => t.replace(`
|
|
1797
|
+
'ROOT_CONFIG',`, "").replace(/\s+extends: '',/, "")), source = babelParse(workspaceTemplate), target = babelParse(workspaceFileContent);
|
|
1798
|
+
if (updateWorkspaceFile(source, target)) {
|
|
1799
|
+
logger17.step("Updating your Vitest workspace file..."), logger17.log(`${vitestWorkspaceFile}`);
|
|
1800
|
+
let formattedContent = await formatFileContent(vitestWorkspaceFile, generate(target).code);
|
|
1801
|
+
await writeFile2(vitestWorkspaceFile, formattedContent);
|
|
1802
|
+
} else
|
|
1803
|
+
logger17.error(
|
|
1804
|
+
import_ts_dedent8.dedent`
|
|
1805
|
+
Could not update existing Vitest workspace file:
|
|
1806
|
+
${vitestWorkspaceFile}
|
|
1807
|
+
|
|
1808
|
+
I was able to configure most of the addon but could not safely extend
|
|
1809
|
+
your existing workspace file automatically, you must do it yourself.
|
|
1810
|
+
|
|
1811
|
+
Please refer to the documentation to complete the setup manually:
|
|
1812
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK3}#manual-setup-advanced
|
|
1813
|
+
`
|
|
1814
|
+
), errors.push(
|
|
1815
|
+
new AddonVitestPostinstallWorkspaceUpdateError({ filePath: vitestWorkspaceFile })
|
|
1816
|
+
);
|
|
1817
|
+
} else if (rootConfig) {
|
|
1818
|
+
let target, updated, configFile = await fs.readFile(rootConfig, "utf8"), configFileHasTypeReference = configFile.match(
|
|
1819
|
+
/\/\/\/\s*<reference\s+types=["']vitest\/config["']\s*\/>/
|
|
1820
|
+
), templateName = getTemplateName(), alreadyConfigured = isConfigAlreadySetup(rootConfig, configFile);
|
|
1821
|
+
if (templateName && !alreadyConfigured) {
|
|
1822
|
+
let configTemplate = await loadTemplate(templateName, {
|
|
1823
|
+
CONFIG_DIR: options.configDir,
|
|
1824
|
+
SETUP_FILE: relative(dirname(rootConfig), existingSetupFile ?? vitestSetupFile)
|
|
1825
|
+
}), source = babelParse(configTemplate);
|
|
1826
|
+
target = babelParse(configFile), updated = updateConfigFile(source, target);
|
|
1827
|
+
}
|
|
1828
|
+
if (alreadyConfigured)
|
|
1829
|
+
logger17.step(
|
|
1830
|
+
CLI_COLORS2.success("Vitest for Storybook is already properly configured. Skipping setup.")
|
|
1831
|
+
);
|
|
1832
|
+
else if (target && updated) {
|
|
1833
|
+
logger17.step(`Updating your ${vitestConfigFile ? "Vitest" : "Vite"} config file:`), logger17.log(` ${rootConfig}`);
|
|
1834
|
+
let formattedContent = await formatFileContent(rootConfig, generate(target).code);
|
|
1835
|
+
await writeFile2(
|
|
1836
|
+
rootConfig,
|
|
1837
|
+
!configFileHasTypeReference && !vitestConfigFile ? `/// <reference types="vitest/config" />
|
|
1838
|
+
` + formattedContent : formattedContent
|
|
1839
|
+
);
|
|
1840
|
+
} else
|
|
1841
|
+
logger17.error(import_ts_dedent8.dedent`
|
|
1842
|
+
We were unable to update your existing ${vitestConfigFile ? "Vitest" : "Vite"} config file.
|
|
1843
|
+
|
|
1844
|
+
Please refer to the documentation to complete the setup manually:
|
|
1845
|
+
https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#manual-setup-advanced
|
|
1846
|
+
`), errors.push(new AddonVitestPostinstallConfigUpdateError({ filePath: rootConfig }));
|
|
1847
|
+
} else {
|
|
1848
|
+
let parentDir = dirname(options.configDir), newConfigFile = resolve(parentDir, `vitest.config.${fileExtension}`), configTemplate = await loadTemplate(getTemplateName(), {
|
|
1849
|
+
CONFIG_DIR: options.configDir,
|
|
1850
|
+
SETUP_FILE: relative(dirname(newConfigFile), vitestSetupFile)
|
|
1851
|
+
});
|
|
1852
|
+
logger17.step("Creating a Vitest config file:"), logger17.log(`${newConfigFile}`);
|
|
1853
|
+
let formattedContent = await formatFileContent(newConfigFile, configTemplate);
|
|
1854
|
+
await writeFile2(newConfigFile, formattedContent);
|
|
1855
|
+
}
|
|
1856
|
+
if (info.addons.find((addon) => addon.includes(addonA11yName)))
|
|
1857
|
+
try {
|
|
1858
|
+
let command = [
|
|
1859
|
+
options.skipInstall ? `storybook@${versions3.storybook}` : "storybook",
|
|
1860
|
+
"automigrate",
|
|
1861
|
+
"addon-a11y-addon-test",
|
|
1862
|
+
"--loglevel",
|
|
1863
|
+
"silent",
|
|
1864
|
+
"--yes",
|
|
1865
|
+
"--skip-doctor"
|
|
1866
|
+
];
|
|
1867
|
+
options.packageManager && command.push("--package-manager", options.packageManager), options.skipInstall && command.push("--skip-install"), options.configDir !== ".storybook" && command.push("--config-dir", options.configDir), await prompt10.executeTask(
|
|
1868
|
+
// TODO: Remove stdio: 'ignore' once we have a way to log the output of the command properly
|
|
1869
|
+
() => packageManager.runPackageCommand({
|
|
1870
|
+
args: command,
|
|
1871
|
+
stdio: "ignore",
|
|
1872
|
+
useRemotePkg: !!options.skipInstall
|
|
1873
|
+
}),
|
|
1874
|
+
{
|
|
1875
|
+
intro: "Setting up a11y addon for @storybook/addon-vitest",
|
|
1876
|
+
error: "Failed to setup a11y addon for @storybook/addon-vitest",
|
|
1877
|
+
success: "a11y addon setup successfully"
|
|
1878
|
+
}
|
|
1879
|
+
);
|
|
1880
|
+
} catch (e) {
|
|
1881
|
+
logger17.error(import_ts_dedent8.dedent`
|
|
1882
|
+
Could not automatically set up ${addonA11yName} for @storybook/addon-vitest.
|
|
1883
|
+
Please refer to the documentation to complete the setup manually:
|
|
1884
|
+
https://storybook.js.org/docs/writing-tests/accessibility-testing#integration-with-vitest-addon
|
|
1885
|
+
`), errors.push(new AddonVitestPostinstallFailedAddonA11yError({ error: e }));
|
|
1886
|
+
}
|
|
1887
|
+
let runCommand = rootConfig ? "npx vitest --project=storybook" : "npx vitest";
|
|
1888
|
+
if (errors.length === 0)
|
|
1889
|
+
logger17.step(CLI_COLORS2.success("@storybook/addon-vitest setup completed successfully")), logger17.log(import_ts_dedent8.dedent`
|
|
1890
|
+
@storybook/addon-vitest is now configured and you're ready to run your tests!
|
|
1891
|
+
Here are a couple of tips to get you started:
|
|
1892
|
+
|
|
1893
|
+
• You can run tests with "${CLI_COLORS2.cta(runCommand)}"
|
|
1894
|
+
• Vitest IDE extension shows all stories as tests in your editor!
|
|
1895
|
+
|
|
1896
|
+
Check the documentation for more information about its features and options at:
|
|
1897
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK3}
|
|
1898
|
+
`);
|
|
1899
|
+
else
|
|
1900
|
+
throw logger17.warn(
|
|
1901
|
+
import_ts_dedent8.dedent`
|
|
1902
|
+
Done, but with errors!
|
|
1903
|
+
@storybook/addon-vitest was installed successfully, but there were some errors during the setup process. Please refer to the documentation to complete the setup manually and check the errors above:
|
|
1904
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK3}#manual-setup-advanced
|
|
1905
|
+
`
|
|
1906
|
+
), new AddonVitestPostinstallError({ errors });
|
|
1907
|
+
}
|
|
1908
|
+
function isStorybookTestPluginSource(value) {
|
|
1909
|
+
return value === STORYBOOK_TEST_PLUGIN_SOURCE;
|
|
1910
|
+
}
|
|
1911
|
+
function isConfigAlreadySetup(_configPath, configContent) {
|
|
1912
|
+
let ast;
|
|
1913
|
+
try {
|
|
1914
|
+
ast = babelParse(configContent);
|
|
1915
|
+
} catch {
|
|
1916
|
+
return !1;
|
|
1917
|
+
}
|
|
1918
|
+
let pluginIdentifiers = /* @__PURE__ */ new Set();
|
|
1919
|
+
traverse(ast, {
|
|
1920
|
+
ImportDeclaration(path) {
|
|
1921
|
+
let source = path.node.source.value;
|
|
1922
|
+
typeof source == "string" && isStorybookTestPluginSource(source) && path.node.specifiers.forEach((specifier) => {
|
|
1923
|
+
"local" in specifier && specifier.local?.name && pluginIdentifiers.add(specifier.local.name);
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
let pluginReferenced = !1;
|
|
1928
|
+
return traverse(ast, {
|
|
1929
|
+
CallExpression(path) {
|
|
1930
|
+
if (pluginReferenced) {
|
|
1931
|
+
path.stop();
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
let callee = path.node.callee;
|
|
1935
|
+
callee.type === "Identifier" && (pluginIdentifiers.has(callee.name) || callee.name === "storybookTest") && (pluginReferenced = !0, path.stop());
|
|
1936
|
+
}
|
|
1937
|
+
}), pluginReferenced;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// src/commands/AddonConfigurationCommand.ts
|
|
1395
1941
|
var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
1396
1942
|
"@storybook/addon-vitest": "https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#manual-setup-advanced"
|
|
1397
1943
|
}, AddonConfigurationCommand = class {
|
|
1398
|
-
constructor(packageManager, commandOptions, addonVitestService = new
|
|
1944
|
+
constructor(packageManager, commandOptions, addonVitestService = new AddonVitestService3(packageManager), telemetryService = new TelemetryService(commandOptions.disableTelemetry)) {
|
|
1399
1945
|
this.packageManager = packageManager;
|
|
1400
1946
|
this.commandOptions = commandOptions;
|
|
1401
1947
|
this.addonVitestService = addonVitestService;
|
|
@@ -1404,22 +1950,22 @@ var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
|
1404
1950
|
/** Execute addon configuration */
|
|
1405
1951
|
async execute({
|
|
1406
1952
|
addons,
|
|
1407
|
-
configDir
|
|
1408
|
-
dependencyInstallationResult
|
|
1953
|
+
configDir
|
|
1409
1954
|
}) {
|
|
1410
|
-
if (!(dependencyInstallationResult.status === "success" && !this.commandOptions.skipInstall) && this.getAddonsWithInstructions(addons).length > 0)
|
|
1411
|
-
return this.logManualAddonInstructions(addons), { status: "failed" };
|
|
1412
1955
|
if (!configDir || addons.length === 0)
|
|
1413
1956
|
return { status: "success" };
|
|
1414
1957
|
try {
|
|
1415
1958
|
let { hasFailures, addonResults } = await this.configureAddons(configDir, addons);
|
|
1416
1959
|
if (addonResults.has("@storybook/addon-vitest")) {
|
|
1417
1960
|
let { result } = await this.addonVitestService.installPlaywright({
|
|
1418
|
-
yes: this.commandOptions.yes
|
|
1961
|
+
yes: this.commandOptions.yes,
|
|
1962
|
+
useRemotePkg: !!this.commandOptions.skipInstall
|
|
1419
1963
|
});
|
|
1420
1964
|
await this.telemetryService.trackPlaywrightPromptDecision(result);
|
|
1421
1965
|
}
|
|
1422
|
-
return
|
|
1966
|
+
return hasFailures && this.logManualAddonInstructions(
|
|
1967
|
+
addons.filter((addon) => addonResults.get(addon)?.result === "failed")
|
|
1968
|
+
), { status: hasFailures ? "failed" : "success" };
|
|
1423
1969
|
} catch (e) {
|
|
1424
1970
|
return logger9.error("Unexpected error during addon configuration:"), logger9.error(e), { status: "failed" };
|
|
1425
1971
|
}
|
|
@@ -1429,7 +1975,7 @@ var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
|
1429
1975
|
}
|
|
1430
1976
|
logManualAddonInstructions(addons) {
|
|
1431
1977
|
let addonsWithInstructions = this.getAddonsWithInstructions(addons);
|
|
1432
|
-
addonsWithInstructions.length > 0 && logger9.warn(
|
|
1978
|
+
addonsWithInstructions.length > 0 && logger9.warn(import_ts_dedent9.dedent`
|
|
1433
1979
|
The following addons couldn't be configured:
|
|
1434
1980
|
|
|
1435
1981
|
${addonsWithInstructions.map((addon) => {
|
|
@@ -1443,13 +1989,14 @@ var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
|
1443
1989
|
}
|
|
1444
1990
|
/** Configure test addons (a11y and vitest) */
|
|
1445
1991
|
async configureAddons(configDir, addons) {
|
|
1446
|
-
let { postinstallAddon } = await import("./postinstallAddon-
|
|
1992
|
+
let { postinstallAddon } = await import("./postinstallAddon-SN6SHJQO.js"), task = prompt6.taskLog({
|
|
1447
1993
|
id: "configure-addons",
|
|
1448
1994
|
title: "Configuring addons..."
|
|
1449
1995
|
}), addonResults = /* @__PURE__ */ new Map();
|
|
1450
1996
|
for (let addon of addons)
|
|
1451
1997
|
try {
|
|
1452
|
-
task.message(`Configuring ${addon}...`)
|
|
1998
|
+
task.message(`Configuring ${addon}...`);
|
|
1999
|
+
let options = {
|
|
1453
2000
|
packageManager: this.packageManager.type,
|
|
1454
2001
|
configDir,
|
|
1455
2002
|
yes: this.commandOptions.yes,
|
|
@@ -1457,15 +2004,16 @@ var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
|
1457
2004
|
skipDependencyManagement: !0,
|
|
1458
2005
|
logger: logger9,
|
|
1459
2006
|
prompt: prompt6
|
|
1460
|
-
}
|
|
2007
|
+
};
|
|
2008
|
+
addon === "@storybook/addon-vitest" ? await postInstall(options) : addon === "@storybook/addon-a11y" ? await postinstall(options) : await postinstallAddon(addon, options), task.message(`${addon} configured
|
|
1461
2009
|
`), addonResults.set(addon, null);
|
|
1462
2010
|
} catch (e) {
|
|
1463
|
-
ErrorCollector.addError(e), addonResults.set(addon, e);
|
|
2011
|
+
logger9.debug(e), ErrorCollector.addError(e), addonResults.set(addon, e);
|
|
1464
2012
|
}
|
|
1465
2013
|
let hasFailures = [...addonResults.values()].some((result) => result !== null);
|
|
1466
2014
|
return hasFailures ? task.error("Failed to configure addons") : task.success("Addons configured successfully"), addons.forEach((addon, index) => {
|
|
1467
2015
|
let error = addonResults.get(addon);
|
|
1468
|
-
logger9.log(
|
|
2016
|
+
logger9.log(CLI_COLORS3.muted(error ? `\u274C ${addon}` : `\u2705 ${addon}`), {
|
|
1469
2017
|
spacing: index === 0 ? 1 : 0
|
|
1470
2018
|
});
|
|
1471
2019
|
}), { hasFailures, addonResults };
|
|
@@ -1477,12 +2025,12 @@ var ADDON_INSTALLATION_INSTRUCTIONS = {
|
|
|
1477
2025
|
}) => new AddonConfigurationCommand(packageManager, options).execute(rest);
|
|
1478
2026
|
|
|
1479
2027
|
// src/commands/DependencyInstallationCommand.ts
|
|
1480
|
-
import { AddonVitestService as
|
|
2028
|
+
import { AddonVitestService as AddonVitestService4 } from "storybook/internal/cli";
|
|
1481
2029
|
import { logger as logger10, prompt as prompt7 } from "storybook/internal/node-logger";
|
|
1482
2030
|
import { ErrorCollector as ErrorCollector2 } from "storybook/internal/telemetry";
|
|
1483
2031
|
import { Feature as Feature5 } from "storybook/internal/types";
|
|
1484
2032
|
var DependencyInstallationCommand = class {
|
|
1485
|
-
constructor(dependencyCollector, packageManager, addonVitestService = new
|
|
2033
|
+
constructor(dependencyCollector, packageManager, addonVitestService = new AddonVitestService4(packageManager)) {
|
|
1486
2034
|
this.dependencyCollector = dependencyCollector;
|
|
1487
2035
|
this.packageManager = packageManager;
|
|
1488
2036
|
this.addonVitestService = addonVitestService;
|
|
@@ -1536,11 +2084,11 @@ var DependencyInstallationCommand = class {
|
|
|
1536
2084
|
}) => new DependencyInstallationCommand(dependencyCollector, packageManager).execute(props);
|
|
1537
2085
|
|
|
1538
2086
|
// src/commands/FinalizationCommand.ts
|
|
1539
|
-
import
|
|
1540
|
-
import { getProjectRoot as
|
|
1541
|
-
import { CLI_COLORS as
|
|
2087
|
+
import fs2 from "node:fs/promises";
|
|
2088
|
+
import { getProjectRoot as getProjectRoot4 } from "storybook/internal/common";
|
|
2089
|
+
import { CLI_COLORS as CLI_COLORS4, logTracker, logger as logger11 } from "storybook/internal/node-logger";
|
|
1542
2090
|
import { ErrorCollector as ErrorCollector3 } from "storybook/internal/telemetry";
|
|
1543
|
-
var
|
|
2091
|
+
var import_ts_dedent10 = __toESM(require_dist(), 1), FinalizationCommand = class {
|
|
1544
2092
|
constructor(logfile) {
|
|
1545
2093
|
this.logfile = logfile;
|
|
1546
2094
|
}
|
|
@@ -1550,15 +2098,15 @@ var import_ts_dedent9 = __toESM(require_dist(), 1), FinalizationCommand = class
|
|
|
1550
2098
|
}
|
|
1551
2099
|
/** Update .gitignore with Storybook-specific entries */
|
|
1552
2100
|
async updateGitignore() {
|
|
1553
|
-
let foundGitIgnoreFile = up2(".gitignore"), rootDirectory =
|
|
2101
|
+
let foundGitIgnoreFile = up2(".gitignore"), rootDirectory = getProjectRoot4();
|
|
1554
2102
|
if (!foundGitIgnoreFile || !foundGitIgnoreFile.includes(rootDirectory))
|
|
1555
2103
|
return;
|
|
1556
|
-
let contents = await
|
|
2104
|
+
let contents = await fs2.readFile(foundGitIgnoreFile, "utf-8"), hasStorybookLog = contents.includes("*storybook.log"), hasStorybookStatic = contents.includes("storybook-static"), linesToAdd = [
|
|
1557
2105
|
hasStorybookLog ? "" : "*storybook.log",
|
|
1558
2106
|
hasStorybookStatic ? "" : "storybook-static"
|
|
1559
2107
|
].filter(Boolean).join(`
|
|
1560
2108
|
`);
|
|
1561
|
-
linesToAdd && await
|
|
2109
|
+
linesToAdd && await fs2.appendFile(foundGitIgnoreFile, `
|
|
1562
2110
|
${linesToAdd}
|
|
1563
2111
|
`);
|
|
1564
2112
|
}
|
|
@@ -1574,14 +2122,14 @@ ${linesToAdd}
|
|
|
1574
2122
|
}
|
|
1575
2123
|
/** Print success message with feature summary */
|
|
1576
2124
|
printSuccessMessage(storybookCommand) {
|
|
1577
|
-
logger11.step(
|
|
2125
|
+
logger11.step(CLI_COLORS4.success("Storybook was successfully installed in your project!")), this.printNextSteps(storybookCommand);
|
|
1578
2126
|
}
|
|
1579
2127
|
printNextSteps(storybookCommand) {
|
|
1580
2128
|
storybookCommand && logger11.log(
|
|
1581
|
-
`To run Storybook manually, run ${
|
|
1582
|
-
), logger11.log(
|
|
1583
|
-
Wanna know more about Storybook? Check out ${
|
|
1584
|
-
Having trouble or want to chat? Join us at ${
|
|
2129
|
+
`To run Storybook manually, run ${CLI_COLORS4.cta(storybookCommand)}. CTRL+C to stop.`
|
|
2130
|
+
), logger11.log(import_ts_dedent10.dedent`
|
|
2131
|
+
Wanna know more about Storybook? Check out ${CLI_COLORS4.cta("https://storybook.js.org/")}
|
|
2132
|
+
Having trouble or want to chat? Join us at ${CLI_COLORS4.cta("https://discord.gg/storybook/")}
|
|
1585
2133
|
`);
|
|
1586
2134
|
}
|
|
1587
2135
|
}, executeFinalization = ({
|
|
@@ -1622,13 +2170,13 @@ var DependencyCollector = class {
|
|
|
1622
2170
|
for (let [type, typeMap] of this.packages.entries()) {
|
|
1623
2171
|
let packageNames = /* @__PURE__ */ new Map();
|
|
1624
2172
|
typeMap.forEach((version, name) => {
|
|
1625
|
-
let
|
|
1626
|
-
|
|
1627
|
-
}), packageNames.forEach((
|
|
1628
|
-
|
|
2173
|
+
let versions4 = packageNames.get(name) || [];
|
|
2174
|
+
versions4.push(version), packageNames.set(name, versions4);
|
|
2175
|
+
}), packageNames.forEach((versions4, name) => {
|
|
2176
|
+
versions4.length > 1 && new Set(versions4).size > 1 && conflicts.push({
|
|
1629
2177
|
packageName: name,
|
|
1630
|
-
existingVersion:
|
|
1631
|
-
newVersion:
|
|
2178
|
+
existingVersion: versions4[0],
|
|
2179
|
+
newVersion: versions4[versions4.length - 1],
|
|
1632
2180
|
type
|
|
1633
2181
|
});
|
|
1634
2182
|
});
|
|
@@ -1706,18 +2254,18 @@ var DependencyCollector = class {
|
|
|
1706
2254
|
};
|
|
1707
2255
|
|
|
1708
2256
|
// src/generators/ANGULAR/index.ts
|
|
1709
|
-
var
|
|
1710
|
-
import { dirname as
|
|
2257
|
+
var import_ts_dedent11 = __toESM(require_dist(), 1);
|
|
2258
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
1711
2259
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1712
2260
|
import { AngularJSON, ProjectType as ProjectType4, copyTemplate } from "storybook/internal/cli";
|
|
1713
2261
|
import { logger as logger12, prompt as prompt8 } from "storybook/internal/node-logger";
|
|
1714
|
-
import { SupportedBuilder as SupportedBuilder2, SupportedFramework as
|
|
2262
|
+
import { SupportedBuilder as SupportedBuilder2, SupportedFramework as SupportedFramework4, SupportedRenderer } from "storybook/internal/types";
|
|
1715
2263
|
import semver2 from "semver";
|
|
1716
2264
|
var ANGULAR_default = {
|
|
1717
2265
|
metadata: {
|
|
1718
2266
|
projectType: ProjectType4.ANGULAR,
|
|
1719
2267
|
renderer: SupportedRenderer.ANGULAR,
|
|
1720
|
-
framework:
|
|
2268
|
+
framework: SupportedFramework4.ANGULAR,
|
|
1721
2269
|
builderOverride: SupportedBuilder2.WEBPACK5
|
|
1722
2270
|
},
|
|
1723
2271
|
configure: async (packageManager, context) => {
|
|
@@ -1752,7 +2300,7 @@ var ANGULAR_default = {
|
|
|
1752
2300
|
let projectTypeValue = projectType || "application";
|
|
1753
2301
|
projectTypeValue !== "application" && projectTypeValue !== "library" && (projectTypeValue = "application");
|
|
1754
2302
|
let templateDir = join4(
|
|
1755
|
-
|
|
2303
|
+
dirname4(fileURLToPath2(import.meta.resolve("create-storybook/package.json"))),
|
|
1756
2304
|
"templates",
|
|
1757
2305
|
"angular",
|
|
1758
2306
|
projectTypeValue
|
|
@@ -1784,7 +2332,7 @@ var ANGULAR_default = {
|
|
|
1784
2332
|
storybookCommand: `ng run ${angularProjectName}:storybook`,
|
|
1785
2333
|
...useCompodoc && {
|
|
1786
2334
|
frameworkPreviewParts: {
|
|
1787
|
-
prefix:
|
|
2335
|
+
prefix: import_ts_dedent11.dedent`
|
|
1788
2336
|
import { setCompodocJson } from "@storybook/addon-docs/angular";
|
|
1789
2337
|
import docJson from "../documentation.json";
|
|
1790
2338
|
setCompodocJson(docJson);
|
|
@@ -1805,12 +2353,12 @@ function promptForCompoDocs() {
|
|
|
1805
2353
|
|
|
1806
2354
|
// src/generators/EMBER/index.ts
|
|
1807
2355
|
import { ProjectType as ProjectType5 } from "storybook/internal/cli";
|
|
1808
|
-
import { SupportedBuilder as SupportedBuilder3, SupportedFramework as
|
|
2356
|
+
import { SupportedBuilder as SupportedBuilder3, SupportedFramework as SupportedFramework5, SupportedRenderer as SupportedRenderer2 } from "storybook/internal/types";
|
|
1809
2357
|
var EMBER_default = {
|
|
1810
2358
|
metadata: {
|
|
1811
2359
|
projectType: ProjectType5.EMBER,
|
|
1812
2360
|
renderer: SupportedRenderer2.EMBER,
|
|
1813
|
-
framework:
|
|
2361
|
+
framework: SupportedFramework5.EMBER,
|
|
1814
2362
|
builderOverride: SupportedBuilder3.WEBPACK5
|
|
1815
2363
|
},
|
|
1816
2364
|
configure: async () => ({
|
|
@@ -1832,14 +2380,14 @@ var HTML_default = {
|
|
|
1832
2380
|
};
|
|
1833
2381
|
|
|
1834
2382
|
// src/generators/NEXTJS/index.ts
|
|
1835
|
-
var
|
|
1836
|
-
import { existsSync as
|
|
1837
|
-
import { readFile } from "node:fs/promises";
|
|
2383
|
+
var import_ts_dedent12 = __toESM(require_dist(), 1);
|
|
2384
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
2385
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
1838
2386
|
import { join as join5 } from "node:path";
|
|
1839
2387
|
import { ProjectType as ProjectType7 } from "storybook/internal/cli";
|
|
1840
2388
|
import { findFilesUp } from "storybook/internal/common";
|
|
1841
2389
|
import { logger as logger13, prompt as prompt9 } from "storybook/internal/node-logger";
|
|
1842
|
-
import { SupportedBuilder as SupportedBuilder5, SupportedFramework as
|
|
2390
|
+
import { SupportedBuilder as SupportedBuilder5, SupportedFramework as SupportedFramework6, SupportedRenderer as SupportedRenderer4 } from "storybook/internal/types";
|
|
1843
2391
|
var NEXT_CONFIG_FILES = [
|
|
1844
2392
|
"next.config.mjs",
|
|
1845
2393
|
"next.config.js",
|
|
@@ -1859,17 +2407,17 @@ var NEXT_CONFIG_FILES = [
|
|
|
1859
2407
|
metadata: {
|
|
1860
2408
|
projectType: ProjectType7.NEXTJS,
|
|
1861
2409
|
renderer: SupportedRenderer4.REACT,
|
|
1862
|
-
framework: (builder) => builder === SupportedBuilder5.VITE ?
|
|
2410
|
+
framework: (builder) => builder === SupportedBuilder5.VITE ? SupportedFramework6.NEXTJS_VITE : SupportedFramework6.NEXTJS,
|
|
1863
2411
|
builderOverride: async () => {
|
|
1864
2412
|
let nextConfigFile = findFilesUp(NEXT_CONFIG_FILES, process.cwd())[0];
|
|
1865
2413
|
if (!nextConfigFile)
|
|
1866
2414
|
return SupportedBuilder5.VITE;
|
|
1867
|
-
let hasCustomWebpackConfig = (await
|
|
2415
|
+
let hasCustomWebpackConfig = (await readFile2(nextConfigFile, "utf-8")).includes("webpack"), babelConfigFile = findFilesUp(BABEL_CONFIG_FILES, process.cwd())[0];
|
|
1868
2416
|
if (!hasCustomWebpackConfig && !babelConfigFile)
|
|
1869
2417
|
return SupportedBuilder5.VITE;
|
|
1870
2418
|
{
|
|
1871
2419
|
let reason = hasCustomWebpackConfig && babelConfigFile ? "custom webpack config and babel config" : hasCustomWebpackConfig ? "custom webpack config" : "custom babel config";
|
|
1872
|
-
return logger13.info(
|
|
2420
|
+
return logger13.info(import_ts_dedent12.dedent`
|
|
1873
2421
|
Storybook has two Next.js builder options: Webpack 5 and Vite.
|
|
1874
2422
|
|
|
1875
2423
|
We generally recommend nextjs-vite, which is much faster, more modern, and supports our latest testing features.
|
|
@@ -1887,7 +2435,7 @@ var NEXT_CONFIG_FILES = [
|
|
|
1887
2435
|
},
|
|
1888
2436
|
configure: async (packageManager, context) => {
|
|
1889
2437
|
let staticDir;
|
|
1890
|
-
|
|
2438
|
+
existsSync4(join5(process.cwd(), "public")) && (staticDir = "public");
|
|
1891
2439
|
let extraPackages = [];
|
|
1892
2440
|
return context.builder === SupportedBuilder5.VITE && extraPackages.push("vite"), {
|
|
1893
2441
|
staticDir,
|
|
@@ -1902,14 +2450,14 @@ import { logger as logger14 } from "storybook/internal/node-logger";
|
|
|
1902
2450
|
import {
|
|
1903
2451
|
Feature as Feature6,
|
|
1904
2452
|
SupportedBuilder as SupportedBuilder6,
|
|
1905
|
-
SupportedFramework as
|
|
2453
|
+
SupportedFramework as SupportedFramework7,
|
|
1906
2454
|
SupportedRenderer as SupportedRenderer5
|
|
1907
2455
|
} from "storybook/internal/types";
|
|
1908
2456
|
var NUXT_default = {
|
|
1909
2457
|
metadata: {
|
|
1910
2458
|
projectType: ProjectType8.NUXT,
|
|
1911
2459
|
renderer: SupportedRenderer5.VUE3,
|
|
1912
|
-
framework:
|
|
2460
|
+
framework: SupportedFramework7.NUXT,
|
|
1913
2461
|
builderOverride: SupportedBuilder6.VITE
|
|
1914
2462
|
},
|
|
1915
2463
|
configure: async (packageManager, context) => {
|
|
@@ -1944,12 +2492,12 @@ var PREACT_default = {
|
|
|
1944
2492
|
|
|
1945
2493
|
// src/generators/QWIK/index.ts
|
|
1946
2494
|
import { ProjectType as ProjectType10 } from "storybook/internal/cli";
|
|
1947
|
-
import { SupportedFramework as
|
|
2495
|
+
import { SupportedFramework as SupportedFramework8, SupportedRenderer as SupportedRenderer7 } from "storybook/internal/types";
|
|
1948
2496
|
var QWIK_default = {
|
|
1949
2497
|
metadata: {
|
|
1950
2498
|
projectType: ProjectType10.QWIK,
|
|
1951
2499
|
renderer: SupportedRenderer7.QWIK,
|
|
1952
|
-
framework:
|
|
2500
|
+
framework: SupportedFramework8.QWIK
|
|
1953
2501
|
},
|
|
1954
2502
|
configure: async () => ({})
|
|
1955
2503
|
};
|
|
@@ -1969,9 +2517,9 @@ var REACT_default = {
|
|
|
1969
2517
|
};
|
|
1970
2518
|
|
|
1971
2519
|
// src/generators/REACT_NATIVE/index.ts
|
|
1972
|
-
var
|
|
2520
|
+
var import_ts_dedent13 = __toESM(require_dist(), 1);
|
|
1973
2521
|
import { ProjectType as ProjectType12, copyTemplateFiles as copyTemplateFiles2, getBabelDependencies } from "storybook/internal/cli";
|
|
1974
|
-
import { CLI_COLORS as
|
|
2522
|
+
import { CLI_COLORS as CLI_COLORS5, logger as logger15 } from "storybook/internal/node-logger";
|
|
1975
2523
|
import { SupportedBuilder as SupportedBuilder9, SupportedLanguage as SupportedLanguage5, SupportedRenderer as SupportedRenderer9 } from "storybook/internal/types";
|
|
1976
2524
|
var REACT_NATIVE_default = {
|
|
1977
2525
|
metadata: {
|
|
@@ -2021,33 +2569,33 @@ var REACT_NATIVE_default = {
|
|
|
2021
2569
|
};
|
|
2022
2570
|
},
|
|
2023
2571
|
postConfigure: ({ packageManager }) => {
|
|
2024
|
-
logger15.log(
|
|
2025
|
-
${
|
|
2572
|
+
logger15.log(import_ts_dedent13.dedent`
|
|
2573
|
+
${CLI_COLORS5.warning("The Storybook for React Native installation is not 100% automated.")}
|
|
2026
2574
|
|
|
2027
2575
|
To run Storybook for React Native, you will need to:
|
|
2028
2576
|
|
|
2029
2577
|
1. Replace the contents of your app entry with the following
|
|
2030
2578
|
|
|
2031
|
-
${
|
|
2579
|
+
${CLI_COLORS5.info(" export {default} from './.rnstorybook'; ")}
|
|
2032
2580
|
|
|
2033
2581
|
2. Wrap your metro config with the withStorybook enhancer function like this:
|
|
2034
2582
|
|
|
2035
|
-
${
|
|
2036
|
-
${
|
|
2583
|
+
${CLI_COLORS5.info(" const { withStorybook } = require('@storybook/react-native/metro/withStorybook'); ")}
|
|
2584
|
+
${CLI_COLORS5.info(" module.exports = withStorybook(defaultConfig); ")}
|
|
2037
2585
|
|
|
2038
2586
|
For more details go to:
|
|
2039
2587
|
https://github.com/storybookjs/react-native#getting-started
|
|
2040
2588
|
|
|
2041
2589
|
Then to start Storybook for React Native, run:
|
|
2042
2590
|
|
|
2043
|
-
${
|
|
2591
|
+
${CLI_COLORS5.cta(" " + packageManager.getRunCommand("start") + " ")}
|
|
2044
2592
|
`);
|
|
2045
2593
|
}
|
|
2046
2594
|
};
|
|
2047
2595
|
|
|
2048
2596
|
// src/generators/REACT_NATIVE_AND_RNW/index.ts
|
|
2049
2597
|
import { ProjectType as ProjectType14 } from "storybook/internal/cli";
|
|
2050
|
-
import { SupportedBuilder as SupportedBuilder11, SupportedFramework as
|
|
2598
|
+
import { SupportedBuilder as SupportedBuilder11, SupportedFramework as SupportedFramework10, SupportedRenderer as SupportedRenderer11 } from "storybook/internal/types";
|
|
2051
2599
|
|
|
2052
2600
|
// src/generators/REACT_NATIVE_WEB/index.ts
|
|
2053
2601
|
import { readdir, rm as rm2 } from "node:fs/promises";
|
|
@@ -2055,7 +2603,7 @@ import { join as join6 } from "node:path";
|
|
|
2055
2603
|
import { ProjectType as ProjectType13, cliStoriesTargetPath } from "storybook/internal/cli";
|
|
2056
2604
|
import {
|
|
2057
2605
|
SupportedBuilder as SupportedBuilder10,
|
|
2058
|
-
SupportedFramework as
|
|
2606
|
+
SupportedFramework as SupportedFramework9,
|
|
2059
2607
|
SupportedLanguage as SupportedLanguage6,
|
|
2060
2608
|
SupportedRenderer as SupportedRenderer10
|
|
2061
2609
|
} from "storybook/internal/types";
|
|
@@ -2063,7 +2611,7 @@ var REACT_NATIVE_WEB_default = {
|
|
|
2063
2611
|
metadata: {
|
|
2064
2612
|
projectType: ProjectType13.REACT_NATIVE_WEB,
|
|
2065
2613
|
renderer: SupportedRenderer10.REACT,
|
|
2066
|
-
framework:
|
|
2614
|
+
framework: SupportedFramework9.REACT_NATIVE_WEB_VITE,
|
|
2067
2615
|
builderOverride: SupportedBuilder10.VITE
|
|
2068
2616
|
},
|
|
2069
2617
|
configure: async (packageManager, { language }) => {
|
|
@@ -2086,7 +2634,7 @@ var REACT_NATIVE_AND_RNW_default = {
|
|
|
2086
2634
|
metadata: {
|
|
2087
2635
|
projectType: ProjectType14.REACT_NATIVE_AND_RNW,
|
|
2088
2636
|
renderer: SupportedRenderer11.REACT,
|
|
2089
|
-
framework:
|
|
2637
|
+
framework: SupportedFramework10.REACT_NATIVE_WEB_VITE,
|
|
2090
2638
|
builderOverride: SupportedBuilder11.VITE
|
|
2091
2639
|
},
|
|
2092
2640
|
configure: async (packageManager, context) => (await REACT_NATIVE_default.configure(packageManager, context), {
|
|
@@ -2103,9 +2651,9 @@ var REACT_NATIVE_AND_RNW_default = {
|
|
|
2103
2651
|
};
|
|
2104
2652
|
|
|
2105
2653
|
// src/generators/REACT_SCRIPTS/index.ts
|
|
2106
|
-
var
|
|
2107
|
-
import { existsSync as
|
|
2108
|
-
import { resolve as
|
|
2654
|
+
var import_ts_dedent14 = __toESM(require_dist(), 1);
|
|
2655
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
2656
|
+
import { resolve as resolve5 } from "node:path";
|
|
2109
2657
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
2110
2658
|
import { ProjectType as ProjectType15 } from "storybook/internal/cli";
|
|
2111
2659
|
import { SupportedBuilder as SupportedBuilder12, SupportedRenderer as SupportedRenderer12 } from "storybook/internal/types";
|
|
@@ -2130,12 +2678,12 @@ var REACT_SCRIPTS_default = {
|
|
|
2130
2678
|
%%`
|
|
2131
2679
|
} : {}, craVersion = (await packageManager.getModulePackageJSON("react-scripts"))?.version ?? null;
|
|
2132
2680
|
if (craVersion === null)
|
|
2133
|
-
throw new Error(
|
|
2681
|
+
throw new Error(import_ts_dedent14.dedent`
|
|
2134
2682
|
It looks like you're trying to initialize Storybook in a CRA project that does not have react-scripts installed.
|
|
2135
2683
|
Please install it and make sure it's of version 5 or higher, which are the versions supported by Storybook 7.0+.
|
|
2136
2684
|
`);
|
|
2137
2685
|
if (craVersion && semver3.lt(craVersion, "5.0.0"))
|
|
2138
|
-
throw new Error(
|
|
2686
|
+
throw new Error(import_ts_dedent14.dedent`
|
|
2139
2687
|
Storybook 7.0+ doesn't support react-scripts@<5.0.0.
|
|
2140
2688
|
|
|
2141
2689
|
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#create-react-app-dropped-cra4-support
|
|
@@ -2145,7 +2693,7 @@ var REACT_SCRIPTS_default = {
|
|
|
2145
2693
|
},
|
|
2146
2694
|
extraAddons: ["@storybook/preset-create-react-app"],
|
|
2147
2695
|
extraPackages: ["webpack", "prop-types"],
|
|
2148
|
-
staticDir:
|
|
2696
|
+
staticDir: existsSync5(resolve5("./public")) ? "public" : void 0,
|
|
2149
2697
|
extraMain
|
|
2150
2698
|
};
|
|
2151
2699
|
}
|
|
@@ -2168,12 +2716,12 @@ var SERVER_default = {
|
|
|
2168
2716
|
|
|
2169
2717
|
// src/generators/SOLID/index.ts
|
|
2170
2718
|
import { ProjectType as ProjectType17 } from "storybook/internal/cli";
|
|
2171
|
-
import { SupportedBuilder as SupportedBuilder14, SupportedFramework as
|
|
2719
|
+
import { SupportedBuilder as SupportedBuilder14, SupportedFramework as SupportedFramework11, SupportedRenderer as SupportedRenderer14 } from "storybook/internal/types";
|
|
2172
2720
|
var SOLID_default = {
|
|
2173
2721
|
metadata: {
|
|
2174
2722
|
projectType: ProjectType17.SOLID,
|
|
2175
2723
|
renderer: SupportedRenderer14.SOLID,
|
|
2176
|
-
framework:
|
|
2724
|
+
framework: SupportedFramework11.SOLID,
|
|
2177
2725
|
builderOverride: SupportedBuilder14.VITE
|
|
2178
2726
|
},
|
|
2179
2727
|
configure: async () => ({
|
|
@@ -2197,12 +2745,12 @@ var SVELTE_default = {
|
|
|
2197
2745
|
|
|
2198
2746
|
// src/generators/SVELTEKIT/index.ts
|
|
2199
2747
|
import { ProjectType as ProjectType19 } from "storybook/internal/cli";
|
|
2200
|
-
import { SupportedBuilder as SupportedBuilder15, SupportedFramework as
|
|
2748
|
+
import { SupportedBuilder as SupportedBuilder15, SupportedFramework as SupportedFramework12, SupportedRenderer as SupportedRenderer16 } from "storybook/internal/types";
|
|
2201
2749
|
var SVELTEKIT_default = {
|
|
2202
2750
|
metadata: {
|
|
2203
2751
|
projectType: ProjectType19.SVELTEKIT,
|
|
2204
2752
|
renderer: SupportedRenderer16.SVELTE,
|
|
2205
|
-
framework:
|
|
2753
|
+
framework: SupportedFramework12.SVELTEKIT,
|
|
2206
2754
|
builderOverride: SupportedBuilder15.VITE
|
|
2207
2755
|
},
|
|
2208
2756
|
configure: async () => ({
|
|
@@ -2298,7 +2846,6 @@ async function doInitiate(options) {
|
|
|
2298
2846
|
packageManager,
|
|
2299
2847
|
addons: extraAddons,
|
|
2300
2848
|
configDir,
|
|
2301
|
-
dependencyInstallationResult,
|
|
2302
2849
|
options
|
|
2303
2850
|
}), await executeFinalization({
|
|
2304
2851
|
logfile: options.logfile,
|