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

Update docs on supported file extensions #917

Merged
merged 5 commits into from Oct 17, 2020

Conversation

ksmithut
Copy link
Contributor

This adds support for common js files using the ES Module interop spec.

This is for projects who have "type": "module" in their package.json, normal .js files fail to load saying that you need to use import. json and yaml work just fine, but in the cases like with typescript where you need to run tsc without passing in file parameters, the only way to do that is with the .js files.

Using the .cjs extension forces it to load as a common js file and works correctly even in es-module enabled projects.

I'm also happy to update the documentation, but the documentation didn't refer to the other possible extensions mentioned in this file, so I'll wait until I hear back.

@iiroj
Copy link
Member

iiroj commented Oct 16, 2020

Thanks for the PR! LGTM, but for some reason Yarn is having troubles when running the tests (not related to this).

Does our readme link to cosmiconfig's, where the extensions are listed? I think having the filenames listed in our readme could only help!

@codecov
Copy link

codecov bot commented Oct 16, 2020

Codecov Report

Merging #917 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #917   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          608       608           
  Branches       143       143           
=========================================
  Hits           608       608           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36e7e58...913db02. Read the comment docs.

@ksmithut
Copy link
Contributor Author

It does link to cosmiconfig's docs, but because there is a static list of searchPlaces in your code, it doesn't include everything that cosmiconfig supports unless you opt into it. Another option would be to remove the searchPlaces option and just use the default: https://github.com/davidtheclark/cosmiconfig#searchplaces which looks like this at the time of writing:

[
  'package.json',
  `.${moduleName}rc`,
  `.${moduleName}rc.json`,
  `.${moduleName}rc.yaml`,
  `.${moduleName}rc.yml`,
  `.${moduleName}rc.js`,
  `.${moduleName}rc.cjs`,
  `${moduleName}.config.js`,
  `${moduleName}.config.cjs`,
]

But then you don't have as much control. I imagine that if you gave a module name of lint-staged it would use .lint-stagedrc instead of what you have now without the dashes. I don't think new file formats will come up too often, so I think it's fine as it is.

Maybe the wording should be changed where it says:

See cosmiconfig for more details on what formats are supported.

to something more like:

We use cosmiconfig. If we're missing a file format they support, let us know.

Since it is configured to be with a list of searchPlaces, you won't automatically get all of the file extensions that cosmiconfig supports.

@iiroj
Copy link
Member

iiroj commented Oct 16, 2020

It looks like there is a prior MR doing the same thing: #909

@iiroj
Copy link
Member

iiroj commented Oct 16, 2020

I merged the other PR, but if you want still want to update the README, that would be nice. 👍

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@ksmithut ksmithut changed the title allow .cjs files for ESModule based packages Update docs on supported file extensions Oct 16, 2020
@iiroj iiroj self-requested a review October 17, 2020 06:20
@iiroj iiroj merged commit 78782f9 into lint-staged:master Oct 17, 2020
@iiroj
Copy link
Member

iiroj commented Oct 17, 2020

Thanks a lot for the PR, I appreciate it!

@github-actions
Copy link
Contributor

🎉 This PR is included in version 10.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ksmithut ksmithut deleted the support-cjs branch October 17, 2020 23:58
@ksmithut
Copy link
Contributor Author

You bet, thank you for the awesome tool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants