WordPress/gutenberg

Scripts: Try using cosmiconf for locating tool configs

Open

#30,842 opened on Apr 14, 2021

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (3,893 forks)batch import
Good First IssueNeeds Dev[Status] In Progress[Tool] WP Scripts[Type] Enhancement

Repository metrics

Stars
 (9,607 stars)
PR merge metrics
 (Avg merge 12d 18h) (509 merged PRs in 30d)

Description

A number of our scripts in the @wordpress/scripts contain logic to find the relevant config and/or ignore file (or package.json entry) for a given tool by replicating that tool's logic in doing so. E.g. lint-js tries to locate the relevant config for eslint here: https://github.com/WordPress/gutenberg/blob/dd4cc1b65433fc1f55ae7b674726e85af5f13ff7/packages/scripts/scripts/lint-js.js#L23-L33

Similar strategies can be found across our other scripts. This has lead to creation of helper methods such as hasProjectFile or hasPackageProp.

Rather than replicating and hard-wiring those tools' strategies, we might consider using a tool like cosmiconf, which seeks to establish somewhat of a standard for config file retrieval across tools. (Here's a broader discussion in the nodejs/tooling repo that had a similar goal but didn't really go anywhere.) AFAIK, some of the tools we use actually use cosmiconf themselves (e.g. prettier), while it has been proposed (but not yet adopted) by others (e.g. eslint).

We could consider multiple strategies:

  • Audit our tools, and only switch those to cosmiconf that use it themselves.
  • Use it for all our tools, as we might consider it "good enough".

Inspired by https://github.com/WordPress/gutenberg/pull/30240#issuecomment-817515651

Contributor guide