ladle icon indicating copy to clipboard operation
ladle copied to clipboard

config.stories does not accept an array of strings as it should

Open colinthesealion opened this issue 3 years ago • 3 comments

Describe the bug

globby can accept a string or an array of strings as patterns to search for, but the ladle build script assumes that config.stories is a single string and specifying an array of strings leads to a fatal error: TypeError: Patterns must be a string or an array of strings

This is due to the build script wrapping config.stories in an array, and thus if the user configures an array of strings we end up with an array of a single array of strings, rather than an array of strings.

See line 39 of build.js.

Reproduction

https://stackblitz.com/edit/ladle-gwkvsl?file=package.json

DEBUG=ladle* npm run dev
DEBUG=ladle* npm run build

Environment

  • OS: macOS Monterey 12.4
  • Version: 2.0.2

colinthesealion avatar Jul 29 '22 18:07 colinthesealion

What's your naming scheme? Even a single glob is pretty flexible.

tajo avatar Jul 29 '22 19:07 tajo

In a mono-repo where we'd like to aggregate stories across the project into a single page. Desired config is: stories: ['../src/src/**/*.stories.tsx', './stories/*.stories.tsx', '../../icons/src/*.stories.tsx']

I guess that could make be expressed in a single glob: ../**/*.stories.tsx, but that might capture more than intended.

It seems like a simple fix to enable multiple globs, tho, which would definitely allow this config variable to be more expressive: const entryData = await getEntryData(await globby(Array.isArray(config.stories) ? config.stories : [config.stories]));

I was planning to submit a PR for this later today.

colinthesealion avatar Jul 29 '22 20:07 colinthesealion

I was planning to submit a PR for this later today

Please do.

tajo avatar Jul 29 '22 22:07 tajo