-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
910b655
commit 3cfb703
Showing
4 changed files
with
85 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import crypto from 'crypto' | ||
import * as sharedState from './sharedState' | ||
|
||
/** | ||
* | ||
* @param {string} str | ||
*/ | ||
function getHash(str) { | ||
try { | ||
return crypto.createHash('md5').update(str, 'utf-8').digest('binary') | ||
} catch (err) { | ||
return '' | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} sourcePath | ||
* @param {import('postcss').Node} root | ||
*/ | ||
export function hasContentChanged(sourcePath, root) { | ||
let css = root.toString() | ||
|
||
// We only care about files with @tailwind directives | ||
// Other files use an existing context | ||
if (!css.includes('@tailwind')) { | ||
return false | ||
} | ||
|
||
let existingHash = sharedState.sourceHashMap.get(sourcePath) | ||
let rootHash = getHash(css) | ||
let didChange = existingHash !== rootHash | ||
|
||
sharedState.sourceHashMap.set(sourcePath, rootHash) | ||
|
||
return didChange | ||
} |
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