-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that S2 style macro produces different class names for di…
…fferent S2 themes
- Loading branch information
1 parent
a792c1a
commit 0ab887a
Showing
5 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
export function getThemeVersion() { | ||
let s2PkgPath = require.resolve('@react-spectrum/s2'); | ||
while (s2PkgPath.length > 2) { | ||
const filePath = path.join(s2PkgPath, 'package.json'); | ||
try { | ||
const stats = fs.statSync(filePath, {throwIfNoEntry: false}); | ||
if (stats?.isFile()) { | ||
break; | ||
} | ||
} catch { /* empty */ } | ||
s2PkgPath = path.dirname(s2PkgPath); | ||
} | ||
const s2PkgMetadata = require(path.join(s2PkgPath, 'package.json')); | ||
return hashSemVer(s2PkgMetadata.version); | ||
} | ||
|
||
function hashSemVer(version: string) { | ||
const alphabet = 'abcdefghijklmnopqrstuvwxyz'; | ||
const base = alphabet.length; | ||
const [major, minor, patch] = version.split('.').map(Number); | ||
const combined = (major << 16) | (minor << 8) | patch; | ||
let hashStr = ''; | ||
let num = combined; | ||
while (num > 0) { | ||
hashStr = alphabet[num % base] + hashStr; | ||
num = Math.floor(num / base); | ||
} | ||
return hashStr; | ||
} |