1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/cli/deno_dir.rs
Bartek Iwańczuk 2e1ab82321 refactor: cleanup compiler pipeline (#2686)
* remove fetch_source_file_and_maybe_compile_async and 
  replace it with State.fetch_compiled_module

* remove SourceFile.js_source()

* introduce CompiledModule which is basically the same as
  deno::SourceInfo and represents arbitrary file that has been 
  compiled to JS module

* introduce //cli/compilers module containing all compilers

* introduce JsCompiler which is a no-op compiler
  - output is the same as input, no compilation takes place
  - it is used for MediaType::JavaScript and MediaType::Unknown

* introduce JsonCompiler that wraps JSON in default export

* support JS-to-JS compilation using checkJs
2019-07-31 13:16:03 -04:00

43 lines
1.4 KiB
Rust

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::disk_cache::DiskCache;
use dirs;
use std;
use std::path::PathBuf;
/// `DenoDir` serves as coordinator for multiple `DiskCache`s containing them
/// in single directory that can be controlled with `$DENO_DIR` env variable.
#[derive(Clone)]
pub struct DenoDir {
// Example: /Users/rld/.deno/
pub root: PathBuf,
/// Used by SourceFileFetcher to cache remote modules.
pub deps_cache: DiskCache,
/// Used by TsCompiler to cache compiler output.
pub gen_cache: DiskCache,
}
impl DenoDir {
pub fn new(custom_root: Option<PathBuf>) -> std::io::Result<Self> {
// Only setup once.
let home_dir = dirs::home_dir().expect("Could not get home directory.");
let fallback = home_dir.join(".deno");
// We use the OS cache dir because all files deno writes are cache files
// Once that changes we need to start using different roots if DENO_DIR
// is not set, and keep a single one if it is.
let default = dirs::cache_dir()
.map(|d| d.join("deno"))
.unwrap_or(fallback);
let root: PathBuf = custom_root.unwrap_or(default);
let deps_path = root.join("deps");
let gen_path = root.join("gen");
let deno_dir = Self {
root,
deps_cache: DiskCache::new(&deps_path),
gen_cache: DiskCache::new(&gen_path),
};
Ok(deno_dir)
}
}