Retrieves the pnpm lock file from upstream on the primary branch and extracts the version.
()
| 69 | |
| 70 | /** Retrieves the pnpm lock file from upstream on the primary branch and extracts the version. */ |
| 71 | async function getExpectedVersionFromPnpmLockUpstream(): Promise<string> { |
| 72 | const git = await GitClient.get(); |
| 73 | try { |
| 74 | const {data} = await git.github.repos.getContent({ |
| 75 | repo: git.remoteConfig.name, |
| 76 | owner: git.remoteConfig.owner, |
| 77 | ref: git.remoteConfig.mainBranchName, |
| 78 | // This media type ensures requested files come back as the raw content. |
| 79 | mediaType: {format: 'application/vnd.github.raw+json'}, |
| 80 | path: 'pnpm-lock.yaml', |
| 81 | }); |
| 82 | if (Array.isArray(data) || data.type !== 'file') { |
| 83 | throw Error( |
| 84 | `A non-single file of content was retrieved from Github when the pnpm-lock.yaml file was requested`, |
| 85 | ); |
| 86 | } |
| 87 | const lockFile = parseYaml( |
| 88 | Buffer.from(data.content, data.encoding as BufferEncoding).toString('utf-8'), |
| 89 | ); |
| 90 | const importers = lockFile['importers']['.']; |
| 91 | const depEntry = |
| 92 | importers.dependencies?.['@angular/ng-dev'] ?? |
| 93 | importers.devDependencies?.['@angular/ng-dev'] ?? |
| 94 | importers.optionalDependencies?.['@angular/ng-dev']; |
| 95 | const packageId = tryGetPackageId(depEntry.version); |
| 96 | |
| 97 | return lockFile['packages'][`@angular/ng-dev@${packageId}`].version; |
| 98 | } catch (e) { |
| 99 | Log.debug('Could not find expected ng-dev version from `pnpm-lock.yaml` file:', e); |
| 100 | return 'unknown'; |
| 101 | } |
| 102 | } |
no test coverage detected