@@ -7,9 +7,8 @@ import * as os from "os"
7
7
import * as path from "path"
8
8
import * as util from "util"
9
9
import xdgBasedir from "xdg-basedir"
10
- import { tmpdir } from "./constants"
11
10
12
- interface Paths {
11
+ export interface Paths {
13
12
data : string
14
13
config : string
15
14
runtime : string
@@ -23,26 +22,33 @@ export const paths = getEnvPaths()
23
22
* ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories.
24
23
*/
25
24
export function getEnvPaths ( ) : Paths {
26
- let paths : Paths
27
- if ( process . platform === "win32" ) {
28
- paths = {
29
- ...envPaths ( "code-server" , {
30
- suffix : "" ,
31
- } ) ,
32
- runtime : tmpdir ,
33
- }
34
- } else {
35
- if ( xdgBasedir . data === undefined || xdgBasedir . config === undefined ) {
36
- throw new Error ( "No home folder?" )
37
- }
38
- paths = {
39
- data : path . join ( xdgBasedir . data , "code-server" ) ,
40
- config : path . join ( xdgBasedir . config , "code-server" ) ,
41
- runtime : xdgBasedir . runtime ? path . join ( xdgBasedir . runtime , "code-server" ) : tmpdir ,
42
- }
25
+ const paths = envPaths ( "code-server" , { suffix : "" } )
26
+ const append = ( p : string ) : string => path . join ( p , "code-server" )
27
+ switch ( process . platform ) {
28
+ case "darwin" :
29
+ return {
30
+ // envPaths uses native directories so force Darwin to use the XDG spec
31
+ // to align with other CLI tools.
32
+ data : xdgBasedir . data ? append ( xdgBasedir . data ) : paths . data ,
33
+ config : xdgBasedir . config ? append ( xdgBasedir . config ) : paths . config ,
34
+ // Fall back to temp if there is no runtime dir.
35
+ runtime : xdgBasedir . runtime ? append ( xdgBasedir . runtime ) : paths . temp ,
36
+ }
37
+ case "win32" :
38
+ return {
39
+ data : paths . data ,
40
+ config : paths . config ,
41
+ // Windows doesn't have a runtime dir.
42
+ runtime : paths . temp ,
43
+ }
44
+ default :
45
+ return {
46
+ data : paths . data ,
47
+ config : paths . config ,
48
+ // Fall back to temp if there is no runtime dir.
49
+ runtime : xdgBasedir . runtime ? append ( xdgBasedir . runtime ) : paths . temp ,
50
+ }
43
51
}
44
-
45
- return paths
46
52
}
47
53
48
54
/**
0 commit comments