keycloakify 10.0.0-rc.90 → 10.0.0-rc.91

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} +180 -131
  3. package/bin/440.index.js +7 -12
  4. package/bin/453.index.js +1 -1
  5. package/bin/526.index.js +78 -65
  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 +168 -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 +130 -90
  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 +187 -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,39 @@ 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
+ dependencies: z.record(z.string()).optional(),
208
+ devDependencies: z.record(z.string()).optional()
209
+ })
210
+ .parse(JSON.parse(fs.readFileSync(packageJsonFilePath).toString("utf8")));
211
+
212
+ if (
213
+ parsedPackageJson.dependencies?.keycloakify === undefined &&
214
+ parsedPackageJson.devDependencies?.keycloakify === undefined
215
+ ) {
216
+ break success;
217
+ }
218
+
219
+ return packageJsonFilePath;
220
+ }
221
+
222
+ return getPackageJSonDirPath(upCount + 1);
223
+ })(0);
143
224
 
144
225
  const parsedPackageJson = (() => {
145
226
  type BuildOptions_packageJson = BuildOptions & {
@@ -149,14 +230,14 @@ export function getBuildContext(params: {
149
230
  };
150
231
 
151
232
  type ParsedPackageJson = {
152
- name: string;
233
+ name?: string;
153
234
  version?: string;
154
235
  homepage?: string;
155
236
  keycloakify?: BuildOptions_packageJson;
156
237
  };
157
238
 
158
239
  const zParsedPackageJson = z.object({
159
- name: z.string(),
240
+ name: z.string().optional(),
160
241
  version: z.string().optional(),
161
242
  homepage: z.string().optional(),
162
243
  keycloakify: id<z.ZodType<BuildOptions_packageJson>>(
@@ -234,63 +315,24 @@ export function getBuildContext(params: {
234
315
  assert<Equals<Got, Expected>>();
235
316
  }
236
317
 
318
+ const configurationPackageJsonFilePath = (() => {
319
+ const rootPackageJsonFilePath = pathJoin(projectDirPath, "package.json");
320
+
321
+ return fs.existsSync(rootPackageJsonFilePath)
322
+ ? rootPackageJsonFilePath
323
+ : packageJsonFilePath;
324
+ })();
325
+
237
326
  return zParsedPackageJson.parse(
238
- JSON.parse(
239
- fs.readFileSync(pathJoin(projectDirPath, "package.json")).toString("utf8")
240
- )
327
+ JSON.parse(fs.readFileSync(configurationPackageJsonFilePath).toString("utf8"))
241
328
  );
242
329
  })();
243
330
 
244
- console.log("DEBUG:", { parsedPackageJson });
245
-
246
331
  const buildOptions = {
247
332
  ...parsedPackageJson.keycloakify,
248
333
  ...resolvedViteConfig?.buildOptions
249
334
  };
250
335
 
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
336
  const recordIsImplementedByThemeType = objectFromEntries(
295
337
  (["login", "account", "email"] as const).map(themeType => [
296
338
  themeType,
@@ -298,16 +340,16 @@ export function getBuildContext(params: {
298
340
  ])
299
341
  );
300
342
 
301
- console.log("DEBUG:", { themeSrcDirPath });
302
-
303
343
  const themeNames = ((): [string, ...string[]] => {
304
344
  if (buildOptions.themeName === undefined) {
305
- return [
306
- parsedPackageJson.name
307
- .replace(/^@(.*)/, "$1")
308
- .split("/")
309
- .join("-")
310
- ];
345
+ return parsedPackageJson.name === undefined
346
+ ? ["keycloakify"]
347
+ : [
348
+ parsedPackageJson.name
349
+ .replace(/^@(.*)/, "$1")
350
+ .split("/")
351
+ .join("-")
352
+ ];
311
353
  }
312
354
 
313
355
  if (typeof buildOptions.themeName === "string") {
@@ -321,8 +363,6 @@ export function getBuildContext(params: {
321
363
  return [mainThemeName, ...themeVariantNames];
322
364
  })();
323
365
 
324
- console.log("DEBUG:", { themeNames });
325
-
326
366
  const projectBuildDirPath = (() => {
327
367
  webpack: {
328
368
  if (resolvedViteConfig !== undefined) {
@@ -342,19 +382,29 @@ export function getBuildContext(params: {
342
382
  return pathJoin(projectDirPath, resolvedViteConfig.buildDir);
343
383
  })();
344
384
 
345
- console.log("DEBUG:", { projectBuildDirPath });
346
-
347
- const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
348
- projectDirPath,
349
- dependencyExpected: "keycloakify"
350
- });
351
-
352
- console.log("DEBUG:", { npmWorkspaceRootDirPath });
353
-
354
385
  const bundler = resolvedViteConfig !== undefined ? "vite" : "webpack";
355
386
 
356
- const buildContext: BuildContext = {
357
- bundler,
387
+ return {
388
+ bundler:
389
+ resolvedViteConfig !== undefined
390
+ ? { type: "vite" }
391
+ : (() => {
392
+ const { scripts } = z
393
+ .object({
394
+ scripts: z.record(z.string()).optional()
395
+ })
396
+ .parse(
397
+ JSON.parse(
398
+ fs.readFileSync(packageJsonFilePath).toString("utf8")
399
+ )
400
+ );
401
+
402
+ return {
403
+ type: "webpack",
404
+ packageJsonDirPath: pathDirname(packageJsonFilePath),
405
+ packageJsonScripts: scripts ?? {}
406
+ };
407
+ })(),
358
408
  themeVersion: buildOptions.themeVersion ?? parsedPackageJson.version ?? "0.0.0",
359
409
  themeNames,
360
410
  extraThemeProperties: buildOptions.extraThemeProperties,
@@ -431,7 +481,11 @@ export function getBuildContext(params: {
431
481
  });
432
482
  }
433
483
 
434
- return pathJoin(npmWorkspaceRootDirPath, "node_modules", ".cache");
484
+ return pathJoin(
485
+ pathDirname(packageJsonFilePath),
486
+ "node_modules",
487
+ ".cache"
488
+ );
435
489
  })(),
436
490
  "keycloakify"
437
491
  );
@@ -480,7 +534,6 @@ export function getBuildContext(params: {
480
534
 
481
535
  return pathJoin(projectBuildDirPath, resolvedViteConfig.assetsDir);
482
536
  })(),
483
- npmWorkspaceRootDirPath,
484
537
  kcContextExclusionsFtlCode: (() => {
485
538
  if (buildOptions.kcContextExclusionsFtl === undefined) {
486
539
  return undefined;
@@ -500,6 +553,33 @@ export function getBuildContext(params: {
500
553
  environmentVariables: buildOptions.environmentVariables ?? [],
501
554
  recordIsImplementedByThemeType,
502
555
  themeSrcDirPath,
556
+ fetchOptions: getProxyFetchOptions({
557
+ npmConfigGetCwd: (function callee(upCount: number): string {
558
+ const dirPath = pathResolve(
559
+ pathJoin(...[projectDirPath, ...Array(upCount).fill("..")])
560
+ );
561
+
562
+ assert(
563
+ dirPath !== pathSep,
564
+ "Couldn't find a place to run 'npm config get'"
565
+ );
566
+
567
+ try {
568
+ child_process.execSync("npm config get", {
569
+ cwd: dirPath,
570
+ stdio: "ignore"
571
+ });
572
+ } catch (error) {
573
+ if (String(error).includes("ENOWORKSPACES")) {
574
+ return callee(upCount + 1);
575
+ }
576
+
577
+ throw error;
578
+ }
579
+
580
+ return dirPath;
581
+ })(0)
582
+ }),
503
583
  jarTargets: (() => {
504
584
  const getDefaultJarFileBasename = (range: string) =>
505
585
  `keycloak-theme-for-kc-${range}.jar`;
@@ -783,8 +863,4 @@ export function getBuildContext(params: {
783
863
  return jarTargets;
784
864
  })()
785
865
  };
786
-
787
- console.log("DEBUG:", JSON.stringify({ buildContext }, null, 2));
788
-
789
- return buildContext;
790
866
  }
@@ -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);