Skip to content

Allow excluding file patterns when generating component definitions  #486

Closed
@pbugnion

Description

Thanks a lot for making Dash -- we have found it very useful for building dashboards.

We ran into an issue migrating to the new dash-generate-components utility.

In dash-bootstrap-components, we keep the components in src/components. Besides components files, this also includes a few unit test files called, e.g. src/components/__tests__/DropdownMenu.test.js. When we run dash-generate-components ./src/components <output>, these test files also get picked up. This leads to a traceback in the build logs:

Error with path src/components/__tests__/DropdownMenu.test.jsError: No suitable component definition found.
Error: No suitable component definition found.
at parse (/project/pascal/dash-bootstrap-components/node_modules/react-docgen/dist/parse.js:84:9)
at Object.defaultParse [as parse] (/project/pascal/dash-bootstrap-components/node_modules/react-docgen/dist/main.js:66:30)
at parseFile (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:64:51)
at dirs.forEach.filename (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:84:17)
at Array.forEach (<anonymous>)
at collectMetadataRecursively (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:79:14)
at dirs.forEach.filename (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:82:17)
at Array.forEach (<anonymous>)
at collectMetadataRecursively (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:79:14)
at componentPaths.forEach.componentPath (/opt/anaconda/envs/Python3/lib/python3.6/site-packages/dash/extract-meta.js:15:5)

While the error is, of course, legitimate, it would be nice to be able to suppress these tracebacks. I can see three routes:

  • do nothing -- after all, this doesn't stop us from building metadata.json, it just makes it slightly more confusing.
  • in dash/extract-meta.js, we could explicitly blacklist __tests__ directories in the same way that files that don't end in jsx? are black-listed. AFAICT, the __tests__ directory structure is the default with jest. react-docgen ignores node_modules, __tests__ and __mocks__ by default, so there is definitely a precedent.
  • add a --ignore argument to dash-generate-components that allows passing file globs to be excluded.

Very happy to submit a PR if you decide on what the best course of action is.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Allow excluding file patterns when generating component definitions · Issue #486 · plotly/dash