MCPcopy Index your code
hub / github.com/angular/angular-cli / useSha

Function useSha

tests/e2e/utils/project.ts:83–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81}
82
83export async function useSha(): Promise<void> {
84 const argv = getGlobalVariable('argv');
85 if (!argv['ng-snapshots'] && !argv['ng-tag']) {
86 return;
87 }
88
89 // We need more than the sha here, version is also needed. Examples of latest tags:
90 // 7.0.0-beta.4+dd2a650
91 // 6.1.6+4a8d56a
92 const label = argv['ng-tag'] || '';
93 const ngSnapshotVersions = require('../ng-snapshot/package.json');
94
95 return updateJsonFile('package.json', (json) => {
96 // Install over the project with snapshot builds.
97 function replaceDependencies(key: string) {
98 const missingSnapshots: string[] = [];
99 Object.keys(json[key] || {})
100 .filter((name) => name.startsWith('@angular/'))
101 .forEach((name) => {
102 const pkgName = name.split(/\//)[1];
103 if (pkgName === 'cli' || pkgName === 'ssr' || pkgName === 'build') {
104 return;
105 }
106
107 if (label) {
108 json[key][`@angular/${pkgName}`] = `github:angular/${pkgName}-builds${label}`;
109 } else {
110 const replacement = ngSnapshotVersions.dependencies[`@angular/${pkgName}`];
111 if (!replacement) {
112 missingSnapshots.push(`missing @angular/${pkgName}`);
113 }
114 json[key][`@angular/${pkgName}`] = replacement;
115 }
116 });
117 if (missingSnapshots.length > 0) {
118 throw new Error(
119 'e2e test with --ng-snapshots requires all angular packages be ' +
120 'listed in tests/e2e/ng-snapshot/package.json.\nErrors:\n' +
121 missingSnapshots.join('\n '),
122 );
123 }
124 }
125
126 replaceDependencies('dependencies');
127 replaceDependencies('devDependencies');
128 });
129}
130
131export function useCIDefaults(projectName = 'test-project'): Promise<void> {
132 return updateJsonFile('angular.json', (workspaceJson) => {

Calls 3

getGlobalVariableFunction · 0.90
replaceDependenciesFunction · 0.85
updateJsonFileFunction · 0.70

Tested by

no test coverage detected