@storybook/cli 10.4.0-alpha.9 → 10.4.0-beta.0
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/{block-dependencies-versions-ZBEFJKRH.js → block-dependencies-versions-G6EVEL6U.js} +11 -11
- package/dist/_node-chunks/{block-experimental-addon-test-2J2EI26J.js → block-experimental-addon-test-MFHC3KUS.js} +9 -9
- package/dist/_node-chunks/{block-major-version-T2HMVIXA.js → block-major-version-4U4WEGMA.js} +9 -9
- package/dist/_node-chunks/{block-node-version-B7D6ADCG.js → block-node-version-ZHYGYUI7.js} +9 -9
- package/dist/_node-chunks/{block-webpack5-frameworks-735HFPAS.js → block-webpack5-frameworks-Y3AGGFNB.js} +11 -11
- package/dist/_node-chunks/chunk-4C3DFANT.js +115 -0
- package/dist/_node-chunks/chunk-6CXRNZGR.js +638 -0
- package/dist/_node-chunks/{chunk-CM5XGY6F.js → chunk-JYKXO3MW.js} +7 -7
- package/dist/_node-chunks/chunk-LIGFKPNZ.js +23 -0
- package/dist/_node-chunks/{chunk-HNY2PNPG.js → chunk-NBAX35QO.js} +7 -7
- package/dist/_node-chunks/chunk-NSIFSQMM.js +11 -0
- package/dist/_node-chunks/chunk-RJYKSYUS.js +20 -0
- package/dist/_node-chunks/{chunk-KMOZMHXY.js → chunk-XXFWAJQS.js} +6 -6
- package/dist/_node-chunks/{chunk-TOPUV6KI.js → chunk-ZBC5DXUL.js} +28 -17
- package/dist/_node-chunks/{globby-GGFRIMJG.js → globby-PHG23IID.js} +8 -8
- package/dist/_node-chunks/monorepo-JBBOX7QG.js +119 -0
- package/dist/_node-chunks/monorepo-optimized-tests-relaxed-limits-no-story-deletion-G2X5WHM3.js +119 -0
- package/dist/_node-chunks/optimized-tests-NI7YTCNF.js +20 -0
- package/dist/_node-chunks/{p-limit-SUJZ4KSM.js → p-limit-T75YPGMQ.js} +7 -7
- package/dist/_node-chunks/pattern-copy-play-6QEXGF3O.js +810 -0
- package/dist/_node-chunks/relaxed-limits-EWX3BPFO.js +115 -0
- package/dist/_node-chunks/{run-2DIHBNRR.js → run-CYEK3WXX.js} +1158 -295
- package/dist/_node-chunks/setup-WAWFVYQV.js +281 -0
- package/dist/bin/index.js +7 -7
- package/package.json +5 -4
- package/dist/_node-chunks/chunk-KV24PD3C.js +0 -11
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_vb9chkpq80c from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_vb9chkpq80c from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_vb9chkpq80c from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_vb9chkpq80c.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_vb9chkpq80c.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_vb9chkpq80c.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
instructions
|
|
14
|
+
} from "./chunk-4C3DFANT.js";
|
|
15
|
+
import "./chunk-6CXRNZGR.js";
|
|
16
|
+
import "./chunk-LIGFKPNZ.js";
|
|
12
17
|
import {
|
|
13
18
|
bannerComment,
|
|
14
19
|
containsDirnameUsage,
|
|
@@ -23,20 +28,21 @@ import {
|
|
|
23
28
|
processAutoblockerResults,
|
|
24
29
|
require_picocolors,
|
|
25
30
|
shortenPath,
|
|
31
|
+
up,
|
|
26
32
|
updateMainConfig,
|
|
27
33
|
upgradeStorybookDependencies
|
|
28
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-ZBC5DXUL.js";
|
|
29
35
|
import {
|
|
30
36
|
slash
|
|
31
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-JYKXO3MW.js";
|
|
32
38
|
import {
|
|
33
39
|
require_semver
|
|
34
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-NBAX35QO.js";
|
|
35
41
|
import {
|
|
36
42
|
__commonJS,
|
|
37
43
|
__require,
|
|
38
44
|
__toESM
|
|
39
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-XXFWAJQS.js";
|
|
40
46
|
|
|
41
47
|
// ../../../node_modules/envinfo/dist/envinfo.js
|
|
42
48
|
var require_envinfo = __commonJS({
|
|
@@ -4417,9 +4423,9 @@ var require_isexe = __commonJS({
|
|
|
4417
4423
|
if (typeof options == "function" && (cb = options, options = {}), !cb) {
|
|
4418
4424
|
if (typeof Promise != "function")
|
|
4419
4425
|
throw new TypeError("callback not provided");
|
|
4420
|
-
return new Promise(function(
|
|
4426
|
+
return new Promise(function(resolve5, reject) {
|
|
4421
4427
|
isexe(path4, options || {}, function(er, is) {
|
|
4422
|
-
er ? reject(er) :
|
|
4428
|
+
er ? reject(er) : resolve5(is);
|
|
4423
4429
|
});
|
|
4424
4430
|
});
|
|
4425
4431
|
}
|
|
@@ -4456,22 +4462,22 @@ var require_which = __commonJS({
|
|
|
4456
4462
|
};
|
|
4457
4463
|
}, which = (cmd, opt, cb) => {
|
|
4458
4464
|
typeof opt == "function" && (cb = opt, opt = {}), opt || (opt = {});
|
|
4459
|
-
let { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt), found = [], step = (i) => new Promise((
|
|
4465
|
+
let { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt), found = [], step = (i) => new Promise((resolve5, reject) => {
|
|
4460
4466
|
if (i === pathEnv.length)
|
|
4461
|
-
return opt.all && found.length ?
|
|
4467
|
+
return opt.all && found.length ? resolve5(found) : reject(getNotFoundError(cmd));
|
|
4462
4468
|
let ppRaw = pathEnv[i], pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw, pCmd = path4.join(pathPart, cmd), p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
4463
|
-
|
|
4464
|
-
}), subStep = (p, i, ii) => new Promise((
|
|
4469
|
+
resolve5(subStep(p, i, 0));
|
|
4470
|
+
}), subStep = (p, i, ii) => new Promise((resolve5, reject) => {
|
|
4465
4471
|
if (ii === pathExt.length)
|
|
4466
|
-
return
|
|
4472
|
+
return resolve5(step(i + 1));
|
|
4467
4473
|
let ext = pathExt[ii];
|
|
4468
4474
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
4469
4475
|
if (!er && is)
|
|
4470
4476
|
if (opt.all)
|
|
4471
4477
|
found.push(p + ext);
|
|
4472
4478
|
else
|
|
4473
|
-
return
|
|
4474
|
-
return
|
|
4479
|
+
return resolve5(p + ext);
|
|
4480
|
+
return resolve5(subStep(p, i, ii + 1));
|
|
4475
4481
|
});
|
|
4476
4482
|
});
|
|
4477
4483
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -4690,7 +4696,7 @@ var require_cross_spawn = __commonJS({
|
|
|
4690
4696
|
"../../../node_modules/cross-spawn/index.js"(exports, module) {
|
|
4691
4697
|
"use strict";
|
|
4692
4698
|
var cp = __require("child_process"), parse2 = require_parse(), enoent = require_enoent();
|
|
4693
|
-
function
|
|
4699
|
+
function spawn2(command2, args, options) {
|
|
4694
4700
|
let parsed = parse2(command2, args, options), spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
4695
4701
|
return enoent.hookChildProcess(spawned, parsed), spawned;
|
|
4696
4702
|
}
|
|
@@ -4698,8 +4704,8 @@ var require_cross_spawn = __commonJS({
|
|
|
4698
4704
|
let parsed = parse2(command2, args, options), result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
4699
4705
|
return result.error = result.error || enoent.verifyENOENTSync(result.status, parsed), result;
|
|
4700
4706
|
}
|
|
4701
|
-
module.exports =
|
|
4702
|
-
module.exports.spawn =
|
|
4707
|
+
module.exports = spawn2;
|
|
4708
|
+
module.exports.spawn = spawn2;
|
|
4703
4709
|
module.exports.sync = spawnSync4;
|
|
4704
4710
|
module.exports._parse = parse2;
|
|
4705
4711
|
module.exports._enoent = enoent;
|
|
@@ -4710,17 +4716,16 @@ var require_cross_spawn = __commonJS({
|
|
|
4710
4716
|
var import_envinfo = __toESM(require_envinfo(), 1);
|
|
4711
4717
|
import { globalSettings } from "storybook/internal/cli";
|
|
4712
4718
|
import {
|
|
4713
|
-
HandledError as
|
|
4719
|
+
HandledError as HandledError3,
|
|
4714
4720
|
JsPackageManagerFactory as JsPackageManagerFactory3,
|
|
4715
4721
|
PackageManagerName as PackageManagerName3,
|
|
4716
|
-
isCI as isCI2,
|
|
4717
4722
|
optionalEnvToBoolean as optionalEnvToBoolean3,
|
|
4718
4723
|
removeAddon as remove,
|
|
4719
4724
|
versions as versions5
|
|
4720
4725
|
} from "storybook/internal/common";
|
|
4721
4726
|
import { withTelemetry } from "storybook/internal/core-server";
|
|
4722
|
-
import { CLI_COLORS as CLI_COLORS5, logTracker as logTracker4, logger as
|
|
4723
|
-
import { addToGlobalContext, telemetry as
|
|
4727
|
+
import { CLI_COLORS as CLI_COLORS5, logTracker as logTracker4, logger as logger26 } from "storybook/internal/node-logger";
|
|
4728
|
+
import { addToGlobalContext, telemetry as telemetry3 } from "storybook/internal/telemetry";
|
|
4724
4729
|
import { Option, program } from "commander";
|
|
4725
4730
|
|
|
4726
4731
|
// ../../../node_modules/leven/index.js
|
|
@@ -4758,10 +4763,10 @@ function leven(first, second, options) {
|
|
|
4758
4763
|
}
|
|
4759
4764
|
|
|
4760
4765
|
// src/bin/run.ts
|
|
4761
|
-
var
|
|
4766
|
+
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
4762
4767
|
|
|
4763
4768
|
// package.json
|
|
4764
|
-
var version = "10.4.0-
|
|
4769
|
+
var version = "10.4.0-beta.0";
|
|
4765
4770
|
|
|
4766
4771
|
// src/add.ts
|
|
4767
4772
|
var import_semver = __toESM(require_semver(), 1);
|
|
@@ -5001,9 +5006,9 @@ var DIR_CWD = process.cwd(), require2 = createRequire2(DIR_CWD), postinstallAddo
|
|
|
5001
5006
|
} catch {
|
|
5002
5007
|
return;
|
|
5003
5008
|
}
|
|
5004
|
-
let postinstall = moduledLoaded?.default || moduledLoaded?.postinstall || moduledLoaded,
|
|
5009
|
+
let postinstall = moduledLoaded?.default || moduledLoaded?.postinstall || moduledLoaded, logger27 = options.logger;
|
|
5005
5010
|
if (!postinstall || typeof postinstall != "function") {
|
|
5006
|
-
|
|
5011
|
+
logger27.error(`Error finding postinstall function for ${addonName}`);
|
|
5007
5012
|
return;
|
|
5008
5013
|
}
|
|
5009
5014
|
try {
|
|
@@ -5024,7 +5029,7 @@ async function add(addon, {
|
|
|
5024
5029
|
configDir: userSpecifiedConfigDir,
|
|
5025
5030
|
yes,
|
|
5026
5031
|
skipInstall
|
|
5027
|
-
},
|
|
5032
|
+
}, logger27 = nodeLogger) {
|
|
5028
5033
|
let [addonName, inputVersion] = getVersionSpecifier(addon), { mainConfig, mainConfigPath, configDir, previewConfigPath, packageManager } = await getStorybookData({
|
|
5029
5034
|
configDir: userSpecifiedConfigDir,
|
|
5030
5035
|
packageManagerName: pkgMgr
|
|
@@ -5034,16 +5039,16 @@ async function add(addon, {
|
|
|
5034
5039
|
Unable to find storybook config directory. Please specify your Storybook config directory with the --config-dir flag.
|
|
5035
5040
|
`);
|
|
5036
5041
|
if (!mainConfigPath) {
|
|
5037
|
-
|
|
5042
|
+
logger27.error("Unable to find Storybook main.js config");
|
|
5038
5043
|
return;
|
|
5039
5044
|
}
|
|
5040
5045
|
let shouldAddToMain = !0;
|
|
5041
|
-
if (checkInstalled(addonName, mainConfig) && (shouldAddToMain = !1, !yes && (
|
|
5046
|
+
if (checkInstalled(addonName, mainConfig) && (shouldAddToMain = !1, !yes && (logger27.log(`The Storybook addon "${addonName}" is already present in ${mainConfigPath}.`), !await prompt.confirm({
|
|
5042
5047
|
message: "Do you wish to install it again?"
|
|
5043
5048
|
}))))
|
|
5044
5049
|
return;
|
|
5045
5050
|
let main = await readConfig(mainConfigPath);
|
|
5046
|
-
|
|
5051
|
+
logger27.log(`Verifying ${addonName}`);
|
|
5047
5052
|
let version2 = inputVersion;
|
|
5048
5053
|
if (!version2 && isCoreAddon(addonName) && (version2 = versions.storybook), !version2) {
|
|
5049
5054
|
let latestVersion = await packageManager.latestVersion(addonName);
|
|
@@ -5052,14 +5057,14 @@ async function add(addon, {
|
|
|
5052
5057
|
version2 = latestVersion;
|
|
5053
5058
|
}
|
|
5054
5059
|
let storybookVersion = versions.storybook, versionIsStorybook = version2 === versions.storybook;
|
|
5055
|
-
isCoreAddon(addonName) && !versionIsStorybook &&
|
|
5060
|
+
isCoreAddon(addonName) && !versionIsStorybook && logger27.warn(
|
|
5056
5061
|
`The version of ${addonName} (${version2}) you are installing is not the same as the version of Storybook you are using (${storybookVersion}). This may lead to unexpected behavior.`
|
|
5057
5062
|
);
|
|
5058
5063
|
let versionRange = packageManager.getDependencyVersion("storybook")?.match(/^[~^]/)?.[0] ?? "", addonWithVersion = versionIsStorybook ? `${addonName}@${versionRange}${storybookVersion}` : isValidVersion(version2) && !version2.includes("-pr-") ? `${addonName}@^${version2}` : `${addonName}@${version2}`;
|
|
5059
|
-
|
|
5064
|
+
logger27.log(`Installing ${addonWithVersion}`), await packageManager.addDependencies(
|
|
5060
5065
|
{ type: "devDependencies", writeOutputToFile: !1, skipInstall },
|
|
5061
5066
|
[addonWithVersion]
|
|
5062
|
-
), shouldAddToMain && (
|
|
5067
|
+
), shouldAddToMain && (logger27.log(`Adding '${addon}' to the "addons" field in ${mainConfigPath}`), await setupAddonInConfig({
|
|
5063
5068
|
addonName,
|
|
5064
5069
|
mainConfigCSFFile: main,
|
|
5065
5070
|
previewConfigPath,
|
|
@@ -5068,7 +5073,7 @@ async function add(addon, {
|
|
|
5068
5073
|
packageManager: packageManager.type,
|
|
5069
5074
|
configDir,
|
|
5070
5075
|
yes,
|
|
5071
|
-
logger:
|
|
5076
|
+
logger: logger27,
|
|
5072
5077
|
prompt,
|
|
5073
5078
|
skipInstall
|
|
5074
5079
|
});
|
|
@@ -5078,9 +5083,9 @@ function isValidVersion(version2) {
|
|
|
5078
5083
|
}
|
|
5079
5084
|
|
|
5080
5085
|
// src/automigrate/index.ts
|
|
5081
|
-
var
|
|
5086
|
+
var import_picocolors15 = __toESM(require_picocolors(), 1);
|
|
5082
5087
|
import { versions as versions3 } from "storybook/internal/common";
|
|
5083
|
-
import { logTracker as logTracker2, logger as
|
|
5088
|
+
import { logTracker as logTracker2, logger as logger18, prompt as prompt4 } from "storybook/internal/node-logger";
|
|
5084
5089
|
import { AutomigrateError } from "storybook/internal/server-errors";
|
|
5085
5090
|
|
|
5086
5091
|
// ../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
@@ -5095,7 +5100,7 @@ function invariant(condition, message) {
|
|
|
5095
5100
|
}
|
|
5096
5101
|
|
|
5097
5102
|
// src/automigrate/index.ts
|
|
5098
|
-
import { dedent as
|
|
5103
|
+
import { dedent as dedent15 } from "ts-dedent";
|
|
5099
5104
|
|
|
5100
5105
|
// src/doctor/index.ts
|
|
5101
5106
|
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
@@ -5625,7 +5630,7 @@ import { logger as logger3 } from "storybook/internal/node-logger";
|
|
|
5625
5630
|
import { promises as fs } from "fs";
|
|
5626
5631
|
var maxConcurrentTasks = Math.max(1, os.cpus().length - 1);
|
|
5627
5632
|
async function runCodemod(globPattern = "**/*.{stories,story}.{js,jsx,ts,tsx,mjs,mjsx,mts,mtsx}", transform, { dryRun = !1, skipFormatting = !1 } = {}) {
|
|
5628
|
-
let modifiedCount = 0, unmodifiedCount = 0, errorCount = 0, { globby } = await import("./globby-
|
|
5633
|
+
let modifiedCount = 0, unmodifiedCount = 0, errorCount = 0, { globby } = await import("./globby-PHG23IID.js"), files = await globby(slash(globPattern), {
|
|
5629
5634
|
followSymbolicLinks: !0,
|
|
5630
5635
|
ignore: ["**/node_modules/**", "**/dist/**", "**/storybook-static/**", "**/build/**"]
|
|
5631
5636
|
});
|
|
@@ -5636,7 +5641,7 @@ Please try a different pattern.
|
|
|
5636
5641
|
`
|
|
5637
5642
|
), new Error("No files matched");
|
|
5638
5643
|
try {
|
|
5639
|
-
let pLimit = (await import("./p-limit-
|
|
5644
|
+
let pLimit = (await import("./p-limit-T75YPGMQ.js")).default, limit = pLimit(maxConcurrentTasks);
|
|
5640
5645
|
await Promise.all(
|
|
5641
5646
|
files.map(
|
|
5642
5647
|
(file) => limit(async () => {
|
|
@@ -6479,7 +6484,7 @@ var addonA11yParameters = {
|
|
|
6479
6484
|
errors.push({ file: previewFileToUpdate, error });
|
|
6480
6485
|
}
|
|
6481
6486
|
}
|
|
6482
|
-
let { default: pLimit } = await import("./p-limit-
|
|
6487
|
+
let { default: pLimit } = await import("./p-limit-T75YPGMQ.js"), limit = pLimit(10);
|
|
6483
6488
|
if (await Promise.all(
|
|
6484
6489
|
storyFilesToUpdate.map(
|
|
6485
6490
|
(file) => limit(async () => {
|
|
@@ -6633,7 +6638,7 @@ var addonGlobalsApi = {
|
|
|
6633
6638
|
}
|
|
6634
6639
|
};
|
|
6635
6640
|
async function transformStoryFiles(files, options, dryRun) {
|
|
6636
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
6641
|
+
let errors = [], { default: pLimit } = await import("./p-limit-T75YPGMQ.js"), limit = pLimit(10);
|
|
6637
6642
|
return await Promise.all(
|
|
6638
6643
|
files.map(
|
|
6639
6644
|
(file) => limit(async () => {
|
|
@@ -6825,7 +6830,7 @@ function transformPackageJson(content) {
|
|
|
6825
6830
|
return hasChanges ? JSON.stringify(packageJson, null, 2) : null;
|
|
6826
6831
|
}
|
|
6827
6832
|
var transformPackageJsonFiles = async (files, dryRun) => {
|
|
6828
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
6833
|
+
let errors = [], { default: pLimit } = await import("./p-limit-T75YPGMQ.js"), limit = pLimit(10);
|
|
6829
6834
|
return await Promise.all(
|
|
6830
6835
|
files.map(
|
|
6831
6836
|
(file) => limit(async () => {
|
|
@@ -6864,7 +6869,7 @@ var transformPackageJsonFiles = async (files, dryRun) => {
|
|
|
6864
6869
|
dryRun
|
|
6865
6870
|
);
|
|
6866
6871
|
errors.push(...packageJsonErrors);
|
|
6867
|
-
let { globby } = await import("./globby-
|
|
6872
|
+
let { globby } = await import("./globby-PHG23IID.js"), configFiles = await globby([`${configDir}/**/*`]), importErrors = await transformImportFiles(
|
|
6868
6873
|
[...storiesPaths, ...configFiles].filter(Boolean),
|
|
6869
6874
|
{
|
|
6870
6875
|
...consolidatedPackages,
|
|
@@ -7220,7 +7225,7 @@ var VITE_DEFAULT_VERSION = "^7.0.0", transformMainConfig = async (mainConfigPath
|
|
|
7220
7225
|
]);
|
|
7221
7226
|
}
|
|
7222
7227
|
mainConfigPath && (logger11.debug("Updating main config file..."), await transformMainConfig(mainConfigPath, dryRun)), logger11.debug("Scanning and updating import statements...");
|
|
7223
|
-
let { globby } = await import("./globby-
|
|
7228
|
+
let { globby } = await import("./globby-PHG23IID.js"), configFiles = await globby([`${configDir}/**/*`]), allFiles = [...storiesPaths, ...configFiles].filter(Boolean), transformErrors = await transformImportFiles2(
|
|
7224
7229
|
allFiles,
|
|
7225
7230
|
{
|
|
7226
7231
|
"@storybook/nextjs": "@storybook/nextjs-vite"
|
|
@@ -7235,6 +7240,334 @@ var VITE_DEFAULT_VERSION = "^7.0.0", transformMainConfig = async (mainConfigPath
|
|
|
7235
7240
|
}
|
|
7236
7241
|
};
|
|
7237
7242
|
|
|
7243
|
+
// src/automigrate/fixes/react-vite-to-tanstack-react.ts
|
|
7244
|
+
import { readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
7245
|
+
import { transformImportFiles as transformImportFiles3 } from "storybook/internal/common";
|
|
7246
|
+
import { logger as logger12, prompt as prompt3 } from "storybook/internal/node-logger";
|
|
7247
|
+
|
|
7248
|
+
// ../../../node_modules/tinyclip/dist/index.js
|
|
7249
|
+
import { spawn } from "node:child_process";
|
|
7250
|
+
var TIMEOUT = 2e3;
|
|
7251
|
+
function checkUnixCommandExists(command2) {
|
|
7252
|
+
return new Promise((resolve5) => {
|
|
7253
|
+
let proc = spawn("which", [command2]);
|
|
7254
|
+
proc.on("error", () => resolve5(!1)), proc.on("close", (code) => resolve5(code === 0));
|
|
7255
|
+
});
|
|
7256
|
+
}
|
|
7257
|
+
async function getWriteCommand() {
|
|
7258
|
+
switch (process.platform) {
|
|
7259
|
+
case "darwin":
|
|
7260
|
+
return ["pbcopy", []];
|
|
7261
|
+
case "win32":
|
|
7262
|
+
return ["clip", []];
|
|
7263
|
+
case "linux":
|
|
7264
|
+
case "freebsd":
|
|
7265
|
+
case "openbsd":
|
|
7266
|
+
return process.env.WSL_DISTRO_NAME ? ["clip.exe", []] : process.env.WAYLAND_DISPLAY ? ["wl-copy", []] : await checkUnixCommandExists("xsel") ? ["xsel", ["--clipboard", "--input"]] : ["xclip", ["-selection", "clipboard", "-i"]];
|
|
7267
|
+
case "android":
|
|
7268
|
+
return ["termux-clipboard-set", []];
|
|
7269
|
+
default:
|
|
7270
|
+
return;
|
|
7271
|
+
}
|
|
7272
|
+
}
|
|
7273
|
+
function writeText(text) {
|
|
7274
|
+
return new Promise(async (resolve5, reject) => {
|
|
7275
|
+
let command2 = await getWriteCommand();
|
|
7276
|
+
if (!command2)
|
|
7277
|
+
return reject(new Error("No clipboard tool found"));
|
|
7278
|
+
let proc = spawn(...command2, {
|
|
7279
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
7280
|
+
signal: AbortSignal.timeout(TIMEOUT)
|
|
7281
|
+
});
|
|
7282
|
+
proc.on("error", (cause) => reject(new Error("An error occurred while copying", { cause }))), proc.on("close", (code) => code === 0 ? resolve5() : reject(new Error("An unknown error occurred while copying"))), proc.stdin.write(text), proc.stdin.end();
|
|
7283
|
+
});
|
|
7284
|
+
}
|
|
7285
|
+
|
|
7286
|
+
// src/automigrate/fixes/react-vite-to-tanstack-react.ts
|
|
7287
|
+
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
7288
|
+
import { dedent as dedent9 } from "ts-dedent";
|
|
7289
|
+
var REACT_VITE_PACKAGE = "@storybook/react-vite", TANSTACK_REACT_PACKAGE = "@storybook/tanstack-react", TANSTACK_ROUTER_DECORATOR_MARKERS = [
|
|
7290
|
+
"createMemoryHistory",
|
|
7291
|
+
"createRootRoute",
|
|
7292
|
+
"createRouter",
|
|
7293
|
+
"RouterProvider"
|
|
7294
|
+
], TANSTACK_ROUTER_PACKAGES = [
|
|
7295
|
+
"@tanstack/react-router",
|
|
7296
|
+
"@tanstack/router-core",
|
|
7297
|
+
"@tanstack/start",
|
|
7298
|
+
"@tanstack/react-start"
|
|
7299
|
+
], fileLooksLikeTanstackRouterDecorator = (content) => TANSTACK_ROUTER_PACKAGES.some(
|
|
7300
|
+
(pkg) => new RegExp(`from\\s+['"]${pkg.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\$&")}['"]`).test(content)
|
|
7301
|
+
) ? TANSTACK_ROUTER_DECORATOR_MARKERS.some((marker) => content.includes(marker)) : !1, detectTanstackRouterDecorator = async ({
|
|
7302
|
+
previewConfigPath,
|
|
7303
|
+
configDir,
|
|
7304
|
+
storiesPaths
|
|
7305
|
+
}) => {
|
|
7306
|
+
let { globby } = await import("./globby-PHG23IID.js"), configFiles = configDir ? await globby([`${configDir}/**/*.{ts,tsx,js,jsx,mjs,cjs}`], {
|
|
7307
|
+
ignore: ["**/node_modules/**", "**/dist/**"]
|
|
7308
|
+
}) : [], candidateFiles = Array.from(
|
|
7309
|
+
/* @__PURE__ */ new Set([...previewConfigPath ? [previewConfigPath] : [], ...configFiles, ...storiesPaths])
|
|
7310
|
+
);
|
|
7311
|
+
for (let file of candidateFiles)
|
|
7312
|
+
try {
|
|
7313
|
+
let content = await readFile7(file, "utf-8");
|
|
7314
|
+
if (fileLooksLikeTanstackRouterDecorator(content))
|
|
7315
|
+
return !0;
|
|
7316
|
+
} catch {
|
|
7317
|
+
continue;
|
|
7318
|
+
}
|
|
7319
|
+
return !1;
|
|
7320
|
+
}, transformMainConfig2 = async (mainConfigPath, dryRun) => {
|
|
7321
|
+
try {
|
|
7322
|
+
let content = await readFile7(mainConfigPath, "utf-8");
|
|
7323
|
+
if (!content.includes(REACT_VITE_PACKAGE))
|
|
7324
|
+
return !1;
|
|
7325
|
+
let transformedContent = content.replaceAll(REACT_VITE_PACKAGE, TANSTACK_REACT_PACKAGE);
|
|
7326
|
+
return transformedContent !== content && !dryRun && await writeFile6(mainConfigPath, transformedContent), transformedContent !== content;
|
|
7327
|
+
} catch (error) {
|
|
7328
|
+
return logger12.error(`Failed to update main config at ${mainConfigPath}: ${error}`), !1;
|
|
7329
|
+
}
|
|
7330
|
+
}, buildAiMigrationPrompt = (previewConfigPath) => dedent9`
|
|
7331
|
+
You are migrating a Storybook project from the "${REACT_VITE_PACKAGE}" framework to the
|
|
7332
|
+
"${TANSTACK_REACT_PACKAGE}" framework. The framework swap in .storybook/main.* and the
|
|
7333
|
+
package.json dependency change have already been performed by the Storybook automigration
|
|
7334
|
+
CLI — do not redo those. Your job is to clean up the user-land code that the CLI cannot
|
|
7335
|
+
safely transform.
|
|
7336
|
+
|
|
7337
|
+
Reference documentation:
|
|
7338
|
+
https://storybook.js.org/docs/get-started/frameworks/tanstack-react
|
|
7339
|
+
|
|
7340
|
+
# Background
|
|
7341
|
+
|
|
7342
|
+
"${TANSTACK_REACT_PACKAGE}" is a TanStack Router-aware Storybook framework built on top
|
|
7343
|
+
of @storybook/react-vite. It mounts every story inside a TanStack Router (in-memory
|
|
7344
|
+
history) automatically. Manual router setup that users previously wired into a
|
|
7345
|
+
decorator is now redundant and must be removed — leaving it in place creates a nested
|
|
7346
|
+
router and breaks stories.
|
|
7347
|
+
|
|
7348
|
+
Telltale signs of a manual decorator that must be removed (any of these in
|
|
7349
|
+
preview / decorator / story files):
|
|
7350
|
+
- imports from "@tanstack/react-router", "@tanstack/router-core",
|
|
7351
|
+
"@tanstack/start", or "@tanstack/react-start" used to construct a router
|
|
7352
|
+
- calls to createMemoryHistory(...), createRootRoute(...), createRouter(...)
|
|
7353
|
+
- JSX usage of <RouterProvider router={...} />
|
|
7354
|
+
- a decorator function (e.g. const withRouter = (Story) => <RouterProvider .../>)
|
|
7355
|
+
wired into "decorators: [...]" of a meta or preview
|
|
7356
|
+
|
|
7357
|
+
# The replacement APIs from "${TANSTACK_REACT_PACKAGE}"
|
|
7358
|
+
|
|
7359
|
+
All of the following are exported from "${TANSTACK_REACT_PACKAGE}" — re-exporting the
|
|
7360
|
+
@storybook/react primitives plus the TanStack-specific additions. Use these instead of
|
|
7361
|
+
a hand-rolled router decorator. Only opt in when a story actually needs a specific
|
|
7362
|
+
route — by default the framework's auto-router is enough.
|
|
7363
|
+
|
|
7364
|
+
1) Preview-level default route (CSF factories — recommended).
|
|
7365
|
+
|
|
7366
|
+
In ${previewConfigPath ?? ".storybook/preview.*"}:
|
|
7367
|
+
|
|
7368
|
+
import { definePreview } from '@storybook/tanstack-react';
|
|
7369
|
+
import { routeTree } from '../src/routeTree.gen'; // or a custom Route
|
|
7370
|
+
|
|
7371
|
+
export default definePreview({
|
|
7372
|
+
// optional — registers a default route for every story in the project
|
|
7373
|
+
route: routeTree,
|
|
7374
|
+
parameters: { /* ... */ },
|
|
7375
|
+
});
|
|
7376
|
+
|
|
7377
|
+
2) Per-meta route via "parameters.tanstack.router" (works with both CSF factories
|
|
7378
|
+
and CSF3). Most TanStack-Router-decorator removals translate to this:
|
|
7379
|
+
|
|
7380
|
+
// CSF factories style (preferred when the project already uses preview.meta):
|
|
7381
|
+
import preview from '#.storybook/preview';
|
|
7382
|
+
import { Route } from './Page';
|
|
7383
|
+
|
|
7384
|
+
const meta = preview.meta({
|
|
7385
|
+
title: 'Example/Page',
|
|
7386
|
+
parameters: {
|
|
7387
|
+
tanstack: {
|
|
7388
|
+
router: {
|
|
7389
|
+
route: Route,
|
|
7390
|
+
},
|
|
7391
|
+
},
|
|
7392
|
+
},
|
|
7393
|
+
});
|
|
7394
|
+
|
|
7395
|
+
export const Default = meta.story();
|
|
7396
|
+
|
|
7397
|
+
// CSF3 style:
|
|
7398
|
+
import type { Meta, StoryObj } from '@storybook/tanstack-react';
|
|
7399
|
+
import { Route } from './Page';
|
|
7400
|
+
|
|
7401
|
+
const meta = {
|
|
7402
|
+
title: 'Example/Page',
|
|
7403
|
+
parameters: {
|
|
7404
|
+
tanstack: { router: { route: Route } },
|
|
7405
|
+
},
|
|
7406
|
+
} satisfies Meta<typeof Route>;
|
|
7407
|
+
|
|
7408
|
+
export default meta;
|
|
7409
|
+
export const Default: StoryObj<typeof meta> = {};
|
|
7410
|
+
|
|
7411
|
+
3) Per-story override — same shape, but on a single story's "parameters" instead of
|
|
7412
|
+
the meta. Useful when one story needs a different route than the others.
|
|
7413
|
+
|
|
7414
|
+
4) Additional "parameters.tanstack.router" fields you can use when needed:
|
|
7415
|
+
- "path" initial pathname (e.g. '/users/$id')
|
|
7416
|
+
- "params" URL params object (typed against the route)
|
|
7417
|
+
- "query" search params object (typed against the route)
|
|
7418
|
+
- "routeOverrides" map of route id -> { loader / beforeLoad / validateSearch / ... }
|
|
7419
|
+
for mocking specific routes in the registered tree
|
|
7420
|
+
- "useRouterContext" function that returns a custom router context per story
|
|
7421
|
+
|
|
7422
|
+
Do NOT introduce any of these unless the original decorator was clearly setting up
|
|
7423
|
+
that exact behavior. Remove the decorator first; only port over the bits that were
|
|
7424
|
+
actually doing work.
|
|
7425
|
+
|
|
7426
|
+
5) Type imports. If the project uses CSF3 types, switch them from "@storybook/react"
|
|
7427
|
+
(or "@storybook/react-vite") to "@storybook/tanstack-react":
|
|
7428
|
+
|
|
7429
|
+
- import type { Meta, StoryObj } from '@storybook/react';
|
|
7430
|
+
+ import type { Meta, StoryObj } from '@storybook/tanstack-react';
|
|
7431
|
+
|
|
7432
|
+
The TanStack-aware "Meta" infers TanStack parameter types from the route in
|
|
7433
|
+
"component" / parameters, giving type-safe params/query.
|
|
7434
|
+
|
|
7435
|
+
# Tasks (perform in order, in the user's repository)
|
|
7436
|
+
|
|
7437
|
+
1. Open ${previewConfigPath ?? ".storybook/preview.*"} and remove any TanStack Router
|
|
7438
|
+
decorator from the "decorators" array. The decorator may be:
|
|
7439
|
+
- defined inline in this file, or
|
|
7440
|
+
- imported from another module (commonly .storybook/decorators.ts,
|
|
7441
|
+
.storybook/withRouter.tsx, or similar) — in that case remove BOTH the
|
|
7442
|
+
import + usage here AND delete the decorator definition at its source.
|
|
7443
|
+
If the source decorator file becomes empty after removal, delete the file.
|
|
7444
|
+
|
|
7445
|
+
Confirm "definePreview" is imported from "@storybook/tanstack-react" (not
|
|
7446
|
+
"@storybook/react" or "@storybook/react-vite"). If the project has a single
|
|
7447
|
+
project-wide route to register, pass it via "definePreview({ route })".
|
|
7448
|
+
|
|
7449
|
+
2. Search the whole repository (not just .storybook/) for any *.stories.* file that
|
|
7450
|
+
declares a per-story or per-meta TanStack Router decorator and remove it. If the
|
|
7451
|
+
removed decorator was setting up a specific route, port that to
|
|
7452
|
+
"parameters.tanstack.router" using the APIs above (route / path / params / query /
|
|
7453
|
+
routeOverrides — whichever applies).
|
|
7454
|
+
|
|
7455
|
+
3. Drop now-unused imports of: RouterProvider, createRouter, createMemoryHistory,
|
|
7456
|
+
createRootRoute, Outlet (from "@tanstack/react-router" / "@tanstack/router-core" /
|
|
7457
|
+
"@tanstack/start" / "@tanstack/react-start"). Keep imports that are still
|
|
7458
|
+
legitimately used elsewhere in the file (Link, useNavigate, createRoute when used
|
|
7459
|
+
to build a Route passed to "parameters.tanstack.router.route", etc.).
|
|
7460
|
+
|
|
7461
|
+
4. Update story-type imports from "@storybook/react" / "@storybook/react-vite" to
|
|
7462
|
+
"@storybook/tanstack-react" wherever the story uses TanStack router parameters,
|
|
7463
|
+
so the types pick up the TanStack additions.
|
|
7464
|
+
|
|
7465
|
+
5. Preserve CSF factories syntax. If the file uses
|
|
7466
|
+
"definePreview({...})" / "preview.meta({...})" / "meta.story(...)", keep that shape;
|
|
7467
|
+
only mutate the affected fields. Do not rewrite CSF1/CSF2/CSF3 -> CSF factories or
|
|
7468
|
+
vice versa.
|
|
7469
|
+
|
|
7470
|
+
6. Preserve all other decorators, parameters, args, argTypes, loaders, beforeEach,
|
|
7471
|
+
tags, and globals exactly as they were. Only the TanStack Router decorator is
|
|
7472
|
+
being removed.
|
|
7473
|
+
|
|
7474
|
+
7. Do not edit .storybook/main.*, package.json, or any lockfile — those are already
|
|
7475
|
+
handled by the automigration CLI.
|
|
7476
|
+
|
|
7477
|
+
# Verification checklist before finishing
|
|
7478
|
+
|
|
7479
|
+
- No remaining manual "RouterProvider", "createRouter", "createMemoryHistory",
|
|
7480
|
+
"createRootRoute" usage in preview, .storybook/**, or *.stories.*.
|
|
7481
|
+
- "decorators" arrays no longer contain the removed TanStack Router decorator.
|
|
7482
|
+
- All previously imported router symbols that are no longer referenced are gone.
|
|
7483
|
+
- Story files importing TanStack-aware types use "@storybook/tanstack-react".
|
|
7484
|
+
- TypeScript still compiles. Storybook still loads. Stories that don't need a
|
|
7485
|
+
specific route now rely on the framework's default in-memory router; stories
|
|
7486
|
+
that do specify a route do so via "parameters.tanstack.router".
|
|
7487
|
+
`, reactViteToTanstackReact = {
|
|
7488
|
+
id: "react-vite-to-tanstack-react",
|
|
7489
|
+
link: "https://storybook.js.org/docs/get-started/frameworks/tanstack-react",
|
|
7490
|
+
defaultSelected: !1,
|
|
7491
|
+
async check({
|
|
7492
|
+
packageManager,
|
|
7493
|
+
previewConfigPath,
|
|
7494
|
+
configDir,
|
|
7495
|
+
storiesPaths
|
|
7496
|
+
}) {
|
|
7497
|
+
let allDeps = packageManager.getAllDependencies(), hasReactVitePackage = !!allDeps[REACT_VITE_PACKAGE], hasTanstackRouter = TANSTACK_ROUTER_PACKAGES.some((pkg) => !!allDeps[pkg]);
|
|
7498
|
+
return !hasReactVitePackage || !hasTanstackRouter ? null : {
|
|
7499
|
+
hasTanstackRouterDecorator: await detectTanstackRouterDecorator({
|
|
7500
|
+
previewConfigPath,
|
|
7501
|
+
configDir,
|
|
7502
|
+
storiesPaths: storiesPaths ?? []
|
|
7503
|
+
})
|
|
7504
|
+
};
|
|
7505
|
+
},
|
|
7506
|
+
prompt() {
|
|
7507
|
+
return `Migrate from ${REACT_VITE_PACKAGE} to ${TANSTACK_REACT_PACKAGE} (TanStack Router-aware framework)`;
|
|
7508
|
+
},
|
|
7509
|
+
async run({
|
|
7510
|
+
result,
|
|
7511
|
+
dryRun = !1,
|
|
7512
|
+
mainConfigPath,
|
|
7513
|
+
previewConfigPath,
|
|
7514
|
+
storiesPaths,
|
|
7515
|
+
configDir,
|
|
7516
|
+
packageManager,
|
|
7517
|
+
storybookVersion,
|
|
7518
|
+
yes
|
|
7519
|
+
}) {
|
|
7520
|
+
if (!result)
|
|
7521
|
+
return;
|
|
7522
|
+
logger12.step(`Migrating from ${REACT_VITE_PACKAGE} to ${TANSTACK_REACT_PACKAGE}...`), dryRun ? logger12.debug("Dry run: Skipping package.json updates.") : (logger12.debug("Updating package.json files..."), await packageManager.removeDependencies([REACT_VITE_PACKAGE]), await packageManager.addDependencies({ type: "devDependencies", skipInstall: !0 }, [
|
|
7523
|
+
`${TANSTACK_REACT_PACKAGE}@${storybookVersion}`
|
|
7524
|
+
])), mainConfigPath && (logger12.debug("Updating main config file..."), await transformMainConfig2(mainConfigPath, dryRun)), logger12.debug("Scanning and updating import statements...");
|
|
7525
|
+
let { globby } = await import("./globby-PHG23IID.js"), configFiles = configDir ? await globby([`${configDir}/**/*.{ts,tsx,js,jsx,mjs,cjs}`], {
|
|
7526
|
+
ignore: ["**/node_modules/**", "**/dist/**"]
|
|
7527
|
+
}) : [], allFiles = [...storiesPaths, ...configFiles, previewConfigPath].filter(
|
|
7528
|
+
Boolean
|
|
7529
|
+
), transformErrors = await transformImportFiles3(
|
|
7530
|
+
allFiles,
|
|
7531
|
+
{
|
|
7532
|
+
[REACT_VITE_PACKAGE]: TANSTACK_REACT_PACKAGE
|
|
7533
|
+
},
|
|
7534
|
+
!!dryRun
|
|
7535
|
+
);
|
|
7536
|
+
if (transformErrors.length > 0 && (logger12.warn(`Encountered ${transformErrors.length} errors during file transformation:`), transformErrors.forEach(({ file, error }) => {
|
|
7537
|
+
logger12.warn(` - ${file}: ${error.message}`);
|
|
7538
|
+
})), result.hasTanstackRouterDecorator && (logger12.logBox(
|
|
7539
|
+
dedent9`
|
|
7540
|
+
We detected what looks like a manual TanStack Router decorator in
|
|
7541
|
+
${import_picocolors11.default.cyan(previewConfigPath ?? ".storybook/preview")}.
|
|
7542
|
+
|
|
7543
|
+
${import_picocolors11.default.bold(TANSTACK_REACT_PACKAGE)} wraps every story in a TanStack Router
|
|
7544
|
+
automatically (see ${import_picocolors11.default.yellow(
|
|
7545
|
+
"https://storybook.js.org/docs/get-started/frameworks/tanstack-react"
|
|
7546
|
+
)}), so that decorator is no longer needed and should be removed.
|
|
7547
|
+
`
|
|
7548
|
+
), yes ? !0 : await prompt3.confirm({
|
|
7549
|
+
message: "Would you like a ready-to-paste AI prompt to help remove the now-unused TanStack Router decorator?",
|
|
7550
|
+
initialValue: !0
|
|
7551
|
+
}))) {
|
|
7552
|
+
let aiPrompt = buildAiMigrationPrompt(previewConfigPath), separator = import_picocolors11.default.dim("\u2500".repeat(60)), clipboardOk = !1;
|
|
7553
|
+
try {
|
|
7554
|
+
await writeText(aiPrompt), clipboardOk = !0;
|
|
7555
|
+
} catch {
|
|
7556
|
+
}
|
|
7557
|
+
logger12.logBox(
|
|
7558
|
+
dedent9`${clipboardOk ? "AI migration prompt copied to clipboard. Full prompt below:" : "Clipboard not available in this environment. Copy the AI migration prompt below manually:"}
|
|
7559
|
+
|
|
7560
|
+
${separator}
|
|
7561
|
+
${aiPrompt}
|
|
7562
|
+
${separator}`
|
|
7563
|
+
);
|
|
7564
|
+
}
|
|
7565
|
+
logger12.step("Migration completed successfully!"), logger12.log(
|
|
7566
|
+
"For more information, see: https://storybook.js.org/docs/get-started/frameworks/tanstack-react"
|
|
7567
|
+
);
|
|
7568
|
+
}
|
|
7569
|
+
};
|
|
7570
|
+
|
|
7238
7571
|
// src/automigrate/fixes/remove-addon-interactions.ts
|
|
7239
7572
|
import { getAddonNames as getAddonNames5, removeAddon as removeAddon4 } from "storybook/internal/common";
|
|
7240
7573
|
var removeAddonInteractions = {
|
|
@@ -7257,10 +7590,10 @@ var removeAddonInteractions = {
|
|
|
7257
7590
|
};
|
|
7258
7591
|
|
|
7259
7592
|
// src/automigrate/fixes/remove-docs-autodocs.ts
|
|
7260
|
-
var
|
|
7593
|
+
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
7261
7594
|
import { Tag } from "storybook/internal/core-server";
|
|
7262
7595
|
import { readConfig as readConfig2 } from "storybook/internal/csf-tools";
|
|
7263
|
-
var
|
|
7596
|
+
var logger13 = {
|
|
7264
7597
|
log: (message) => {
|
|
7265
7598
|
process.env.NODE_ENV !== "test" && console.log(message);
|
|
7266
7599
|
}
|
|
@@ -7279,13 +7612,13 @@ var logger12 = {
|
|
|
7279
7612
|
return null;
|
|
7280
7613
|
}
|
|
7281
7614
|
},
|
|
7282
|
-
prompt: () => `${
|
|
7615
|
+
prompt: () => `${import_picocolors12.default.cyan("docs.autodocs")} has been removed in Storybook 9 and will be removed from your configuration.`,
|
|
7283
7616
|
async run({ result, dryRun, mainConfigPath, previewConfigPath }) {
|
|
7284
7617
|
let { autodocs } = result;
|
|
7285
|
-
|
|
7618
|
+
logger13.log(`\u{1F504} Updating ${import_picocolors12.default.cyan("docs")} parameter in main config file...`), await updateMainConfig({ mainConfigPath, dryRun: !!dryRun }, async (main) => {
|
|
7286
7619
|
let docs = main.getFieldValue(["docs"]) || {};
|
|
7287
7620
|
dryRun || (delete docs.autodocs, Object.keys(docs).length === 0 ? main.removeField(["docs"]) : main.setFieldValue(["docs"], docs));
|
|
7288
|
-
}), autodocs === !0 && previewConfigPath && (
|
|
7621
|
+
}), autodocs === !0 && previewConfigPath && (logger13.log(`\u{1F504} Updating ${import_picocolors12.default.cyan("tags")} parameter in preview config file...`), await updateMainConfig(
|
|
7289
7622
|
{ mainConfigPath: previewConfigPath, dryRun: !!dryRun },
|
|
7290
7623
|
async (preview) => {
|
|
7291
7624
|
let tags = preview.getFieldValue(["tags"]) || [];
|
|
@@ -7296,7 +7629,7 @@ var logger12 = {
|
|
|
7296
7629
|
};
|
|
7297
7630
|
|
|
7298
7631
|
// src/automigrate/fixes/remove-essentials.ts
|
|
7299
|
-
import { getAddonNames as getAddonNames6, removeAddon as removeAddon5, transformImportFiles as
|
|
7632
|
+
import { getAddonNames as getAddonNames6, removeAddon as removeAddon5, transformImportFiles as transformImportFiles4 } from "storybook/internal/common";
|
|
7300
7633
|
|
|
7301
7634
|
// src/automigrate/fixes/remove-essentials.utils.ts
|
|
7302
7635
|
function moveEssentialOptions(dryRun, essentialsOptions) {
|
|
@@ -7390,7 +7723,7 @@ var consolidatedAddons = {
|
|
|
7390
7723
|
packageManager,
|
|
7391
7724
|
skipInstall: !0
|
|
7392
7725
|
});
|
|
7393
|
-
let errors = await
|
|
7726
|
+
let errors = await transformImportFiles4(
|
|
7394
7727
|
[...storiesPaths, mainConfigPath, previewConfigPath].filter(Boolean),
|
|
7395
7728
|
consolidatedAddons,
|
|
7396
7729
|
dryRun
|
|
@@ -7416,13 +7749,13 @@ ${errors.map(({ file, error }) => `- ${file}: ${error.message}`).join(`
|
|
|
7416
7749
|
};
|
|
7417
7750
|
|
|
7418
7751
|
// src/automigrate/fixes/renderer-to-framework.ts
|
|
7419
|
-
import { readFile as
|
|
7752
|
+
import { readFile as readFile8, writeFile as writeFile7 } from "node:fs/promises";
|
|
7420
7753
|
import {
|
|
7421
7754
|
frameworkPackages as frameworkPackages4,
|
|
7422
7755
|
frameworkToRenderer,
|
|
7423
7756
|
rendererPackages as rendererPackages2
|
|
7424
7757
|
} from "storybook/internal/common";
|
|
7425
|
-
import { logger as
|
|
7758
|
+
import { logger as logger14 } from "storybook/internal/node-logger";
|
|
7426
7759
|
var getAllDependencies = (packageJson) => Object.keys({
|
|
7427
7760
|
...packageJson.dependencies || {},
|
|
7428
7761
|
...packageJson.devDependencies || {}
|
|
@@ -7430,13 +7763,13 @@ var getAllDependencies = (packageJson) => Object.keys({
|
|
|
7430
7763
|
let regex = new RegExp(`(['"])${renderer}(['"])`, "g");
|
|
7431
7764
|
return regex.test(source) ? source.replace(regex, `$1${framework}$2`) : null;
|
|
7432
7765
|
}, transformSourceFiles = async (files, renderer, framework, dryRun) => {
|
|
7433
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
7766
|
+
let errors = [], { default: pLimit } = await import("./p-limit-T75YPGMQ.js"), limit = pLimit(10);
|
|
7434
7767
|
return await Promise.all(
|
|
7435
7768
|
files.map(
|
|
7436
7769
|
(file) => limit(async () => {
|
|
7437
7770
|
try {
|
|
7438
|
-
let contents = await
|
|
7439
|
-
!dryRun && transformed && await
|
|
7771
|
+
let contents = await readFile8(file, "utf-8"), transformed = replaceImports(contents, renderer, framework);
|
|
7772
|
+
!dryRun && transformed && await writeFile7(file, transformed);
|
|
7440
7773
|
} catch (error) {
|
|
7441
7774
|
errors.push({ file, error });
|
|
7442
7775
|
}
|
|
@@ -7445,13 +7778,13 @@ var getAllDependencies = (packageJson) => Object.keys({
|
|
|
7445
7778
|
), errors;
|
|
7446
7779
|
}, removeRendererInPackageJson = async (packageJsonPath, renderer, dryRun) => {
|
|
7447
7780
|
try {
|
|
7448
|
-
let content = await
|
|
7449
|
-
return packageJson.dependencies?.[renderer] && (delete packageJson.dependencies[renderer], hasChanges = !0), packageJson.devDependencies?.[renderer] && (delete packageJson.devDependencies[renderer], hasChanges = !0), !dryRun && hasChanges && await
|
|
7781
|
+
let content = await readFile8(packageJsonPath, "utf-8"), packageJson = JSON.parse(content), hasChanges = !1;
|
|
7782
|
+
return packageJson.dependencies?.[renderer] && (delete packageJson.dependencies[renderer], hasChanges = !0), packageJson.devDependencies?.[renderer] && (delete packageJson.devDependencies[renderer], hasChanges = !0), !dryRun && hasChanges && await writeFile7(packageJsonPath, JSON.stringify(packageJson, null, 2)), hasChanges;
|
|
7450
7783
|
} catch (error) {
|
|
7451
7784
|
throw new Error(`Failed to update package.json: ${error}`);
|
|
7452
7785
|
}
|
|
7453
7786
|
}, checkPackageJson = async (packageJsonPath) => {
|
|
7454
|
-
let content = await
|
|
7787
|
+
let content = await readFile8(packageJsonPath, "utf-8"), packageJson = JSON.parse(content), dependencies = getAllDependencies(packageJson), frameworks = detectFrameworks(dependencies);
|
|
7455
7788
|
if (frameworks.length === 0)
|
|
7456
7789
|
return null;
|
|
7457
7790
|
let renderers = detectRenderers(dependencies);
|
|
@@ -7485,25 +7818,25 @@ var getAllDependencies = (packageJson) => Object.keys({
|
|
|
7485
7818
|
let { result, dryRun = !1, storiesPaths, configDir } = options;
|
|
7486
7819
|
for (let selectedFramework of result.frameworks) {
|
|
7487
7820
|
if (!frameworkPackages4[selectedFramework]) {
|
|
7488
|
-
|
|
7821
|
+
logger14.warn(`Framework name not found for ${selectedFramework}, skipping.`);
|
|
7489
7822
|
continue;
|
|
7490
7823
|
}
|
|
7491
7824
|
let rendererName = frameworkToRenderer[frameworkPackages4[selectedFramework]], [rendererPackage] = Object.entries(rendererPackages2).find(([, renderer]) => renderer === rendererName) ?? [];
|
|
7492
7825
|
if (!rendererPackage) {
|
|
7493
|
-
|
|
7826
|
+
logger14.warn(`Renderer package not found for ${selectedFramework}, skipping.`);
|
|
7494
7827
|
continue;
|
|
7495
7828
|
}
|
|
7496
7829
|
if (rendererPackage === selectedFramework)
|
|
7497
7830
|
continue;
|
|
7498
|
-
|
|
7831
|
+
logger14.debug(`
|
|
7499
7832
|
Migrating ${rendererPackage} to ${selectedFramework}`);
|
|
7500
|
-
let { globby } = await import("./globby-
|
|
7833
|
+
let { globby } = await import("./globby-PHG23IID.js"), configFiles = await globby([`${configDir}/**/*`]);
|
|
7501
7834
|
await transformSourceFiles(
|
|
7502
7835
|
[...storiesPaths, ...configFiles].filter(Boolean),
|
|
7503
7836
|
rendererPackage,
|
|
7504
7837
|
selectedFramework,
|
|
7505
7838
|
dryRun
|
|
7506
|
-
),
|
|
7839
|
+
), logger14.debug("Updating package.json files..."), await Promise.all(
|
|
7507
7840
|
result.packageJsonFiles.map(
|
|
7508
7841
|
(file) => removeRendererInPackageJson(file, rendererPackage, dryRun)
|
|
7509
7842
|
)
|
|
@@ -7512,29 +7845,105 @@ Migrating ${rendererPackage} to ${selectedFramework}`);
|
|
|
7512
7845
|
}
|
|
7513
7846
|
};
|
|
7514
7847
|
|
|
7515
|
-
// src/automigrate/fixes/
|
|
7848
|
+
// src/automigrate/fixes/rn-ondevice-addons-to-device-addons.ts
|
|
7516
7849
|
import { existsSync as existsSync2 } from "node:fs";
|
|
7517
|
-
import {
|
|
7518
|
-
import {
|
|
7519
|
-
import {
|
|
7850
|
+
import { basename as basename2, dirname as dirname2, isAbsolute as isAbsolute2, join as join2, resolve as resolve2 } from "node:path";
|
|
7851
|
+
import { findConfigFile, loadMainConfig } from "storybook/internal/common";
|
|
7852
|
+
import { logger as logger15 } from "storybook/internal/node-logger";
|
|
7853
|
+
|
|
7854
|
+
// ../../core/src/shared/constants/config-folder.ts
|
|
7855
|
+
var RN_STORYBOOK_DIR = ".rnstorybook";
|
|
7856
|
+
|
|
7857
|
+
// src/automigrate/fixes/rn-ondevice-addons-to-device-addons.ts
|
|
7858
|
+
var resolveAbsoluteConfigDir = (configDir) => isAbsolute2(configDir) ? configDir : join2(process.cwd(), configDir), getSiblingStorybookConfigDir = (configDirAbs) => {
|
|
7859
|
+
let base = basename2(configDirAbs), parent = dirname2(configDirAbs);
|
|
7860
|
+
if (base === ".storybook") {
|
|
7861
|
+
let rn = join2(parent, RN_STORYBOOK_DIR);
|
|
7862
|
+
return existsSync2(rn) ? rn : null;
|
|
7863
|
+
}
|
|
7864
|
+
if (base === RN_STORYBOOK_DIR) {
|
|
7865
|
+
let web = join2(parent, ".storybook");
|
|
7866
|
+
return existsSync2(web) ? web : null;
|
|
7867
|
+
}
|
|
7868
|
+
return null;
|
|
7869
|
+
}, isReactNativeMain = (mainConfigPath, mainConfig) => basename2(dirname2(mainConfigPath)) === RN_STORYBOOK_DIR ? !0 : getFrameworkPackageName(mainConfig) === "@storybook/react-native", hasAddonsToRename = (cfg) => {
|
|
7870
|
+
let addons = cfg.addons;
|
|
7871
|
+
return !(!Array.isArray(addons) || addons.length === 0 || cfg.deviceAddons !== void 0);
|
|
7872
|
+
}, rnOndeviceAddonsToDeviceAddons = {
|
|
7873
|
+
id: "rn-ondevice-addons-to-device-addons",
|
|
7874
|
+
link: "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-native-on-device-addons-moved-to-deviceaddons",
|
|
7875
|
+
async check({ mainConfig, packageManager, configDir, mainConfigPath }) {
|
|
7876
|
+
if (!packageManager.getAllDependencies()["@storybook/react-native"])
|
|
7877
|
+
return null;
|
|
7878
|
+
let candidateDirs = [];
|
|
7879
|
+
if (configDir) {
|
|
7880
|
+
let absConfigDir = resolveAbsoluteConfigDir(configDir);
|
|
7881
|
+
candidateDirs.push(absConfigDir);
|
|
7882
|
+
let siblingConfigDir = getSiblingStorybookConfigDir(absConfigDir);
|
|
7883
|
+
siblingConfigDir && candidateDirs.push(siblingConfigDir);
|
|
7884
|
+
}
|
|
7885
|
+
let targets = [], seenResolvedMainPaths = /* @__PURE__ */ new Set();
|
|
7886
|
+
if (candidateDirs.length > 0)
|
|
7887
|
+
for (let dir of candidateDirs) {
|
|
7888
|
+
let mainPath = findConfigFile("main", dir);
|
|
7889
|
+
if (!mainPath)
|
|
7890
|
+
continue;
|
|
7891
|
+
let resolvedMain = resolve2(mainPath);
|
|
7892
|
+
if (seenResolvedMainPaths.has(resolvedMain))
|
|
7893
|
+
continue;
|
|
7894
|
+
seenResolvedMainPaths.add(resolvedMain);
|
|
7895
|
+
let cfg;
|
|
7896
|
+
if (mainConfigPath && resolve2(mainConfigPath) === resolvedMain)
|
|
7897
|
+
cfg = mainConfig;
|
|
7898
|
+
else
|
|
7899
|
+
try {
|
|
7900
|
+
cfg = await loadMainConfig({ configDir: dir });
|
|
7901
|
+
} catch (e) {
|
|
7902
|
+
logger15.debug(
|
|
7903
|
+
`Failed to load Storybook main config at ${dir}: ${e instanceof Error ? e.message : String(e)}`
|
|
7904
|
+
);
|
|
7905
|
+
continue;
|
|
7906
|
+
}
|
|
7907
|
+
isReactNativeMain(mainPath, cfg) && hasAddonsToRename(cfg) && targets.push({ mainConfigPath: mainPath });
|
|
7908
|
+
}
|
|
7909
|
+
else mainConfigPath && isReactNativeMain(mainConfigPath, mainConfig) && hasAddonsToRename(mainConfig) && targets.push({ mainConfigPath });
|
|
7910
|
+
return targets.length === 0 ? null : { targets };
|
|
7911
|
+
},
|
|
7912
|
+
prompt() {
|
|
7913
|
+
return "Renaming `addons` to `deviceAddons` in your React Native Storybook config (on-device addons must not be evaluated as Node.js presets).";
|
|
7914
|
+
},
|
|
7915
|
+
async run({ result, dryRun }) {
|
|
7916
|
+
for (let { mainConfigPath } of result.targets)
|
|
7917
|
+
await updateMainConfig({ mainConfigPath, dryRun: !!dryRun }, (main) => {
|
|
7918
|
+
let node = main.getFieldNode(["addons"]);
|
|
7919
|
+
node && (main.setFieldNode(["deviceAddons"], node), main.removeField(["addons"]));
|
|
7920
|
+
});
|
|
7921
|
+
}
|
|
7922
|
+
};
|
|
7923
|
+
|
|
7924
|
+
// src/automigrate/fixes/rnstorybook-config.ts
|
|
7925
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
7926
|
+
import { readFile as readFile9, rename, writeFile as writeFile8 } from "node:fs/promises";
|
|
7927
|
+
import { join as join3 } from "node:path";
|
|
7928
|
+
import { dedent as dedent10 } from "ts-dedent";
|
|
7520
7929
|
async function renameInFile(filePath, oldText, newText) {
|
|
7521
7930
|
try {
|
|
7522
|
-
let updatedContent = (await
|
|
7523
|
-
await
|
|
7931
|
+
let updatedContent = (await readFile9(filePath, "utf8")).replaceAll(oldText, newText);
|
|
7932
|
+
await writeFile8(filePath, updatedContent, "utf8");
|
|
7524
7933
|
} catch (error) {
|
|
7525
7934
|
console.error(`Error updating references in ${filePath}:`, error);
|
|
7526
7935
|
}
|
|
7527
7936
|
}
|
|
7528
7937
|
var getDotStorybookReferences = async (searchDir) => {
|
|
7529
7938
|
try {
|
|
7530
|
-
let { globby } = await import("./globby-
|
|
7939
|
+
let { globby } = await import("./globby-PHG23IID.js"), { readFile: readFile11 } = await import("node:fs/promises"), files = await globby(`${searchDir}/**/*`, {
|
|
7531
7940
|
onlyFiles: !0,
|
|
7532
7941
|
gitignore: !0
|
|
7533
7942
|
}), referencedFiles = [];
|
|
7534
7943
|
return await Promise.all(
|
|
7535
7944
|
files.map(async (file) => {
|
|
7536
7945
|
try {
|
|
7537
|
-
(await
|
|
7946
|
+
(await readFile11(file, "utf8")).includes(".storybook") && referencedFiles.push(file);
|
|
7538
7947
|
} catch {
|
|
7539
7948
|
}
|
|
7540
7949
|
})
|
|
@@ -7548,25 +7957,25 @@ var getDotStorybookReferences = async (searchDir) => {
|
|
|
7548
7957
|
async check({ packageManager, mainConfigPath }) {
|
|
7549
7958
|
if (!packageManager.getAllDependencies()["@storybook/react-native"])
|
|
7550
7959
|
return null;
|
|
7551
|
-
let projectDir = mainConfigPath ?
|
|
7552
|
-
return
|
|
7960
|
+
let projectDir = mainConfigPath ? join3(mainConfigPath, "..", "..") : process.cwd(), storybookDir = join3(projectDir, ".storybook"), rnStorybookDir = join3(projectDir, RN_STORYBOOK_DIR), { globby } = await import("./globby-PHG23IID.js"), requiresFiles = await globby(join3(storybookDir, "storybook.requires.*"));
|
|
7961
|
+
return existsSync3(storybookDir) && requiresFiles.length > 0 && !existsSync3(rnStorybookDir) ? { storybookDir, rnStorybookDir } : null;
|
|
7553
7962
|
},
|
|
7554
7963
|
prompt() {
|
|
7555
|
-
return
|
|
7964
|
+
return dedent10`We'll rename your .storybook directory to .rnstorybook and update all references to it.`;
|
|
7556
7965
|
},
|
|
7557
7966
|
async run({ result: { storybookDir, rnStorybookDir }, dryRun, packageManager }) {
|
|
7558
7967
|
let instanceDir = packageManager.instanceDir, dotStorybookReferences = await getDotStorybookReferences(instanceDir);
|
|
7559
7968
|
dryRun || (await Promise.all(
|
|
7560
7969
|
dotStorybookReferences.map(async (ref) => {
|
|
7561
|
-
await renameInFile(ref, ".storybook",
|
|
7970
|
+
await renameInFile(ref, ".storybook", RN_STORYBOOK_DIR);
|
|
7562
7971
|
})
|
|
7563
7972
|
), await rename(storybookDir, rnStorybookDir));
|
|
7564
7973
|
}
|
|
7565
7974
|
};
|
|
7566
7975
|
|
|
7567
7976
|
// src/automigrate/fixes/storybook-package-name-conflict.ts
|
|
7568
|
-
var
|
|
7569
|
-
import { dedent as
|
|
7977
|
+
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
7978
|
+
import { dedent as dedent11 } from "ts-dedent";
|
|
7570
7979
|
var storybookPackageNameConflict = {
|
|
7571
7980
|
id: "storybookPackageNameConflict",
|
|
7572
7981
|
promptType: "notification",
|
|
@@ -7576,15 +7985,15 @@ var storybookPackageNameConflict = {
|
|
|
7576
7985
|
return packageName === "storybook" ? { packageName } : null;
|
|
7577
7986
|
},
|
|
7578
7987
|
prompt() {
|
|
7579
|
-
return
|
|
7580
|
-
Your package.json ${
|
|
7988
|
+
return dedent11`
|
|
7989
|
+
Your package.json ${import_picocolors13.default.cyan('"name"')} field is set to ${import_picocolors13.default.cyan('"storybook"')}.
|
|
7581
7990
|
|
|
7582
7991
|
In npm, pnpm, or yarn workspaces this creates a symlink at
|
|
7583
|
-
${
|
|
7584
|
-
package, causing ${
|
|
7992
|
+
${import_picocolors13.default.yellow("node_modules/storybook")} that shadows the real Storybook
|
|
7993
|
+
package, causing ${import_picocolors13.default.red('"Cannot find module storybook/internal/..."')} errors.
|
|
7585
7994
|
|
|
7586
|
-
To fix this, rename the ${
|
|
7587
|
-
to something other than ${
|
|
7995
|
+
To fix this, rename the ${import_picocolors13.default.cyan('"name"')} field in your package.json
|
|
7996
|
+
to something other than ${import_picocolors13.default.cyan('"storybook"')} (e.g. "my-storybook", "docs", "@myorg/storybook").
|
|
7588
7997
|
`;
|
|
7589
7998
|
}
|
|
7590
7999
|
};
|
|
@@ -7592,10 +8001,10 @@ var storybookPackageNameConflict = {
|
|
|
7592
8001
|
// src/automigrate/fixes/upgrade-storybook-related-dependencies.ts
|
|
7593
8002
|
var import_semver5 = __toESM(require_semver(), 1);
|
|
7594
8003
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7595
|
-
import { dirname as
|
|
8004
|
+
import { dirname as dirname3 } from "node:path";
|
|
7596
8005
|
import { isCorePackage, isSatelliteAddon } from "storybook/internal/common";
|
|
7597
|
-
import { logger as
|
|
7598
|
-
import { dedent as
|
|
8006
|
+
import { logger as logger16 } from "storybook/internal/node-logger";
|
|
8007
|
+
import { dedent as dedent12 } from "ts-dedent";
|
|
7599
8008
|
async function getLatestVersions(packageManager, packages) {
|
|
7600
8009
|
return Promise.all(
|
|
7601
8010
|
packages.map(async ([packageName]) => ({
|
|
@@ -7606,14 +8015,14 @@ async function getLatestVersions(packageManager, packages) {
|
|
|
7606
8015
|
);
|
|
7607
8016
|
}
|
|
7608
8017
|
function isValidVersionType(packageName, specifier) {
|
|
7609
|
-
return specifier.startsWith("patch:") || specifier.startsWith("file:") || specifier.startsWith("link:") || specifier.startsWith("portal:") || specifier.startsWith("git:") || specifier.startsWith("git+") || specifier.startsWith("http:") || specifier.startsWith("https:") || specifier.startsWith("workspace:") ? (
|
|
8018
|
+
return specifier.startsWith("patch:") || specifier.startsWith("file:") || specifier.startsWith("link:") || specifier.startsWith("portal:") || specifier.startsWith("git:") || specifier.startsWith("git+") || specifier.startsWith("http:") || specifier.startsWith("https:") || specifier.startsWith("workspace:") ? (logger16.debug(`Skipping ${packageName} as it does not have a valid version type: ${specifier}`), !1) : !0;
|
|
7610
8019
|
}
|
|
7611
8020
|
var upgradeStorybookRelatedDependencies = {
|
|
7612
8021
|
id: "upgrade-storybook-related-dependencies",
|
|
7613
8022
|
promptType: "auto",
|
|
7614
8023
|
defaultSelected: !1,
|
|
7615
8024
|
async check({ packageManager, storybookVersion }) {
|
|
7616
|
-
|
|
8025
|
+
logger16.debug("Checking for incompatible storybook packages...");
|
|
7617
8026
|
let analyzedPackages = await getIncompatibleStorybookPackages({
|
|
7618
8027
|
currentStorybookVersion: storybookVersion,
|
|
7619
8028
|
packageManager,
|
|
@@ -7634,7 +8043,7 @@ var upgradeStorybookRelatedDependencies = {
|
|
|
7634
8043
|
},
|
|
7635
8044
|
async run({ result: { upgradable }, packageManager, dryRun }) {
|
|
7636
8045
|
if (dryRun) {
|
|
7637
|
-
|
|
8046
|
+
logger16.log(dedent12`
|
|
7638
8047
|
The following would have been upgraded:
|
|
7639
8048
|
${upgradable.map(
|
|
7640
8049
|
({ packageName, afterVersion, beforeVersion }) => `${packageName}: ${beforeVersion} => ${afterVersion}`
|
|
@@ -7650,7 +8059,7 @@ var upgradeStorybookRelatedDependencies = {
|
|
|
7650
8059
|
return;
|
|
7651
8060
|
let { packageName, afterVersion: version2 } = item, prefixed = `^${version2}`;
|
|
7652
8061
|
packageJson.dependencies?.[packageName] && (packageJson.dependencies[packageName] = prefixed), packageJson.devDependencies?.[packageName] && (packageJson.devDependencies[packageName] = prefixed), packageJson.peerDependencies?.[packageName] && (packageJson.peerDependencies[packageName] = prefixed);
|
|
7653
|
-
}), packageManager.writePackageJson(packageJson,
|
|
8062
|
+
}), packageManager.writePackageJson(packageJson, dirname3(packageJsonPath));
|
|
7654
8063
|
});
|
|
7655
8064
|
}
|
|
7656
8065
|
};
|
|
@@ -7666,7 +8075,7 @@ import {
|
|
|
7666
8075
|
} from "storybook/internal/common";
|
|
7667
8076
|
import { readConfig as readConfig3 } from "storybook/internal/csf-tools";
|
|
7668
8077
|
import { CommonJsConfigNotSupportedError } from "storybook/internal/server-errors";
|
|
7669
|
-
import { dedent as
|
|
8078
|
+
import { dedent as dedent13 } from "ts-dedent";
|
|
7670
8079
|
var wrapGetAbsolutePath = {
|
|
7671
8080
|
id: "wrap-getAbsolutePath",
|
|
7672
8081
|
link: "https://storybook.js.org/docs/faq#how-do-i-fix-module-resolution-in-special-environments",
|
|
@@ -7683,7 +8092,7 @@ var wrapGetAbsolutePath = {
|
|
|
7683
8092
|
return { storybookVersion, isStorybookInMonorepo, isPnp, isConfigTypescript };
|
|
7684
8093
|
},
|
|
7685
8094
|
prompt() {
|
|
7686
|
-
return
|
|
8095
|
+
return dedent13`We have detected that you're using Storybook in a monorepo or PnP project. Some fields in your main config must be updated.`;
|
|
7687
8096
|
},
|
|
7688
8097
|
async run({ dryRun, mainConfigPath, result }) {
|
|
7689
8098
|
await updateMainConfig({ dryRun: !!dryRun, mainConfigPath }, (mainConfig) => {
|
|
@@ -7712,8 +8121,10 @@ var allFixes = [
|
|
|
7712
8121
|
consolidatedImports,
|
|
7713
8122
|
addonExperimentalTest,
|
|
7714
8123
|
rnstorybookConfig,
|
|
8124
|
+
rnOndeviceAddonsToDeviceAddons,
|
|
7715
8125
|
migrateAddonConsole,
|
|
7716
8126
|
nextjsToNextjsVite,
|
|
8127
|
+
reactViteToTanstackReact,
|
|
7717
8128
|
removeAddonInteractions,
|
|
7718
8129
|
rendererToFramework,
|
|
7719
8130
|
removeEssentials,
|
|
@@ -7726,9 +8137,9 @@ var allFixes = [
|
|
|
7726
8137
|
var commandFixes = [csfFactories];
|
|
7727
8138
|
|
|
7728
8139
|
// src/automigrate/helpers/logMigrationSummary.ts
|
|
7729
|
-
var
|
|
7730
|
-
import { CLI_COLORS as CLI_COLORS2, logger as
|
|
7731
|
-
import { dedent as
|
|
8140
|
+
var import_picocolors14 = __toESM(require_picocolors(), 1);
|
|
8141
|
+
import { CLI_COLORS as CLI_COLORS2, logger as logger17 } from "storybook/internal/node-logger";
|
|
8142
|
+
import { dedent as dedent14 } from "ts-dedent";
|
|
7732
8143
|
var messageDivider2 = `
|
|
7733
8144
|
|
|
7734
8145
|
`, segmentDivider = `
|
|
@@ -7738,23 +8149,23 @@ var messageDivider2 = `
|
|
|
7738
8149
|
`;
|
|
7739
8150
|
function getGlossaryMessages(fixSummary, fixResults) {
|
|
7740
8151
|
let messages2 = [];
|
|
7741
|
-
return fixSummary.succeeded.length > 0 && (messages2.push(
|
|
7742
|
-
Object.entries(fixSummary.failed).map(([id, error]) => `${
|
|
8152
|
+
return fixSummary.succeeded.length > 0 && (messages2.push(import_picocolors14.default.bold("Successful migrations:")), messages2.push(fixSummary.succeeded.map((m) => import_picocolors14.default.green(m)).join(", "))), Object.keys(fixSummary.failed).length > 0 && (messages2.push(import_picocolors14.default.bold("Failed migrations:")), messages2.push(
|
|
8153
|
+
Object.entries(fixSummary.failed).map(([id, error]) => `${import_picocolors14.default.bold(import_picocolors14.default.red(id))}:
|
|
7743
8154
|
${error}`).join(`
|
|
7744
8155
|
`)
|
|
7745
|
-
)), fixSummary.manual.length > 0 && (messages2.push(
|
|
8156
|
+
)), fixSummary.manual.length > 0 && (messages2.push(import_picocolors14.default.bold("Manual migrations:")), messages2.push(
|
|
7746
8157
|
fixSummary.manual.map(
|
|
7747
|
-
(m) => fixResults[m] === "manual_succeeded" /* MANUAL_SUCCEEDED */ ?
|
|
8158
|
+
(m) => fixResults[m] === "manual_succeeded" /* MANUAL_SUCCEEDED */ ? import_picocolors14.default.green(m) : import_picocolors14.default.blue(m)
|
|
7748
8159
|
).join(", ")
|
|
7749
|
-
)), fixSummary.skipped.length > 0 && (messages2.push(
|
|
8160
|
+
)), fixSummary.skipped.length > 0 && (messages2.push(import_picocolors14.default.bold("Skipped migrations:")), messages2.push(fixSummary.skipped.map((m) => import_picocolors14.default.cyan(m)).join(", "))), messages2;
|
|
7750
8161
|
}
|
|
7751
8162
|
function logMigrationSummary({
|
|
7752
8163
|
fixResults,
|
|
7753
8164
|
fixSummary
|
|
7754
8165
|
}) {
|
|
7755
8166
|
let messages2 = [];
|
|
7756
|
-
messages2.push(getGlossaryMessages(fixSummary, fixResults).join(messageDivider2)), messages2.push(
|
|
7757
|
-
${
|
|
8167
|
+
messages2.push(getGlossaryMessages(fixSummary, fixResults).join(messageDivider2)), messages2.push(dedent14`If you'd like to run the migrations again, you can do so by running
|
|
8168
|
+
${import_picocolors14.default.cyan("npx storybook automigrate")}
|
|
7758
8169
|
|
|
7759
8170
|
The automigrations try to migrate common patterns in your project, but might not contain everything needed to migrate to the latest version of Storybook.
|
|
7760
8171
|
|
|
@@ -7765,21 +8176,21 @@ function logMigrationSummary({
|
|
|
7765
8176
|
let hasNoFixes = Object.values(fixResults).every((r) => r === "unnecessary" /* UNNECESSARY */), hasFailures2 = Object.values(fixResults).some(
|
|
7766
8177
|
(r) => r === "failed" /* FAILED */ || r === "check_failed" /* CHECK_FAILED */
|
|
7767
8178
|
);
|
|
7768
|
-
hasNoFixes ?
|
|
8179
|
+
hasNoFixes ? logger17.warn("No migrations were applicable to your project") : hasFailures2 ? logger17.error("Migration check ran with failures") : logger17.step(CLI_COLORS2.success("Migration check ran successfully")), logger17.log(messages2.filter(Boolean).join(segmentDivider));
|
|
7769
8180
|
}
|
|
7770
8181
|
|
|
7771
8182
|
// src/automigrate/index.ts
|
|
7772
8183
|
var logAvailableMigrations = () => {
|
|
7773
|
-
let availableFixes = [...allFixes, ...commandFixes].map((f) =>
|
|
8184
|
+
let availableFixes = [...allFixes, ...commandFixes].map((f) => import_picocolors15.default.yellow(f.id)).map((x) => `- ${x}`).join(`
|
|
7774
8185
|
`);
|
|
7775
|
-
|
|
8186
|
+
logger18.log(dedent15`
|
|
7776
8187
|
The following migrations are available:
|
|
7777
8188
|
${availableFixes}
|
|
7778
8189
|
`);
|
|
7779
8190
|
}, hasFailures = (fixResults) => Object.values(fixResults || {}).some(
|
|
7780
8191
|
(r) => r === "failed" /* FAILED */ || r === "check_failed" /* CHECK_FAILED */
|
|
7781
8192
|
), doAutomigrate = async (options) => {
|
|
7782
|
-
|
|
8193
|
+
logger18.debug("Extracting storybook data...");
|
|
7783
8194
|
let {
|
|
7784
8195
|
mainConfig,
|
|
7785
8196
|
mainConfigPath,
|
|
@@ -7813,7 +8224,7 @@ var logAvailableMigrations = () => {
|
|
|
7813
8224
|
) && !options.skipInstall && await packageManager.installDependencies(), outcome && !options.skipDoctor && await doctor({ configDir, packageManager: options.packageManager }), hasFailures(outcome?.fixResults)) {
|
|
7814
8225
|
let failedMigrations = Object.entries(outcome?.fixResults ?? {}).filter(([, status]) => status === "failed" /* FAILED */ || status === "check_failed" /* CHECK_FAILED */).map(([id, status]) => {
|
|
7815
8226
|
let statusLabel = status === "check_failed" /* CHECK_FAILED */ ? "check failed" : "failed";
|
|
7816
|
-
return `${
|
|
8227
|
+
return `${import_picocolors15.default.cyan(id)} (${statusLabel})`;
|
|
7817
8228
|
});
|
|
7818
8229
|
throw new AutomigrateError({ errors: failedMigrations });
|
|
7819
8230
|
}
|
|
@@ -7842,7 +8253,7 @@ var logAvailableMigrations = () => {
|
|
|
7842
8253
|
return logAvailableMigrations(), null;
|
|
7843
8254
|
let commandFix = commandFixes.find((f) => f.id === fixId);
|
|
7844
8255
|
if (commandFix)
|
|
7845
|
-
return
|
|
8256
|
+
return logger18.step(`Running migration ${import_picocolors15.default.magenta(fixId)}..`), await commandFix.run({
|
|
7846
8257
|
mainConfigPath,
|
|
7847
8258
|
previewConfigPath,
|
|
7848
8259
|
packageManager,
|
|
@@ -7857,8 +8268,8 @@ var logAvailableMigrations = () => {
|
|
|
7857
8268
|
}), null;
|
|
7858
8269
|
let selectedFixes = inputFixes || allFixes.filter((fix) => !(fix.id === upgradeStorybookRelatedDependencies.id && isLatest === !1 && fixId !== upgradeStorybookRelatedDependencies.id)), fixes = fixId ? selectedFixes.filter((f) => f.id === fixId) : selectedFixes;
|
|
7859
8270
|
if (fixId && fixes.length === 0)
|
|
7860
|
-
return
|
|
7861
|
-
|
|
8271
|
+
return logger18.log(`\u{1F4ED} No migrations found for ${import_picocolors15.default.magenta(fixId)}.`), logAvailableMigrations(), null;
|
|
8272
|
+
logger18.step("Checking possible migrations..");
|
|
7862
8273
|
let { fixResults, fixSummary, preCheckFailure } = await runFixes({
|
|
7863
8274
|
fixes,
|
|
7864
8275
|
packageManager,
|
|
@@ -7899,7 +8310,7 @@ async function runFixes({
|
|
|
7899
8310
|
for (let i = 0; i < fixes.length; i += 1) {
|
|
7900
8311
|
let f = fixes[i], result;
|
|
7901
8312
|
try {
|
|
7902
|
-
|
|
8313
|
+
logger18.debug(`Running ${import_picocolors15.default.cyan(f.id)} migration checks`), result = await f.check({
|
|
7903
8314
|
packageManager,
|
|
7904
8315
|
configDir,
|
|
7905
8316
|
rendererPackage,
|
|
@@ -7909,14 +8320,14 @@ async function runFixes({
|
|
|
7909
8320
|
mainConfigPath,
|
|
7910
8321
|
storiesPaths,
|
|
7911
8322
|
hasCsfFactoryPreview
|
|
7912
|
-
}),
|
|
8323
|
+
}), logger18.debug(`End of ${import_picocolors15.default.cyan(f.id)} migration checks`);
|
|
7913
8324
|
} catch (error) {
|
|
7914
|
-
|
|
8325
|
+
logger18.warn(`\u26A0\uFE0F failed to check fix ${import_picocolors15.default.bold(f.id)}`), error instanceof Error && (logger18.error(`
|
|
7915
8326
|
${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "check_failed" /* CHECK_FAILED */;
|
|
7916
8327
|
}
|
|
7917
8328
|
if (result) {
|
|
7918
8329
|
let promptType = typeof f.promptType == "function" ? await f.promptType(result) : f.promptType ?? "auto";
|
|
7919
|
-
|
|
8330
|
+
logger18.log(`\u{1F50E} found a '${import_picocolors15.default.cyan(f.id)}' migration:`);
|
|
7920
8331
|
let getTitle = () => {
|
|
7921
8332
|
switch (promptType) {
|
|
7922
8333
|
case "auto":
|
|
@@ -7926,11 +8337,11 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7926
8337
|
case "notification":
|
|
7927
8338
|
return "Migration notification";
|
|
7928
8339
|
}
|
|
7929
|
-
}, currentTaskLogger =
|
|
8340
|
+
}, currentTaskLogger = prompt4.taskLog({
|
|
7930
8341
|
id: `automigrate-task-${f.id}`,
|
|
7931
|
-
title: `${getTitle()}: ${
|
|
8342
|
+
title: `${getTitle()}: ${import_picocolors15.default.cyan(f.id)}`
|
|
7932
8343
|
});
|
|
7933
|
-
|
|
8344
|
+
logger18.logBox(f.prompt());
|
|
7934
8345
|
let runAnswer;
|
|
7935
8346
|
try {
|
|
7936
8347
|
if (dryRun)
|
|
@@ -7938,7 +8349,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7938
8349
|
else if (yes)
|
|
7939
8350
|
runAnswer = { fix: !0 }, promptType === "manual" && (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id));
|
|
7940
8351
|
else if (promptType === "manual") {
|
|
7941
|
-
if (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id), !await
|
|
8352
|
+
if (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id), !await prompt4.confirm(
|
|
7942
8353
|
{
|
|
7943
8354
|
message: "Select continue once you have made the required changes, or quit to exit the migration process",
|
|
7944
8355
|
initialValue: !0,
|
|
@@ -7954,9 +8365,9 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7954
8365
|
fixResults[f.id] = "manual_skipped" /* MANUAL_SKIPPED */;
|
|
7955
8366
|
break;
|
|
7956
8367
|
}
|
|
7957
|
-
} else promptType === "auto" ? runAnswer = { fix: yes ? !0 : await
|
|
8368
|
+
} else promptType === "auto" ? runAnswer = { fix: yes ? !0 : await prompt4.confirm(
|
|
7958
8369
|
{
|
|
7959
|
-
message: `Do you want to run the '${
|
|
8370
|
+
message: `Do you want to run the '${import_picocolors15.default.cyan(f.id)}' migration on your project?`,
|
|
7960
8371
|
initialValue: f.defaultSelected ?? !0
|
|
7961
8372
|
},
|
|
7962
8373
|
{
|
|
@@ -7964,7 +8375,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7964
8375
|
throw new Error();
|
|
7965
8376
|
}
|
|
7966
8377
|
}
|
|
7967
|
-
) } : promptType === "notification" && (runAnswer = { fix: await
|
|
8378
|
+
) } : promptType === "notification" && (runAnswer = { fix: await prompt4.confirm(
|
|
7968
8379
|
{
|
|
7969
8380
|
message: "Do you want to continue?"
|
|
7970
8381
|
},
|
|
@@ -7992,14 +8403,14 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7992
8403
|
storybookVersion,
|
|
7993
8404
|
storiesPaths,
|
|
7994
8405
|
yes
|
|
7995
|
-
}),
|
|
8406
|
+
}), logger18.log(`\u2705 ran ${import_picocolors15.default.cyan(f.id)} migration`), fixResults[f.id] = "succeeded" /* SUCCEEDED */, fixSummary.succeeded.push(f.id), currentTaskLogger.success(`Ran ${import_picocolors15.default.cyan(f.id)} migration`);
|
|
7996
8407
|
} catch (error) {
|
|
7997
8408
|
fixResults[f.id] = "failed" /* FAILED */;
|
|
7998
8409
|
let errorMessage = error instanceof Error ? error.message : "Failed to run migration";
|
|
7999
|
-
fixSummary.failed[f.id] = errorMessage, currentTaskLogger.error(`Error when running ${
|
|
8410
|
+
fixSummary.failed[f.id] = errorMessage, currentTaskLogger.error(`Error when running ${import_picocolors15.default.cyan(f.id)} migration`);
|
|
8000
8411
|
}
|
|
8001
8412
|
else
|
|
8002
|
-
fixResults[f.id] = "skipped" /* SKIPPED */, fixSummary.skipped.push(f.id), currentTaskLogger.success(`Skipped ${
|
|
8413
|
+
fixResults[f.id] = "skipped" /* SKIPPED */, fixSummary.skipped.push(f.id), currentTaskLogger.success(`Skipped ${import_picocolors15.default.cyan(f.id)} migration`);
|
|
8003
8414
|
} else
|
|
8004
8415
|
fixResults[f.id] = fixResults[f.id] || "unnecessary" /* UNNECESSARY */;
|
|
8005
8416
|
}
|
|
@@ -8008,26 +8419,26 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
8008
8419
|
|
|
8009
8420
|
// src/link.ts
|
|
8010
8421
|
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
8011
|
-
import { mkdir, readFile as
|
|
8012
|
-
import { basename as
|
|
8422
|
+
import { mkdir, readFile as readFile10, writeFile as writeFile9 } from "node:fs/promises";
|
|
8423
|
+
import { basename as basename3, extname as extname2, join as join4 } from "node:path";
|
|
8013
8424
|
import { executeCommand } from "storybook/internal/common";
|
|
8014
|
-
import { logger as
|
|
8425
|
+
import { logger as logger19 } from "storybook/internal/node-logger";
|
|
8015
8426
|
var link = async ({ target, local, start }) => {
|
|
8016
8427
|
let storybookDir = process.cwd();
|
|
8017
8428
|
try {
|
|
8018
|
-
if (JSON.parse(await
|
|
8429
|
+
if (JSON.parse(await readFile10("package.json", { encoding: "utf8" })).name !== "@storybook/code")
|
|
8019
8430
|
throw new Error();
|
|
8020
8431
|
} catch {
|
|
8021
8432
|
throw new Error("Expected to run link from the root of the storybook monorepo");
|
|
8022
8433
|
}
|
|
8023
|
-
let reproDir = target, reproName =
|
|
8434
|
+
let reproDir = target, reproName = basename3(target);
|
|
8024
8435
|
if (!local) {
|
|
8025
|
-
let reprosDir =
|
|
8026
|
-
|
|
8436
|
+
let reprosDir = join4(storybookDir, "../storybook-repros");
|
|
8437
|
+
logger19.info(`Ensuring directory ${reprosDir}`), await mkdir(reprosDir, { recursive: !0 }), logger19.info(`Cloning ${target}`), await executeCommand({
|
|
8027
8438
|
command: "git",
|
|
8028
8439
|
args: ["clone", target],
|
|
8029
8440
|
cwd: reprosDir
|
|
8030
|
-
}), reproName =
|
|
8441
|
+
}), reproName = basename3(target, extname2(target)), reproDir = join4(reprosDir, reproName);
|
|
8031
8442
|
}
|
|
8032
8443
|
let version2 = (0, import_cross_spawn.sync)("yarn", ["--version"], {
|
|
8033
8444
|
cwd: reproDir,
|
|
@@ -8035,16 +8446,16 @@ var link = async ({ target, local, start }) => {
|
|
|
8035
8446
|
shell: !0
|
|
8036
8447
|
}).stdout.toString();
|
|
8037
8448
|
if (!/^[2-4]\./.test(version2)) {
|
|
8038
|
-
|
|
8449
|
+
logger19.warn(`\u{1F6A8} Expected yarn 2 or higher in ${reproDir}!`), logger19.warn(""), logger19.warn("Please set it up with `yarn set version berry`,"), logger19.warn(`then link '${reproDir}' with the '--local' flag.`);
|
|
8039
8450
|
return;
|
|
8040
8451
|
}
|
|
8041
|
-
|
|
8452
|
+
logger19.info(`Linking ${reproDir}`), await executeCommand({
|
|
8042
8453
|
command: "yarn",
|
|
8043
8454
|
args: ["link", "--all", "--relative", storybookDir],
|
|
8044
8455
|
cwd: reproDir
|
|
8045
|
-
}),
|
|
8456
|
+
}), logger19.info(`Installing ${reproName}`);
|
|
8046
8457
|
let reproPackageJson = JSON.parse(
|
|
8047
|
-
await
|
|
8458
|
+
await readFile10(join4(reproDir, "package.json"), { encoding: "utf8" })
|
|
8048
8459
|
);
|
|
8049
8460
|
reproPackageJson.devDependencies?.vite || (reproPackageJson.devDependencies = {
|
|
8050
8461
|
...reproPackageJson.devDependencies,
|
|
@@ -8052,11 +8463,11 @@ var link = async ({ target, local, start }) => {
|
|
|
8052
8463
|
}), reproPackageJson.devDependencies = {
|
|
8053
8464
|
...reproPackageJson.devDependencies,
|
|
8054
8465
|
"@types/node": "^22"
|
|
8055
|
-
}, await
|
|
8466
|
+
}, await writeFile9(join4(reproDir, "package.json"), JSON.stringify(reproPackageJson, null, 2)), await executeCommand({
|
|
8056
8467
|
command: "yarn",
|
|
8057
8468
|
args: ["install"],
|
|
8058
8469
|
cwd: reproDir
|
|
8059
|
-
}), start && (
|
|
8470
|
+
}), start && (logger19.info(`Running ${reproName} storybook`), await executeCommand({
|
|
8060
8471
|
command: "yarn",
|
|
8061
8472
|
args: ["run", "storybook"],
|
|
8062
8473
|
cwd: reproDir
|
|
@@ -8064,22 +8475,22 @@ var link = async ({ target, local, start }) => {
|
|
|
8064
8475
|
};
|
|
8065
8476
|
|
|
8066
8477
|
// src/migrate.ts
|
|
8067
|
-
import { logger as
|
|
8478
|
+
import { logger as logger20 } from "storybook/internal/node-logger";
|
|
8068
8479
|
import { listCodemods, runCodemod as runCodemod2 } from "@storybook/codemod";
|
|
8069
8480
|
async function migrate(migration, { glob, dryRun, list, rename: rename2, parser }) {
|
|
8070
8481
|
if (list)
|
|
8071
|
-
listCodemods().forEach((key) =>
|
|
8482
|
+
listCodemods().forEach((key) => logger20.log(key));
|
|
8072
8483
|
else if (migration)
|
|
8073
|
-
await runCodemod2(migration, { glob, dryRun, logger:
|
|
8484
|
+
await runCodemod2(migration, { glob, dryRun, logger: logger20, rename: rename2, parser });
|
|
8074
8485
|
else
|
|
8075
8486
|
throw new Error("Migrate: please specify a migration name or --list");
|
|
8076
8487
|
}
|
|
8077
8488
|
|
|
8078
8489
|
// src/sandbox.ts
|
|
8079
8490
|
var import_cross_spawn2 = __toESM(require_cross_spawn(), 1);
|
|
8080
|
-
import { existsSync as
|
|
8491
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
8081
8492
|
import { mkdir as mkdir2, readdir, rm } from "node:fs/promises";
|
|
8082
|
-
import { isAbsolute as
|
|
8493
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
8083
8494
|
import { PackageManagerName } from "storybook/internal/common";
|
|
8084
8495
|
import {
|
|
8085
8496
|
JsPackageManagerFactory,
|
|
@@ -8087,9 +8498,9 @@ import {
|
|
|
8087
8498
|
optionalEnvToBoolean as optionalEnvToBoolean2,
|
|
8088
8499
|
versions as versions4
|
|
8089
8500
|
} from "storybook/internal/common";
|
|
8090
|
-
import { logger as
|
|
8091
|
-
var
|
|
8092
|
-
import { dedent as
|
|
8501
|
+
import { logger as logger21, prompt as prompt5 } from "storybook/internal/node-logger";
|
|
8502
|
+
var import_picocolors16 = __toESM(require_picocolors(), 1), import_semver6 = __toESM(require_semver(), 1);
|
|
8503
|
+
import { dedent as dedent16 } from "ts-dedent";
|
|
8093
8504
|
|
|
8094
8505
|
// src/sandbox-templates.ts
|
|
8095
8506
|
var baseTemplates = {
|
|
@@ -8204,7 +8615,8 @@ var baseTemplates = {
|
|
|
8204
8615
|
features: {
|
|
8205
8616
|
experimentalRSC: !0,
|
|
8206
8617
|
developmentModeForBuild: !0,
|
|
8207
|
-
experimentalTestSyntax: !0
|
|
8618
|
+
experimentalTestSyntax: !0,
|
|
8619
|
+
changeDetection: !0
|
|
8208
8620
|
}
|
|
8209
8621
|
},
|
|
8210
8622
|
extraDependencies: ["server-only", "prop-types"]
|
|
@@ -8297,7 +8709,8 @@ var baseTemplates = {
|
|
|
8297
8709
|
features: {
|
|
8298
8710
|
experimentalRSC: !0,
|
|
8299
8711
|
developmentModeForBuild: !0,
|
|
8300
|
-
experimentalTestSyntax: !0
|
|
8712
|
+
experimentalTestSyntax: !0,
|
|
8713
|
+
changeDetection: !0
|
|
8301
8714
|
}
|
|
8302
8715
|
},
|
|
8303
8716
|
extraDependencies: ["server-only", "vite", "prop-types"]
|
|
@@ -8339,7 +8752,8 @@ var baseTemplates = {
|
|
|
8339
8752
|
mainConfig: {
|
|
8340
8753
|
features: {
|
|
8341
8754
|
developmentModeForBuild: !0,
|
|
8342
|
-
experimentalTestSyntax: !0
|
|
8755
|
+
experimentalTestSyntax: !0,
|
|
8756
|
+
changeDetection: !0
|
|
8343
8757
|
}
|
|
8344
8758
|
}
|
|
8345
8759
|
},
|
|
@@ -8470,6 +8884,46 @@ var baseTemplates = {
|
|
|
8470
8884
|
},
|
|
8471
8885
|
skipTasks: ["e2e-tests", "e2e-tests-dev", "bench", "vitest-integration"]
|
|
8472
8886
|
},
|
|
8887
|
+
"tanstack-react-router/default-ts": {
|
|
8888
|
+
name: "TanStack React Router Latest (Vite | TypeScript)",
|
|
8889
|
+
script: "npx @tanstack/cli@latest create {{beforeDir}} --tailwind --router-only",
|
|
8890
|
+
expected: {
|
|
8891
|
+
framework: "@storybook/tanstack-react",
|
|
8892
|
+
renderer: "@storybook/react",
|
|
8893
|
+
builder: "@storybook/builder-vite"
|
|
8894
|
+
},
|
|
8895
|
+
modifications: {
|
|
8896
|
+
useCsfFactory: !0,
|
|
8897
|
+
extraDependencies: ["prop-types"],
|
|
8898
|
+
mainConfig: {
|
|
8899
|
+
framework: "@storybook/tanstack-react",
|
|
8900
|
+
features: {
|
|
8901
|
+
experimentalTestSyntax: !0
|
|
8902
|
+
}
|
|
8903
|
+
}
|
|
8904
|
+
},
|
|
8905
|
+
skipTasks: ["bench"]
|
|
8906
|
+
},
|
|
8907
|
+
"tanstack-react-start/default-ts": {
|
|
8908
|
+
name: "TanStack React Start Latest (Vite | TypeScript)",
|
|
8909
|
+
script: "npx @tanstack/cli@latest create {{beforeDir}} --tailwind",
|
|
8910
|
+
expected: {
|
|
8911
|
+
framework: "@storybook/tanstack-react",
|
|
8912
|
+
renderer: "@storybook/react",
|
|
8913
|
+
builder: "@storybook/builder-vite"
|
|
8914
|
+
},
|
|
8915
|
+
modifications: {
|
|
8916
|
+
useCsfFactory: !0,
|
|
8917
|
+
extraDependencies: ["prop-types"],
|
|
8918
|
+
mainConfig: {
|
|
8919
|
+
framework: "@storybook/tanstack-react",
|
|
8920
|
+
features: {
|
|
8921
|
+
experimentalTestSyntax: !0
|
|
8922
|
+
}
|
|
8923
|
+
}
|
|
8924
|
+
},
|
|
8925
|
+
skipTasks: ["bench"]
|
|
8926
|
+
},
|
|
8473
8927
|
"vue3-vite/default-js": {
|
|
8474
8928
|
name: "Vue v3 (Vite | JavaScript)",
|
|
8475
8929
|
script: "npm create vite --yes {{beforeDir}} -- --template vue",
|
|
@@ -8953,7 +9407,9 @@ var baseTemplates = {
|
|
|
8953
9407
|
"bench/react-vite-default-ts-test-build",
|
|
8954
9408
|
"bench/react-webpack-18-ts-test-build",
|
|
8955
9409
|
// 'ember/default-js',
|
|
8956
|
-
"react-rsbuild/default-ts"
|
|
9410
|
+
"react-rsbuild/default-ts",
|
|
9411
|
+
"tanstack-react-router/default-ts",
|
|
9412
|
+
"tanstack-react-start/default-ts"
|
|
8957
9413
|
], merged = [
|
|
8958
9414
|
...normal,
|
|
8959
9415
|
"react-webpack/18-ts",
|
|
@@ -8999,20 +9455,20 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
8999
9455
|
let selectedConfig = allTemplates[filterValue], templateId = selectedConfig ? filterValue : null, packageManager = JsPackageManagerFactory.getPackageManager({
|
|
9000
9456
|
force: PackageManagerName.NPM
|
|
9001
9457
|
}), latestVersion = await packageManager.latestVersion("storybook"), nextVersion = await packageManager.latestVersion("storybook@next") ?? "0.0.0", currentVersion = versions4.storybook, isPrerelease = (0, import_semver6.prerelease)(currentVersion), isOutdated = (0, import_semver6.lt)(currentVersion, isPrerelease ? nextVersion : latestVersion), downloadType = !isOutdated && init ? "after-storybook" : "before-storybook", branch = isPrerelease ? "next" : "main", messages2 = {
|
|
9002
|
-
welcome: `Creating a Storybook ${
|
|
9003
|
-
notLatest:
|
|
9004
|
-
This version is behind the latest release, which is: ${
|
|
9458
|
+
welcome: `Creating a Storybook ${import_picocolors16.default.bold(currentVersion)} sandbox..`,
|
|
9459
|
+
notLatest: import_picocolors16.default.red(dedent16`
|
|
9460
|
+
This version is behind the latest release, which is: ${import_picocolors16.default.bold(latestVersion)}!
|
|
9005
9461
|
You likely ran the init command through npx, which can use a locally cached version, to get the latest please run:
|
|
9006
|
-
${
|
|
9462
|
+
${import_picocolors16.default.bold("npx storybook@latest sandbox")}
|
|
9007
9463
|
|
|
9008
9464
|
You may want to CTRL+C to stop, and run with the latest version instead.
|
|
9009
9465
|
`),
|
|
9010
|
-
longInitTime:
|
|
9466
|
+
longInitTime: import_picocolors16.default.yellow(
|
|
9011
9467
|
"The creation of the sandbox will take longer, because we will need to run init."
|
|
9012
9468
|
),
|
|
9013
|
-
prerelease:
|
|
9469
|
+
prerelease: import_picocolors16.default.yellow("This is a pre-release version.")
|
|
9014
9470
|
};
|
|
9015
|
-
if (
|
|
9471
|
+
if (logger21.logBox(
|
|
9016
9472
|
[messages2.welcome].concat(isOutdated && !isPrerelease ? [messages2.notLatest] : []).concat(init && (isOutdated || isPrerelease) ? [messages2.longInitTime] : []).concat(isPrerelease ? [messages2.prerelease] : []).join(`
|
|
9017
9473
|
`),
|
|
9018
9474
|
{
|
|
@@ -9023,24 +9479,24 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
9023
9479
|
let current = allTemplates[group];
|
|
9024
9480
|
return (!filterValue || current.name.match(filterRegex) || group.match(filterRegex) || current.expected.builder.match(filterRegex) || current.expected.framework.match(filterRegex) || current.expected.renderer.match(filterRegex)) && acc.push(group), acc;
|
|
9025
9481
|
}, []);
|
|
9026
|
-
if (choices.length === 0 && (
|
|
9027
|
-
|
|
9482
|
+
if (choices.length === 0 && (logger21.logBox(
|
|
9483
|
+
dedent16`
|
|
9028
9484
|
🔎 You filtered out all templates. 🔍
|
|
9029
9485
|
|
|
9030
|
-
After filtering all the templates with "${
|
|
9486
|
+
After filtering all the templates with "${import_picocolors16.default.yellow(
|
|
9031
9487
|
filterValue
|
|
9032
9488
|
)}", we found no results. Please try again with a different filter.
|
|
9033
9489
|
|
|
9034
9490
|
Available templates:
|
|
9035
|
-
${keys.map((key) =>
|
|
9491
|
+
${keys.map((key) => import_picocolors16.default.blue(`- ${key}`)).join(`
|
|
9036
9492
|
`)}
|
|
9037
9493
|
`.trim(),
|
|
9038
9494
|
{ borderStyle: "round", padding: 1, borderColor: "#F1618C" }
|
|
9039
|
-
), process.exit(1)), choices.length === 1 ? [templateId] = choices : (
|
|
9040
|
-
|
|
9041
|
-
🤗 Welcome to ${
|
|
9495
|
+
), process.exit(1)), choices.length === 1 ? [templateId] = choices : (logger21.logBox(
|
|
9496
|
+
dedent16`
|
|
9497
|
+
🤗 Welcome to ${import_picocolors16.default.yellow("sb sandbox")}! 🤗
|
|
9042
9498
|
|
|
9043
|
-
Create a ${
|
|
9499
|
+
Create a ${import_picocolors16.default.green("new project")} to minimally reproduce Storybook issues.
|
|
9044
9500
|
|
|
9045
9501
|
1. select an environment that most closely matches your project setup.
|
|
9046
9502
|
2. select a location for the reproduction, outside of your project.
|
|
@@ -9049,36 +9505,36 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
9049
9505
|
`.trim(),
|
|
9050
9506
|
{ borderStyle: "round", padding: 1, borderColor: "#F1618C" }
|
|
9051
9507
|
), templateId = await promptSelectedTemplate(choices)), !!!(templateId ?? null)) {
|
|
9052
|
-
|
|
9508
|
+
logger21.error("Somehow we got no templates. Please rerun this command!");
|
|
9053
9509
|
return;
|
|
9054
9510
|
}
|
|
9055
9511
|
if (selectedConfig = templateId ? allTemplates[templateId] : void 0, !selectedConfig)
|
|
9056
9512
|
throw new Error("\u{1F6A8} Sandbox: please specify a valid template type");
|
|
9057
9513
|
}
|
|
9058
9514
|
let selectedDirectory = outputDirectory, outputDirectoryName = outputDirectory || templateId;
|
|
9059
|
-
selectedDirectory &&
|
|
9515
|
+
selectedDirectory && existsSync4(`${selectedDirectory}`) && (logger21.log(`\u26A0\uFE0F ${selectedDirectory} already exists! Overwriting...`), await rm(selectedDirectory, { recursive: !0, force: !0 })), selectedDirectory || (selectedDirectory = await prompt5.text(
|
|
9060
9516
|
{
|
|
9061
9517
|
message: "Enter the output directory",
|
|
9062
9518
|
initialValue: outputDirectoryName ?? void 0,
|
|
9063
|
-
validate: (directoryName) => directoryName &&
|
|
9519
|
+
validate: (directoryName) => directoryName && existsSync4(directoryName) ? `${directoryName} already exists. Please choose another name.` : void 0
|
|
9064
9520
|
},
|
|
9065
9521
|
{
|
|
9066
9522
|
onCancel: () => {
|
|
9067
|
-
|
|
9523
|
+
logger21.log("Command cancelled by the user. Exiting..."), process.exit(1);
|
|
9068
9524
|
}
|
|
9069
9525
|
}
|
|
9070
9526
|
)), invariant(selectedDirectory);
|
|
9071
9527
|
try {
|
|
9072
|
-
let templateDestination =
|
|
9073
|
-
|
|
9528
|
+
let templateDestination = isAbsolute3(selectedDirectory) ? selectedDirectory : join(process.cwd(), selectedDirectory);
|
|
9529
|
+
logger21.log(`\u{1F3C3} Adding ${selectedConfig.name} into ${templateDestination}`), logger21.log(`\u{1F4E6} Downloading sandbox template (${import_picocolors16.default.bold(downloadType)})...`);
|
|
9074
9530
|
try {
|
|
9075
9531
|
let gitPath = `storybookjs/sandboxes/tree/${branch}/${templateId}/${downloadType}`;
|
|
9076
9532
|
if (await mkdir2(templateDestination, { recursive: !0 }), (0, import_cross_spawn2.sync)("npx", ["gitpick@4.12.4", gitPath, templateDestination, "-o"], {
|
|
9077
9533
|
stdio: "inherit"
|
|
9078
9534
|
}), (await readdir(templateDestination)).length === 0) {
|
|
9079
|
-
let selected =
|
|
9080
|
-
throw new Error(
|
|
9081
|
-
Template downloaded from ${
|
|
9535
|
+
let selected = import_picocolors16.default.yellow(templateId);
|
|
9536
|
+
throw new Error(dedent16`
|
|
9537
|
+
Template downloaded from ${import_picocolors16.default.blue(gitPath)} is empty.
|
|
9082
9538
|
Are you use it exists? Or did you want to set ${selected} to inDevelopment first?
|
|
9083
9539
|
`);
|
|
9084
9540
|
}
|
|
@@ -9094,22 +9550,22 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
9094
9550
|
}), process.chdir(before);
|
|
9095
9551
|
}
|
|
9096
9552
|
} catch (err) {
|
|
9097
|
-
throw
|
|
9553
|
+
throw logger21.error(`\u{1F6A8} Failed to download sandbox template: ${String(err)}`), err;
|
|
9098
9554
|
}
|
|
9099
|
-
let initMessage = init ?
|
|
9555
|
+
let initMessage = init ? import_picocolors16.default.yellow(dedent16`
|
|
9100
9556
|
yarn install
|
|
9101
9557
|
yarn storybook
|
|
9102
|
-
`) : `Recreate your setup, then ${
|
|
9103
|
-
|
|
9104
|
-
|
|
9558
|
+
`) : `Recreate your setup, then ${import_picocolors16.default.yellow("npx storybook@latest init")}`;
|
|
9559
|
+
logger21.logBox(
|
|
9560
|
+
dedent16`
|
|
9105
9561
|
🎉 Your Storybook reproduction project is ready to use! 🎉
|
|
9106
9562
|
|
|
9107
|
-
${
|
|
9563
|
+
${import_picocolors16.default.yellow(`cd ${selectedDirectory}`)}
|
|
9108
9564
|
${initMessage}
|
|
9109
9565
|
|
|
9110
9566
|
Once you've recreated the problem you're experiencing, please:
|
|
9111
9567
|
|
|
9112
|
-
1. Document any additional steps in ${
|
|
9568
|
+
1. Document any additional steps in ${import_picocolors16.default.cyan("README.md")}
|
|
9113
9569
|
2. Publish the repository to github
|
|
9114
9570
|
3. Link to the repro repository in your issue
|
|
9115
9571
|
|
|
@@ -9118,40 +9574,416 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
9118
9574
|
{ rounded: !0 }
|
|
9119
9575
|
);
|
|
9120
9576
|
} catch (error) {
|
|
9121
|
-
throw
|
|
9577
|
+
throw logger21.error("\u{1F6A8} Failed to create sandbox"), error;
|
|
9122
9578
|
}
|
|
9123
9579
|
};
|
|
9124
9580
|
async function promptSelectedTemplate(choices) {
|
|
9125
|
-
return await
|
|
9581
|
+
return await prompt5.select({
|
|
9126
9582
|
message: "Select a template",
|
|
9127
9583
|
options: choices.map(toChoices)
|
|
9128
9584
|
});
|
|
9129
9585
|
}
|
|
9130
9586
|
|
|
9587
|
+
// src/ai/index.ts
|
|
9588
|
+
import { writeFile as writeFile10 } from "node:fs/promises";
|
|
9589
|
+
import { resolve as resolve4 } from "node:path";
|
|
9590
|
+
import { cache, getPrettyPackageManagerName } from "storybook/internal/common";
|
|
9591
|
+
import { logger as logger23 } from "storybook/internal/node-logger";
|
|
9592
|
+
import { telemetry } from "storybook/internal/telemetry";
|
|
9593
|
+
import { SupportedLanguage as SupportedLanguage2 } from "storybook/internal/types";
|
|
9594
|
+
|
|
9595
|
+
// ../create-storybook/src/services/ProjectTypeService.ts
|
|
9596
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
9597
|
+
import { resolve as resolve3 } from "node:path";
|
|
9598
|
+
import { ProjectType as ProjectType2 } from "storybook/internal/cli";
|
|
9599
|
+
import { HandledError, getProjectRoot } from "storybook/internal/common";
|
|
9600
|
+
import { logger as logger22 } from "storybook/internal/node-logger";
|
|
9601
|
+
import { NxProjectDetectedError } from "storybook/internal/server-errors";
|
|
9602
|
+
import { SupportedLanguage } from "storybook/internal/types";
|
|
9603
|
+
|
|
9604
|
+
// ../../../node_modules/empathic/find.mjs
|
|
9605
|
+
import { join as join5 } from "node:path";
|
|
9606
|
+
import { existsSync as existsSync5, statSync } from "node:fs";
|
|
9607
|
+
function up2(name, options) {
|
|
9608
|
+
let dir, tmp, start = options && options.cwd || "";
|
|
9609
|
+
for (dir of up(start, options))
|
|
9610
|
+
if (tmp = join5(dir, name), existsSync5(tmp)) return tmp;
|
|
9611
|
+
}
|
|
9612
|
+
|
|
9613
|
+
// ../create-storybook/src/services/ProjectTypeService.ts
|
|
9614
|
+
var import_semver7 = __toESM(require_semver(), 1);
|
|
9615
|
+
import { dedent as dedent17 } from "ts-dedent";
|
|
9616
|
+
var ProjectTypeService = class {
|
|
9617
|
+
constructor(jsPackageManager) {
|
|
9618
|
+
this.jsPackageManager = jsPackageManager;
|
|
9619
|
+
}
|
|
9620
|
+
/** Sorted configuration to match a Storybook preset template */
|
|
9621
|
+
getSupportedTemplates() {
|
|
9622
|
+
return [
|
|
9623
|
+
{
|
|
9624
|
+
preset: ProjectType2.NUXT,
|
|
9625
|
+
dependencies: ["nuxt"],
|
|
9626
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9627
|
+
},
|
|
9628
|
+
{
|
|
9629
|
+
preset: ProjectType2.TANSTACK_REACT,
|
|
9630
|
+
dependencies: ["@tanstack/start", "@tanstack/react-start", "@tanstack/react-router"],
|
|
9631
|
+
matcherFunction: ({ dependencies }) => dependencies?.some(Boolean) ?? !1
|
|
9632
|
+
},
|
|
9633
|
+
{
|
|
9634
|
+
preset: ProjectType2.VUE3,
|
|
9635
|
+
dependencies: {
|
|
9636
|
+
// This Vue template works with Vue 3
|
|
9637
|
+
vue: (versionRange) => versionRange === "next" || this.eqMajor(versionRange, 3)
|
|
9638
|
+
},
|
|
9639
|
+
matcherFunction: ({ dependencies }) => dependencies?.some(Boolean) ?? !1
|
|
9640
|
+
},
|
|
9641
|
+
{
|
|
9642
|
+
preset: ProjectType2.EMBER,
|
|
9643
|
+
dependencies: ["ember-cli"],
|
|
9644
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9645
|
+
},
|
|
9646
|
+
{
|
|
9647
|
+
preset: ProjectType2.NEXTJS,
|
|
9648
|
+
dependencies: ["next"],
|
|
9649
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9650
|
+
},
|
|
9651
|
+
{
|
|
9652
|
+
preset: ProjectType2.QWIK,
|
|
9653
|
+
dependencies: ["@builder.io/qwik"],
|
|
9654
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9655
|
+
},
|
|
9656
|
+
{
|
|
9657
|
+
preset: ProjectType2.REACT_NATIVE,
|
|
9658
|
+
dependencies: ["react-native", "react-native-scripts", "expo"],
|
|
9659
|
+
matcherFunction: ({ dependencies }) => dependencies?.some(Boolean) ?? !1
|
|
9660
|
+
},
|
|
9661
|
+
{
|
|
9662
|
+
preset: ProjectType2.REACT_SCRIPTS,
|
|
9663
|
+
// For projects using a custom/forked `react-scripts` package.
|
|
9664
|
+
files: ["/node_modules/.bin/react-scripts"],
|
|
9665
|
+
// For standard CRA projects
|
|
9666
|
+
dependencies: ["react-scripts"],
|
|
9667
|
+
matcherFunction: ({ dependencies, files }) => (dependencies?.every(Boolean) || files?.every(Boolean)) ?? !1
|
|
9668
|
+
},
|
|
9669
|
+
{
|
|
9670
|
+
preset: ProjectType2.ANGULAR,
|
|
9671
|
+
dependencies: ["@angular/core"],
|
|
9672
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9673
|
+
},
|
|
9674
|
+
{
|
|
9675
|
+
preset: ProjectType2.WEB_COMPONENTS,
|
|
9676
|
+
dependencies: ["lit-element", "lit-html", "lit"],
|
|
9677
|
+
matcherFunction: ({ dependencies }) => dependencies?.some(Boolean) ?? !1
|
|
9678
|
+
},
|
|
9679
|
+
{
|
|
9680
|
+
preset: ProjectType2.PREACT,
|
|
9681
|
+
dependencies: ["preact"],
|
|
9682
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9683
|
+
},
|
|
9684
|
+
{
|
|
9685
|
+
// TODO: This only works because it is before the SVELTE template. could be more explicit
|
|
9686
|
+
preset: ProjectType2.SVELTEKIT,
|
|
9687
|
+
dependencies: ["@sveltejs/kit"],
|
|
9688
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9689
|
+
},
|
|
9690
|
+
{
|
|
9691
|
+
preset: ProjectType2.SVELTE,
|
|
9692
|
+
dependencies: ["svelte"],
|
|
9693
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9694
|
+
},
|
|
9695
|
+
{
|
|
9696
|
+
preset: ProjectType2.SOLID,
|
|
9697
|
+
dependencies: ["solid-js"],
|
|
9698
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9699
|
+
},
|
|
9700
|
+
// DO NOT MOVE ANY TEMPLATES BELOW THIS LINE
|
|
9701
|
+
// React is part of every Template, after Storybook is initialized once
|
|
9702
|
+
{
|
|
9703
|
+
preset: ProjectType2.REACT,
|
|
9704
|
+
dependencies: ["react"],
|
|
9705
|
+
matcherFunction: ({ dependencies }) => dependencies?.every(Boolean) ?? !0
|
|
9706
|
+
}
|
|
9707
|
+
];
|
|
9708
|
+
}
|
|
9709
|
+
isStorybookInstantiated(configDir = resolve3(process.cwd(), ".storybook")) {
|
|
9710
|
+
return existsSync6(configDir);
|
|
9711
|
+
}
|
|
9712
|
+
async validateProvidedType(projectTypeProvided) {
|
|
9713
|
+
if (Object.values(ProjectType2).filter(
|
|
9714
|
+
(t10) => !["undetected", "unsupported", "nx"].includes(String(t10))
|
|
9715
|
+
).includes(projectTypeProvided))
|
|
9716
|
+
return projectTypeProvided;
|
|
9717
|
+
throw logger22.error(
|
|
9718
|
+
`The provided project type ${projectTypeProvided} was not recognized by Storybook`
|
|
9719
|
+
), new HandledError(`Unknown project type supplied: ${projectTypeProvided}`);
|
|
9720
|
+
}
|
|
9721
|
+
async autoDetectProjectType(options) {
|
|
9722
|
+
try {
|
|
9723
|
+
let detectedType = await this.detectProjectType(options);
|
|
9724
|
+
if (detectedType === ProjectType2.UNDETECTED || detectedType === null)
|
|
9725
|
+
throw logger22.error(dedent17`
|
|
9726
|
+
Unable to initialize Storybook in this directory.
|
|
9727
|
+
|
|
9728
|
+
Storybook couldn't detect a supported framework or configuration for your project. Make sure you're inside a framework project (e.g., React, Vue, Svelte, Angular, Next.js) and that its dependencies are installed.
|
|
9729
|
+
|
|
9730
|
+
Tips:
|
|
9731
|
+
- Run init in an empty directory or create a new framework app first.
|
|
9732
|
+
- If this directory contains unrelated files, try a new directory for Storybook.
|
|
9733
|
+
`), new HandledError("Storybook failed to detect your project type");
|
|
9734
|
+
if (detectedType === ProjectType2.NX)
|
|
9735
|
+
throw new NxProjectDetectedError();
|
|
9736
|
+
return detectedType;
|
|
9737
|
+
} catch (err) {
|
|
9738
|
+
throw err instanceof HandledError || err instanceof NxProjectDetectedError ? err : (logger22.error(String(err)), new HandledError(err instanceof Error ? err.message : String(err)));
|
|
9739
|
+
}
|
|
9740
|
+
}
|
|
9741
|
+
async detectLanguage() {
|
|
9742
|
+
let language = SupportedLanguage.JAVASCRIPT;
|
|
9743
|
+
return existsSync6("jsconfig.json") || (!!this.jsPackageManager.getAllDependencies().typescript ? (await this.detectIncompatiblePackageVersions()).length === 0 && (language = SupportedLanguage.TYPESCRIPT) : existsSync6("tsconfig.json") && (language = SupportedLanguage.TYPESCRIPT)), language;
|
|
9744
|
+
}
|
|
9745
|
+
/** Check installed tooling versions for TypeScript compatibility constraints */
|
|
9746
|
+
async detectIncompatiblePackageVersions() {
|
|
9747
|
+
let getModulePackageJSONVersion = async (pkg) => (await this.jsPackageManager.getModulePackageJSON(pkg))?.version ?? null, [
|
|
9748
|
+
typescriptVersion,
|
|
9749
|
+
prettierVersion,
|
|
9750
|
+
babelPluginTransformTypescriptVersion,
|
|
9751
|
+
typescriptEslintParserVersion,
|
|
9752
|
+
eslintPluginStorybookVersion
|
|
9753
|
+
] = await Promise.all([
|
|
9754
|
+
getModulePackageJSONVersion("typescript"),
|
|
9755
|
+
getModulePackageJSONVersion("prettier"),
|
|
9756
|
+
getModulePackageJSONVersion("@babel/plugin-transform-typescript"),
|
|
9757
|
+
getModulePackageJSONVersion("@typescript-eslint/parser"),
|
|
9758
|
+
getModulePackageJSONVersion("eslint-plugin-storybook")
|
|
9759
|
+
]), satisfies = (version2, range) => version2 ? import_semver7.default.satisfies(version2, range, { includePrerelease: !0 }) : !1, incompatibleReasons = [];
|
|
9760
|
+
return typescriptVersion && !satisfies(typescriptVersion, ">=4.9.0") && incompatibleReasons.push(`typescript ${typescriptVersion} is below 4.9.0`), prettierVersion && !import_semver7.default.gte(prettierVersion, "2.8.0") && incompatibleReasons.push(`prettier ${prettierVersion} is below 2.8.0`), babelPluginTransformTypescriptVersion && !satisfies(babelPluginTransformTypescriptVersion, ">=7.20.0") && incompatibleReasons.push(
|
|
9761
|
+
`@babel/plugin-transform-typescript ${babelPluginTransformTypescriptVersion} is below 7.20.0`
|
|
9762
|
+
), typescriptEslintParserVersion && !satisfies(typescriptEslintParserVersion, ">=5.44.0") && incompatibleReasons.push(
|
|
9763
|
+
`@typescript-eslint/parser ${typescriptEslintParserVersion} is below 5.44.0`
|
|
9764
|
+
), eslintPluginStorybookVersion && !eslintPluginStorybookVersion.startsWith("0.0.0-") && !satisfies(eslintPluginStorybookVersion, ">=0.6.8") && incompatibleReasons.push(
|
|
9765
|
+
`eslint-plugin-storybook ${eslintPluginStorybookVersion} is below 0.6.8`
|
|
9766
|
+
), incompatibleReasons;
|
|
9767
|
+
}
|
|
9768
|
+
eqMajor(versionRange, major) {
|
|
9769
|
+
return import_semver7.default.validRange(versionRange) ? import_semver7.default.minVersion(versionRange)?.major === major : !1;
|
|
9770
|
+
}
|
|
9771
|
+
async detectProjectType(options) {
|
|
9772
|
+
try {
|
|
9773
|
+
if (this.isNxProject())
|
|
9774
|
+
return ProjectType2.NX;
|
|
9775
|
+
if (options.html)
|
|
9776
|
+
return ProjectType2.HTML;
|
|
9777
|
+
let { packageJson } = this.jsPackageManager.primaryPackageJson;
|
|
9778
|
+
return this.detectFrameworkPreset(packageJson);
|
|
9779
|
+
} catch {
|
|
9780
|
+
return ProjectType2.UNDETECTED;
|
|
9781
|
+
}
|
|
9782
|
+
}
|
|
9783
|
+
detectFrameworkPreset(packageJson) {
|
|
9784
|
+
let result = [...this.getSupportedTemplates(), this.getUnsupportedTemplate()].find(
|
|
9785
|
+
(framework) => this.getProjectType(packageJson, framework) !== null
|
|
9786
|
+
);
|
|
9787
|
+
return result ? result.preset : ProjectType2.UNDETECTED;
|
|
9788
|
+
}
|
|
9789
|
+
/** Template that matches unsupported frameworks */
|
|
9790
|
+
getUnsupportedTemplate() {
|
|
9791
|
+
return {
|
|
9792
|
+
preset: ProjectType2.UNSUPPORTED,
|
|
9793
|
+
dependencies: {},
|
|
9794
|
+
matcherFunction: ({ dependencies }) => dependencies?.some(Boolean) ?? !1
|
|
9795
|
+
};
|
|
9796
|
+
}
|
|
9797
|
+
getProjectType(packageJson, framework) {
|
|
9798
|
+
let matcher = {
|
|
9799
|
+
dependencies: [!1],
|
|
9800
|
+
peerDependencies: [!1],
|
|
9801
|
+
files: [!1]
|
|
9802
|
+
}, { preset, files, dependencies, peerDependencies, matcherFunction } = framework, dependencySearches = [];
|
|
9803
|
+
Array.isArray(dependencies) ? dependencySearches = dependencies.map((name) => [name, void 0]) : typeof dependencies == "object" && (dependencySearches = Object.entries(dependencies)), dependencySearches.length > 0 && (matcher.dependencies = dependencySearches.map(
|
|
9804
|
+
([name, matchFn]) => this.hasDependency(packageJson, name, matchFn)
|
|
9805
|
+
));
|
|
9806
|
+
let peerDependencySearches = [];
|
|
9807
|
+
return Array.isArray(peerDependencies) ? peerDependencySearches = peerDependencies.map((name) => [name, void 0]) : typeof peerDependencies == "object" && (peerDependencySearches = Object.entries(peerDependencies)), peerDependencySearches.length > 0 && (matcher.peerDependencies = peerDependencySearches.map(
|
|
9808
|
+
([name, matchFn]) => this.hasPeerDependency(packageJson, name, matchFn)
|
|
9809
|
+
)), Array.isArray(files) && files.length > 0 && (matcher.files = files.map((name) => existsSync6(name))), matcherFunction(matcher) ? preset : null;
|
|
9810
|
+
}
|
|
9811
|
+
hasDependency(packageJson, name, matcher) {
|
|
9812
|
+
let version2 = packageJson.dependencies?.[name] || packageJson.devDependencies?.[name];
|
|
9813
|
+
return version2 && typeof matcher == "function" ? matcher(version2) : !!version2;
|
|
9814
|
+
}
|
|
9815
|
+
hasPeerDependency(packageJson, name, matcher) {
|
|
9816
|
+
let version2 = packageJson.peerDependencies?.[name];
|
|
9817
|
+
return version2 && typeof matcher == "function" ? matcher(version2) : !!version2;
|
|
9818
|
+
}
|
|
9819
|
+
isNxProject() {
|
|
9820
|
+
return up2("nx.json", { last: getProjectRoot() });
|
|
9821
|
+
}
|
|
9822
|
+
};
|
|
9823
|
+
|
|
9824
|
+
// src/ai/setup-prompts/index.ts
|
|
9825
|
+
import { dedent as dedent18 } from "ts-dedent";
|
|
9826
|
+
|
|
9827
|
+
// src/ai/utils/project-overview.ts
|
|
9828
|
+
function getProjectOverview(projectInfo) {
|
|
9829
|
+
let rows = [
|
|
9830
|
+
["Version", projectInfo.storybookVersion || "unknown"],
|
|
9831
|
+
["Renderer", projectInfo.rendererPackage || "unknown"],
|
|
9832
|
+
["Framework", projectInfo.framework || "unknown"],
|
|
9833
|
+
["Builder", projectInfo.builderPackage || "unknown"],
|
|
9834
|
+
["Config Dir", `\`${projectInfo.configDir}\``],
|
|
9835
|
+
["Language", projectInfo.language === "ts" ? "TypeScript" : "JavaScript"]
|
|
9836
|
+
];
|
|
9837
|
+
return projectInfo.packageManager && rows.push(["Package Manager", projectInfo.packageManagerName || "unknown"]), rows.push(["Addons", projectInfo.addons.length > 0 ? projectInfo.addons.join(", ") : "none"]), ["## Project Info", "", "| Property | Value |", "|----------|-------|", rows.map(([key, value]) => `| ${key} | ${value} |`).join(`
|
|
9838
|
+
`)].join(
|
|
9839
|
+
`
|
|
9840
|
+
`
|
|
9841
|
+
);
|
|
9842
|
+
}
|
|
9843
|
+
|
|
9844
|
+
// src/ai/setup-prompts/index.ts
|
|
9845
|
+
var DEFAULT_PROMPT_NAME = "optimized-tests", CURRENTLY_USED_PROMPT = {
|
|
9846
|
+
[DEFAULT_PROMPT_NAME]: instructions
|
|
9847
|
+
}, FORMERLY_USED_PROMPTS = {
|
|
9848
|
+
monorepo: async () => (await import("./monorepo-JBBOX7QG.js")).instructions,
|
|
9849
|
+
"optimized-tests": async () => (await import("./optimized-tests-NI7YTCNF.js")).instructions,
|
|
9850
|
+
"relaxed-limits": async () => (await import("./relaxed-limits-EWX3BPFO.js")).instructions,
|
|
9851
|
+
setup: async () => (await import("./setup-WAWFVYQV.js")).instructions,
|
|
9852
|
+
"pattern-copy-play": async () => (await import("./pattern-copy-play-6QEXGF3O.js")).instructions,
|
|
9853
|
+
"monorepo-optimized-tests-relaxed-limits-no-story-deletion": async () => (await import("./monorepo-optimized-tests-relaxed-limits-no-story-deletion-G2X5WHM3.js")).instructions
|
|
9854
|
+
}, PROMPT_NAMES = [
|
|
9855
|
+
...Object.keys(CURRENTLY_USED_PROMPT),
|
|
9856
|
+
...Object.keys(FORMERLY_USED_PROMPTS)
|
|
9857
|
+
], EVAL_SETUP_PROMPT_ENV = "EVAL_SETUP_PROMPT";
|
|
9858
|
+
function resolvePromptName() {
|
|
9859
|
+
let requested = process.env[EVAL_SETUP_PROMPT_ENV]?.trim();
|
|
9860
|
+
return requested && (Object.hasOwn(CURRENTLY_USED_PROMPT, requested) || Object.hasOwn(FORMERLY_USED_PROMPTS, requested)) ? requested : DEFAULT_PROMPT_NAME;
|
|
9861
|
+
}
|
|
9862
|
+
async function getAiSetupPrompt(projectInfo) {
|
|
9863
|
+
let name = resolvePromptName();
|
|
9864
|
+
return { content: (CURRENTLY_USED_PROMPT[name] ?? await FORMERLY_USED_PROMPTS[name]())(projectInfo), name };
|
|
9865
|
+
}
|
|
9866
|
+
async function getAiSetupMarkdownOutput(projectInfo) {
|
|
9867
|
+
let { content, name } = await getAiSetupPrompt(projectInfo);
|
|
9868
|
+
return {
|
|
9869
|
+
markdown: dedent18`
|
|
9870
|
+
# Storybook Setup
|
|
9871
|
+
|
|
9872
|
+
${getProjectOverview(projectInfo)}
|
|
9873
|
+
|
|
9874
|
+
${content}
|
|
9875
|
+
`,
|
|
9876
|
+
prompt: name
|
|
9877
|
+
};
|
|
9878
|
+
}
|
|
9879
|
+
|
|
9880
|
+
// src/ai/index.ts
|
|
9881
|
+
async function aiSetup(options) {
|
|
9882
|
+
let { configDir: userConfigDir, packageManager, output } = options, projectInfo;
|
|
9883
|
+
try {
|
|
9884
|
+
let data = await getStorybookData({
|
|
9885
|
+
configDir: userConfigDir,
|
|
9886
|
+
packageManagerName: packageManager
|
|
9887
|
+
});
|
|
9888
|
+
if (!data.frameworkPackage || !data.rendererPackage || !data.builderPackage) {
|
|
9889
|
+
logger23.error(
|
|
9890
|
+
"Could not detect framework, renderer, or builder from your Storybook config. Make sure you are running this command from your project root, or specify --config-dir."
|
|
9891
|
+
);
|
|
9892
|
+
return;
|
|
9893
|
+
}
|
|
9894
|
+
let majorVersion = data.versionInstalled ? parseMajorVersion(data.versionInstalled) : void 0, language = await new ProjectTypeService(data.packageManager).detectLanguage() === SupportedLanguage2.TYPESCRIPT ? "ts" : "js", needsUserOnboarding = await cache.get("onboarding-pending", !1);
|
|
9895
|
+
projectInfo = {
|
|
9896
|
+
storybookVersion: data.versionInstalled,
|
|
9897
|
+
majorVersion,
|
|
9898
|
+
framework: data.frameworkPackage,
|
|
9899
|
+
rendererPackage: data.rendererPackage,
|
|
9900
|
+
renderer: data.renderer,
|
|
9901
|
+
builderPackage: data.builderPackage,
|
|
9902
|
+
addons: data.addons ?? [],
|
|
9903
|
+
configDir: data.configDir,
|
|
9904
|
+
storiesPaths: data.storiesPaths,
|
|
9905
|
+
packageManager: data.packageManager,
|
|
9906
|
+
packageManagerName: getPrettyPackageManagerName(data.packageManager.type),
|
|
9907
|
+
language,
|
|
9908
|
+
hasCsfFactoryPreview: data.hasCsfFactoryPreview,
|
|
9909
|
+
needsUserOnboarding
|
|
9910
|
+
};
|
|
9911
|
+
} catch (err) {
|
|
9912
|
+
logger23.error(
|
|
9913
|
+
`Failed to read Storybook configuration: ${err instanceof Error ? err.message : String(err)}`
|
|
9914
|
+
), logger23.log(
|
|
9915
|
+
"Make sure you are running this command from your project root, or specify --config-dir."
|
|
9916
|
+
);
|
|
9917
|
+
return;
|
|
9918
|
+
}
|
|
9919
|
+
if (projectInfo.rendererPackage !== "@storybook/react" || projectInfo.builderPackage !== "@storybook/builder-vite") {
|
|
9920
|
+
logger23.log(
|
|
9921
|
+
"AI-assisted setup is currently only available for projects using the React renderer with Vite builder. Detected renderer: " + projectInfo.rendererPackage + ", builder: " + projectInfo.builderPackage
|
|
9922
|
+
);
|
|
9923
|
+
return;
|
|
9924
|
+
}
|
|
9925
|
+
let result = await getAiSetupMarkdownOutput(projectInfo), markdownOutput = result.markdown;
|
|
9926
|
+
if (await cache.set("ai-setup-ran", {
|
|
9927
|
+
timestamp: Date.now(),
|
|
9928
|
+
runId: options.runId,
|
|
9929
|
+
configDir: resolve4(projectInfo.configDir)
|
|
9930
|
+
}).catch(() => {
|
|
9931
|
+
}), await telemetry("ai-setup", {
|
|
9932
|
+
cliOptions: {
|
|
9933
|
+
output: output ? "file" : void 0,
|
|
9934
|
+
configDir: projectInfo.configDir,
|
|
9935
|
+
packageManager: projectInfo.packageManager.type,
|
|
9936
|
+
prompt: result.prompt
|
|
9937
|
+
},
|
|
9938
|
+
project: {
|
|
9939
|
+
framework: projectInfo.framework,
|
|
9940
|
+
renderer: projectInfo.rendererPackage,
|
|
9941
|
+
builder: projectInfo.builderPackage,
|
|
9942
|
+
language: projectInfo.language
|
|
9943
|
+
},
|
|
9944
|
+
runId: options.runId
|
|
9945
|
+
}), output) {
|
|
9946
|
+
let outputPath = resolve4(output);
|
|
9947
|
+
await writeFile10(outputPath, markdownOutput, "utf-8"), logger23.log(`Prompt written to ${outputPath}`);
|
|
9948
|
+
} else
|
|
9949
|
+
process.stdout.write(`${markdownOutput}
|
|
9950
|
+
`);
|
|
9951
|
+
}
|
|
9952
|
+
function parseMajorVersion(version2) {
|
|
9953
|
+
let match = version2.match(/^(\d+)/);
|
|
9954
|
+
return match ? parseInt(match[1], 10) : void 0;
|
|
9955
|
+
}
|
|
9956
|
+
|
|
9131
9957
|
// src/upgrade.ts
|
|
9132
|
-
var import_cross_spawn3 = __toESM(require_cross_spawn(), 1),
|
|
9958
|
+
var import_cross_spawn3 = __toESM(require_cross_spawn(), 1), import_picocolors17 = __toESM(require_picocolors(), 1), import_semver8 = __toESM(require_semver(), 1);
|
|
9133
9959
|
import { PackageManagerName as PackageManagerName2 } from "storybook/internal/common";
|
|
9134
|
-
import {
|
|
9960
|
+
import {
|
|
9961
|
+
HandledError as HandledError2,
|
|
9962
|
+
JsPackageManagerFactory as JsPackageManagerFactory2,
|
|
9963
|
+
isCI as isCI2,
|
|
9964
|
+
isCorePackage as isCorePackage2
|
|
9965
|
+
} from "storybook/internal/common";
|
|
9135
9966
|
import {
|
|
9136
9967
|
CLI_COLORS as CLI_COLORS4,
|
|
9137
9968
|
createHyperlink,
|
|
9138
9969
|
logTracker as logTracker3,
|
|
9139
|
-
logger as
|
|
9140
|
-
prompt as
|
|
9970
|
+
logger as logger25,
|
|
9971
|
+
prompt as prompt7
|
|
9141
9972
|
} from "storybook/internal/node-logger";
|
|
9142
9973
|
import {
|
|
9974
|
+
MinimumReleaseAgeHandledError,
|
|
9143
9975
|
UpgradeStorybookToLowerVersionError,
|
|
9144
9976
|
UpgradeStorybookUnknownCurrentVersionError
|
|
9145
9977
|
} from "storybook/internal/server-errors";
|
|
9146
|
-
import { telemetry } from "storybook/internal/telemetry";
|
|
9147
|
-
import { dedent as
|
|
9978
|
+
import { telemetry as telemetry2 } from "storybook/internal/telemetry";
|
|
9979
|
+
import { dedent as dedent19 } from "ts-dedent";
|
|
9148
9980
|
|
|
9149
9981
|
// src/automigrate/multi-project.ts
|
|
9150
|
-
import { CLI_COLORS as CLI_COLORS3, logger as
|
|
9982
|
+
import { CLI_COLORS as CLI_COLORS3, logger as logger24, prompt as prompt6 } from "storybook/internal/node-logger";
|
|
9151
9983
|
import { ErrorCollector, sanitizeError } from "storybook/internal/telemetry";
|
|
9152
9984
|
async function collectAutomigrationsAcrossProjects(options) {
|
|
9153
9985
|
let { fixes, projects, taskLog } = options, automigrationMap = /* @__PURE__ */ new Map();
|
|
9154
|
-
|
|
9986
|
+
logger24.debug(
|
|
9155
9987
|
`Starting automigration collection across ${projects.length} projects and ${fixes.length} fixes...`
|
|
9156
9988
|
);
|
|
9157
9989
|
function collectResult(fix, project, status, result) {
|
|
@@ -9173,10 +10005,10 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
9173
10005
|
}
|
|
9174
10006
|
for (let project of projects) {
|
|
9175
10007
|
let projectName = shortenPath(project.configDir);
|
|
9176
|
-
taskLog.message(`Checking automigrations for ${projectName}...`),
|
|
10008
|
+
taskLog.message(`Checking automigrations for ${projectName}...`), logger24.debug(`Processing project: ${projectName}`);
|
|
9177
10009
|
for (let fix of fixes)
|
|
9178
10010
|
try {
|
|
9179
|
-
|
|
10011
|
+
logger24.debug(`Checking fix ${fix.id} for project ${projectName}...`);
|
|
9180
10012
|
let checkOptions = {
|
|
9181
10013
|
packageManager: project.packageManager,
|
|
9182
10014
|
configDir: project.configDir,
|
|
@@ -9189,9 +10021,9 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
9189
10021
|
}, result = await fix.check(checkOptions);
|
|
9190
10022
|
result !== null ? collectResult(fix, project, "check_succeeded", result) : collectResult(fix, project, "not_applicable");
|
|
9191
10023
|
} catch (error) {
|
|
9192
|
-
collectResult(fix, project, "check_failed"),
|
|
10024
|
+
collectResult(fix, project, "check_failed"), logger24.debug(
|
|
9193
10025
|
`Failed to check fix ${fix.id} for project ${shortenPath(project.configDir)}.`
|
|
9194
|
-
),
|
|
10026
|
+
), logger24.debug(`${error instanceof Error ? error.stack : String(error)}`), ErrorCollector.addError(error);
|
|
9195
10027
|
}
|
|
9196
10028
|
}
|
|
9197
10029
|
let allAutomigrations = Array.from(automigrationMap.values()), applicableAutomigrations = allAutomigrations.filter(
|
|
@@ -9205,9 +10037,9 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
9205
10037
|
);
|
|
9206
10038
|
return taskLog.message(`
|
|
9207
10039
|
Automigrations detected:`), successAutomigrations.forEach((fixId) => {
|
|
9208
|
-
taskLog.message(`${CLI_COLORS3.success(`${
|
|
10040
|
+
taskLog.message(`${CLI_COLORS3.success(`${logger24.SYMBOLS.success} ${fixId}`)}`);
|
|
9209
10041
|
}), failedAutomigrations.forEach((fixId) => {
|
|
9210
|
-
taskLog.message(`${CLI_COLORS3.error(`${
|
|
10042
|
+
taskLog.message(`${CLI_COLORS3.error(`${logger24.SYMBOLS.error} ${fixId}`)}`);
|
|
9211
10043
|
}), failedAutomigrations.length > 0 ? taskLog.error(
|
|
9212
10044
|
`${failedAutomigrations.length} automigration ${failedAutomigrations.length > 1 ? "checks" : "check"} failed`
|
|
9213
10045
|
) : taskLog.success(
|
|
@@ -9225,12 +10057,12 @@ async function promptForAutomigrations(automigrations, options) {
|
|
|
9225
10057
|
if (automigrations.length === 0)
|
|
9226
10058
|
return [];
|
|
9227
10059
|
if (options.dryRun)
|
|
9228
|
-
return
|
|
9229
|
-
|
|
10060
|
+
return logger24.log("Detected automigrations (dry run - no changes will be made):"), automigrations.forEach(({ fix, reports: list }) => {
|
|
10061
|
+
logger24.log(` - ${fix.id} (${formatProjectDirs(list)})`);
|
|
9230
10062
|
}), [];
|
|
9231
10063
|
if (options.yes)
|
|
9232
|
-
return
|
|
9233
|
-
|
|
10064
|
+
return logger24.log("Running all detected automigrations:"), automigrations.forEach(({ fix, reports: list }) => {
|
|
10065
|
+
logger24.log(` - ${fix.id} (${formatProjectDirs(list)})`);
|
|
9234
10066
|
}), automigrations;
|
|
9235
10067
|
let choices = automigrations.map((am) => {
|
|
9236
10068
|
let hint = [];
|
|
@@ -9243,7 +10075,7 @@ async function promptForAutomigrations(automigrations, options) {
|
|
|
9243
10075
|
`),
|
|
9244
10076
|
defaultSelected: am.fix.defaultSelected ?? !0
|
|
9245
10077
|
};
|
|
9246
|
-
}), selectedIds = await
|
|
10078
|
+
}), selectedIds = await prompt6.multiselect({
|
|
9247
10079
|
message: "Select automigrations to run",
|
|
9248
10080
|
options: choices,
|
|
9249
10081
|
initialValues: choices.filter((c) => c.defaultSelected).map((c) => c.value),
|
|
@@ -9274,18 +10106,18 @@ async function runAutomigrationsForProjects(selectedAutomigrations, options) {
|
|
|
9274
10106
|
}
|
|
9275
10107
|
let projectIndex = 0;
|
|
9276
10108
|
for (let [configDir, projectAutomigration] of projectAutomigrationResults) {
|
|
9277
|
-
let countPrefix = projectAutomigrationResults.size > 1 ? `(${++projectIndex}/${projectAutomigrationResults.size}) ` : "", { project } = projectAutomigration[0], projectName = shortenPath(project.configDir), taskLog = applicableAutomigrations.length > 0 ?
|
|
10109
|
+
let countPrefix = projectAutomigrationResults.size > 1 ? `(${++projectIndex}/${projectAutomigrationResults.size}) ` : "", { project } = projectAutomigration[0], projectName = shortenPath(project.configDir), taskLog = applicableAutomigrations.length > 0 ? prompt6.taskLog({
|
|
9278
10110
|
id: `automigrate-${projectName}`,
|
|
9279
10111
|
title: `${countPrefix}Running automigrations for ${projectName}`
|
|
9280
10112
|
}) : {
|
|
9281
10113
|
message: (message) => {
|
|
9282
|
-
|
|
10114
|
+
logger24.debug(`${message}`);
|
|
9283
10115
|
},
|
|
9284
10116
|
error: (message) => {
|
|
9285
|
-
|
|
10117
|
+
logger24.debug(`${message}`);
|
|
9286
10118
|
},
|
|
9287
10119
|
success: (message) => {
|
|
9288
|
-
|
|
10120
|
+
logger24.debug(`${message}`);
|
|
9289
10121
|
}
|
|
9290
10122
|
}, fixResults = {}, fixFailures = {};
|
|
9291
10123
|
for (let automigration of projectAutomigration) {
|
|
@@ -9319,11 +10151,11 @@ async function runAutomigrationsForProjects(selectedAutomigrations, options) {
|
|
|
9319
10151
|
storiesPaths: project2.storiesPaths,
|
|
9320
10152
|
yes
|
|
9321
10153
|
};
|
|
9322
|
-
await fix.run(runOptions), fixResults[fix.id] = "succeeded" /* SUCCEEDED */, taskLog.message(CLI_COLORS3.success(`${
|
|
10154
|
+
await fix.run(runOptions), fixResults[fix.id] = "succeeded" /* SUCCEEDED */, taskLog.message(CLI_COLORS3.success(`${logger24.SYMBOLS.success} ${fix.id}`));
|
|
9323
10155
|
}
|
|
9324
10156
|
} catch (error) {
|
|
9325
10157
|
let errorMessage = (error instanceof Error ? error.stack : String(error)) ?? "Unknown error";
|
|
9326
|
-
fixResults[fix.id] = "failed" /* FAILED */, fixFailures[fix.id] = sanitizeError(error), taskLog.message(CLI_COLORS3.error(`${
|
|
10158
|
+
fixResults[fix.id] = "failed" /* FAILED */, fixFailures[fix.id] = sanitizeError(error), taskLog.message(CLI_COLORS3.error(`${logger24.SYMBOLS.error} ${automigration.fix.id}`)), logger24.debug(errorMessage), ErrorCollector.addError(error);
|
|
9327
10159
|
}
|
|
9328
10160
|
}
|
|
9329
10161
|
let automigrationsWithErrors = Object.values(fixResults).filter(
|
|
@@ -9352,7 +10184,7 @@ async function runAutomigrations(projects, options) {
|
|
|
9352
10184
|
beforeVersion: project.beforeVersion,
|
|
9353
10185
|
storiesPaths: project.storiesPaths,
|
|
9354
10186
|
hasCsfFactoryPreview: project.hasCsfFactoryPreview
|
|
9355
|
-
})), detectingAutomigrationTask =
|
|
10187
|
+
})), detectingAutomigrationTask = prompt6.taskLog({
|
|
9356
10188
|
id: "detect-automigrations",
|
|
9357
10189
|
title: projectAutomigrationData.length > 1 ? `Detecting automigrations for ${projectAutomigrationData.length} projects...` : "Detecting automigrations..."
|
|
9358
10190
|
}), detectedAutomigrations = await collectAutomigrationsAcrossProjects({
|
|
@@ -9378,7 +10210,7 @@ async function runAutomigrations(projects, options) {
|
|
|
9378
10210
|
let project = projects.find((p) => p.configDir === configDir);
|
|
9379
10211
|
if (project) {
|
|
9380
10212
|
let oldConfigDir = project.configDir;
|
|
9381
|
-
project.configDir = project.configDir.replace(".storybook",
|
|
10213
|
+
project.configDir = project.configDir.replace(".storybook", RN_STORYBOOK_DIR), automigrationResults[project.configDir] = resultData, delete automigrationResults[oldConfigDir];
|
|
9382
10214
|
}
|
|
9383
10215
|
}
|
|
9384
10216
|
}), {
|
|
@@ -9433,29 +10265,29 @@ function logUpgradeResults(projectResults, detectedAutomigrations, doctorResults
|
|
|
9433
10265
|
doctorResults
|
|
9434
10266
|
);
|
|
9435
10267
|
if (failedProjects.length > 0) {
|
|
9436
|
-
if (logTracker3.enableLogWriting(),
|
|
10268
|
+
if (logTracker3.enableLogWriting(), logger25.step(
|
|
9437
10269
|
"The upgrade is complete, but some projects failed to upgrade or migrate completely. Please see the debug logs for more details."
|
|
9438
10270
|
), successfulProjects.length > 0) {
|
|
9439
10271
|
let successfulProjectsList = successfulProjects.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9440
10272
|
`);
|
|
9441
|
-
|
|
10273
|
+
logger25.log(`${CLI_COLORS4.success("Successfully upgraded:")}
|
|
9442
10274
|
${successfulProjectsList}`);
|
|
9443
10275
|
}
|
|
9444
10276
|
let failedProjectsList = failedProjects.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9445
10277
|
`);
|
|
9446
|
-
if (
|
|
10278
|
+
if (logger25.log(
|
|
9447
10279
|
`${CLI_COLORS4.error("Failed to upgrade:")}
|
|
9448
10280
|
Some automigrations failed, please check the logs in the log file for more details.
|
|
9449
10281
|
${failedProjectsList}`
|
|
9450
10282
|
), projectsWithNoFixes.length > 0) {
|
|
9451
10283
|
let projectList = projectsWithNoFixes.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9452
10284
|
`);
|
|
9453
|
-
|
|
10285
|
+
logger25.log(`${CLI_COLORS4.info("No applicable migrations:")}
|
|
9454
10286
|
${projectList}`);
|
|
9455
10287
|
}
|
|
9456
10288
|
} else
|
|
9457
|
-
Object.values(doctorResults).every((result) => result.status === "healthy") ?
|
|
9458
|
-
`${
|
|
10289
|
+
Object.values(doctorResults).every((result) => result.status === "healthy") ? logger25.step(`${CLI_COLORS4.success("Your project(s) have been upgraded successfully! \u{1F389}")}`) : logger25.step(
|
|
10290
|
+
`${import_picocolors17.default.yellow("Your project(s) have been upgraded successfully, but some issues were found which need your attention, please check Storybook doctor logs above.")}`
|
|
9459
10291
|
);
|
|
9460
10292
|
let automigrationLinks = detectedAutomigrations.filter(
|
|
9461
10293
|
(am) => Object.entries(projectResults).some(
|
|
@@ -9468,9 +10300,9 @@ ${projectList}`);
|
|
|
9468
10300
|
...automigrationLinks
|
|
9469
10301
|
].join(`
|
|
9470
10302
|
`);
|
|
9471
|
-
|
|
10303
|
+
logger25.log(automigrationLinksMessage);
|
|
9472
10304
|
}
|
|
9473
|
-
|
|
10305
|
+
logger25.log(
|
|
9474
10306
|
`For a full list of changes, please check our migration guide: ${CLI_COLORS4.cta("https://storybook.js.org/docs/releases/migration-guide?ref=upgrade")}`
|
|
9475
10307
|
);
|
|
9476
10308
|
}
|
|
@@ -9491,7 +10323,7 @@ async function sendMultiUpgradeTelemetry(options) {
|
|
|
9491
10323
|
(result) => result.status !== "healthy"
|
|
9492
10324
|
).length;
|
|
9493
10325
|
try {
|
|
9494
|
-
await
|
|
10326
|
+
await telemetry2("multi-upgrade", {
|
|
9495
10327
|
totalDetectedProjects: allProjects.length,
|
|
9496
10328
|
totalSelectedProjects: selectedProjects.length,
|
|
9497
10329
|
projectsWithSuccessfulAutomigrations: successfulProjects.length,
|
|
@@ -9502,7 +10334,7 @@ async function sendMultiUpgradeTelemetry(options) {
|
|
|
9502
10334
|
hasUserInterrupted
|
|
9503
10335
|
});
|
|
9504
10336
|
} catch (error) {
|
|
9505
|
-
|
|
10337
|
+
logger25.debug(`Failed to send multi-upgrade telemetry: ${String(error)}`);
|
|
9506
10338
|
}
|
|
9507
10339
|
}
|
|
9508
10340
|
async function upgrade(options) {
|
|
@@ -9510,13 +10342,13 @@ async function upgrade(options) {
|
|
|
9510
10342
|
if (projectsResult === void 0 || projectsResult.selectedProjects.length === 0)
|
|
9511
10343
|
return;
|
|
9512
10344
|
let { allProjects, selectedProjects: storybookProjects } = projectsResult;
|
|
9513
|
-
storybookProjects.length > 1 ?
|
|
9514
|
-
${storybookProjects.map((p) => `${
|
|
9515
|
-
`)}`) :
|
|
9516
|
-
`Upgrading from ${
|
|
10345
|
+
storybookProjects.length > 1 ? logger25.info(`Upgrading the following projects:
|
|
10346
|
+
${storybookProjects.map((p) => `${import_picocolors17.default.cyan(shortenPath(p.configDir))}: ${import_picocolors17.default.bold(p.beforeVersion)} -> ${import_picocolors17.default.bold(p.currentCLIVersion)}`).join(`
|
|
10347
|
+
`)}`) : logger25.info(
|
|
10348
|
+
`Upgrading from ${import_picocolors17.default.bold(storybookProjects[0].beforeVersion)} to ${import_picocolors17.default.bold(storybookProjects[0].currentCLIVersion)}`
|
|
9517
10349
|
);
|
|
9518
10350
|
let automigrationResults = {}, doctorResults = {}, handleInterruption = async () => {
|
|
9519
|
-
throw
|
|
10351
|
+
throw logger25.log(`
|
|
9520
10352
|
|
|
9521
10353
|
Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgradeTelemetry({
|
|
9522
10354
|
allProjects,
|
|
@@ -9524,16 +10356,16 @@ Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgrade
|
|
|
9524
10356
|
projectResults: automigrationResults,
|
|
9525
10357
|
doctorResults,
|
|
9526
10358
|
hasUserInterrupted: !0
|
|
9527
|
-
}), new
|
|
10359
|
+
}), new HandledError2("Upgrade cancelled by user");
|
|
9528
10360
|
};
|
|
9529
10361
|
process.on("SIGINT", handleInterruption), process.on("SIGTERM", handleInterruption);
|
|
9530
10362
|
try {
|
|
9531
10363
|
if (processAutoblockerResults(storybookProjects, (message) => {
|
|
9532
|
-
|
|
10364
|
+
logger25.error(dedent19`Blockers detected\n\n${message}`);
|
|
9533
10365
|
}))
|
|
9534
|
-
throw new
|
|
10366
|
+
throw new HandledError2("Blockers detected");
|
|
9535
10367
|
if (storybookProjects.some((project) => {
|
|
9536
|
-
if (!project.isCanary && (0,
|
|
10368
|
+
if (!project.isCanary && (0, import_semver8.lt)(project.currentCLIVersion, project.beforeVersion))
|
|
9537
10369
|
throw new UpgradeStorybookToLowerVersionError({
|
|
9538
10370
|
beforeVersion: project.beforeVersion,
|
|
9539
10371
|
currentVersion: project.currentCLIVersion
|
|
@@ -9541,14 +10373,28 @@ Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgrade
|
|
|
9541
10373
|
if (!project.beforeVersion)
|
|
9542
10374
|
throw new UpgradeStorybookUnknownCurrentVersionError();
|
|
9543
10375
|
}), !options.dryRun) {
|
|
9544
|
-
let
|
|
10376
|
+
for (let project of storybookProjects)
|
|
10377
|
+
try {
|
|
10378
|
+
await project.packageManager.precheckStorybookPackageInstall({
|
|
10379
|
+
storybookVersion: project.currentCLIVersion,
|
|
10380
|
+
nonInteractive: !!options.yes || !process.stdout.isTTY || !!isCI2(),
|
|
10381
|
+
installContext: "upgrade"
|
|
10382
|
+
});
|
|
10383
|
+
} catch (error) {
|
|
10384
|
+
if (error instanceof MinimumReleaseAgeHandledError)
|
|
10385
|
+
throw error;
|
|
10386
|
+
logger25.debug(
|
|
10387
|
+
`Skipping minimum-release-age precheck for ${project.configDir} after an unexpected failure: ${error}`
|
|
10388
|
+
);
|
|
10389
|
+
}
|
|
10390
|
+
let task = prompt7.taskLog({
|
|
9545
10391
|
id: "upgrade-dependencies",
|
|
9546
10392
|
title: "Fetching versions to update package.json files.."
|
|
9547
10393
|
});
|
|
9548
10394
|
try {
|
|
9549
10395
|
let loggedPaths = [];
|
|
9550
10396
|
for (let project of storybookProjects) {
|
|
9551
|
-
|
|
10397
|
+
logger25.debug(`Updating dependencies in ${shortenPath(project.configDir)}...`);
|
|
9552
10398
|
let newPaths = project.packageManager.packageJsonPaths.map(shortenPath).filter((path4) => !loggedPaths.includes(path4));
|
|
9553
10399
|
newPaths.length > 0 && (task.message(newPaths.join(`
|
|
9554
10400
|
`)), loggedPaths.push(...newPaths)), await upgradeStorybookDependencies({
|
|
@@ -9565,16 +10411,18 @@ Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgrade
|
|
|
9565
10411
|
task.error(`Failed to upgrade dependencies: ${String(err)}`);
|
|
9566
10412
|
}
|
|
9567
10413
|
}
|
|
9568
|
-
let
|
|
10414
|
+
let automigrationResults2 = {}, detectedAutomigrations = [];
|
|
10415
|
+
options.skipAutomigrations ? logger25.log("Skipping automigrations (--skip-automigrations).") : { automigrationResults: automigrationResults2, detectedAutomigrations } = await runAutomigrations(
|
|
9569
10416
|
storybookProjects,
|
|
9570
10417
|
options
|
|
9571
|
-
)
|
|
9572
|
-
rootPackageManager.
|
|
10418
|
+
);
|
|
10419
|
+
let rootPackageManager = storybookProjects.length > 1 ? JsPackageManagerFactory2.getPackageManager({ force: options.packageManager }) : storybookProjects[0].packageManager;
|
|
10420
|
+
rootPackageManager.type === "npm" ? await rootPackageManager.installDependencies({ force: !0 }) : await rootPackageManager.installDependencies(), rootPackageManager.type !== PackageManagerName2.YARN1 && rootPackageManager.isStorybookInMonorepo() && (logger25.warn(
|
|
9573
10421
|
"Since you are in a monorepo, we advise you to deduplicate your dependencies. We can do this for you but it might take some time."
|
|
9574
|
-
), options.yes || await
|
|
10422
|
+
), options.yes || await prompt7.confirm({
|
|
9575
10423
|
message: `Execute ${rootPackageManager.getRunCommand("dedupe")}?`,
|
|
9576
10424
|
initialValue: !0
|
|
9577
|
-
}) ? rootPackageManager.type === "npm" ? await rootPackageManager.dedupeDependencies({ force: !0 }) : await rootPackageManager.dedupeDependencies() :
|
|
10425
|
+
}) ? rootPackageManager.type === "npm" ? await rootPackageManager.dedupeDependencies({ force: !0 }) : await rootPackageManager.dedupeDependencies() : logger25.log(
|
|
9578
10426
|
`If you find any issues running Storybook, you can run ${rootPackageManager.getRunCommand("dedupe")} manually to deduplicate your dependencies and try again.`
|
|
9579
10427
|
));
|
|
9580
10428
|
let doctorProjects = storybookProjects.map((project) => ({
|
|
@@ -9583,35 +10431,34 @@ Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgrade
|
|
|
9583
10431
|
storybookVersion: project.currentCLIVersion,
|
|
9584
10432
|
mainConfig: project.mainConfig
|
|
9585
10433
|
}));
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
});
|
|
9607
|
-
}
|
|
9608
|
-
await sendMultiUpgradeTelemetry({
|
|
9609
|
-
allProjects,
|
|
9610
|
-
selectedProjects: storybookProjects,
|
|
9611
|
-
projectResults: automigrationResults2,
|
|
9612
|
-
doctorResults
|
|
10434
|
+
logger25.step("Checking the health of your project(s).."), doctorResults = await runMultiProjectDoctor(doctorProjects), displayDoctorResults(doctorResults) && logTracker3.enableLogWriting(), logUpgradeResults(automigrationResults2, detectedAutomigrations, doctorResults);
|
|
10435
|
+
for (let project of storybookProjects) {
|
|
10436
|
+
let resultData = automigrationResults2[project.configDir] || {
|
|
10437
|
+
automigrationStatuses: {},
|
|
10438
|
+
automigrationErrors: {}
|
|
10439
|
+
}, doctorFailureCount = 0, doctorErrorCount = 0;
|
|
10440
|
+
Object.values(doctorResults[project.configDir]?.diagnostics || {}).forEach((status) => {
|
|
10441
|
+
status === "has_issues" && doctorFailureCount++, status === "check_error" && doctorErrorCount++;
|
|
10442
|
+
});
|
|
10443
|
+
let automigrationFailureCount = Object.keys(resultData.automigrationErrors).length, automigrationPreCheckFailure = project.autoblockerCheckResults && project.autoblockerCheckResults.length > 0 ? project.autoblockerCheckResults?.map((result) => result.result !== null ? result.blocker.id : null).filter(Boolean) : null;
|
|
10444
|
+
await telemetry2("upgrade", {
|
|
10445
|
+
beforeVersion: project.beforeVersion,
|
|
10446
|
+
afterVersion: project.currentCLIVersion,
|
|
10447
|
+
automigrationResults: resultData.automigrationStatuses,
|
|
10448
|
+
automigrationErrors: resultData.automigrationErrors,
|
|
10449
|
+
automigrationFailureCount,
|
|
10450
|
+
automigrationPreCheckFailure,
|
|
10451
|
+
doctorResults: doctorResults[project.configDir]?.diagnostics || {},
|
|
10452
|
+
doctorFailureCount,
|
|
10453
|
+
doctorErrorCount
|
|
9613
10454
|
});
|
|
9614
10455
|
}
|
|
10456
|
+
await sendMultiUpgradeTelemetry({
|
|
10457
|
+
allProjects,
|
|
10458
|
+
selectedProjects: storybookProjects,
|
|
10459
|
+
projectResults: automigrationResults2,
|
|
10460
|
+
doctorResults
|
|
10461
|
+
});
|
|
9615
10462
|
} finally {
|
|
9616
10463
|
process.removeListener("SIGINT", handleInterruption), process.removeListener("SIGTERM", handleInterruption);
|
|
9617
10464
|
}
|
|
@@ -9620,13 +10467,13 @@ Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgrade
|
|
|
9620
10467
|
// src/bin/run.ts
|
|
9621
10468
|
addToGlobalContext("cliVersion", versions5.storybook);
|
|
9622
10469
|
var handleCommandFailure = (logFilePath) => async (error) => {
|
|
9623
|
-
error instanceof
|
|
10470
|
+
error instanceof HandledError3 || logger26.error(String(error));
|
|
9624
10471
|
try {
|
|
9625
10472
|
let logFile = await logTracker4.writeToFile(logFilePath);
|
|
9626
|
-
|
|
10473
|
+
logger26.log(`Debug logs are written to: ${logFile}`);
|
|
9627
10474
|
} catch {
|
|
9628
10475
|
}
|
|
9629
|
-
|
|
10476
|
+
logger26.outro(""), process.exit(1);
|
|
9630
10477
|
}, command = (name) => program.command(name).option(
|
|
9631
10478
|
"--disable-telemetry",
|
|
9632
10479
|
"Disable sending telemetry data",
|
|
@@ -9636,34 +10483,30 @@ var handleCommandFailure = (logFilePath) => async (error) => {
|
|
|
9636
10483
|
"Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided"
|
|
9637
10484
|
).option("--loglevel <trace | debug | info | warn | error | silent>", "Define log level", "info").hook("preAction", async (self2) => {
|
|
9638
10485
|
let options = self2.opts();
|
|
9639
|
-
options.debug &&
|
|
10486
|
+
options.debug && logger26.setLogLevel("debug"), options.loglevel && logger26.setLogLevel(options.loglevel), options.logfile && logTracker4.enableLogWriting();
|
|
9640
10487
|
try {
|
|
9641
10488
|
await globalSettings();
|
|
9642
10489
|
} catch (e) {
|
|
9643
|
-
|
|
10490
|
+
logger26.error(`Error loading global settings:
|
|
9644
10491
|
` + String(e));
|
|
9645
10492
|
}
|
|
9646
10493
|
}).hook("postAction", async (command2) => {
|
|
9647
10494
|
if (logTracker4.shouldWriteLogsToFile) {
|
|
9648
10495
|
try {
|
|
9649
10496
|
let logFile = await logTracker4.writeToFile(command2.getOptionValue("logfile"));
|
|
9650
|
-
|
|
10497
|
+
logger26.log(`Debug logs are written to: ${logFile}`);
|
|
9651
10498
|
} catch {
|
|
9652
10499
|
}
|
|
9653
|
-
|
|
10500
|
+
logger26.outro(CLI_COLORS5.success("Done!"));
|
|
9654
10501
|
}
|
|
9655
10502
|
});
|
|
9656
10503
|
command("init").description("Initialize Storybook into your project").option("-f --force", "Force add Storybook").option("-s --skip-install", "Skip installing deps").addOption(
|
|
9657
10504
|
new Option("--package-manager <type>", "Force package manager for installing deps").choices(
|
|
9658
10505
|
Object.values(PackageManagerName3)
|
|
9659
10506
|
)
|
|
9660
|
-
).option("--use-pnp", "Enable PnP mode for Yarn 2+").option("-p --parser <babel | babylon | flow | ts | tsx>", "jscodeshift parser").option("-t --type <type>", "Add Storybook for a specific project type").option("-y --yes", "Answer yes to all prompts").option("-b --builder <webpack5 | vite>", "Builder library").option("-l --linkable", "Prepare installation for link (contributor helper)").option(
|
|
9661
|
-
"--dev",
|
|
9662
|
-
"Launch the development server after completing initialization. Enabled by default (default: true)",
|
|
9663
|
-
!isCI2() && !optionalEnvToBoolean3(process.env.IN_STORYBOOK_SANDBOX)
|
|
9664
|
-
).option(
|
|
10507
|
+
).option("--use-pnp", "Enable PnP mode for Yarn 2+").option("-p --parser <babel | babylon | flow | ts | tsx>", "jscodeshift parser").option("-t --type <type>", "Add Storybook for a specific project type").option("-y --yes", "Answer yes to all prompts").option("-b --builder <webpack5 | vite>", "Builder library").option("-l --linkable", "Prepare installation for link (contributor helper)").option("--dev", "Launch the development server after completing initialization").option(
|
|
9665
10508
|
"--no-dev",
|
|
9666
|
-
"
|
|
10509
|
+
"Do not launch the Storybook development server after completing initialization (default)"
|
|
9667
10510
|
);
|
|
9668
10511
|
command("add <addon>").description("Add an addon to your Storybook").addOption(
|
|
9669
10512
|
new Option("--package-manager <type>", "Force package manager for installing deps").choices(
|
|
@@ -9671,7 +10514,7 @@ command("add <addon>").description("Add an addon to your Storybook").addOption(
|
|
|
9671
10514
|
)
|
|
9672
10515
|
).option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option("--skip-install", "Skip installing deps").option("-s --skip-postinstall", "Skip package specific postinstall config modifications").option("-y --yes", "Skip prompting the user").option("--skip-doctor", "Skip doctor check").action((addonName, options) => {
|
|
9673
10516
|
withTelemetry("add", { cliOptions: options }, async () => {
|
|
9674
|
-
|
|
10517
|
+
logger26.intro(`Setting up your project for ${addonName}`), await add(addonName, options), await telemetry3("add", { addon: addonName, source: "cli" }), logger26.outro("Done!");
|
|
9675
10518
|
}).catch(handleCommandFailure);
|
|
9676
10519
|
});
|
|
9677
10520
|
command("remove <addon>").description("Remove an addon from your Storybook").addOption(
|
|
@@ -9680,7 +10523,7 @@ command("remove <addon>").description("Remove an addon from your Storybook").add
|
|
|
9680
10523
|
)
|
|
9681
10524
|
).option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option("-s --skip-install", "Skip installing deps").action(
|
|
9682
10525
|
(addonName, options) => withTelemetry("remove", { cliOptions: options }, async () => {
|
|
9683
|
-
|
|
10526
|
+
logger26.intro(`Removing ${addonName} from your Storybook`);
|
|
9684
10527
|
let packageManager = JsPackageManagerFactory3.getPackageManager({
|
|
9685
10528
|
configDir: options.configDir,
|
|
9686
10529
|
force: options.packageManager
|
|
@@ -9689,7 +10532,7 @@ command("remove <addon>").description("Remove an addon from your Storybook").add
|
|
|
9689
10532
|
configDir: options.configDir,
|
|
9690
10533
|
packageManager,
|
|
9691
10534
|
skipInstall: options.skipInstall
|
|
9692
|
-
}),
|
|
10535
|
+
}), await telemetry3("remove", { addon: addonName, source: "cli" }), logger26.outro("Done!");
|
|
9693
10536
|
}).catch(handleCommandFailure(options.logfile))
|
|
9694
10537
|
);
|
|
9695
10538
|
command("upgrade").description(`Upgrade your Storybook packages to v${versions5.storybook}`).addOption(
|
|
@@ -9697,6 +10540,9 @@ command("upgrade").description(`Upgrade your Storybook packages to v${versions5.
|
|
|
9697
10540
|
Object.values(PackageManagerName3)
|
|
9698
10541
|
)
|
|
9699
10542
|
).option("-y --yes", "Skip prompting the user").option("-f --force", "force the upgrade, skipping autoblockers").option("-n --dry-run", "Only check for upgrades, do not install").option("-s --skip-check", "Skip postinstall version and automigration checks").option(
|
|
10543
|
+
"--skip-automigrations",
|
|
10544
|
+
"Skip running automigrations entirely (only update package versions and install)"
|
|
10545
|
+
).option(
|
|
9700
10546
|
"-c, --config-dir <dir-name...>",
|
|
9701
10547
|
"Directory(ies) where to load Storybook configurations from"
|
|
9702
10548
|
).action(async (options) => {
|
|
@@ -9704,12 +10550,12 @@ command("upgrade").description(`Upgrade your Storybook packages to v${versions5.
|
|
|
9704
10550
|
"upgrade",
|
|
9705
10551
|
{ cliOptions: { ...options, configDir: options.configDir?.[0] } },
|
|
9706
10552
|
async () => {
|
|
9707
|
-
|
|
10553
|
+
logger26.intro(`Storybook upgrade - v${versions5.storybook}`), await upgrade(options), logger26.outro("Storybook upgrade completed!");
|
|
9708
10554
|
}
|
|
9709
10555
|
).catch(handleCommandFailure(options.logfile));
|
|
9710
10556
|
});
|
|
9711
10557
|
command("info").description("Prints debugging information about the local environment").action(async () => {
|
|
9712
|
-
|
|
10558
|
+
logger26.log(import_picocolors18.default.bold(`
|
|
9713
10559
|
Storybook Environment Info:`));
|
|
9714
10560
|
let activePackageManager = JsPackageManagerFactory3.getPackageManager().type.replace(/\d/, ""), output = await import_envinfo.default.run({
|
|
9715
10561
|
System: ["OS", "CPU", "Shell"],
|
|
@@ -9718,10 +10564,10 @@ Storybook Environment Info:`));
|
|
|
9718
10564
|
npmPackages: "{@storybook/*,*storybook*,sb,chromatic}",
|
|
9719
10565
|
npmGlobalPackages: "{@storybook/*,*storybook*,sb,chromatic}"
|
|
9720
10566
|
}), activePackageManagerLine = output.match(new RegExp(`${activePackageManager}:.*`, "i"));
|
|
9721
|
-
|
|
10567
|
+
logger26.log(
|
|
9722
10568
|
output.replace(
|
|
9723
10569
|
activePackageManagerLine,
|
|
9724
|
-
|
|
10570
|
+
import_picocolors18.default.bold(`${activePackageManagerLine} <----- active`)
|
|
9725
10571
|
)
|
|
9726
10572
|
);
|
|
9727
10573
|
});
|
|
@@ -9733,12 +10579,12 @@ command("migrate [migration]").description("Run a Storybook codemod migration on
|
|
|
9733
10579
|
'Rename suffix of matching files after codemod has been applied, e.g. ".js:.ts"'
|
|
9734
10580
|
).action((migration, options) => {
|
|
9735
10581
|
withTelemetry("migrate", { cliOptions: options }, async () => {
|
|
9736
|
-
|
|
10582
|
+
logger26.intro(`Running ${migration} migration`), await migrate(migration, options), logger26.outro("Migration completed");
|
|
9737
10583
|
}).catch(handleCommandFailure(options.logfile));
|
|
9738
10584
|
});
|
|
9739
10585
|
command("sandbox [filterValue]").alias("repro").description("Create a sandbox from a set of possible templates").option("-o --output <outDir>", "Define an output directory").option("--no-init", "Whether to download a template without an initialized Storybook", !1).action((filterValue, options) => {
|
|
9740
|
-
|
|
9741
|
-
|
|
10586
|
+
logger26.intro("Creating a Storybook sandbox..."), sandbox({ filterValue, ...options }).catch(handleCommandFailure).finally(() => {
|
|
10587
|
+
logger26.outro("Done!");
|
|
9742
10588
|
});
|
|
9743
10589
|
});
|
|
9744
10590
|
command("link <repo-url-or-directory>").description("Pull down a repro from a URL (or a local directory), link it, and run storybook").option("--local", "Link a local directory already in your file system").option("--no-start", "Start the storybook", !0).action(
|
|
@@ -9753,7 +10599,7 @@ command("automigrate [fixId]").description("Check storybook for incompatibilitie
|
|
|
9753
10599
|
"The renderer package for the framework Storybook is using."
|
|
9754
10600
|
).option("--skip-doctor", "Skip doctor check").option("--glob <pattern>", "Glob pattern for story files (for csf-factories codemod)").action(async (fixId, options) => {
|
|
9755
10601
|
withTelemetry("automigrate", { cliOptions: options }, async () => {
|
|
9756
|
-
|
|
10602
|
+
logger26.intro(fixId ? `Running ${fixId} automigration` : "Running automigrations"), await doAutomigrate({ fixId, ...options }), logger26.outro("Done");
|
|
9757
10603
|
}).catch(handleCommandFailure(options.logfile));
|
|
9758
10604
|
});
|
|
9759
10605
|
command("doctor").description("Check Storybook for known problems and provide suggestions or fixes").addOption(
|
|
@@ -9762,13 +10608,30 @@ command("doctor").description("Check Storybook for known problems and provide su
|
|
|
9762
10608
|
)
|
|
9763
10609
|
).option("-c, --config-dir <dir-name>", "Directory of Storybook configuration").action(async (options) => {
|
|
9764
10610
|
withTelemetry("doctor", { cliOptions: options }, async () => {
|
|
9765
|
-
|
|
10611
|
+
logger26.intro("Doctoring Storybook"), await doctor(options), logger26.outro("Done");
|
|
9766
10612
|
}).catch(handleCommandFailure(options.logfile));
|
|
9767
10613
|
});
|
|
10614
|
+
var aiCommand = command("ai").description("AI agent helpers for Storybook").option(
|
|
10615
|
+
"-o, --output <path>",
|
|
10616
|
+
"Write the prompt output to a file instead of printing it to stdout"
|
|
10617
|
+
);
|
|
10618
|
+
aiCommand.command("setup").description("Generate setup instructions to write stories for real components").addOption(
|
|
10619
|
+
new Option("--package-manager <type>", "Force package manager for installing deps").choices(
|
|
10620
|
+
Object.values(PackageManagerName3)
|
|
10621
|
+
)
|
|
10622
|
+
).option("-c, --config-dir <dir-name>", "Directory of Storybook configuration").action(async (options, cmd) => {
|
|
10623
|
+
let parentOptions = cmd.parent?.opts() ?? {}, runId = Math.random().toString(36), mergedOptions = { ...parentOptions, ...options, runId };
|
|
10624
|
+
await withTelemetry("ai-setup", { cliOptions: mergedOptions }, async () => {
|
|
10625
|
+
await aiSetup(mergedOptions);
|
|
10626
|
+
}).catch(handleCommandFailure(mergedOptions.logfile));
|
|
10627
|
+
});
|
|
10628
|
+
aiCommand.action(() => {
|
|
10629
|
+
aiCommand.outputHelp();
|
|
10630
|
+
});
|
|
9768
10631
|
program.on("command:*", ([invalidCmd]) => {
|
|
9769
|
-
let errorMessage = ` Invalid command: ${
|
|
10632
|
+
let errorMessage = ` Invalid command: ${import_picocolors18.default.bold(invalidCmd)}.
|
|
9770
10633
|
See --help for a list of available commands.`, suggestion = program.commands.map((cmd) => cmd.name()).find((cmd) => leven(cmd, invalidCmd) < 3);
|
|
9771
10634
|
suggestion && (errorMessage += `
|
|
9772
|
-
Did you mean ${
|
|
10635
|
+
Did you mean ${import_picocolors18.default.yellow(suggestion)}?`), logger26.error(errorMessage), process.exit(1);
|
|
9773
10636
|
});
|
|
9774
10637
|
program.usage("<command> [options]").version(String(version)).parse(process.argv);
|