mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
Merge the --recompile and --reload flags (#2003)
This commit is contained in:
parent
51abcd6147
commit
c25e262b04
15 changed files with 188 additions and 194 deletions
|
@ -84,6 +84,10 @@ pub struct ModuleMetaData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleMetaData {
|
impl ModuleMetaData {
|
||||||
|
pub fn has_output_code_and_source_map(&self) -> bool {
|
||||||
|
self.maybe_output_code.is_some() && self.maybe_source_map.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn js_source(&self) -> String {
|
pub fn js_source(&self) -> String {
|
||||||
if self.media_type == msg::MediaType::Json {
|
if self.media_type == msg::MediaType::Json {
|
||||||
return format!(
|
return format!(
|
||||||
|
|
318
cli/deno_dir.rs
318
cli/deno_dir.rs
|
@ -48,22 +48,12 @@ pub struct DenoDir {
|
||||||
// This splits to http and https deps
|
// This splits to http and https deps
|
||||||
pub deps_http: PathBuf,
|
pub deps_http: PathBuf,
|
||||||
pub deps_https: PathBuf,
|
pub deps_https: PathBuf,
|
||||||
// If remote resources should be reloaded.
|
|
||||||
reload: bool,
|
|
||||||
// recompile the typescript files.
|
|
||||||
// if true, not load cache files
|
|
||||||
// else, load cache files
|
|
||||||
recompile: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DenoDir {
|
impl DenoDir {
|
||||||
// Must be called before using any function from this module.
|
// Must be called before using any function from this module.
|
||||||
// https://github.com/denoland/deno/blob/golang/deno_dir.go#L99-L111
|
// https://github.com/denoland/deno/blob/golang/deno_dir.go#L99-L111
|
||||||
pub fn new(
|
pub fn new(custom_root: Option<PathBuf>) -> std::io::Result<Self> {
|
||||||
reload: bool,
|
|
||||||
recompile: bool,
|
|
||||||
custom_root: Option<PathBuf>,
|
|
||||||
) -> std::io::Result<Self> {
|
|
||||||
// Only setup once.
|
// Only setup once.
|
||||||
let home_dir = dirs::home_dir().expect("Could not get home directory.");
|
let home_dir = dirs::home_dir().expect("Could not get home directory.");
|
||||||
let fallback = home_dir.join(".deno");
|
let fallback = home_dir.join(".deno");
|
||||||
|
@ -86,8 +76,6 @@ impl DenoDir {
|
||||||
deps,
|
deps,
|
||||||
deps_http,
|
deps_http,
|
||||||
deps_https,
|
deps_https,
|
||||||
reload,
|
|
||||||
recompile,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO Lazily create these directories.
|
// TODO Lazily create these directories.
|
||||||
|
@ -143,79 +131,11 @@ impl DenoDir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_source_code_async(
|
|
||||||
self: &Self,
|
|
||||||
module_name: &str,
|
|
||||||
filename: &str,
|
|
||||||
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
|
|
||||||
let filename = filename.to_string();
|
|
||||||
let module_name = module_name.to_string();
|
|
||||||
let is_module_remote = is_remote(&module_name);
|
|
||||||
// We try fetch local. Two cases:
|
|
||||||
// 1. This is a remote module, but no reload provided
|
|
||||||
// 2. This is a local module
|
|
||||||
if !is_module_remote || !self.reload {
|
|
||||||
debug!(
|
|
||||||
"fetch local or reload {} is_module_remote {}",
|
|
||||||
module_name, is_module_remote
|
|
||||||
);
|
|
||||||
// Note that local fetch is done synchronously.
|
|
||||||
match fetch_local_source(&module_name, &filename) {
|
|
||||||
Ok(Some(output)) => {
|
|
||||||
debug!("found local source ");
|
|
||||||
return Either::A(futures::future::ok(output));
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
debug!("fetch_local_source returned None");
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
return Either::A(futures::future::err(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If not remote file, stop here!
|
|
||||||
if !is_module_remote {
|
|
||||||
debug!("not remote file stop here");
|
|
||||||
return Either::A(futures::future::err(DenoError::from(
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
format!("cannot find local file '{}'", &filename),
|
|
||||||
),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("is remote but didn't find module");
|
|
||||||
|
|
||||||
let filename2 = filename.clone();
|
|
||||||
// not cached/local, try remote
|
|
||||||
let f = fetch_remote_source_async(&module_name, &filename).and_then(
|
|
||||||
move |maybe_remote_source| match maybe_remote_source {
|
|
||||||
Some(output) => Ok(output),
|
|
||||||
None => Err(DenoError::from(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
|
||||||
format!("cannot find remote file '{}'", &filename2),
|
|
||||||
))),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Either::B(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
/// Synchronous version of get_source_code_async
|
|
||||||
/// This function is deprecated.
|
|
||||||
fn get_source_code(
|
|
||||||
self: &Self,
|
|
||||||
module_name: &str,
|
|
||||||
filename: &str,
|
|
||||||
) -> DenoResult<ModuleMetaData> {
|
|
||||||
tokio_util::block_on(self.get_source_code_async(module_name, filename))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fetch_module_meta_data_async(
|
pub fn fetch_module_meta_data_async(
|
||||||
self: &Self,
|
self: &Self,
|
||||||
specifier: &str,
|
specifier: &str,
|
||||||
referrer: &str,
|
referrer: &str,
|
||||||
|
use_cache: bool,
|
||||||
) -> impl Future<Item = ModuleMetaData, Error = errors::DenoError> {
|
) -> impl Future<Item = ModuleMetaData, Error = errors::DenoError> {
|
||||||
debug!(
|
debug!(
|
||||||
"fetch_module_meta_data. specifier {} referrer {}",
|
"fetch_module_meta_data. specifier {} referrer {}",
|
||||||
|
@ -232,11 +152,9 @@ impl DenoDir {
|
||||||
let (module_name, filename) = result.unwrap();
|
let (module_name, filename) = result.unwrap();
|
||||||
|
|
||||||
let gen = self.gen.clone();
|
let gen = self.gen.clone();
|
||||||
let recompile = self.recompile;
|
|
||||||
|
|
||||||
Either::B(
|
Either::B(
|
||||||
self
|
get_source_code_async(module_name.as_str(), filename.as_str(), use_cache)
|
||||||
.get_source_code_async(module_name.as_str(), filename.as_str())
|
|
||||||
.then(move |result| {
|
.then(move |result| {
|
||||||
let mut out = match result {
|
let mut out = match result {
|
||||||
Ok(out) => out,
|
Ok(out) => out,
|
||||||
|
@ -260,7 +178,9 @@ impl DenoDir {
|
||||||
out.source_code = filter_shebang(out.source_code);
|
out.source_code = filter_shebang(out.source_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if out.media_type != msg::MediaType::TypeScript {
|
// If TypeScript we have to also load corresponding compile js and
|
||||||
|
// source maps (called output_code and output_source_map)
|
||||||
|
if out.media_type != msg::MediaType::TypeScript || !use_cache {
|
||||||
return Ok(out);
|
return Ok(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,41 +191,28 @@ impl DenoDir {
|
||||||
gen.join(cache_key.to_string() + ".js.map"),
|
gen.join(cache_key.to_string() + ".js.map"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut maybe_output_code = None;
|
let result =
|
||||||
let mut maybe_source_map = None;
|
load_cache2(&output_code_filename, &output_source_map_filename);
|
||||||
|
match result {
|
||||||
if !recompile {
|
Err(err) => {
|
||||||
let result =
|
if err.kind() == std::io::ErrorKind::NotFound {
|
||||||
load_cache2(&output_code_filename, &output_source_map_filename);
|
// If there's no compiled JS or source map, that's ok, just
|
||||||
match result {
|
// return what we have.
|
||||||
Err(err) => {
|
Ok(out)
|
||||||
if err.kind() == std::io::ErrorKind::NotFound {
|
} else {
|
||||||
return Ok(out);
|
Err(err.into())
|
||||||
} else {
|
|
||||||
return Err(err.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok((output_code, source_map)) => {
|
|
||||||
maybe_output_code = Some(output_code);
|
|
||||||
maybe_source_map = Some(source_map);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok((output_code, source_map)) => {
|
||||||
|
out.maybe_output_code = Some(output_code);
|
||||||
|
out.maybe_source_map = Some(source_map);
|
||||||
|
out.maybe_output_code_filename =
|
||||||
|
Some(output_code_filename.to_str().unwrap().to_string());
|
||||||
|
out.maybe_source_map_filename =
|
||||||
|
Some(output_source_map_filename.to_str().unwrap().to_string());
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ModuleMetaData {
|
|
||||||
module_name: out.module_name,
|
|
||||||
filename: out.filename,
|
|
||||||
media_type: out.media_type,
|
|
||||||
source_code: out.source_code,
|
|
||||||
maybe_output_code_filename: output_code_filename
|
|
||||||
.to_str()
|
|
||||||
.map(String::from),
|
|
||||||
maybe_output_code,
|
|
||||||
maybe_source_map_filename: output_source_map_filename
|
|
||||||
.to_str()
|
|
||||||
.map(String::from),
|
|
||||||
maybe_source_map,
|
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -316,8 +223,11 @@ impl DenoDir {
|
||||||
self: &Self,
|
self: &Self,
|
||||||
specifier: &str,
|
specifier: &str,
|
||||||
referrer: &str,
|
referrer: &str,
|
||||||
|
use_cache: bool,
|
||||||
) -> Result<ModuleMetaData, errors::DenoError> {
|
) -> Result<ModuleMetaData, errors::DenoError> {
|
||||||
tokio_util::block_on(self.fetch_module_meta_data_async(specifier, referrer))
|
tokio_util::block_on(
|
||||||
|
self.fetch_module_meta_data_async(specifier, referrer, use_cache),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prototype: https://github.com/denoland/deno/blob/golang/os.go#L56-L68
|
// Prototype: https://github.com/denoland/deno/blob/golang/os.go#L56-L68
|
||||||
|
@ -419,7 +329,7 @@ impl DenoDir {
|
||||||
|
|
||||||
impl SourceMapGetter for DenoDir {
|
impl SourceMapGetter for DenoDir {
|
||||||
fn get_source_map(&self, script_name: &str) -> Option<Vec<u8>> {
|
fn get_source_map(&self, script_name: &str) -> Option<Vec<u8>> {
|
||||||
match self.fetch_module_meta_data(script_name, ".") {
|
match self.fetch_module_meta_data(script_name, ".", true) {
|
||||||
Err(_e) => None,
|
Err(_e) => None,
|
||||||
Ok(out) => match out.maybe_source_map {
|
Ok(out) => match out.maybe_source_map {
|
||||||
None => None,
|
None => None,
|
||||||
|
@ -429,6 +339,86 @@ impl SourceMapGetter for DenoDir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This fetches source code, locally or remotely.
|
||||||
|
/// module_name is the URL specifying the module.
|
||||||
|
/// filename is the local path to the module (if remote, it is in the cache
|
||||||
|
/// folder, and potentially does not exist yet)
|
||||||
|
///
|
||||||
|
/// It *does not* fill the compiled JS nor source map portions of
|
||||||
|
/// ModuleMetaData. This is the only difference between this function and
|
||||||
|
/// fetch_module_meta_data_async(). TODO(ry) change return type to reflect this
|
||||||
|
/// fact.
|
||||||
|
///
|
||||||
|
/// If this is a remote module, and it has not yet been cached, the resulting
|
||||||
|
/// download will be written to "filename". This happens no matter the value of
|
||||||
|
/// use_cache.
|
||||||
|
fn get_source_code_async(
|
||||||
|
module_name: &str,
|
||||||
|
filename: &str,
|
||||||
|
use_cache: bool,
|
||||||
|
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
|
||||||
|
let filename = filename.to_string();
|
||||||
|
let module_name = module_name.to_string();
|
||||||
|
let is_module_remote = is_remote(&module_name);
|
||||||
|
// We try fetch local. Two cases:
|
||||||
|
// 1. This is a remote module and we're allowed to use cached downloads
|
||||||
|
// 2. This is a local module
|
||||||
|
if !is_module_remote || use_cache {
|
||||||
|
debug!(
|
||||||
|
"fetch local or reload {} is_module_remote {}",
|
||||||
|
module_name, is_module_remote
|
||||||
|
);
|
||||||
|
// Note that local fetch is done synchronously.
|
||||||
|
match fetch_local_source(&module_name, &filename) {
|
||||||
|
Ok(Some(output)) => {
|
||||||
|
debug!("found local source ");
|
||||||
|
return Either::A(futures::future::ok(output));
|
||||||
|
}
|
||||||
|
Ok(None) => {
|
||||||
|
debug!("fetch_local_source returned None");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Either::A(futures::future::err(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not remote file, stop here!
|
||||||
|
if !is_module_remote {
|
||||||
|
debug!("not remote file stop here");
|
||||||
|
return Either::A(futures::future::err(DenoError::from(
|
||||||
|
std::io::Error::new(
|
||||||
|
std::io::ErrorKind::NotFound,
|
||||||
|
format!("cannot find local file '{}'", &filename),
|
||||||
|
),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("is remote but didn't find module");
|
||||||
|
|
||||||
|
// not cached/local, try remote
|
||||||
|
Either::B(fetch_remote_source_async(&module_name, &filename).and_then(
|
||||||
|
move |maybe_remote_source| match maybe_remote_source {
|
||||||
|
Some(output) => Ok(output),
|
||||||
|
None => Err(DenoError::from(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::NotFound,
|
||||||
|
format!("cannot find remote file '{}'", &filename),
|
||||||
|
))),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
/// Synchronous version of get_source_code_async
|
||||||
|
/// This function is deprecated.
|
||||||
|
fn get_source_code(
|
||||||
|
module_name: &str,
|
||||||
|
filename: &str,
|
||||||
|
use_cache: bool,
|
||||||
|
) -> DenoResult<ModuleMetaData> {
|
||||||
|
tokio_util::block_on(get_source_code_async(module_name, filename, use_cache))
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cache_filename(basedir: &Path, url: &Url) -> PathBuf {
|
fn get_cache_filename(basedir: &Path, url: &Url) -> PathBuf {
|
||||||
let host = url.host_str().unwrap();
|
let host = url.host_str().unwrap();
|
||||||
let host_port = match url.port() {
|
let host_port = match url.port() {
|
||||||
|
@ -557,10 +547,9 @@ fn fetch_remote_source_async(
|
||||||
// cached file, containing just the media type.
|
// cached file, containing just the media type.
|
||||||
let media_type_filename = [&filename, ".mime"].concat();
|
let media_type_filename = [&filename, ".mime"].concat();
|
||||||
let mt = PathBuf::from(&media_type_filename);
|
let mt = PathBuf::from(&media_type_filename);
|
||||||
eprint!("Downloading {}...", &module_name); // no newline
|
eprintln!("Downloading {}", &module_name);
|
||||||
http_util::fetch_string(&module_name).and_then(
|
http_util::fetch_string(&module_name).and_then(
|
||||||
move |(source, content_type)| {
|
move |(source, content_type)| {
|
||||||
eprintln!(""); // next line
|
|
||||||
match p.parent() {
|
match p.parent() {
|
||||||
Some(ref parent) => fs::create_dir_all(parent),
|
Some(ref parent) => fs::create_dir_all(parent),
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
|
@ -646,11 +635,10 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
fn test_setup(reload: bool, recompile: bool) -> (TempDir, DenoDir) {
|
fn test_setup() -> (TempDir, DenoDir) {
|
||||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||||
let deno_dir =
|
let deno_dir =
|
||||||
DenoDir::new(reload, recompile, Some(temp_dir.path().to_path_buf()))
|
DenoDir::new(Some(temp_dir.path().to_path_buf())).expect("setup fail");
|
||||||
.expect("setup fail");
|
|
||||||
(temp_dir, deno_dir)
|
(temp_dir, deno_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,7 +678,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cache_path() {
|
fn test_cache_path() {
|
||||||
let (temp_dir, deno_dir) = test_setup(false, false);
|
let (temp_dir, deno_dir) = test_setup();
|
||||||
let filename = "hello.js";
|
let filename = "hello.js";
|
||||||
let source_code = b"1+2";
|
let source_code = b"1+2";
|
||||||
let hash = source_code_hash(filename, source_code, version::DENO);
|
let hash = source_code_hash(filename, source_code, version::DENO);
|
||||||
|
@ -705,7 +693,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_code_cache() {
|
fn test_code_cache() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let filename = "hello.js";
|
let filename = "hello.js";
|
||||||
let source_code = b"1+2";
|
let source_code = b"1+2";
|
||||||
|
@ -759,7 +747,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_source_code_1() {
|
fn test_get_source_code_1() {
|
||||||
let (temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
// http_util::fetch_sync_string requires tokio
|
// http_util::fetch_sync_string requires tokio
|
||||||
tokio_util::init(|| {
|
tokio_util::init(|| {
|
||||||
let module_name = "http://localhost:4545/tests/subdir/mod2.ts";
|
let module_name = "http://localhost:4545/tests/subdir/mod2.ts";
|
||||||
|
@ -771,8 +759,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let mime_file_name = format!("{}.mime", &filename);
|
let mime_file_name = format!("{}.mime", &filename);
|
||||||
|
|
||||||
let result = deno_dir.get_source_code(module_name, &filename);
|
let result = get_source_code(module_name, &filename, true);
|
||||||
println!("module_name {} filename {}", module_name, filename);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -785,7 +772,7 @@ mod tests {
|
||||||
|
|
||||||
// Modify .mime
|
// Modify .mime
|
||||||
let _ = fs::write(&mime_file_name, "text/javascript");
|
let _ = fs::write(&mime_file_name, "text/javascript");
|
||||||
let result2 = deno_dir.get_source_code(module_name, &filename);
|
let result2 = get_source_code(module_name, &filename, true);
|
||||||
assert!(result2.is_ok());
|
assert!(result2.is_ok());
|
||||||
let r2 = result2.unwrap();
|
let r2 = result2.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -800,11 +787,8 @@ mod tests {
|
||||||
"text/javascript"
|
"text/javascript"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Force self.reload
|
// Don't use_cache
|
||||||
let deno_dir =
|
let result3 = get_source_code(module_name, &filename, false);
|
||||||
DenoDir::new(true, false, Some(temp_dir.path().to_path_buf()))
|
|
||||||
.expect("setup fail");
|
|
||||||
let result3 = deno_dir.get_source_code(module_name, &filename);
|
|
||||||
assert!(result3.is_ok());
|
assert!(result3.is_ok());
|
||||||
let r3 = result3.unwrap();
|
let r3 = result3.unwrap();
|
||||||
let expected3 =
|
let expected3 =
|
||||||
|
@ -818,7 +802,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_source_code_2() {
|
fn test_get_source_code_2() {
|
||||||
let (temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
// http_util::fetch_sync_string requires tokio
|
// http_util::fetch_sync_string requires tokio
|
||||||
tokio_util::init(|| {
|
tokio_util::init(|| {
|
||||||
let module_name = "http://localhost:4545/tests/subdir/mismatch_ext.ts";
|
let module_name = "http://localhost:4545/tests/subdir/mismatch_ext.ts";
|
||||||
|
@ -830,8 +814,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let mime_file_name = format!("{}.mime", &filename);
|
let mime_file_name = format!("{}.mime", &filename);
|
||||||
|
|
||||||
let result = deno_dir.get_source_code(module_name, &filename);
|
let result = get_source_code(module_name, &filename, true);
|
||||||
println!("module_name {} filename {}", module_name, filename);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
let expected = "export const loaded = true;\n".as_bytes();
|
let expected = "export const loaded = true;\n".as_bytes();
|
||||||
|
@ -845,7 +828,7 @@ mod tests {
|
||||||
|
|
||||||
// Modify .mime
|
// Modify .mime
|
||||||
let _ = fs::write(&mime_file_name, "text/typescript");
|
let _ = fs::write(&mime_file_name, "text/typescript");
|
||||||
let result2 = deno_dir.get_source_code(module_name, &filename);
|
let result2 = get_source_code(module_name, &filename, true);
|
||||||
assert!(result2.is_ok());
|
assert!(result2.is_ok());
|
||||||
let r2 = result2.unwrap();
|
let r2 = result2.unwrap();
|
||||||
let expected2 = "export const loaded = true;\n".as_bytes();
|
let expected2 = "export const loaded = true;\n".as_bytes();
|
||||||
|
@ -858,11 +841,8 @@ mod tests {
|
||||||
"text/typescript"
|
"text/typescript"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Force self.reload
|
// Don't use_cache
|
||||||
let deno_dir =
|
let result3 = get_source_code(module_name, &filename, false);
|
||||||
DenoDir::new(true, false, Some(temp_dir.path().to_path_buf()))
|
|
||||||
.expect("setup fail");
|
|
||||||
let result3 = deno_dir.get_source_code(module_name, &filename);
|
|
||||||
assert!(result3.is_ok());
|
assert!(result3.is_ok());
|
||||||
let r3 = result3.unwrap();
|
let r3 = result3.unwrap();
|
||||||
let expected3 = "export const loaded = true;\n".as_bytes();
|
let expected3 = "export const loaded = true;\n".as_bytes();
|
||||||
|
@ -882,7 +862,7 @@ mod tests {
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
// http_util::fetch_sync_string requires tokio
|
// http_util::fetch_sync_string requires tokio
|
||||||
tokio_util::init(|| {
|
tokio_util::init(|| {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
let module_name =
|
let module_name =
|
||||||
"http://127.0.0.1:4545/tests/subdir/mt_video_mp2t.t3.ts".to_string();
|
"http://127.0.0.1:4545/tests/subdir/mt_video_mp2t.t3.ts".to_string();
|
||||||
let filename = deno_fs::normalize_path(
|
let filename = deno_fs::normalize_path(
|
||||||
|
@ -920,7 +900,7 @@ mod tests {
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
// http_util::fetch_sync_string requires tokio
|
// http_util::fetch_sync_string requires tokio
|
||||||
tokio_util::init(|| {
|
tokio_util::init(|| {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
let module_name =
|
let module_name =
|
||||||
"http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts";
|
"http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts";
|
||||||
let filename = deno_fs::normalize_path(
|
let filename = deno_fs::normalize_path(
|
||||||
|
@ -955,7 +935,7 @@ mod tests {
|
||||||
use crate::tokio_util;
|
use crate::tokio_util;
|
||||||
// http_util::fetch_sync_string requires tokio
|
// http_util::fetch_sync_string requires tokio
|
||||||
tokio_util::init(|| {
|
tokio_util::init(|| {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
let module_name = "http://localhost:4545/tests/subdir/no_ext";
|
let module_name = "http://localhost:4545/tests/subdir/no_ext";
|
||||||
let filename = deno_fs::normalize_path(
|
let filename = deno_fs::normalize_path(
|
||||||
deno_dir
|
deno_dir
|
||||||
|
@ -1019,7 +999,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fetch_source_3() {
|
fn test_fetch_source_3() {
|
||||||
// only local, no http_util::fetch_sync_string called
|
// only local, no http_util::fetch_sync_string called
|
||||||
let (_temp_dir, _deno_dir) = test_setup(false, false);
|
let (_temp_dir, _deno_dir) = test_setup();
|
||||||
let cwd = std::env::current_dir().unwrap();
|
let cwd = std::env::current_dir().unwrap();
|
||||||
let cwd_string = cwd.to_str().unwrap();
|
let cwd_string = cwd.to_str().unwrap();
|
||||||
let module_name = "http://example.com/mt_text_typescript.t1.ts"; // not used
|
let module_name = "http://example.com/mt_text_typescript.t1.ts"; // not used
|
||||||
|
@ -1035,7 +1015,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fetch_module_meta_data() {
|
fn test_fetch_module_meta_data() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let cwd = std::env::current_dir().unwrap();
|
let cwd = std::env::current_dir().unwrap();
|
||||||
let cwd_string = String::from(cwd.to_str().unwrap()) + "/";
|
let cwd_string = String::from(cwd.to_str().unwrap()) + "/";
|
||||||
|
@ -1044,23 +1024,21 @@ mod tests {
|
||||||
// Test failure case.
|
// Test failure case.
|
||||||
let specifier = "hello.ts";
|
let specifier = "hello.ts";
|
||||||
let referrer = add_root!("/baddir/badfile.ts");
|
let referrer = add_root!("/baddir/badfile.ts");
|
||||||
let r = deno_dir.fetch_module_meta_data(specifier, referrer);
|
let r = deno_dir.fetch_module_meta_data(specifier, referrer, true);
|
||||||
assert!(r.is_err());
|
assert!(r.is_err());
|
||||||
|
|
||||||
// Assuming cwd is the deno repo root.
|
// Assuming cwd is the deno repo root.
|
||||||
let specifier = "./js/main.ts";
|
let specifier = "./js/main.ts";
|
||||||
let referrer = cwd_string.as_str();
|
let referrer = cwd_string.as_str();
|
||||||
let r = deno_dir.fetch_module_meta_data(specifier, referrer);
|
let r = deno_dir.fetch_module_meta_data(specifier, referrer, true);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
//let fetch_module_meta_data_output = r.unwrap();
|
|
||||||
//println!("fetch_module_meta_data_output {:?}", fetch_module_meta_data_output);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fetch_module_meta_data_1() {
|
fn test_fetch_module_meta_data_1() {
|
||||||
/*recompile ts file*/
|
/*recompile ts file*/
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, true);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let cwd = std::env::current_dir().unwrap();
|
let cwd = std::env::current_dir().unwrap();
|
||||||
let cwd_string = String::from(cwd.to_str().unwrap()) + "/";
|
let cwd_string = String::from(cwd.to_str().unwrap()) + "/";
|
||||||
|
@ -1069,20 +1047,20 @@ mod tests {
|
||||||
// Test failure case.
|
// Test failure case.
|
||||||
let specifier = "hello.ts";
|
let specifier = "hello.ts";
|
||||||
let referrer = add_root!("/baddir/badfile.ts");
|
let referrer = add_root!("/baddir/badfile.ts");
|
||||||
let r = deno_dir.fetch_module_meta_data(specifier, referrer);
|
let r = deno_dir.fetch_module_meta_data(specifier, referrer, false);
|
||||||
assert!(r.is_err());
|
assert!(r.is_err());
|
||||||
|
|
||||||
// Assuming cwd is the deno repo root.
|
// Assuming cwd is the deno repo root.
|
||||||
let specifier = "./js/main.ts";
|
let specifier = "./js/main.ts";
|
||||||
let referrer = cwd_string.as_str();
|
let referrer = cwd_string.as_str();
|
||||||
let r = deno_dir.fetch_module_meta_data(specifier, referrer);
|
let r = deno_dir.fetch_module_meta_data(specifier, referrer, false);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_src_file_to_url_1() {
|
fn test_src_file_to_url_1() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
assert_eq!("hello", deno_dir.src_file_to_url("hello"));
|
assert_eq!("hello", deno_dir.src_file_to_url("hello"));
|
||||||
assert_eq!("/hello", deno_dir.src_file_to_url("/hello"));
|
assert_eq!("/hello", deno_dir.src_file_to_url("/hello"));
|
||||||
let x = deno_dir.deps_http.join("hello/world.txt");
|
let x = deno_dir.deps_http.join("hello/world.txt");
|
||||||
|
@ -1094,7 +1072,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_src_file_to_url_2() {
|
fn test_src_file_to_url_2() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
assert_eq!("hello", deno_dir.src_file_to_url("hello"));
|
assert_eq!("hello", deno_dir.src_file_to_url("hello"));
|
||||||
assert_eq!("/hello", deno_dir.src_file_to_url("/hello"));
|
assert_eq!("/hello", deno_dir.src_file_to_url("/hello"));
|
||||||
let x = deno_dir.deps_https.join("hello/world.txt");
|
let x = deno_dir.deps_https.join("hello/world.txt");
|
||||||
|
@ -1106,7 +1084,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_src_file_to_url_3() {
|
fn test_src_file_to_url_3() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
let x = deno_dir.deps_http.join("localhost_PORT4545/world.txt");
|
let x = deno_dir.deps_http.join("localhost_PORT4545/world.txt");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"http://localhost:4545/world.txt",
|
"http://localhost:4545/world.txt",
|
||||||
|
@ -1116,7 +1094,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_src_file_to_url_4() {
|
fn test_src_file_to_url_4() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
let x = deno_dir.deps_https.join("localhost_PORT4545/world.txt");
|
let x = deno_dir.deps_https.join("localhost_PORT4545/world.txt");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"https://localhost:4545/world.txt",
|
"https://localhost:4545/world.txt",
|
||||||
|
@ -1127,7 +1105,7 @@ mod tests {
|
||||||
// https://github.com/denoland/deno/blob/golang/os_test.go#L16-L87
|
// https://github.com/denoland/deno/blob/golang/os_test.go#L16-L87
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_1() {
|
fn test_resolve_module_1() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let test_cases = [
|
let test_cases = [
|
||||||
(
|
(
|
||||||
|
@ -1167,7 +1145,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_2() {
|
fn test_resolve_module_2() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "http://localhost:4545/testdata/subdir/print_hello.ts";
|
let specifier = "http://localhost:4545/testdata/subdir/print_hello.ts";
|
||||||
let referrer = add_root!("/deno/testdata/006_url_imports.ts");
|
let referrer = add_root!("/deno/testdata/006_url_imports.ts");
|
||||||
|
@ -1189,7 +1167,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_3() {
|
fn test_resolve_module_3() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier_ =
|
let specifier_ =
|
||||||
deno_dir.deps_http.join("unpkg.com/liltest@0.0.5/index.ts");
|
deno_dir.deps_http.join("unpkg.com/liltest@0.0.5/index.ts");
|
||||||
|
@ -1212,7 +1190,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_4() {
|
fn test_resolve_module_4() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "./util";
|
let specifier = "./util";
|
||||||
let referrer_ = deno_dir.deps_http.join("unpkg.com/liltest@0.0.5/index.ts");
|
let referrer_ = deno_dir.deps_http.join("unpkg.com/liltest@0.0.5/index.ts");
|
||||||
|
@ -1235,7 +1213,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_5() {
|
fn test_resolve_module_5() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "./util";
|
let specifier = "./util";
|
||||||
let referrer_ =
|
let referrer_ =
|
||||||
|
@ -1259,7 +1237,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_6() {
|
fn test_resolve_module_6() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "http://localhost:4545/tests/subdir/mod2.ts";
|
let specifier = "http://localhost:4545/tests/subdir/mod2.ts";
|
||||||
let referrer = add_root!("/deno/tests/006_url_imports.ts");
|
let referrer = add_root!("/deno/tests/006_url_imports.ts");
|
||||||
|
@ -1279,7 +1257,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_7() {
|
fn test_resolve_module_7() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "http_test.ts";
|
let specifier = "http_test.ts";
|
||||||
let referrer = add_root!("/Users/rld/src/deno_net/");
|
let referrer = add_root!("/Users/rld/src/deno_net/");
|
||||||
|
@ -1295,7 +1273,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_referrer_dot() {
|
fn test_resolve_module_referrer_dot() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "tests/001_hello.js";
|
let specifier = "tests/001_hello.js";
|
||||||
|
|
||||||
|
@ -1318,7 +1296,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_module_referrer_dotdot() {
|
fn test_resolve_module_referrer_dotdot() {
|
||||||
let (_temp_dir, deno_dir) = test_setup(false, false);
|
let (_temp_dir, deno_dir) = test_setup();
|
||||||
|
|
||||||
let specifier = "tests/001_hello.js";
|
let specifier = "tests/001_hello.js";
|
||||||
|
|
||||||
|
|
11
cli/flags.rs
11
cli/flags.rs
|
@ -16,7 +16,6 @@ pub struct DenoFlags {
|
||||||
pub log_debug: bool,
|
pub log_debug: bool,
|
||||||
pub version: bool,
|
pub version: bool,
|
||||||
pub reload: bool,
|
pub reload: bool,
|
||||||
pub recompile: bool,
|
|
||||||
pub allow_read: bool,
|
pub allow_read: bool,
|
||||||
pub allow_write: bool,
|
pub allow_write: bool,
|
||||||
pub allow_net: bool,
|
pub allow_net: bool,
|
||||||
|
@ -83,9 +82,6 @@ fn set_recognized_flags(
|
||||||
if matches.opt_present("reload") {
|
if matches.opt_present("reload") {
|
||||||
flags.reload = true;
|
flags.reload = true;
|
||||||
}
|
}
|
||||||
if matches.opt_present("recompile") {
|
|
||||||
flags.recompile = true;
|
|
||||||
}
|
|
||||||
if matches.opt_present("allow-read") {
|
if matches.opt_present("allow-read") {
|
||||||
flags.allow_read = true;
|
flags.allow_read = true;
|
||||||
}
|
}
|
||||||
|
@ -154,11 +150,14 @@ pub fn set_flags(
|
||||||
opts.optflag("", "allow-run", "Allow running subprocesses");
|
opts.optflag("", "allow-run", "Allow running subprocesses");
|
||||||
opts.optflag("A", "allow-all", "Allow all permissions");
|
opts.optflag("A", "allow-all", "Allow all permissions");
|
||||||
opts.optflag("", "no-prompt", "Do not use prompts");
|
opts.optflag("", "no-prompt", "Do not use prompts");
|
||||||
opts.optflag("", "recompile", "Force recompilation of TypeScript code");
|
|
||||||
opts.optflag("h", "help", "Print this message");
|
opts.optflag("h", "help", "Print this message");
|
||||||
opts.optflag("D", "log-debug", "Log debug output");
|
opts.optflag("D", "log-debug", "Log debug output");
|
||||||
opts.optflag("v", "version", "Print the version");
|
opts.optflag("v", "version", "Print the version");
|
||||||
opts.optflag("r", "reload", "Reload cached remote resources");
|
opts.optflag(
|
||||||
|
"r",
|
||||||
|
"reload",
|
||||||
|
"Reload source code cache (recompile TypeScript)",
|
||||||
|
);
|
||||||
opts.optflag("", "v8-options", "Print V8 command line options");
|
opts.optflag("", "v8-options", "Print V8 command line options");
|
||||||
opts.optflag("", "types", "Print runtime TypeScript declarations");
|
opts.optflag("", "types", "Print runtime TypeScript declarations");
|
||||||
opts.optflag("", "prefetch", "Prefetch the dependencies");
|
opts.optflag("", "prefetch", "Prefetch the dependencies");
|
||||||
|
|
|
@ -172,20 +172,22 @@ impl<B: DenoBehavior> Future for Isolate<B> {
|
||||||
self.inner.poll().map_err(|err| self.apply_source_map(err))
|
self.inner.poll().map_err(|err| self.apply_source_map(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_module_meta_data_and_maybe_compile_async(
|
fn fetch_module_meta_data_and_maybe_compile_async(
|
||||||
state: &Arc<IsolateState>,
|
state: &Arc<IsolateState>,
|
||||||
specifier: &str,
|
specifier: &str,
|
||||||
referrer: &str,
|
referrer: &str,
|
||||||
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
|
) -> impl Future<Item = ModuleMetaData, Error = DenoError> {
|
||||||
|
let use_cache = !state.flags.reload;
|
||||||
let state_ = state.clone();
|
let state_ = state.clone();
|
||||||
let specifier = specifier.to_string();
|
let specifier = specifier.to_string();
|
||||||
let referrer = referrer.to_string();
|
let referrer = referrer.to_string();
|
||||||
state
|
state
|
||||||
.dir
|
.dir
|
||||||
.fetch_module_meta_data_async(&specifier, &referrer)
|
.fetch_module_meta_data_async(&specifier, &referrer, use_cache)
|
||||||
.and_then(move |mut out| {
|
.and_then(move |mut out| {
|
||||||
if out.media_type == msg::MediaType::TypeScript
|
if out.media_type == msg::MediaType::TypeScript
|
||||||
&& (out.maybe_output_code.is_none() || state_.flags.recompile)
|
&& !out.has_output_code_and_source_map()
|
||||||
{
|
{
|
||||||
debug!(">>>>> compile_sync START");
|
debug!(">>>>> compile_sync START");
|
||||||
out = compile_sync(state_.clone(), &specifier, &referrer, &out);
|
out = compile_sync(state_.clone(), &specifier, &referrer, &out);
|
||||||
|
|
|
@ -53,8 +53,7 @@ impl IsolateState {
|
||||||
let custom_root = env::var("DENO_DIR").map(|s| s.into()).ok();
|
let custom_root = env::var("DENO_DIR").map(|s| s.into()).ok();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
dir: deno_dir::DenoDir::new(flags.reload, flags.recompile, custom_root)
|
dir: deno_dir::DenoDir::new(custom_root).unwrap(),
|
||||||
.unwrap(),
|
|
||||||
argv: argv_rest,
|
argv: argv_rest,
|
||||||
permissions: DenoPermissions::from_flags(&flags),
|
permissions: DenoPermissions::from_flags(&flags),
|
||||||
flags,
|
flags,
|
||||||
|
|
|
@ -88,7 +88,8 @@ impl Modules {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_file_info(&self, deno_dir: &DenoDir, filename: String) {
|
pub fn print_file_info(&self, deno_dir: &DenoDir, filename: String) {
|
||||||
let maybe_out = deno_dir.fetch_module_meta_data(&filename, ".");
|
// TODO Note the --reload flag is ignored here.
|
||||||
|
let maybe_out = deno_dir.fetch_module_meta_data(&filename, ".", true);
|
||||||
if maybe_out.is_err() {
|
if maybe_out.is_err() {
|
||||||
println!("{}", maybe_out.unwrap_err());
|
println!("{}", maybe_out.unwrap_err());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -386,9 +386,15 @@ fn op_fetch_module_meta_data(
|
||||||
"Sanity check"
|
"Sanity check"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let use_cache = !sc.state().flags.reload;
|
||||||
|
|
||||||
Box::new(futures::future::result(|| -> OpResult {
|
Box::new(futures::future::result(|| -> OpResult {
|
||||||
let builder = &mut FlatBufferBuilder::new();
|
let builder = &mut FlatBufferBuilder::new();
|
||||||
let out = sc.state().dir.fetch_module_meta_data(specifier, referrer)?;
|
// TODO(ry) Use fetch_module_meta_data_async.
|
||||||
|
let out = sc
|
||||||
|
.state()
|
||||||
|
.dir
|
||||||
|
.fetch_module_meta_data(specifier, referrer, use_cache)?;
|
||||||
let data_off = builder.create_vector(out.source_code.as_slice());
|
let data_off = builder.create_vector(out.source_code.as_slice());
|
||||||
let msg_args = msg::FetchModuleMetaDataResArgs {
|
let msg_args = msg::FetchModuleMetaDataResArgs {
|
||||||
module_name: Some(builder.create_string(&out.module_name)),
|
module_name: Some(builder.create_string(&out.module_name)),
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
args: tests/023_no_ext_with_mime --reload --recompile
|
args: tests/023_no_ext_with_mime --reload
|
||||||
output: tests/023_no_ext_with_mime.out
|
output: tests/023_no_ext_with_mime.out
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
args: tests/024_import_no_ext_with_mime.ts --reload --recompile
|
args: tests/024_import_no_ext_with_mime.ts --reload
|
||||||
output: tests/024_import_no_ext_with_mime.ts.out
|
output: tests/024_import_no_ext_with_mime.ts.out
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// There was a bug where if this was executed with --recompile it would throw a
|
// There was a bug where if this was executed with --reload it would throw a
|
||||||
// type error.
|
// type error.
|
||||||
window.test = null;
|
window.test = null;
|
||||||
test = console;
|
test = console;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
args: tests/025_reload_js_type_error.js --reload --recompile
|
args: tests/025_reload_js_type_error.js --reload
|
||||||
output: tests/025_reload_js_type_error.js.out
|
output: tests/025_reload_js_type_error.js.out
|
||||||
|
|
|
@ -23,8 +23,8 @@ exec_time_benchmarks = [
|
||||||
("hello", ["tests/002_hello.ts"]),
|
("hello", ["tests/002_hello.ts"]),
|
||||||
("relative_import", ["tests/003_relative_import.ts"]),
|
("relative_import", ["tests/003_relative_import.ts"]),
|
||||||
("error_001", ["tests/error_001.ts"]),
|
("error_001", ["tests/error_001.ts"]),
|
||||||
("cold_hello", ["tests/002_hello.ts", "--recompile"]),
|
("cold_hello", ["tests/002_hello.ts", "--reload"]),
|
||||||
("cold_relative_import", ["tests/003_relative_import.ts", "--recompile"]),
|
("cold_relative_import", ["tests/003_relative_import.ts", "--reload"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
gh_pages_data_file = "gh-pages/data.json"
|
gh_pages_data_file = "gh-pages/data.json"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from util import mkdtemp, root_path, tests_path, run, green_ok
|
from util import mkdtemp, root_path, tests_path, run, green_ok
|
||||||
import shutil
|
import shutil
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def fmt_test(deno_exe):
|
def fmt_test(deno_exe):
|
||||||
|
@ -18,13 +19,17 @@ def fmt_test(deno_exe):
|
||||||
# Set DENO_DIR to //js/ so we don't have to rely on an intenet
|
# Set DENO_DIR to //js/ so we don't have to rely on an intenet
|
||||||
# connection to download https://deno.land/std/prettier/main.ts
|
# connection to download https://deno.land/std/prettier/main.ts
|
||||||
deno_dir = os.path.join(root_path, "js")
|
deno_dir = os.path.join(root_path, "js")
|
||||||
run([deno_exe, dst, "--fmt", "--allow-read"],
|
run([deno_exe, dst, "--fmt"], merge_env={"DENO_DIR": deno_dir})
|
||||||
merge_env={"DENO_DIR": deno_dir})
|
|
||||||
with open(fixed_filename) as f:
|
with open(fixed_filename) as f:
|
||||||
expected = f.read()
|
expected = f.read()
|
||||||
with open(dst) as f:
|
with open(dst) as f:
|
||||||
actual = f.read()
|
actual = f.read()
|
||||||
assert expected == actual
|
if expected != actual:
|
||||||
|
print "Expected didn't match actual."
|
||||||
|
print "expected: ", json.dumps(expected)
|
||||||
|
print "actual: ", json.dumps(actual)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(d)
|
shutil.rmtree(d)
|
||||||
print green_ok()
|
print green_ok()
|
||||||
|
|
|
@ -32,7 +32,7 @@ def run_unit_test2(cmd):
|
||||||
def run_unit_test(deno_exe, permStr, flags=None):
|
def run_unit_test(deno_exe, permStr, flags=None):
|
||||||
if flags is None:
|
if flags is None:
|
||||||
flags = []
|
flags = []
|
||||||
cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags
|
cmd = [deno_exe, "js/unit_tests.ts", permStr] + flags
|
||||||
run_unit_test2(cmd)
|
run_unit_test2(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def run_unit_test(deno_exe, permStr, flags=None):
|
||||||
# tests by the special string. permW0N0 means allow-write but not allow-net.
|
# tests by the special string. permW0N0 means allow-write but not allow-net.
|
||||||
# See js/test_util.ts for more details.
|
# See js/test_util.ts for more details.
|
||||||
def unit_tests(deno_exe):
|
def unit_tests(deno_exe):
|
||||||
run_unit_test(deno_exe, "permR0W0N0E0U0")
|
run_unit_test(deno_exe, "permR0W0N0E0U0", ["--reload"])
|
||||||
run_unit_test(deno_exe, "permR1W0N0E0U0", ["--allow-read"])
|
run_unit_test(deno_exe, "permR1W0N0E0U0", ["--allow-read"])
|
||||||
run_unit_test(deno_exe, "permR0W1N0E0U0", ["--allow-write"])
|
run_unit_test(deno_exe, "permR0W1N0E0U0", ["--allow-write"])
|
||||||
run_unit_test(deno_exe, "permR1W1N0E0U0",
|
run_unit_test(deno_exe, "permR1W1N0E0U0",
|
||||||
|
|
|
@ -531,7 +531,7 @@ Options:
|
||||||
--allow-env Allow environment access
|
--allow-env Allow environment access
|
||||||
--allow-run Allow running subprocesses
|
--allow-run Allow running subprocesses
|
||||||
-A, --allow-all Allow all permissions
|
-A, --allow-all Allow all permissions
|
||||||
--recompile Force recompilation of TypeScript code
|
--no-prompt Do not use prompts
|
||||||
-h, --help Print this message
|
-h, --help Print this message
|
||||||
-D, --log-debug Log debug output
|
-D, --log-debug Log debug output
|
||||||
-v, --version Print the version
|
-v, --version Print the version
|
||||||
|
|
Loading…
Reference in a new issue