Skip to content

Commit

Permalink
Fix plugin usage in build watch mode [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 18, 2023
1 parent 22f403e commit 61d1375
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 0.7.2

- Fix plugin usage in build watch mode

## 0.7.1

- Sort defaults to get a stable output
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -112,7 +112,7 @@ export const config: DownwindConfig = {

### Arbitrary values

The implementation would work most of the time, but some shortcuts have been made to keep the implementation lean and fast:
Few complex cases are not implemented to keep the implementation lean and fast:

- `backgroundImage`, `backgroundPosition` and `fontFamily` are not supported
- For prefix with collision (divide, border, bg, gradient steps, stroke, text, decoration, outline, ring, ring-offset), if the value doesn't match a CSS color (hex, rgb\[a], hsl\[a]) or a CSS variable it's interpreted as the "size" version. Using data types is not supported
Expand Down Expand Up @@ -155,7 +155,7 @@ export const config: DownwindConfig = {

`max-<screen>` is supported when the screens config is a basic `min-width` only. No sorting is done.

It means `min-*`, `data-*`, `aria-*`, `group-*`, `peer-*` are **not** supported.
Other dynamic variants are not implemented for now. It means `min-*`, `data-*`, `aria-*`, `group-*`, `peer-*` are **not** supported.

Punctual need usage can be accomplished using arbitrary variants: `[@media(min-width:900px)]:block`

Expand Down Expand Up @@ -275,6 +275,6 @@ Then an object with few methods is returned:
- else if ends with `]`, parse the left as arbitrary value
- else search for `/`, parse search for the left in the static rules map and parse the end as a modifier

If the token matches a rule and is new it's added to an internal map structure by media queries. `true` is returned and this can be used to invalidate utils in developments.
If the token matches a rule and is new it's added to an internal map structured by media queries. `true` is returned and this can be used to invalidate utils in developments.

- `generate` is used to transform the recursive map into a CSS output. This is returned as the content of `virtual:@downwind/utils.css` in plugins.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"description": "A bundler-first & PostCSS-independent implementation of Tailwind",
"private": true,
"type": "module",
"version": "0.7.1",
"version": "0.7.2",
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
"license": "MIT",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/esbuildPlugin.ts
Expand Up @@ -50,6 +50,11 @@ const esbuildPlugin: typeof declaration = ({
);

// CSS files
build.onStart(() => {
hasBase = false;
hasUtils = false;
utilsIntervalCheck.reset();
});
build.onLoad({ filter: /\.css$/ }, ({ path }) => {
utilsIntervalCheck.taskRunning();
return {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/intervalCheck.ts
Expand Up @@ -3,6 +3,11 @@ export const intervalCheck = <T>(ms: number, getValue: () => T) => {
let scanHappenedOnce = false;
let scanHappened = false;
return {
reset: () => {
utilsResolved = false;
scanHappenedOnce = false;
scanHappened = false;
},
promise: new Promise<T>((resolve) => {
const intervalId = setInterval(() => {
if (!scanHappenedOnce) return;
Expand Down
5 changes: 5 additions & 0 deletions src/vitePlugin.ts
Expand Up @@ -166,6 +166,11 @@ const vitePlugin: typeof declaration = ({
enforce: "pre",
configResolved,
resolveId,
buildStart() {
hasBase = false;
hasUtils = false;
utilsIntervalCheck.reset();
},
load(id) {
if (id === baseModuleId) return downwind.getBase();
if (id === utilsModuleId) return utilsIntervalCheck.promise;
Expand Down

0 comments on commit 61d1375

Please sign in to comment.