Update prettier configuration
This commit is contained in:
.prettierrc.jsonpackage.jsonvitest.config.ts
scripts
build.tsdump-keycloak-realm.tsgenerate-i18n-messages.tsgrant-exec-perms.tslink-in-app.tslink-in-starter.ts
src
PUBLIC_URL.ts
account
bin
copy-keycloak-resources-to-public.tsdownload-keycloak-default-theme.tseject-page.tsinitialize-email-theme.tsmain.ts
keycloakify
buildJars
generateFtl
generateSrcMainResources
bringInAccountV1.tsgenerateMessageProperties.tsgenerateSrcMainResources.tsgenerateSrcMainResourcesForMainTheme.tsgenerateSrcMainResourcesForThemeVariant.tsreadExtraPageNames.tsreadFieldNameUsage.ts
generateStartKeycloakTestingContainer.tskeycloakify.tsreplacers
shared
KeycloakVersionRange.tsbuildOptions.tsconstants.tscopyKeycloakResourcesToPublic.tsdownloadAndUnzip.tsdownloadKeycloakDefaultTheme.tsdownloadKeycloakStaticResources.tsgetJarFileBasename.tsgetThemeSrcDirPath.tsmetaInfKeycloakThemes.tspromptKeycloakVersion.ts
start-keycloak
tools
lib
login
tools
AndByDiscriminatingKey.tsArray.prototype.every.tsLazyOrNot.tsclsx.tsdeepAssign.tsdeepClone.tsformatNumber.tsuseConstCallback.tsuseInsertLinkTags.tsuseInsertScriptTags.tsuseSetClassName.ts
vite-plugin
stories
intro
login
KcApp.tsx
pages
IdpReviewUserProfile.stories.tsxInfo.stories.tsxLogin.stories.tsxLoginConfigTotp.stories.tsxLoginDeviceVerifyUserCode.stories.tsxLoginIdpLinkConfirm.stories.tsxLoginIdpLinkEmail.stories.tsxLoginOauthGrant.stories.tsxLoginOtp.stories.tsxLoginPageExpired.stories.tsxLoginPassword.stories.tsxLoginResetPassword.stories.tsxLoginUpdatePassword.stories.tsxLoginUpdateProfile.stories.tsxLoginUsername.stories.tsxLoginVerifyEmail.stories.tsxLogoutConfirm.stories.tsxRegister.stories.tsxSamlPostForm.stories.tsxSelectAuthenticator.stories.tsxTerms.stories.tsxUpdateEmail.stories.tsxWebauthnAuthenticate.stories.tsx
test
bin
lib
tools
@ -1,4 +1,7 @@
|
||||
import { nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "../../../shared/constants";
|
||||
import {
|
||||
nameOfTheGlobal,
|
||||
basenameOfTheKeycloakifyResourcesDir
|
||||
} from "../../../shared/constants";
|
||||
import { assert } from "tsafe/assert";
|
||||
import type { BuildOptions } from "../../../shared/buildOptions";
|
||||
import * as nodePath from "path";
|
||||
@ -12,10 +15,18 @@ export type BuildOptionsLike = {
|
||||
|
||||
assert<BuildOptions extends BuildOptionsLike ? true : false>();
|
||||
|
||||
export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOptions: BuildOptionsLike; systemType?: "posix" | "win32" }): {
|
||||
export function replaceImportsInJsCode_webpack(params: {
|
||||
jsCode: string;
|
||||
buildOptions: BuildOptionsLike;
|
||||
systemType?: "posix" | "win32";
|
||||
}): {
|
||||
fixedJsCode: string;
|
||||
} {
|
||||
const { jsCode, buildOptions, systemType = nodePath.sep === "/" ? "posix" : "win32" } = params;
|
||||
const {
|
||||
jsCode,
|
||||
buildOptions,
|
||||
systemType = nodePath.sep === "/" ? "posix" : "win32"
|
||||
} = params;
|
||||
|
||||
const { relative: pathRelative, sep: pathSep } = nodePath[systemType];
|
||||
|
||||
@ -24,29 +35,51 @@ export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOp
|
||||
if (buildOptions.urlPathname !== undefined) {
|
||||
// "__esModule",{value:!0})},n.p="/foo-bar/",function(){if("undefined" -> ... n.p="/" ...
|
||||
fixedJsCode = fixedJsCode.replace(
|
||||
new RegExp(`,([a-zA-Z]\\.[a-zA-Z])="${replaceAll(buildOptions.urlPathname, "/", "\\/")}",`, "g"),
|
||||
new RegExp(
|
||||
`,([a-zA-Z]\\.[a-zA-Z])="${replaceAll(
|
||||
buildOptions.urlPathname,
|
||||
"/",
|
||||
"\\/"
|
||||
)}",`,
|
||||
"g"
|
||||
),
|
||||
(...[, assignTo]) => `,${assignTo}="/",`
|
||||
);
|
||||
}
|
||||
|
||||
// Example: "static/ or "foo/bar/"
|
||||
const staticDir = (() => {
|
||||
let out = pathRelative(buildOptions.reactAppBuildDirPath, buildOptions.assetsDirPath);
|
||||
let out = pathRelative(
|
||||
buildOptions.reactAppBuildDirPath,
|
||||
buildOptions.assetsDirPath
|
||||
);
|
||||
|
||||
out = replaceAll(out, pathSep, "/") + "/";
|
||||
|
||||
if (out === "/") {
|
||||
throw new Error(`The assetsDirPath must be a subdirectory of reactAppBuildDirPath`);
|
||||
throw new Error(
|
||||
`The assetsDirPath must be a subdirectory of reactAppBuildDirPath`
|
||||
);
|
||||
}
|
||||
|
||||
return out;
|
||||
})();
|
||||
|
||||
const getReplaceArgs = (language: "js" | "css"): Parameters<typeof String.prototype.replace> => [
|
||||
new RegExp(`([a-zA-Z_]+)\\.([a-zA-Z]+)=(function\\(([a-z]+)\\){return|([a-z]+)=>)"${staticDir.replace(/\//g, "\\/")}${language}\\/"`, "g"),
|
||||
const getReplaceArgs = (
|
||||
language: "js" | "css"
|
||||
): Parameters<typeof String.prototype.replace> => [
|
||||
new RegExp(
|
||||
`([a-zA-Z_]+)\\.([a-zA-Z]+)=(function\\(([a-z]+)\\){return|([a-z]+)=>)"${staticDir.replace(
|
||||
/\//g,
|
||||
"\\/"
|
||||
)}${language}\\/"`,
|
||||
"g"
|
||||
),
|
||||
(...[, n, u, matchedFunction, eForFunction]) => {
|
||||
const isArrowFunction = matchedFunction.includes("=>");
|
||||
const e = isArrowFunction ? matchedFunction.replace("=>", "").trim() : eForFunction;
|
||||
const e = isArrowFunction
|
||||
? matchedFunction.replace("=>", "").trim()
|
||||
: eForFunction;
|
||||
|
||||
return `
|
||||
${n}[(function(){
|
||||
@ -58,7 +91,9 @@ export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOp
|
||||
});
|
||||
}
|
||||
return "${u}";
|
||||
})()] = ${isArrowFunction ? `${e} =>` : `function(${e}) { return `} "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}${language}/"`
|
||||
})()] = ${
|
||||
isArrowFunction ? `${e} =>` : `function(${e}) { return `
|
||||
} "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}${language}/"`
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
@ -68,7 +103,10 @@ export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOp
|
||||
.replace(...getReplaceArgs("js"))
|
||||
.replace(...getReplaceArgs("css"))
|
||||
.replace(
|
||||
new RegExp(`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`, "g"),
|
||||
new RegExp(
|
||||
`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`,
|
||||
"g"
|
||||
),
|
||||
`window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}`
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user