Skip to content

Commit 9d91d7e

Browse files
committed
chore: utils
1 parent 20a80bb commit 9d91d7e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/utils/global.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ export const getUri = (webview: Webview, extensionUri: Uri, pathList: string[])
1818
return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList));
1919
};
2020

21-
export const projectRootDirectory = () => {
22-
21+
export const projectRootDirectory = (): string => {
2322
const configuration = getConfiguration().monorepoMode.DirectoryName;
23+
const workspaceFolder = workspace.workspaceFolders?.[0]?.uri.fsPath;
2424

25-
if (!configuration) {
26-
return workspace.workspaceFolders?.[0]?.uri.fsPath;
27-
} else {
25+
if (!workspaceFolder) {
26+
throw new Error('Workspace folder not found');
27+
}
2828

29-
return workspace.workspaceFolders?.[0]?.uri.fsPath + `/` + configuration;
29+
if (configuration) {
30+
return `${workspaceFolder}/${configuration}`;
3031
}
3132

33+
return workspaceFolder;
3234
};
3335

34-
export const projectSrcDirectory = () => {
35-
if (hasSrcDir() === '/') {
36-
return projectRootDirectory();
37-
} else {
38-
return projectRootDirectory() + hasSrcDir();
39-
}
36+
37+
export const projectSrcDirectory = (): string => {
38+
const projectRootDir = projectRootDirectory();
39+
const srcDir = hasSrcDir();
40+
return srcDir === '/' ? projectRootDir : projectRootDir + srcDir;
4041
};
4142

4243
export const openExternalLink = (url: string) => {

0 commit comments

Comments
 (0)