MCPcopy
hub / github.com/angular/angular-cli / readWorkspace

Function readWorkspace

packages/angular_devkit/core/src/workspace/core.ts:60–112  ·  view source on GitHub ↗
(
  path: string,
  host: WorkspaceHost,
  format?: WorkspaceFormat,
  // return type will eventually have a `diagnostics` property as well
)

Source from the content-addressed store, hash-verified

58 * the `workspace` property.
59 */
60export async function readWorkspace(
61 path: string,
62 host: WorkspaceHost,
63 format?: WorkspaceFormat,
64 // return type will eventually have a `diagnostics` property as well
65): Promise<{ workspace: WorkspaceDefinition }> {
66 if (await host.isDirectory(path)) {
67 // TODO: Warn if multiple found (requires diagnostics support)
68 const directory = normalize(path);
69 let found = false;
70 for (const [name, nameFormat] of Object.entries(workspaceFiles)) {
71 if (format !== undefined && format !== nameFormat) {
72 continue;
73 }
74
75 const potential = getSystemPath(join(directory, name));
76 if (await host.isFile(potential)) {
77 path = potential;
78 format = nameFormat;
79 found = true;
80 break;
81 }
82 }
83 if (!found) {
84 throw new Error(
85 'Unable to locate a workspace file for workspace path. Are you missing an `angular.json`' +
86 ' or `.angular.json` file?',
87 );
88 }
89 } else if (format === undefined) {
90 const filename = basename(normalize(path));
91 if (filename in workspaceFiles) {
92 format = workspaceFiles[filename];
93 }
94 }
95
96 if (format === undefined) {
97 throw new Error('Unable to determine format for workspace path.');
98 }
99
100 let workspace;
101 switch (format) {
102 case WorkspaceFormat.JSON:
103 workspace = await readJsonWorkspace(path, host);
104 break;
105 default:
106 throw new Error('Unsupported workspace format.');
107 }
108
109 formatLookup.set(workspace, WorkspaceFormat.JSON);
110
111 return { workspace };
112}
113
114/**
115 * Writes a `WorkspaceDefinition` to the underlying storage via the provided `WorkspaceHost`.

Callers 8

core_spec.tsFile · 0.90
workspace_spec.tsFile · 0.85
getLegacyOutputPathsFunction · 0.85
addServerFileFunction · 0.85
index.tsFile · 0.85

Calls 9

normalizeFunction · 0.90
getSystemPathFunction · 0.90
joinFunction · 0.90
basenameFunction · 0.90
readJsonWorkspaceFunction · 0.90
isDirectoryMethod · 0.65
isFileMethod · 0.65
entriesMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected