@akanjs/devkit 3.3.0-rc.75 → 3.3.0-rc.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,18 @@ describe("CssCandidateCache token extraction", () => {
18
18
  expect(candidates).toEqual(expect.arrayContaining(["w-full", "hover:bg-muted", "md:w-1/2", "text-[#fff]"]));
19
19
  });
20
20
 
21
+ test("keeps Tailwind's important mark on the candidate, leading or trailing, and reads code's `!` as code", async () => {
22
+ const candidates = await scan(
23
+ `const c = "h-0! w-0! !h-0 md:!w-1 md:w-1! -mt-2! !-mt-2 w-[10px]!"; if (a !== b && x!==y) ref!.focus();`,
24
+ );
25
+ expect(candidates).toEqual(
26
+ expect.arrayContaining(["h-0!", "w-0!", "!h-0", "md:!w-1", "md:w-1!", "-mt-2!", "!-mt-2", "w-[10px]!"]),
27
+ );
28
+ expect(candidates).toEqual(expect.arrayContaining(["a", "b", "x", "y", "ref", "focus"]));
29
+ expect(candidates).not.toContain("h-0");
30
+ expect(candidates).not.toContain("x!");
31
+ });
32
+
21
33
  test("keeps an arbitrary variant that starts with a bracket", async () => {
22
34
  const candidates = await scan(`const c = "[&_td]:px-3 [&>*]:gap-2 [&_tbody_tr]:border-t";`);
23
35
  expect(candidates).toEqual(expect.arrayContaining(["[&_td]:px-3", "[&>*]:gap-2", "[&_tbody_tr]:border-t"]));
@@ -6,9 +6,11 @@ import { type BuildCacheStamp, buildCacheStamp, isBuildCacheStamp } from "./buil
6
6
  // bracket (`[&_[data-slot=x]]:p-2`, `has-[[aria-expanded=true]]:x`), or the candidate is cut at the inner `]` and the
7
7
  // rule silently never compiles. Brackets hold no whitespace: a labelled tuple type scanned as a class compiles to a
8
8
  // rule lightningcss cannot parse, and it then drops every variant rule. Parentheses pass only as Tailwind v4's
9
- // variable shorthand, `(--x)` or `(length:--x)`, so `cn("flex")` still yields `flex` on its own.
9
+ // variable shorthand, `(--x)` or `(length:--x)`, so `cn("flex")` still yields `flex` on its own. Tailwind's important
10
+ // mark stays on the candidate, leading (`!h-0`, `md:!h-0`) or trailing (`h-0!`): a candidate cut off it compiles
11
+ // without `!important`, silently. A trailing `!` followed by `=` or a word is code (`a !== b`, `ref!.x`), not a mark.
10
12
  const CANDIDATE_RE =
11
- /-?(?:[\w@]|\[(?:[^[\]\s]|\[[^[\]\s]+\])+\])[\w:/.-]*(?:(?:\[(?:[^[\]\s]|\[[^[\]\s]+\])+\]|\((?:[a-z-]+:)?--[^)\s]+\))[\w:/.-]*)*/g;
13
+ /!?-?(?:[\w@]|\[(?:[^[\]\s]|\[[^[\]\s]+\])+\])(?:[\w:/.-]|(?<=:)!)*(?:(?:\[(?:[^[\]\s]|\[[^[\]\s]+\])+\]|\((?:[a-z-]+:)?--[^)\s]+\))(?:[\w:/.-]|(?<=:)!)*)*(?:!(?![\w=.([]))?/g;
12
14
 
13
15
  interface CachedFile {
14
16
  mtimeMs: number;
@@ -24,7 +26,7 @@ interface CacheFile extends BuildCacheStamp {
24
26
  /** Tailwind candidates per source file, on disk: the batch worker that compiles CSS exits before the next save. */
25
27
  export class CssCandidateCache {
26
28
  // Bump when the token regex or the entry shape changes, so stale extractions are not reused.
27
- static readonly #version = 6;
29
+ static readonly #version = 7;
28
30
  readonly #path: string;
29
31
  readonly #stamp: BuildCacheStamp;
30
32
  readonly #entries = new Map<string, CachedFile>();
@@ -98,6 +98,20 @@ describe("CssCompiler on a stylesheet that uses no Tailwind", () => {
98
98
  expect(compiled).toContain(".flex {");
99
99
  });
100
100
 
101
+ test("compiles a utility marked important, leading or trailing, as `!important`", async () => {
102
+ const root = await makeTempRoot();
103
+ await write(path.join(root, "styles.css"), '@import "tailwindcss";\n');
104
+ await write(path.join(root, "Page.tsx"), 'export const Page = () => <main className="h-0! !w-0" />;\n');
105
+
106
+ const compiled = await cssCompilerFor(root, root).compileCss(
107
+ [path.join(root, "styles.css")],
108
+ [path.join(root, "Page.tsx")],
109
+ );
110
+
111
+ expect(compiled).toMatch(/\.h-0\\! \{\s*height: 0px !important;/);
112
+ expect(compiled).toMatch(/\.\\!w-0 \{\s*width: 0px !important;/);
113
+ });
114
+
101
115
  test("switches to Tailwind on the next rebuild once a stylesheet gains a directive, and back", async () => {
102
116
  const root = await makeTempRoot();
103
117
  const stylesPath = path.join(root, "page/styles.css");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.3.0-rc.75",
3
+ "version": "3.3.0-rc.77",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -52,10 +52,10 @@
52
52
  "./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
53
53
  },
54
54
  "dependencies": {
55
- "@akanjs/language": "3.3.0-rc.75",
55
+ "@akanjs/language": "3.3.0-rc.77",
56
56
  "@inquirer/prompts": "^8.7.3",
57
57
  "@tailwindcss/node": "^4.3.3",
58
- "akanjs": "3.3.0-rc.75",
58
+ "akanjs": "3.3.0-rc.77",
59
59
  "chalk": "^6.0.1",
60
60
  "commander": "^15.0.0",
61
61
  "dayjs": "^1.11.23",