diff --git a/deno_dir.go b/deno_dir.go index d53bf85d84..5db85cf41c 100644 --- a/deno_dir.go +++ b/deno_dir.go @@ -12,6 +12,10 @@ import ( "strings" ) +var DenoDir string +var CacheDir string +var SrcDir string + func SourceCodeHash(filename string, sourceCodeBuf []byte) string { h := md5.New() h.Write([]byte(filename)) @@ -21,7 +25,7 @@ func SourceCodeHash(filename string, sourceCodeBuf []byte) string { func CacheFileName(filename string, sourceCodeBuf []byte) string { cacheKey := SourceCodeHash(filename, sourceCodeBuf) - return path.Join(CompileDir, cacheKey+".js") + return path.Join(CacheDir, cacheKey+".js") } // Fetches a remoteUrl but also caches it to the localFilename. @@ -87,8 +91,8 @@ func UserHomeDir() string { func createDirs() { DenoDir = path.Join(UserHomeDir(), ".deno") - CompileDir = path.Join(DenoDir, "compile") - err := os.MkdirAll(CompileDir, 0700) + CacheDir = path.Join(DenoDir, "cache") + err := os.MkdirAll(CacheDir, 0700) check(err) SrcDir = path.Join(DenoDir, "src") err = os.MkdirAll(SrcDir, 0700) diff --git a/deno_dir_test.go b/deno_dir_test.go index fa3d68aedd..2e98461eb7 100644 --- a/deno_dir_test.go +++ b/deno_dir_test.go @@ -5,16 +5,16 @@ import ( "testing" ) -func SetCompileDirForTest(prefix string) { +func SetCacheDirForTest(prefix string) { dir, err := ioutil.TempDir("", prefix) if err != nil { panic(err) } - CompileDir = dir + CacheDir = dir } func TestLoadOutputCodeCache(t *testing.T) { - SetCompileDirForTest("TestLoadOutputCodeCache") + SetCacheDirForTest("TestLoadOutputCodeCache") filename := "Hello.ts" sourceCodeBuf := []byte("1+2") diff --git a/main.go b/main.go index 68ef8fb7af..d557ab2045 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "fmt" "github.com/ry/v8worker2" "io/ioutil" "log" @@ -15,22 +14,17 @@ var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line option var flagDebug = flag.Bool("debug", false, "Enable debug output.") var flagGoProf = flag.String("goprof", "", "Write golang cpu profile to file.") -var DenoDir string -var CompileDir string -var SrcDir string - func stringAsset(path string) string { data, err := Asset("dist/" + path) check(err) return string(data) } -func main() { +func FlagsParse() []string { flag.Parse() args := flag.Args() if *flagV8Options { args = append(args, "--help") - fmt.Println(args) } args = v8worker2.SetFlags(args) @@ -38,6 +32,11 @@ func main() { if !*flagDebug { log.SetOutput(ioutil.Discard) } + return args +} + +func main() { + args := FlagsParse() // Maybe start Golang CPU profiler. // Use --prof for profiling JS.