Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifiying a path to Histoire config file (or parent directory) #167

Closed
6 tasks done
clowNay opened this issue Jul 7, 2022 · 3 comments · Fixed by #612
Closed
6 tasks done

Allow specifiying a path to Histoire config file (or parent directory) #167

clowNay opened this issue Jul 7, 2022 · 3 comments · Fixed by #612
Labels
enhancement New feature or request need spec Need Specs, UX or UI design...

Comments

@clowNay
Copy link

clowNay commented Jul 7, 2022

Describe the bug

I run in to several issues with the following directory structure.

<root>
    <playground>
        app.vue
        nuxt.config.ts
        histoire.config.ts
    </playground>
    package.json
    ...etc
</root>
Error while collecting story /Users/andreasquist/Sites/ui/playground/components/UI-Alert.story.vue:
Error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
    at formatError (/Users/andreasquist/Sites/ui/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39055:46)
    at TransformContext.error (/Users/andreasquist/Sites/ui/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39051:19)
    at TransformContext.transform (/Users/andreasquist/Sites/ui/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:58269:22)
    at async Object.transform (/Users/andreasquist/Sites/ui/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:39292:30)
    at async doTransform (/Users/andreasquist/Sites/ui/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:50012:29)

After that I moved the histoire.config.ts to the <root> and then it worked. Why does it need to be in the root folder?

Reproduction

Move histoire.config.file to folder
https://stackblitz.com/edit/nuxt3-histoire

System Info

System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 22.14 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
    Watchman: 2022.03.21.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 103.0.5060.53
    Firefox: 89.0.2
    Safari: 15.4

Used Package Manager

npm

Validations

@clowNay clowNay added the to triage This issue needs to be triaged label Jul 7, 2022
@NozomuIkuta
Copy link
Contributor

@clowNay

Currently, Histoire looks for its config file(s) only at the current working directory (i.e. usually project root).

For example, when you run histoire dev command as in your reproduction link:

program.command('dev')
.describe('open the stories in your browser for development')
.option('-p, --port <port>', 'Listening port of the server')
.action(async (options) => {
const { devCommand } = await import('./commands/dev.js')
return devCommand(options)
})

const configFile = await resolveConfigFile()

export const configFileNames = [
'histoire.config.ts',
'histoire.config.js',
'.histoire.ts',
'.histoire.js',
]
export function resolveConfigFile (cwd: string = process.cwd()): string {
return findUp(cwd, configFileNames)
}

If you want to change this behavior, it would be a feature request.

@clowNay
Copy link
Author

clowNay commented Jul 8, 2022

@NozomuIkuta I think that behaviour should be changed or at least provide a way of defining where config file is located with an argument.

@NozomuIkuta
Copy link
Contributor

For you and authors to design the feature in more detail, here are information about how Histoire related tools handle config file.

Vite

Histoire is Vite-powoered (or its wrapper), so aligning API with it would be reasonable and intuitive.

Vite CLI provides -c, --config <file> option, which is passed to configFile JavaScript API.

Refs

Storybook

When it comes to "story", it's worth mentioning Storybook.
Storybook CLI (i.e. start-storybook and build-storybook) provides -c, --config-dir [dir-name] option, where [dir-name] represents a path to directory where Storybook configs are located.

As far as I know, Storybook doesn't provide JavaScript API to run it.

Refs

Ladle

Ladle is an alternative to Storybook and is referred to in Histoire README.

Ladle CLI also provides --config [string] option, where [string] represents a path to directory where Ladle configs are located. --config option is passed to serve function as config option internally.

While serve function is exported as a JavaSript API, there seems to be no explanation about it in documentation but in the source code.

Refs

Summary

  • All the tools above have it in common how they give a name to such option to specify configuration file.
  • If a tool require a dedicated directory to store related files, such option expects path to a directory, otherwise to a file
  • If a tool provides JavaScript API, CLI option(s) are supposed to be used to override options passed to JavaScript API at runtime

IMO, -c, --config option like Vite looks nice to me, and since Histoire doesn't require a dedicated directory such as .ladle at the moment, the option should accept a path to a configuration file.

@Akryum Akryum added enhancement New feature or request need spec Need Specs, UX or UI design... and removed to triage This issue needs to be triaged labels Jul 14, 2022
@Akryum Akryum changed the title Issues when histoire.config.ts is not located in project root Allow specifiying a path to Histoire config file (or parent directory) Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need spec Need Specs, UX or UI design...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants