(projectPath)
| 124 | } |
| 125 | |
| 126 | async function findWorkspaceRoot(projectPath) { |
| 127 | for (const ev of ['NPM_CONFIG_WORKSPACE_DIR', 'npm_config_workspace_dir']) { |
| 128 | if (process.env[ev]) { |
| 129 | return process.env[ev] |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | try { |
| 134 | const canonicalPath = await fs.realpath(projectPath) |
| 135 | let currentDir = canonicalPath |
| 136 | |
| 137 | while (currentDir !== path.parse(currentDir).root) { |
| 138 | if (await fileExists(path.join(currentDir, 'pnpm-workspace.yaml'))) { |
| 139 | return currentDir |
| 140 | } |
| 141 | |
| 142 | const packageJsonPath = path.join(currentDir, 'package.json') |
| 143 | if (await fileExists(packageJsonPath)) { |
| 144 | const content = await fs.readFile(packageJsonPath, 'utf8') |
| 145 | const pkg = JSON.parse(content) |
| 146 | if (pkg.workspaces) { |
| 147 | return currentDir |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | currentDir = path.dirname(currentDir) |
| 152 | } |
| 153 | |
| 154 | return null |
| 155 | } catch { |
| 156 | return null |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // --- Patch package.json --- |
| 161 |
no test coverage detected