76 Commits

Author SHA1 Message Date
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
bf44941049
Allow resolving content paths relative to the config file (#9396)
* Update lockfile

* Tweak formatting

* Refactor content path parsing

* Allow resolving content paths relative to the config file

* Include resolved symlinks as additional content paths

* Update changelog

* Work on suite of tests for content resolution

* reformat integration test list

* Move content resolution tests to integration

* Update future and experimental types
2022-09-23 08:09:02 -04:00
Jordan Pittman
4e623343e4
Revert "Only listen for stdin close on TTYs (#8523)" (#9331)
* Revert "Only listen for stdin close on TTYs (#8523)"

This reverts commit 14f6574318b66f7df4d8767c2c70ecb73c4ee26d.

* Update changelog
2022-09-14 16:06:34 -04:00
Jordan Pittman
8b1bf8006d
CLI: Ignore watch events for files that don't match globs (#9215)
* Don’t re-add files in the CLI watcher that are covered by dynamic patterns

They don’t have the same problem. As long as the parent directory is watched their add/change events will fire correctly

* Ignore raw events for files that don’t match the content files

* fixup

* Update changelog
2022-08-31 12:59:56 -04:00
Jordan Pittman
b0a549923f Handle when watchedPath is a file and not directory 2022-08-26 14:35:08 -04:00
Jordan Pittman
ad7dbda7e9
Fix CLI not watching atomically renamed files (#9173)
* Fix CLI not watching atomically renamed files

Chokdar should take care of this itself but sometimes it doesn’t do so OR is otherwise very sensitive to timing problems

* Force chokidar to always check for atomic writes

* Handle repeated atomic saves by retrying file reads

* Update changelog
2022-08-26 12:47:00 -04:00
Robin Malfait
0d064ea032
Enable postcss-import in the CLI by default in watch mode (#8580)
* Add support for postcss-import in watch mode

* Add regression test

* Extract shared logic

* restructure test a little bit

Instead of relying on a arbitrary setTimout value, let's wait for the
file to be created instead.

* update changelog

Co-authored-by: Adam Bergman <adam@fransvilhelm.com>
2022-06-10 11:33:35 +02:00
Robin Malfait
a0c2ee8c38
Ensure we can use @import 'tailwindcss/...' without node_modules (#8537)
* ensure we can use `@import 'tailwindcss/...'` without node_modules

This is useful if you are using `npx tailwindcs ...` and to prevent
that postcss-import crashes on the tailwind specific imports which we
will replace anyway.

* update changelog
2022-06-07 19:03:38 +02:00
Jordan Pittman
14f6574318
Only listen for stdin close on TTYs (#8523) 2022-06-06 10:04:18 -04:00
Robin Malfait
4a745439f0
Add type annotations to the tailwind.config.js file (#8493)
* add type annotation to the config by default

* use `@type {import('tailwindcss').Config}` instead
2022-06-02 16:44:12 +02:00
Jordan Pittman
c4e443acc0
Add postcss-import support to the CLI (#8437)
* Add postcss-import support to the CLI

* Update changelog
2022-05-25 14:28:52 -04:00
Jordan Pittman
6c63f67d20
Create tailwind.config.cjs file in ESM package when running init (#8363)
* refactor

* Adds support for tailwind.config.cjs files to CLI

* Update changelog

Co-authored-by: Nate Moore <nate@natemoo.re>
2022-05-16 10:53:03 -04:00
Jordan Pittman
0313f02e2c
Move some config error checking out of resolveConfig (#8362) 2022-05-16 10:10:40 -04:00
Jordan Pittman
67d2286838
Try using local postcss installation first in the CLI (#8270)
* Load local PostCSS package if available

* Update changelog
2022-05-05 10:43:09 -04:00
Jordan Pittman
122fb89e6c
Support postcss config options in config file in the CLI (#8226)
* Support config options from postcss CLI

* Update changelog
2022-04-28 15:14:36 -04:00
Jordan Pittman
7ed46b6f52 Re-enable new features
This reverts commits 1456ed9021b3455dbb4458c2fb7d8ab66dfb3fed, d0269c24b3c7ad4557b7e3f2779bd15c5ac501f7, and 57699a04036c542d82e7b7102d775d4d2379493d.
2022-04-12 14:13:04 -04:00
Jordan Pittman
57699a0403
Prep for patch release (#8098)
* Disable backdrop variant

* Disable enabled variant

* Disable border spacing utilities

* Disable text-start/end utilities

* Disable poll option in CLI

* Disable ring color default fn

* Disable dark mode class name customization

* Disable support for `Document` node types

* Disable rgb/hsl fns

* Update tests

* Temporarily disable type generation

* Update changelog
2022-04-12 13:58:57 -04:00
Robin Malfait
407a5c368c
Add TypeScript types for the tailwind.config.js file (#7891)
* add generate-types script

This script will generate the full list of core plugins, which will
allow you to get code completion for the `corePlugins` section.

It will also generate all the colors (and deprecated colors) which is
used in multiple places in the config.

* add types for the `tailwind.config.js` config file

* annotate stubs with a JSDoc pointing to the types

* add types to package.json

- Updated the files to make sure that the types are being published
- Add a `types` section in the `package.json`, otherwise your editor by
  default will look for the `DefinitelyTyped` types which got me really
  confused for a second.
- Added some scripts to make sure that the generation of types happens
  when needed (before tests and before building). This way you never
  ever have to think about generating them when working on Tailwind CSS
  internals.

* re-export types top-level

Having a `colors.d.ts` next to the `colors.js` file allows us to type
the `colors.js` file and your editor will pickup the types from
`colors.d.ts`.

* also publish generated types

* update changelog

* enable TypeScript only when using `init --types` for now

* update tests to verify that `--types` works
2022-03-22 10:24:28 +01:00
Jordan Pittman
ee945bbea2
Add an explicit --poll option to the CLI (#7725)
* Refactor

* Allow user to enable polling

* Update changelog
2022-03-02 11:16:06 -05:00
Bogdan Chadkin
f31c4ee4cf
Replace cosmiconfig with lilconfig (#6038)
* Replace cosmiconfig with lilconfig

It's already replaced in postcss-load-config

See https://github.com/postcss/postcss-load-config/blob/main/package.json#L26

* Manually restore parse-json in lockfile removed by npm conflict resolver

* Revert `postcss` version change

Co-authored-by: Brad Cornes <hello@bradley.dev>
2022-03-01 18:27:56 +00:00
Robin Malfait
64cf0b8e8a
Remove false positive warning in CLI when using the --content option (#7220)
* ensure content files are available in config

If you use the cli with the `--content` option, then we first resolve
the config (empty), then add the `content` to the config. The issue is
that this means that the content will be empty when you resolve it
initially. This results in a warning in your terminal.

Now, we will make sure to merge 2 configs if you have the `--content`
data passed. We will also make sure to override the final
`config.content.files` to whatever you passed in to make sure that this
is the same behaviour as before.

* update changelog
2022-01-26 19:31:50 +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
Geoffrey
0bcd628ec3
Avoid writing to output files when no changes (#6550)
* fix(cli): avoid write same output when no changes

* generalize outputFile

This function will check a cache, it will only write the file if:
- The modified timestamps changed since last time we wrote something.
  This is useful to know if something changed by another tool or
  manually without diffing the full file.
- The contents changed.

* further simplify checks

Turns out that reading files and comparing them is fairly fast and there
is no huge benefit over only using the Stats of the file and keeping
track of that information.

Thanks @kentcdodds!

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-04 16:29:16 +01:00
Dany Castillo
de1bdb4f5d
Fix debug mode being active although explicitly disabled (#5837)
* fix debug mode being active although explicitly disabled

* also set debug mode correctly in sharedState
2021-10-25 11:25:25 +02:00
Brad Cornes
92df04d0c3
Fix CLI --content option (#5775)
* Add failing test

* Fix CLI `--content` option
2021-10-13 19:58:15 +01:00
Brad Cornes
f599430d56
Configure awaitWriteFinish for chokidar (#5774)
* Configure `awaitWriteFinish` for chokidar

* Enable `awaitWriteFinish` on Windows only
2021-10-13 12:59:26 +01: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
Jonathan Reinink
cd5cb00266
Implement one-time logging to prevent duplicate warnings (#5661)
Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2021-09-30 21:16:01 -04:00
Robin Malfait
39ccd06141
Fix fallback argument in CLI (#5646)
I don't know exactly what happened here, but it seems like I screwed
this trivial fallback up in a spectacular way... anyway, here to fix it!
2021-09-29 23:33:43 +02:00
Brad Cornes
484acb3f6b
Fix using backslashes in content globs (#5628)
* Normalize content globs

* Update changelog
2021-09-29 14:13:10 +01:00
Robin Malfait
30badadd21
ensure that we fallback to the first argument without any flags (#5464) 2021-09-10 10:14:44 +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
José Valim
b280378c33
Abort the watcher if stdin is closed to avoid zombie processes (#4997)
* Abort the watcher if stdin is closed to avoid zombie processes

* Apply suggestions from code review
2021-08-23 14:35:28 -04:00
Arnout Roemers
aefd5f71cb
Enable purging when --purge option is supplied in CLI (#4772)
Do not require NODE_ENV to be set to 'production' as well, as using
the --purge option in the CLI should be explicit enough.

Co-authored-by: Arnout Roemers <roemers@zorgdomein.nl>
2021-06-23 14:12:06 -04:00
Robin Malfait
70ca673d96
ensure the CLI in watch mode keeps running when on error (#4693) 2021-06-18 08:46:00 -04:00
Robin Malfait
f4799a32e8
add tests for the --postcss option in the new CLI (#4607)
* add tests for the --postcss option in the new CLI

* add `oneOf` ability to the `arg()` functionality

By default, `arg()` doesn't have a way to define multiple types. We want
the possibility of using `--postcss` (Boolean) or `--postcss
./custom-path.js`. But by default this is not possible.

This commit will allow us to do a few things, mainly:
- Keep the same API using the `{ type: oneOf(String, Boolean), description: '...' }`
- Keep the `--help` output similar

What we did behind the scenes is make sure to put the non recognized
flags in the `_` arguments list. This is possible by doing `permissive:
true`. We then manually parse those and resolve the correct value.

* ensure that we can use a custom `--postcss ./with-custom-path.js`
2021-06-10 11:35:17 -04:00
Robin Malfait
6f1d5f03cb
prefer local plugins (#4598)
* prefer local plugins over bundled plugins

* hoist resolving of plugins

* drop `options` when local `cssnano` is found
2021-06-09 13:13:30 -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
Brad Cornes
3569d49f7e
fix cli purge option when using commas (#4578) 2021-06-08 06:32:50 -04:00
Adam Wathan
40645d7dca Rename --files option in CLI to --purge 2021-06-07 14:01:59 -04:00
Adam Wathan
67ee5e033d Write to stdout in watch mode if no output file provided 2021-06-05 16:38:54 -04:00
Adam Wathan
bd20d2c0fa Don't reassign configPath 2021-06-04 12:52:53 -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
Robin Malfait
4528bdc2d8
Start of new CLI (#4526)
* Ignore workspace settings

* Parameterize setting up the context

* WIP

* WIP

* WIP

* WIP

* wip

* WIP

Co-Authored-By: Jesse Katsumata <niconico.clarinet@gmail.com>

* WIP

Co-Authored-By: Jesse Katsumata <niconico.clarinet@gmail.com>

* WIP

Co-Authored-By: Jesse Katsumata <niconico.clarinet@gmail.com>

* Update some comments

Co-Authored-By: Jesse Katsumata <niconico.clarinet@gmail.com>

* Fix bug

* WIP

* WIP'

* more things

* log console.time calls conditionally based on process.env.DEBUG

* add `init` command

* clean up when using --jit

* Make config file optional

* cleanup path.resolve calls

path.resolve('.') is the same as path.resolve(process.cwd(), '.')

* implement `--help`

* shush eslint

* drop unnecessary file

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
Co-authored-by: Jesse Katsumata <niconico.clarinet@gmail.com>
2021-06-01 14:02:23 +02:00
Adam Wathan
38b4eeb288 Prettier likes parens a lot now
git blame is now broken forever.
2020-10-16 15:39:44 -04:00
Matt Stypa
eb4da80ede Code style updates 2018-09-24 07:55:24 -05:00
Matt Stypa
1b1ae8abc9 When no output file is specified for the build command, the result will be piped to stdout 2018-09-23 22:00:50 -05:00
mattstypa
d91eea88fb Reverted changes to processTailwindFeatures that would impact Webpack watch ability. As a result all commands also became Promise based 2018-09-14 11:07:23 -05:00
Matt Stypa
a20b4519d4 Node hashbang is required for npm bin files 2018-09-14 06:38:13 -05:00
Matt Stypa
b71cfe711e CLI tool rewrite 2018-09-13 21:37:10 -05:00