Add cache to getNpmWorkspaceRootDirPath
This commit is contained in:
@ -2,9 +2,26 @@ 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";
|
||||||
|
|
||||||
|
let cache:
|
||||||
|
| {
|
||||||
|
reactAppRootDirPath: string;
|
||||||
|
npmWorkspaceRootDirPath: string;
|
||||||
|
}
|
||||||
|
| undefined = undefined;
|
||||||
|
|
||||||
export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string }) {
|
export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string }) {
|
||||||
const { reactAppRootDirPath } = params;
|
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 npmWorkspaceRootDirPath = (function callee(depth: number): string {
|
||||||
const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]));
|
const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]));
|
||||||
|
|
||||||
@ -23,5 +40,10 @@ export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string
|
|||||||
return cwd;
|
return cwd;
|
||||||
})(0);
|
})(0);
|
||||||
|
|
||||||
|
cache = {
|
||||||
|
reactAppRootDirPath,
|
||||||
|
npmWorkspaceRootDirPath
|
||||||
|
};
|
||||||
|
|
||||||
return { npmWorkspaceRootDirPath };
|
return { npmWorkspaceRootDirPath };
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user