-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathsys.go
69 lines (57 loc) · 1.5 KB
/
sys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"io"
"os"
"runtime"
"time"
"github.com/microsoft/typescript-go/internal/bundled"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/execute"
"github.com/microsoft/typescript-go/internal/tspath"
"github.com/microsoft/typescript-go/internal/vfs"
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
)
type osSys struct {
writer io.Writer
fs vfs.FS
defaultLibraryPath string
newLine string
cwd string
}
func (s *osSys) Now() time.Time {
return time.Now()
}
func (s *osSys) FS() vfs.FS {
return s.fs
}
func (s *osSys) DefaultLibraryPath() string {
return s.defaultLibraryPath
}
func (s *osSys) GetCurrentDirectory() string {
return s.cwd
}
func (s *osSys) NewLine() string {
return s.newLine
}
func (s *osSys) Writer() io.Writer {
return s.writer
}
func (s *osSys) EndWrite() {
// do nothing, this is needed in the interface for testing
// todo: revisit if improving tsc/build/watch unittest baselines
}
func newSystem() *osSys {
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting current directory: %v\n", err)
os.Exit(int(execute.ExitStatusInvalidProject_OutputsSkipped))
}
return &osSys{
cwd: tspath.NormalizePath(cwd),
fs: bundled.WrapFS(osvfs.FS()),
defaultLibraryPath: bundled.LibPath(),
writer: os.Stdout,
newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"),
}
}