Skip to content

Function: resolveWorkspaceRoot()

Makaio Framework


Makaio Framework / utils/workspace-root / 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 contains framework/package.json.
  • Standalone framework repo: repo root contains package.json directly; the workspace root is the nearest ancestor that contains package.json.

Resolution uses two passes over bounded candidate depths (2–4 levels up):

  1. Nested-layout pass — prefer the shallowest candidate containing framework/package.json (avoids overshooting into a parent workspace).
  2. 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.

string

Absolute path to a package directory inside the repo (e.g. the value of path.dirname(fileURLToPath(import.meta.url))).

string

Absolute path to the workspace root.

If neither supported repo layout is detected at any candidate depth.