-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20802 from storybookjs/feat/warn-regarding-defaul…
…t-exports-in-main CLI: add warning when main config does not use default exports
- Loading branch information
Showing
8 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 23 additions & 7 deletions
30
code/lib/core-common/src/utils/validate-configuration-files.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
import { dedent } from 'ts-dedent'; | ||
import glob from 'glob'; | ||
import { promise as glob } from 'glob-promise'; | ||
import path from 'path'; | ||
import { readConfig } from '@storybook/csf-tools'; | ||
import { once } from '@storybook/node-logger'; | ||
|
||
import { boost } from './interpret-files'; | ||
|
||
export function validateConfigurationFiles(configDir: string) { | ||
export async function validateConfigurationFiles(configDir: string) { | ||
const extensionsPattern = `{${Array.from(boost).join(',')}}`; | ||
const exists = (file: string) => | ||
!!glob.sync(path.resolve(configDir, `${file}${extensionsPattern}`)).length; | ||
const mainConfigMatches = await glob(path.resolve(configDir, `main${extensionsPattern}`)); | ||
|
||
const main = exists('main'); | ||
const [mainConfigPath] = mainConfigMatches; | ||
|
||
if (!main) { | ||
if (mainConfigMatches.length > 1) { | ||
once.warn(dedent` | ||
Multiple main files found in your configDir (${path.resolve(configDir)}). | ||
Storybook will use the first one found and ignore the others. Please remove the extra files. | ||
`); | ||
} | ||
|
||
if (!mainConfigPath) { | ||
throw new Error(dedent` | ||
No configuration files have been found in your configDir (${path.resolve(configDir)}). | ||
Storybook needs either a "main" or "config" file. | ||
Storybook needs "main.js" file, please add it. | ||
`); | ||
} else { | ||
const main = await readConfig(mainConfigPath); | ||
if (!main.hasDefaultExport) { | ||
once.warn(dedent` | ||
Your main.js is not using a default export, which is the recommended format. Please update it. | ||
For more info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#esm-format-in-mainjs | ||
`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters