keycloakify 9.4.0-rc.1 → 9.4.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/PUBLIC_URL.d.ts +5 -0
  2. package/PUBLIC_URL.js +15 -0
  3. package/PUBLIC_URL.js.map +1 -0
  4. package/account/kcContext/createGetKcContext.js +7 -4
  5. package/account/kcContext/createGetKcContext.js.map +1 -1
  6. package/account/kcContext/kcContextMocks.js +3 -5
  7. package/account/kcContext/kcContextMocks.js.map +1 -1
  8. package/bin/constants.d.ts +1 -1
  9. package/bin/constants.js +1 -1
  10. package/bin/constants.js.map +1 -1
  11. package/bin/copy-keycloak-resources-to-public.d.ts +12 -1
  12. package/bin/copy-keycloak-resources-to-public.js +133 -70
  13. package/bin/copy-keycloak-resources-to-public.js.map +1 -1
  14. package/bin/download-builtin-keycloak-theme.d.ts +1 -0
  15. package/bin/download-builtin-keycloak-theme.js +37 -27
  16. package/bin/download-builtin-keycloak-theme.js.map +1 -1
  17. package/bin/{tools/downloadAndUnzip.d.ts → downloadAndUnzip.d.ts} +6 -6
  18. package/bin/downloadAndUnzip.js +255 -0
  19. package/bin/downloadAndUnzip.js.map +1 -0
  20. package/bin/eject-keycloak-page.js +6 -3
  21. package/bin/eject-keycloak-page.js.map +1 -1
  22. package/bin/initialize-email-theme.js +2 -4
  23. package/bin/initialize-email-theme.js.map +1 -1
  24. package/bin/keycloakify/buildOptions/buildOptions.d.ts +1 -1
  25. package/bin/keycloakify/buildOptions/buildOptions.js +56 -32
  26. package/bin/keycloakify/buildOptions/buildOptions.js.map +1 -1
  27. package/bin/keycloakify/buildOptions/getCacheDirPath.d.ts +5 -0
  28. package/bin/keycloakify/buildOptions/getCacheDirPath.js +22 -0
  29. package/bin/keycloakify/buildOptions/getCacheDirPath.js.map +1 -0
  30. package/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.d.ts +5 -0
  31. package/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.js +86 -0
  32. package/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.js.map +1 -0
  33. package/bin/keycloakify/buildOptions/getReactAppRootDirPath.d.ts +5 -0
  34. package/bin/keycloakify/buildOptions/getReactAppRootDirPath.js +26 -0
  35. package/bin/keycloakify/buildOptions/getReactAppRootDirPath.js.map +1 -0
  36. package/bin/keycloakify/buildOptions/resolvedViteConfig.d.ts +3 -4
  37. package/bin/keycloakify/buildOptions/resolvedViteConfig.js +4 -11
  38. package/bin/keycloakify/buildOptions/resolvedViteConfig.js.map +1 -1
  39. package/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +8 -0
  40. package/bin/keycloakify/generateFtl/generateFtl.js +2 -1
  41. package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
  42. package/bin/keycloakify/generateStartKeycloakTestingContainer.js +0 -1
  43. package/bin/keycloakify/generateStartKeycloakTestingContainer.js.map +1 -1
  44. package/bin/keycloakify/generateTheme/bringInAccountV1.d.ts +1 -0
  45. package/bin/keycloakify/generateTheme/bringInAccountV1.js.map +1 -1
  46. package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.d.ts +1 -0
  47. package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.js.map +1 -1
  48. package/bin/keycloakify/generateTheme/generateTheme.d.ts +1 -0
  49. package/bin/keycloakify/generateTheme/generateTheme.js.map +1 -1
  50. package/bin/keycloakify/keycloakify.js +11 -16
  51. package/bin/keycloakify/keycloakify.js.map +1 -1
  52. package/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.js +0 -5
  53. package/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.js.map +1 -1
  54. package/bin/tools/fetchProxyOptions.d.ts +5 -0
  55. package/bin/tools/fetchProxyOptions.js +172 -0
  56. package/bin/tools/fetchProxyOptions.js.map +1 -0
  57. package/bin/tools/fs.existsAsync.d.ts +1 -0
  58. package/bin/tools/fs.existsAsync.js +86 -0
  59. package/bin/tools/fs.existsAsync.js.map +1 -0
  60. package/bin/tools/getThisCodebaseRootDirPath.d.ts +1 -0
  61. package/bin/tools/{getProjectRoot.js → getThisCodebaseRootDirPath.js} +7 -7
  62. package/bin/tools/getThisCodebaseRootDirPath.js.map +1 -0
  63. package/bin/tools/grant-exec-perms.js +6 -4
  64. package/bin/tools/grant-exec-perms.js.map +1 -1
  65. package/bin/tools/readThisNpmProjectVersion.d.ts +1 -0
  66. package/bin/tools/readThisNpmProjectVersion.js +37 -0
  67. package/bin/tools/readThisNpmProjectVersion.js.map +1 -0
  68. package/bin/tools/transformCodebase.js +5 -5
  69. package/bin/tools/transformCodebase.js.map +1 -1
  70. package/lib/BASE_URL.d.ts +10 -0
  71. package/lib/BASE_URL.js +38 -0
  72. package/lib/BASE_URL.js.map +1 -0
  73. package/lib/isStorybook.d.ts +1 -0
  74. package/lib/isStorybook.js +3 -0
  75. package/lib/isStorybook.js.map +1 -0
  76. package/lib/keycloakJsAdapter.d.ts +4 -0
  77. package/lib/keycloakJsAdapter.js +4 -0
  78. package/lib/keycloakJsAdapter.js.map +1 -1
  79. package/login/kcContext/createGetKcContext.js +7 -4
  80. package/login/kcContext/createGetKcContext.js.map +1 -1
  81. package/login/kcContext/kcContextMocks.js +3 -5
  82. package/login/kcContext/kcContextMocks.js.map +1 -1
  83. package/package.json +56 -23
  84. package/src/PUBLIC_URL.ts +21 -0
  85. package/src/account/kcContext/createGetKcContext.ts +8 -5
  86. package/src/account/kcContext/kcContextMocks.ts +3 -5
  87. package/src/bin/constants.ts +1 -1
  88. package/src/bin/copy-keycloak-resources-to-public.ts +73 -12
  89. package/src/bin/download-builtin-keycloak-theme.ts +40 -27
  90. package/src/bin/downloadAndUnzip.ts +203 -0
  91. package/src/bin/eject-keycloak-page.ts +6 -3
  92. package/src/bin/initialize-email-theme.ts +1 -4
  93. package/src/bin/keycloakify/buildOptions/buildOptions.ts +35 -35
  94. package/src/bin/keycloakify/buildOptions/getCacheDirPath.ts +25 -0
  95. package/src/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.ts +49 -0
  96. package/src/bin/keycloakify/buildOptions/getReactAppRootDirPath.ts +23 -0
  97. package/src/bin/keycloakify/buildOptions/resolvedViteConfig.ts +7 -21
  98. package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +8 -0
  99. package/src/bin/keycloakify/generateFtl/generateFtl.ts +3 -2
  100. package/src/bin/keycloakify/generateStartKeycloakTestingContainer.ts +0 -1
  101. package/src/bin/keycloakify/generateTheme/bringInAccountV1.ts +1 -0
  102. package/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts +1 -0
  103. package/src/bin/keycloakify/generateTheme/generateTheme.ts +1 -0
  104. package/src/bin/keycloakify/keycloakify.ts +13 -19
  105. package/src/bin/keycloakify/replacers/replaceImportsInJsCode/webpack.ts +0 -14
  106. package/src/bin/tools/fetchProxyOptions.ts +73 -0
  107. package/src/bin/tools/fs.existsAsync.ts +11 -0
  108. package/src/bin/tools/{getProjectRoot.ts → getThisCodebaseRootDirPath.ts} +4 -4
  109. package/src/bin/tools/grant-exec-perms.ts +5 -3
  110. package/src/bin/tools/readThisNpmProjectVersion.ts +12 -0
  111. package/src/bin/tools/transformCodebase.ts +6 -5
  112. package/src/lib/BASE_URL.ts +44 -0
  113. package/src/lib/isStorybook.ts +3 -0
  114. package/src/lib/keycloakJsAdapter.ts +4 -0
  115. package/src/login/kcContext/createGetKcContext.ts +8 -5
  116. package/src/login/kcContext/kcContextMocks.ts +3 -5
  117. package/src/vite-plugin/vite-plugin.ts +12 -11
  118. package/vite-plugin/tsconfig.tsbuildinfo +1 -1
  119. package/vite-plugin/vite-plugin.js +11 -11
  120. package/vite-plugin/vite-plugin.js.map +1 -1
  121. package/bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath.d.ts +0 -7
  122. package/bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath.js +0 -27
  123. package/bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath.js.map +0 -1
  124. package/bin/tools/downloadAndUnzip.js +0 -445
  125. package/bin/tools/downloadAndUnzip.js.map +0 -1
  126. package/bin/tools/getProjectRoot.d.ts +0 -1
  127. package/bin/tools/getProjectRoot.js.map +0 -1
  128. package/bin/tools/pathJoin.d.ts +0 -1
  129. package/bin/tools/pathJoin.js +0 -15
  130. package/bin/tools/pathJoin.js.map +0 -1
  131. package/src/bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath.ts +0 -33
  132. package/src/bin/tools/downloadAndUnzip.ts +0 -301
  133. package/src/bin/tools/pathJoin.ts +0 -6
  134. package/src/vite-plugin/config.json +0 -232
@@ -29,20 +29,6 @@ export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOp
29
29
  );
30
30
  }
31
31
 
32
- // d={NODE_ENV:"production",PUBLIC_URL:"/foo-bar",WDS_SOCKET_HOST
33
- // d={NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST
34
- // ->
35
- // ... PUBLIC_URL:window.kcContext.url.resourcesPath+"/build" ...
36
- fixedJsCode = fixedJsCode.replace(
37
- new RegExp(
38
- `NODE_ENV:"production",PUBLIC_URL:"${
39
- buildOptions.urlPathname !== undefined ? replaceAll(buildOptions.urlPathname.slice(0, -1), "/", "\\/") : ""
40
- }"`,
41
- "g"
42
- ),
43
- `NODE_ENV:"production",PUBLIC_URL:window.${nameOfTheGlobal}.url.resourcesPath+"/${basenameOfTheKeycloakifyResourcesDir}"`
44
- );
45
-
46
32
  // Example: "static/ or "foo/bar/"
47
33
  const staticDir = (() => {
48
34
  let out = pathRelative(buildOptions.reactAppBuildDirPath, buildOptions.assetsDirPath);
@@ -0,0 +1,73 @@
1
+ import { exec as execCallback } from "child_process";
2
+ import { readFile } from "fs/promises";
3
+ import { type FetchOptions } from "make-fetch-happen";
4
+ import { promisify } from "util";
5
+
6
+ function ensureArray<T>(arg0: T | T[]) {
7
+ return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
8
+ }
9
+
10
+ function ensureSingleOrNone<T>(arg0: T | T[]) {
11
+ if (!Array.isArray(arg0)) return arg0;
12
+ if (arg0.length === 0) return undefined;
13
+ if (arg0.length === 1) return arg0[0];
14
+ throw new Error("Illegal configuration, expected a single value but found multiple: " + arg0.map(String).join(", "));
15
+ }
16
+
17
+ type NPMConfig = Record<string, string | string[]>;
18
+
19
+ /**
20
+ * Get npm configuration as map
21
+ */
22
+ async function getNmpConfig(params: { npmWorkspaceRootDirPath: string }) {
23
+ const { npmWorkspaceRootDirPath } = params;
24
+
25
+ const exec = promisify(execCallback);
26
+
27
+ const stdout = await exec("npm config get", { "encoding": "utf8", "cwd": npmWorkspaceRootDirPath }).then(({ stdout }) => stdout);
28
+
29
+ const npmConfigReducer = (cfg: NPMConfig, [key, value]: [string, string]) =>
30
+ key in cfg ? { ...cfg, [key]: [...ensureArray(cfg[key]), value] } : { ...cfg, [key]: value };
31
+
32
+ return stdout
33
+ .split("\n")
34
+ .filter(line => !line.startsWith(";"))
35
+ .map(line => line.trim())
36
+ .map(line => line.split("=", 2) as [string, string])
37
+ .reduce(npmConfigReducer, {} as NPMConfig);
38
+ }
39
+
40
+ export type ProxyFetchOptions = Pick<FetchOptions, "proxy" | "noProxy" | "strictSSL" | "cert" | "ca">;
41
+
42
+ export async function getProxyFetchOptions(params: { npmWorkspaceRootDirPath: string }): Promise<ProxyFetchOptions> {
43
+ const { npmWorkspaceRootDirPath } = params;
44
+
45
+ const cfg = await getNmpConfig({ npmWorkspaceRootDirPath });
46
+
47
+ const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
48
+ const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
49
+
50
+ function maybeBoolean(arg0: string | undefined) {
51
+ return typeof arg0 === "undefined" ? undefined : Boolean(arg0);
52
+ }
53
+
54
+ const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"]));
55
+ const cert = cfg["cert"];
56
+ const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]);
57
+ const cafile = ensureSingleOrNone(cfg["cafile"]);
58
+
59
+ if (typeof cafile !== "undefined" && cafile !== "null") {
60
+ ca.push(
61
+ ...(await (async () => {
62
+ function chunks<T>(arr: T[], size: number = 2) {
63
+ return arr.map((_, i) => i % size == 0 && arr.slice(i, i + size)).filter(Boolean) as T[][];
64
+ }
65
+
66
+ const cafileContent = await readFile(cafile, "utf-8");
67
+ return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(ca => ca.join("").replace(/^\n/, "").replace(/\n/g, "\\n"));
68
+ })())
69
+ );
70
+ }
71
+
72
+ return { proxy, noProxy, strictSSL, cert, "ca": ca.length === 0 ? undefined : ca };
73
+ }
@@ -0,0 +1,11 @@
1
+ import * as fs from "fs/promises";
2
+
3
+ export async function existsAsync(path: string) {
4
+ try {
5
+ await fs.stat(path);
6
+ return true;
7
+ } catch (error) {
8
+ if ((error as Error & { code: string }).code === "ENOENT") return false;
9
+ throw error;
10
+ }
11
+ }
@@ -1,19 +1,19 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
3
 
4
- function getProjectRootRec(dirPath: string): string {
4
+ function getThisCodebaseRootDirPath_rec(dirPath: string): string {
5
5
  if (fs.existsSync(path.join(dirPath, "package.json"))) {
6
6
  return dirPath;
7
7
  }
8
- return getProjectRootRec(path.join(dirPath, ".."));
8
+ return getThisCodebaseRootDirPath_rec(path.join(dirPath, ".."));
9
9
  }
10
10
 
11
11
  let result: string | undefined = undefined;
12
12
 
13
- export function getProjectRoot(): string {
13
+ export function getThisCodebaseRootDirPath(): string {
14
14
  if (result !== undefined) {
15
15
  return result;
16
16
  }
17
17
 
18
- return (result = getProjectRootRec(__dirname));
18
+ return (result = getThisCodebaseRootDirPath_rec(__dirname));
19
19
  }
@@ -1,13 +1,15 @@
1
- import { getProjectRoot } from "./getProjectRoot";
1
+ import { getThisCodebaseRootDirPath } from "./getThisCodebaseRootDirPath";
2
2
  import { join as pathJoin } from "path";
3
3
  import { constants } from "fs";
4
4
  import { chmod, stat } from "fs/promises";
5
5
 
6
6
  (async () => {
7
- const { bin } = await import(pathJoin(getProjectRoot(), "package.json"));
7
+ const thisCodebaseRootDirPath = getThisCodebaseRootDirPath();
8
+
9
+ const { bin } = await import(pathJoin(thisCodebaseRootDirPath, "package.json"));
8
10
 
9
11
  const promises = Object.values<string>(bin).map(async scriptPath => {
10
- const fullPath = pathJoin(getProjectRoot(), scriptPath);
12
+ const fullPath = pathJoin(thisCodebaseRootDirPath, scriptPath);
11
13
  const oldMode = (await stat(fullPath)).mode;
12
14
  const newMode = oldMode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
13
15
  await chmod(fullPath, newMode);
@@ -0,0 +1,12 @@
1
+ import { getThisCodebaseRootDirPath } from "./getThisCodebaseRootDirPath";
2
+ import { assert } from "tsafe/assert";
3
+ import * as fs from "fs";
4
+ import { join as pathJoin } from "path";
5
+
6
+ export function readThisNpmProjectVersion(): string {
7
+ const version = JSON.parse(fs.readFileSync(pathJoin(getThisCodebaseRootDirPath(), "package.json")).toString("utf8"))["version"];
8
+
9
+ assert(typeof version === "string");
10
+
11
+ return version;
12
+ }
@@ -17,13 +17,14 @@ type TransformSourceCode = (params: { sourceCode: Buffer; filePath: string; file
17
17
  * */
18
18
  export function transformCodebase(params: { srcDirPath: string; destDirPath: string; transformSourceCode?: TransformSourceCode }) {
19
19
  const { srcDirPath, transformSourceCode } = params;
20
- let { destDirPath } = params;
21
20
 
22
- const isTargetSameAsSource = path.relative(srcDirPath, destDirPath) === "";
21
+ const isTargetSameAsSource = path.relative(srcDirPath, params.destDirPath) === "";
23
22
 
24
- if (isTargetSameAsSource) {
25
- destDirPath = path.join(srcDirPath, "..", "tmp_xOsPdkPsTdzPs34sOkHs");
26
- }
23
+ const destDirPath = isTargetSameAsSource ? path.join(srcDirPath, "..", "tmp_xOsPdkPsTdzPs34sOkHs") : params.destDirPath;
24
+
25
+ fs.mkdirSync(destDirPath, {
26
+ "recursive": true
27
+ });
27
28
 
28
29
  for (const fileRelativePath of crawl({ "dirPath": srcDirPath, "returnedPathsType": "relative to dirPath" })) {
29
30
  const filePath = path.join(srcDirPath, fileRelativePath);
@@ -0,0 +1,44 @@
1
+ import { assert } from "tsafe/assert";
2
+
3
+ /**
4
+ * WARNING: Internal use only!!
5
+ * THIS DOES NOT WORK IN KEYCLOAK! It's only for resolving mock assets.
6
+ * This is just a way to know what's the base url that works
7
+ * both in webpack and vite.
8
+ * You can see this as a polyfill that return `import.meta.env.BASE_URL` when in Vite
9
+ * and when in Webpack returns the base url in the same format as vite does meaning
10
+ * "/" if hosted at root or "/foo/" when hosted under a subpath (always start and ends with a "/").
11
+ */
12
+ export const BASE_URL = (() => {
13
+ vite: {
14
+ let BASE_URL: string;
15
+
16
+ try {
17
+ // @ts-expect-error
18
+ BASE_URL = import.meta.env.BASE_URL;
19
+
20
+ assert(typeof BASE_URL === "string");
21
+ } catch {
22
+ break vite;
23
+ }
24
+
25
+ return BASE_URL;
26
+ }
27
+
28
+ webpack: {
29
+ let BASE_URL: string;
30
+
31
+ try {
32
+ // @ts-expect-error
33
+ BASE_URL = process.env.PUBLIC_URL;
34
+
35
+ assert(typeof BASE_URL === "string");
36
+ } catch {
37
+ break webpack;
38
+ }
39
+
40
+ return BASE_URL === "" ? "/" : `${BASE_URL}/`;
41
+ }
42
+
43
+ throw new Error("Bundler not supported");
44
+ })();
@@ -0,0 +1,3 @@
1
+ import { BASE_URL } from "./BASE_URL";
2
+
3
+ export const isStorybook = BASE_URL.startsWith(".");
@@ -36,6 +36,10 @@ export declare namespace keycloak_js {
36
36
  }
37
37
 
38
38
  /**
39
+ * @deprecated: This will be removed in the next major version.
40
+ * If you use this, please copy paste the code into your project.
41
+ * Better yet migrate away from keycloak-js and use https://docs.oidc-spa.dev instead.
42
+ *
39
43
  * NOTE: This is just a slightly modified version of the default adapter in keycloak-js
40
44
  * The goal here is just to be able to inject search param in url before keycloak redirect.
41
45
  * Our use case for it is to pass over the login screen the states of useGlobalState
@@ -2,14 +2,13 @@ import type { KcContext, Attribute } from "./KcContext";
2
2
  import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
3
3
  import type { DeepPartial } from "keycloakify/tools/DeepPartial";
4
4
  import { deepAssign } from "keycloakify/tools/deepAssign";
5
+ import { isStorybook } from "keycloakify/lib/isStorybook";
5
6
  import { id } from "tsafe/id";
6
7
  import { exclude } from "tsafe/exclude";
7
8
  import { assert } from "tsafe/assert";
8
9
  import type { ExtendKcContext } from "./getKcContextFromWindow";
9
10
  import { getKcContextFromWindow } from "./getKcContextFromWindow";
10
- import { pathJoin } from "keycloakify/bin/tools/pathJoin";
11
11
  import { symToStr } from "tsafe/symToStr";
12
- import { resources_common } from "keycloakify/bin/constants";
13
12
 
14
13
  export function createGetKcContext<KcContextExtension extends { pageId: string } = never>(params?: {
15
14
  mockData?: readonly DeepPartial<ExtendKcContext<KcContextExtension>>[];
@@ -31,7 +30,13 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
31
30
  if (mockPageId !== undefined && realKcContext === undefined) {
32
31
  //TODO maybe trow if no mock fo custom page
33
32
 
34
- console.log(`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`, "background: red; color: yellow; font-size: medium");
33
+ warn_that_mock_is_enbaled: {
34
+ if (isStorybook) {
35
+ break warn_that_mock_is_enbaled;
36
+ }
37
+
38
+ console.log(`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`, "background: red; color: yellow; font-size: medium");
39
+ }
35
40
 
36
41
  const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
37
42
 
@@ -147,8 +152,6 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
147
152
  return { "kcContext": undefined as any };
148
153
  }
149
154
 
150
- realKcContext.url.resourcesCommonPath = pathJoin(realKcContext.url.resourcesPath, resources_common);
151
-
152
155
  return { "kcContext": realKcContext as any };
153
156
  }
154
157
 
@@ -1,10 +1,10 @@
1
1
  import "minimal-polyfills/Object.fromEntries";
2
2
  import type { KcContext, Attribute } from "./KcContext";
3
3
  import { resources_common, keycloak_resources } from "keycloakify/bin/constants";
4
- import { pathJoin } from "keycloakify/bin/tools/pathJoin";
5
4
  import { id } from "tsafe/id";
6
5
  import { assert, type Equals } from "tsafe/assert";
7
6
  import type { LoginThemePageId } from "keycloakify/bin/keycloakify/generateFtl";
7
+ import { BASE_URL } from "keycloakify/lib/BASE_URL";
8
8
 
9
9
  const attributes: Attribute[] = [
10
10
  {
@@ -100,9 +100,7 @@ const attributes: Attribute[] = [
100
100
 
101
101
  const attributesByName = Object.fromEntries(attributes.map(attribute => [attribute.name, attribute])) as any;
102
102
 
103
- const PUBLIC_URL = (typeof process !== "object" ? undefined : process.env?.["PUBLIC_URL"]) || "/";
104
-
105
- const resourcesPath = pathJoin(PUBLIC_URL, keycloak_resources, "login", "resources");
103
+ const resourcesPath = `${BASE_URL}${keycloak_resources}/login/resources`;
106
104
 
107
105
  export const kcContextCommonMock: KcContext.Common = {
108
106
  "themeVersion": "0.0.0",
@@ -112,7 +110,7 @@ export const kcContextCommonMock: KcContext.Common = {
112
110
  "url": {
113
111
  "loginAction": "#",
114
112
  resourcesPath,
115
- "resourcesCommonPath": pathJoin(resourcesPath, resources_common),
113
+ "resourcesCommonPath": `${resourcesPath}/${resources_common}`,
116
114
  "loginRestartFlowUrl": "/auth/realms/myrealm/login-actions/restart?client_id=account&tab_id=HoAx28ja4xg",
117
115
  "loginUrl": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg"
118
116
  },
@@ -1,14 +1,14 @@
1
1
  import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
2
- import { readParsedPackageJson } from "../bin/keycloakify/buildOptions/parsedPackageJson";
3
2
  import type { Plugin } from "vite";
4
3
  import { assert } from "tsafe/assert";
5
4
  import * as fs from "fs";
6
5
  import { resolvedViteConfigJsonBasename, nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir, keycloak_resources } from "../bin/constants";
7
6
  import type { ResolvedViteConfig } from "../bin/keycloakify/buildOptions/resolvedViteConfig";
8
- import { getKeycloakifyBuildDirPath } from "../bin/keycloakify/buildOptions/getKeycloakifyBuildDirPath";
7
+ import { getCacheDirPath } from "../bin/keycloakify/buildOptions/getCacheDirPath";
9
8
  import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
10
9
  import { id } from "tsafe/id";
11
10
  import { rm } from "../bin/tools/fs.rm";
11
+ import { copyKeycloakResourcesToPublic } from "../bin/copy-keycloak-resources-to-public";
12
12
 
13
13
  export function keycloakify(): Plugin {
14
14
  let reactAppRootDirPath: string | undefined = undefined;
@@ -18,7 +18,7 @@ export function keycloakify(): Plugin {
18
18
  return {
19
19
  "name": "keycloakify",
20
20
  "apply": "build",
21
- "configResolved": resolvedConfig => {
21
+ "configResolved": async resolvedConfig => {
22
22
  reactAppRootDirPath = resolvedConfig.root;
23
23
  urlPathname = (() => {
24
24
  let out = resolvedConfig.env.BASE_URL;
@@ -40,19 +40,16 @@ export function keycloakify(): Plugin {
40
40
 
41
41
  buildDirPath = pathJoin(reactAppRootDirPath, resolvedConfig.build.outDir);
42
42
 
43
- const { keycloakifyBuildDirPath } = getKeycloakifyBuildDirPath({
44
- "parsedPackageJson_keycloakify_keycloakifyBuildDirPath": readParsedPackageJson({ reactAppRootDirPath }).keycloakify
45
- ?.keycloakifyBuildDirPath,
46
- reactAppRootDirPath,
47
- "bundler": "vite"
43
+ const { cacheDirPath } = getCacheDirPath({
44
+ reactAppRootDirPath
48
45
  });
49
46
 
50
- if (!fs.existsSync(keycloakifyBuildDirPath)) {
51
- fs.mkdirSync(keycloakifyBuildDirPath);
47
+ if (!fs.existsSync(cacheDirPath)) {
48
+ fs.mkdirSync(cacheDirPath);
52
49
  }
53
50
 
54
51
  fs.writeFileSync(
55
- pathJoin(keycloakifyBuildDirPath, resolvedViteConfigJsonBasename),
52
+ pathJoin(cacheDirPath, resolvedViteConfigJsonBasename),
56
53
  Buffer.from(
57
54
  JSON.stringify(
58
55
  id<ResolvedViteConfig>({
@@ -67,6 +64,10 @@ export function keycloakify(): Plugin {
67
64
  "utf8"
68
65
  )
69
66
  );
67
+
68
+ await copyKeycloakResourcesToPublic({
69
+ "processArgv": ["--project", reactAppRootDirPath]
70
+ });
70
71
  },
71
72
  "transform": (code, id) => {
72
73
  assert(reactAppRootDirPath !== undefined);