Skip to content

Conversation

@romainmenke
Copy link
Member

@romainmenke romainmenke commented Jan 29, 2022

Note on the size of this change :

I did not dare adding more logic to preset-env without having more granular unit tests.
This required splitting everything up into separate functions and files.

My aim was to make the entire code base more clear and easier to update with this in mind.

Some newer JS features like Symbol and Map are used to make everything a bit more predictable.

  • Symbol makes it safer to combine data from multiple source (plugin options, cssdb) while still knowing which keys were set by postcss-preset-env.
  • Map prevents unexpected behaviour when users set options that overlap with build-ins like toString.

This does not yet have full test coverage with unit tests alone but the combo of the new unit tests and postcss-tape should still be a step in the right direction.


After this initial refactor it became trivial to add the minimumVendorImplementations option.

There is no overloading of this option or hidden logic around it.

minimumVendorImplementations is always converted to a number between 0 and 3.
0 is equivalent to not setting the option.


There is still one bit of undefined logic that I haven't tracked down and added tests for.

When using insertAfter or insertBefore it is unclear if those plugins become dynamic based on the browser lists of the feature they are attached to.

I need to check this on main first.

Update :

  • added tests in main and merged them into this branch
  • behaviour is to always run the inserted plugins, these are not dynamic

Notable fix :

see :

.test-nesting-rules + p, #test-is-pseudo + p {
order: 8;
}

We added getOptionsForBrowsersByFeature some time ago and this had a bug.

if (features[feature.id] === true) {
	// if the plugin is enabled
	options = sharedOpts ? Object.assign({}, options, sharedOpts) : undefined;
}

When manually enabling a feature like postcss-nesting but without adding any sharedOpts the flags set by getOptionsForBrowsersByFeature would be erased. As options was set to undefined in this case.

This has been fixed.

…c344' into postcss-preset-env-filter-by-implementation-status--amiable-hippopotamus-d560d56350
@romainmenke romainmenke added this to the 7.3.0 milestone Jan 29, 2022
@romainmenke romainmenke changed the title postcss-preset-env: filter by implementation status postcss-preset-env: filter features by implementation status Jan 29, 2022
Copy link
Member

@Antonio-Laguna Antonio-Laguna left a comment

Choose a reason for hiding this comment

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

Wow! This is really great!

Thanks for cleaning this up and making this much more manageable and sustainable in the future.

Only question I have is if you want to clarify more around the vendorImplementations as in explaining what stability usually means?

Copy link
Member

@Antonio-Laguna Antonio-Laguna left a comment

Choose a reason for hiding this comment

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

❤️

@romainmenke romainmenke merged commit b086276 into 7.3--philosophical-mayfly-9d15adc344 Jan 30, 2022
@romainmenke romainmenke deleted the postcss-preset-env-filter-by-implementation-status--amiable-hippopotamus-d560d56350 branch January 30, 2022 16:26
romainmenke added a commit that referenced this pull request Jan 31, 2022
* 7.3

* add `postcss-is-pseudo-class` to `postcss-preset-env` and `cli` (#159)

* add postcss-is-pseudo-class to preset-env and cli

* add test

* cli : emit warnings (#164)

* cli : emit warnings

* update change log

* Adding debug option (#163)

* Updating dependencies

* Simplifying Object usaging

* Clearer stage

* Adding debug

* Adding documentation

* Useful on issues too

* eslint enforce radix in parseInt

* Naive approach to using result.warn

* Clamping

* Switching for better clarity

* Update plugin-packs/postcss-preset-env/src/index.js

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/src/index.js

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* 7.3

* add `postcss-is-pseudo-class` to `postcss-preset-env` and `cli` (#159)

* add postcss-is-pseudo-class to preset-env and cli

* add test

* Updating CHANGELOG

* Fixing link

* Fixing changelog

Co-authored-by: romainmenke <romainmenke@gmail.com>
Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Disable javascript features (#167)

* Updating dependencies

* Simplifying Object usaging

* Clearer stage

* Adding debug

* Adding documentation

* Useful on issues too

* eslint enforce radix in parseInt

* Naive approach to using result.warn

* Clamping

* Switching for better clarity

* Update plugin-packs/postcss-preset-env/src/index.js

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/src/index.js

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* 7.3

* add `postcss-is-pseudo-class` to `postcss-preset-env` and `cli` (#159)

* add postcss-is-pseudo-class to preset-env and cli

* add test

* Updating CHANGELOG

* Fixing link

* Fixing changelog

* Moving to separate file

* Adding option that disables client side polyfills

* Adding useful logging to debug mode

* Consistency

* Adding meaningful tests

* Updating README

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Adding missing library

Co-authored-by: romainmenke <romainmenke@gmail.com>
Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* apply new test suite to more plugins and sourcemap fixes

* Revert "apply new test suite to more plugins and sourcemap fixes"

This reverts commit b94037e.

* apply new test suite to more plugins and sourcemap fixes (#182)

* apply new test suite to more plugins and sourcemap fixes

* cleanup dev dependencies

* Removing Can I Use Lite (#185)

* Getting things up to date

* Creating a query for browsers from given browser support

* Updating tests

* Moving to cssdb feature

* Using the new logic with logs too

* Allowing `.` for float versions

* Updating package

* flip disableClientSidePolyfills (#189)

* :any-link fixes (#183)

* :any-link fixes

* update tests

* update tests

* make it work without :is

* postcss-hwb-function in preset-env / cli (#190)

* postcss-hwb-function in preset-env / cli

* add a test for hwb in preset-env

* merge

* add a shortcut to rewrite expect files and log warnings (#193)

* add a shortcut to rewrite expect files

* emit warnings if they don't match

* Adding Opacity Percent Feature (#196)

* Updating badges (#197)

* Replacing all chat badges

* Adding package phobia

#165

* Adding PostCSS clamp (#198)

* Adding postcss-clamp

* Updating CHANGELOG

* New test for preserve: true with every feature enabled

* postcss-is-pseudo-class : better warnings and skip (#199)

* wip

* wip

* wip

* wip

* wip

* finish

* Getting ready-er

* Integrate font & display plugins (#205)

* Adding two new plugins

* Adding missing plugins to the CLI

* postcss-is-pseudo-class : browser tests and transform in 2 stages (#212)

* postcss-is-pseudo-class : browser tests

* postcss-is-pseudo-class: 2 stage transform

* cleanup

* postcss-preset-env: filter features by implementation status (#211)

* postcss-preset-env: filter by implementation status

* tweak

* fix insertBefore/insertAfter

* fix

* few more tests and simplify postcss-tape expect/result option

* fix

* update docs

* postcss-preset-env: pin some features to stage: 1 (#213)

* Adding more to the README (#207)

* Adding more to the README

#202

* Updating docs

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Update plugin-packs/postcss-preset-env/README.md

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>

* Updating CSSDB to latest version

* Tests fixing

* Test after building

* Upgrading all deps

* Updating packages

Co-authored-by: Antonio Laguna <sombragriselros@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants