keycloakify 10.0.0-rc.90 → 10.0.0-rc.92

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 (31) hide show
  1. package/bin/193.index.js +3 -3
  2. package/bin/{751.index.js → 31.index.js} +183 -131
  3. package/bin/440.index.js +7 -12
  4. package/bin/453.index.js +1 -1
  5. package/bin/526.index.js +79 -68
  6. package/bin/538.index.js +1 -1
  7. package/bin/{837.index.js → 893.index.js} +7 -89
  8. package/bin/932.index.js +2 -2
  9. package/bin/97.index.js +1 -1
  10. package/bin/main.js +7 -7
  11. package/bin/shared/buildContext.d.ts +9 -2
  12. package/bin/shared/buildContext.js.map +1 -1
  13. package/bin/shared/copyKeycloakResourcesToPublic.js.map +1 -1
  14. package/bin/shared/downloadKeycloakDefaultTheme.d.ts +2 -1
  15. package/bin/shared/downloadKeycloakDefaultTheme.js.map +1 -1
  16. package/package.json +7 -9
  17. package/src/bin/keycloakify/generateFtl/generateFtl.ts +14 -10
  18. package/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +2 -1
  19. package/src/bin/keycloakify/keycloakify.ts +1 -7
  20. package/src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts +2 -2
  21. package/src/bin/shared/buildContext.ts +170 -92
  22. package/src/bin/shared/copyKeycloakResourcesToPublic.ts +1 -4
  23. package/src/bin/shared/downloadKeycloakDefaultTheme.ts +2 -2
  24. package/src/bin/start-keycloak/appBuild.ts +131 -94
  25. package/src/bin/start-keycloak/keycloakifyBuild.ts +0 -1
  26. package/src/bin/start-keycloak/start-keycloak.ts +1 -1
  27. package/src/bin/tools/{downloadAndExtractArchive/downloadAndExtractArchive.ts → downloadAndExtractArchive.ts} +9 -17
  28. package/src/bin/tools/{downloadAndExtractArchive/fetchProxyOptions.ts → fetchProxyOptions.ts} +52 -60
  29. package/vite-plugin/index.js +190 -228
  30. package/src/bin/tools/downloadAndExtractArchive/index.ts +0 -1
  31. package/src/bin/tools/getNpmWorkspaceRootDirPath.ts +0 -84
@@ -1,6 +1,12 @@
1
1
  import cheerio from "cheerio";
2
- import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
3
- import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
2
+ import {
3
+ replaceImportsInJsCode,
4
+ BuildContextLike as BuildContextLike_replaceImportsInJsCode
5
+ } from "../replacers/replaceImportsInJsCode";
6
+ import {
7
+ replaceImportsInCssCode,
8
+ BuildContextLike as BuildContextLike_replaceImportsInCssCode
9
+ } from "../replacers/replaceImportsInCssCode";
4
10
  import * as fs from "fs";
5
11
  import { join as pathJoin } from "path";
6
12
  import type { BuildContext } from "../../shared/buildContext";
@@ -12,14 +18,12 @@ import {
12
18
  } from "../../shared/constants";
13
19
  import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
14
20
 
15
- export type BuildContextLike = {
16
- bundler: "vite" | "webpack";
17
- themeVersion: string;
18
- urlPathname: string | undefined;
19
- projectBuildDirPath: string;
20
- assetsDirPath: string;
21
- kcContextExclusionsFtlCode: string | undefined;
22
- };
21
+ export type BuildContextLike = BuildContextLike_replaceImportsInJsCode &
22
+ BuildContextLike_replaceImportsInCssCode & {
23
+ urlPathname: string | undefined;
24
+ themeVersion: string;
25
+ kcContextExclusionsFtlCode: string | undefined;
26
+ };
23
27
 
24
28
  assert<BuildContext extends BuildContextLike ? true : false>();
25
29
 
@@ -53,6 +53,7 @@ export type BuildContextLike = BuildContextLike_kcContextExclusionsFtlCode &
53
53
  environmentVariables: { name: string; default: string }[];
54
54
  recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
55
55
  themeSrcDirPath: string;
56
+ bundler: { type: "vite" } | { type: "webpack" };
56
57
  };
57
58
 
58
59
  assert<BuildContext extends BuildContextLike ? true : false>();
@@ -113,7 +114,7 @@ export async function generateResourcesForMainTheme(params: {
113
114
  );
114
115
 
115
116
  if (fs.existsSync(dirPath)) {
116
- assert(buildContext.bundler === "webpack");
117
+ assert(buildContext.bundler.type === "webpack");
117
118
 
118
119
  throw new Error(
119
120
  [
@@ -12,12 +12,6 @@ import * as os from "os";
12
12
  import { rmSync } from "../tools/fs.rmSync";
13
13
 
14
14
  export async function command(params: { cliCommandOptions: CliCommandOptions }) {
15
- console.log("DEBUG:", {
16
- __filename,
17
- __dirname,
18
- "process.cwd()": process.cwd()
19
- });
20
-
21
15
  exit_if_maven_not_installed: {
22
16
  let commandOutput: Buffer | undefined = undefined;
23
17
 
@@ -91,7 +85,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
91
85
  });
92
86
 
93
87
  run_post_build_script: {
94
- if (buildContext.bundler !== "vite") {
88
+ if (buildContext.bundler.type !== "vite") {
95
89
  break run_post_build_script;
96
90
  }
97
91
 
@@ -8,7 +8,7 @@ export type BuildContextLike = {
8
8
  projectBuildDirPath: string;
9
9
  assetsDirPath: string;
10
10
  urlPathname: string | undefined;
11
- bundler: "vite" | "webpack";
11
+ bundler: { type: "vite" } | { type: "webpack" };
12
12
  };
13
13
 
14
14
  assert<BuildContext extends BuildContextLike ? true : false>();
@@ -20,7 +20,7 @@ export function replaceImportsInJsCode(params: {
20
20
  const { jsCode, buildContext } = params;
21
21
 
22
22
  const { fixedJsCode } = (() => {
23
- switch (buildContext.bundler) {
23
+ switch (buildContext.bundler.type) {
24
24
  case "vite":
25
25
  return replaceImportsInJsCode_vite({
26
26
  jsCode,
@@ -1,7 +1,12 @@
1
1
  import { parse as urlParse } from "url";
2
- import { join as pathJoin } from "path";
2
+ import {
3
+ join as pathJoin,
4
+ sep as pathSep,
5
+ relative as pathRelative,
6
+ resolve as pathResolve,
7
+ dirname as pathDirname
8
+ } from "path";
3
9
  import { getAbsoluteAndInOsFormatPath } from "../tools/getAbsoluteAndInOsFormatPath";
4
- import { getNpmWorkspaceRootDirPath } from "../tools/getNpmWorkspaceRootDirPath";
5
10
  import type { CliCommandOptions } from "../main";
6
11
  import { z } from "zod";
7
12
  import * as fs from "fs";
@@ -21,9 +26,9 @@ import { type ThemeType } from "./constants";
21
26
  import { id } from "tsafe/id";
22
27
  import { symToStr } from "tsafe/symToStr";
23
28
  import chalk from "chalk";
29
+ import { getProxyFetchOptions, type ProxyFetchOptions } from "../tools/fetchProxyOptions";
24
30
 
25
31
  export type BuildContext = {
26
- bundler: "vite" | "webpack";
27
32
  themeVersion: string;
28
33
  themeNames: [string, ...string[]];
29
34
  extraThemeProperties: string[] | undefined;
@@ -40,7 +45,7 @@ export type BuildContext = {
40
45
  * In this case the urlPathname will be "/my-app/" */
41
46
  urlPathname: string | undefined;
42
47
  assetsDirPath: string;
43
- npmWorkspaceRootDirPath: string;
48
+ fetchOptions: ProxyFetchOptions;
44
49
  kcContextExclusionsFtlCode: string | undefined;
45
50
  environmentVariables: { name: string; default: string }[];
46
51
  themeSrcDirPath: string;
@@ -49,6 +54,15 @@ export type BuildContext = {
49
54
  keycloakVersionRange: KeycloakVersionRange;
50
55
  jarFileBasename: string;
51
56
  }[];
57
+ bundler:
58
+ | {
59
+ type: "vite";
60
+ }
61
+ | {
62
+ type: "webpack";
63
+ packageJsonDirPath: string;
64
+ packageJsonScripts: Record<string, string>;
65
+ };
52
66
  };
53
67
 
54
68
  export type BuildOptions = {
@@ -90,20 +104,55 @@ export function getBuildContext(params: {
90
104
  }): BuildContext {
91
105
  const { cliCommandOptions } = params;
92
106
 
93
- console.log("DEBUG:", { cliCommandOptions });
107
+ const projectDirPath =
108
+ cliCommandOptions.projectDirPath !== undefined
109
+ ? getAbsoluteAndInOsFormatPath({
110
+ pathIsh: cliCommandOptions.projectDirPath,
111
+ cwd: process.cwd()
112
+ })
113
+ : process.cwd();
114
+
115
+ const { themeSrcDirPath } = (() => {
116
+ const srcDirPath = pathJoin(projectDirPath, "src");
94
117
 
95
- const projectDirPath = (() => {
96
- if (cliCommandOptions.projectDirPath === undefined) {
97
- return process.cwd();
118
+ const themeSrcDirPath: string | undefined = crawl({
119
+ dirPath: srcDirPath,
120
+ returnedPathsType: "relative to dirPath"
121
+ })
122
+ .map(fileRelativePath => {
123
+ for (const themeSrcDirBasename of ["keycloak-theme", "keycloak_theme"]) {
124
+ const split = fileRelativePath.split(themeSrcDirBasename);
125
+ if (split.length === 2) {
126
+ return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
127
+ }
128
+ }
129
+ return undefined;
130
+ })
131
+ .filter(exclude(undefined))[0];
132
+
133
+ if (themeSrcDirPath !== undefined) {
134
+ return { themeSrcDirPath };
98
135
  }
99
136
 
100
- return getAbsoluteAndInOsFormatPath({
101
- pathIsh: cliCommandOptions.projectDirPath,
102
- cwd: process.cwd()
103
- });
104
- })();
137
+ for (const themeType of [...themeTypes, "email"]) {
138
+ if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
139
+ continue;
140
+ }
141
+ return { themeSrcDirPath: srcDirPath };
142
+ }
105
143
 
106
- console.log("DEBUG:", { projectDirPath });
144
+ console.log(
145
+ chalk.red(
146
+ [
147
+ `Can't locate your Keycloak theme source directory in .${pathSep}${pathRelative(process.cwd(), srcDirPath)}`,
148
+ `Make sure to either use the Keycloakify CLI in the root of your Keycloakify project or use the --project CLI option`,
149
+ `If you are collocating your Keycloak theme with your app you must have a directory named 'keycloak-theme' or 'keycloak_theme' in your 'src' directory`
150
+ ].join("\n")
151
+ )
152
+ );
153
+
154
+ process.exit(1);
155
+ })();
107
156
 
108
157
  const { resolvedViteConfig } = (() => {
109
158
  if (
@@ -139,7 +188,41 @@ export function getBuildContext(params: {
139
188
  return { resolvedViteConfig };
140
189
  })();
141
190
 
142
- console.log("DEBUG:", { resolvedViteConfig });
191
+ const packageJsonFilePath = (function getPackageJSonDirPath(upCount: number): string {
192
+ const dirPath = pathResolve(
193
+ pathJoin(...[projectDirPath, ...Array(upCount).fill("..")])
194
+ );
195
+
196
+ assert(dirPath !== pathSep, "Root package.json not found");
197
+
198
+ success: {
199
+ const packageJsonFilePath = pathJoin(dirPath, "package.json");
200
+
201
+ if (!fs.existsSync(packageJsonFilePath)) {
202
+ break success;
203
+ }
204
+
205
+ const parsedPackageJson = z
206
+ .object({
207
+ name: z.string().optional(),
208
+ dependencies: z.record(z.string()).optional(),
209
+ devDependencies: z.record(z.string()).optional()
210
+ })
211
+ .parse(JSON.parse(fs.readFileSync(packageJsonFilePath).toString("utf8")));
212
+
213
+ if (
214
+ parsedPackageJson.dependencies?.keycloakify === undefined &&
215
+ parsedPackageJson.devDependencies?.keycloakify === undefined &&
216
+ parsedPackageJson.name !== "keycloakify" // NOTE: For local storybook build
217
+ ) {
218
+ break success;
219
+ }
220
+
221
+ return packageJsonFilePath;
222
+ }
223
+
224
+ return getPackageJSonDirPath(upCount + 1);
225
+ })(0);
143
226
 
144
227
  const parsedPackageJson = (() => {
145
228
  type BuildOptions_packageJson = BuildOptions & {
@@ -149,14 +232,14 @@ export function getBuildContext(params: {
149
232
  };
150
233
 
151
234
  type ParsedPackageJson = {
152
- name: string;
235
+ name?: string;
153
236
  version?: string;
154
237
  homepage?: string;
155
238
  keycloakify?: BuildOptions_packageJson;
156
239
  };
157
240
 
158
241
  const zParsedPackageJson = z.object({
159
- name: z.string(),
242
+ name: z.string().optional(),
160
243
  version: z.string().optional(),
161
244
  homepage: z.string().optional(),
162
245
  keycloakify: id<z.ZodType<BuildOptions_packageJson>>(
@@ -234,63 +317,24 @@ export function getBuildContext(params: {
234
317
  assert<Equals<Got, Expected>>();
235
318
  }
236
319
 
320
+ const configurationPackageJsonFilePath = (() => {
321
+ const rootPackageJsonFilePath = pathJoin(projectDirPath, "package.json");
322
+
323
+ return fs.existsSync(rootPackageJsonFilePath)
324
+ ? rootPackageJsonFilePath
325
+ : packageJsonFilePath;
326
+ })();
327
+
237
328
  return zParsedPackageJson.parse(
238
- JSON.parse(
239
- fs.readFileSync(pathJoin(projectDirPath, "package.json")).toString("utf8")
240
- )
329
+ JSON.parse(fs.readFileSync(configurationPackageJsonFilePath).toString("utf8"))
241
330
  );
242
331
  })();
243
332
 
244
- console.log("DEBUG:", { parsedPackageJson });
245
-
246
333
  const buildOptions = {
247
334
  ...parsedPackageJson.keycloakify,
248
335
  ...resolvedViteConfig?.buildOptions
249
336
  };
250
337
 
251
- console.log("DEBUG:", { buildOptions });
252
-
253
- const { themeSrcDirPath } = (() => {
254
- const srcDirPath = pathJoin(projectDirPath, "src");
255
-
256
- const themeSrcDirPath: string | undefined = crawl({
257
- dirPath: srcDirPath,
258
- returnedPathsType: "relative to dirPath"
259
- })
260
- .map(fileRelativePath => {
261
- for (const themeSrcDirBasename of ["keycloak-theme", "keycloak_theme"]) {
262
- const split = fileRelativePath.split(themeSrcDirBasename);
263
- if (split.length === 2) {
264
- return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
265
- }
266
- }
267
- return undefined;
268
- })
269
- .filter(exclude(undefined))[0];
270
-
271
- if (themeSrcDirPath !== undefined) {
272
- return { themeSrcDirPath };
273
- }
274
-
275
- for (const themeType of [...themeTypes, "email"]) {
276
- if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
277
- continue;
278
- }
279
- return { themeSrcDirPath: srcDirPath };
280
- }
281
-
282
- console.log(
283
- chalk.red(
284
- [
285
- "Can't locate your keycloak theme source directory.",
286
- "See: https://docs.keycloakify.dev/v/v10/keycloakify-in-my-app/collocation"
287
- ].join("\n")
288
- )
289
- );
290
-
291
- process.exit(1);
292
- })();
293
-
294
338
  const recordIsImplementedByThemeType = objectFromEntries(
295
339
  (["login", "account", "email"] as const).map(themeType => [
296
340
  themeType,
@@ -298,16 +342,16 @@ export function getBuildContext(params: {
298
342
  ])
299
343
  );
300
344
 
301
- console.log("DEBUG:", { themeSrcDirPath });
302
-
303
345
  const themeNames = ((): [string, ...string[]] => {
304
346
  if (buildOptions.themeName === undefined) {
305
- return [
306
- parsedPackageJson.name
307
- .replace(/^@(.*)/, "$1")
308
- .split("/")
309
- .join("-")
310
- ];
347
+ return parsedPackageJson.name === undefined
348
+ ? ["keycloakify"]
349
+ : [
350
+ parsedPackageJson.name
351
+ .replace(/^@(.*)/, "$1")
352
+ .split("/")
353
+ .join("-")
354
+ ];
311
355
  }
312
356
 
313
357
  if (typeof buildOptions.themeName === "string") {
@@ -321,8 +365,6 @@ export function getBuildContext(params: {
321
365
  return [mainThemeName, ...themeVariantNames];
322
366
  })();
323
367
 
324
- console.log("DEBUG:", { themeNames });
325
-
326
368
  const projectBuildDirPath = (() => {
327
369
  webpack: {
328
370
  if (resolvedViteConfig !== undefined) {
@@ -342,19 +384,29 @@ export function getBuildContext(params: {
342
384
  return pathJoin(projectDirPath, resolvedViteConfig.buildDir);
343
385
  })();
344
386
 
345
- console.log("DEBUG:", { projectBuildDirPath });
346
-
347
- const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
348
- projectDirPath,
349
- dependencyExpected: "keycloakify"
350
- });
351
-
352
- console.log("DEBUG:", { npmWorkspaceRootDirPath });
353
-
354
387
  const bundler = resolvedViteConfig !== undefined ? "vite" : "webpack";
355
388
 
356
- const buildContext: BuildContext = {
357
- bundler,
389
+ return {
390
+ bundler:
391
+ resolvedViteConfig !== undefined
392
+ ? { type: "vite" }
393
+ : (() => {
394
+ const { scripts } = z
395
+ .object({
396
+ scripts: z.record(z.string()).optional()
397
+ })
398
+ .parse(
399
+ JSON.parse(
400
+ fs.readFileSync(packageJsonFilePath).toString("utf8")
401
+ )
402
+ );
403
+
404
+ return {
405
+ type: "webpack",
406
+ packageJsonDirPath: pathDirname(packageJsonFilePath),
407
+ packageJsonScripts: scripts ?? {}
408
+ };
409
+ })(),
358
410
  themeVersion: buildOptions.themeVersion ?? parsedPackageJson.version ?? "0.0.0",
359
411
  themeNames,
360
412
  extraThemeProperties: buildOptions.extraThemeProperties,
@@ -431,7 +483,11 @@ export function getBuildContext(params: {
431
483
  });
432
484
  }
433
485
 
434
- return pathJoin(npmWorkspaceRootDirPath, "node_modules", ".cache");
486
+ return pathJoin(
487
+ pathDirname(packageJsonFilePath),
488
+ "node_modules",
489
+ ".cache"
490
+ );
435
491
  })(),
436
492
  "keycloakify"
437
493
  );
@@ -480,7 +536,6 @@ export function getBuildContext(params: {
480
536
 
481
537
  return pathJoin(projectBuildDirPath, resolvedViteConfig.assetsDir);
482
538
  })(),
483
- npmWorkspaceRootDirPath,
484
539
  kcContextExclusionsFtlCode: (() => {
485
540
  if (buildOptions.kcContextExclusionsFtl === undefined) {
486
541
  return undefined;
@@ -500,6 +555,33 @@ export function getBuildContext(params: {
500
555
  environmentVariables: buildOptions.environmentVariables ?? [],
501
556
  recordIsImplementedByThemeType,
502
557
  themeSrcDirPath,
558
+ fetchOptions: getProxyFetchOptions({
559
+ npmConfigGetCwd: (function callee(upCount: number): string {
560
+ const dirPath = pathResolve(
561
+ pathJoin(...[projectDirPath, ...Array(upCount).fill("..")])
562
+ );
563
+
564
+ assert(
565
+ dirPath !== pathSep,
566
+ "Couldn't find a place to run 'npm config get'"
567
+ );
568
+
569
+ try {
570
+ child_process.execSync("npm config get", {
571
+ cwd: dirPath,
572
+ stdio: "ignore"
573
+ });
574
+ } catch (error) {
575
+ if (String(error).includes("ENOWORKSPACES")) {
576
+ return callee(upCount + 1);
577
+ }
578
+
579
+ throw error;
580
+ }
581
+
582
+ return dirPath;
583
+ })(0)
584
+ }),
503
585
  jarTargets: (() => {
504
586
  const getDefaultJarFileBasename = (range: string) =>
505
587
  `keycloak-theme-for-kc-${range}.jar`;
@@ -783,8 +865,4 @@ export function getBuildContext(params: {
783
865
  return jarTargets;
784
866
  })()
785
867
  };
786
-
787
- console.log("DEBUG:", JSON.stringify({ buildContext }, null, 2));
788
-
789
- return buildContext;
790
868
  }
@@ -37,10 +37,7 @@ export async function copyKeycloakResourcesToPublic(params: {
37
37
  buildContext: {
38
38
  loginThemeResourcesFromKeycloakVersion: readThisNpmPackageVersion(),
39
39
  cacheDirPath: pathRelative(destDirPath, buildContext.cacheDirPath),
40
- npmWorkspaceRootDirPath: pathRelative(
41
- destDirPath,
42
- buildContext.npmWorkspaceRootDirPath
43
- )
40
+ fetchOptions: buildContext.fetchOptions
44
41
  }
45
42
  },
46
43
  null,
@@ -6,7 +6,7 @@ import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
6
6
 
7
7
  export type BuildContextLike = {
8
8
  cacheDirPath: string;
9
- npmWorkspaceRootDirPath: string;
9
+ fetchOptions: BuildContext["fetchOptions"];
10
10
  };
11
11
 
12
12
  assert<BuildContext extends BuildContextLike ? true : false>();
@@ -23,7 +23,7 @@ export async function downloadKeycloakDefaultTheme(params: {
23
23
  const { extractedDirPath } = await downloadAndExtractArchive({
24
24
  url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
25
25
  cacheDirPath: buildContext.cacheDirPath,
26
- npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
26
+ fetchOptions: buildContext.fetchOptions,
27
27
  uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
28
28
  onArchiveFile: async params => {
29
29
  const fileRelativePath = pathRelative("theme", params.fileRelativePath);