@storybook/cli 10.1.0-alpha.9 → 10.1.0-beta.1
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-BGKJ74J2.js → block-dependencies-versions-RWX4DX7W.js} +13 -16
- package/dist/_node-chunks/{block-experimental-addon-test-5WOB3QXI.js → block-experimental-addon-test-OM3MVIEF.js} +16 -23
- package/dist/_node-chunks/block-major-version-7X5ELMS5.js +77 -0
- package/dist/_node-chunks/block-node-version-IVL2SO4R.js +38 -0
- package/dist/_node-chunks/{block-webpack5-frameworks-UY6KAASI.js → block-webpack5-frameworks-DRJJONK4.js} +14 -19
- package/dist/_node-chunks/chunk-B52WZYLE.js +1160 -0
- package/dist/_node-chunks/chunk-H7CKG54H.js +45 -0
- package/dist/_node-chunks/chunk-IMEW6HKQ.js +11 -0
- package/dist/_node-chunks/chunk-OVP33YUF.js +591 -0
- package/dist/_node-chunks/chunk-YET6YMCR.js +4375 -0
- package/dist/_node-chunks/{globby-DNHQPHUT.js → globby-7EVLGXCD.js} +8 -8
- package/dist/_node-chunks/p-limit-DCVNL4HF.js +116 -0
- package/dist/_node-chunks/run-CFKOL6SH.js +9627 -0
- package/dist/bin/index.js +10 -13
- package/package.json +5 -9
- package/dist/_node-chunks/block-major-version-UQXLZ64F.js +0 -100
- package/dist/_node-chunks/block-node-version-QP5KXT5Q.js +0 -43
- package/dist/_node-chunks/chunk-3ISYWOFW.js +0 -1770
- package/dist/_node-chunks/chunk-5JXVRX4Y.js +0 -50
- package/dist/_node-chunks/chunk-7ZMKNOV3.js +0 -24
- package/dist/_node-chunks/chunk-KK6KWG7C.js +0 -1939
- package/dist/_node-chunks/chunk-QLMPSJFV.js +0 -6737
- package/dist/_node-chunks/p-limit-YAWAKA4U.js +0 -168
- package/dist/_node-chunks/run-IFPXJ7NW.js +0 -11461
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_7na3jaknjbu from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_7na3jaknjbu from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_7na3jaknjbu from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_7na3jaknjbu.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_7na3jaknjbu.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_7na3jaknjbu.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
var __create = Object.create;
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require < "u" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
});
|
|
23
|
+
var __commonJS = (cb, mod) => function() {
|
|
24
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
__require,
|
|
43
|
+
__commonJS,
|
|
44
|
+
__toESM
|
|
45
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_7na3jaknjbu from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_7na3jaknjbu from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_7na3jaknjbu from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_7na3jaknjbu.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_7na3jaknjbu.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_7na3jaknjbu.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_7na3jaknjbu from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_7na3jaknjbu from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_7na3jaknjbu from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_7na3jaknjbu.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_7na3jaknjbu.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_7na3jaknjbu.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
globby,
|
|
14
|
+
globbySync
|
|
15
|
+
} from "./chunk-YET6YMCR.js";
|
|
16
|
+
import {
|
|
17
|
+
require_semver
|
|
18
|
+
} from "./chunk-B52WZYLE.js";
|
|
19
|
+
import {
|
|
20
|
+
__commonJS,
|
|
21
|
+
__toESM
|
|
22
|
+
} from "./chunk-H7CKG54H.js";
|
|
23
|
+
|
|
24
|
+
// ../../node_modules/picocolors/picocolors.js
|
|
25
|
+
var require_picocolors = __commonJS({
|
|
26
|
+
"../../node_modules/picocolors/picocolors.js"(exports, module) {
|
|
27
|
+
var p = process || {}, argv = p.argv || [], env = p.env || {}, isColorSupported = !(env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI), formatter = (open, close, replace = open) => (input) => {
|
|
28
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
29
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
30
|
+
}, replaceClose = (string, close, replace, index) => {
|
|
31
|
+
let result = "", cursor = 0;
|
|
32
|
+
do
|
|
33
|
+
result += string.substring(cursor, index) + replace, cursor = index + close.length, index = string.indexOf(close, cursor);
|
|
34
|
+
while (~index);
|
|
35
|
+
return result + string.substring(cursor);
|
|
36
|
+
}, createColors = (enabled = isColorSupported) => {
|
|
37
|
+
let f = enabled ? formatter : () => String;
|
|
38
|
+
return {
|
|
39
|
+
isColorSupported: enabled,
|
|
40
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
41
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
42
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
43
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
44
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
45
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
46
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
47
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
48
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
49
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
50
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
51
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
52
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
53
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
54
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
55
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
56
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
57
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
58
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
59
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
60
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
61
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
62
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
63
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
64
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
65
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
66
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
67
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
68
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
69
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
70
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
71
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
72
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
73
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
74
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
75
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
76
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
77
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
78
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
79
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
80
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
module.exports = createColors();
|
|
84
|
+
module.exports.createColors = createColors;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// src/autoblock/utils.ts
|
|
89
|
+
var import_semver2 = __toESM(require_semver(), 1);
|
|
90
|
+
import { CLI_COLORS } from "storybook/internal/node-logger";
|
|
91
|
+
|
|
92
|
+
// src/util.ts
|
|
93
|
+
import { HandledError, JsPackageManager, normalizeStories } from "storybook/internal/common";
|
|
94
|
+
import { getProjectRoot, isSatelliteAddon, versions } from "storybook/internal/common";
|
|
95
|
+
import { StoryIndexGenerator, experimental_loadStorybook } from "storybook/internal/core-server";
|
|
96
|
+
import { logTracker, logger as logger2, prompt } from "storybook/internal/node-logger";
|
|
97
|
+
import {
|
|
98
|
+
UpgradeStorybookToLowerVersionError,
|
|
99
|
+
UpgradeStorybookUnknownCurrentVersionError
|
|
100
|
+
} from "storybook/internal/server-errors";
|
|
101
|
+
|
|
102
|
+
// ../../node_modules/empathic/walk.mjs
|
|
103
|
+
import { dirname } from "node:path";
|
|
104
|
+
|
|
105
|
+
// ../../node_modules/empathic/resolve.mjs
|
|
106
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
107
|
+
function absolute(input, root) {
|
|
108
|
+
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ../../node_modules/empathic/walk.mjs
|
|
112
|
+
function up(base, options) {
|
|
113
|
+
let { last, cwd } = options || {}, tmp = absolute(base, cwd), root = absolute(last || "/", cwd), prev, arr = [];
|
|
114
|
+
for (; prev !== root && (arr.push(tmp), tmp = dirname(prev = tmp), tmp !== prev); )
|
|
115
|
+
;
|
|
116
|
+
return arr;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/util.ts
|
|
120
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1), import_semver = __toESM(require_semver(), 1);
|
|
121
|
+
|
|
122
|
+
// src/autoblock/index.ts
|
|
123
|
+
var blockers = () => [
|
|
124
|
+
// add/remove blockers here
|
|
125
|
+
import("./block-dependencies-versions-RWX4DX7W.js"),
|
|
126
|
+
import("./block-node-version-IVL2SO4R.js"),
|
|
127
|
+
import("./block-webpack5-frameworks-DRJJONK4.js"),
|
|
128
|
+
import("./block-major-version-7X5ELMS5.js"),
|
|
129
|
+
import("./block-experimental-addon-test-OM3MVIEF.js")
|
|
130
|
+
], autoblock = async (options, list = blockers()) => list.length === 0 ? null : await Promise.all(
|
|
131
|
+
list.map(async (i) => {
|
|
132
|
+
let blocker = (await i).blocker;
|
|
133
|
+
return { result: await blocker.check(options), blocker };
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// src/automigrate/helpers/mainConfigFile.ts
|
|
138
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
139
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join2, normalize } from "node:path";
|
|
140
|
+
import {
|
|
141
|
+
JsPackageManagerFactory,
|
|
142
|
+
builderPackages,
|
|
143
|
+
extractFrameworkPackageName,
|
|
144
|
+
frameworkPackages,
|
|
145
|
+
getStorybookInfo
|
|
146
|
+
} from "storybook/internal/common";
|
|
147
|
+
import { frameworkToRenderer, getCoercedStorybookVersion } from "storybook/internal/common";
|
|
148
|
+
import { readConfig, writeConfig as writeConfigFile } from "storybook/internal/csf-tools";
|
|
149
|
+
import { logger } from "storybook/internal/node-logger";
|
|
150
|
+
var getFrameworkPackageName = (mainConfig) => {
|
|
151
|
+
let packageNameOrPath = typeof mainConfig?.framework == "string" ? mainConfig.framework : mainConfig?.framework?.name;
|
|
152
|
+
return packageNameOrPath ? extractFrameworkPackageName(packageNameOrPath) : null;
|
|
153
|
+
};
|
|
154
|
+
var getStorybookData = async ({
|
|
155
|
+
configDir: userDefinedConfigDir,
|
|
156
|
+
cwd,
|
|
157
|
+
packageManagerName
|
|
158
|
+
}) => {
|
|
159
|
+
logger.debug("Getting Storybook info...");
|
|
160
|
+
let {
|
|
161
|
+
mainConfig,
|
|
162
|
+
mainConfigPath,
|
|
163
|
+
configDir: configDirFromScript,
|
|
164
|
+
previewConfigPath
|
|
165
|
+
} = await getStorybookInfo(userDefinedConfigDir, cwd), configDir = userDefinedConfigDir || configDirFromScript || ".storybook";
|
|
166
|
+
logger.debug("Loading main config...");
|
|
167
|
+
let workingDir = isAbsolute2(configDir) ? dirname2(configDir) : dirname2(join2(cwd ?? process.cwd(), configDir));
|
|
168
|
+
logger.debug("Getting stories paths...");
|
|
169
|
+
let storiesPaths = await getStoriesPathsFromConfig({
|
|
170
|
+
stories: mainConfig.stories,
|
|
171
|
+
configDir,
|
|
172
|
+
workingDir
|
|
173
|
+
});
|
|
174
|
+
logger.debug("Getting package manager...");
|
|
175
|
+
let packageManager = JsPackageManagerFactory.getPackageManager({
|
|
176
|
+
force: packageManagerName,
|
|
177
|
+
configDir,
|
|
178
|
+
storiesPaths
|
|
179
|
+
});
|
|
180
|
+
logger.debug("Getting Storybook version...");
|
|
181
|
+
let storybookVersion = await getCoercedStorybookVersion(packageManager);
|
|
182
|
+
return {
|
|
183
|
+
configDir,
|
|
184
|
+
mainConfig,
|
|
185
|
+
storybookVersion,
|
|
186
|
+
mainConfigPath,
|
|
187
|
+
previewConfigPath,
|
|
188
|
+
packageManager,
|
|
189
|
+
storiesPaths
|
|
190
|
+
};
|
|
191
|
+
}, updateMainConfig = async ({ mainConfigPath, dryRun }, callback) => {
|
|
192
|
+
try {
|
|
193
|
+
let main = await readConfig(mainConfigPath);
|
|
194
|
+
await callback(main), dryRun || await writeConfigFile(main);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
logger.log(
|
|
197
|
+
`\u274C The migration failed to update your ${import_picocolors.default.blue(
|
|
198
|
+
mainConfigPath
|
|
199
|
+
)} on your behalf because of the following error:
|
|
200
|
+
${e}
|
|
201
|
+
`
|
|
202
|
+
), logger.log(
|
|
203
|
+
`\u26A0\uFE0F Storybook automigrations are based on AST parsing and it's possible that your ${import_picocolors.default.blue(
|
|
204
|
+
mainConfigPath
|
|
205
|
+
)} file contains a non-standard format (e.g. your export is not an object) or that there was an error when parsing dynamic values (e.g. "require" calls, or usage of environment variables). When your main config is non-standard, automigrations are unfortunately not possible. Please follow the instructions given previously and follow the documentation to make the updates manually.`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
function containsESMUsage(content) {
|
|
210
|
+
let hasImportStatement = /^\s*import\s+/m.test(content) || /^\s*import\s*{/m.test(content) || /^\s*import\s*\(/m.test(content), hasExportStatement = /^\s*export\s+/m.test(content) || /^\s*export\s*{/m.test(content) || /^\s*export\s*default/m.test(content), hasImportMeta = /import\.meta/.test(content);
|
|
211
|
+
return hasImportStatement || hasExportStatement || hasImportMeta;
|
|
212
|
+
}
|
|
213
|
+
function containsRequireUsage(content) {
|
|
214
|
+
let requireCallRegex = /\brequire\(/, requireDotRegex = /\brequire\./;
|
|
215
|
+
return requireCallRegex.test(content) || requireDotRegex.test(content);
|
|
216
|
+
}
|
|
217
|
+
function containsPatternUsage(content, pattern) {
|
|
218
|
+
let cleanContent = ((s) => s.replace(/(['"`])(?:\\.|(?!\1)[\s\S])*?\1/g, '""'))(content).replace(/\/\*[\s\S]*?\*\//g, "").split(`
|
|
219
|
+
`).map((line) => line.split("//")[0]).join(`
|
|
220
|
+
`);
|
|
221
|
+
return pattern.test(cleanContent);
|
|
222
|
+
}
|
|
223
|
+
function containsDirnameUsage(content) {
|
|
224
|
+
return containsPatternUsage(content, /\b__dirname\b/);
|
|
225
|
+
}
|
|
226
|
+
function containsFilenameUsage(content) {
|
|
227
|
+
return containsPatternUsage(content, /\b__filename\b/);
|
|
228
|
+
}
|
|
229
|
+
var bannerComment = "// This file has been automatically migrated to valid ESM format by Storybook.", hasRequireBanner = (content) => content.includes(bannerComment);
|
|
230
|
+
|
|
231
|
+
// src/util.ts
|
|
232
|
+
var STORYBOOK_DIR_PATTERN = ["**/.storybook", "**/.rnstorybook"], isSuccessResult = (result) => !("error" in result), isErrorResult = (result) => "error" in result, getVersionModifier = (versionSpecifier) => {
|
|
233
|
+
if (!versionSpecifier || typeof versionSpecifier != "string")
|
|
234
|
+
return { modifier: "", useFixed: !0 };
|
|
235
|
+
let firstPart = versionSpecifier.split(/\s*\|\|\s*/)[0]?.trim();
|
|
236
|
+
if (!firstPart)
|
|
237
|
+
return { modifier: "", useFixed: !0 };
|
|
238
|
+
let modifier = firstPart.match(/^([~^><=]+)/)?.[1] ?? "";
|
|
239
|
+
return {
|
|
240
|
+
modifier,
|
|
241
|
+
useFixed: !modifier
|
|
242
|
+
};
|
|
243
|
+
}, isCanaryVersion = (version) => version.startsWith("0.0.0") || version.startsWith("portal:") || version.startsWith("workspace:");
|
|
244
|
+
function validateVersion(version) {
|
|
245
|
+
if (!version)
|
|
246
|
+
throw new UpgradeStorybookUnknownCurrentVersionError();
|
|
247
|
+
}
|
|
248
|
+
var validateUpgradeCompatibility = (currentVersion, beforeVersion, isCanary) => {
|
|
249
|
+
if (!isCanary && (0, import_semver.lt)(currentVersion, beforeVersion))
|
|
250
|
+
throw new UpgradeStorybookToLowerVersionError({
|
|
251
|
+
beforeVersion,
|
|
252
|
+
currentVersion
|
|
253
|
+
});
|
|
254
|
+
}, findStorybookProjects = async (cwd = process.cwd()) => {
|
|
255
|
+
try {
|
|
256
|
+
logger2.debug("Finding Storybook projects...");
|
|
257
|
+
let storybookDirs = await globby(STORYBOOK_DIR_PATTERN, {
|
|
258
|
+
cwd,
|
|
259
|
+
dot: !0,
|
|
260
|
+
gitignore: !0,
|
|
261
|
+
absolute: !0,
|
|
262
|
+
onlyDirectories: !0,
|
|
263
|
+
followSymbolicLinks: !1
|
|
264
|
+
});
|
|
265
|
+
return logger2.debug(`Found ${storybookDirs.length} Storybook projects`), storybookDirs.length === 0 ? [await prompt.text({
|
|
266
|
+
message: "No Storybook projects were found. Please enter the path to the .storybook directory for the project you want to upgrade."
|
|
267
|
+
})] : storybookDirs;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
throw logger2.error("Failed to find Storybook projects"), error;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
var processProject = async ({
|
|
273
|
+
configDir,
|
|
274
|
+
options,
|
|
275
|
+
currentCLIVersion,
|
|
276
|
+
onScanStart
|
|
277
|
+
}) => {
|
|
278
|
+
try {
|
|
279
|
+
onScanStart();
|
|
280
|
+
let name = configDir.replace(getProjectRoot(), "");
|
|
281
|
+
logger2.debug("Getting Storybook data...");
|
|
282
|
+
let {
|
|
283
|
+
configDir: resolvedConfigDir,
|
|
284
|
+
mainConfig,
|
|
285
|
+
mainConfigPath,
|
|
286
|
+
packageManager,
|
|
287
|
+
previewConfigPath,
|
|
288
|
+
storiesPaths,
|
|
289
|
+
storybookVersion: beforeVersion
|
|
290
|
+
} = await getStorybookData({ configDir });
|
|
291
|
+
logger2.debug(`${name} - Validating before version... ${beforeVersion}`), validateVersion(beforeVersion);
|
|
292
|
+
let isCanary = isCanaryVersion(currentCLIVersion) || isCanaryVersion(beforeVersion);
|
|
293
|
+
logger2.debug(`${name} - Validating upgrade compatibility...`), validateUpgradeCompatibility(currentCLIVersion, beforeVersion, isCanary), logger2.debug(`${name} - Fetching NPM version information...`);
|
|
294
|
+
let [latestCLIVersionOnNPM, latestPrereleaseCLIVersionOnNPM] = await Promise.all([
|
|
295
|
+
packageManager.latestVersion("storybook"),
|
|
296
|
+
packageManager.latestVersion("storybook@next")
|
|
297
|
+
]), isCLIOutdated = (0, import_semver.lt)(currentCLIVersion, latestCLIVersionOnNPM), isCLIExactLatest = currentCLIVersion === latestCLIVersionOnNPM, isCLIPrerelease = (0, import_semver.prerelease)(currentCLIVersion) !== null, isCLIExactPrerelease = currentCLIVersion === latestPrereleaseCLIVersionOnNPM, isUpgrade = (0, import_semver.lt)(beforeVersion, currentCLIVersion), autoblockerCheckResults = null;
|
|
298
|
+
return typeof mainConfig != "boolean" && typeof mainConfigPath < "u" && !options.force && (logger2.debug(`${name} - Evaluating blockers...`), autoblockerCheckResults = await autoblock({
|
|
299
|
+
packageManager,
|
|
300
|
+
configDir: resolvedConfigDir,
|
|
301
|
+
mainConfig,
|
|
302
|
+
mainConfigPath
|
|
303
|
+
})), {
|
|
304
|
+
configDir: resolvedConfigDir,
|
|
305
|
+
mainConfig,
|
|
306
|
+
mainConfigPath,
|
|
307
|
+
packageManager,
|
|
308
|
+
isCanary,
|
|
309
|
+
isCLIOutdated,
|
|
310
|
+
isCLIPrerelease,
|
|
311
|
+
isCLIExactLatest,
|
|
312
|
+
isUpgrade,
|
|
313
|
+
beforeVersion,
|
|
314
|
+
currentCLIVersion,
|
|
315
|
+
latestCLIVersionOnNPM,
|
|
316
|
+
isCLIExactPrerelease,
|
|
317
|
+
autoblockerCheckResults,
|
|
318
|
+
previewConfigPath,
|
|
319
|
+
storiesPaths
|
|
320
|
+
};
|
|
321
|
+
} catch (error) {
|
|
322
|
+
return logger2.debug(String(error)), {
|
|
323
|
+
configDir,
|
|
324
|
+
error
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}, collectProjects = async (options, configDirs, onProjectScanStart) => {
|
|
328
|
+
let { default: pLimit } = await import("./p-limit-DCVNL4HF.js"), currentCLIVersion = versions.storybook, limit = pLimit(5), projectPromises = configDirs.map(
|
|
329
|
+
(configDir) => limit(
|
|
330
|
+
() => processProject({
|
|
331
|
+
configDir,
|
|
332
|
+
options,
|
|
333
|
+
currentCLIVersion,
|
|
334
|
+
onScanStart: () => onProjectScanStart()
|
|
335
|
+
})
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
return await Promise.all(projectPromises);
|
|
339
|
+
}, generateUpgradeSpecs = async (dependencies = {}, config) => {
|
|
340
|
+
let {
|
|
341
|
+
packageManager,
|
|
342
|
+
isCanary,
|
|
343
|
+
isCLIOutdated,
|
|
344
|
+
isCLIPrerelease,
|
|
345
|
+
isCLIExactPrerelease,
|
|
346
|
+
isCLIExactLatest
|
|
347
|
+
} = config, storybookCoreUpgrades = Object.keys(dependencies).filter(
|
|
348
|
+
(dependency) => dependency in versions
|
|
349
|
+
).map((dependency) => {
|
|
350
|
+
let versionSpec = dependencies[dependency];
|
|
351
|
+
if (!versionSpec)
|
|
352
|
+
return `${dependency}@${versions[dependency]}`;
|
|
353
|
+
let { modifier } = getVersionModifier(versionSpec);
|
|
354
|
+
return `${dependency}@${isCLIOutdated || isCanary ? "" : modifier}${versions[dependency]}`;
|
|
355
|
+
}), storybookSatelliteUpgrades = [];
|
|
356
|
+
if (isCLIExactPrerelease || isCLIExactLatest) {
|
|
357
|
+
let satelliteDependencies = Object.keys(dependencies).filter(isSatelliteAddon);
|
|
358
|
+
if (satelliteDependencies.length > 0)
|
|
359
|
+
try {
|
|
360
|
+
let upgradePromises = satelliteDependencies.map(async (dependency) => {
|
|
361
|
+
try {
|
|
362
|
+
let packageName = isCLIPrerelease ? `${dependency}@next` : dependency, mostRecentVersion = await packageManager.latestVersion(packageName);
|
|
363
|
+
if (!mostRecentVersion)
|
|
364
|
+
return null;
|
|
365
|
+
let { modifier } = getVersionModifier(dependencies[dependency] ?? "");
|
|
366
|
+
return `${dependency}@${modifier}${mostRecentVersion}`;
|
|
367
|
+
} catch {
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
storybookSatelliteUpgrades = (await Promise.all(upgradePromises)).filter((result) => result !== null);
|
|
372
|
+
} catch {
|
|
373
|
+
logger2.warn("Failed to fetch satellite dependencies");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return [...storybookCoreUpgrades, ...storybookSatelliteUpgrades];
|
|
377
|
+
}, upgradeStorybookDependencies = async (config) => {
|
|
378
|
+
let { packageManager } = config;
|
|
379
|
+
for (let packageJsonPath of packageManager.packageJsonPaths) {
|
|
380
|
+
let packageJson = JsPackageManager.getPackageJson(packageJsonPath), [upgradedDependencies, upgradedDevDependencies, upgradedPeerDependencies] = await Promise.all([
|
|
381
|
+
generateUpgradeSpecs(packageJson.dependencies, config),
|
|
382
|
+
generateUpgradeSpecs(packageJson.devDependencies, config),
|
|
383
|
+
generateUpgradeSpecs(packageJson.peerDependencies, config)
|
|
384
|
+
]);
|
|
385
|
+
logger2.debug(JSON.stringify({ upgradedDependencies }, null, 2)), logger2.debug(JSON.stringify({ upgradedDevDependencies }, null, 2)), logger2.debug(JSON.stringify({ upgradedPeerDependencies }, null, 2)), await packageManager.addDependencies(
|
|
386
|
+
{
|
|
387
|
+
type: "dependencies",
|
|
388
|
+
skipInstall: !0,
|
|
389
|
+
packageJsonInfo: JsPackageManager.getPackageJsonInfo(packageJsonPath)
|
|
390
|
+
},
|
|
391
|
+
upgradedDependencies
|
|
392
|
+
), await packageManager.addDependencies(
|
|
393
|
+
{
|
|
394
|
+
type: "devDependencies",
|
|
395
|
+
skipInstall: !0,
|
|
396
|
+
packageJsonInfo: JsPackageManager.getPackageJsonInfo(packageJsonPath)
|
|
397
|
+
},
|
|
398
|
+
upgradedDevDependencies
|
|
399
|
+
), await packageManager.addDependencies(
|
|
400
|
+
{
|
|
401
|
+
type: "peerDependencies",
|
|
402
|
+
skipInstall: !0,
|
|
403
|
+
packageJsonInfo: JsPackageManager.getPackageJsonInfo(packageJsonPath)
|
|
404
|
+
},
|
|
405
|
+
upgradedPeerDependencies
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
}, formatProjectDirectories = (projectData, modifier) => projectData.length === 0 ? "" : projectData.map((project) => project.configDir).map((dir) => `${modifier} ${import_picocolors2.default.cyan(shortenPath(dir))}`).join(`
|
|
409
|
+
`), shortenPath = (path) => {
|
|
410
|
+
let gitRoot = getProjectRoot();
|
|
411
|
+
return path.replace(gitRoot, "");
|
|
412
|
+
}, handleMultipleProjects = async (validProjects, errorProjects, detectedConfigDirs, yes) => {
|
|
413
|
+
let allPackageJsonPaths = validProjects.flatMap((data) => data.packageManager.packageJsonPaths).filter(JsPackageManager.hasAnyStorybookDependency);
|
|
414
|
+
if (new Set(allPackageJsonPaths).size !== allPackageJsonPaths.length) {
|
|
415
|
+
let projectsFoundMessage = [
|
|
416
|
+
"Multiple Storybook projects found. Storybook can only upgrade all projects at once:"
|
|
417
|
+
];
|
|
418
|
+
if (validProjects.length > 0 && projectsFoundMessage.push(formatProjectDirectories(validProjects, logger2.SYMBOLS.success)), errorProjects.length > 0 && (logTracker.enableLogWriting(), projectsFoundMessage.push(
|
|
419
|
+
`There were some errors while collecting data for the following projects:
|
|
420
|
+
${formatProjectDirectories(errorProjects, logger2.SYMBOLS.error)}`,
|
|
421
|
+
"",
|
|
422
|
+
"Full logs will be available in the Storybook debug logs at the end of the run."
|
|
423
|
+
)), logger2.log(projectsFoundMessage.join(`
|
|
424
|
+
`)), !(yes || await prompt.confirm({
|
|
425
|
+
message: "Continue with the upgrade?",
|
|
426
|
+
initialValue: !0
|
|
427
|
+
})))
|
|
428
|
+
throw new HandledError("Upgrade cancelled by user");
|
|
429
|
+
return [...validProjects];
|
|
430
|
+
}
|
|
431
|
+
if (detectedConfigDirs.length > 1) {
|
|
432
|
+
let selectedConfigDirs = await prompt.multiselect({
|
|
433
|
+
message: "Select which projects to upgrade",
|
|
434
|
+
options: detectedConfigDirs.map((configDir) => ({
|
|
435
|
+
label: shortenPath(configDir),
|
|
436
|
+
value: configDir
|
|
437
|
+
}))
|
|
438
|
+
});
|
|
439
|
+
return validProjects.filter((data) => selectedConfigDirs.includes(data.configDir));
|
|
440
|
+
}
|
|
441
|
+
}, getProjects = async (options) => {
|
|
442
|
+
try {
|
|
443
|
+
let task = prompt.spinner({ id: "detect-projects" });
|
|
444
|
+
task.start("Detecting projects...");
|
|
445
|
+
let detectedConfigDirs = options.configDir ?? [];
|
|
446
|
+
(!options.configDir || options.configDir.length === 0) && (detectedConfigDirs = await findStorybookProjects());
|
|
447
|
+
let count = 0, projects = await collectProjects(
|
|
448
|
+
options,
|
|
449
|
+
detectedConfigDirs,
|
|
450
|
+
() => task.message(`Detecting projects: ${++count} projects`)
|
|
451
|
+
);
|
|
452
|
+
task.stop(`${projects.length} ${projects.length > 1 ? "projects" : "project"} detected`);
|
|
453
|
+
let validProjects = projects.filter(isSuccessResult), errorProjects = projects.filter(isErrorResult);
|
|
454
|
+
if (logger2.debug(
|
|
455
|
+
`Found ${validProjects.length} valid projects and ${errorProjects.length} error projects`
|
|
456
|
+
), validProjects.length === 1)
|
|
457
|
+
return { allProjects: validProjects, selectedProjects: validProjects };
|
|
458
|
+
if (validProjects.length === 0 && errorProjects.length > 0) {
|
|
459
|
+
let errorMessage = errorProjects.map((project) => `${shortenPath(project.configDir)}:
|
|
460
|
+
${project.error.stack || project.error.message}`).join(`
|
|
461
|
+
`);
|
|
462
|
+
throw new Error(
|
|
463
|
+
`\u274C Storybook found errors while collecting data for the following projects:
|
|
464
|
+
${errorMessage}
|
|
465
|
+
Please fix the errors and run the upgrade command again.`
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
let selectedProjects = await handleMultipleProjects(
|
|
469
|
+
validProjects,
|
|
470
|
+
errorProjects,
|
|
471
|
+
detectedConfigDirs,
|
|
472
|
+
options.yes
|
|
473
|
+
);
|
|
474
|
+
return selectedProjects ? { allProjects: validProjects, selectedProjects } : void 0;
|
|
475
|
+
} catch (error) {
|
|
476
|
+
throw error instanceof HandledError || logger2.error("Failed to get projects"), error;
|
|
477
|
+
}
|
|
478
|
+
}, findFilesUp = (matchers, cwd) => {
|
|
479
|
+
let matchingFiles = [];
|
|
480
|
+
for (let directory of up(cwd, { last: getProjectRoot() }))
|
|
481
|
+
matchingFiles.push(
|
|
482
|
+
...globbySync(matchers, {
|
|
483
|
+
gitignore: !0,
|
|
484
|
+
absolute: !0,
|
|
485
|
+
cwd: directory
|
|
486
|
+
})
|
|
487
|
+
);
|
|
488
|
+
return matchingFiles;
|
|
489
|
+
};
|
|
490
|
+
var getStoriesPathsFromConfig = async ({
|
|
491
|
+
stories,
|
|
492
|
+
configDir,
|
|
493
|
+
workingDir
|
|
494
|
+
}) => {
|
|
495
|
+
if (stories.length === 0)
|
|
496
|
+
return [];
|
|
497
|
+
let normalizedStories = normalizeStories(stories, {
|
|
498
|
+
configDir,
|
|
499
|
+
workingDir
|
|
500
|
+
});
|
|
501
|
+
return (await StoryIndexGenerator.findMatchingFilesForSpecifiers(
|
|
502
|
+
normalizedStories,
|
|
503
|
+
workingDir,
|
|
504
|
+
!0
|
|
505
|
+
)).flatMap(([specifier, cache]) => StoryIndexGenerator.storyFileNames(/* @__PURE__ */ new Map([[specifier, cache]])));
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// src/autoblock/utils.ts
|
|
509
|
+
var typedKeys = (obj) => Object.keys(obj);
|
|
510
|
+
async function findOutdatedPackage(minimalVersionsMap, options) {
|
|
511
|
+
return (await Promise.all(
|
|
512
|
+
typedKeys(minimalVersionsMap).map(async (packageName) => ({
|
|
513
|
+
packageName,
|
|
514
|
+
installedVersion: (await options.packageManager.getModulePackageJSON(packageName))?.version ?? null,
|
|
515
|
+
minimumVersion: minimalVersionsMap[packageName]
|
|
516
|
+
}))
|
|
517
|
+
)).reduce(
|
|
518
|
+
(acc, { installedVersion, minimumVersion, packageName }) => acc || (packageName && installedVersion && (0, import_semver2.lt)(installedVersion, minimumVersion) ? {
|
|
519
|
+
installedVersion,
|
|
520
|
+
packageName,
|
|
521
|
+
minimumVersion
|
|
522
|
+
} : acc),
|
|
523
|
+
!1
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
function processAutoblockerResults(projects, onError) {
|
|
527
|
+
let autoblockerMessagesMap = /* @__PURE__ */ new Map();
|
|
528
|
+
projects.forEach((result) => {
|
|
529
|
+
result.autoblockerCheckResults?.forEach((blocker) => {
|
|
530
|
+
if (blocker.result === null || blocker.result === !1)
|
|
531
|
+
return;
|
|
532
|
+
let blockerResult = blocker.blocker.log(blocker.result), message = blockerResult.message, link = blockerResult.link;
|
|
533
|
+
autoblockerMessagesMap.has(message) ? autoblockerMessagesMap.get(message).configDirs.push(result.configDir) : autoblockerMessagesMap.set(message, {
|
|
534
|
+
title: blockerResult.title,
|
|
535
|
+
message,
|
|
536
|
+
link,
|
|
537
|
+
configDirs: [result.configDir]
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
let autoblockerMessages = Array.from(autoblockerMessagesMap.values());
|
|
542
|
+
if (autoblockerMessages.length > 0) {
|
|
543
|
+
let formatConfigDirs = (configDirs) => {
|
|
544
|
+
let baseMessage = "Affected projects:", relativeDirs = configDirs.map((dir) => shortenPath(dir) || ".");
|
|
545
|
+
if (relativeDirs.length <= 3)
|
|
546
|
+
return `${baseMessage} ${relativeDirs.join(", ")}`;
|
|
547
|
+
let remaining = relativeDirs.length - 3;
|
|
548
|
+
return `${baseMessage} ${relativeDirs.slice(0, 3).join(", ")}${remaining > 0 ? ` and ${remaining} more...` : ""}`;
|
|
549
|
+
}, formattedMessages = autoblockerMessages.map((item) => {
|
|
550
|
+
let message = `${CLI_COLORS.warning(item.title)}
|
|
551
|
+
|
|
552
|
+
${item.message}
|
|
553
|
+
|
|
554
|
+
${formatConfigDirs(item.configDirs)}`;
|
|
555
|
+
return item.link && (message += `
|
|
556
|
+
|
|
557
|
+
More information: ${item.link}`), message;
|
|
558
|
+
});
|
|
559
|
+
return onError(
|
|
560
|
+
`Storybook has found potential blockers that need to be resolved before upgrading:
|
|
561
|
+
|
|
562
|
+
${[...formattedMessages].join(`
|
|
563
|
+
|
|
564
|
+
`)}
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
After addressing this, you can try running the upgrade command again. You can also rerun the upgrade command with the ${CLI_COLORS.info("--force")} flag to skip the blocker check and to proceed with the upgrade.`
|
|
569
|
+
), !0;
|
|
570
|
+
}
|
|
571
|
+
return !1;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export {
|
|
575
|
+
require_picocolors,
|
|
576
|
+
findOutdatedPackage,
|
|
577
|
+
processAutoblockerResults,
|
|
578
|
+
upgradeStorybookDependencies,
|
|
579
|
+
shortenPath,
|
|
580
|
+
getProjects,
|
|
581
|
+
findFilesUp,
|
|
582
|
+
getFrameworkPackageName,
|
|
583
|
+
getStorybookData,
|
|
584
|
+
updateMainConfig,
|
|
585
|
+
containsESMUsage,
|
|
586
|
+
containsRequireUsage,
|
|
587
|
+
containsDirnameUsage,
|
|
588
|
+
containsFilenameUsage,
|
|
589
|
+
bannerComment,
|
|
590
|
+
hasRequireBanner
|
|
591
|
+
};
|