Skip to content

Improve config documentation and remove 22 dependencies from cssnano#1168

Merged
ludofischer merged 2 commits intomasterfrom
replace-config-loading
Jul 19, 2021
Merged

Improve config documentation and remove 22 dependencies from cssnano#1168
ludofischer merged 2 commits intomasterfrom
replace-config-loading

Conversation

@ludofischer
Copy link
Copy Markdown
Collaborator

This PR does two things.
First, I've reworked the documentation to mention the config file priorities and added some tests to verify the basic config loading.
In a separate commit, I've replaced cosmiconfig with lilconfig. This gets rid of 22 dependencies and about 1MB when doing npm i cssnano. This makes cssnano use the same library as the lastest postcss-load-config (postcss/postcss-load-config@d147864).
You can't see the removed dependencies in the repository yarn.lock because lerna depends on cosmiconfig.

"dependencies": {
"cosmiconfig": "^7.0.0",
"lilconfig": "^2.0.3",
"yaml": "^1.10.2",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was uncertain whether to keep YAML config parsing since it was never documented explicitly, but removing would be a breaking change in theory.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good call to keep it for now, even if the chance of it being used is remote 👍

Question:

Since the tests you added were paired with a .cssnanorc.json and you mentioned keeping YAML support, I decided to attempt running the test suite with a .cssnanorc.yaml and a few other variations (replacing .cssnanorc.json in the config_loading dir) for the sake of diligence. And it doesn't appear to be picked up.

It's entirely possible I'm having some form of "brainfart" and doing something wrong here - but shouldn't that work?

(Out of curiosity I had a look at the searchItems found by lilconfig in lilconfigSync.search() and it only appears to look for package.json, cssnanorc.json, cssnano.config.js, and cssnanorc.js, .cssnanorc.cjs, and cssnano.config.cjs)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My inner conviction is nobody is really using the YAML format, so I did not bother checking whether it works, I have just copied the instructions on the lilconfig repo. Looking at the lilconfig code, it seems it does not even load .rc (with no extension) by default.

Comment thread site/docs/config-file.mdx
}
```

## Alternatives
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section about the PostCSS config file has been moved to the top as that is what most people will use and the PostCSS config overrides the config in the cssnano files.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 18, 2021

Codecov Report

Merging #1168 (8e39090) into master (9886775) will decrease coverage by 0.02%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1168      +/-   ##
==========================================
- Coverage   96.53%   96.51%   -0.03%     
==========================================
  Files         114      114              
  Lines        3582     3584       +2     
  Branches     1052     1052              
==========================================
+ Hits         3458     3459       +1     
- Misses        115      117       +2     
+ Partials        9        8       -1     
Impacted Files Coverage Δ
packages/cssnano/src/index.js 90.32% <33.33%> (-1.35%) ⬇️

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 9886775...8e39090. Read the comment docs.

Copy link
Copy Markdown
Collaborator

@sigveio sigveio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All-in-all good job - this documentation seems a lot clearer now 👍

And nice one with the deps!!

Comment thread site/docs/config-file.mdx Outdated
Comment thread site/docs/config-file.mdx Outdated
Comment thread site/docs/config-file.mdx
Comment thread site/docs/config-file.mdx Outdated
Comment thread site/docs/config-file.mdx Outdated
Closes #904
Add tests for configuration loading and correct the documentation.

* correct configuration file names in the docs
* specify that the PostCss config overrides the cssnano-specific config
* remove mention of cosmiconfig to avoid being tied to a single implementation
@ludofischer ludofischer force-pushed the replace-config-loading branch from 81dc41f to a1db6ff Compare July 18, 2021 13:20
loaders: {
'.yaml': (filepath, content) => yaml.parse(content),
'.yml': (filepath, content) => yaml.parse(content),
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you may also need to add something like searchPlaces: ['.cssnanorc.yaml', '.cssnanorc.yml'] to the options in order for lilconfig to actually look for yaml files?

It seems like lilconfig uses this as basis for merging in the loaders.

Ref. #1168 (comment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a bit of a bug or design weakness on their part

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code with explicit search places. I did try renaming the file to .cssnanorc.yml and it worked.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed! And perhaps not such a bad thing for it to be explicit anyway 👍

Remove about 22 dependencies according to npm i --production (from 110 to 88 deps)

* reduce node_modules after `yarn install cssnano` in empty project from 14MB to 13MB
* add YAML dep to preserve YAML configuration compatibility
  YAML configuration was only implicitly documented by referring to cosmiconfig,
  but removing it would be a breaking change
@ludofischer ludofischer force-pushed the replace-config-loading branch from a1db6ff to 8e39090 Compare July 18, 2021 18:10
Copy link
Copy Markdown
Collaborator

@sigveio sigveio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@alexander-akait
Copy link
Copy Markdown
Member

/cc @sigveio I can invite your in cssnano repo so you can help us more better 😄 @ludofischer What do you think?

@ludofischer ludofischer merged commit 506a823 into master Jul 19, 2021
@ludofischer ludofischer deleted the replace-config-loading branch July 19, 2021 15:35
@ludofischer
Copy link
Copy Markdown
Collaborator Author

/cc @sigveio I can invite your in cssnano repo so you can help us more better smile @ludofischer What do you think?

Sure, @sigveio can certainly help.

@sigveio
Copy link
Copy Markdown
Collaborator

sigveio commented Jul 20, 2021

Thanks @alexander-akait and @ludofischer - I appreciate the trust, and looking forward to help where I can 😄

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants