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

Function getWorkspace

packages/angular/cli/src/utilities/config.ts:177–212  ·  view source on GitHub ↗
(
  level: 'local' | 'global',
)

Source from the content-addressed store, hash-verified

175): Promise<AngularWorkspace | undefined>;
176
177export async function getWorkspace(
178 level: 'local' | 'global',
179): Promise<AngularWorkspace | undefined> {
180 if (cachedWorkspaces.has(level)) {
181 return cachedWorkspaces.get(level);
182 }
183
184 const configPath = level === 'local' ? await projectFilePath() : globalFilePath();
185 if (!configPath) {
186 if (level === 'global') {
187 // Unlike a local config, a global config is not mandatory.
188 // So we create an empty one in memory and keep it as such until it has been modified and saved.
189 const globalWorkspace = new AngularWorkspace(
190 { extensions: {}, projects: new workspaces.ProjectDefinitionCollection() },
191 defaultGlobalFilePath,
192 );
193
194 cachedWorkspaces.set(level, globalWorkspace);
195
196 return globalWorkspace;
197 }
198
199 cachedWorkspaces.set(level, undefined);
200
201 return undefined;
202 }
203
204 try {
205 const workspace = await AngularWorkspace.load(configPath);
206 cachedWorkspaces.set(level, workspace);
207
208 return workspace;
209 } catch (error) {
210 throw new Error(`Workspace config file cannot be loaded: ${configPath}`, { cause: error });
211 }
212}
213
214/**
215 * This method will load the workspace configuration in raw JSON format.

Callers 10

runCommandFunction · 0.90
getCompletionConfigFunction · 0.90
setCompletionConfigFunction · 0.90
setAnalyticsConfigFunction · 0.90
promptAnalyticsFunction · 0.90
getWorkspaceRawFunction · 0.70
getSchematicDefaultsFunction · 0.70
isWarningEnabledFunction · 0.70

Calls 6

projectFilePathFunction · 0.85
globalFilePathFunction · 0.85
loadMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected