Joseph Garrone 2024-05-19 23:17:45 +02:00
parent 9b6d1a957f
commit 06a24d35cb
2 changed files with 39 additions and 3 deletions

View File

@ -163,7 +163,10 @@ export function readBuildOptions(params: { cliCommandOptions: CliCommandOptions
return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir); return pathJoin(reactAppRootDirPath, resolvedViteConfig.buildDir);
})(); })();
const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({ reactAppRootDirPath }); const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({
reactAppRootDirPath,
"dependencyExpected": "keycloakify"
});
return { return {
"bundler": resolvedViteConfig !== undefined ? "vite" : "webpack", "bundler": resolvedViteConfig !== undefined ? "vite" : "webpack",

View File

@ -1,9 +1,10 @@
import * as child_process from "child_process"; import * as child_process from "child_process";
import { join as pathJoin, resolve as pathResolve, sep as pathSep } from "path"; import { join as pathJoin, resolve as pathResolve, sep as pathSep } from "path";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import * as fs from "fs";
export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string }) { export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string; dependencyExpected: string }) {
const { reactAppRootDirPath } = params; const { reactAppRootDirPath, dependencyExpected } = params;
const npmWorkspaceRootDirPath = (function callee(depth: number): string { const npmWorkspaceRootDirPath = (function callee(depth: number): string {
const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")])); const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]));
@ -20,6 +21,38 @@ export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string
throw error; throw error;
} }
const { isExpectedDependencyFound } = (() => {
const packageJsonFilePath = pathJoin(cwd, "package.json");
assert(fs.existsSync(packageJsonFilePath));
const parsedPackageJson = JSON.parse(fs.readFileSync(packageJsonFilePath).toString("utf8"));
let isExpectedDependencyFound = false;
for (const dependenciesOrDevDependencies of ["dependencies", "devDependencies"] as const) {
const dependencies = parsedPackageJson[dependenciesOrDevDependencies];
if (dependencies === undefined) {
continue;
}
assert(dependencies instanceof Object);
if (dependencies[dependencyExpected] === undefined) {
continue;
}
isExpectedDependencyFound = true;
}
return { isExpectedDependencyFound };
})();
if (!isExpectedDependencyFound) {
return callee(depth + 1);
}
return cwd; return cwd;
})(0); })(0);