@storybook/cli 10.1.0-alpha.11 → 10.1.0-alpha.13
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-BSOWKUBK.js → block-dependencies-versions-SS4BDH5O.js} +11 -11
- package/dist/_node-chunks/{block-experimental-addon-test-NCLKFTFM.js → block-experimental-addon-test-P7QACEDC.js} +9 -9
- package/dist/_node-chunks/{block-major-version-APSLHSTD.js → block-major-version-VZZEBR2I.js} +9 -9
- package/dist/_node-chunks/{block-node-version-7KHFZLS3.js → block-node-version-GTG6EMC6.js} +9 -9
- package/dist/_node-chunks/{block-webpack5-frameworks-LITSHF6U.js → block-webpack5-frameworks-5M5LRWBZ.js} +11 -11
- package/dist/_node-chunks/{chunk-L3YQORQI.js → chunk-6W4VQEQU.js} +7 -7
- package/dist/_node-chunks/chunk-7YBSMZ26.js +591 -0
- package/dist/_node-chunks/{chunk-E5Z34X6V.js → chunk-F7UQW24R.js} +6 -6
- package/dist/_node-chunks/{chunk-B4S5ZX67.js → chunk-LDMUFWYZ.js} +7 -7
- package/dist/_node-chunks/chunk-XAG3F7AB.js +11 -0
- package/dist/_node-chunks/{globby-IWIML67A.js → globby-ZADA2ALJ.js} +8 -8
- package/dist/_node-chunks/{p-limit-DF2LUMCM.js → p-limit-DSW6PYCD.js} +7 -7
- package/dist/_node-chunks/{run-OYHFTFCG.js → run-VPUT3EEF.js} +593 -608
- package/dist/bin/index.js +7 -7
- package/package.json +4 -8
- package/dist/_node-chunks/chunk-44HOCZ5E.js +0 -11
- package/dist/_node-chunks/chunk-RIDG5WQZ.js +0 -1340
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_87zcmh4d65e from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_87zcmh4d65e from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_87zcmh4d65e from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_87zcmh4d65e.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_87zcmh4d65e.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_87zcmh4d65e.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -25,18 +25,18 @@ import {
|
|
|
25
25
|
shortenPath,
|
|
26
26
|
updateMainConfig,
|
|
27
27
|
upgradeStorybookDependencies
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-7YBSMZ26.js";
|
|
29
29
|
import {
|
|
30
30
|
slash
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-6W4VQEQU.js";
|
|
32
32
|
import {
|
|
33
33
|
require_semver
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-LDMUFWYZ.js";
|
|
35
35
|
import {
|
|
36
36
|
__commonJS,
|
|
37
37
|
__require,
|
|
38
38
|
__toESM
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-F7UQW24R.js";
|
|
40
40
|
|
|
41
41
|
// ../../node_modules/envinfo/dist/envinfo.js
|
|
42
42
|
var require_envinfo = __commonJS({
|
|
@@ -4694,13 +4694,13 @@ var require_cross_spawn = __commonJS({
|
|
|
4694
4694
|
let parsed = parse2(command2, args, options), spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
4695
4695
|
return enoent.hookChildProcess(spawned, parsed), spawned;
|
|
4696
4696
|
}
|
|
4697
|
-
function
|
|
4697
|
+
function spawnSync4(command2, args, options) {
|
|
4698
4698
|
let parsed = parse2(command2, args, options), result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
4699
4699
|
return result.error = result.error || enoent.verifyENOENTSync(result.status, parsed), result;
|
|
4700
4700
|
}
|
|
4701
4701
|
module.exports = spawn;
|
|
4702
4702
|
module.exports.spawn = spawn;
|
|
4703
|
-
module.exports.sync =
|
|
4703
|
+
module.exports.sync = spawnSync4;
|
|
4704
4704
|
module.exports._parse = parse2;
|
|
4705
4705
|
module.exports._enoent = enoent;
|
|
4706
4706
|
}
|
|
@@ -4715,10 +4715,10 @@ import {
|
|
|
4715
4715
|
isCI as isCI2,
|
|
4716
4716
|
optionalEnvToBoolean as optionalEnvToBoolean3,
|
|
4717
4717
|
removeAddon as remove,
|
|
4718
|
-
versions as
|
|
4718
|
+
versions as versions4
|
|
4719
4719
|
} from "storybook/internal/common";
|
|
4720
|
-
import { withTelemetry
|
|
4721
|
-
import { CLI_COLORS as
|
|
4720
|
+
import { withTelemetry } from "storybook/internal/core-server";
|
|
4721
|
+
import { CLI_COLORS as CLI_COLORS5, logTracker as logTracker4, logger as logger22 } from "storybook/internal/node-logger";
|
|
4722
4722
|
import { addToGlobalContext, telemetry as telemetry2 } from "storybook/internal/telemetry";
|
|
4723
4723
|
import { program } from "commander";
|
|
4724
4724
|
|
|
@@ -4757,123 +4757,19 @@ function leven(first, second, options) {
|
|
|
4757
4757
|
}
|
|
4758
4758
|
|
|
4759
4759
|
// src/bin/run.ts
|
|
4760
|
-
var
|
|
4760
|
+
var import_picocolors16 = __toESM(require_picocolors(), 1);
|
|
4761
4761
|
|
|
4762
4762
|
// package.json
|
|
4763
|
-
var version = "10.1.0-alpha.
|
|
4763
|
+
var version = "10.1.0-alpha.13";
|
|
4764
4764
|
|
|
4765
4765
|
// src/add.ts
|
|
4766
4766
|
var import_semver = __toESM(require_semver(), 1);
|
|
4767
|
-
import {
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
versions
|
|
4771
|
-
} from "storybook/internal/common";
|
|
4772
|
-
import { readConfig, writeConfig } from "storybook/internal/csf-tools";
|
|
4767
|
+
import { setupAddonInConfig, versions } from "storybook/internal/common";
|
|
4768
|
+
import { readConfig } from "storybook/internal/csf-tools";
|
|
4769
|
+
import { logger as nodeLogger } from "storybook/internal/node-logger";
|
|
4773
4770
|
import { prompt } from "storybook/internal/node-logger";
|
|
4774
4771
|
import { dedent } from "ts-dedent";
|
|
4775
4772
|
|
|
4776
|
-
// src/automigrate/fixes/wrap-getAbsolutePath-utils.ts
|
|
4777
|
-
import { types as t } from "storybook/internal/babel";
|
|
4778
|
-
var PREFERRED_GET_ABSOLUTE_PATH_WRAPPER_NAME = "getAbsolutePath", ALTERNATIVE_GET_ABSOLUTE_PATH_WRAPPER_NAME = "wrapForPnp";
|
|
4779
|
-
function doesVariableOrFunctionDeclarationExist(node, name) {
|
|
4780
|
-
return t.isVariableDeclaration(node) && node.declarations.length === 1 && t.isVariableDeclarator(node.declarations[0]) && t.isIdentifier(node.declarations[0].id) && node.declarations[0].id?.name === name || t.isFunctionDeclaration(node) && t.isIdentifier(node.id) && node.id.name === name;
|
|
4781
|
-
}
|
|
4782
|
-
function getReferenceToGetAbsolutePathWrapper(config, value) {
|
|
4783
|
-
return t.callExpression(
|
|
4784
|
-
t.identifier(getAbsolutePathWrapperName(config) ?? PREFERRED_GET_ABSOLUTE_PATH_WRAPPER_NAME),
|
|
4785
|
-
[t.stringLiteral(value)]
|
|
4786
|
-
);
|
|
4787
|
-
}
|
|
4788
|
-
function getAbsolutePathWrapperName(config) {
|
|
4789
|
-
let declarationName = config.getBodyDeclarations().flatMap(
|
|
4790
|
-
(node) => doesVariableOrFunctionDeclarationExist(node, ALTERNATIVE_GET_ABSOLUTE_PATH_WRAPPER_NAME) ? [ALTERNATIVE_GET_ABSOLUTE_PATH_WRAPPER_NAME] : doesVariableOrFunctionDeclarationExist(node, PREFERRED_GET_ABSOLUTE_PATH_WRAPPER_NAME) ? [PREFERRED_GET_ABSOLUTE_PATH_WRAPPER_NAME] : []
|
|
4791
|
-
);
|
|
4792
|
-
return declarationName.length ? declarationName[0] : null;
|
|
4793
|
-
}
|
|
4794
|
-
function isGetAbsolutePathWrapperNecessary(node, cb = () => {
|
|
4795
|
-
}) {
|
|
4796
|
-
if (t.isStringLiteral(node))
|
|
4797
|
-
return cb(node), !0;
|
|
4798
|
-
if (t.isObjectExpression(node)) {
|
|
4799
|
-
let nameProperty = node.properties.find(
|
|
4800
|
-
(property) => t.isObjectProperty(property) && t.isIdentifier(property.key) && property.key.name === "name"
|
|
4801
|
-
);
|
|
4802
|
-
if (nameProperty && t.isStringLiteral(nameProperty.value))
|
|
4803
|
-
return cb(nameProperty), !0;
|
|
4804
|
-
}
|
|
4805
|
-
return t.isArrayExpression(node) && node.elements.some((element) => element && isGetAbsolutePathWrapperNecessary(element)) ? (cb(node), !0) : !1;
|
|
4806
|
-
}
|
|
4807
|
-
function getFieldsForGetAbsolutePathWrapper(config) {
|
|
4808
|
-
let frameworkNode = config.getFieldNode(["framework"]), builderNode = config.getFieldNode(["core", "builder"]), rendererNode = config.getFieldNode(["core", "renderer"]), addons = config.getFieldNode(["addons"]);
|
|
4809
|
-
return [
|
|
4810
|
-
...frameworkNode ? [frameworkNode] : [],
|
|
4811
|
-
...builderNode ? [builderNode] : [],
|
|
4812
|
-
...rendererNode ? [rendererNode] : [],
|
|
4813
|
-
...addons && t.isArrayExpression(addons) ? [addons] : []
|
|
4814
|
-
];
|
|
4815
|
-
}
|
|
4816
|
-
function getAbsolutePathWrapperAsCallExpression(isConfigTypescript) {
|
|
4817
|
-
let functionDeclaration = {
|
|
4818
|
-
...t.functionDeclaration(
|
|
4819
|
-
t.identifier(PREFERRED_GET_ABSOLUTE_PATH_WRAPPER_NAME),
|
|
4820
|
-
[
|
|
4821
|
-
{
|
|
4822
|
-
...t.identifier("value"),
|
|
4823
|
-
...isConfigTypescript ? { typeAnnotation: t.tsTypeAnnotation(t.tSStringKeyword()) } : {}
|
|
4824
|
-
}
|
|
4825
|
-
],
|
|
4826
|
-
t.blockStatement([
|
|
4827
|
-
t.returnStatement(
|
|
4828
|
-
t.callExpression(t.identifier("dirname"), [
|
|
4829
|
-
t.callExpression(t.identifier("fileURLToPath"), [
|
|
4830
|
-
t.callExpression(
|
|
4831
|
-
t.memberExpression(
|
|
4832
|
-
t.metaProperty(t.identifier("import"), t.identifier("meta")),
|
|
4833
|
-
t.identifier("resolve")
|
|
4834
|
-
),
|
|
4835
|
-
[
|
|
4836
|
-
t.templateLiteral(
|
|
4837
|
-
[
|
|
4838
|
-
t.templateElement({ raw: "" }),
|
|
4839
|
-
t.templateElement({ raw: "/package.json" }, !0)
|
|
4840
|
-
],
|
|
4841
|
-
[t.identifier("value")]
|
|
4842
|
-
)
|
|
4843
|
-
]
|
|
4844
|
-
)
|
|
4845
|
-
])
|
|
4846
|
-
])
|
|
4847
|
-
)
|
|
4848
|
-
])
|
|
4849
|
-
),
|
|
4850
|
-
...isConfigTypescript ? { returnType: t.tSTypeAnnotation(t.tsAnyKeyword()) } : {}
|
|
4851
|
-
};
|
|
4852
|
-
return t.addComment(
|
|
4853
|
-
functionDeclaration,
|
|
4854
|
-
"leading",
|
|
4855
|
-
`*
|
|
4856
|
-
* This function is used to resolve the absolute path of a package.
|
|
4857
|
-
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
|
4858
|
-
`
|
|
4859
|
-
), functionDeclaration;
|
|
4860
|
-
}
|
|
4861
|
-
function wrapValueWithGetAbsolutePathWrapper(config, node) {
|
|
4862
|
-
isGetAbsolutePathWrapperNecessary(node, (n) => {
|
|
4863
|
-
if (t.isStringLiteral(n)) {
|
|
4864
|
-
let wrapperNode = getReferenceToGetAbsolutePathWrapper(config, n.value);
|
|
4865
|
-
Object.keys(n).forEach((k) => {
|
|
4866
|
-
delete n[k];
|
|
4867
|
-
}), Object.keys(wrapperNode).forEach((k) => {
|
|
4868
|
-
n[k] = wrapperNode[k];
|
|
4869
|
-
});
|
|
4870
|
-
}
|
|
4871
|
-
t.isObjectProperty(n) && t.isStringLiteral(n.value) && (n.value = getReferenceToGetAbsolutePathWrapper(config, n.value.value)), t.isArrayExpression(n) && n.elements.forEach((element) => {
|
|
4872
|
-
element && isGetAbsolutePathWrapperNecessary(element) && wrapValueWithGetAbsolutePathWrapper(config, element);
|
|
4873
|
-
});
|
|
4874
|
-
});
|
|
4875
|
-
}
|
|
4876
|
-
|
|
4877
4773
|
// src/postinstallAddon.ts
|
|
4878
4774
|
import { createRequire as createRequire2 } from "node:module";
|
|
4879
4775
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -5104,15 +5000,15 @@ var DIR_CWD = process.cwd(), require2 = createRequire2(DIR_CWD), postinstallAddo
|
|
|
5104
5000
|
} catch {
|
|
5105
5001
|
return;
|
|
5106
5002
|
}
|
|
5107
|
-
let postinstall = moduledLoaded?.default || moduledLoaded?.postinstall || moduledLoaded;
|
|
5003
|
+
let postinstall = moduledLoaded?.default || moduledLoaded?.postinstall || moduledLoaded, logger23 = options.logger;
|
|
5108
5004
|
if (!postinstall || typeof postinstall != "function") {
|
|
5109
|
-
|
|
5005
|
+
logger23.error(`Error finding postinstall function for ${addonName}`);
|
|
5110
5006
|
return;
|
|
5111
5007
|
}
|
|
5112
5008
|
try {
|
|
5113
|
-
|
|
5009
|
+
await postinstall(options);
|
|
5114
5010
|
} catch (e) {
|
|
5115
|
-
|
|
5011
|
+
throw e;
|
|
5116
5012
|
}
|
|
5117
5013
|
};
|
|
5118
5014
|
|
|
@@ -5127,7 +5023,7 @@ async function add(addon, {
|
|
|
5127
5023
|
configDir: userSpecifiedConfigDir,
|
|
5128
5024
|
yes,
|
|
5129
5025
|
skipInstall
|
|
5130
|
-
},
|
|
5026
|
+
}, logger23 = nodeLogger) {
|
|
5131
5027
|
let [addonName, inputVersion] = getVersionSpecifier(addon), { mainConfig, mainConfigPath, configDir, previewConfigPath, packageManager } = await getStorybookData({
|
|
5132
5028
|
configDir: userSpecifiedConfigDir,
|
|
5133
5029
|
packageManagerName: pkgMgr
|
|
@@ -5137,16 +5033,16 @@ async function add(addon, {
|
|
|
5137
5033
|
Unable to find storybook config directory. Please specify your Storybook config directory with the --config-dir flag.
|
|
5138
5034
|
`);
|
|
5139
5035
|
if (!mainConfigPath) {
|
|
5140
|
-
|
|
5036
|
+
logger23.error("Unable to find Storybook main.js config");
|
|
5141
5037
|
return;
|
|
5142
5038
|
}
|
|
5143
5039
|
let shouldAddToMain = !0;
|
|
5144
|
-
if (checkInstalled(addonName, mainConfig) && (shouldAddToMain = !1, !yes && (
|
|
5040
|
+
if (checkInstalled(addonName, mainConfig) && (shouldAddToMain = !1, !yes && (logger23.log(`The Storybook addon "${addonName}" is already present in ${mainConfigPath}.`), !await prompt.confirm({
|
|
5145
5041
|
message: "Do you wish to install it again?"
|
|
5146
5042
|
}))))
|
|
5147
5043
|
return;
|
|
5148
5044
|
let main = await readConfig(mainConfigPath);
|
|
5149
|
-
|
|
5045
|
+
logger23.log(`Verifying ${addonName}`);
|
|
5150
5046
|
let version2 = inputVersion;
|
|
5151
5047
|
if (!version2 && isCoreAddon(addonName) && (version2 = versions.storybook), !version2) {
|
|
5152
5048
|
let latestVersion = await packageManager.latestVersion(addonName);
|
|
@@ -5155,30 +5051,24 @@ async function add(addon, {
|
|
|
5155
5051
|
version2 = latestVersion;
|
|
5156
5052
|
}
|
|
5157
5053
|
let storybookVersion = versions.storybook, versionIsStorybook = version2 === versions.storybook;
|
|
5158
|
-
isCoreAddon(addonName) && !versionIsStorybook &&
|
|
5054
|
+
isCoreAddon(addonName) && !versionIsStorybook && logger23.warn(
|
|
5159
5055
|
`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.`
|
|
5160
5056
|
);
|
|
5161
5057
|
let versionRange = packageManager.getDependencyVersion("storybook")?.match(/^[~^]/)?.[0] ?? "", addonWithVersion = versionIsStorybook ? `${addonName}@${versionRange}${storybookVersion}` : isValidVersion(version2) && !version2.includes("-pr-") ? `${addonName}@^${version2}` : `${addonName}@${version2}`;
|
|
5162
|
-
|
|
5058
|
+
logger23.log(`Installing ${addonWithVersion}`), await packageManager.addDependencies(
|
|
5163
5059
|
{ type: "devDependencies", writeOutputToFile: !1, skipInstall },
|
|
5164
5060
|
[addonWithVersion]
|
|
5165
|
-
), shouldAddToMain) {
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
await writeConfig(main);
|
|
5172
|
-
}
|
|
5173
|
-
try {
|
|
5174
|
-
let newMainConfig = await loadMainConfig({ configDir, skipCache: !0 });
|
|
5175
|
-
await syncStorybookAddons(newMainConfig, previewConfigPath, configDir);
|
|
5176
|
-
} catch {
|
|
5177
|
-
}
|
|
5178
|
-
!skipPostinstall && isCoreAddon(addonName) && await postinstallAddon(addonName, {
|
|
5061
|
+
), shouldAddToMain && (logger23.log(`Adding '${addon}' to the "addons" field in ${mainConfigPath}`), await setupAddonInConfig({
|
|
5062
|
+
addonName,
|
|
5063
|
+
mainConfigCSFFile: main,
|
|
5064
|
+
previewConfigPath,
|
|
5065
|
+
configDir
|
|
5066
|
+
})), !skipPostinstall && isCoreAddon(addonName) && await postinstallAddon(addonName, {
|
|
5179
5067
|
packageManager: packageManager.type,
|
|
5180
5068
|
configDir,
|
|
5181
5069
|
yes,
|
|
5070
|
+
logger: logger23,
|
|
5071
|
+
prompt,
|
|
5182
5072
|
skipInstall
|
|
5183
5073
|
});
|
|
5184
5074
|
}
|
|
@@ -5188,7 +5078,8 @@ function isValidVersion(version2) {
|
|
|
5188
5078
|
|
|
5189
5079
|
// src/automigrate/index.ts
|
|
5190
5080
|
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
5191
|
-
import { logTracker as logTracker2, logger as
|
|
5081
|
+
import { logTracker as logTracker2, logger as logger16, prompt as prompt3 } from "storybook/internal/node-logger";
|
|
5082
|
+
import { AutomigrateError } from "storybook/internal/server-errors";
|
|
5192
5083
|
|
|
5193
5084
|
// ../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
5194
5085
|
var isProduction = process.env.NODE_ENV === "production", prefix = "Invariant failed";
|
|
@@ -5216,18 +5107,18 @@ import { frameworkPackages, rendererPackages } from "storybook/internal/common";
|
|
|
5216
5107
|
|
|
5217
5108
|
// src/doctor/hasMultipleVersions.ts
|
|
5218
5109
|
var import_semver2 = __toESM(require_semver(), 1);
|
|
5219
|
-
function hasMultipleVersions(
|
|
5220
|
-
return
|
|
5110
|
+
function hasMultipleVersions(versions5) {
|
|
5111
|
+
return versions5.find((v) => {
|
|
5221
5112
|
let major = import_semver2.default.major(v);
|
|
5222
5113
|
if (major === 0) {
|
|
5223
5114
|
let minor = import_semver2.default.minor(v);
|
|
5224
5115
|
if (minor === 0) {
|
|
5225
5116
|
let patch = import_semver2.default.patch(v);
|
|
5226
|
-
return
|
|
5117
|
+
return versions5.some((v2) => import_semver2.default.patch(v2) !== patch);
|
|
5227
5118
|
}
|
|
5228
|
-
return
|
|
5119
|
+
return versions5.some((v2) => import_semver2.default.minor(v2) !== minor);
|
|
5229
5120
|
}
|
|
5230
|
-
return
|
|
5121
|
+
return versions5.some((v2) => import_semver2.default.major(v2) !== major);
|
|
5231
5122
|
});
|
|
5232
5123
|
}
|
|
5233
5124
|
|
|
@@ -5719,7 +5610,7 @@ ${error}`);
|
|
|
5719
5610
|
var import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
5720
5611
|
import {
|
|
5721
5612
|
optionalEnvToBoolean,
|
|
5722
|
-
syncStorybookAddons
|
|
5613
|
+
syncStorybookAddons
|
|
5723
5614
|
} from "storybook/internal/common";
|
|
5724
5615
|
import { logger as logger6, prompt as prompt2 } from "storybook/internal/node-logger";
|
|
5725
5616
|
import { dedent as dedent3 } from "ts-dedent";
|
|
@@ -5732,7 +5623,7 @@ import { logger as logger3 } from "storybook/internal/node-logger";
|
|
|
5732
5623
|
import { promises as fs } from "fs";
|
|
5733
5624
|
var maxConcurrentTasks = Math.max(1, os.cpus().length - 1);
|
|
5734
5625
|
async function runCodemod(globPattern = "**/*.stories.*", transform, { dryRun = !1, skipFormatting = !1 } = {}) {
|
|
5735
|
-
let modifiedCount = 0, unmodifiedCount = 0, errorCount = 0, { globby } = await import("./globby-
|
|
5626
|
+
let modifiedCount = 0, unmodifiedCount = 0, errorCount = 0, { globby } = await import("./globby-ZADA2ALJ.js"), files = await globby(slash(globPattern), {
|
|
5736
5627
|
followSymbolicLinks: !0,
|
|
5737
5628
|
ignore: ["**/node_modules/**", "**/dist/**", "**/storybook-static/**", "**/build/**"]
|
|
5738
5629
|
});
|
|
@@ -5743,7 +5634,7 @@ Please try a different pattern.
|
|
|
5743
5634
|
`
|
|
5744
5635
|
), new Error("No files matched");
|
|
5745
5636
|
try {
|
|
5746
|
-
let pLimit = (await import("./p-limit-
|
|
5637
|
+
let pLimit = (await import("./p-limit-DSW6PYCD.js")).default, limit = pLimit(maxConcurrentTasks);
|
|
5747
5638
|
await Promise.all(
|
|
5748
5639
|
files.map(
|
|
5749
5640
|
(file) => limit(async () => {
|
|
@@ -5782,13 +5673,13 @@ Please try a different pattern.
|
|
|
5782
5673
|
|
|
5783
5674
|
// src/codemod/helpers/config-to-csf-factory.ts
|
|
5784
5675
|
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
5785
|
-
import { types as
|
|
5676
|
+
import { types as t2 } from "storybook/internal/babel";
|
|
5786
5677
|
import { formatFileContent as formatFileContent2 } from "storybook/internal/common";
|
|
5787
5678
|
import { loadConfig, printConfig } from "storybook/internal/csf-tools";
|
|
5788
5679
|
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
5789
5680
|
|
|
5790
5681
|
// src/codemod/helpers/csf-factories-utils.ts
|
|
5791
|
-
import { types as
|
|
5682
|
+
import { types as t, traverse } from "storybook/internal/babel";
|
|
5792
5683
|
var projectAnnotationNames = [
|
|
5793
5684
|
"decorators",
|
|
5794
5685
|
"parameters",
|
|
@@ -5820,11 +5711,11 @@ function cleanupTypeImports(programNode, disallowList2) {
|
|
|
5820
5711
|
} catch {
|
|
5821
5712
|
}
|
|
5822
5713
|
return programNode.body.filter((node) => {
|
|
5823
|
-
if (
|
|
5714
|
+
if (t.isImportDeclaration(node)) {
|
|
5824
5715
|
let { source, specifiers } = node;
|
|
5825
5716
|
if (source.value.startsWith("@storybook/")) {
|
|
5826
5717
|
let allowedSpecifiers = specifiers.filter((specifier) => {
|
|
5827
|
-
if (
|
|
5718
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
|
|
5828
5719
|
let name = specifier.imported.name;
|
|
5829
5720
|
return !disallowList2.includes(name) || usedIdentifiers.has(name);
|
|
5830
5721
|
}
|
|
@@ -5838,14 +5729,14 @@ function cleanupTypeImports(programNode, disallowList2) {
|
|
|
5838
5729
|
}
|
|
5839
5730
|
function removeExportDeclarations(programNode, exportDecls) {
|
|
5840
5731
|
return programNode.body.filter((node) => {
|
|
5841
|
-
if (
|
|
5842
|
-
if (
|
|
5732
|
+
if (t.isExportNamedDeclaration(node) && node.declaration) {
|
|
5733
|
+
if (t.isVariableDeclaration(node.declaration))
|
|
5843
5734
|
return node.declaration.declarations = node.declaration.declarations.filter(
|
|
5844
|
-
(decl) =>
|
|
5735
|
+
(decl) => t.isIdentifier(decl.id) && !exportDecls[decl.id.name]
|
|
5845
5736
|
), node.declaration.declarations.length > 0;
|
|
5846
|
-
if (
|
|
5737
|
+
if (t.isFunctionDeclaration(node.declaration)) {
|
|
5847
5738
|
let funcDecl = node.declaration;
|
|
5848
|
-
return
|
|
5739
|
+
return t.isIdentifier(funcDecl.id) && !exportDecls[funcDecl.id.name];
|
|
5849
5740
|
}
|
|
5850
5741
|
}
|
|
5851
5742
|
return !0;
|
|
@@ -5854,8 +5745,8 @@ function removeExportDeclarations(programNode, exportDecls) {
|
|
|
5854
5745
|
function getConfigProperties(exportDecls, options) {
|
|
5855
5746
|
let properties = [];
|
|
5856
5747
|
for (let [name, decl] of Object.entries(exportDecls))
|
|
5857
|
-
options.configType === "preview" && !projectAnnotationNames.includes(name) || (
|
|
5858
|
-
|
|
5748
|
+
options.configType === "preview" && !projectAnnotationNames.includes(name) || (t.isVariableDeclarator(decl) && decl.init ? properties.push(t.objectProperty(t.identifier(name), decl.init)) : t.isFunctionDeclaration(decl) && properties.push(
|
|
5749
|
+
t.objectProperty(t.identifier(name), t.arrowFunctionExpression([], decl.body))
|
|
5859
5750
|
));
|
|
5860
5751
|
return properties;
|
|
5861
5752
|
}
|
|
@@ -5872,60 +5763,60 @@ ${err}`), info.source;
|
|
|
5872
5763
|
let methodName = configType === "main" ? "defineMain" : "definePreview", programNode = config._ast.program, exportDecls = config._exportDecls, defineConfigProps = getConfigProperties(exportDecls, { configType }), hasNamedExports = defineConfigProps.length > 0;
|
|
5873
5764
|
function findDeclarationNodeIndex(declarationName) {
|
|
5874
5765
|
return programNode.body.findIndex(
|
|
5875
|
-
(n) =>
|
|
5766
|
+
(n) => t2.isVariableDeclaration(n) && n.declarations.some((d) => {
|
|
5876
5767
|
let declaration = d.init;
|
|
5877
|
-
return (
|
|
5768
|
+
return (t2.isTSAsExpression(declaration) || t2.isTSSatisfiesExpression(declaration)) && (declaration = declaration.expression), t2.isIdentifier(d.id) && d.id.name === declarationName && t2.isObjectExpression(declaration);
|
|
5878
5769
|
})
|
|
5879
5770
|
);
|
|
5880
5771
|
}
|
|
5881
5772
|
if (config._exportsObject && hasNamedExports) {
|
|
5882
5773
|
config._exportsObject.properties = [...defineConfigProps, ...config._exportsObject.properties], programNode.body = removeExportDeclarations(programNode, exportDecls);
|
|
5883
|
-
let defineConfigCall =
|
|
5774
|
+
let defineConfigCall = t2.callExpression(t2.identifier(methodName), [config._exportsObject]), exportDefaultNode = null, declarationNodeIndex = -1;
|
|
5884
5775
|
programNode.body.forEach((node) => {
|
|
5885
|
-
if (
|
|
5776
|
+
if (t2.isExportDefaultDeclaration(node) && t2.isIdentifier(node.declaration)) {
|
|
5886
5777
|
let declarationName = node.declaration.name;
|
|
5887
5778
|
if (declarationNodeIndex = findDeclarationNodeIndex(declarationName), declarationNodeIndex !== -1) {
|
|
5888
5779
|
exportDefaultNode = node;
|
|
5889
5780
|
let declarationNode = programNode.body[declarationNodeIndex];
|
|
5890
|
-
if (
|
|
5781
|
+
if (t2.isVariableDeclaration(declarationNode)) {
|
|
5891
5782
|
let id = declarationNode.declarations[0].id;
|
|
5892
|
-
|
|
5783
|
+
t2.isIdentifier(id) && id.name && programNode.body.splice(declarationNodeIndex, 1);
|
|
5893
5784
|
}
|
|
5894
5785
|
}
|
|
5895
|
-
} else
|
|
5786
|
+
} else t2.isExportDefaultDeclaration(node) && t2.isObjectExpression(node.declaration) && (exportDefaultNode = node);
|
|
5896
5787
|
}), exportDefaultNode !== null && (exportDefaultNode.declaration = defineConfigCall);
|
|
5897
5788
|
} else if (config._exportsObject) {
|
|
5898
|
-
let defineConfigCall =
|
|
5789
|
+
let defineConfigCall = t2.callExpression(t2.identifier(methodName), [config._exportsObject]), exportDefaultNode = null, declarationNodeIndex = -1;
|
|
5899
5790
|
programNode.body.forEach((node) => {
|
|
5900
|
-
let declaration =
|
|
5901
|
-
if (
|
|
5791
|
+
let declaration = t2.isExportDefaultDeclaration(node) && config._unwrap(node.declaration);
|
|
5792
|
+
if (t2.isExportDefaultDeclaration(node) && t2.isIdentifier(declaration)) {
|
|
5902
5793
|
let declarationName = declaration.name;
|
|
5903
5794
|
if (declarationNodeIndex = findDeclarationNodeIndex(declarationName), declarationNodeIndex !== -1) {
|
|
5904
5795
|
exportDefaultNode = node;
|
|
5905
5796
|
let declarationNode = programNode.body[declarationNodeIndex];
|
|
5906
|
-
if (
|
|
5797
|
+
if (t2.isVariableDeclaration(declarationNode)) {
|
|
5907
5798
|
let id = declarationNode.declarations[0].id;
|
|
5908
|
-
|
|
5799
|
+
t2.isIdentifier(id) && id.name && programNode.body.splice(declarationNodeIndex, 1);
|
|
5909
5800
|
}
|
|
5910
5801
|
}
|
|
5911
|
-
} else
|
|
5802
|
+
} else t2.isExportDefaultDeclaration(node) && t2.isObjectExpression(node.declaration) && (exportDefaultNode = node);
|
|
5912
5803
|
}), exportDefaultNode !== null && (exportDefaultNode.declaration = defineConfigCall);
|
|
5913
5804
|
} else if (hasNamedExports) {
|
|
5914
|
-
let defineConfigCall =
|
|
5915
|
-
|
|
5805
|
+
let defineConfigCall = t2.callExpression(t2.identifier(methodName), [
|
|
5806
|
+
t2.objectExpression(defineConfigProps)
|
|
5916
5807
|
]);
|
|
5917
|
-
programNode.body = removeExportDeclarations(programNode, exportDecls), programNode.body.push(
|
|
5808
|
+
programNode.body = removeExportDeclarations(programNode, exportDecls), programNode.body.push(t2.exportDefaultDeclaration(defineConfigCall));
|
|
5918
5809
|
}
|
|
5919
|
-
let configImport =
|
|
5920
|
-
[
|
|
5921
|
-
|
|
5810
|
+
let configImport = t2.importDeclaration(
|
|
5811
|
+
[t2.importSpecifier(t2.identifier(methodName), t2.identifier(methodName))],
|
|
5812
|
+
t2.stringLiteral(frameworkPackage + `${configType === "main" ? "/node" : ""}`)
|
|
5922
5813
|
), existingImport = programNode.body.find(
|
|
5923
|
-
(node) =>
|
|
5814
|
+
(node) => t2.isImportDeclaration(node) && node.importKind !== "type" && node.source.value === configImport.source.value
|
|
5924
5815
|
);
|
|
5925
|
-
existingImport &&
|
|
5926
|
-
(specifier) =>
|
|
5816
|
+
existingImport && t2.isImportDeclaration(existingImport) ? existingImport.specifiers.some(
|
|
5817
|
+
(specifier) => t2.isImportSpecifier(specifier) && t2.isIdentifier(specifier.imported) && specifier.imported.name === methodName
|
|
5927
5818
|
) || existingImport.specifiers.push(
|
|
5928
|
-
|
|
5819
|
+
t2.importSpecifier(t2.identifier(methodName), t2.identifier(methodName))
|
|
5929
5820
|
) : programNode.body.unshift(configImport);
|
|
5930
5821
|
let disallowList2 = ["StorybookConfig", "Preview"];
|
|
5931
5822
|
programNode.body = cleanupTypeImports(programNode, disallowList2);
|
|
@@ -5935,11 +5826,14 @@ ${import_picocolors6.default.green(output)}`), info.source) : skipFormatting ? o
|
|
|
5935
5826
|
}
|
|
5936
5827
|
|
|
5937
5828
|
// src/codemod/helpers/story-to-csf-factory.ts
|
|
5938
|
-
import { types as t4, traverse as
|
|
5829
|
+
import { types as t4, traverse as traverse3 } from "storybook/internal/babel";
|
|
5939
5830
|
import { isValidPreviewPath, loadCsf, printCsf } from "storybook/internal/csf-tools";
|
|
5940
5831
|
import { logger as logger5 } from "storybook/internal/node-logger";
|
|
5941
5832
|
import path2 from "path";
|
|
5942
|
-
|
|
5833
|
+
|
|
5834
|
+
// src/codemod/helpers/remove-unused-types.ts
|
|
5835
|
+
import { types as t3, traverse as traverse2 } from "storybook/internal/babel";
|
|
5836
|
+
var typesDisallowList = [
|
|
5943
5837
|
"Story",
|
|
5944
5838
|
"StoryFn",
|
|
5945
5839
|
"StoryObj",
|
|
@@ -5947,7 +5841,63 @@ var reuseDisallowList = ["play", "run", "extends", "story"], typesDisallowList =
|
|
|
5947
5841
|
"MetaObj",
|
|
5948
5842
|
"ComponentStory",
|
|
5949
5843
|
"ComponentMeta"
|
|
5950
|
-
];
|
|
5844
|
+
], disallowedTypesSet = new Set(typesDisallowList);
|
|
5845
|
+
function removeUnusedTypes(programNode, ast) {
|
|
5846
|
+
let declaredTypes = /* @__PURE__ */ new Set(), referencedTypes = /* @__PURE__ */ new Set(), pendingIdentifierNames = /* @__PURE__ */ new Set(), typeDeclReferencesDisallowed = /* @__PURE__ */ new Set();
|
|
5847
|
+
traverse2(ast, {
|
|
5848
|
+
enter(path4) {
|
|
5849
|
+
let node = path4.node;
|
|
5850
|
+
if (path4.isTSTypeAliasDeclaration() || path4.isTSInterfaceDeclaration()) {
|
|
5851
|
+
let idNode = node.id, name = idNode && t3.isIdentifier(idNode) ? idNode.name : void 0;
|
|
5852
|
+
name && (declaredTypes.add(name), pendingIdentifierNames.has(name) && referencedTypes.add(name));
|
|
5853
|
+
return;
|
|
5854
|
+
}
|
|
5855
|
+
if (path4.isIdentifier()) {
|
|
5856
|
+
let name = node.name, parentPath = path4.parentPath;
|
|
5857
|
+
if (parentPath && (parentPath.isTSTypeAliasDeclaration() || parentPath.isTSInterfaceDeclaration()) && parentPath.node.id === node)
|
|
5858
|
+
return;
|
|
5859
|
+
declaredTypes.has(name) ? referencedTypes.add(name) : pendingIdentifierNames.add(name);
|
|
5860
|
+
return;
|
|
5861
|
+
}
|
|
5862
|
+
if (path4.isTSTypeReference()) {
|
|
5863
|
+
let typeNameNode = node.typeName;
|
|
5864
|
+
if (t3.isIdentifier(typeNameNode) && disallowedTypesSet.has(typeNameNode.name)) {
|
|
5865
|
+
let owner = path4.findParent(
|
|
5866
|
+
(p) => p.isTSTypeAliasDeclaration() || p.isTSInterfaceDeclaration()
|
|
5867
|
+
);
|
|
5868
|
+
if (owner && (owner.isTSTypeAliasDeclaration() || owner.isTSInterfaceDeclaration())) {
|
|
5869
|
+
let ownerId = owner.node.id, ownerName = t3.isIdentifier(ownerId) ? ownerId.name : void 0;
|
|
5870
|
+
ownerName && typeDeclReferencesDisallowed.add(ownerName);
|
|
5871
|
+
}
|
|
5872
|
+
}
|
|
5873
|
+
return;
|
|
5874
|
+
}
|
|
5875
|
+
if (path4.isTSExpressionWithTypeArguments()) {
|
|
5876
|
+
let expr = node.expression;
|
|
5877
|
+
if (t3.isIdentifier(expr) && disallowedTypesSet.has(expr.name)) {
|
|
5878
|
+
let owner = path4.findParent(
|
|
5879
|
+
(p) => p.isTSTypeAliasDeclaration() || p.isTSInterfaceDeclaration()
|
|
5880
|
+
);
|
|
5881
|
+
if (owner && (owner.isTSTypeAliasDeclaration() || owner.isTSInterfaceDeclaration())) {
|
|
5882
|
+
let ownerId = owner.node.id, ownerName = t3.isIdentifier(ownerId) ? ownerId.name : void 0;
|
|
5883
|
+
ownerName && typeDeclReferencesDisallowed.add(ownerName);
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
return;
|
|
5887
|
+
}
|
|
5888
|
+
}
|
|
5889
|
+
}), programNode.body = programNode.body.filter((node) => {
|
|
5890
|
+
if (t3.isTSTypeAliasDeclaration(node) || t3.isTSInterfaceDeclaration(node)) {
|
|
5891
|
+
let name = node.id.name;
|
|
5892
|
+
if (declaredTypes.has(name) && !referencedTypes.has(name) && typeDeclReferencesDisallowed.has(name))
|
|
5893
|
+
return !1;
|
|
5894
|
+
}
|
|
5895
|
+
return !0;
|
|
5896
|
+
}), programNode.body = cleanupTypeImports(programNode, typesDisallowList);
|
|
5897
|
+
}
|
|
5898
|
+
|
|
5899
|
+
// src/codemod/helpers/story-to-csf-factory.ts
|
|
5900
|
+
var reuseDisallowList = ["play", "run", "extends", "story"];
|
|
5951
5901
|
async function storyToCsfFactory(info, { previewConfigPath, useSubPathImports }) {
|
|
5952
5902
|
let csf = loadCsf(info.source, { makeTitle: () => "FIXME" });
|
|
5953
5903
|
try {
|
|
@@ -6002,7 +5952,7 @@ ${err}`), info.source;
|
|
|
6002
5952
|
(entry) => !t4.isFunctionDeclaration(entry[1])
|
|
6003
5953
|
)
|
|
6004
5954
|
);
|
|
6005
|
-
if (
|
|
5955
|
+
if (traverse3(csf._ast, {
|
|
6006
5956
|
Identifier(nodePath) {
|
|
6007
5957
|
let identifierName = nodePath.node.name, binding = nodePath.scope.getBinding(identifierName);
|
|
6008
5958
|
if (binding && storyExportDecls.has(binding.identifier.name) || identifierName === metaVariableName) {
|
|
@@ -6065,11 +6015,7 @@ Some of the detected stories [${detectedStoryNames.map((name) => `"${name}"`).jo
|
|
|
6065
6015
|
);
|
|
6066
6016
|
programNode.body.unshift(configImport);
|
|
6067
6017
|
}
|
|
6068
|
-
return programNode.
|
|
6069
|
-
t4.isTSTypeAliasDeclaration(node) && (programNode.body.some((otherNode) => t4.isVariableDeclaration(otherNode) ? otherNode.declarations.some(
|
|
6070
|
-
(declaration) => t4.isIdentifier(declaration.init) && declaration.init.name === node.id.name
|
|
6071
|
-
) : !1) || programNode.body.splice(index, 1));
|
|
6072
|
-
}), programNode.body = cleanupTypeImports(programNode, typesDisallowList), printCsf(csf).code;
|
|
6018
|
+
return removeUnusedTypes(programNode, csf._ast), printCsf(csf).code;
|
|
6073
6019
|
}
|
|
6074
6020
|
|
|
6075
6021
|
// src/codemod/csf-factories.ts
|
|
@@ -6080,16 +6026,8 @@ async function runStoriesCodemod(options) {
|
|
|
6080
6026
|
optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX) || (logger6.log("Please enter the glob for your stories to migrate"), globString = await prompt2.text({
|
|
6081
6027
|
message: "glob",
|
|
6082
6028
|
initialValue: "**/*.stories.*"
|
|
6083
|
-
})), logger6.
|
|
6084
|
-
|
|
6085
|
-
command: packageManager.getRemoteRunCommand("storybook", [
|
|
6086
|
-
"migrate",
|
|
6087
|
-
"csf-2-to-3",
|
|
6088
|
-
`--glob='${globString}'`
|
|
6089
|
-
]),
|
|
6090
|
-
args: [],
|
|
6091
|
-
stdio: "ignore",
|
|
6092
|
-
ignoreError: !0
|
|
6029
|
+
})), logger6.step("Applying codemod on your stories, this might take some time..."), await packageManager.runPackageCommand({
|
|
6030
|
+
args: ["storybook", "migrate", "csf-2-to-3", `--glob="${globString}"`]
|
|
6093
6031
|
}), await runCodemod(globString, (info) => storyToCsfFactory(info, codemodOptions), {
|
|
6094
6032
|
dryRun
|
|
6095
6033
|
});
|
|
@@ -6122,8 +6060,8 @@ var csfFactories = {
|
|
|
6122
6060
|
]
|
|
6123
6061
|
}));
|
|
6124
6062
|
let { packageJson } = packageManager.primaryPackageJson;
|
|
6125
|
-
useSubPathImports && !packageJson.imports?.["#*"] && (logger6.
|
|
6126
|
-
|
|
6063
|
+
useSubPathImports && !packageJson.imports?.["#*"] && (logger6.step(
|
|
6064
|
+
`Adding imports map in ${import_picocolors7.default.cyan(packageManager.primaryPackageJson.packageJsonPath)}`
|
|
6127
6065
|
), packageJson.imports = {
|
|
6128
6066
|
...packageJson.imports,
|
|
6129
6067
|
// @ts-expect-error we need to upgrade type-fest
|
|
@@ -6133,17 +6071,15 @@ var csfFactories = {
|
|
|
6133
6071
|
packageManager,
|
|
6134
6072
|
useSubPathImports,
|
|
6135
6073
|
previewConfigPath
|
|
6136
|
-
}), logger6.
|
|
6137
|
-
\u{1F6E0}\uFE0F Applying codemod on your main config...`);
|
|
6074
|
+
}), logger6.step("Applying codemod on your main config...");
|
|
6138
6075
|
let frameworkPackage = getFrameworkPackageName(mainConfig) || "@storybook/your-framework-here";
|
|
6139
6076
|
await runCodemod(
|
|
6140
6077
|
mainConfigPath,
|
|
6141
6078
|
(fileInfo) => configToCsfFactory(fileInfo, { configType: "main", frameworkPackage }, { dryRun })
|
|
6142
|
-
), logger6.
|
|
6143
|
-
\u{1F6E0}\uFE0F Applying codemod on your preview config...`), await runCodemod(
|
|
6079
|
+
), logger6.step("Applying codemod on your preview config..."), await runCodemod(
|
|
6144
6080
|
previewConfigPath,
|
|
6145
6081
|
(fileInfo) => configToCsfFactory(fileInfo, { configType: "preview", frameworkPackage }, { dryRun })
|
|
6146
|
-
), await
|
|
6082
|
+
), await syncStorybookAddons(mainConfig, previewConfigPath, configDir), logger6.logBox(
|
|
6147
6083
|
dedent3`
|
|
6148
6084
|
You can now run Storybook with the new CSF factories format.
|
|
6149
6085
|
|
|
@@ -6156,73 +6092,12 @@ var csfFactories = {
|
|
|
6156
6092
|
|
|
6157
6093
|
// src/automigrate/fixes/addon-a11y-addon-test.ts
|
|
6158
6094
|
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
6159
|
-
import { formatFileContent as formatFileContent3, getAddonNames } from "storybook/internal/common";
|
|
6095
|
+
import { formatFileContent as formatFileContent3, frameworkPackages as frameworkPackages3, getAddonNames } from "storybook/internal/common";
|
|
6160
6096
|
import { formatConfig, loadConfig as loadConfig2 } from "storybook/internal/csf-tools";
|
|
6161
6097
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
6162
6098
|
import jscodeshift from "jscodeshift";
|
|
6163
6099
|
import path3 from "path";
|
|
6164
6100
|
import { dedent as dedent4 } from "ts-dedent";
|
|
6165
|
-
|
|
6166
|
-
// ../../core/src/component-testing/constants.ts
|
|
6167
|
-
var ADDON_ID = "storybook/interactions", PANEL_ID = `${ADDON_ID}/panel`, DOCUMENTATION_LINK = "writing-tests/integrations/vitest-addon", DOCUMENTATION_DISCREPANCY_LINK = `${DOCUMENTATION_LINK}#what-happens-when-there-are-different-test-results-in-multiple-environments`;
|
|
6168
|
-
|
|
6169
|
-
// ../../addons/a11y/src/constants.ts
|
|
6170
|
-
var ADDON_ID2 = "storybook/a11y", PANEL_ID2 = `${ADDON_ID2}/panel`;
|
|
6171
|
-
var UI_STATE_ID = `${ADDON_ID2}/ui`, RESULT = `${ADDON_ID2}/result`, REQUEST = `${ADDON_ID2}/request`, RUNNING = `${ADDON_ID2}/running`, ERROR = `${ADDON_ID2}/error`, MANUAL = `${ADDON_ID2}/manual`, SELECT = `${ADDON_ID2}/select`, DOCUMENTATION_LINK2 = "writing-tests/accessibility-testing", DOCUMENTATION_DISCREPANCY_LINK2 = `${DOCUMENTATION_LINK2}#why-are-my-tests-failing-in-different-environments`;
|
|
6172
|
-
|
|
6173
|
-
// ../../addons/vitest/src/constants.ts
|
|
6174
|
-
var ADDON_ID3 = "storybook/test", TEST_PROVIDER_ID = `${ADDON_ID3}/test-provider`;
|
|
6175
|
-
var DOCUMENTATION_LINK3 = "writing-tests/integrations/vitest-addon", DOCUMENTATION_FATAL_ERROR_LINK = `${DOCUMENTATION_LINK3}#what-happens-if-vitest-itself-has-an-error`;
|
|
6176
|
-
var SUPPORTED_FRAMEWORKS = [
|
|
6177
|
-
"@storybook/nextjs",
|
|
6178
|
-
"@storybook/nextjs-vite",
|
|
6179
|
-
"@storybook/react-vite",
|
|
6180
|
-
"@storybook/preact-vite",
|
|
6181
|
-
"@storybook/svelte-vite",
|
|
6182
|
-
"@storybook/vue3-vite",
|
|
6183
|
-
"@storybook/html-vite",
|
|
6184
|
-
"@storybook/web-components-vite",
|
|
6185
|
-
"@storybook/sveltekit",
|
|
6186
|
-
"@storybook/react-native-web-vite"
|
|
6187
|
-
], storeOptions = {
|
|
6188
|
-
id: ADDON_ID3,
|
|
6189
|
-
initialState: {
|
|
6190
|
-
config: {
|
|
6191
|
-
coverage: !1,
|
|
6192
|
-
a11y: !1
|
|
6193
|
-
},
|
|
6194
|
-
watching: !1,
|
|
6195
|
-
cancelling: !1,
|
|
6196
|
-
fatalError: void 0,
|
|
6197
|
-
indexUrl: void 0,
|
|
6198
|
-
previewAnnotations: [],
|
|
6199
|
-
currentRun: {
|
|
6200
|
-
triggeredBy: void 0,
|
|
6201
|
-
config: {
|
|
6202
|
-
coverage: !1,
|
|
6203
|
-
a11y: !1
|
|
6204
|
-
},
|
|
6205
|
-
componentTestCount: {
|
|
6206
|
-
success: 0,
|
|
6207
|
-
error: 0
|
|
6208
|
-
},
|
|
6209
|
-
a11yCount: {
|
|
6210
|
-
success: 0,
|
|
6211
|
-
warning: 0,
|
|
6212
|
-
error: 0
|
|
6213
|
-
},
|
|
6214
|
-
storyIds: void 0,
|
|
6215
|
-
totalTestCount: void 0,
|
|
6216
|
-
startedAt: void 0,
|
|
6217
|
-
finishedAt: void 0,
|
|
6218
|
-
unhandledErrors: [],
|
|
6219
|
-
coverageSummary: void 0
|
|
6220
|
-
}
|
|
6221
|
-
}
|
|
6222
|
-
};
|
|
6223
|
-
var STORE_CHANNEL_EVENT_NAME = `UNIVERSAL_STORE:${storeOptions.id}`;
|
|
6224
|
-
|
|
6225
|
-
// src/automigrate/fixes/addon-a11y-addon-test.ts
|
|
6226
6101
|
var fileExtensions = [
|
|
6227
6102
|
".js",
|
|
6228
6103
|
".ts",
|
|
@@ -6238,7 +6113,7 @@ var fileExtensions = [
|
|
|
6238
6113
|
promptType: "auto",
|
|
6239
6114
|
async check({ mainConfig, configDir }) {
|
|
6240
6115
|
let addons = getAddonNames(mainConfig), frameworkPackageName = getFrameworkPackageName(mainConfig), hasA11yAddon = !!addons.find((addon) => addon.includes("@storybook/addon-a11y")), hasTestAddon = !!addons.find((addon) => addon.includes("@storybook/addon-vitest"));
|
|
6241
|
-
if (!
|
|
6116
|
+
if (!Object.keys(frameworkPackages3).find((framework) => frameworkPackageName?.includes(framework)) || !hasA11yAddon || !hasTestAddon || !configDir)
|
|
6242
6117
|
return null;
|
|
6243
6118
|
let vitestSetupFile = fileExtensions.map((ext) => path3.join(configDir, `vitest.setup${ext}`)).find((filePath) => existsSync(filePath)) ?? null, previewFile = fileExtensions.map((ext) => path3.join(configDir, `preview${ext}`)).find((filePath) => existsSync(filePath)) ?? null, skipVitestSetupTransformation = !1, skipPreviewTransformation = !1;
|
|
6244
6119
|
if (vitestSetupFile && previewFile) {
|
|
@@ -6361,7 +6236,7 @@ function shouldPreviewFileBeTransformed(source) {
|
|
|
6361
6236
|
// src/automigrate/fixes/addon-a11y-parameters.ts
|
|
6362
6237
|
var import_picocolors9 = __toESM(require_picocolors(), 1);
|
|
6363
6238
|
import { readFile } from "node:fs/promises";
|
|
6364
|
-
import { writeConfig
|
|
6239
|
+
import { writeConfig, writeCsf } from "storybook/internal/csf-tools";
|
|
6365
6240
|
import { logger as logger7 } from "storybook/internal/node-logger";
|
|
6366
6241
|
import { dedent as dedent5 } from "ts-dedent";
|
|
6367
6242
|
|
|
@@ -6514,12 +6389,12 @@ var addonA11yParameters = {
|
|
|
6514
6389
|
logger7.log(`Would have updated ${code.fileName}`);
|
|
6515
6390
|
else
|
|
6516
6391
|
try {
|
|
6517
|
-
await
|
|
6392
|
+
await writeConfig(code, previewFileToUpdate);
|
|
6518
6393
|
} catch (error) {
|
|
6519
6394
|
errors.push({ file: previewFileToUpdate, error });
|
|
6520
6395
|
}
|
|
6521
6396
|
}
|
|
6522
|
-
let { default: pLimit } = await import("./p-limit-
|
|
6397
|
+
let { default: pLimit } = await import("./p-limit-DSW6PYCD.js"), limit = pLimit(10);
|
|
6523
6398
|
if (await Promise.all(
|
|
6524
6399
|
storyFilesToUpdate.map(
|
|
6525
6400
|
(file) => limit(async () => {
|
|
@@ -6673,7 +6548,7 @@ var addonGlobalsApi = {
|
|
|
6673
6548
|
}
|
|
6674
6549
|
};
|
|
6675
6550
|
async function transformStoryFiles(files, options, dryRun) {
|
|
6676
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
6551
|
+
let errors = [], { default: pLimit } = await import("./p-limit-DSW6PYCD.js"), limit = pLimit(10);
|
|
6677
6552
|
return await Promise.all(
|
|
6678
6553
|
files.map(
|
|
6679
6554
|
(file) => limit(async () => {
|
|
@@ -6865,7 +6740,7 @@ function transformPackageJson(content) {
|
|
|
6865
6740
|
return hasChanges ? JSON.stringify(packageJson, null, 2) : null;
|
|
6866
6741
|
}
|
|
6867
6742
|
var transformPackageJsonFiles = async (files, dryRun) => {
|
|
6868
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
6743
|
+
let errors = [], { default: pLimit } = await import("./p-limit-DSW6PYCD.js"), limit = pLimit(10);
|
|
6869
6744
|
return await Promise.all(
|
|
6870
6745
|
files.map(
|
|
6871
6746
|
(file) => limit(async () => {
|
|
@@ -6904,7 +6779,7 @@ var transformPackageJsonFiles = async (files, dryRun) => {
|
|
|
6904
6779
|
dryRun
|
|
6905
6780
|
);
|
|
6906
6781
|
errors.push(...packageJsonErrors);
|
|
6907
|
-
let { globby } = await import("./globby-
|
|
6782
|
+
let { globby } = await import("./globby-ZADA2ALJ.js"), configFiles = await globby([`${configDir}/**/*`]), importErrors = await transformImportFiles(
|
|
6908
6783
|
[...storiesPaths, ...configFiles].filter(Boolean),
|
|
6909
6784
|
{
|
|
6910
6785
|
...consolidatedPackages,
|
|
@@ -7194,6 +7069,75 @@ async function transformPreviewFile2(source, filePath) {
|
|
|
7194
7069
|
return formatFileContent4(filePath, formatConfig4(previewConfig));
|
|
7195
7070
|
}
|
|
7196
7071
|
|
|
7072
|
+
// src/automigrate/fixes/nextjs-to-nextjs-vite.ts
|
|
7073
|
+
import { readFile as readFile6, writeFile as writeFile5 } from "node:fs/promises";
|
|
7074
|
+
import { transformImportFiles as transformImportFiles2 } from "storybook/internal/common";
|
|
7075
|
+
import { logger as logger11 } from "storybook/internal/node-logger";
|
|
7076
|
+
var transformMainConfig = async (mainConfigPath, dryRun) => {
|
|
7077
|
+
try {
|
|
7078
|
+
let content = await readFile6(mainConfigPath, "utf-8");
|
|
7079
|
+
if (!content.includes("@storybook/nextjs"))
|
|
7080
|
+
return !1;
|
|
7081
|
+
let transformedContent = content.replace(/@storybook\/nextjs/g, "@storybook/nextjs-vite");
|
|
7082
|
+
return transformedContent !== content && !dryRun && await writeFile5(mainConfigPath, transformedContent), transformedContent !== content;
|
|
7083
|
+
} catch (error) {
|
|
7084
|
+
return logger11.error(`Failed to update main config at ${mainConfigPath}: ${error}`), !1;
|
|
7085
|
+
}
|
|
7086
|
+
}, nextjsToNextjsVite = {
|
|
7087
|
+
id: "nextjs-to-nextjs-vite",
|
|
7088
|
+
link: "https://storybook.js.org/docs/get-started/frameworks/nextjs-vite",
|
|
7089
|
+
defaultSelected: !1,
|
|
7090
|
+
async check({ packageManager }) {
|
|
7091
|
+
if (!packageManager.getAllDependencies()["@storybook/nextjs"])
|
|
7092
|
+
return null;
|
|
7093
|
+
let packageJsonFiles = [];
|
|
7094
|
+
for (let packageJsonPath of packageManager.packageJsonPaths)
|
|
7095
|
+
try {
|
|
7096
|
+
let content = await readFile6(packageJsonPath, "utf-8"), packageJson = JSON.parse(content);
|
|
7097
|
+
Object.keys({
|
|
7098
|
+
...packageJson.dependencies || {},
|
|
7099
|
+
...packageJson.devDependencies || {}
|
|
7100
|
+
}).includes("@storybook/nextjs") && packageJsonFiles.push(packageJsonPath);
|
|
7101
|
+
} catch {
|
|
7102
|
+
continue;
|
|
7103
|
+
}
|
|
7104
|
+
return {
|
|
7105
|
+
hasNextjsPackage: !0,
|
|
7106
|
+
packageJsonFiles
|
|
7107
|
+
};
|
|
7108
|
+
},
|
|
7109
|
+
prompt() {
|
|
7110
|
+
return "Migrate from @storybook/nextjs to @storybook/nextjs-vite (Vite framework)";
|
|
7111
|
+
},
|
|
7112
|
+
async run({
|
|
7113
|
+
result,
|
|
7114
|
+
dryRun = !1,
|
|
7115
|
+
mainConfigPath,
|
|
7116
|
+
storiesPaths,
|
|
7117
|
+
configDir,
|
|
7118
|
+
packageManager,
|
|
7119
|
+
storybookVersion
|
|
7120
|
+
}) {
|
|
7121
|
+
if (!result)
|
|
7122
|
+
return;
|
|
7123
|
+
logger11.step("Migrating from @storybook/nextjs to @storybook/nextjs-vite..."), dryRun ? logger11.debug("Dry run: Skipping package.json updates.") : (logger11.debug("Updating package.json files..."), await packageManager.removeDependencies(["@storybook/nextjs"]), await packageManager.addDependencies({ type: "devDependencies", skipInstall: !0 }, [
|
|
7124
|
+
`@storybook/nextjs-vite@${storybookVersion}`
|
|
7125
|
+
])), mainConfigPath && (logger11.debug("Updating main config file..."), await transformMainConfig(mainConfigPath, dryRun)), logger11.debug("Scanning and updating import statements...");
|
|
7126
|
+
let { globby } = await import("./globby-ZADA2ALJ.js"), configFiles = await globby([`${configDir}/**/*`]), allFiles = [...storiesPaths, ...configFiles].filter(Boolean), transformErrors = await transformImportFiles2(
|
|
7127
|
+
allFiles,
|
|
7128
|
+
{
|
|
7129
|
+
"@storybook/nextjs": "@storybook/nextjs-vite"
|
|
7130
|
+
},
|
|
7131
|
+
!!dryRun
|
|
7132
|
+
);
|
|
7133
|
+
transformErrors.length > 0 && (logger11.warn(`Encountered ${transformErrors.length} errors during file transformation:`), transformErrors.forEach(({ file, error }) => {
|
|
7134
|
+
logger11.warn(` - ${file}: ${error.message}`);
|
|
7135
|
+
})), logger11.step("Migration completed successfully!"), logger11.log(
|
|
7136
|
+
"For more information, see: https://storybook.js.org/docs/nextjs/get-started/nextjs-vite"
|
|
7137
|
+
);
|
|
7138
|
+
}
|
|
7139
|
+
};
|
|
7140
|
+
|
|
7197
7141
|
// src/automigrate/fixes/remove-addon-interactions.ts
|
|
7198
7142
|
import { getAddonNames as getAddonNames5, removeAddon as removeAddon4 } from "storybook/internal/common";
|
|
7199
7143
|
var removeAddonInteractions = {
|
|
@@ -7218,7 +7162,7 @@ var removeAddonInteractions = {
|
|
|
7218
7162
|
// src/automigrate/fixes/remove-docs-autodocs.ts
|
|
7219
7163
|
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
7220
7164
|
import { readConfig as readConfig2 } from "storybook/internal/csf-tools";
|
|
7221
|
-
var
|
|
7165
|
+
var logger12 = {
|
|
7222
7166
|
log: (message) => {
|
|
7223
7167
|
process.env.NODE_ENV !== "test" && console.log(message);
|
|
7224
7168
|
}
|
|
@@ -7240,10 +7184,10 @@ var logger11 = {
|
|
|
7240
7184
|
prompt: () => `${import_picocolors11.default.cyan("docs.autodocs")} has been removed in Storybook 9 and will be removed from your configuration.`,
|
|
7241
7185
|
async run({ result, dryRun, mainConfigPath, previewConfigPath }) {
|
|
7242
7186
|
let { autodocs } = result;
|
|
7243
|
-
|
|
7187
|
+
logger12.log(`\u{1F504} Updating ${import_picocolors11.default.cyan("docs")} parameter in main config file...`), await updateMainConfig({ mainConfigPath, dryRun: !!dryRun }, async (main) => {
|
|
7244
7188
|
let docs = main.getFieldValue(["docs"]) || {};
|
|
7245
7189
|
dryRun || (delete docs.autodocs, Object.keys(docs).length === 0 ? main.removeField(["docs"]) : main.setFieldValue(["docs"], docs));
|
|
7246
|
-
}), autodocs === !0 && previewConfigPath && (
|
|
7190
|
+
}), autodocs === !0 && previewConfigPath && (logger12.log(`\u{1F504} Updating ${import_picocolors11.default.cyan("tags")} parameter in preview config file...`), await updateMainConfig(
|
|
7247
7191
|
{ mainConfigPath: previewConfigPath, dryRun: !!dryRun },
|
|
7248
7192
|
async (preview) => {
|
|
7249
7193
|
let tags = preview.getFieldValue(["tags"]) || [];
|
|
@@ -7254,7 +7198,7 @@ var logger11 = {
|
|
|
7254
7198
|
};
|
|
7255
7199
|
|
|
7256
7200
|
// src/automigrate/fixes/remove-essentials.ts
|
|
7257
|
-
import { getAddonNames as getAddonNames6, removeAddon as removeAddon5, transformImportFiles as
|
|
7201
|
+
import { getAddonNames as getAddonNames6, removeAddon as removeAddon5, transformImportFiles as transformImportFiles3 } from "storybook/internal/common";
|
|
7258
7202
|
|
|
7259
7203
|
// src/automigrate/fixes/remove-essentials.utils.ts
|
|
7260
7204
|
function moveEssentialOptions(dryRun, essentialsOptions) {
|
|
@@ -7355,7 +7299,7 @@ var consolidatedAddons = {
|
|
|
7355
7299
|
packageManager,
|
|
7356
7300
|
skipInstall: !0
|
|
7357
7301
|
});
|
|
7358
|
-
let errors = await
|
|
7302
|
+
let errors = await transformImportFiles3(
|
|
7359
7303
|
[...storiesPaths, mainConfigPath, previewConfigPath].filter(Boolean),
|
|
7360
7304
|
consolidatedAddons,
|
|
7361
7305
|
dryRun
|
|
@@ -7381,27 +7325,27 @@ ${errors.map(({ file, error }) => `- ${file}: ${error.message}`).join(`
|
|
|
7381
7325
|
};
|
|
7382
7326
|
|
|
7383
7327
|
// src/automigrate/fixes/renderer-to-framework.ts
|
|
7384
|
-
import { readFile as
|
|
7328
|
+
import { readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
7385
7329
|
import {
|
|
7386
|
-
frameworkPackages as
|
|
7330
|
+
frameworkPackages as frameworkPackages4,
|
|
7387
7331
|
frameworkToRenderer,
|
|
7388
7332
|
rendererPackages as rendererPackages2
|
|
7389
7333
|
} from "storybook/internal/common";
|
|
7390
|
-
import { logger as
|
|
7334
|
+
import { logger as logger13 } from "storybook/internal/node-logger";
|
|
7391
7335
|
var getAllDependencies = (packageJson) => Object.keys({
|
|
7392
7336
|
...packageJson.dependencies || {},
|
|
7393
7337
|
...packageJson.devDependencies || {}
|
|
7394
|
-
}), detectFrameworks = (dependencies) => Object.keys(
|
|
7338
|
+
}), detectFrameworks = (dependencies) => Object.keys(frameworkPackages4).filter((pkg) => dependencies.includes(pkg)), detectRenderers = (dependencies) => Object.keys(rendererPackages2).filter((pkg) => dependencies.includes(pkg)).filter((pkg) => !Object.keys(frameworkPackages4).includes(pkg)), replaceImports = (source, renderer, framework) => {
|
|
7395
7339
|
let regex = new RegExp(`(['"])${renderer}(['"])`, "g");
|
|
7396
7340
|
return regex.test(source) ? source.replace(regex, `$1${framework}$2`) : null;
|
|
7397
7341
|
}, transformSourceFiles = async (files, renderer, framework, dryRun) => {
|
|
7398
|
-
let errors = [], { default: pLimit } = await import("./p-limit-
|
|
7342
|
+
let errors = [], { default: pLimit } = await import("./p-limit-DSW6PYCD.js"), limit = pLimit(10);
|
|
7399
7343
|
return await Promise.all(
|
|
7400
7344
|
files.map(
|
|
7401
7345
|
(file) => limit(async () => {
|
|
7402
7346
|
try {
|
|
7403
|
-
let contents = await
|
|
7404
|
-
!dryRun && transformed && await
|
|
7347
|
+
let contents = await readFile7(file, "utf-8"), transformed = replaceImports(contents, renderer, framework);
|
|
7348
|
+
!dryRun && transformed && await writeFile6(file, transformed);
|
|
7405
7349
|
} catch (error) {
|
|
7406
7350
|
errors.push({ file, error });
|
|
7407
7351
|
}
|
|
@@ -7410,13 +7354,13 @@ var getAllDependencies = (packageJson) => Object.keys({
|
|
|
7410
7354
|
), errors;
|
|
7411
7355
|
}, removeRendererInPackageJson = async (packageJsonPath, renderer, dryRun) => {
|
|
7412
7356
|
try {
|
|
7413
|
-
let content = await
|
|
7414
|
-
return packageJson.dependencies?.[renderer] && (delete packageJson.dependencies[renderer], hasChanges = !0), packageJson.devDependencies?.[renderer] && (delete packageJson.devDependencies[renderer], hasChanges = !0), !dryRun && hasChanges && await
|
|
7357
|
+
let content = await readFile7(packageJsonPath, "utf-8"), packageJson = JSON.parse(content), hasChanges = !1;
|
|
7358
|
+
return packageJson.dependencies?.[renderer] && (delete packageJson.dependencies[renderer], hasChanges = !0), packageJson.devDependencies?.[renderer] && (delete packageJson.devDependencies[renderer], hasChanges = !0), !dryRun && hasChanges && await writeFile6(packageJsonPath, JSON.stringify(packageJson, null, 2)), hasChanges;
|
|
7415
7359
|
} catch (error) {
|
|
7416
7360
|
throw new Error(`Failed to update package.json: ${error}`);
|
|
7417
7361
|
}
|
|
7418
7362
|
}, checkPackageJson = async (packageJsonPath) => {
|
|
7419
|
-
let content = await
|
|
7363
|
+
let content = await readFile7(packageJsonPath, "utf-8"), packageJson = JSON.parse(content), dependencies = getAllDependencies(packageJson), frameworks = detectFrameworks(dependencies);
|
|
7420
7364
|
if (frameworks.length === 0)
|
|
7421
7365
|
return null;
|
|
7422
7366
|
let renderers = detectRenderers(dependencies);
|
|
@@ -7449,26 +7393,26 @@ var getAllDependencies = (packageJson) => Object.keys({
|
|
|
7449
7393
|
async run(options) {
|
|
7450
7394
|
let { result, dryRun = !1, storiesPaths, configDir } = options;
|
|
7451
7395
|
for (let selectedFramework of result.frameworks) {
|
|
7452
|
-
if (!
|
|
7453
|
-
|
|
7396
|
+
if (!frameworkPackages4[selectedFramework]) {
|
|
7397
|
+
logger13.warn(`Framework name not found for ${selectedFramework}, skipping.`);
|
|
7454
7398
|
continue;
|
|
7455
7399
|
}
|
|
7456
|
-
let rendererName = frameworkToRenderer[
|
|
7400
|
+
let rendererName = frameworkToRenderer[frameworkPackages4[selectedFramework]], [rendererPackage] = Object.entries(rendererPackages2).find(([, renderer]) => renderer === rendererName) ?? [];
|
|
7457
7401
|
if (!rendererPackage) {
|
|
7458
|
-
|
|
7402
|
+
logger13.warn(`Renderer package not found for ${selectedFramework}, skipping.`);
|
|
7459
7403
|
continue;
|
|
7460
7404
|
}
|
|
7461
7405
|
if (rendererPackage === selectedFramework)
|
|
7462
7406
|
continue;
|
|
7463
|
-
|
|
7407
|
+
logger13.debug(`
|
|
7464
7408
|
Migrating ${rendererPackage} to ${selectedFramework}`);
|
|
7465
|
-
let { globby } = await import("./globby-
|
|
7409
|
+
let { globby } = await import("./globby-ZADA2ALJ.js"), configFiles = await globby([`${configDir}/**/*`]);
|
|
7466
7410
|
await transformSourceFiles(
|
|
7467
7411
|
[...storiesPaths, ...configFiles].filter(Boolean),
|
|
7468
7412
|
rendererPackage,
|
|
7469
7413
|
selectedFramework,
|
|
7470
7414
|
dryRun
|
|
7471
|
-
),
|
|
7415
|
+
), logger13.debug("Updating package.json files..."), await Promise.all(
|
|
7472
7416
|
result.packageJsonFiles.map(
|
|
7473
7417
|
(file) => removeRendererInPackageJson(file, rendererPackage, dryRun)
|
|
7474
7418
|
)
|
|
@@ -7479,27 +7423,27 @@ Migrating ${rendererPackage} to ${selectedFramework}`);
|
|
|
7479
7423
|
|
|
7480
7424
|
// src/automigrate/fixes/rnstorybook-config.ts
|
|
7481
7425
|
import { existsSync as existsSync2 } from "node:fs";
|
|
7482
|
-
import { readFile as
|
|
7426
|
+
import { readFile as readFile8, rename, writeFile as writeFile7 } from "node:fs/promises";
|
|
7483
7427
|
import { join as join2 } from "node:path";
|
|
7484
7428
|
import { dedent as dedent9 } from "ts-dedent";
|
|
7485
7429
|
async function renameInFile(filePath, oldText, newText) {
|
|
7486
7430
|
try {
|
|
7487
|
-
let updatedContent = (await
|
|
7488
|
-
await
|
|
7431
|
+
let updatedContent = (await readFile8(filePath, "utf8")).replaceAll(oldText, newText);
|
|
7432
|
+
await writeFile7(filePath, updatedContent, "utf8");
|
|
7489
7433
|
} catch (error) {
|
|
7490
7434
|
console.error(`Error updating references in ${filePath}:`, error);
|
|
7491
7435
|
}
|
|
7492
7436
|
}
|
|
7493
7437
|
var getDotStorybookReferences = async (searchDir) => {
|
|
7494
7438
|
try {
|
|
7495
|
-
let { globby } = await import("./globby-
|
|
7439
|
+
let { globby } = await import("./globby-ZADA2ALJ.js"), { readFile: readFile10 } = await import("node:fs/promises"), files = await globby(`${searchDir}/**/*`, {
|
|
7496
7440
|
onlyFiles: !0,
|
|
7497
7441
|
gitignore: !0
|
|
7498
7442
|
}), referencedFiles = [];
|
|
7499
7443
|
return await Promise.all(
|
|
7500
7444
|
files.map(async (file) => {
|
|
7501
7445
|
try {
|
|
7502
|
-
(await
|
|
7446
|
+
(await readFile10(file, "utf8")).includes(".storybook") && referencedFiles.push(file);
|
|
7503
7447
|
} catch {
|
|
7504
7448
|
}
|
|
7505
7449
|
})
|
|
@@ -7513,7 +7457,7 @@ var getDotStorybookReferences = async (searchDir) => {
|
|
|
7513
7457
|
async check({ packageManager, mainConfigPath }) {
|
|
7514
7458
|
if (!packageManager.getAllDependencies()["@storybook/react-native"])
|
|
7515
7459
|
return null;
|
|
7516
|
-
let projectDir = mainConfigPath ? join2(mainConfigPath, "..", "..") : process.cwd(), storybookDir = join2(projectDir, ".storybook"), rnStorybookDir = join2(projectDir, ".rnstorybook"), { globby } = await import("./globby-
|
|
7460
|
+
let projectDir = mainConfigPath ? join2(mainConfigPath, "..", "..") : process.cwd(), storybookDir = join2(projectDir, ".storybook"), rnStorybookDir = join2(projectDir, ".rnstorybook"), { globby } = await import("./globby-ZADA2ALJ.js"), requiresFiles = await globby(join2(storybookDir, "storybook.requires.*"));
|
|
7517
7461
|
return existsSync2(storybookDir) && requiresFiles.length > 0 && !existsSync2(rnStorybookDir) ? { storybookDir, rnStorybookDir } : null;
|
|
7518
7462
|
},
|
|
7519
7463
|
prompt() {
|
|
@@ -7534,7 +7478,7 @@ var import_semver5 = __toESM(require_semver(), 1);
|
|
|
7534
7478
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
7535
7479
|
import { dirname as dirname2 } from "node:path";
|
|
7536
7480
|
import { isCorePackage, isSatelliteAddon } from "storybook/internal/common";
|
|
7537
|
-
import { logger as
|
|
7481
|
+
import { logger as logger14 } from "storybook/internal/node-logger";
|
|
7538
7482
|
import { dedent as dedent10 } from "ts-dedent";
|
|
7539
7483
|
async function getLatestVersions(packageManager, packages) {
|
|
7540
7484
|
return Promise.all(
|
|
@@ -7546,14 +7490,14 @@ async function getLatestVersions(packageManager, packages) {
|
|
|
7546
7490
|
);
|
|
7547
7491
|
}
|
|
7548
7492
|
function isValidVersionType(packageName, specifier) {
|
|
7549
|
-
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:") ? (
|
|
7493
|
+
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:") ? (logger14.debug(`Skipping ${packageName} as it does not have a valid version type: ${specifier}`), !1) : !0;
|
|
7550
7494
|
}
|
|
7551
7495
|
var upgradeStorybookRelatedDependencies = {
|
|
7552
7496
|
id: "upgrade-storybook-related-dependencies",
|
|
7553
7497
|
promptType: "auto",
|
|
7554
7498
|
defaultSelected: !1,
|
|
7555
7499
|
async check({ packageManager, storybookVersion }) {
|
|
7556
|
-
|
|
7500
|
+
logger14.debug("Checking for incompatible storybook packages...");
|
|
7557
7501
|
let analyzedPackages = await getIncompatibleStorybookPackages({
|
|
7558
7502
|
currentStorybookVersion: storybookVersion,
|
|
7559
7503
|
packageManager,
|
|
@@ -7574,7 +7518,7 @@ var upgradeStorybookRelatedDependencies = {
|
|
|
7574
7518
|
},
|
|
7575
7519
|
async run({ result: { upgradable }, packageManager, dryRun }) {
|
|
7576
7520
|
if (dryRun) {
|
|
7577
|
-
|
|
7521
|
+
logger14.log(dedent10`
|
|
7578
7522
|
The following would have been upgraded:
|
|
7579
7523
|
${upgradable.map(
|
|
7580
7524
|
({ packageName, afterVersion, beforeVersion }) => `${packageName}: ${beforeVersion} => ${afterVersion}`
|
|
@@ -7597,6 +7541,13 @@ var upgradeStorybookRelatedDependencies = {
|
|
|
7597
7541
|
|
|
7598
7542
|
// src/automigrate/fixes/wrap-getAbsolutePath.ts
|
|
7599
7543
|
import { detectPnp } from "storybook/internal/cli";
|
|
7544
|
+
import {
|
|
7545
|
+
getAbsolutePathWrapperAsCallExpression,
|
|
7546
|
+
getAbsolutePathWrapperName,
|
|
7547
|
+
getFieldsForGetAbsolutePathWrapper,
|
|
7548
|
+
isGetAbsolutePathWrapperNecessary,
|
|
7549
|
+
wrapValueWithGetAbsolutePathWrapper
|
|
7550
|
+
} from "storybook/internal/common";
|
|
7600
7551
|
import { readConfig as readConfig3 } from "storybook/internal/csf-tools";
|
|
7601
7552
|
import { CommonJsConfigNotSupportedError } from "storybook/internal/server-errors";
|
|
7602
7553
|
import { dedent as dedent11 } from "ts-dedent";
|
|
@@ -7646,6 +7597,7 @@ var allFixes = [
|
|
|
7646
7597
|
addonExperimentalTest,
|
|
7647
7598
|
rnstorybookConfig,
|
|
7648
7599
|
migrateAddonConsole,
|
|
7600
|
+
nextjsToNextjsVite,
|
|
7649
7601
|
removeAddonInteractions,
|
|
7650
7602
|
rendererToFramework,
|
|
7651
7603
|
removeEssentials,
|
|
@@ -7658,7 +7610,7 @@ var commandFixes = [csfFactories];
|
|
|
7658
7610
|
|
|
7659
7611
|
// src/automigrate/helpers/logMigrationSummary.ts
|
|
7660
7612
|
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
7661
|
-
import { logger as
|
|
7613
|
+
import { CLI_COLORS as CLI_COLORS2, logger as logger15 } from "storybook/internal/node-logger";
|
|
7662
7614
|
import { dedent as dedent12 } from "ts-dedent";
|
|
7663
7615
|
var messageDivider2 = `
|
|
7664
7616
|
|
|
@@ -7684,38 +7636,33 @@ function logMigrationSummary({
|
|
|
7684
7636
|
fixSummary
|
|
7685
7637
|
}) {
|
|
7686
7638
|
let messages2 = [];
|
|
7687
|
-
messages2.push(getGlossaryMessages(fixSummary, fixResults).join(messageDivider2)), messages2.push(dedent12`If you'd like to run the migrations again, you can do so by running
|
|
7688
|
-
"npx storybook automigrate"
|
|
7689
|
-
)}'
|
|
7639
|
+
messages2.push(getGlossaryMessages(fixSummary, fixResults).join(messageDivider2)), messages2.push(dedent12`If you'd like to run the migrations again, you can do so by running
|
|
7640
|
+
${import_picocolors12.default.cyan("npx storybook automigrate")}
|
|
7690
7641
|
|
|
7691
7642
|
The automigrations try to migrate common patterns in your project, but might not contain everything needed to migrate to the latest version of Storybook.
|
|
7692
7643
|
|
|
7693
|
-
Please check the changelog and migration guide for manual migrations and more information:
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
And reach out on Discord if you need help: ${import_picocolors12.default.yellow("https://discord.gg/storybook")}
|
|
7644
|
+
Please check the changelog and migration guide for manual migrations and more information:
|
|
7645
|
+
https://storybook.js.org/docs/releases/migration-guide?ref=upgrade
|
|
7646
|
+
And reach out on Discord if you need help: https://discord.gg/storybook
|
|
7697
7647
|
`);
|
|
7698
7648
|
let hasNoFixes = Object.values(fixResults).every((r) => r === "unnecessary" /* UNNECESSARY */), hasFailures2 = Object.values(fixResults).some(
|
|
7699
7649
|
(r) => r === "failed" /* FAILED */ || r === "check_failed" /* CHECK_FAILED */
|
|
7700
|
-
)
|
|
7701
|
-
|
|
7702
|
-
title,
|
|
7703
|
-
borderColor: hasFailures2 ? "red" : "green"
|
|
7704
|
-
});
|
|
7650
|
+
);
|
|
7651
|
+
hasNoFixes ? logger15.warn("No migrations were applicable to your project") : hasFailures2 ? logger15.error("Migration check ran with failures") : logger15.step(CLI_COLORS2.success("Migration check ran successfully")), logger15.log(messages2.filter(Boolean).join(segmentDivider));
|
|
7705
7652
|
}
|
|
7706
7653
|
|
|
7707
7654
|
// src/automigrate/index.ts
|
|
7708
7655
|
var logAvailableMigrations = () => {
|
|
7709
7656
|
let availableFixes = [...allFixes, ...commandFixes].map((f) => import_picocolors13.default.yellow(f.id)).map((x) => `- ${x}`).join(`
|
|
7710
7657
|
`);
|
|
7711
|
-
|
|
7658
|
+
logger16.log(dedent13`
|
|
7712
7659
|
The following migrations are available:
|
|
7713
7660
|
${availableFixes}
|
|
7714
7661
|
`);
|
|
7715
7662
|
}, hasFailures = (fixResults) => Object.values(fixResults || {}).some(
|
|
7716
7663
|
(r) => r === "failed" /* FAILED */ || r === "check_failed" /* CHECK_FAILED */
|
|
7717
7664
|
), doAutomigrate = async (options) => {
|
|
7718
|
-
|
|
7665
|
+
logger16.debug("Extracting storybook data...");
|
|
7719
7666
|
let {
|
|
7720
7667
|
mainConfig,
|
|
7721
7668
|
mainConfigPath,
|
|
@@ -7747,8 +7694,13 @@ var logAvailableMigrations = () => {
|
|
|
7747
7694
|
});
|
|
7748
7695
|
if (Object.values(outcome?.fixResults ?? {}).some(
|
|
7749
7696
|
(r) => r === "succeeded" /* SUCCEEDED */ || r === "manual_succeeded" /* MANUAL_SUCCEEDED */
|
|
7750
|
-
) && packageManager.installDependencies(), outcome && !options.skipDoctor && await doctor({ configDir, packageManager: options.packageManager }), hasFailures(outcome?.fixResults))
|
|
7751
|
-
|
|
7697
|
+
) && !options.skipInstall && packageManager.installDependencies(), outcome && !options.skipDoctor && await doctor({ configDir, packageManager: options.packageManager }), hasFailures(outcome?.fixResults)) {
|
|
7698
|
+
let failedMigrations = Object.entries(outcome?.fixResults ?? {}).filter(([, status]) => status === "failed" /* FAILED */ || status === "check_failed" /* CHECK_FAILED */).map(([id, status]) => {
|
|
7699
|
+
let statusLabel = status === "check_failed" /* CHECK_FAILED */ ? "check failed" : "failed";
|
|
7700
|
+
return `${import_picocolors13.default.cyan(id)} (${statusLabel})`;
|
|
7701
|
+
});
|
|
7702
|
+
throw new AutomigrateError({ errors: failedMigrations });
|
|
7703
|
+
}
|
|
7752
7704
|
}, automigrate = async ({
|
|
7753
7705
|
fixId,
|
|
7754
7706
|
fixes: inputFixes,
|
|
@@ -7773,7 +7725,7 @@ var logAvailableMigrations = () => {
|
|
|
7773
7725
|
return logAvailableMigrations(), null;
|
|
7774
7726
|
let commandFix = commandFixes.find((f) => f.id === fixId);
|
|
7775
7727
|
if (commandFix)
|
|
7776
|
-
return
|
|
7728
|
+
return logger16.step(`Running migration ${import_picocolors13.default.magenta(fixId)}..`), await commandFix.run({
|
|
7777
7729
|
mainConfigPath,
|
|
7778
7730
|
previewConfigPath,
|
|
7779
7731
|
packageManager,
|
|
@@ -7786,8 +7738,8 @@ var logAvailableMigrations = () => {
|
|
|
7786
7738
|
}), null;
|
|
7787
7739
|
let selectedFixes = inputFixes || allFixes.filter((fix) => !(fix.id === upgradeStorybookRelatedDependencies.id && isLatest === !1 && fixId !== upgradeStorybookRelatedDependencies.id)), fixes = fixId ? selectedFixes.filter((f) => f.id === fixId) : selectedFixes;
|
|
7788
7740
|
if (fixId && fixes.length === 0)
|
|
7789
|
-
return
|
|
7790
|
-
|
|
7741
|
+
return logger16.log(`\u{1F4ED} No migrations found for ${import_picocolors13.default.magenta(fixId)}.`), logAvailableMigrations(), null;
|
|
7742
|
+
logger16.step("Checking possible migrations..");
|
|
7791
7743
|
let { fixResults, fixSummary, preCheckFailure } = await runFixes({
|
|
7792
7744
|
fixes,
|
|
7793
7745
|
packageManager,
|
|
@@ -7804,10 +7756,10 @@ var logAvailableMigrations = () => {
|
|
|
7804
7756
|
yes,
|
|
7805
7757
|
storiesPaths
|
|
7806
7758
|
});
|
|
7807
|
-
return hasFailures(fixResults) && logTracker2.enableLogWriting(), hideMigrationSummary ||
|
|
7759
|
+
return hasFailures(fixResults) && logTracker2.enableLogWriting(), hideMigrationSummary || logMigrationSummary({
|
|
7808
7760
|
fixResults,
|
|
7809
7761
|
fixSummary
|
|
7810
|
-
}),
|
|
7762
|
+
}), { fixResults, preCheckFailure };
|
|
7811
7763
|
};
|
|
7812
7764
|
async function runFixes({
|
|
7813
7765
|
fixes,
|
|
@@ -7827,7 +7779,7 @@ async function runFixes({
|
|
|
7827
7779
|
for (let i = 0; i < fixes.length; i += 1) {
|
|
7828
7780
|
let f = fixes[i], result;
|
|
7829
7781
|
try {
|
|
7830
|
-
|
|
7782
|
+
logger16.debug(`Running ${import_picocolors13.default.cyan(f.id)} migration checks`), result = await f.check({
|
|
7831
7783
|
packageManager,
|
|
7832
7784
|
configDir,
|
|
7833
7785
|
rendererPackage,
|
|
@@ -7836,14 +7788,14 @@ async function runFixes({
|
|
|
7836
7788
|
previewConfigPath,
|
|
7837
7789
|
mainConfigPath,
|
|
7838
7790
|
storiesPaths
|
|
7839
|
-
}),
|
|
7791
|
+
}), logger16.debug(`End of ${import_picocolors13.default.cyan(f.id)} migration checks`);
|
|
7840
7792
|
} catch (error) {
|
|
7841
|
-
|
|
7793
|
+
logger16.warn(`\u26A0\uFE0F failed to check fix ${import_picocolors13.default.bold(f.id)}`), error instanceof Error && (logger16.error(`
|
|
7842
7794
|
${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "check_failed" /* CHECK_FAILED */;
|
|
7843
7795
|
}
|
|
7844
7796
|
if (result) {
|
|
7845
7797
|
let promptType = typeof f.promptType == "function" ? await f.promptType(result) : f.promptType ?? "auto";
|
|
7846
|
-
|
|
7798
|
+
logger16.log(`\u{1F50E} found a '${import_picocolors13.default.cyan(f.id)}' migration:`);
|
|
7847
7799
|
let getTitle = () => {
|
|
7848
7800
|
switch (promptType) {
|
|
7849
7801
|
case "auto":
|
|
@@ -7857,7 +7809,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7857
7809
|
id: `automigrate-task-${f.id}`,
|
|
7858
7810
|
title: `${getTitle()}: ${import_picocolors13.default.cyan(f.id)}`
|
|
7859
7811
|
});
|
|
7860
|
-
|
|
7812
|
+
logger16.logBox(f.prompt());
|
|
7861
7813
|
let runAnswer;
|
|
7862
7814
|
try {
|
|
7863
7815
|
if (dryRun)
|
|
@@ -7865,7 +7817,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7865
7817
|
else if (yes)
|
|
7866
7818
|
runAnswer = { fix: !0 }, promptType === "manual" && (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id));
|
|
7867
7819
|
else if (promptType === "manual") {
|
|
7868
|
-
if (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id),
|
|
7820
|
+
if (fixResults[f.id] = "manual_succeeded" /* MANUAL_SUCCEEDED */, fixSummary.manual.push(f.id), !await prompt3.confirm(
|
|
7869
7821
|
{
|
|
7870
7822
|
message: "Select continue once you have made the required changes, or quit to exit the migration process",
|
|
7871
7823
|
initialValue: !0,
|
|
@@ -7881,7 +7833,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7881
7833
|
fixResults[f.id] = "manual_skipped" /* MANUAL_SKIPPED */;
|
|
7882
7834
|
break;
|
|
7883
7835
|
}
|
|
7884
|
-
} else promptType === "auto" ? runAnswer = { fix: await prompt3.confirm(
|
|
7836
|
+
} else promptType === "auto" ? runAnswer = { fix: yes ? !0 : await prompt3.confirm(
|
|
7885
7837
|
{
|
|
7886
7838
|
message: `Do you want to run the '${import_picocolors13.default.cyan(f.id)}' migration on your project?`,
|
|
7887
7839
|
initialValue: f.defaultSelected ?? !0
|
|
@@ -7918,7 +7870,7 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7918
7870
|
skipInstall,
|
|
7919
7871
|
storybookVersion,
|
|
7920
7872
|
storiesPaths
|
|
7921
|
-
}),
|
|
7873
|
+
}), logger16.log(`\u2705 ran ${import_picocolors13.default.cyan(f.id)} migration`), fixResults[f.id] = "succeeded" /* SUCCEEDED */, fixSummary.succeeded.push(f.id), currentTaskLogger.success(`Ran ${import_picocolors13.default.cyan(f.id)} migration`);
|
|
7922
7874
|
} catch (error) {
|
|
7923
7875
|
fixResults[f.id] = "failed" /* FAILED */;
|
|
7924
7876
|
let errorMessage = error instanceof Error ? error.message : "Failed to run migration";
|
|
@@ -7933,35 +7885,15 @@ ${error.stack}`), fixSummary.failed[f.id] = error.message), fixResults[f.id] = "
|
|
|
7933
7885
|
}
|
|
7934
7886
|
|
|
7935
7887
|
// src/link.ts
|
|
7936
|
-
var import_cross_spawn = __toESM(require_cross_spawn(), 1)
|
|
7937
|
-
import { mkdir, readFile as
|
|
7888
|
+
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
7889
|
+
import { mkdir, readFile as readFile9, writeFile as writeFile8 } from "node:fs/promises";
|
|
7938
7890
|
import { basename as basename2, extname as extname2, join as join3 } from "node:path";
|
|
7939
|
-
import {
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
errorMessage,
|
|
7943
|
-
dryRun
|
|
7944
|
-
} = {}) => {
|
|
7945
|
-
if (startMessage && logger16.info(startMessage), dryRun) {
|
|
7946
|
-
logger16.info(`
|
|
7947
|
-
> ${command2}
|
|
7948
|
-
`);
|
|
7949
|
-
return;
|
|
7950
|
-
}
|
|
7951
|
-
return logger16.info(command2), new Promise((resolve2, reject) => {
|
|
7952
|
-
let child = (0, import_cross_spawn.spawn)(command2, {
|
|
7953
|
-
...options,
|
|
7954
|
-
shell: !0,
|
|
7955
|
-
stdio: "pipe"
|
|
7956
|
-
});
|
|
7957
|
-
child.stderr.pipe(process.stdout), child.stdout.pipe(process.stdout), child.on("exit", (code) => {
|
|
7958
|
-
code === 0 ? resolve2(void 0) : (logger16.error(import_picocolors14.default.red(`An error occurred while executing: \`${command2}\``)), errorMessage && logger16.info(errorMessage), reject(new Error(`command exited with code: ${code}: `)));
|
|
7959
|
-
});
|
|
7960
|
-
});
|
|
7961
|
-
}, link = async ({ target, local, start }) => {
|
|
7891
|
+
import { executeCommand } from "storybook/internal/common";
|
|
7892
|
+
import { logger as logger17 } from "storybook/internal/node-logger";
|
|
7893
|
+
var link = async ({ target, local, start }) => {
|
|
7962
7894
|
let storybookDir = process.cwd();
|
|
7963
7895
|
try {
|
|
7964
|
-
if (JSON.parse(await
|
|
7896
|
+
if (JSON.parse(await readFile9("package.json", { encoding: "utf8" })).name !== "@storybook/root")
|
|
7965
7897
|
throw new Error();
|
|
7966
7898
|
} catch {
|
|
7967
7899
|
throw new Error("Expected to run link from the root of the storybook monorepo");
|
|
@@ -7969,7 +7901,11 @@ var exec = async (command2, options = {}, {
|
|
|
7969
7901
|
let reproDir = target, reproName = basename2(target);
|
|
7970
7902
|
if (!local) {
|
|
7971
7903
|
let reprosDir = join3(storybookDir, "../storybook-repros");
|
|
7972
|
-
|
|
7904
|
+
logger17.info(`Ensuring directory ${reprosDir}`), await mkdir(reprosDir, { recursive: !0 }), logger17.info(`Cloning ${target}`), await executeCommand({
|
|
7905
|
+
command: "git",
|
|
7906
|
+
args: ["clone", target],
|
|
7907
|
+
cwd: reprosDir
|
|
7908
|
+
}), reproName = basename2(target, extname2(target)), reproDir = join3(reprosDir, reproName);
|
|
7973
7909
|
}
|
|
7974
7910
|
let version2 = (0, import_cross_spawn.sync)("yarn", ["--version"], {
|
|
7975
7911
|
cwd: reproDir,
|
|
@@ -7977,12 +7913,16 @@ var exec = async (command2, options = {}, {
|
|
|
7977
7913
|
shell: !0
|
|
7978
7914
|
}).stdout.toString();
|
|
7979
7915
|
if (!/^[2-4]\./.test(version2)) {
|
|
7980
|
-
|
|
7916
|
+
logger17.warn(`\u{1F6A8} Expected yarn 2 or higher in ${reproDir}!`), logger17.warn(""), logger17.warn("Please set it up with `yarn set version berry`,"), logger17.warn(`then link '${reproDir}' with the '--local' flag.`);
|
|
7981
7917
|
return;
|
|
7982
7918
|
}
|
|
7983
|
-
|
|
7919
|
+
logger17.info(`Linking ${reproDir}`), await executeCommand({
|
|
7920
|
+
command: "yarn",
|
|
7921
|
+
args: ["link", "--all", "--relative", storybookDir],
|
|
7922
|
+
cwd: reproDir
|
|
7923
|
+
}), logger17.info(`Installing ${reproName}`);
|
|
7984
7924
|
let reproPackageJson = JSON.parse(
|
|
7985
|
-
await
|
|
7925
|
+
await readFile9(join3(reproDir, "package.json"), { encoding: "utf8" })
|
|
7986
7926
|
);
|
|
7987
7927
|
reproPackageJson.devDependencies?.vite || (reproPackageJson.devDependencies = {
|
|
7988
7928
|
...reproPackageJson.devDependencies,
|
|
@@ -7990,24 +7930,33 @@ var exec = async (command2, options = {}, {
|
|
|
7990
7930
|
}), reproPackageJson.devDependencies = {
|
|
7991
7931
|
...reproPackageJson.devDependencies,
|
|
7992
7932
|
"@types/node": "^22"
|
|
7993
|
-
}, await
|
|
7933
|
+
}, await writeFile8(join3(reproDir, "package.json"), JSON.stringify(reproPackageJson, null, 2)), await executeCommand({
|
|
7934
|
+
command: "yarn",
|
|
7935
|
+
args: ["install"],
|
|
7936
|
+
cwd: reproDir
|
|
7937
|
+
}), start && (logger17.info(`Running ${reproName} storybook`), await executeCommand({
|
|
7938
|
+
command: "yarn",
|
|
7939
|
+
args: ["run", "storybook"],
|
|
7940
|
+
cwd: reproDir
|
|
7941
|
+
}));
|
|
7994
7942
|
};
|
|
7995
7943
|
|
|
7996
7944
|
// src/migrate.ts
|
|
7997
|
-
import { logger as
|
|
7945
|
+
import { logger as logger18 } from "storybook/internal/node-logger";
|
|
7998
7946
|
import { listCodemods, runCodemod as runCodemod2 } from "@storybook/codemod";
|
|
7999
7947
|
async function migrate(migration, { glob, dryRun, list, rename: rename2, parser }) {
|
|
8000
7948
|
if (list)
|
|
8001
|
-
listCodemods().forEach((key) =>
|
|
7949
|
+
listCodemods().forEach((key) => logger18.log(key));
|
|
8002
7950
|
else if (migration)
|
|
8003
|
-
await runCodemod2(migration, { glob, dryRun, logger:
|
|
7951
|
+
await runCodemod2(migration, { glob, dryRun, logger: logger18, rename: rename2, parser });
|
|
8004
7952
|
else
|
|
8005
7953
|
throw new Error("Migrate: please specify a migration name or --list");
|
|
8006
7954
|
}
|
|
8007
7955
|
|
|
8008
7956
|
// src/sandbox.ts
|
|
7957
|
+
var import_cross_spawn2 = __toESM(require_cross_spawn(), 1);
|
|
8009
7958
|
import { existsSync as existsSync3 } from "node:fs";
|
|
8010
|
-
import {
|
|
7959
|
+
import { readdir, rm } from "node:fs/promises";
|
|
8011
7960
|
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
8012
7961
|
import {
|
|
8013
7962
|
JsPackageManagerFactory,
|
|
@@ -8015,9 +7964,8 @@ import {
|
|
|
8015
7964
|
optionalEnvToBoolean as optionalEnvToBoolean2,
|
|
8016
7965
|
versions as versions3
|
|
8017
7966
|
} from "storybook/internal/common";
|
|
8018
|
-
import { logger as
|
|
8019
|
-
|
|
8020
|
-
var import_picocolors15 = __toESM(require_picocolors(), 1), import_semver6 = __toESM(require_semver(), 1);
|
|
7967
|
+
import { logger as logger19, prompt as prompt4 } from "storybook/internal/node-logger";
|
|
7968
|
+
var import_picocolors14 = __toESM(require_picocolors(), 1), import_semver6 = __toESM(require_semver(), 1);
|
|
8021
7969
|
import { dedent as dedent14 } from "ts-dedent";
|
|
8022
7970
|
|
|
8023
7971
|
// src/sandbox-templates.ts
|
|
@@ -8090,7 +8038,10 @@ var baseTemplates = {
|
|
|
8090
8038
|
},
|
|
8091
8039
|
extraDependencies: ["server-only", "prop-types"]
|
|
8092
8040
|
},
|
|
8093
|
-
|
|
8041
|
+
initOptions: {
|
|
8042
|
+
builder: "webpack5" /* WEBPACK5 */
|
|
8043
|
+
},
|
|
8044
|
+
skipTasks: ["e2e-tests-dev", "e2e-tests", "bench", "vitest-integration"]
|
|
8094
8045
|
},
|
|
8095
8046
|
"nextjs/15-ts": {
|
|
8096
8047
|
name: "Next.js v15 (Webpack | TypeScript)",
|
|
@@ -8111,6 +8062,9 @@ var baseTemplates = {
|
|
|
8111
8062
|
},
|
|
8112
8063
|
extraDependencies: ["server-only", "prop-types"]
|
|
8113
8064
|
},
|
|
8065
|
+
initOptions: {
|
|
8066
|
+
builder: "webpack5" /* WEBPACK5 */
|
|
8067
|
+
},
|
|
8114
8068
|
skipTasks: ["e2e-tests", "bench", "vitest-integration"]
|
|
8115
8069
|
},
|
|
8116
8070
|
"nextjs/default-ts": {
|
|
@@ -8132,6 +8086,9 @@ var baseTemplates = {
|
|
|
8132
8086
|
},
|
|
8133
8087
|
extraDependencies: ["server-only", "prop-types"]
|
|
8134
8088
|
},
|
|
8089
|
+
initOptions: {
|
|
8090
|
+
builder: "webpack5" /* WEBPACK5 */
|
|
8091
|
+
},
|
|
8135
8092
|
skipTasks: ["bench", "vitest-integration"]
|
|
8136
8093
|
},
|
|
8137
8094
|
"nextjs/prerelease": {
|
|
@@ -8153,6 +8110,9 @@ var baseTemplates = {
|
|
|
8153
8110
|
},
|
|
8154
8111
|
extraDependencies: ["server-only", "prop-types"]
|
|
8155
8112
|
},
|
|
8113
|
+
initOptions: {
|
|
8114
|
+
builder: "webpack5" /* WEBPACK5 */
|
|
8115
|
+
},
|
|
8156
8116
|
skipTasks: ["e2e-tests", "bench", "vitest-integration"]
|
|
8157
8117
|
},
|
|
8158
8118
|
"nextjs-vite/14-ts": {
|
|
@@ -8173,7 +8133,7 @@ var baseTemplates = {
|
|
|
8173
8133
|
experimentalTestSyntax: !0
|
|
8174
8134
|
}
|
|
8175
8135
|
},
|
|
8176
|
-
extraDependencies: ["server-only", "
|
|
8136
|
+
extraDependencies: ["server-only", "vite", "prop-types"]
|
|
8177
8137
|
},
|
|
8178
8138
|
skipTasks: ["e2e-tests", "bench"]
|
|
8179
8139
|
},
|
|
@@ -8195,7 +8155,7 @@ var baseTemplates = {
|
|
|
8195
8155
|
experimentalTestSyntax: !0
|
|
8196
8156
|
}
|
|
8197
8157
|
},
|
|
8198
|
-
extraDependencies: ["server-only", "
|
|
8158
|
+
extraDependencies: ["server-only", "vite", "prop-types"]
|
|
8199
8159
|
},
|
|
8200
8160
|
skipTasks: ["e2e-tests", "bench"]
|
|
8201
8161
|
},
|
|
@@ -8217,7 +8177,7 @@ var baseTemplates = {
|
|
|
8217
8177
|
experimentalTestSyntax: !0
|
|
8218
8178
|
}
|
|
8219
8179
|
},
|
|
8220
|
-
extraDependencies: ["server-only", "
|
|
8180
|
+
extraDependencies: ["server-only", "vite", "prop-types"]
|
|
8221
8181
|
},
|
|
8222
8182
|
skipTasks: ["bench"]
|
|
8223
8183
|
},
|
|
@@ -8414,7 +8374,10 @@ var baseTemplates = {
|
|
|
8414
8374
|
renderer: "@storybook/html",
|
|
8415
8375
|
builder: "@storybook/builder-vite"
|
|
8416
8376
|
},
|
|
8417
|
-
skipTasks: ["e2e-tests", "bench", "vitest-integration"]
|
|
8377
|
+
skipTasks: ["e2e-tests", "bench", "vitest-integration"],
|
|
8378
|
+
initOptions: {
|
|
8379
|
+
type: "html" /* HTML */
|
|
8380
|
+
}
|
|
8418
8381
|
},
|
|
8419
8382
|
"html-vite/default-ts": {
|
|
8420
8383
|
name: "HTML Latest (Vite | TypeScript)",
|
|
@@ -8424,7 +8387,10 @@ var baseTemplates = {
|
|
|
8424
8387
|
renderer: "@storybook/html",
|
|
8425
8388
|
builder: "@storybook/builder-vite"
|
|
8426
8389
|
},
|
|
8427
|
-
skipTasks: ["e2e-tests", "bench", "vitest-integration"]
|
|
8390
|
+
skipTasks: ["e2e-tests", "bench", "vitest-integration"],
|
|
8391
|
+
initOptions: {
|
|
8392
|
+
type: "html" /* HTML */
|
|
8393
|
+
}
|
|
8428
8394
|
},
|
|
8429
8395
|
"svelte-vite/default-js": {
|
|
8430
8396
|
name: "Svelte Latest (Vite | JavaScript)",
|
|
@@ -8582,7 +8548,10 @@ var baseTemplates = {
|
|
|
8582
8548
|
}
|
|
8583
8549
|
}
|
|
8584
8550
|
},
|
|
8585
|
-
skipTasks: ["bench", "vitest-integration"]
|
|
8551
|
+
skipTasks: ["bench", "vitest-integration"],
|
|
8552
|
+
initOptions: {
|
|
8553
|
+
type: "react_native_web" /* REACT_NATIVE_WEB */
|
|
8554
|
+
}
|
|
8586
8555
|
},
|
|
8587
8556
|
"react-native-web-vite/rn-cli-ts": {
|
|
8588
8557
|
// NOTE: create-expo-app installs React 18.2.0. But yarn portal
|
|
@@ -8600,7 +8569,10 @@ var baseTemplates = {
|
|
|
8600
8569
|
renderer: "@storybook/react",
|
|
8601
8570
|
builder: "@storybook/builder-vite"
|
|
8602
8571
|
},
|
|
8603
|
-
skipTasks: ["e2e-tests", "bench", "vitest-integration"]
|
|
8572
|
+
skipTasks: ["e2e-tests", "bench", "vitest-integration"],
|
|
8573
|
+
initOptions: {
|
|
8574
|
+
type: "react_native_web" /* REACT_NATIVE_WEB */
|
|
8575
|
+
}
|
|
8604
8576
|
}
|
|
8605
8577
|
}, internalTemplates = {
|
|
8606
8578
|
"internal/react18-webpack-babel": {
|
|
@@ -8655,7 +8627,10 @@ var baseTemplates = {
|
|
|
8655
8627
|
builder: "@storybook/builder-webpack5"
|
|
8656
8628
|
},
|
|
8657
8629
|
isInternal: !0,
|
|
8658
|
-
skipTasks: ["bench", "vitest-integration"]
|
|
8630
|
+
skipTasks: ["bench", "vitest-integration"],
|
|
8631
|
+
initOptions: {
|
|
8632
|
+
type: "server" /* SERVER */
|
|
8633
|
+
}
|
|
8659
8634
|
}
|
|
8660
8635
|
}, benchTemplates = {
|
|
8661
8636
|
"bench/react-vite-default-ts": {
|
|
@@ -8804,47 +8779,49 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
8804
8779
|
}) => {
|
|
8805
8780
|
let selectedConfig = allTemplates[filterValue], templateId = selectedConfig ? filterValue : null, { packageManager: pkgMgr } = options, packageManager = JsPackageManagerFactory.getPackageManager({
|
|
8806
8781
|
force: pkgMgr
|
|
8807
|
-
}), latestVersion = await packageManager.latestVersion("storybook"), nextVersion = await packageManager.latestVersion("storybook@next") ?? "0.0.0", currentVersion = versions3.storybook, isPrerelease = (0, import_semver6.prerelease)(currentVersion), isOutdated = (0, import_semver6.lt)(currentVersion, isPrerelease ? nextVersion : latestVersion),
|
|
8808
|
-
welcome: `Creating a Storybook ${
|
|
8809
|
-
notLatest:
|
|
8810
|
-
This version is behind the latest release, which is: ${
|
|
8782
|
+
}), latestVersion = await packageManager.latestVersion("storybook"), nextVersion = await packageManager.latestVersion("storybook@next") ?? "0.0.0", currentVersion = versions3.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 = {
|
|
8783
|
+
welcome: `Creating a Storybook ${import_picocolors14.default.bold(currentVersion)} sandbox..`,
|
|
8784
|
+
notLatest: import_picocolors14.default.red(dedent14`
|
|
8785
|
+
This version is behind the latest release, which is: ${import_picocolors14.default.bold(latestVersion)}!
|
|
8811
8786
|
You likely ran the init command through npx, which can use a locally cached version, to get the latest please run:
|
|
8812
|
-
${
|
|
8787
|
+
${import_picocolors14.default.bold("npx storybook@latest sandbox")}
|
|
8813
8788
|
|
|
8814
8789
|
You may want to CTRL+C to stop, and run with the latest version instead.
|
|
8815
8790
|
`),
|
|
8816
|
-
longInitTime:
|
|
8791
|
+
longInitTime: import_picocolors14.default.yellow(
|
|
8817
8792
|
"The creation of the sandbox will take longer, because we will need to run init."
|
|
8818
8793
|
),
|
|
8819
|
-
prerelease:
|
|
8794
|
+
prerelease: import_picocolors14.default.yellow("This is a pre-release version.")
|
|
8820
8795
|
};
|
|
8821
|
-
if (
|
|
8796
|
+
if (logger19.logBox(
|
|
8822
8797
|
[messages2.welcome].concat(isOutdated && !isPrerelease ? [messages2.notLatest] : []).concat(init && (isOutdated || isPrerelease) ? [messages2.longInitTime] : []).concat(isPrerelease ? [messages2.prerelease] : []).join(`
|
|
8823
8798
|
`),
|
|
8824
|
-
{
|
|
8799
|
+
{
|
|
8800
|
+
rounded: !0
|
|
8801
|
+
}
|
|
8825
8802
|
), !selectedConfig) {
|
|
8826
8803
|
let filterRegex = new RegExp(`^${filterValue || ""}`, "i"), keys = Object.keys(allTemplates), choices = keys.reduce((acc, group) => {
|
|
8827
8804
|
let current = allTemplates[group];
|
|
8828
8805
|
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;
|
|
8829
8806
|
}, []);
|
|
8830
|
-
if (choices.length === 0 && (
|
|
8807
|
+
if (choices.length === 0 && (logger19.logBox(
|
|
8831
8808
|
dedent14`
|
|
8832
8809
|
🔎 You filtered out all templates. 🔍
|
|
8833
8810
|
|
|
8834
|
-
After filtering all the templates with "${
|
|
8811
|
+
After filtering all the templates with "${import_picocolors14.default.yellow(
|
|
8835
8812
|
filterValue
|
|
8836
8813
|
)}", we found no results. Please try again with a different filter.
|
|
8837
8814
|
|
|
8838
8815
|
Available templates:
|
|
8839
|
-
${keys.map((key) =>
|
|
8816
|
+
${keys.map((key) => import_picocolors14.default.blue(`- ${key}`)).join(`
|
|
8840
8817
|
`)}
|
|
8841
8818
|
`.trim(),
|
|
8842
8819
|
{ borderStyle: "round", padding: 1, borderColor: "#F1618C" }
|
|
8843
|
-
), process.exit(1)), choices.length === 1 ? [templateId] = choices : (
|
|
8820
|
+
), process.exit(1)), choices.length === 1 ? [templateId] = choices : (logger19.logBox(
|
|
8844
8821
|
dedent14`
|
|
8845
|
-
🤗 Welcome to ${
|
|
8822
|
+
🤗 Welcome to ${import_picocolors14.default.yellow("sb sandbox")}! 🤗
|
|
8846
8823
|
|
|
8847
|
-
Create a ${
|
|
8824
|
+
Create a ${import_picocolors14.default.green("new project")} to minimally reproduce Storybook issues.
|
|
8848
8825
|
|
|
8849
8826
|
1. select an environment that most closely matches your project setup.
|
|
8850
8827
|
2. select a location for the reproduction, outside of your project.
|
|
@@ -8853,14 +8830,14 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
8853
8830
|
`.trim(),
|
|
8854
8831
|
{ borderStyle: "round", padding: 1, borderColor: "#F1618C" }
|
|
8855
8832
|
), templateId = await promptSelectedTemplate(choices)), !!!(templateId ?? null)) {
|
|
8856
|
-
|
|
8833
|
+
logger19.error("Somehow we got no templates. Please rerun this command!");
|
|
8857
8834
|
return;
|
|
8858
8835
|
}
|
|
8859
8836
|
if (selectedConfig = templateId ? allTemplates[templateId] : void 0, !selectedConfig)
|
|
8860
8837
|
throw new Error("\u{1F6A8} Sandbox: please specify a valid template type");
|
|
8861
8838
|
}
|
|
8862
8839
|
let selectedDirectory = outputDirectory, outputDirectoryName = outputDirectory || templateId;
|
|
8863
|
-
selectedDirectory && existsSync3(`${selectedDirectory}`) && (
|
|
8840
|
+
selectedDirectory && existsSync3(`${selectedDirectory}`) && (logger19.log(`\u26A0\uFE0F ${selectedDirectory} already exists! Overwriting...`), await rm(selectedDirectory, { recursive: !0, force: !0 })), selectedDirectory || (selectedDirectory = await prompt4.text(
|
|
8864
8841
|
{
|
|
8865
8842
|
message: "Enter the output directory",
|
|
8866
8843
|
initialValue: outputDirectoryName ?? void 0,
|
|
@@ -8868,22 +8845,19 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
8868
8845
|
},
|
|
8869
8846
|
{
|
|
8870
8847
|
onCancel: () => {
|
|
8871
|
-
|
|
8848
|
+
logger19.log("Command cancelled by the user. Exiting..."), process.exit(1);
|
|
8872
8849
|
}
|
|
8873
8850
|
}
|
|
8874
8851
|
)), invariant(selectedDirectory);
|
|
8875
8852
|
try {
|
|
8876
8853
|
let templateDestination = isAbsolute2(selectedDirectory) ? selectedDirectory : join(process.cwd(), selectedDirectory);
|
|
8877
|
-
|
|
8854
|
+
logger19.log(`\u{1F3C3} Adding ${selectedConfig.name} into ${templateDestination}`), logger19.log(`\u{1F4E6} Downloading sandbox template (${import_picocolors14.default.bold(downloadType)})...`);
|
|
8878
8855
|
try {
|
|
8879
|
-
let gitPath = `
|
|
8880
|
-
if (
|
|
8881
|
-
|
|
8882
|
-
dir: templateDestination
|
|
8883
|
-
}), (await readdir(templateDestination)).length === 0) {
|
|
8884
|
-
let selected = import_picocolors15.default.yellow(templateId);
|
|
8856
|
+
let gitPath = `storybookjs/sandboxes/tree/${branch}/${templateId}/${downloadType}`;
|
|
8857
|
+
if ((0, import_cross_spawn2.sync)("npx", ["gitpick@4.12.4", gitPath, templateDestination, "-o"]), (await readdir(templateDestination)).length === 0) {
|
|
8858
|
+
let selected = import_picocolors14.default.yellow(templateId);
|
|
8885
8859
|
throw new Error(dedent14`
|
|
8886
|
-
Template downloaded from ${
|
|
8860
|
+
Template downloaded from ${import_picocolors14.default.blue(gitPath)} is empty.
|
|
8887
8861
|
Are you use it exists? Or did you want to set ${selected} to inDevelopment first?
|
|
8888
8862
|
`);
|
|
8889
8863
|
}
|
|
@@ -8894,35 +8868,36 @@ var toChoices = (c) => ({ label: allTemplates[c].name, value: c }), sandbox = as
|
|
|
8894
8868
|
await initiate({
|
|
8895
8869
|
dev: isCI() && !optionalEnvToBoolean2(process.env.IN_STORYBOOK_SANDBOX),
|
|
8896
8870
|
...options,
|
|
8871
|
+
...selectedConfig.initOptions || {},
|
|
8897
8872
|
features: ["docs", "test"]
|
|
8898
8873
|
}), process.chdir(before);
|
|
8899
8874
|
}
|
|
8900
8875
|
} catch (err) {
|
|
8901
|
-
throw
|
|
8876
|
+
throw logger19.error(`\u{1F6A8} Failed to download sandbox template: ${String(err)}`), err;
|
|
8902
8877
|
}
|
|
8903
|
-
let initMessage = init ?
|
|
8878
|
+
let initMessage = init ? import_picocolors14.default.yellow(dedent14`
|
|
8904
8879
|
yarn install
|
|
8905
8880
|
yarn storybook
|
|
8906
|
-
`) : `Recreate your setup, then ${
|
|
8907
|
-
|
|
8881
|
+
`) : `Recreate your setup, then ${import_picocolors14.default.yellow("npx storybook@latest init")}`;
|
|
8882
|
+
logger19.logBox(
|
|
8908
8883
|
dedent14`
|
|
8909
8884
|
🎉 Your Storybook reproduction project is ready to use! 🎉
|
|
8910
8885
|
|
|
8911
|
-
${
|
|
8886
|
+
${import_picocolors14.default.yellow(`cd ${selectedDirectory}`)}
|
|
8912
8887
|
${initMessage}
|
|
8913
8888
|
|
|
8914
8889
|
Once you've recreated the problem you're experiencing, please:
|
|
8915
8890
|
|
|
8916
|
-
1. Document any additional steps in ${
|
|
8891
|
+
1. Document any additional steps in ${import_picocolors14.default.cyan("README.md")}
|
|
8917
8892
|
2. Publish the repository to github
|
|
8918
8893
|
3. Link to the repro repository in your issue
|
|
8919
8894
|
|
|
8920
8895
|
Having a clean repro helps us solve your issue faster! 🙏
|
|
8921
8896
|
`.trim(),
|
|
8922
|
-
{
|
|
8897
|
+
{ rounded: !0 }
|
|
8923
8898
|
);
|
|
8924
8899
|
} catch (error) {
|
|
8925
|
-
throw
|
|
8900
|
+
throw logger19.error("\u{1F6A8} Failed to create sandbox"), error;
|
|
8926
8901
|
}
|
|
8927
8902
|
};
|
|
8928
8903
|
async function promptSelectedTemplate(choices) {
|
|
@@ -8933,15 +8908,14 @@ async function promptSelectedTemplate(choices) {
|
|
|
8933
8908
|
}
|
|
8934
8909
|
|
|
8935
8910
|
// src/upgrade.ts
|
|
8936
|
-
var
|
|
8937
|
-
import {
|
|
8911
|
+
var import_cross_spawn3 = __toESM(require_cross_spawn(), 1), import_picocolors15 = __toESM(require_picocolors(), 1), import_semver7 = __toESM(require_semver(), 1);
|
|
8912
|
+
import { PackageManagerName } from "storybook/internal/common";
|
|
8938
8913
|
import { HandledError, JsPackageManagerFactory as JsPackageManagerFactory2, isCorePackage as isCorePackage2 } from "storybook/internal/common";
|
|
8939
|
-
import { withTelemetry } from "storybook/internal/core-server";
|
|
8940
8914
|
import {
|
|
8941
|
-
CLI_COLORS as
|
|
8915
|
+
CLI_COLORS as CLI_COLORS4,
|
|
8942
8916
|
createHyperlink,
|
|
8943
8917
|
logTracker as logTracker3,
|
|
8944
|
-
logger as
|
|
8918
|
+
logger as logger21,
|
|
8945
8919
|
prompt as prompt6
|
|
8946
8920
|
} from "storybook/internal/node-logger";
|
|
8947
8921
|
import {
|
|
@@ -8952,11 +8926,11 @@ import { telemetry } from "storybook/internal/telemetry";
|
|
|
8952
8926
|
import { dedent as dedent15 } from "ts-dedent";
|
|
8953
8927
|
|
|
8954
8928
|
// src/automigrate/multi-project.ts
|
|
8955
|
-
import { CLI_COLORS as
|
|
8956
|
-
import { sanitizeError } from "storybook/internal/telemetry";
|
|
8929
|
+
import { CLI_COLORS as CLI_COLORS3, logger as logger20, prompt as prompt5 } from "storybook/internal/node-logger";
|
|
8930
|
+
import { ErrorCollector, sanitizeError } from "storybook/internal/telemetry";
|
|
8957
8931
|
async function collectAutomigrationsAcrossProjects(options) {
|
|
8958
8932
|
let { fixes, projects, taskLog } = options, automigrationMap = /* @__PURE__ */ new Map();
|
|
8959
|
-
|
|
8933
|
+
logger20.debug(
|
|
8960
8934
|
`Starting automigration collection across ${projects.length} projects and ${fixes.length} fixes...`
|
|
8961
8935
|
);
|
|
8962
8936
|
function collectResult(fix, project, status, result) {
|
|
@@ -8978,10 +8952,10 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
8978
8952
|
}
|
|
8979
8953
|
for (let project of projects) {
|
|
8980
8954
|
let projectName = shortenPath(project.configDir);
|
|
8981
|
-
taskLog.message(`Checking automigrations for ${projectName}...`),
|
|
8955
|
+
taskLog.message(`Checking automigrations for ${projectName}...`), logger20.debug(`Processing project: ${projectName}`);
|
|
8982
8956
|
for (let fix of fixes)
|
|
8983
8957
|
try {
|
|
8984
|
-
|
|
8958
|
+
logger20.debug(`Checking fix ${fix.id} for project ${projectName}...`);
|
|
8985
8959
|
let checkOptions = {
|
|
8986
8960
|
packageManager: project.packageManager,
|
|
8987
8961
|
configDir: project.configDir,
|
|
@@ -8993,9 +8967,9 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
8993
8967
|
}, result = await fix.check(checkOptions);
|
|
8994
8968
|
result !== null ? collectResult(fix, project, "check_succeeded", result) : collectResult(fix, project, "not_applicable");
|
|
8995
8969
|
} catch (error) {
|
|
8996
|
-
collectResult(fix, project, "check_failed"),
|
|
8970
|
+
collectResult(fix, project, "check_failed"), logger20.debug(
|
|
8997
8971
|
`Failed to check fix ${fix.id} for project ${shortenPath(project.configDir)}.`
|
|
8998
|
-
),
|
|
8972
|
+
), logger20.debug(`${error instanceof Error ? error.stack : String(error)}`), ErrorCollector.addError(error);
|
|
8999
8973
|
}
|
|
9000
8974
|
}
|
|
9001
8975
|
let allAutomigrations = Array.from(automigrationMap.values()), applicableAutomigrations = allAutomigrations.filter(
|
|
@@ -9009,9 +8983,9 @@ async function collectAutomigrationsAcrossProjects(options) {
|
|
|
9009
8983
|
);
|
|
9010
8984
|
return taskLog.message(`
|
|
9011
8985
|
Automigrations detected:`), successAutomigrations.forEach((fixId) => {
|
|
9012
|
-
taskLog.message(`${
|
|
8986
|
+
taskLog.message(`${CLI_COLORS3.success(`${logger20.SYMBOLS.success} ${fixId}`)}`);
|
|
9013
8987
|
}), failedAutomigrations.forEach((fixId) => {
|
|
9014
|
-
taskLog.message(`${
|
|
8988
|
+
taskLog.message(`${CLI_COLORS3.error(`${logger20.SYMBOLS.error} ${fixId}`)}`);
|
|
9015
8989
|
}), failedAutomigrations.length > 0 ? taskLog.error(
|
|
9016
8990
|
`${failedAutomigrations.length} automigration ${failedAutomigrations.length > 1 ? "checks" : "check"} failed`
|
|
9017
8991
|
) : taskLog.success(
|
|
@@ -9029,12 +9003,12 @@ async function promptForAutomigrations(automigrations, options) {
|
|
|
9029
9003
|
if (automigrations.length === 0)
|
|
9030
9004
|
return [];
|
|
9031
9005
|
if (options.dryRun)
|
|
9032
|
-
return
|
|
9033
|
-
|
|
9006
|
+
return logger20.log("Detected automigrations (dry run - no changes will be made):"), automigrations.forEach(({ fix, reports: list }) => {
|
|
9007
|
+
logger20.log(` - ${fix.id} (${formatProjectDirs(list)})`);
|
|
9034
9008
|
}), [];
|
|
9035
9009
|
if (options.yes)
|
|
9036
|
-
return
|
|
9037
|
-
|
|
9010
|
+
return logger20.log("Running all detected automigrations:"), automigrations.forEach(({ fix, reports: list }) => {
|
|
9011
|
+
logger20.log(` - ${fix.id} (${formatProjectDirs(list)})`);
|
|
9038
9012
|
}), automigrations;
|
|
9039
9013
|
let choices = automigrations.map((am) => {
|
|
9040
9014
|
let hint = [];
|
|
@@ -9083,13 +9057,13 @@ async function runAutomigrationsForProjects(selectedAutomigrations, options) {
|
|
|
9083
9057
|
title: `${countPrefix}Running automigrations for ${projectName}`
|
|
9084
9058
|
}) : {
|
|
9085
9059
|
message: (message) => {
|
|
9086
|
-
|
|
9060
|
+
logger20.debug(`${message}`);
|
|
9087
9061
|
},
|
|
9088
9062
|
error: (message) => {
|
|
9089
|
-
|
|
9063
|
+
logger20.debug(`${message}`);
|
|
9090
9064
|
},
|
|
9091
9065
|
success: (message) => {
|
|
9092
|
-
|
|
9066
|
+
logger20.debug(`${message}`);
|
|
9093
9067
|
}
|
|
9094
9068
|
}, fixResults = {}, fixFailures = {};
|
|
9095
9069
|
for (let automigration of projectAutomigration) {
|
|
@@ -9122,11 +9096,11 @@ async function runAutomigrationsForProjects(selectedAutomigrations, options) {
|
|
|
9122
9096
|
storybookVersion: project2.storybookVersion,
|
|
9123
9097
|
storiesPaths: project2.storiesPaths
|
|
9124
9098
|
};
|
|
9125
|
-
await fix.run(runOptions), fixResults[fix.id] = "succeeded" /* SUCCEEDED */, taskLog.message(
|
|
9099
|
+
await fix.run(runOptions), fixResults[fix.id] = "succeeded" /* SUCCEEDED */, taskLog.message(CLI_COLORS3.success(`${logger20.SYMBOLS.success} ${fix.id}`));
|
|
9126
9100
|
}
|
|
9127
9101
|
} catch (error) {
|
|
9128
9102
|
let errorMessage = (error instanceof Error ? error.stack : String(error)) ?? "Unknown error";
|
|
9129
|
-
fixResults[fix.id] = "failed" /* FAILED */, fixFailures[fix.id] = sanitizeError(error), taskLog.message(
|
|
9103
|
+
fixResults[fix.id] = "failed" /* FAILED */, fixFailures[fix.id] = sanitizeError(error), taskLog.message(CLI_COLORS3.error(`${logger20.SYMBOLS.error} ${automigration.fix.id}`)), logger20.debug(errorMessage), ErrorCollector.addError(error);
|
|
9130
9104
|
}
|
|
9131
9105
|
}
|
|
9132
9106
|
let automigrationsWithErrors = Object.values(fixResults).filter(
|
|
@@ -9235,29 +9209,29 @@ function logUpgradeResults(projectResults, detectedAutomigrations, doctorResults
|
|
|
9235
9209
|
doctorResults
|
|
9236
9210
|
);
|
|
9237
9211
|
if (failedProjects.length > 0) {
|
|
9238
|
-
if (logTracker3.enableLogWriting(),
|
|
9212
|
+
if (logTracker3.enableLogWriting(), logger21.step(
|
|
9239
9213
|
"The upgrade is complete, but some projects failed to upgrade or migrate completely. Please see the debug logs for more details."
|
|
9240
9214
|
), successfulProjects.length > 0) {
|
|
9241
9215
|
let successfulProjectsList = successfulProjects.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9242
9216
|
`);
|
|
9243
|
-
|
|
9217
|
+
logger21.log(`${CLI_COLORS4.success("Successfully upgraded:")}
|
|
9244
9218
|
${successfulProjectsList}`);
|
|
9245
9219
|
}
|
|
9246
9220
|
let failedProjectsList = failedProjects.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9247
9221
|
`);
|
|
9248
|
-
if (
|
|
9249
|
-
`${
|
|
9222
|
+
if (logger21.log(
|
|
9223
|
+
`${CLI_COLORS4.error("Failed to upgrade:")}
|
|
9250
9224
|
Some automigrations failed, please check the logs in the log file for more details.
|
|
9251
9225
|
${failedProjectsList}`
|
|
9252
9226
|
), projectsWithNoFixes.length > 0) {
|
|
9253
9227
|
let projectList = projectsWithNoFixes.map((dir) => ` \u2022 ${shortenPath(dir)}`).join(`
|
|
9254
9228
|
`);
|
|
9255
|
-
|
|
9229
|
+
logger21.log(`${CLI_COLORS4.info("No applicable migrations:")}
|
|
9256
9230
|
${projectList}`);
|
|
9257
9231
|
}
|
|
9258
9232
|
} else
|
|
9259
|
-
|
|
9260
|
-
`${
|
|
9233
|
+
Object.values(doctorResults).every((result) => result.status === "healthy") ? logger21.step(`${CLI_COLORS4.success("Your project(s) have been upgraded successfully! \u{1F389}")}`) : logger21.step(
|
|
9234
|
+
`${import_picocolors15.default.yellow("Your project(s) have been upgraded successfully, but some issues were found which need your attention, please check Storybook doctor logs above.")}`
|
|
9261
9235
|
);
|
|
9262
9236
|
let automigrationLinks = detectedAutomigrations.filter(
|
|
9263
9237
|
(am) => Object.entries(projectResults).some(
|
|
@@ -9271,10 +9245,10 @@ ${projectList}`);
|
|
|
9271
9245
|
...automigrationLinks
|
|
9272
9246
|
].join(`
|
|
9273
9247
|
`);
|
|
9274
|
-
|
|
9248
|
+
logger21.log(automigrationLinksMessage);
|
|
9275
9249
|
}
|
|
9276
|
-
|
|
9277
|
-
`For a full list of changes, please check our migration guide: ${
|
|
9250
|
+
logger21.log(
|
|
9251
|
+
`For a full list of changes, please check our migration guide: ${CLI_COLORS4.cta("https://storybook.js.org/docs/releases/migration-guide?ref=upgrade")}`
|
|
9278
9252
|
);
|
|
9279
9253
|
}
|
|
9280
9254
|
async function sendMultiUpgradeTelemetry(options) {
|
|
@@ -9305,150 +9279,147 @@ async function sendMultiUpgradeTelemetry(options) {
|
|
|
9305
9279
|
hasUserInterrupted
|
|
9306
9280
|
});
|
|
9307
9281
|
} catch (error) {
|
|
9308
|
-
|
|
9282
|
+
logger21.debug(`Failed to send multi-upgrade telemetry: ${String(error)}`);
|
|
9309
9283
|
}
|
|
9310
9284
|
}
|
|
9311
9285
|
async function upgrade(options) {
|
|
9312
|
-
await
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
`)}`) : logger20.info(
|
|
9324
|
-
`Upgrading from ${import_picocolors16.default.bold(storybookProjects[0].beforeVersion)} to ${import_picocolors16.default.bold(storybookProjects[0].currentCLIVersion)}`
|
|
9325
|
-
);
|
|
9326
|
-
let automigrationResults = {}, doctorResults = {}, handleInterruption = async () => {
|
|
9327
|
-
throw logger20.log(`
|
|
9286
|
+
let projectsResult = await getProjects(options);
|
|
9287
|
+
if (projectsResult === void 0 || projectsResult.selectedProjects.length === 0)
|
|
9288
|
+
return;
|
|
9289
|
+
let { allProjects, selectedProjects: storybookProjects } = projectsResult;
|
|
9290
|
+
storybookProjects.length > 1 ? logger21.info(`Upgrading the following projects:
|
|
9291
|
+
${storybookProjects.map((p) => `${import_picocolors15.default.cyan(shortenPath(p.configDir))}: ${import_picocolors15.default.bold(p.beforeVersion)} -> ${import_picocolors15.default.bold(p.currentCLIVersion)}`).join(`
|
|
9292
|
+
`)}`) : logger21.info(
|
|
9293
|
+
`Upgrading from ${import_picocolors15.default.bold(storybookProjects[0].beforeVersion)} to ${import_picocolors15.default.bold(storybookProjects[0].currentCLIVersion)}`
|
|
9294
|
+
);
|
|
9295
|
+
let automigrationResults = {}, doctorResults = {}, handleInterruption = async () => {
|
|
9296
|
+
throw logger21.log(`
|
|
9328
9297
|
|
|
9329
9298
|
Upgrade interrupted by user.`), allProjects.length > 1 && await sendMultiUpgradeTelemetry({
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9299
|
+
allProjects,
|
|
9300
|
+
selectedProjects: storybookProjects,
|
|
9301
|
+
projectResults: automigrationResults,
|
|
9302
|
+
doctorResults,
|
|
9303
|
+
hasUserInterrupted: !0
|
|
9304
|
+
}), new HandledError("Upgrade cancelled by user");
|
|
9305
|
+
};
|
|
9306
|
+
process.on("SIGINT", handleInterruption), process.on("SIGTERM", handleInterruption);
|
|
9307
|
+
try {
|
|
9308
|
+
if (processAutoblockerResults(storybookProjects, (message) => {
|
|
9309
|
+
logger21.error(dedent15`Blockers detected\n\n${message}`);
|
|
9310
|
+
}))
|
|
9311
|
+
throw new HandledError("Blockers detected");
|
|
9312
|
+
if (storybookProjects.some((project) => {
|
|
9313
|
+
if (!project.isCanary && (0, import_semver7.lt)(project.currentCLIVersion, project.beforeVersion))
|
|
9314
|
+
throw new UpgradeStorybookToLowerVersionError({
|
|
9315
|
+
beforeVersion: project.beforeVersion,
|
|
9316
|
+
currentVersion: project.currentCLIVersion
|
|
9317
|
+
});
|
|
9318
|
+
if (!project.beforeVersion)
|
|
9319
|
+
throw new UpgradeStorybookUnknownCurrentVersionError();
|
|
9320
|
+
}), !options.dryRun) {
|
|
9321
|
+
let task = prompt6.taskLog({
|
|
9322
|
+
id: "upgrade-dependencies",
|
|
9323
|
+
title: "Fetching versions to update package.json files.."
|
|
9324
|
+
});
|
|
9338
9325
|
try {
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
if (!project.isCanary && (0, import_semver7.lt)(project.currentCLIVersion, project.beforeVersion))
|
|
9345
|
-
throw new UpgradeStorybookToLowerVersionError({
|
|
9346
|
-
beforeVersion: project.beforeVersion,
|
|
9347
|
-
currentVersion: project.currentCLIVersion
|
|
9348
|
-
});
|
|
9349
|
-
if (!project.beforeVersion)
|
|
9350
|
-
throw new UpgradeStorybookUnknownCurrentVersionError();
|
|
9351
|
-
}), !options.dryRun) {
|
|
9352
|
-
let task = prompt6.taskLog({
|
|
9353
|
-
id: "upgrade-dependencies",
|
|
9354
|
-
title: "Fetching versions to update package.json files.."
|
|
9355
|
-
});
|
|
9356
|
-
try {
|
|
9357
|
-
let loggedPaths = [];
|
|
9358
|
-
for (let project of storybookProjects) {
|
|
9359
|
-
logger20.debug(`Updating dependencies in ${shortenPath(project.configDir)}...`);
|
|
9360
|
-
let newPaths = project.packageManager.packageJsonPaths.map(shortenPath).filter((path4) => !loggedPaths.includes(path4));
|
|
9361
|
-
newPaths.length > 0 && (task.message(newPaths.join(`
|
|
9326
|
+
let loggedPaths = [];
|
|
9327
|
+
for (let project of storybookProjects) {
|
|
9328
|
+
logger21.debug(`Updating dependencies in ${shortenPath(project.configDir)}...`);
|
|
9329
|
+
let newPaths = project.packageManager.packageJsonPaths.map(shortenPath).filter((path4) => !loggedPaths.includes(path4));
|
|
9330
|
+
newPaths.length > 0 && (task.message(newPaths.join(`
|
|
9362
9331
|
`)), loggedPaths.push(...newPaths)), await upgradeStorybookDependencies({
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
});
|
|
9370
|
-
}
|
|
9371
|
-
task.success("Updated package versions in package.json files");
|
|
9372
|
-
} catch (err) {
|
|
9373
|
-
task.error(`Failed to upgrade dependencies: ${String(err)}`);
|
|
9374
|
-
}
|
|
9375
|
-
}
|
|
9376
|
-
let { automigrationResults: automigrationResults2, detectedAutomigrations } = await runAutomigrations(
|
|
9377
|
-
storybookProjects,
|
|
9378
|
-
options
|
|
9379
|
-
), rootPackageManager = storybookProjects.length > 1 ? JsPackageManagerFactory2.getPackageManager({ force: options.packageManager }) : storybookProjects[0].packageManager;
|
|
9380
|
-
rootPackageManager.type === "npm" ? await rootPackageManager.installDependencies({ force: !0 }) : await rootPackageManager.installDependencies(), rootPackageManager.type !== "yarn1" && rootPackageManager.isStorybookInMonorepo() && (logger20.warn(
|
|
9381
|
-
"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."
|
|
9382
|
-
), options.yes || await prompt6.confirm({
|
|
9383
|
-
message: `Execute ${rootPackageManager.getRunCommand("dedupe")}?`,
|
|
9384
|
-
initialValue: !0
|
|
9385
|
-
}) ? rootPackageManager.type === "npm" ? await rootPackageManager.dedupeDependencies({ force: !0 }) : await rootPackageManager.dedupeDependencies() : logger20.log(
|
|
9386
|
-
`If you find any issues running Storybook, you can run ${rootPackageManager.getRunCommand("dedupe")} manually to deduplicate your dependencies and try again.`
|
|
9387
|
-
));
|
|
9388
|
-
let doctorProjects = storybookProjects.map((project) => ({
|
|
9389
|
-
configDir: project.configDir,
|
|
9390
|
-
packageManager: project.packageManager,
|
|
9391
|
-
storybookVersion: project.currentCLIVersion,
|
|
9392
|
-
mainConfig: project.mainConfig
|
|
9393
|
-
}));
|
|
9394
|
-
if (logger20.step("Checking the health of your project(s).."), doctorResults = await runMultiProjectDoctor(doctorProjects), displayDoctorResults(doctorResults) && logTracker3.enableLogWriting(), logUpgradeResults(automigrationResults2, detectedAutomigrations, doctorResults), !options.disableTelemetry) {
|
|
9395
|
-
for (let project of storybookProjects) {
|
|
9396
|
-
let resultData = automigrationResults2[project.configDir] || {
|
|
9397
|
-
automigrationStatuses: {},
|
|
9398
|
-
automigrationErrors: {}
|
|
9399
|
-
}, doctorFailureCount = 0, doctorErrorCount = 0;
|
|
9400
|
-
Object.values(doctorResults[project.configDir]?.diagnostics || {}).forEach((status) => {
|
|
9401
|
-
status === "has_issues" && doctorFailureCount++, status === "check_error" && doctorErrorCount++;
|
|
9402
|
-
});
|
|
9403
|
-
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;
|
|
9404
|
-
await telemetry("upgrade", {
|
|
9405
|
-
beforeVersion: project.beforeVersion,
|
|
9406
|
-
afterVersion: project.currentCLIVersion,
|
|
9407
|
-
automigrationResults: resultData.automigrationStatuses,
|
|
9408
|
-
automigrationErrors: resultData.automigrationErrors,
|
|
9409
|
-
automigrationFailureCount,
|
|
9410
|
-
automigrationPreCheckFailure,
|
|
9411
|
-
doctorResults: doctorResults[project.configDir]?.diagnostics || {},
|
|
9412
|
-
doctorFailureCount,
|
|
9413
|
-
doctorErrorCount
|
|
9414
|
-
});
|
|
9415
|
-
}
|
|
9416
|
-
await sendMultiUpgradeTelemetry({
|
|
9417
|
-
allProjects,
|
|
9418
|
-
selectedProjects: storybookProjects,
|
|
9419
|
-
projectResults: automigrationResults2,
|
|
9420
|
-
doctorResults
|
|
9332
|
+
packageManager: project.packageManager,
|
|
9333
|
+
isCanary: project.isCanary,
|
|
9334
|
+
isCLIOutdated: project.isCLIOutdated,
|
|
9335
|
+
isCLIPrerelease: project.isCLIPrerelease,
|
|
9336
|
+
isCLIExactLatest: project.isCLIExactLatest,
|
|
9337
|
+
isCLIExactPrerelease: project.isCLIExactPrerelease
|
|
9421
9338
|
});
|
|
9422
9339
|
}
|
|
9423
|
-
|
|
9424
|
-
|
|
9340
|
+
task.success("Updated package versions in package.json files");
|
|
9341
|
+
} catch (err) {
|
|
9342
|
+
task.error(`Failed to upgrade dependencies: ${String(err)}`);
|
|
9425
9343
|
}
|
|
9426
9344
|
}
|
|
9427
|
-
|
|
9345
|
+
let { automigrationResults: automigrationResults2, detectedAutomigrations } = await runAutomigrations(
|
|
9346
|
+
storybookProjects,
|
|
9347
|
+
options
|
|
9348
|
+
), rootPackageManager = storybookProjects.length > 1 ? JsPackageManagerFactory2.getPackageManager({ force: options.packageManager }) : storybookProjects[0].packageManager;
|
|
9349
|
+
rootPackageManager.type === "npm" ? await rootPackageManager.installDependencies({ force: !0 }) : await rootPackageManager.installDependencies(), rootPackageManager.type !== PackageManagerName.YARN1 && rootPackageManager.isStorybookInMonorepo() && (logger21.warn(
|
|
9350
|
+
"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."
|
|
9351
|
+
), options.yes || await prompt6.confirm({
|
|
9352
|
+
message: `Execute ${rootPackageManager.getRunCommand("dedupe")}?`,
|
|
9353
|
+
initialValue: !0
|
|
9354
|
+
}) ? rootPackageManager.type === "npm" ? await rootPackageManager.dedupeDependencies({ force: !0 }) : await rootPackageManager.dedupeDependencies() : logger21.log(
|
|
9355
|
+
`If you find any issues running Storybook, you can run ${rootPackageManager.getRunCommand("dedupe")} manually to deduplicate your dependencies and try again.`
|
|
9356
|
+
));
|
|
9357
|
+
let doctorProjects = storybookProjects.map((project) => ({
|
|
9358
|
+
configDir: project.configDir,
|
|
9359
|
+
packageManager: project.packageManager,
|
|
9360
|
+
storybookVersion: project.currentCLIVersion,
|
|
9361
|
+
mainConfig: project.mainConfig
|
|
9362
|
+
}));
|
|
9363
|
+
if (logger21.step("Checking the health of your project(s).."), doctorResults = await runMultiProjectDoctor(doctorProjects), displayDoctorResults(doctorResults) && logTracker3.enableLogWriting(), logUpgradeResults(automigrationResults2, detectedAutomigrations, doctorResults), !options.disableTelemetry) {
|
|
9364
|
+
for (let project of storybookProjects) {
|
|
9365
|
+
let resultData = automigrationResults2[project.configDir] || {
|
|
9366
|
+
automigrationStatuses: {},
|
|
9367
|
+
automigrationErrors: {}
|
|
9368
|
+
}, doctorFailureCount = 0, doctorErrorCount = 0;
|
|
9369
|
+
Object.values(doctorResults[project.configDir]?.diagnostics || {}).forEach((status) => {
|
|
9370
|
+
status === "has_issues" && doctorFailureCount++, status === "check_error" && doctorErrorCount++;
|
|
9371
|
+
});
|
|
9372
|
+
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;
|
|
9373
|
+
await telemetry("upgrade", {
|
|
9374
|
+
beforeVersion: project.beforeVersion,
|
|
9375
|
+
afterVersion: project.currentCLIVersion,
|
|
9376
|
+
automigrationResults: resultData.automigrationStatuses,
|
|
9377
|
+
automigrationErrors: resultData.automigrationErrors,
|
|
9378
|
+
automigrationFailureCount,
|
|
9379
|
+
automigrationPreCheckFailure,
|
|
9380
|
+
doctorResults: doctorResults[project.configDir]?.diagnostics || {},
|
|
9381
|
+
doctorFailureCount,
|
|
9382
|
+
doctorErrorCount
|
|
9383
|
+
});
|
|
9384
|
+
}
|
|
9385
|
+
await sendMultiUpgradeTelemetry({
|
|
9386
|
+
allProjects,
|
|
9387
|
+
selectedProjects: storybookProjects,
|
|
9388
|
+
projectResults: automigrationResults2,
|
|
9389
|
+
doctorResults
|
|
9390
|
+
});
|
|
9391
|
+
}
|
|
9392
|
+
} finally {
|
|
9393
|
+
process.removeListener("SIGINT", handleInterruption), process.removeListener("SIGTERM", handleInterruption);
|
|
9394
|
+
}
|
|
9428
9395
|
}
|
|
9429
9396
|
|
|
9430
9397
|
// src/bin/run.ts
|
|
9431
|
-
addToGlobalContext("cliVersion",
|
|
9432
|
-
var handleCommandFailure = async (error) => {
|
|
9433
|
-
error instanceof HandledError2 ||
|
|
9434
|
-
let logFile = await logTracker4.writeToFile();
|
|
9435
|
-
|
|
9398
|
+
addToGlobalContext("cliVersion", versions4.storybook);
|
|
9399
|
+
var handleCommandFailure = (logFilePath) => async (error) => {
|
|
9400
|
+
error instanceof HandledError2 || logger22.error(String(error));
|
|
9401
|
+
let logFile = await logTracker4.writeToFile(logFilePath);
|
|
9402
|
+
logger22.log(`Storybook debug logs can be found at: ${logFile}`), logger22.outro(""), process.exit(1);
|
|
9436
9403
|
}, command = (name) => program.command(name).option(
|
|
9437
9404
|
"--disable-telemetry",
|
|
9438
9405
|
"Disable sending telemetry data",
|
|
9439
9406
|
optionalEnvToBoolean3(process.env.STORYBOOK_DISABLE_TELEMETRY)
|
|
9440
|
-
).option("--debug", "Get more logs in debug mode", !1).option("--enable-crash-reports", "Enable sending crash reports to telemetry data").option(
|
|
9407
|
+
).option("--debug", "Get more logs in debug mode", !1).option("--enable-crash-reports", "Enable sending crash reports to telemetry data").option(
|
|
9408
|
+
"--logfile [path]",
|
|
9409
|
+
"Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided"
|
|
9410
|
+
).option("--loglevel <trace | debug | info | warn | error | silent>", "Define log level", "info").hook("preAction", async (self2) => {
|
|
9411
|
+
let options = self2.opts();
|
|
9412
|
+
options.debug && logger22.setLogLevel("debug"), options.loglevel && logger22.setLogLevel(options.loglevel), options.logfile && logTracker4.enableLogWriting();
|
|
9441
9413
|
try {
|
|
9442
|
-
|
|
9443
|
-
options.loglevel && logger21.setLogLevel(options.loglevel), options.writeLogs && logTracker4.enableLogWriting(), await globalSettings();
|
|
9414
|
+
await globalSettings();
|
|
9444
9415
|
} catch (e) {
|
|
9445
|
-
|
|
9416
|
+
logger22.error(`Error loading global settings:
|
|
9446
9417
|
` + String(e));
|
|
9447
9418
|
}
|
|
9448
|
-
}).hook("postAction", async () => {
|
|
9419
|
+
}).hook("postAction", async ({ getOptionValue }) => {
|
|
9449
9420
|
if (logTracker4.shouldWriteLogsToFile) {
|
|
9450
|
-
let logFile = await logTracker4.writeToFile();
|
|
9451
|
-
|
|
9421
|
+
let logFile = await logTracker4.writeToFile(getOptionValue("logfile"));
|
|
9422
|
+
logger22.log(`Storybook debug logs can be found at: ${logFile}`), logger22.outro(CLI_COLORS5.success("Done!"));
|
|
9452
9423
|
}
|
|
9453
9424
|
});
|
|
9454
9425
|
command("init").description("Initialize Storybook into your project").option("-f --force", "Force add Storybook").option("-s --skip-install", "Skip installing deps").option("--package-manager <npm|pnpm|yarn1|yarn2>", "Force package manager for installing deps").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(
|
|
@@ -9462,12 +9433,17 @@ command("init").description("Initialize Storybook into your project").option("-f
|
|
|
9462
9433
|
command("add <addon>").description("Add an addon to your Storybook").option(
|
|
9463
9434
|
"--package-manager <npm|pnpm|yarn1|yarn2|bun>",
|
|
9464
9435
|
"Force package manager for installing dependencies"
|
|
9465
|
-
).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) =>
|
|
9436
|
+
).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) => {
|
|
9437
|
+
withTelemetry("add", { cliOptions: options }, async () => {
|
|
9438
|
+
logger22.intro(`Setting up your project for ${addonName}`), await add(addonName, options), options.disableTelemetry || await telemetry2("add", { addon: addonName, source: "cli" }), logger22.outro("Done!");
|
|
9439
|
+
}).catch(handleCommandFailure);
|
|
9440
|
+
});
|
|
9466
9441
|
command("remove <addon>").description("Remove an addon from your Storybook").option(
|
|
9467
9442
|
"--package-manager <npm|pnpm|yarn1|yarn2|bun>",
|
|
9468
9443
|
"Force package manager for installing dependencies"
|
|
9469
9444
|
).option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option("-s --skip-install", "Skip installing deps").action(
|
|
9470
|
-
(addonName, options) =>
|
|
9445
|
+
(addonName, options) => withTelemetry("remove", { cliOptions: options }, async () => {
|
|
9446
|
+
logger22.intro(`Removing ${addonName} from your Storybook`);
|
|
9471
9447
|
let packageManager = JsPackageManagerFactory3.getPackageManager({
|
|
9472
9448
|
configDir: options.configDir,
|
|
9473
9449
|
force: options.packageManager
|
|
@@ -9476,20 +9452,26 @@ command("remove <addon>").description("Remove an addon from your Storybook").opt
|
|
|
9476
9452
|
configDir: options.configDir,
|
|
9477
9453
|
packageManager,
|
|
9478
9454
|
skipInstall: options.skipInstall
|
|
9479
|
-
}), options.disableTelemetry || await telemetry2("remove", { addon: addonName, source: "cli" });
|
|
9480
|
-
})
|
|
9455
|
+
}), options.disableTelemetry || await telemetry2("remove", { addon: addonName, source: "cli" }), logger22.outro("Done!");
|
|
9456
|
+
}).catch(handleCommandFailure(options.logfile))
|
|
9481
9457
|
);
|
|
9482
|
-
command("upgrade").description(`Upgrade your Storybook packages to v${
|
|
9458
|
+
command("upgrade").description(`Upgrade your Storybook packages to v${versions4.storybook}`).option(
|
|
9483
9459
|
"--package-manager <npm|pnpm|yarn1|yarn2|bun>",
|
|
9484
9460
|
"Force package manager for installing dependencies"
|
|
9485
9461
|
).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(
|
|
9486
9462
|
"-c, --config-dir <dir-name...>",
|
|
9487
9463
|
"Directory(ies) where to load Storybook configurations from"
|
|
9488
9464
|
).action(async (options) => {
|
|
9489
|
-
|
|
9465
|
+
await withTelemetry(
|
|
9466
|
+
"upgrade",
|
|
9467
|
+
{ cliOptions: { ...options, configDir: options.configDir?.[0] } },
|
|
9468
|
+
async () => {
|
|
9469
|
+
logger22.intro(`Storybook upgrade - v${versions4.storybook}`), await upgrade(options), logger22.outro("Storybook upgrade completed!");
|
|
9470
|
+
}
|
|
9471
|
+
).catch(handleCommandFailure(options.logfile));
|
|
9490
9472
|
});
|
|
9491
9473
|
command("info").description("Prints debugging information about the local environment").action(async () => {
|
|
9492
|
-
|
|
9474
|
+
logger22.log(import_picocolors16.default.bold(`
|
|
9493
9475
|
Storybook Environment Info:`));
|
|
9494
9476
|
let activePackageManager = JsPackageManagerFactory3.getPackageManager().type.replace(/\d/, ""), output = await import_envinfo.default.run({
|
|
9495
9477
|
System: ["OS", "CPU", "Shell"],
|
|
@@ -9498,10 +9480,10 @@ Storybook Environment Info:`));
|
|
|
9498
9480
|
npmPackages: "{@storybook/*,*storybook*,sb,chromatic}",
|
|
9499
9481
|
npmGlobalPackages: "{@storybook/*,*storybook*,sb,chromatic}"
|
|
9500
9482
|
}), activePackageManagerLine = output.match(new RegExp(`${activePackageManager}:.*`, "i"));
|
|
9501
|
-
|
|
9483
|
+
logger22.log(
|
|
9502
9484
|
output.replace(
|
|
9503
9485
|
activePackageManagerLine,
|
|
9504
|
-
|
|
9486
|
+
import_picocolors16.default.bold(`${activePackageManagerLine} <----- active`)
|
|
9505
9487
|
)
|
|
9506
9488
|
);
|
|
9507
9489
|
});
|
|
@@ -9511,33 +9493,36 @@ command("migrate [migration]").description("Run a Storybook codemod migration on
|
|
|
9511
9493
|
).option(
|
|
9512
9494
|
"-r --rename <from-to>",
|
|
9513
9495
|
'Rename suffix of matching files after codemod has been applied, e.g. ".js:.ts"'
|
|
9514
|
-
).action((migration,
|
|
9515
|
-
migrate
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
|
|
9522
|
-
})
|
|
9496
|
+
).action((migration, options) => {
|
|
9497
|
+
withTelemetry("migrate", { cliOptions: options }, async () => {
|
|
9498
|
+
logger22.intro(`Running ${migration} migration`), await migrate(migration, options), logger22.outro("Migration completed");
|
|
9499
|
+
}).catch(handleCommandFailure(options.logfile));
|
|
9500
|
+
});
|
|
9501
|
+
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) => {
|
|
9502
|
+
logger22.intro("Creating a Storybook sandbox..."), sandbox({ filterValue, ...options }).catch(handleCommandFailure).finally(() => {
|
|
9503
|
+
logger22.outro("Done!");
|
|
9504
|
+
});
|
|
9523
9505
|
});
|
|
9524
|
-
command("
|
|
9525
|
-
(
|
|
9506
|
+
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(
|
|
9507
|
+
(target, { local, start, logfile }) => link({ target, local, start }).catch(handleCommandFailure(logfile))
|
|
9526
9508
|
);
|
|
9527
|
-
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((target, { local, start }) => link({ target, local, start }).catch(handleCommandFailure));
|
|
9528
9509
|
command("automigrate [fixId]").description("Check storybook for incompatibilities or migrations and apply fixes").option("-y --yes", "Skip prompting the user").option("-n --dry-run", "Only check for fixes, do not actually run them").option("--package-manager <npm|pnpm|yarn1|yarn2|bun>", "Force package manager").option("-l --list", "List available migrations").option("-c, --config-dir <dir-name>", "Directory of Storybook configurations to migrate").option("-s --skip-install", "Skip installing deps").option(
|
|
9529
9510
|
"--renderer <renderer-pkg-name>",
|
|
9530
9511
|
"The renderer package for the framework Storybook is using."
|
|
9531
9512
|
).option("--skip-doctor", "Skip doctor check").action(async (fixId, options) => {
|
|
9532
|
-
|
|
9513
|
+
withTelemetry("automigrate", { cliOptions: options }, async () => {
|
|
9514
|
+
logger22.intro(fixId ? `Running ${fixId} automigration` : "Running automigrations"), await doAutomigrate({ fixId, ...options }), logger22.outro("Done");
|
|
9515
|
+
}).catch(handleCommandFailure(options.logfile));
|
|
9533
9516
|
});
|
|
9534
9517
|
command("doctor").description("Check Storybook for known problems and provide suggestions or fixes").option("--package-manager <npm|pnpm|yarn1|yarn2|bun>", "Force package manager").option("-c, --config-dir <dir-name>", "Directory of Storybook configuration").action(async (options) => {
|
|
9535
|
-
|
|
9518
|
+
withTelemetry("doctor", { cliOptions: options }, async () => {
|
|
9519
|
+
logger22.intro("Doctoring Storybook"), await doctor(options), logger22.outro("Done");
|
|
9520
|
+
}).catch(handleCommandFailure(options.logfile));
|
|
9536
9521
|
});
|
|
9537
9522
|
program.on("command:*", ([invalidCmd]) => {
|
|
9538
|
-
let errorMessage = ` Invalid command: ${
|
|
9523
|
+
let errorMessage = ` Invalid command: ${import_picocolors16.default.bold(invalidCmd)}.
|
|
9539
9524
|
See --help for a list of available commands.`, suggestion = program.commands.map((cmd) => cmd.name()).find((cmd) => leven(cmd, invalidCmd) < 3);
|
|
9540
9525
|
suggestion && (errorMessage += `
|
|
9541
|
-
Did you mean ${
|
|
9526
|
+
Did you mean ${import_picocolors16.default.yellow(suggestion)}?`), logger22.error(errorMessage), process.exit(1);
|
|
9542
9527
|
});
|
|
9543
9528
|
program.usage("<command> [options]").version(String(version)).parse(process.argv);
|