Skip to content

Commit

Permalink
Removed #25 's update
Browse files Browse the repository at this point in the history
  • Loading branch information
soranoo committed Mar 8, 2024
1 parent 374ba8c commit ad4c46f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-css-obfuscator",
"version": "2.2.11",
"version": "2.2.12",
"description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
60 changes: 54 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "./types";

import { obfuscateCss } from "./handlers/css";
import { obfuscateHtmlClassNames } from "./handlers/html";
import { obfuscateHtmlClassNames, findHtmlTagContentsByClass, findHtmlTagContents } from "./handlers/html";
import { obfuscateJs } from "./handlers/js";

//! ====================
Expand Down Expand Up @@ -171,11 +171,50 @@ function replaceJsonKeysInFiles(
if (htmlMatch) {
let html = htmlMatch[0];
const htmlOriginal = html;
const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass);
addKeysToRegistery(usedKeys);
if (htmlOriginal !== obfuscatedContent) {
fileContent = fileContent.replace(htmlOriginal, html);

//! rollback
const tagContents = findHtmlTagContentsByClass(html, obfuscateMarkerClass);
tagContents.forEach(tagContent => {
const { obfuscatedContent, usedKeys } = obfuscateKeys(classConversion, tagContent, contentIgnoreRegexes);
addKeysToRegistery(usedKeys);
if (tagContent !== obfuscatedContent) {
html = html.replace(tagContent, obfuscatedContent);
log("debug", `Obscured keys under HTML tag in file:`, normalizePath(filePath));
}
});

//! rollback
const scriptTagContents = findHtmlTagContents(html, "script");
scriptTagContents.forEach(scriptTagContent => {
const obfuscateScriptContent = obfuscateJs(
scriptTagContent,
obfuscateMarkerClass,
classConversion,
filePath,
contentIgnoreRegexes,
enableJsAst
);
if (scriptTagContent !== obfuscateScriptContent) {
html = html.replace(scriptTagContent, obfuscateScriptContent);
log("debug", `Obscured keys under HTML script tag in file:`, normalizePath(filePath));
}
});

//! rollback
if (htmlOriginal !== html) {
const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass);
addKeysToRegistery(usedKeys);
if (htmlOriginal !== obfuscatedContent) {
fileContent = fileContent.replace(htmlOriginal, html);
}
}


// const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass);
// addKeysToRegistery(usedKeys);
// if (htmlOriginal !== obfuscatedContent) {
// fileContent = fileContent.replace(htmlOriginal, html);
// }
}
} else {
const obfuscateScriptContent = obfuscateJs(fileContent,
Expand Down Expand Up @@ -209,7 +248,16 @@ function replaceJsonKeysInFiles(
log("debug", `Obscured keys in JSX related file:`, normalizePath(filePath));
}
} else {
const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion);
//! rollback
const { obfuscatedContent, usedKeys } = obfuscateKeys(
classConversion,
fileContent,
contentIgnoreRegexes,
[".html"].includes(fileExt)
);

// const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion);

fileContent = obfuscatedContent;
addKeysToRegistery(usedKeys);
}
Expand Down

0 comments on commit ad4c46f

Please sign in to comment.