Skip to content

Commit

Permalink
fix: use pseudo and media for hashing (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
axyz authored Feb 11, 2020
1 parent cf3d6ae commit 1b85fc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@utilitycss/atomic",
"version": "0.8.0",
"version": "0.9.0",
"author": "Andrea Moretti (@axyz) <[email protected]>",
"description": "Atomic CSS composition for yarn workspaces",
"repository": "utilitycss/atomic",
Expand Down Expand Up @@ -57,10 +57,7 @@
}
},
"lint-staged": {
"*.js": [
"prettier --no-config --write",
"git add"
],
"*.js": ["prettier --no-config --write", "git add"],
"*.ts": [
"prettier --no-config --write",
"tslint -c tslint.json -p tsconfig.json --fix",
Expand Down
30 changes: 25 additions & 5 deletions src/postcss/atomic-css-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,31 @@ function hashFunction(string: string, length: number): string {

const CLASS_RE = /\.([\w-]+)/g;

const generateHashableContent = (rule: Rule): string =>
rule.nodes
.filter((d: Declaration) => d.prop !== "composes")
.map((node: Declaration) => node.type + node.prop + node.value)
.join(";");
const generateHashableContent = (rule: Rule): string => {
let pseudo = "";
let media = "";

if (rule.selector && rule.selector.indexOf(":") !== -1) {
pseudo = `;${rule.selector.split(/:+/)[1]}`;
}

if (
rule.parent &&
rule.parent.type === "atrule" &&
rule.parent.name === "media"
) {
media = `;${rule.parent.params}`;
}

return (
rule.nodes
.filter((d: Declaration) => d.prop !== "composes")
.map((node: Declaration) => node.type + node.prop + node.value)
.join(";") +
pseudo +
media
);
};

const getElectronDefinition = (server: AtomsServer, name: any): string => {
const definitionsMap = new Map();
Expand Down

0 comments on commit 1b85fc5

Please sign in to comment.