(cwd: string)
| 109 | } |
| 110 | |
| 111 | export async function detectMaturityConfig(cwd: string): Promise<DetectedMaturityConfig | undefined> { |
| 112 | // 1. pnpm-workspace.yaml → minimumReleaseAge (minutes) |
| 113 | const pnpmYamlPath = findUp('pnpm-workspace.yaml', { cwd }) |
| 114 | const pnpmYaml = await readYamlTop(pnpmYamlPath) |
| 115 | const pnpmExclude = readStringList(pnpmYaml?.minimumReleaseAgeExclude) |
| 116 | if (pnpmYaml && typeof pnpmYaml.minimumReleaseAge === 'number' && pnpmYaml.minimumReleaseAge > 0) { |
| 117 | const days = pnpmYaml.minimumReleaseAge / 1440 |
| 118 | debug(`maturityPeriod=${days}d from ${pnpmYamlPath} (minimumReleaseAge=${pnpmYaml.minimumReleaseAge}m, minimumReleaseAgeExclude=${JSON.stringify(pnpmExclude)})`) |
| 119 | return { maturityPeriod: days, maturityPeriodExclude: pnpmExclude } |
| 120 | } |
| 121 | |
| 122 | // 2. .yarnrc.yml → npmMinimalAgeGate (duration) |
| 123 | const yarnYamlPath = findUp('.yarnrc.yml', { cwd }) |
| 124 | const yarnYaml = await readYamlTop(yarnYamlPath) |
| 125 | const yarnExclude = readStringList(yarnYaml?.npmPreapprovedPackages) |
| 126 | if (yarnYaml && yarnYaml.npmMinimalAgeGate != null) { |
| 127 | const days = parseYarnDuration(yarnYaml.npmMinimalAgeGate) |
| 128 | if (days != null) { |
| 129 | debug(`maturityPeriod=${days}d from ${yarnYamlPath} (npmMinimalAgeGate=${JSON.stringify(yarnYaml.npmMinimalAgeGate)}, npmPreapprovedPackages=${JSON.stringify(yarnExclude)})`) |
| 130 | return { maturityPeriod: days, maturityPeriodExclude: yarnExclude } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // 3. packageManager defaults via package-manager-detector |
| 135 | const agent = await detectAgentAndVersion(cwd) |
| 136 | const parts = parseSemverParts(agent?.version) |
| 137 | if (agent && parts) { |
| 138 | if (agent.name === 'pnpm' && parts.major >= PNPM_DEFAULT_MAJOR) { |
| 139 | debug(`maturityPeriod=${DEFAULT_DAYS}d from detected ${agent.name}@${agent.version}`) |
| 140 | return { maturityPeriod: DEFAULT_DAYS, maturityPeriodExclude: pnpmExclude } |
| 141 | } |
| 142 | if (agent.name === 'yarn' && (parts.major > YARN_DEFAULT_MAJOR || (parts.major === YARN_DEFAULT_MAJOR && parts.minor >= YARN_DEFAULT_MINOR))) { |
| 143 | debug(`maturityPeriod=${DEFAULT_DAYS}d from detected ${agent.name}@${agent.version}`) |
| 144 | return { maturityPeriod: DEFAULT_DAYS, maturityPeriodExclude: yarnExclude } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if (pnpmExclude.length > 0 || yarnExclude.length > 0) |
| 149 | return { maturityPeriodExclude: [...pnpmExclude, ...yarnExclude] } |
| 150 | |
| 151 | return undefined |
| 152 | } |
| 153 | |
| 154 | export async function detectMaturityPeriod(cwd: string): Promise<number | undefined> { |
| 155 | return (await detectMaturityConfig(cwd))?.maturityPeriod |
no test coverage detected
searching dependent graphs…