MCPcopy Create free account
hub / github.com/angular/dev-infra / getExpectedVersionFromPnpmLockUpstream

Function getExpectedVersionFromPnpmLockUpstream

ng-dev/utils/version-check.ts:71–102  ·  view source on GitHub ↗

Retrieves the pnpm lock file from upstream on the primary branch and extracts the version.

()

Source from the content-addressed store, hash-verified

69 if (localVersion !== expectedVersion) {
70 Log.warn(' ⚠ Your locally installed version of the `ng-dev` tool is outdated and not');
71 Log.warn(' matching with the version in the `package.json` file.');
72 Log.warn(' Re-install the dependencies to ensure you are using the correct version.');
73 return false;
74 }
75
76 return true;
77}
78
79/** Retrieves the pnpm lock file from upstream on the primary branch and extracts the version. */
80async function getExpectedVersionFromPnpmLockUpstream(): Promise<string | null> {
81 const git = await GitClient.get();
82 try {
83 const {data} = await git.github.repos.getContent({
84 repo: git.remoteConfig.name,
85 owner: git.remoteConfig.owner,
86 ref: git.remoteConfig.mainBranchName,
87 // This media type ensures requested files come back as the raw content.
88 mediaType: {format: 'application/vnd.github.raw+json'},
89 path: 'pnpm-lock.yaml',
90 });
91 if (Array.isArray(data) || data.type !== 'file') {
92 throw Error(
93 `A non-single file of content was retrieved from Github when the pnpm-lock.yaml file was requested`,
94 );
95 }
96 const content = Buffer.from(data.content, data.encoding as BufferEncoding).toString('utf-8');
97 const expectedVersion = extractNgDevVersionFromPnpmLock(content);
98 if (expectedVersion === null) {
99 throw Error('Could not find @angular/ng-dev entry in pnpm-lock.yaml');
100 }
101
102 return expectedVersion;
103 } catch (e) {
104 Log.debug('Could not find expected ng-dev version from `pnpm-lock.yaml` file:', e);
105 return null;

Callers 1

Calls 2

getMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected