keycloakify 11.8.18 → 11.8.19

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.
package/bin/97.index.js CHANGED
@@ -2161,6 +2161,82 @@ async function existsAsync(path) {
2161
2161
 
2162
2162
  /***/ }),
2163
2163
 
2164
+ /***/ 93721:
2165
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2166
+
2167
+
2168
+ // EXPORTS
2169
+ __webpack_require__.d(__webpack_exports__, {
2170
+ "p": () => (/* binding */ getInstalledModuleDirPath)
2171
+ });
2172
+
2173
+ // EXTERNAL MODULE: external "path"
2174
+ var external_path_ = __webpack_require__(71017);
2175
+ // EXTERNAL MODULE: ./dist/bin/tools/fs.existsAsync.js
2176
+ var fs_existsAsync = __webpack_require__(43765);
2177
+ // EXTERNAL MODULE: external "child_process"
2178
+ var external_child_process_ = __webpack_require__(32081);
2179
+ // EXTERNAL MODULE: ./node_modules/tsafe/esm/assert.mjs + 1 modules
2180
+ var assert = __webpack_require__(29041);
2181
+ ;// CONCATENATED MODULE: ./dist/bin/tools/isRootPath.js
2182
+
2183
+ function getIsRootPath(filePath) {
2184
+ const path_normalized = (0,external_path_.normalize)(filePath);
2185
+ // Unix-like root ("/")
2186
+ if (path_normalized === "/") {
2187
+ return true;
2188
+ }
2189
+ // Check for Windows drive root (e.g., "C:\\")
2190
+ if (/^[a-zA-Z]:\\$/.test(path_normalized)) {
2191
+ return true;
2192
+ }
2193
+ // Check for UNC root (e.g., "\\server\share")
2194
+ if (/^\\\\[^\\]+\\[^\\]+\\?$/.test(path_normalized)) {
2195
+ return true;
2196
+ }
2197
+ return false;
2198
+ }
2199
+ //# sourceMappingURL=isRootPath.js.map
2200
+ ;// CONCATENATED MODULE: ./dist/bin/tools/getInstalledModuleDirPath.js
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+ async function getInstalledModuleDirPath(params) {
2207
+ const { moduleName, packageJsonDirPath } = params;
2208
+ {
2209
+ let dirPath = packageJsonDirPath;
2210
+ while (true) {
2211
+ const dirPath_candidate = (0,external_path_.join)(dirPath, "node_modules", ...moduleName.split("/"));
2212
+ let doesExist;
2213
+ try {
2214
+ doesExist = await (0,fs_existsAsync/* existsAsync */.o)(dirPath_candidate);
2215
+ }
2216
+ catch (_a) {
2217
+ doesExist = false;
2218
+ }
2219
+ if (doesExist) {
2220
+ return dirPath_candidate;
2221
+ }
2222
+ if (getIsRootPath(dirPath)) {
2223
+ break;
2224
+ }
2225
+ dirPath = (0,external_path_.join)(dirPath, "..");
2226
+ }
2227
+ }
2228
+ const dirPath = external_child_process_.execSync(`npm list ${moduleName}`, {
2229
+ cwd: packageJsonDirPath
2230
+ })
2231
+ .toString("utf8")
2232
+ .trim();
2233
+ (0,assert/* assert */.h)(dirPath !== "");
2234
+ return dirPath;
2235
+ }
2236
+ //# sourceMappingURL=getInstalledModuleDirPath.js.map
2237
+
2238
+ /***/ }),
2239
+
2164
2240
  /***/ 90665:
2165
2241
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2166
2242
 
@@ -2186,11 +2262,38 @@ function isInside(params) {
2186
2262
  /* harmony export */ });
2187
2263
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(71017);
2188
2264
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
2265
+ /* harmony import */ var _getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(58822);
2266
+ /* harmony import */ var _getInstalledModuleDirPath__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(93721);
2267
+ /* harmony import */ var _fs_existsAsync__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(43765);
2268
+ /* harmony import */ var zod__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(52300);
2269
+ /* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(73292);
2270
+ /* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_4__);
2271
+ /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(29041);
2272
+ /* harmony import */ var tsafe_id__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(38469);
2189
2273
 
2190
- let cache = undefined;
2191
- function getNodeModulesBinDirPath() {
2192
- if (cache !== undefined) {
2193
- return cache;
2274
+
2275
+
2276
+
2277
+
2278
+
2279
+
2280
+
2281
+ let cache_bestEffort = undefined;
2282
+ /** NOTE: Careful, this function can fail when the binary
2283
+ * Used is not in the node_modules directory of the project
2284
+ * (for example when running tests with vscode extension we'll get
2285
+ * '/Users/dylan/.vscode/extensions/vitest.explorer-1.16.0/dist/worker.js'
2286
+ *
2287
+ * instead of
2288
+ * '/Users/joseph/.nvm/versions/node/v22.12.0/bin/node'
2289
+ * or
2290
+ * '/Users/joseph/github/keycloakify-starter/node_modules/.bin/vite'
2291
+ *
2292
+ * as the value of process.argv[1]
2293
+ */
2294
+ function getNodeModulesBinDirPath_bestEffort() {
2295
+ if (cache_bestEffort !== undefined) {
2296
+ return cache_bestEffort;
2194
2297
  }
2195
2298
  const binPath = process.argv[1];
2196
2299
  const segments = [".bin"];
@@ -2208,10 +2311,71 @@ function getNodeModulesBinDirPath() {
2208
2311
  }
2209
2312
  segments.unshift(segment);
2210
2313
  }
2314
+ if (!foundNodeModules) {
2315
+ throw new Error(`Could not find node_modules in path ${binPath}`);
2316
+ }
2211
2317
  const nodeModulesBinDirPath = segments.join(path__WEBPACK_IMPORTED_MODULE_0__.sep);
2212
- cache = nodeModulesBinDirPath;
2318
+ cache_bestEffort = nodeModulesBinDirPath;
2213
2319
  return nodeModulesBinDirPath;
2214
2320
  }
2321
+ let cache_withPackageJsonFileDirPath = undefined;
2322
+ async function getNodeModulesBinDirPath_withPackageJsonFileDirPath(params) {
2323
+ const { packageJsonFilePath } = params;
2324
+ use_cache: {
2325
+ if (cache_withPackageJsonFileDirPath === undefined) {
2326
+ break use_cache;
2327
+ }
2328
+ if (cache_withPackageJsonFileDirPath.packageJsonFilePath !== packageJsonFilePath) {
2329
+ cache_withPackageJsonFileDirPath = undefined;
2330
+ break use_cache;
2331
+ }
2332
+ return cache_withPackageJsonFileDirPath.nodeModulesBinDirPath;
2333
+ }
2334
+ // [...]node_modules/keycloakify
2335
+ const installedModuleDirPath = await (0,_getInstalledModuleDirPath__WEBPACK_IMPORTED_MODULE_2__/* .getInstalledModuleDirPath */ .p)({
2336
+ // Here it will always be "keycloakify" but since we are in tools/ we make something generic
2337
+ moduleName: await (async () => {
2338
+ const zParsedPackageJson = (() => {
2339
+ const zTargetType = zod__WEBPACK_IMPORTED_MODULE_6__.z.object({
2340
+ name: zod__WEBPACK_IMPORTED_MODULE_6__.z.string()
2341
+ });
2342
+ tsafe_assert__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .h;
2343
+ return (0,tsafe_id__WEBPACK_IMPORTED_MODULE_7__.id)(zTargetType);
2344
+ })();
2345
+ const parsedPackageJson = JSON.parse((await fs_promises__WEBPACK_IMPORTED_MODULE_4__.readFile((0,path__WEBPACK_IMPORTED_MODULE_0__.join)((0,_getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_1__/* .getThisCodebaseRootDirPath */ .e)(), "package.json"))).toString("utf8"));
2346
+ zParsedPackageJson.parse(parsedPackageJson);
2347
+ (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .h)((0,tsafe_assert__WEBPACK_IMPORTED_MODULE_5__.is)(parsedPackageJson));
2348
+ return parsedPackageJson.name;
2349
+ })(),
2350
+ packageJsonDirPath: (0,path__WEBPACK_IMPORTED_MODULE_0__.dirname)(packageJsonFilePath)
2351
+ });
2352
+ const segments = installedModuleDirPath.split(path__WEBPACK_IMPORTED_MODULE_0__.sep);
2353
+ while (true) {
2354
+ const segment = segments.pop();
2355
+ if (segment === undefined) {
2356
+ throw new Error(`Could not find .bin directory relative to ${packageJsonFilePath}`);
2357
+ }
2358
+ if (segment !== "node_modules") {
2359
+ continue;
2360
+ }
2361
+ const candidate = (0,path__WEBPACK_IMPORTED_MODULE_0__.join)(segments.join(path__WEBPACK_IMPORTED_MODULE_0__.sep), segment, ".bin");
2362
+ if (!(await (0,_fs_existsAsync__WEBPACK_IMPORTED_MODULE_3__/* .existsAsync */ .o)(candidate))) {
2363
+ continue;
2364
+ }
2365
+ cache_withPackageJsonFileDirPath = {
2366
+ packageJsonFilePath,
2367
+ nodeModulesBinDirPath: candidate
2368
+ };
2369
+ break;
2370
+ }
2371
+ return cache_withPackageJsonFileDirPath.nodeModulesBinDirPath;
2372
+ }
2373
+ function getNodeModulesBinDirPath(params) {
2374
+ const { packageJsonFilePath } = params !== null && params !== void 0 ? params : {};
2375
+ return packageJsonFilePath === undefined
2376
+ ? getNodeModulesBinDirPath_bestEffort()
2377
+ : getNodeModulesBinDirPath_withPackageJsonFileDirPath({ packageJsonFilePath });
2378
+ }
2215
2379
  //# sourceMappingURL=nodeModulesBinDirPath.js.map
2216
2380
 
2217
2381
  /***/ }),
@@ -2252,7 +2416,9 @@ async function getIsPrettierAvailable() {
2252
2416
  if (getIsPrettierAvailable.cache !== undefined) {
2253
2417
  return getIsPrettierAvailable.cache;
2254
2418
  }
2255
- const nodeModulesBinDirPath = (0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)();
2419
+ const nodeModulesBinDirPath = (0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)({
2420
+ packageJsonFilePath: undefined
2421
+ });
2256
2422
  const prettierBinPath = (0,path__WEBPACK_IMPORTED_MODULE_1__.join)(nodeModulesBinDirPath, "prettier");
2257
2423
  const stats = await fs_promises__WEBPACK_IMPORTED_MODULE_2__.stat(prettierBinPath).catch(() => undefined);
2258
2424
  const isPrettierAvailable = (_a = stats === null || stats === void 0 ? void 0 : stats.isFile()) !== null && _a !== void 0 ? _a : false;
@@ -2272,14 +2438,14 @@ async function getPrettier() {
2272
2438
  // So we do a sketchy eval to bypass ncc.
2273
2439
  // We make sure to only do that when linking, otherwise we import properly.
2274
2440
  if ((0,_readThisNpmPackageVersion__WEBPACK_IMPORTED_MODULE_6__/* .readThisNpmPackageVersion */ .K)().startsWith("0.0.0")) {
2275
- eval(`${(0,tsafe_symToStr__WEBPACK_IMPORTED_MODULE_8__/* .symToStr */ .r)({ prettier })} = require("${(0,path__WEBPACK_IMPORTED_MODULE_1__.resolve)((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)(), "..", "prettier"))}")`);
2441
+ eval(`${(0,tsafe_symToStr__WEBPACK_IMPORTED_MODULE_8__/* .symToStr */ .r)({ prettier })} = require("${(0,path__WEBPACK_IMPORTED_MODULE_1__.resolve)((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)({ packageJsonFilePath: undefined }), "..", "prettier"))}")`);
2276
2442
  (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)(!(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__.is)(prettier));
2277
2443
  break import_prettier;
2278
2444
  }
2279
2445
  prettier = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 79421, 23));
2280
2446
  }
2281
2447
  const configHash = await (async () => {
2282
- const configFilePath = await prettier.resolveConfigFile((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)(), ".."));
2448
+ const configFilePath = await prettier.resolveConfigFile((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_0__/* .getNodeModulesBinDirPath */ .K)({ packageJsonFilePath: undefined }), ".."));
2283
2449
  if (configFilePath === null) {
2284
2450
  return "";
2285
2451
  }
package/bin/main.js CHANGED
@@ -16237,7 +16237,7 @@ program
16237
16237
  .task({
16238
16238
  skip,
16239
16239
  handler: async ({ projectDirPath }) => {
16240
- const { command } = await __nccwpck_require__.e(/* import() */ 453).then(__nccwpck_require__.bind(__nccwpck_require__, 93453));
16240
+ const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(949), __nccwpck_require__.e(453)]).then(__nccwpck_require__.bind(__nccwpck_require__, 93453));
16241
16241
  await command({ buildContext: getBuildContext({ projectDirPath }) });
16242
16242
  }
16243
16243
  });
@@ -16249,7 +16249,7 @@ program
16249
16249
  .task({
16250
16250
  skip,
16251
16251
  handler: async ({ projectDirPath }) => {
16252
- const { command } = await __nccwpck_require__.e(/* import() */ 369).then(__nccwpck_require__.bind(__nccwpck_require__, 98097));
16252
+ const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(949), __nccwpck_require__.e(369)]).then(__nccwpck_require__.bind(__nccwpck_require__, 98097));
16253
16253
  await command({ buildContext: getBuildContext({ projectDirPath }) });
16254
16254
  }
16255
16255
  });
@@ -3,6 +3,6 @@ import { type CommandName } from "./customHandler";
3
3
  export declare function maybeDelegateCommandToCustomHandler(params: {
4
4
  commandName: CommandName;
5
5
  buildContext: BuildContext;
6
- }): {
6
+ }): Promise<{
7
7
  hasBeenHandled: boolean;
8
- };
8
+ }>;
@@ -1 +1,6 @@
1
- export declare function getNodeModulesBinDirPath(): string;
1
+ export declare function getNodeModulesBinDirPath(params: {
2
+ packageJsonFilePath: string;
3
+ }): Promise<string>;
4
+ export declare function getNodeModulesBinDirPath(params: {
5
+ packageJsonFilePath: undefined;
6
+ }): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keycloakify",
3
- "version": "11.8.18",
3
+ "version": "11.8.19",
4
4
  "description": "Framework to create custom Keycloak UIs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1141,6 +1141,7 @@
1141
1141
  "bin/930.index.js",
1142
1142
  "bin/932.index.js",
1143
1143
  "bin/946.index.js",
1144
+ "bin/949.index.js",
1144
1145
  "bin/97.index.js",
1145
1146
  "bin/shared/constants.js",
1146
1147
  "bin/shared/constants.js.map",
@@ -20,7 +20,7 @@ import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_dele
20
20
  export async function command(params: { buildContext: BuildContext }) {
21
21
  const { buildContext } = params;
22
22
 
23
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
23
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
24
24
  commandName: "add-story",
25
25
  buildContext
26
26
  });
@@ -11,7 +11,7 @@ import { getThisCodebaseRootDirPath } from "./tools/getThisCodebaseRootDirPath";
11
11
  export async function command(params: { buildContext: BuildContext }) {
12
12
  const { buildContext } = params;
13
13
 
14
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
14
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
15
15
  commandName: "copy-keycloak-resources-to-public",
16
16
  buildContext
17
17
  });
@@ -22,7 +22,7 @@ import { runPrettier, getIsPrettierAvailable } from "./tools/runPrettier";
22
22
  export async function command(params: { buildContext: BuildContext }) {
23
23
  const { buildContext } = params;
24
24
 
25
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
25
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
26
26
  commandName: "eject-page",
27
27
  buildContext
28
28
  });
@@ -12,7 +12,7 @@ import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath"
12
12
  export async function command(params: { buildContext: BuildContext }) {
13
13
  const { buildContext } = params;
14
14
 
15
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
15
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
16
16
  commandName: "initialize-account-theme",
17
17
  buildContext
18
18
  });
@@ -7,7 +7,7 @@ import { command as updateKcGenCommand } from "./update-kc-gen";
7
7
  export async function command(params: { buildContext: BuildContext }) {
8
8
  const { buildContext } = params;
9
9
 
10
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
10
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
11
11
  commandName: "initialize-admin-theme",
12
12
  buildContext
13
13
  });
@@ -17,7 +17,7 @@ import chalk from "chalk";
17
17
  export async function command(params: { buildContext: BuildContext }) {
18
18
  const { buildContext } = params;
19
19
 
20
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
20
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
21
21
  commandName: "initialize-account-theme",
22
22
  buildContext
23
23
  });
@@ -13,13 +13,15 @@ import * as fs from "fs";
13
13
 
14
14
  assert<Equals<ApiVersion, "v1">>();
15
15
 
16
- export function maybeDelegateCommandToCustomHandler(params: {
16
+ export async function maybeDelegateCommandToCustomHandler(params: {
17
17
  commandName: CommandName;
18
18
  buildContext: BuildContext;
19
- }): { hasBeenHandled: boolean } {
19
+ }): Promise<{ hasBeenHandled: boolean }> {
20
20
  const { commandName, buildContext } = params;
21
21
 
22
- const nodeModulesBinDirPath = getNodeModulesBinDirPath();
22
+ const nodeModulesBinDirPath = await getNodeModulesBinDirPath({
23
+ packageJsonFilePath: buildContext.packageJsonFilePath
24
+ });
23
25
 
24
26
  if (!fs.readdirSync(nodeModulesBinDirPath).includes(BIN_NAME)) {
25
27
  return { hasBeenHandled: false };
@@ -1,10 +1,29 @@
1
- import { sep as pathSep } from "path";
1
+ import { sep as pathSep, dirname as pathDirname, join as pathJoin } from "path";
2
+ import { getThisCodebaseRootDirPath } from "./getThisCodebaseRootDirPath";
3
+ import { getInstalledModuleDirPath } from "./getInstalledModuleDirPath";
4
+ import { existsAsync } from "./fs.existsAsync";
5
+ import { z } from "zod";
6
+ import * as fs from "fs/promises";
7
+ import { assert, is, type Equals } from "tsafe/assert";
8
+ import { id } from "tsafe/id";
2
9
 
3
- let cache: string | undefined = undefined;
10
+ let cache_bestEffort: string | undefined = undefined;
4
11
 
5
- export function getNodeModulesBinDirPath() {
6
- if (cache !== undefined) {
7
- return cache;
12
+ /** NOTE: Careful, this function can fail when the binary
13
+ * Used is not in the node_modules directory of the project
14
+ * (for example when running tests with vscode extension we'll get
15
+ * '/Users/dylan/.vscode/extensions/vitest.explorer-1.16.0/dist/worker.js'
16
+ *
17
+ * instead of
18
+ * '/Users/joseph/.nvm/versions/node/v22.12.0/bin/node'
19
+ * or
20
+ * '/Users/joseph/github/keycloakify-starter/node_modules/.bin/vite'
21
+ *
22
+ * as the value of process.argv[1]
23
+ */
24
+ function getNodeModulesBinDirPath_bestEffort() {
25
+ if (cache_bestEffort !== undefined) {
26
+ return cache_bestEffort;
8
27
  }
9
28
 
10
29
  const binPath = process.argv[1];
@@ -30,9 +49,122 @@ export function getNodeModulesBinDirPath() {
30
49
  segments.unshift(segment);
31
50
  }
32
51
 
52
+ if (!foundNodeModules) {
53
+ throw new Error(`Could not find node_modules in path ${binPath}`);
54
+ }
55
+
33
56
  const nodeModulesBinDirPath = segments.join(pathSep);
34
57
 
35
- cache = nodeModulesBinDirPath;
58
+ cache_bestEffort = nodeModulesBinDirPath;
36
59
 
37
60
  return nodeModulesBinDirPath;
38
61
  }
62
+
63
+ let cache_withPackageJsonFileDirPath:
64
+ | { packageJsonFilePath: string; nodeModulesBinDirPath: string }
65
+ | undefined = undefined;
66
+
67
+ async function getNodeModulesBinDirPath_withPackageJsonFileDirPath(params: {
68
+ packageJsonFilePath: string;
69
+ }): Promise<string> {
70
+ const { packageJsonFilePath } = params;
71
+
72
+ use_cache: {
73
+ if (cache_withPackageJsonFileDirPath === undefined) {
74
+ break use_cache;
75
+ }
76
+
77
+ if (
78
+ cache_withPackageJsonFileDirPath.packageJsonFilePath !== packageJsonFilePath
79
+ ) {
80
+ cache_withPackageJsonFileDirPath = undefined;
81
+ break use_cache;
82
+ }
83
+
84
+ return cache_withPackageJsonFileDirPath.nodeModulesBinDirPath;
85
+ }
86
+
87
+ // [...]node_modules/keycloakify
88
+ const installedModuleDirPath = await getInstalledModuleDirPath({
89
+ // Here it will always be "keycloakify" but since we are in tools/ we make something generic
90
+ moduleName: await (async () => {
91
+ type ParsedPackageJson = {
92
+ name: string;
93
+ };
94
+
95
+ const zParsedPackageJson = (() => {
96
+ type TargetType = ParsedPackageJson;
97
+
98
+ const zTargetType = z.object({
99
+ name: z.string()
100
+ });
101
+
102
+ assert<Equals<z.infer<typeof zTargetType>, TargetType>>;
103
+
104
+ return id<z.ZodType<TargetType>>(zTargetType);
105
+ })();
106
+
107
+ const parsedPackageJson = JSON.parse(
108
+ (
109
+ await fs.readFile(
110
+ pathJoin(getThisCodebaseRootDirPath(), "package.json")
111
+ )
112
+ ).toString("utf8")
113
+ );
114
+
115
+ zParsedPackageJson.parse(parsedPackageJson);
116
+
117
+ assert(is<ParsedPackageJson>(parsedPackageJson));
118
+
119
+ return parsedPackageJson.name;
120
+ })(),
121
+ packageJsonDirPath: pathDirname(packageJsonFilePath)
122
+ });
123
+
124
+ const segments = installedModuleDirPath.split(pathSep);
125
+
126
+ while (true) {
127
+ const segment = segments.pop();
128
+
129
+ if (segment === undefined) {
130
+ throw new Error(
131
+ `Could not find .bin directory relative to ${packageJsonFilePath}`
132
+ );
133
+ }
134
+
135
+ if (segment !== "node_modules") {
136
+ continue;
137
+ }
138
+
139
+ const candidate = pathJoin(segments.join(pathSep), segment, ".bin");
140
+
141
+ if (!(await existsAsync(candidate))) {
142
+ continue;
143
+ }
144
+
145
+ cache_withPackageJsonFileDirPath = {
146
+ packageJsonFilePath,
147
+ nodeModulesBinDirPath: candidate
148
+ };
149
+
150
+ break;
151
+ }
152
+
153
+ return cache_withPackageJsonFileDirPath.nodeModulesBinDirPath;
154
+ }
155
+
156
+ export function getNodeModulesBinDirPath(params: {
157
+ packageJsonFilePath: string;
158
+ }): Promise<string>;
159
+ export function getNodeModulesBinDirPath(params: {
160
+ packageJsonFilePath: undefined;
161
+ }): string;
162
+ export function getNodeModulesBinDirPath(params: {
163
+ packageJsonFilePath: string | undefined;
164
+ }): string | Promise<string> {
165
+ const { packageJsonFilePath } = params ?? {};
166
+
167
+ return packageJsonFilePath === undefined
168
+ ? getNodeModulesBinDirPath_bestEffort()
169
+ : getNodeModulesBinDirPath_withPackageJsonFileDirPath({ packageJsonFilePath });
170
+ }
@@ -15,7 +15,9 @@ export async function getIsPrettierAvailable(): Promise<boolean> {
15
15
  return getIsPrettierAvailable.cache;
16
16
  }
17
17
 
18
- const nodeModulesBinDirPath = getNodeModulesBinDirPath();
18
+ const nodeModulesBinDirPath = getNodeModulesBinDirPath({
19
+ packageJsonFilePath: undefined
20
+ });
19
21
 
20
22
  const prettierBinPath = pathJoin(nodeModulesBinDirPath, "prettier");
21
23
 
@@ -51,7 +53,7 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
51
53
  // We make sure to only do that when linking, otherwise we import properly.
52
54
  if (readThisNpmPackageVersion().startsWith("0.0.0")) {
53
55
  eval(
54
- `${symToStr({ prettier })} = require("${pathResolve(pathJoin(getNodeModulesBinDirPath(), "..", "prettier"))}")`
56
+ `${symToStr({ prettier })} = require("${pathResolve(pathJoin(getNodeModulesBinDirPath({ packageJsonFilePath: undefined }), "..", "prettier"))}")`
55
57
  );
56
58
 
57
59
  assert(!is<undefined>(prettier));
@@ -64,7 +66,7 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
64
66
 
65
67
  const configHash = await (async () => {
66
68
  const configFilePath = await prettier.resolveConfigFile(
67
- pathJoin(getNodeModulesBinDirPath(), "..")
69
+ pathJoin(getNodeModulesBinDirPath({ packageJsonFilePath: undefined }), "..")
68
70
  );
69
71
 
70
72
  if (configFilePath === null) {
@@ -19,7 +19,7 @@ export async function command(params: { buildContext: BuildContext }) {
19
19
  await command({ buildContext });
20
20
  }
21
21
 
22
- const { hasBeenHandled } = maybeDelegateCommandToCustomHandler({
22
+ const { hasBeenHandled } = await maybeDelegateCommandToCustomHandler({
23
23
  commandName: "update-kc-gen",
24
24
  buildContext
25
25
  });