Skip to content

Commit 6d74ae0

Browse files
committed
Force nextjs cache tu be updated when icons have changed
1 parent 0c6bfda commit 6d74ae0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "rimraf dist/ && tsc -p src/bin && yarn copy_dsfr_dist_to_root && yarn css_to_ts && tsc -p src && yarn grant_exec_perms",
1313
"test": "vitest",
1414
"start_cra": "yarn yarn_link && cd test/integration/cra && yarn start",
15-
"start_next": "yarn yarn_link && cd test/integration/next && rm -rf .next && yarn dev",
15+
"start_next": "yarn yarn_link && cd test/integration/next && yarn dev",
1616
"start_vite": "yarn yarn_link && cd test/integration/vite && yarn dev",
1717
"lint:check": "eslint . --ext .ts,.tsx",
1818
"lint": "yarn lint:check --fix",

src/bin/only_include_used_icons.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as fs from "fs";
88
import { join as pathJoin } from "path";
99
import { assert } from "tsafe/assert";
1010
import { exclude } from "tsafe/exclude";
11-
import { writeFile, readFile } from "fs/promises";
11+
import { writeFile, readFile, rm } from "fs/promises";
1212
import { crawl } from "./tools/crawl";
1313
import { basename as pathBasename } from "path";
1414
import type { Equals } from "tsafe";
@@ -149,6 +149,16 @@ import type { Equals } from "tsafe";
149149
"utf8"
150150
);
151151

152+
const onConfirmedChange = async () => {
153+
const nextCacheDir = pathJoin(cwd, ".next", "cache");
154+
155+
if (!fs.existsSync(nextCacheDir)) {
156+
return;
157+
}
158+
159+
rm(nextCacheDir, { "recursive": true, "force": true });
160+
};
161+
152162
[
153163
dsfrDistDirPath,
154164
...(() => {
@@ -173,11 +183,18 @@ import type { Equals } from "tsafe";
173183
)
174184
);
175185

176-
["icons.css", "icons.min.css"].forEach(cssFileBasename =>
177-
writeFile(
178-
pathJoin(dsfrDistDirPath, "utility", "icons", cssFileBasename),
179-
rawIconCssCodeBuffer
180-
)
181-
);
186+
["icons.css", "icons.min.css"].forEach(async cssFileBasename => {
187+
const filePath = pathJoin(dsfrDistDirPath, "utility", "icons", cssFileBasename);
188+
189+
const currentCode = await readFile(filePath);
190+
191+
if (Buffer.compare(rawIconCssCodeBuffer, currentCode) === 0) {
192+
return;
193+
}
194+
195+
onConfirmedChange();
196+
197+
writeFile(filePath, rawIconCssCodeBuffer);
198+
});
182199
});
183200
})();

0 commit comments

Comments
 (0)