Move getNpmWorkspaceRootDirPath to tools

This commit is contained in:
Joseph Garrone 2024-05-16 07:57:27 +02:00
parent ab9e163105
commit afcc3fd0ce
2 changed files with 1 additions and 25 deletions

View File

@ -3,7 +3,7 @@ import { readParsedPackageJson } from "./parsedPackageJson";
import { join as pathJoin } from "path";
import { getAbsoluteAndInOsFormatPath } from "../../tools/getAbsoluteAndInOsFormatPath";
import { getResolvedViteConfig } from "./resolvedViteConfig";
import { getNpmWorkspaceRootDirPath } from "./getNpmWorkspaceRootDirPath";
import { getNpmWorkspaceRootDirPath } from "../../tools/getNpmWorkspaceRootDirPath";
import type { CliCommandOptions } from "../../main";
/** Consolidated build option gathered form CLI arguments and config in package.json */
@ -150,8 +150,6 @@ export function readBuildOptions(params: { cliCommandOptions: CliCommandOptions
return pathJoin(reactAppRootDirPath, resolvedViteConfig.publicDir);
})(),
"cacheDirPath": (() => {
const { npmWorkspaceRootDirPath } = getNpmWorkspaceRootDirPath({ reactAppRootDirPath });
const cacheDirPath = pathJoin(
(() => {
if (process.env.XDG_CACHE_HOME !== undefined) {

View File

@ -2,26 +2,9 @@ import * as child_process from "child_process";
import { join as pathJoin, resolve as pathResolve, sep as pathSep } from "path";
import { assert } from "tsafe/assert";
let cache:
| {
reactAppRootDirPath: string;
npmWorkspaceRootDirPath: string;
}
| undefined = undefined;
export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string }) {
const { reactAppRootDirPath } = params;
use_cache: {
if (cache === undefined || cache.reactAppRootDirPath !== reactAppRootDirPath) {
break use_cache;
}
const { npmWorkspaceRootDirPath } = cache;
return { npmWorkspaceRootDirPath };
}
const npmWorkspaceRootDirPath = (function callee(depth: number): string {
const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]));
@ -40,10 +23,5 @@ export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string
return cwd;
})(0);
cache = {
reactAppRootDirPath,
npmWorkspaceRootDirPath
};
return { npmWorkspaceRootDirPath };
}