Skip to content

Commit 3493a4e

Browse files
authored
fix(fmt): bypass cache for Tailwind plugin files (#632)
1 parent 8a60840 commit 3493a4e

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎packages/rstack/src/fmt/plugins.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ const fingerprintPlugin = async (
7979
return undefined;
8080
}
8181

82+
// Tailwind sorting can depend on stylesheets and auto-discovered configs,
83+
// including their transitive dependencies, which our cache does not track.
84+
if (pkg.name === 'prettier-plugin-tailwindcss') {
85+
return undefined;
86+
}
87+
8288
return JSON.stringify([
8389
'package',
8490
pkg.name,

‎packages/rstack/tests/cli/fmt/cache.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@ test('--no-cache bypasses cache reads and writes', () => {
8282
expect(projectFileExists('.rstack/cache/.gitignore')).toBe(false);
8383
});
8484

85+
test('bypasses the cache for files using the Tailwind plugin', () => {
86+
writeProjectFile(
87+
'rstack.config.ts',
88+
`import { define } from 'rstack';
89+
90+
define.fmt({
91+
overrides: [{
92+
files: '*.html',
93+
options: {
94+
plugins: ['prettier-plugin-tailwindcss'],
95+
tailwindStylesheet: ${JSON.stringify(resolveProjectPath('app.css'))},
96+
},
97+
}],
98+
});
99+
`,
100+
);
101+
writeProjectFile('index.html', '<div class="alpha beta"></div>\n');
102+
writeProjectFile('index.ts', 'const value = 1;\n');
103+
writeProjectFile(
104+
'app.css',
105+
'@utility alpha { display: flex; }\n@utility beta { padding: 1rem; }\n',
106+
);
107+
108+
expect(runFmt(['--check', 'index.html', 'index.ts']).status).toBe(0);
109+
110+
writeProjectFile(
111+
'app.css',
112+
'@utility alpha { padding: 1rem; }\n@utility beta { display: flex; }\n',
113+
);
114+
expect(runFmt(['--check', 'index.html']).status).toBe(1);
115+
expect(runFmt(['index.html']).status).toBe(0);
116+
expect(readProjectFile('index.html')).toBe(
117+
'<div class="beta alpha"></div>\n',
118+
);
119+
expectSingleCleanEntry(
120+
readFmtCache('.rstack/cache/fmt/cache.json'),
121+
'index.ts',
122+
);
123+
});
124+
85125
test.each(['relative', 'absolute'] as const)(
86126
'uses a %s custom cache location',
87127
(kind) => {

0 commit comments

Comments
 (0)