17 Commits

Author SHA1 Message Date
Robin Malfait
72bc31867b
Replace __OXIDE__ at build time to prevent @tailwindcss/oxide leaks in the stable engine (#10988)
* replace `env.OXIDE` with global `__OXIDE__`

This will allow us to replace the `__OXIDE__` at build time, and fully
remove the branches from the final code so that there is not even any
reference to `@tailwindcss/oxide` on the stable engine.

* update changelog

* use `env.ENGINE` in integration tests

* drop oxide branching for the PostCSS plugin for now

This is currently a redirect to the same file, so doesn't hurt.

* Enable better dead-code elimination

* Update CLI tests

Fix indentation

* Fix indentation

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2023-04-18 12:19:20 +02:00
Robin Malfait
a785c93b54
Try resolving config.default before config to ensure the config file is resolved correctly (#10898)
* try to use `config.default` before using `config`

* update changelog

* add quick `SHOW_OUTPUT` toggle for integration tests

Setting this to `true` shows the output of the executed commands.

* add integration tests for `tailwind.config.ts` and `tailwind.config.js` with ESM syntax
2023-03-29 16:52:22 +02:00
Robin Malfait
c8bf2d49b6
Disable color opacity plugins by default in the oxide engine (#10618)
* disable color opacity plugins by default for the `oxide` engine

* update tests to reflect this change in the `oxide` engine

* update changelog

* reflect changes in integration tests
2023-02-17 20:21:22 +01:00
Robin Malfait
8e60a3c7e8
Use Lightning CSS in the PostCSS Plugin (#10399)
* bump lightningcss

* use `lightningcss` in the main PostCss Plugin

* use lightningcss in our custom matchers

Now that we are using `lightningcss` and nesting in the new `oxide`
engine, the generated output _will_ be different in the majority of test
cases.

Using a combination of `prettier` and `lightningcss` will make the
output consistent.

The moment we are fully using the `oxide` engine, we can drop
`lightningcss` or `prettier` again to improve the performance of the
tests.

* update tests to apply `lightningcss` related changes

* update changelog

* add `lightningcss` and `browserslist` as dev dependencies to stable package.json

* only use `lightningcss` in tests (without prettier)

We will only fallback to prettier if lightningcss fails somehow.

* apply side effect chagnes due to only using lightningcss for tests

* make CI happy (integration tests)

Apply changes to integration tests now that we are using lightningcss

* transform `lightningcss` for Node 12 when running tests

* run prettier on failing tests for `toMatchFormattedCss`

This will result in better diffs because diffs are typically per block
and/or per line. But lightningcss will simplify certain selectors and
the diff won't be as clear.

We will only apply the prettier formatting for failing tests in the diff
view so that diffs are cleaner and we don't pay for the additional
prettier calls when tests pass.
2023-01-23 20:44:31 +01:00
Will Cosgrove
1f5d117cf9
Fix shadowed variable when using raw content (#9773)
* Fix shadowed variable when using raw content

* Add test

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-11-08 17:02:10 -05:00
Robin Malfait
40f6b4ff64
Fix missing PostCSS dependencies in the CLI (#9617)
* Record and watch PostCSS dependencies in the CLI

* ensure `changedContent` gets cleared

Otherwise this list gets bigger and bigger, not only that there is a
subtle bug. The moment you save a `.css` file we want to create a new
context and start from scratch. However, since the list was never
cleared, it meant that every subsequent save to *any* file (not only
config / css files) creates a new context...

By clearing the least we should work around this problem.

* add test that verifies an odd bug

The story goes like this:

1. add `underline` to html file
  -> css contains `underline` rule
2. add `font-bold` to html file
  -> css contains `underline` and `font-bold`
3. remove `underline` from html file
  -> css still contains `underline` and `font-bold` for performance reasons
4. Save a css file (! RED FLAG)
  -> css contains `font-bold` because we started from scratch
5. add `underline` to html file
  -> css contains `underline` and `font-bold`
6. remove `underline` from html file
  -> css only contains `font-bold`... (UH OH)

This is because the moment we did step 4, every single save in any file created a new context. Every. Single. Time.

* use a property that doesn't require `autoprefixer`

* update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-10-20 18:01:39 +02:00
Jordan Pittman
5ea752e85c
Add @config support (#9405)
* Refactor CLI

* Add `@config` support

* Update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-09-23 13:48:17 -04:00
Jordan Pittman
30538b363f
Update integration tests (#8386)
* Add content glob integration tests

* Use tagged version in parcel integration tests

* Upgrade postcss-cli integration tests

* upgrade integration test deps

* Fix CS

* Fix tests

* Update lockfile

* Fix vite test in CI
2022-05-19 16:44:20 -04:00
Robin Malfait
96d4ce2516
Expose context.sortClassList(classes) (#7412)
* add prettier-plugin-tailwindcss

This will use the prettier plugin in our tests as well, yay consistency!

* ensure that both `group` and `peer` can't be used in `@apply`

This was only configured for `group`

* expose `sortClassList` on the context

This function will be used by the `prettier-plugin-tailwindcss` plugin,
this way the sorting happens within Tailwind CSS itself adn the
`prettier-plugin-tailwindcss` plugin doesn't have to use internal /
private APIs.

The signature looks like this:
```ts
function sortClassList(classes: string[]): string[]
```

E.g.:
```js
let sortedClasses = context.sortClassList(['p-1', 'm-1', 'container'])
```

* update changelog

* add sort test for utilities with the important modifier e.g.: `!p-4`
2022-02-10 18:06:41 +01:00
Robin Malfait
657bf5f8c9
Allow piping data into the CLI (#6876)
* use outputFile instead of direct writeFile

This is an improvement we introduced earlier but forgot this part.

* allow to pipe in data to the CLI

* add integration tests to validate piping to the CLI

* update changelog
2022-01-04 18:58:55 +01:00
Robin Malfait
f12c0e1fa5
Improve css expectations in tests (#5819)
* use String.raw for css escapes

This will allow us to write code like:
```css
.mobile\:font-bold {}
```
Instead of
```css
.mobile\\:font-bold {}
```

Which resembles "real" css way better in our tests.

* use String.raw in integration tests as well
2021-10-18 12:08:48 +02:00
Robin Malfait
d94541cbf3
Handle old to new config when normalizing the config (#5658)
* immediately take the `safelist` values into account

Currently we had to manually add them in the `setupTrackingContext`,
`setupWatchingContext` and the `cli`.

This was a bit cumbersome, because the `safelist` function (to resolve
regex patterns) was implemented on the context. This means that we had
to do something like this:

```js
let changedContent = []
let context = createContext(config, changedContent)
for (let content of context.safelist()) {
  changedContent.push(content)
}
```

This just feels wrong in general, so now it is handled internally for
you which means that we can't mess it up anymore in those 3 spots.

* drop the dot from the extension

Our transformers and extractors are implemented for `html` for example.
However the `path.extname()` returns `.html`.

This isn't an issue by default, but it could be for with custom
extractors / transformers.

* normalize the configuration

* make shared cache local per extractor

* ensure we always have an `extension`

Defaults to `html`

* splitup custom-extractors test

* update old config structure to new structure

* ensure we validate the "old" structure, and warn if invalid

* add tests with "old" config, to ensure it keeps working

* add missing `content` object

* inline unnecessary function abstraction
2021-10-01 12:56:54 +02:00
Robin Malfait
516ba530f0
Setup integration tests (#5466)
* setup integration tests

* fix rgb color syntax

* ensure integration tests always exit

If for any reason the integration tests fail, then it will run forever
on CI (~2hours or something). The `--forceExit` is not ideal but it will
prevent long running processes.

* fix incorrect test

We were never properly waiting for the command to finish.

* handle AbortError properly

In CI, when an AbortController gets aborted an error is thrown
(AbortError). If we don't catch it properly then it will "leak" and the
test will fail.

* improve IO functions

* quit integration tests after 10seconds

* only test a few integrations

* test all integrations using matrix

This will cancel other builds when one fails, it will also separate the
output per integration which can be useful especially now that we are
still figuring things out.

* rename `build` to `test`

* add --verbose flag to receive output in the console

* when reading stdout or stderr, wait a certain about to ensure stability

Debouncing for 200ms means that if another message comes in within those
200ms we delay the execution of the callback.

* simplify workflow

* use terminal output instead of disk events

* cache node_modules for integrations

* empty commit, to test cache hits
2021-09-14 16:18:14 +02:00
Robin Malfait
691ed02f63
Remove AOT (#5340)
* make `jit` mode the default when no mode is specified

* unify JIT and AOT codepaths

* ensure `Object.entries` on undefined doesn't break

It could be that sometimes you don't have values in your config (e.g.: `presets: []`), this in turn will break some plugins where we assume we have a value.

* drop AOT specific tests

These tests are all covered by JIT mode already and were AOT specific.

* simplify tests, and add a few

Some of the tests were written for AOT specifically, some were missing. We also updated the way we write those tests, essentially making Tailwind a blackbox, by testing against the final output.
Now that JIT mode is the default, this is super fast because we only generate what is used, instead of partially testing in a 3MB file or building it all, then purging.

* add some todo's to make sure we warn in a few cases

* make `darkMode: 'media'`, the default

This also includes moving dark mode tests to its own dedicated file.

* remove PostCSS 7 compat mode

* update CLI to be JIT-first

* fix integration tests

This is not a _real_ fix, but it does solve the broken test for now.

* warn when using @responsive or @variants

* remove the JIT preview warning

* remove AOT-only code paths

* remove all `mode: 'jit'` blocks

Also remove `variants: {}` since they are not useful in `JIT` mode
anymore.

* drop unused dependencies

* rename `purge` to `content`

* remove static CDN builds

* mark `--purge` as deprecated in the CLI

This will still work, but a warning will be printed and it won't show up
in the `--help` output.

* cleanup nesting plugin

We don't have to duplicate it anymore since there is no PostCSS 7
version anymore.

* make sure integration tests run in band

* cleanup folder structure

* make sure nesting folder is available

* simplify resolving of purge/content information
2021-09-01 17:13:59 +02:00
Robin Malfait
f4ea2cf77d
Cleanup leftover layers (#4853)
* update snapshots with correct version

* add test that verifies @layer is removed correctly

* cleanup leftover `@layer` nodes
2021-07-01 06:34:11 -04:00
Robin Malfait
8518fee9ea
implement purge safelist (#4580)
* fix --help output in tests

* add tests to ensure we can use `purge.safelist`

* implement the `purge.safelist` for strings

* proxy `purge.safelist` to `purge.options.safelist`

This allows us to have a similar API in `AOT` and `JIT` mode.

* only proxy `purge.safelist` to `purge.options.safelist` if
`purge.options.safelist` doesn't exists yet.
2021-06-09 10:00:09 -04:00
Adam Wathan
746a12602e
Improve new JIT-compatible CLI (#4558)
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2021-06-04 10:28:09 -04:00