Function: resolveWorkspaceRoot()
Makaio Framework / utils/workspace-root / resolveWorkspaceRoot
Function: resolveWorkspaceRoot()
Section titled “Function: resolveWorkspaceRoot()”resolveWorkspaceRoot(
packageDir):string
Defined in: ../../../packages/utils/src/workspace-root.ts:27
Resolve the workspace root from a package directory 2–4 levels below the root.
Supports two repo layouts:
- Nested framework checkout: repo root contains
framework/package.json; the workspace root is the nearest ancestor (up to 4 levels) that containsframework/package.json. - Standalone framework repo: repo root contains
package.jsondirectly; the workspace root is the nearest ancestor that containspackage.json.
Resolution uses two passes over bounded candidate depths (2–4 levels up):
- Nested-layout pass — prefer the shallowest candidate containing
framework/package.json(avoids overshooting into a parent workspace). - Standalone fallback — if no nested-layout marker is found, accept the
shallowest candidate containing
package.json.
The two-pass approach prevents a bare package.json above the repo root
from being mistakenly selected when the nested-layout marker is present deeper.
Parameters
Section titled “Parameters”packageDir
Section titled “packageDir”string
Absolute path to a package directory inside the repo
(e.g. the value of path.dirname(fileURLToPath(import.meta.url))).
Returns
Section titled “Returns”string
Absolute path to the workspace root.
Throws
Section titled “Throws”If neither supported repo layout is detected at any candidate depth.