2021-10-11 21:35:40 +02:00
|
|
|
import {
|
2021-03-26 14:02:14 +01:00
|
|
|
replaceImportsFromStaticInJsCode,
|
|
|
|
replaceImportsInCssCode,
|
2021-10-11 21:35:40 +02:00
|
|
|
generateCssCodeToDefineGlobals,
|
2021-06-28 04:04:48 +02:00
|
|
|
} from "../../bin/build-keycloak-theme/replaceImportFromStatic";
|
2022-07-22 15:35:23 +02:00
|
|
|
import { assert } from "tsafe/assert";
|
|
|
|
import { same } from "evt/tools/inDepth/same";
|
|
|
|
import { assetIsSameCode } from "../tools/assertIsSameCode";
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
{
|
|
|
|
const jsCodeUntransformed = `
|
2021-02-21 17:38:59 +01:00
|
|
|
function f() {
|
2021-04-11 18:18:52 +02:00
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
2021-02-21 17:38:59 +01:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2021-02-21 17:38:59 +01:00
|
|
|
function f2() {
|
2021-04-11 18:18:52 +02:00
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
2021-02-21 17:38:59 +01:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 15:35:23 +02:00
|
|
|
`;
|
2021-04-11 18:18:52 +02:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
{
|
|
|
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
|
|
|
"jsCode": jsCodeUntransformed,
|
|
|
|
"urlOrigin": undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
|
|
|
function f() {
|
|
|
|
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
|
|
|
|
function f2() {
|
|
|
|
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const urlOrigin = "https://example.com";
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
|
|
|
"jsCode": jsCodeUntransformed,
|
|
|
|
urlOrigin,
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
|
|
|
function f() {
|
|
|
|
return ("kcContext" in window ? "${urlOrigin}" : "") + a.p + "static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
|
|
|
|
function f2() {
|
|
|
|
return ("kcContext" in window ? "${urlOrigin}" : "") + a.p + "static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
|
|
|
"cssCode": `
|
|
|
|
.my-div {
|
|
|
|
background: url(/logo192.png) no-repeat center center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.my-div2 {
|
|
|
|
background: url(/logo192.png) no-repeat center center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.my-div {
|
|
|
|
background-image: url(/static/media/something.svg);
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedCssCodeExpected = `
|
|
|
|
.my-div {
|
|
|
|
background: var(--url1f9ef5a892c104c);
|
2021-04-11 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div2 {
|
|
|
|
background: var(--url1f9ef5a892c104c);
|
2021-04-11 18:18:52 +02:00
|
|
|
}
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div {
|
|
|
|
background-image: var(--urldd75cab58377c19);
|
|
|
|
}
|
|
|
|
`;
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
const cssGlobalsToDefineExpected = {
|
|
|
|
"url1f9ef5a892c104c": "url(/logo192.png) no-repeat center center",
|
|
|
|
"urldd75cab58377c19": "url(/static/media/something.svg)",
|
|
|
|
};
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
assert(same(cssGlobalsToDefine, cssGlobalsToDefineExpected));
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
|
|
cssGlobalsToDefine,
|
|
|
|
"urlPathname": "/",
|
|
|
|
});
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
const cssCodeToPrependInHeadExpected = `
|
|
|
|
:root {
|
|
|
|
--url1f9ef5a892c104c: url(\${url.resourcesPath}/build/logo192.png) no-repeat center center;
|
|
|
|
--urldd75cab58377c19: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
|
|
}
|
|
|
|
`;
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
assetIsSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected);
|
|
|
|
}
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
console.log("PASS replace import from static");
|