Skip to content

Commit 8959404

Browse files
authored
switch to blake3 hashing (#83)
1 parent d4a605f commit 8959404

10 files changed

Lines changed: 170 additions & 127 deletions

.changeset/full-tips-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fuzdev/fuz_css': minor
3+
---
4+
5+
switch to blake3 hashing, add optional peer dep `@fuzdev/blake3_wasm`

package-lock.json

Lines changed: 69 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"node": ">=22.15"
3131
},
3232
"peerDependencies": {
33+
"@fuzdev/blake3_wasm": "^0.1.0",
3334
"@fuzdev/fuz_util": ">=0.52.0",
3435
"@fuzdev/gro": ">=0.195.0",
3536
"@sveltejs/acorn-typescript": "^1",
@@ -39,6 +40,9 @@
3940
"zod": "^4"
4041
},
4142
"peerDependenciesMeta": {
43+
"@fuzdev/blake3_wasm": {
44+
"optional": true
45+
},
4246
"@fuzdev/fuz_util": {
4347
"optional": true
4448
},
@@ -63,15 +67,16 @@
6367
},
6468
"devDependencies": {
6569
"@changesets/changelog-git": "^0.2.1",
70+
"@fuzdev/blake3_wasm": "^0.1.0",
6671
"@fuzdev/fuz_code": "^0.45.1",
6772
"@fuzdev/fuz_ui": "^0.185.2",
68-
"@fuzdev/fuz_util": "^0.52.1",
73+
"@fuzdev/fuz_util": "^0.53.0",
6974
"@fuzdev/gro": "^0.196.0",
7075
"@jridgewell/trace-mapping": "^0.3.31",
7176
"@ryanatkn/eslint-config": "^0.9.0",
72-
"@sveltejs/acorn-typescript": "^1.0.8",
77+
"@sveltejs/acorn-typescript": "^1.0.9",
7378
"@sveltejs/adapter-static": "^3.0.10",
74-
"@sveltejs/kit": "^2.50.1",
79+
"@sveltejs/kit": "^2.53.4",
7580
"@sveltejs/package": "^2.5.7",
7681
"@sveltejs/vite-plugin-svelte": "^6.2.4",
7782
"@types/estree": "^1.0.8",
@@ -84,9 +89,9 @@
8489
"magic-string": "^0.30.21",
8590
"prettier": "^3.7.4",
8691
"prettier-plugin-svelte": "^3.4.1",
87-
"svelte": "^5.49.1",
88-
"svelte-check": "^4.3.6",
89-
"svelte2tsx": "^0.7.47",
92+
"svelte": "^5.53.7",
93+
"svelte-check": "^4.4.4",
94+
"svelte2tsx": "^0.7.51",
9095
"tslib": "^2.8.1",
9196
"typescript": "^5.9.3",
9297
"typescript-eslint": "^8.48.1",

src/lib/css_ruleset_parser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const parse_ruleset = (css: string): ParsedRuleset => {
6363
* @mutates rules - pushes extracted rules to the array
6464
*/
6565
const walk_css_children = (
66-
node: Omit<AST.CSS.StyleSheet, 'attributes' | 'content'> | AST.CSS.Atrule,
66+
node: Omit<AST.CSS.StyleSheetFile, 'attributes' | 'content'> | AST.CSS.Atrule,
6767
original_css: string,
6868
rules: Array<ParsedRule>,
6969
): void => {
@@ -72,7 +72,6 @@ const walk_css_children = (
7272
for (const child of children) {
7373
if (child.type === 'Rule') {
7474
extract_rule(child, original_css, rules);
75-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7675
} else if (child.type === 'Atrule' && child.block) {
7776
// Recurse into at-rules (like @media) - rules are in block.children
7877
walk_css_block(child.block, original_css, rules);

src/lib/gen_fuz_css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ export const gen_fuz_css = (options: GenFuzCssOptions = {}): Gen => {
168168
if (!style_rule_index) {
169169
if (typeof base_css === 'string') {
170170
// Custom CSS string provided (replacement)
171-
style_rule_index = await create_style_rule_index(base_css);
171+
style_rule_index = create_style_rule_index(base_css);
172172
} else if (typeof base_css === 'function') {
173173
// Callback to modify default CSS
174174
const default_css = await load_default_style_css(deps);
175175
const modified_css = base_css(default_css);
176-
style_rule_index = await create_style_rule_index(modified_css);
176+
style_rule_index = create_style_rule_index(modified_css);
177177
} else {
178178
// Use default style.css (undefined or null - null handled by include_base flag)
179179
style_rule_index = await load_style_rule_index(deps);

src/lib/style_rule_parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import {parseCss, type AST} from 'svelte/compiler';
13-
import {hash_secure} from '@fuzdev/fuz_util/hash.js';
13+
import {hash_blake3} from '@fuzdev/fuz_util/hash_blake3.js';
1414

1515
import {extract_css_variables} from './css_variable_utils.js';
1616
import type {CacheDeps} from './deps.js';
@@ -503,7 +503,7 @@ export const load_style_rule_index = async (
503503
if (css === null) {
504504
throw new Error(`Failed to read style.css from ${path}`);
505505
}
506-
const content_hash = await hash_secure(css);
506+
const content_hash = hash_blake3(css);
507507
return parse_style_css(css, content_hash);
508508
};
509509

@@ -512,10 +512,10 @@ export const load_style_rule_index = async (
512512
* Use this to parse user-provided base styles instead of loading from file.
513513
*
514514
* @param css - raw CSS string to parse
515-
* @returns promise resolving to `StyleRuleIndex`
515+
* @returns `StyleRuleIndex`
516516
*/
517-
export const create_style_rule_index = async (css: string): Promise<StyleRuleIndex> => {
518-
const content_hash = await hash_secure(css);
517+
export const create_style_rule_index = (css: string): StyleRuleIndex => {
518+
const content_hash = hash_blake3(css);
519519
return parse_style_css(css, content_hash);
520520
};
521521

0 commit comments

Comments
 (0)