2024-01-30 00:06:17 +01:00
|
|
|
import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/vite";
|
2024-01-30 00:15:08 +01:00
|
|
|
import { replaceImportsInJsCode_webpack } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/webpack";
|
2024-06-19 01:41:22 +02:00
|
|
|
import { replaceImportsInCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
2023-03-30 02:46:25 -06:00
|
|
|
import { expect, it, describe } from "vitest";
|
2024-06-14 22:24:51 +02:00
|
|
|
import { basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/shared/constants";
|
2024-01-30 00:06:17 +01:00
|
|
|
|
2024-01-30 00:10:59 +01:00
|
|
|
describe("js replacer - vite", () => {
|
2024-01-30 00:06:17 +01:00
|
|
|
it("replaceImportsInJsCode_vite - 1", () => {
|
|
|
|
const before = `Uv="modulepreload",`;
|
|
|
|
const after = `,Wc={},`;
|
|
|
|
const jsCodeUntransformed = `${before}Hv=function(e){return"/foo-bar-baz/"+e}${after}`;
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
|
|
|
basenameOfAssetsFiles: [],
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/dist/",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets/",
|
|
|
|
urlPathname: "/foo-bar-baz/"
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
const fixedJsCodeExpected = `${before}Hv=function(e){return"/"+e}${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 2", () => {
|
|
|
|
const before = `Uv="modulepreload",`;
|
|
|
|
const after = `,Wc={},`;
|
|
|
|
const jsCodeUntransformed = `${before}Hv=function(e){return"/foo/bar/baz/"+e}${after}`;
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
|
|
|
basenameOfAssetsFiles: [],
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/dist/",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets/",
|
|
|
|
urlPathname: "/foo/bar/baz/"
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `${before}Hv=function(e){return"/"+e}${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 3", () => {
|
2024-01-27 18:49:29 +01:00
|
|
|
const jsCodeUntransformed = `
|
2024-01-30 00:06:17 +01:00
|
|
|
S="/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
|
|
|
|
2024-01-27 18:49:29 +01:00
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
2024-01-30 00:06:17 +01:00
|
|
|
|
2024-06-09 09:36:16 +02:00
|
|
|
for (const { projectBuildDirPath, assetsDirPath, systemType } of [
|
2024-01-30 00:06:17 +01:00
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "posix",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets"
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "win32",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath:
|
2024-05-20 15:48:51 +02:00
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
|
|
|
assetsDirPath:
|
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
] as const) {
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
|
|
|
basenameOfAssetsFiles: [
|
|
|
|
"Login-dJpPRzM4.js",
|
|
|
|
"index-XwzrZ5Gu.js",
|
|
|
|
"keycloakify-logo-mqjydaoZ.png"
|
|
|
|
],
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath,
|
2024-01-30 00:06:17 +01:00
|
|
|
assetsDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
urlPathname: undefined
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
systemType
|
2024-01-27 18:49:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
2024-06-14 22:24:51 +02:00
|
|
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
2024-01-30 00:06:17 +01:00
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = [
|
2024-06-14 22:24:51 +02:00
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
2024-01-30 00:06:17 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
2024-01-27 18:49:29 +01:00
|
|
|
}
|
2024-01-30 00:06:17 +01:00
|
|
|
`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 4", () => {
|
|
|
|
const jsCodeUntransformed = `
|
2024-02-06 07:28:03 +01:00
|
|
|
S="/foo/bar/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
2024-01-30 00:06:17 +01:00
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
2024-02-06 07:28:03 +01:00
|
|
|
__vite__mapDeps.viteFileDeps = ["foo/bar/Login-dJpPRzM4.js", "foo/bar/index-XwzrZ5Gu.js"]
|
2024-01-27 18:49:29 +01:00
|
|
|
}
|
2024-01-30 00:06:17 +01:00
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2024-06-09 09:36:16 +02:00
|
|
|
for (const { projectBuildDirPath, assetsDirPath, systemType } of [
|
2024-01-30 00:06:17 +01:00
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "posix",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/foo/bar"
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "win32",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath:
|
2024-05-20 15:48:51 +02:00
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
|
|
|
assetsDirPath:
|
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\foo\\bar"
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
] as const) {
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
|
|
|
basenameOfAssetsFiles: [
|
|
|
|
"Login-dJpPRzM4.js",
|
|
|
|
"index-XwzrZ5Gu.js",
|
|
|
|
"keycloakify-logo-mqjydaoZ.png"
|
|
|
|
],
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath,
|
2024-01-30 00:06:17 +01:00
|
|
|
assetsDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
urlPathname: undefined
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
systemType
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
2024-06-14 22:24:51 +02:00
|
|
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
2024-01-30 00:06:17 +01:00
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = [
|
2024-06-14 22:24:51 +02:00
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"),
|
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js")
|
2024-01-30 00:06:17 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
2024-01-27 18:49:29 +01:00
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
});
|
2024-01-27 18:49:29 +01:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
it("replaceImportsInJsCode_vite - 5", () => {
|
2024-01-27 18:49:29 +01:00
|
|
|
const jsCodeUntransformed = `
|
2024-01-30 00:06:17 +01:00
|
|
|
S="/foo-bar-baz/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2024-06-09 09:36:16 +02:00
|
|
|
for (const { projectBuildDirPath, assetsDirPath, systemType } of [
|
2024-01-30 00:06:17 +01:00
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "posix",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets"
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
{
|
2024-05-20 15:48:51 +02:00
|
|
|
systemType: "win32",
|
2024-06-09 09:36:16 +02:00
|
|
|
projectBuildDirPath:
|
2024-05-20 15:48:51 +02:00
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
|
|
|
assetsDirPath:
|
|
|
|
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
] as const) {
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
|
|
|
basenameOfAssetsFiles: [
|
|
|
|
"Login-dJpPRzM4.js",
|
|
|
|
"index-XwzrZ5Gu.js",
|
|
|
|
"keycloakify-logo-mqjydaoZ.png"
|
|
|
|
],
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath,
|
2024-01-30 00:06:17 +01:00
|
|
|
assetsDirPath,
|
2024-05-20 15:48:51 +02:00
|
|
|
urlPathname: "/foo-bar-baz/"
|
2024-01-30 00:06:17 +01:00
|
|
|
},
|
|
|
|
systemType
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
2024-06-14 22:24:51 +02:00
|
|
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
2024-01-30 00:06:17 +01:00
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = [
|
2024-06-14 22:24:51 +02:00
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
|
|
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
2024-01-30 00:06:17 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-01-30 00:10:59 +01:00
|
|
|
describe("js replacer - webpack", () => {
|
2024-01-30 00:15:08 +01:00
|
|
|
it("replaceImportsInJsCode_webpack - 1", () => {
|
|
|
|
const jsCodeUntransformed = `
|
|
|
|
function f() {
|
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2024-01-30 00:15:08 +01:00
|
|
|
function sameAsF() {
|
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 18:20:50 +02:00
|
|
|
|
2024-01-30 00:15:08 +01:00
|
|
|
__webpack_require__.u=function(e){return"static/js/" + e + "." + {
|
|
|
|
147: "6c5cee76",
|
|
|
|
787: "8da10fcf",
|
|
|
|
922: "be170a73"
|
|
|
|
} [e] + ".chunk.js"
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
|
2024-01-30 00:15:08 +01:00
|
|
|
t.miniCssF=function(e){return"static/css/"+e+"."+{
|
|
|
|
164:"dcfd7749",
|
|
|
|
908:"67c9ed2c"
|
|
|
|
}[e]+".chunk.css"
|
|
|
|
}
|
2023-09-24 23:42:10 +02:00
|
|
|
|
2024-01-30 00:15:08 +01:00
|
|
|
n.u=e=>"static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
2023-09-24 23:42:10 +02:00
|
|
|
|
2024-01-30 00:15:08 +01:00
|
|
|
t.miniCssF=e=>"static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
|
|
|
`;
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/build/static",
|
|
|
|
urlPathname: undefined
|
2024-01-30 00:15:08 +01:00
|
|
|
}
|
2024-01-30 00:06:17 +01:00
|
|
|
});
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
const fixedJsCodeExpected = `
|
2022-07-22 15:35:23 +02:00
|
|
|
function f() {
|
2024-06-16 17:55:06 +02:00
|
|
|
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
|
2022-07-22 15:35:23 +02:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
|
2022-07-28 04:24:10 +02:00
|
|
|
function sameAsF() {
|
2024-06-16 17:55:06 +02:00
|
|
|
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
|
2022-07-22 15:35:23 +02:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 18:20:50 +02:00
|
|
|
|
2022-09-05 00:08:50 +02:00
|
|
|
__webpack_require__[(function (){
|
2023-09-24 23:42:10 +02:00
|
|
|
var pd = Object.getOwnPropertyDescriptor(__webpack_require__, "p");
|
2022-09-01 17:22:15 +02:00
|
|
|
if( pd === undefined || pd.configurable ){
|
2022-09-05 00:08:50 +02:00
|
|
|
Object.defineProperty(__webpack_require__, "p", {
|
2022-09-01 17:22:15 +02:00
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
2023-09-24 23:42:10 +02:00
|
|
|
set: function() {}
|
2022-09-01 17:22:15 +02:00
|
|
|
});
|
|
|
|
}
|
2022-07-28 04:24:10 +02:00
|
|
|
return "u";
|
|
|
|
})()] = function(e) {
|
2024-06-16 17:55:06 +02:00
|
|
|
return "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + e + "." + {
|
2022-07-22 18:20:50 +02:00
|
|
|
147: "6c5cee76",
|
|
|
|
787: "8da10fcf",
|
|
|
|
922: "be170a73"
|
|
|
|
} [e] + ".chunk.js"
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
|
|
|
|
t[(function (){
|
2023-09-24 23:42:10 +02:00
|
|
|
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
2022-09-01 17:22:15 +02:00
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(t, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
2023-09-24 23:42:10 +02:00
|
|
|
set: function() {}
|
2022-09-01 17:22:15 +02:00
|
|
|
});
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
return "miniCssF";
|
|
|
|
})()] = function(e) {
|
2024-06-16 17:55:06 +02:00
|
|
|
return "/${basenameOfTheKeycloakifyResourcesDir}/static/css/" + e + "." + {
|
2022-08-02 21:00:52 +02:00
|
|
|
164:"dcfd7749",
|
|
|
|
908:"67c9ed2c"
|
|
|
|
} [e] + ".chunk.css"
|
|
|
|
}
|
2023-09-24 23:42:10 +02:00
|
|
|
|
|
|
|
n[(function(){
|
|
|
|
var pd = Object.getOwnPropertyDescriptor(n, "p");
|
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(n, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
|
|
|
set: function() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return "u";
|
2024-06-16 17:55:06 +02:00
|
|
|
})()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
2023-09-24 23:42:10 +02:00
|
|
|
|
|
|
|
t[(function(){
|
|
|
|
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(t, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
|
|
|
set: function() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return "miniCssF";
|
2024-06-16 17:55:06 +02:00
|
|
|
})()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
2022-07-22 15:35:23 +02:00
|
|
|
`;
|
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
2024-01-30 00:37:30 +01:00
|
|
|
|
|
|
|
it("replaceImportsInJsCode_webpack - 2", () => {
|
|
|
|
const before = `"__esModule",{value:!0})}`;
|
|
|
|
const after = `function(){if("undefined"`;
|
|
|
|
|
|
|
|
const jsCodeUntransformed = `${before},n.p="/foo-bar/",${after}`;
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath: "/Users/someone/github/keycloakify-starter/build/static",
|
|
|
|
urlPathname: "/foo-bar/"
|
2024-01-30 00:37:30 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `${before},n.p="/",${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_webpack - 3", () => {
|
|
|
|
const before = `"__esModule",{value:!0})}`;
|
|
|
|
const after = `function(){if("undefined"`;
|
|
|
|
|
|
|
|
const jsCodeUntransformed = `${before},n.p="/foo/bar/",${after}`;
|
|
|
|
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
2024-05-20 15:48:51 +02:00
|
|
|
jsCode: jsCodeUntransformed,
|
2024-06-09 09:36:16 +02:00
|
|
|
buildContext: {
|
|
|
|
projectBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
2024-05-20 15:48:51 +02:00
|
|
|
assetsDirPath:
|
|
|
|
"/Users/someone/github/keycloakify-starter/dist/build/static",
|
|
|
|
urlPathname: "/foo/bar/"
|
2024-01-30 00:37:30 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `${before},n.p="/",${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
|
|
|
|
2024-01-30 00:10:59 +01:00
|
|
|
describe("css replacer", () => {
|
2024-06-19 01:41:22 +02:00
|
|
|
it("replaceImportsInCssCode - 1", () => {
|
|
|
|
const { fixedCssCode } = replaceImportsInCssCode({
|
2024-05-20 15:48:51 +02:00
|
|
|
cssCode: `
|
2023-03-30 02:46:25 -06:00
|
|
|
.my-div {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(/background.png) no-repeat center center;
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
.my-div2 {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(/assets/background.png) repeat center center;
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
|
|
|
|
2024-06-19 01:41:22 +02:00
|
|
|
.my-div3 {
|
|
|
|
background-image: url(/assets/media/something.svg);
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
2024-06-19 01:41:22 +02:00
|
|
|
`,
|
|
|
|
fileRelativeDirPath: "assets/",
|
|
|
|
buildContext: {
|
|
|
|
urlPathname: undefined
|
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const fixedCssCodeExpected = `
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(../background.png) no-repeat center center;
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div2 {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(background.png) repeat center center;
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2024-06-19 01:41:22 +02:00
|
|
|
.my-div3 {
|
|
|
|
background-image: url(media/something.svg);
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
`;
|
2021-04-11 18:18:52 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
2022-07-22 15:35:23 +02:00
|
|
|
});
|
2024-06-19 01:41:22 +02:00
|
|
|
|
|
|
|
it("replaceImportsInCssCode - 2", () => {
|
|
|
|
const { fixedCssCode } = replaceImportsInCssCode({
|
2024-05-20 15:48:51 +02:00
|
|
|
cssCode: `
|
2023-03-30 02:46:25 -06:00
|
|
|
.my-div {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(/a/b/background.png) no-repeat center center;
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
.my-div2 {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(/a/b/assets/background.png) repeat center center;
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
|
|
|
|
2024-06-19 01:41:22 +02:00
|
|
|
.my-div3 {
|
|
|
|
background-image: url(/a/b/assets/media/something.svg);
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
2024-06-19 01:41:22 +02:00
|
|
|
`,
|
|
|
|
fileRelativeDirPath: "assets/",
|
|
|
|
buildContext: {
|
|
|
|
urlPathname: "/a/b/"
|
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const fixedCssCodeExpected = `
|
2022-07-22 17:22:23 +02:00
|
|
|
.my-div {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(../background.png) no-repeat center center;
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 17:22:23 +02:00
|
|
|
.my-div2 {
|
2024-06-19 01:41:22 +02:00
|
|
|
background: url(background.png) repeat center center;
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2024-06-19 01:41:22 +02:00
|
|
|
.my-div3 {
|
|
|
|
background-image: url(media/something.svg);
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
`;
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2024-06-03 18:28:34 +02:00
|
|
|
|
|
|
|
export function isSameCode(code1: string, code2: string): boolean {
|
|
|
|
const removeSpacesAndNewLines = (code: string) =>
|
|
|
|
code.replace(/\s/g, "").replace(/\n/g, "");
|
|
|
|
|
|
|
|
return removeSpacesAndNewLines(code1) === removeSpacesAndNewLines(code2);
|
|
|
|
}
|