-
-
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.
Warn users to use default export in main.js
- involves changes in csf-tools to define a flag that tells us there is (or not) a default export - involves changes in affected packages now that loadMainConfig is async
- Loading branch information
Showing
8 changed files
with
29 additions
and
11 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
21 changes: 15 additions & 6 deletions
21
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,29 @@ | ||
import { dedent } from 'ts-dedent'; | ||
import glob from 'glob'; | ||
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 = glob.sync(path.resolve(configDir, `main${extensionsPattern}`)); | ||
|
||
const main = exists('main'); | ||
const [mainConfigPath] = mainConfigMatches; | ||
|
||
if (!main) { | ||
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