Repository: storybookjs/storybook
File: code/lib/cli-storybook/src/automigrate/helpers/mainConfigFile.ts (TypeScript)

Code before:

  const workingDir = isAbsolute(configDir)
    ? dirname(configDir)
    : dirname(join(process.cwd(), configDir));

  logger.debug('Getting stories paths...');
  const storiesPaths = await getStoriesPathsFromConfig({
    stories: mainConfig.stories,
    configDir,
    workingDir,
  });

  logger.debug('Getting package manager...');
  const packageManager = JsPackageManagerFactory.getPackageManager({
    force: packageManagerName,
    configDir,
    storiesPaths,
  });

  logger.debug('Getting Storybook version...');
  const versionInstalled = (await packageManager.getModulePackageJSON('storybook'))?.version;

  return {
    configDir,
    mainConfig,
    /** The version specifier of Storybook from the user'spackage.json */
    versionSpecifier,
    /** The version of Storybook installed in the user's project */
    versionInstalled,
    mainConfigPath,
    previewConfigPath,
    packageManager,
    storiesPaths,
  };
};
export type GetStorybookData = typeof getStorybookData;

/**
 * A helper function to safely read and write the main config file. At the end of the callback,
 * main.js will be overwritten. If it fails, it will handle the error and log a message to the user
 * explaining what to do.
 *
 * It receives a mainConfigPath and a callback which will have access to utilities to manipulate
 * main.js.
 *
 * @example
 *
 * ```ts
 * await safeWriteMain({ mainConfigPath, dryRun }, async ({ main }) => {
 *   // manipulate main.js here
 * });

Review comment (suggestion):
```suggestion
    /** The version specifier of Storybook from the user's package.json */
```

Code after:

  const workingDir = isAbsolute(configDir)
    ? dirname(configDir)
    : dirname(join(process.cwd(), configDir));

  logger.debug('Getting stories paths...');
  const storiesPaths = await getStoriesPathsFromConfig({
    stories: mainConfig.stories,
    configDir,
    workingDir,
  });

  logger.debug('Getting package manager...');
  const packageManager = JsPackageManagerFactory.getPackageManager({
    force: packageManagerName,
    configDir,
    storiesPaths,
  });

  logger.debug('Getting Storybook version...');
  const versionInstalled = (await packageManager.getModulePackageJSON('storybook'))?.version;

  return {
    configDir,
    mainConfig,
    /** The version specifier of Storybook from the user's package.json */
    versionSpecifier,
    /** The version of Storybook installed in the user's project */
    versionInstalled,
    mainConfigPath,
    previewConfigPath,
    packageManager,
    storiesPaths,
  };
};
export type GetStorybookData = typeof getStorybookData;

/**
 * A helper function to safely read and write the main config file. At the end of the callback,
 * main.js will be overwritten. If it fails, it will handle the error and log a message to the user
 * explaining what to do.
 *
 * It receives a mainConfigPath and a callback which will have access to utilities to manipulate
 * main.js.
 *
 * @example
 *
 * ```ts
 * await safeWriteMain({ mainConfigPath, dryRun }, async ({ main }) => {
 *   // manipulate main.js here
 * });