@storybook/cli 11.0.0-alpha.1 → 11.0.0-alpha.3

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.
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_ejw65m8bp8s from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ejw65m8bp8s from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ejw65m8bp8s from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ft71o55xt7f from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ft71o55xt7f from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ft71o55xt7f from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ejw65m8bp8s.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ejw65m8bp8s.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ejw65m8bp8s.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ft71o55xt7f.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ft71o55xt7f.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ft71o55xt7f.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -12,14 +12,14 @@ var require = CJS_COMPAT_NODE_MODULE_ejw65m8bp8s.createRequire(import.meta.url);
12
12
  import {
13
13
  globby,
14
14
  globbySync
15
- } from "./chunk-DM3PGJRR.js";
15
+ } from "./chunk-HOYDQ5IU.js";
16
16
  import {
17
17
  require_semver
18
- } from "./chunk-5FE4RXTH.js";
18
+ } from "./chunk-FFWBHZJ6.js";
19
19
  import {
20
20
  __commonJS,
21
21
  __toESM
22
- } from "./chunk-PCYXDPOV.js";
22
+ } from "./chunk-6WU77S4B.js";
23
23
 
24
24
  // ../../../node_modules/picocolors/picocolors.js
25
25
  var require_picocolors = __commonJS({
@@ -104,7 +104,7 @@ import {
104
104
  experimental_loadStorybook,
105
105
  getStoriesPathsFromConfig
106
106
  } from "storybook/internal/core-server";
107
- import { logTracker, logger as logger2, prompt } from "storybook/internal/node-logger";
107
+ import { logTracker, logger, prompt } from "storybook/internal/node-logger";
108
108
  import {
109
109
  UpgradeStorybookToLowerVersionError,
110
110
  UpgradeStorybookUnknownCurrentVersionError
@@ -128,17 +128,18 @@ function up(base, options) {
128
128
  }
129
129
 
130
130
  // src/util.ts
131
- var import_picocolors2 = __toESM(require_picocolors(), 1), import_semver = __toESM(require_semver(), 1);
131
+ var import_picocolors = __toESM(require_picocolors(), 1), import_semver = __toESM(require_semver(), 1);
132
132
 
133
133
  // src/autoblock/index.ts
134
134
  var blockers = () => [
135
135
  // add/remove blockers here
136
- import("./block-dependencies-versions-6RWASWRE.js"),
137
- import("./block-create-react-app-5WUURBEP.js"),
138
- import("./block-node-version-KVUWT5EX.js"),
139
- import("./block-webpack5-frameworks-LACV2DMG.js"),
140
- import("./block-major-version-6LSQ7CKE.js"),
141
- import("./block-experimental-addon-test-PM6V5OKU.js")
136
+ import("./block-dependencies-versions-JPEPIUKB.js"),
137
+ import("./block-create-react-app-NIM5OOA3.js"),
138
+ import("./block-node-version-E4VDUXTX.js"),
139
+ import("./block-webpack5-frameworks-CQYV65P6.js"),
140
+ import("./block-major-version-K75BAQWK.js"),
141
+ import("./block-experimental-addon-test-WOWVN4IX.js"),
142
+ import("./block-react-legacy-root-api-XK44TU4N.js")
142
143
  ], autoblock = async (options, list = blockers()) => list.length === 0 ? null : await Promise.all(
143
144
  list.map(async (i) => {
144
145
  let blocker = (await i).blocker;
@@ -147,15 +148,8 @@ var blockers = () => [
147
148
  );
148
149
 
149
150
  // src/automigrate/helpers/mainConfigFile.ts
150
- var import_picocolors = __toESM(require_picocolors(), 1);
151
- import {
152
- builderPackages,
153
- extractFrameworkPackageName,
154
- frameworkPackages
155
- } from "storybook/internal/common";
151
+ import { extractFrameworkPackageName, frameworkPackages } from "storybook/internal/common";
156
152
  import { frameworkToRenderer } from "storybook/internal/common";
157
- import { readConfig, writeConfig as writeConfigFile } from "storybook/internal/csf-tools";
158
- import { logger } from "storybook/internal/node-logger";
159
153
  import { getStorybookData } from "storybook/internal/cli";
160
154
  var getFrameworkPackageName = (mainConfig) => {
161
155
  let packageNameOrPath = typeof mainConfig?.framework == "string" ? mainConfig.framework : mainConfig?.framework?.name;
@@ -167,45 +161,6 @@ var getFrameworkPackageName = (mainConfig) => {
167
161
  let frameworkName = frameworkPackages[frameworkPackageName];
168
162
  return frameworkToRenderer[frameworkName];
169
163
  };
170
- var updateMainConfig = async ({ mainConfigPath, dryRun }, callback) => {
171
- try {
172
- let main = await readConfig(mainConfigPath);
173
- await callback(main), dryRun || await writeConfigFile(main);
174
- } catch (e) {
175
- logger.log(
176
- `\u274C The migration failed to update your ${import_picocolors.default.blue(
177
- mainConfigPath
178
- )} on your behalf because of the following error:
179
- ${e}
180
- `
181
- ), logger.log(
182
- `\u26A0\uFE0F Storybook automigrations are based on AST parsing and it's possible that your ${import_picocolors.default.blue(
183
- mainConfigPath
184
- )} 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.`
185
- );
186
- }
187
- };
188
- function containsESMUsage(content) {
189
- 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);
190
- return hasImportStatement || hasExportStatement || hasImportMeta;
191
- }
192
- function containsRequireUsage(content) {
193
- let requireCallRegex = /\brequire\(/, requireDotRegex = /\brequire\./;
194
- return requireCallRegex.test(content) || requireDotRegex.test(content);
195
- }
196
- function containsPatternUsage(content, pattern) {
197
- let cleanContent = ((s) => s.replace(/(['"`])(?:\\.|(?!\1)[\s\S])*?\1/g, '""'))(content).replace(/\/\*[\s\S]*?\*\//g, "").split(`
198
- `).map((line) => line.split("//")[0]).join(`
199
- `);
200
- return pattern.test(cleanContent);
201
- }
202
- function containsDirnameUsage(content) {
203
- return containsPatternUsage(content, /\b__dirname\b/);
204
- }
205
- function containsFilenameUsage(content) {
206
- return containsPatternUsage(content, /\b__filename\b/);
207
- }
208
- var bannerComment = "// This file has been automatically migrated to valid ESM format by Storybook.", hasRequireBanner = (content) => content.includes(bannerComment);
209
164
 
210
165
  // src/util.ts
211
166
  var STORYBOOK_DIR_PATTERN = ["**/.storybook", "**/.rnstorybook"], isSuccessResult = (result) => !("error" in result), isErrorResult = (result) => "error" in result, getVersionModifier = (versionSpecifier) => {
@@ -232,20 +187,23 @@ var validateUpgradeCompatibility = (currentVersion, beforeVersion, isCanary) =>
232
187
  });
233
188
  }, findStorybookProjects = async (cwd = process.cwd()) => {
234
189
  try {
235
- logger2.debug("Finding Storybook projects...");
190
+ logger.debug("Finding Storybook projects...");
236
191
  let storybookDirs = await globby(STORYBOOK_DIR_PATTERN, {
237
192
  cwd,
238
193
  dot: !0,
239
194
  gitignore: !0,
195
+ // Packages like @nx/storybook ship .storybook templates, and globby misses .gitignore patterns
196
+ // like `**/**/node_modules/`, so never rely on .gitignore to skip them.
197
+ ignore: ["**/node_modules/**"],
240
198
  absolute: !0,
241
199
  onlyDirectories: !0,
242
200
  followSymbolicLinks: !1
243
201
  });
244
- return logger2.debug(`Found ${storybookDirs.length} Storybook projects`), storybookDirs.length === 0 ? [await prompt.text({
202
+ return logger.debug(`Found ${storybookDirs.length} Storybook projects`), storybookDirs.length === 0 ? [await prompt.text({
245
203
  message: "No Storybook projects were found. Please enter the path to the .storybook directory for the project you want to upgrade."
246
204
  })] : storybookDirs;
247
205
  } catch (error) {
248
- throw logger2.error("Failed to find Storybook projects"), error;
206
+ throw logger.error("Failed to find Storybook projects"), error;
249
207
  }
250
208
  };
251
209
  var processProject = async ({
@@ -257,7 +215,7 @@ var processProject = async ({
257
215
  try {
258
216
  onScanStart();
259
217
  let name = configDir.replace(getProjectRoot(), "");
260
- logger2.debug("Getting Storybook data...");
218
+ logger.debug("Getting Storybook data...");
261
219
  let {
262
220
  configDir: resolvedConfigDir,
263
221
  mainConfig,
@@ -266,21 +224,20 @@ var processProject = async ({
266
224
  previewConfigPath,
267
225
  storiesPaths,
268
226
  versionSpecifier,
269
- versionInstalled,
270
- hasCsfFactoryPreview
227
+ versionInstalled
271
228
  } = await getStorybookData({ configDir });
272
- logger2.debug(`${name} - Validating before version... ${versionInstalled}`), validateVersion(versionInstalled);
229
+ logger.debug(`${name} - Validating before version... ${versionInstalled}`), validateVersion(versionInstalled);
273
230
  let isCanary = isCanaryVersion(currentCLIVersion) || isCanaryVersion(versionInstalled) || isPkgPrNewVersionSpecifier(versionSpecifier);
274
- logger2.debug(`${name} - Validating upgrade compatibility...`), validateUpgradeCompatibility(currentCLIVersion, versionInstalled, isCanary), logger2.debug(`${name} - Fetching NPM version information...`);
231
+ logger.debug(`${name} - Validating upgrade compatibility...`), validateUpgradeCompatibility(currentCLIVersion, versionInstalled, isCanary), logger.debug(`${name} - Fetching NPM version information...`);
275
232
  let [latestCLIVersionOnNPM, latestPrereleaseCLIVersionOnNPM] = await Promise.all([
276
233
  packageManager.latestVersion("storybook"),
277
234
  packageManager.latestVersion("storybook@next")
278
235
  ]);
279
- latestCLIVersionOnNPM == null && logger2.debug(
236
+ latestCLIVersionOnNPM == null && logger.debug(
280
237
  `${name} - Could not determine the latest Storybook version from the registry; skipping the outdated-version check.`
281
238
  );
282
239
  let isCLIOutdated = latestCLIVersionOnNPM != null && (0, import_semver.lt)(currentCLIVersion, latestCLIVersionOnNPM), isCLIExactLatest = currentCLIVersion === latestCLIVersionOnNPM, isCLIPrerelease = (0, import_semver.prerelease)(currentCLIVersion) !== null, isCLIExactPrerelease = currentCLIVersion === latestPrereleaseCLIVersionOnNPM, isUpgrade = (0, import_semver.lt)(versionInstalled, currentCLIVersion), autoblockerCheckResults = null;
283
- return typeof mainConfig != "boolean" && typeof mainConfigPath < "u" && !options.force && (logger2.debug(`${name} - Evaluating blockers...`), autoblockerCheckResults = await autoblock({
240
+ return typeof mainConfig != "boolean" && typeof mainConfigPath < "u" && !options.force && (logger.debug(`${name} - Evaluating blockers...`), autoblockerCheckResults = await autoblock({
284
241
  packageManager,
285
242
  configDir: resolvedConfigDir,
286
243
  mainConfig,
@@ -302,17 +259,16 @@ var processProject = async ({
302
259
  storybookVersionSpecifier: versionSpecifier,
303
260
  autoblockerCheckResults,
304
261
  previewConfigPath,
305
- storiesPaths,
306
- hasCsfFactoryPreview
262
+ storiesPaths
307
263
  };
308
264
  } catch (error) {
309
- return logger2.debug(String(error)), {
265
+ return logger.debug(String(error)), {
310
266
  configDir,
311
267
  error
312
268
  };
313
269
  }
314
270
  }, collectProjects = async (options, configDirs, onProjectScanStart) => {
315
- let { default: pLimit } = await import("./p-limit-ZIP5AIWC.js"), currentCLIVersion = versions.storybook, limit = pLimit(5), projectPromises = configDirs.map(
271
+ let { default: pLimit } = await import("./p-limit-N6WTORTF.js"), currentCLIVersion = versions.storybook, limit = pLimit(5), projectPromises = configDirs.map(
316
272
  (configDir) => limit(
317
273
  () => processProject({
318
274
  configDir,
@@ -362,7 +318,7 @@ var processProject = async ({
362
318
  });
363
319
  storybookSatelliteUpgrades = (await Promise.all(upgradePromises)).filter((result) => result !== null);
364
320
  } catch {
365
- logger2.warn("Failed to fetch satellite dependencies");
321
+ logger.warn("Failed to fetch satellite dependencies");
366
322
  }
367
323
  }
368
324
  return [...storybookCoreUpgrades, ...storybookSatelliteUpgrades];
@@ -374,7 +330,7 @@ var processProject = async ({
374
330
  generateUpgradeSpecs(packageJson.devDependencies, config),
375
331
  generateUpgradeSpecs(packageJson.peerDependencies, config)
376
332
  ]);
377
- logger2.debug(JSON.stringify({ upgradedDependencies }, null, 2)), logger2.debug(JSON.stringify({ upgradedDevDependencies }, null, 2)), logger2.debug(JSON.stringify({ upgradedPeerDependencies }, null, 2)), await packageManager.addDependencies(
333
+ logger.debug(JSON.stringify({ upgradedDependencies }, null, 2)), logger.debug(JSON.stringify({ upgradedDevDependencies }, null, 2)), logger.debug(JSON.stringify({ upgradedPeerDependencies }, null, 2)), await packageManager.addDependencies(
378
334
  {
379
335
  type: "dependencies",
380
336
  skipInstall: !0,
@@ -397,7 +353,7 @@ var processProject = async ({
397
353
  upgradedPeerDependencies
398
354
  );
399
355
  }
400
- }, formatProjectDirectories = (projectData, modifier) => projectData.length === 0 ? "" : projectData.map((project) => project.configDir).map((dir) => `${modifier} ${import_picocolors2.default.cyan(shortenPath(dir))}`).join(`
356
+ }, formatProjectDirectories = (projectData, modifier) => projectData.length === 0 ? "" : projectData.map((project) => project.configDir).map((dir) => `${modifier} ${import_picocolors.default.cyan(shortenPath(dir))}`).join(`
401
357
  `), shortenPath = (path) => {
402
358
  let gitRoot = getProjectRoot();
403
359
  return path.replace(gitRoot, "");
@@ -407,12 +363,12 @@ var processProject = async ({
407
363
  let projectsFoundMessage = [
408
364
  "Multiple Storybook projects found. Storybook can only upgrade all projects at once:"
409
365
  ];
410
- if (validProjects.length > 0 && projectsFoundMessage.push(formatProjectDirectories(validProjects, logger2.SYMBOLS.success)), errorProjects.length > 0 && (logTracker.enableLogWriting(), projectsFoundMessage.push(
366
+ if (validProjects.length > 0 && projectsFoundMessage.push(formatProjectDirectories(validProjects, logger.SYMBOLS.success)), errorProjects.length > 0 && (logTracker.enableLogWriting(), projectsFoundMessage.push(
411
367
  `There were some errors while collecting data for the following projects:
412
- ${formatProjectDirectories(errorProjects, logger2.SYMBOLS.error)}`,
368
+ ${formatProjectDirectories(errorProjects, logger.SYMBOLS.error)}`,
413
369
  "",
414
370
  "Full logs will be available in the Storybook debug logs at the end of the run."
415
- )), logger2.log(projectsFoundMessage.join(`
371
+ )), logger.log(projectsFoundMessage.join(`
416
372
  `)), !(yes || await prompt.confirm({
417
373
  message: "Continue with the upgrade?",
418
374
  initialValue: !0
@@ -443,7 +399,7 @@ ${formatProjectDirectories(errorProjects, logger2.SYMBOLS.error)}`,
443
399
  );
444
400
  task.stop(`${projects.length} ${projects.length > 1 ? "projects" : "project"} detected`);
445
401
  let validProjects = projects.filter(isSuccessResult), errorProjects = projects.filter(isErrorResult);
446
- if (logger2.debug(
402
+ if (logger.debug(
447
403
  `Found ${validProjects.length} valid projects and ${errorProjects.length} error projects`
448
404
  ), validProjects.length === 1)
449
405
  return { allProjects: validProjects, selectedProjects: validProjects };
@@ -465,18 +421,12 @@ Please fix the errors and run the upgrade command again.`
465
421
  );
466
422
  return selectedProjects ? { allProjects: validProjects, selectedProjects } : void 0;
467
423
  } catch (error) {
468
- throw error instanceof HandledError || logger2.error("Failed to get projects"), error;
424
+ throw error instanceof HandledError || logger.error("Failed to get projects"), error;
469
425
  }
470
426
  }, findFilesUp = (matchers, cwd) => {
471
427
  let matchingFiles = [];
472
428
  for (let directory of up(cwd, { last: getProjectRoot() }))
473
- matchingFiles.push(
474
- ...globbySync(matchers, {
475
- gitignore: !0,
476
- absolute: !0,
477
- cwd: directory
478
- })
479
- );
429
+ matchingFiles.push(...globbySync(matchers, { absolute: !0, cwd: directory }));
480
430
  return matchingFiles;
481
431
  };
482
432
 
@@ -553,13 +503,6 @@ export {
553
503
  require_picocolors,
554
504
  getFrameworkPackageName,
555
505
  getRendererName,
556
- updateMainConfig,
557
- containsESMUsage,
558
- containsRequireUsage,
559
- containsDirnameUsage,
560
- containsFilenameUsage,
561
- bannerComment,
562
- hasRequireBanner,
563
506
  getStorybookData,
564
507
  up,
565
508
  findOutdatedPackage,
@@ -0,0 +1,11 @@
1
+ import CJS_COMPAT_NODE_URL_ft71o55xt7f from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ft71o55xt7f from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ft71o55xt7f from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_ft71o55xt7f.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ft71o55xt7f.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ft71o55xt7f.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_ejw65m8bp8s from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ejw65m8bp8s from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ejw65m8bp8s from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ft71o55xt7f from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ft71o55xt7f from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ft71o55xt7f from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ejw65m8bp8s.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ejw65m8bp8s.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ejw65m8bp8s.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ft71o55xt7f.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ft71o55xt7f.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ft71o55xt7f.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -21,8 +21,8 @@ import {
21
21
  isGitIgnoredSync,
22
22
  isIgnoredByIgnoreFiles,
23
23
  isIgnoredByIgnoreFilesSync
24
- } from "./chunk-DM3PGJRR.js";
25
- import "./chunk-PCYXDPOV.js";
24
+ } from "./chunk-HOYDQ5IU.js";
25
+ import "./chunk-6WU77S4B.js";
26
26
  export {
27
27
  convertPathToPattern,
28
28
  generateGlobTasks,
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_ejw65m8bp8s from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ejw65m8bp8s from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ejw65m8bp8s from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ft71o55xt7f from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ft71o55xt7f from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ft71o55xt7f from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ejw65m8bp8s.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ejw65m8bp8s.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ejw65m8bp8s.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ft71o55xt7f.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ft71o55xt7f.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ft71o55xt7f.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import "./chunk-PCYXDPOV.js";
12
+ import "./chunk-6WU77S4B.js";
13
13
 
14
14
  // ../../../node_modules/yocto-queue/index.js
15
15
  var Node = class {