From 61d137517c1913117ac57d2c2fc7e08aa26bfd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Mon, 18 Dec 2023 16:19:54 +0100 Subject: [PATCH] Fix plugin usage in build watch mode [publish] --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- package.json | 2 +- src/esbuildPlugin.ts | 5 +++++ src/utils/intervalCheck.ts | 5 +++++ src/vitePlugin.ts | 5 +++++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0ad24..ee4e8b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 2fc3783..9bb6f96 100644 --- a/README.md +++ b/README.md @@ -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 @@ -155,7 +155,7 @@ export const config: DownwindConfig = { `max-` 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` @@ -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. diff --git a/package.json b/package.json index fe2bdcc..d7282da 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/esbuildPlugin.ts b/src/esbuildPlugin.ts index d906c85..f198d5f 100644 --- a/src/esbuildPlugin.ts +++ b/src/esbuildPlugin.ts @@ -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 { diff --git a/src/utils/intervalCheck.ts b/src/utils/intervalCheck.ts index 30549e7..26abbe1 100644 --- a/src/utils/intervalCheck.ts +++ b/src/utils/intervalCheck.ts @@ -3,6 +3,11 @@ export const intervalCheck = (ms: number, getValue: () => T) => { let scanHappenedOnce = false; let scanHappened = false; return { + reset: () => { + utilsResolved = false; + scanHappenedOnce = false; + scanHappened = false; + }, promise: new Promise((resolve) => { const intervalId = setInterval(() => { if (!scanHappenedOnce) return; diff --git a/src/vitePlugin.ts b/src/vitePlugin.ts index 8e62d45..7131475 100644 --- a/src/vitePlugin.ts +++ b/src/vitePlugin.ts @@ -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;